2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
 
   7  * ================================================================================
 
   8  * Licensed under the Apache License, Version 2.0 (the "License");
 
   9  * you may not use this file except in compliance with the License.
 
  10  * You may obtain a copy of the License at
 
  12  *      http://www.apache.org/licenses/LICENSE-2.0
 
  14  * Unless required by applicable law or agreed to in writing, software
 
  15  * distributed under the License is distributed on an "AS IS" BASIS,
 
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  17  * See the License for the specific language governing permissions and
 
  18  * limitations under the License.
 
  19  * ============LICENSE_END=========================================================
 
  22 package org.openecomp.appc.provider.lcm.util;
 
  24 import java.text.ParseException;
 
  25 import java.text.SimpleDateFormat;
 
  27 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.Payload;
 
  28 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.action.identifiers.ActionIdentifiers;
 
  29 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.common.header.CommonHeader;
 
  30 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.common.header.common.header.Flags;
 
  31 import org.openecomp.appc.domainmodel.lcm.RequestContext;
 
  32 import org.openecomp.appc.domainmodel.lcm.VNFOperation;
 
  33 import org.openecomp.appc.requesthandler.objects.RequestHandlerInput;
 
  34 import com.att.eelf.configuration.EELFLogger;
 
  35 import com.att.eelf.configuration.EELFManager;
 
  39 public class RequestInputBuilder {
 
  40     private static EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
 
  42     private static final String FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
 
  44     private RequestContext requestContext;
 
  45     private String rpcName;
 
  47     public RequestInputBuilder() {
 
  51     public RequestInputBuilder requestContext() {
 
  52         this.requestContext = new RequestContext();
 
  56     public RequestInputBuilder action(String action) {
 
  57         this.requestContext.setAction(VNFOperation.findByString(action));
 
  62     public RequestInputBuilder additionalContext(String key, String value) {
 
  63         this.requestContext.addKeyValueToAdditionalContext(key, value);
 
  67     public RequestInputBuilder payload(Payload payload) {
 
  68         if (payload != null) {
 
  69             this.requestContext.setPayload(payload.getValue());
 
  74     public RequestHandlerInput  build (){
 
  75         RequestHandlerInput request = new RequestHandlerInput();
 
  76         request.setRequestContext(this.requestContext);
 
  77         request.setRpcName(rpcName);
 
  81     public RequestInputBuilder rpcName(String rpcName) {
 
  82         this.rpcName = rpcName;
 
  86     public RequestInputBuilder commonHeader(CommonHeader commonHeader) throws ParseException {
 
  87         org.openecomp.appc.domainmodel.lcm.CommonHeader header = new org.openecomp.appc.domainmodel.lcm.CommonHeader();
 
  88         this.requestContext.setCommonHeader(header);
 
  91             if(null != commonHeader.getTimestamp()) {
 
  92                 SimpleDateFormat format = new SimpleDateFormat(FORMAT);
 
  93                 format.setLenient(false);
 
  94                 header.setTimestamp(format.parse(commonHeader.getTimestamp().getValue()));
 
  96                 throw new ParseException("Missing mandatory parameter : timestamp " , 0);
 
  98         } catch (ParseException e) {
 
  99             logger.error(String.format("DATE format is incorrect: %s", e.getMessage()));
 
 102         header.setApiVer(commonHeader.getApiVer());
 
 103         header.setRequestId(commonHeader.getRequestId());
 
 104         header.setOriginatorId(commonHeader.getOriginatorId());
 
 105         header.setSubRequestId(commonHeader.getSubRequestId());
 
 107         Flags inFlags = commonHeader.getFlags();
 
 108         org.openecomp.appc.domainmodel.lcm.Flags flags = new org.openecomp.appc.domainmodel.lcm.Flags();
 
 109         if (inFlags != null) {
 
 111             if(null != inFlags.getForce()) {
 
 112                 flags.setForce(Boolean.parseBoolean(inFlags.getForce().toString().toLowerCase()));
 
 114             if(null!=inFlags.getMode()) {
 
 115                 flags.setMode(inFlags.getMode().name());
 
 117             if(null!=  inFlags.getTtl()) {
 
 118                 flags.setTtl(inFlags.getTtl());
 
 122         this.requestContext.getCommonHeader().setFlags(flags);
 
 126     public RequestInputBuilder actionIdentifiers(ActionIdentifiers actionIdentifiers)  throws ParseException  {
 
 127         if(null!= actionIdentifiers) {
 
 128             org.openecomp.appc.domainmodel.lcm.ActionIdentifiers actionIds = new org.openecomp.appc.domainmodel.lcm.ActionIdentifiers();
 
 129             actionIds.setServiceInstanceId(actionIdentifiers.getServiceInstanceId());
 
 130             actionIds.setVnfcName(actionIdentifiers.getVnfcName());
 
 131             actionIds.setvServerId(actionIdentifiers.getVserverId());
 
 132             actionIds.setVnfId(actionIdentifiers.getVnfId());
 
 133             this.requestContext.setActionIdentifiers(actionIds);
 
 136             throw new ParseException("Missing action identifier" , 0);