2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.provider.lcm.util;
28 import java.text.ParseException;
29 import java.text.SimpleDateFormat;
30 import java.util.TimeZone;
32 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
33 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
34 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
35 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.common.header.Flags;
36 import org.onap.appc.domainmodel.lcm.ActionLevel;
37 import org.onap.appc.domainmodel.lcm.RequestContext;
38 import org.onap.appc.domainmodel.lcm.VNFOperation;
39 import org.onap.appc.requesthandler.objects.RequestHandlerInput;
40 import com.att.eelf.configuration.EELFLogger;
41 import com.att.eelf.configuration.EELFManager;
45 public class RequestInputBuilder {
46 private final EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
48 private static final String FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
50 private RequestContext requestContext;
51 private String rpcName;
54 public RequestInputBuilder requestContext() {
55 this.requestContext = new RequestContext();
59 public RequestInputBuilder action(String action) {
60 this.requestContext.setAction(VNFOperation.findByString(action));
65 public RequestInputBuilder additionalContext(String key, String value) {
66 this.requestContext.addKeyValueToAdditionalContext(key, value);
70 public RequestInputBuilder payload(Payload payload) {
71 if (payload != null) {
72 this.requestContext.setPayload(payload.getValue());
77 public RequestHandlerInput build (){
78 RequestHandlerInput request = new RequestHandlerInput();
79 request.setRequestContext(this.requestContext);
80 request.setRpcName(rpcName);
84 public RequestInputBuilder rpcName(String rpcName) {
85 this.rpcName = rpcName;
89 public RequestInputBuilder commonHeader(CommonHeader commonHeader) throws ParseException {
90 org.onap.appc.domainmodel.lcm.CommonHeader header = new org.onap.appc.domainmodel.lcm.CommonHeader();
91 this.requestContext.setCommonHeader(header);
94 if(null != commonHeader.getTimestamp()) {
95 SimpleDateFormat format = new SimpleDateFormat(FORMAT);
96 format.setLenient(false);
97 format.setTimeZone(TimeZone.getTimeZone("UTC"));
98 header.setTimestamp(format.parse(commonHeader.getTimestamp().getValue()));
100 throw new ParseException("Missing mandatory parameter : timestamp " , 0);
102 } catch (ParseException e) {
103 logger.error(String.format("DATE format is incorrect: %s", e.getMessage()));
106 header.setApiVer(commonHeader.getApiVer());
107 header.setRequestId(commonHeader.getRequestId());
108 header.setOriginatorId(commonHeader.getOriginatorId());
109 header.setSubRequestId(commonHeader.getSubRequestId());
111 Flags inFlags = commonHeader.getFlags();
112 org.onap.appc.domainmodel.lcm.Flags flags = new org.onap.appc.domainmodel.lcm.Flags();
113 if (inFlags != null) {
115 if(null != inFlags.getForce()) {
116 flags.setForce(Boolean.parseBoolean(inFlags.getForce().toString().toLowerCase()));
118 if(null!=inFlags.getMode()) {
119 flags.setMode(inFlags.getMode().name());
121 if(null!= inFlags.getTtl()) {
122 flags.setTtl(inFlags.getTtl());
126 this.requestContext.getCommonHeader().setFlags(flags);
130 public RequestInputBuilder actionIdentifiers(ActionIdentifiers actionIdentifiers) throws ParseException {
131 if(null!= actionIdentifiers) {
132 org.onap.appc.domainmodel.lcm.ActionIdentifiers actionIds = new org.onap.appc.domainmodel.lcm.ActionIdentifiers();
133 actionIds.setServiceInstanceId(actionIdentifiers.getServiceInstanceId());
134 actionIds.setVnfcName(actionIdentifiers.getVnfcName());
135 actionIds.setvServerId(actionIdentifiers.getVserverId());
136 actionIds.setVnfId(actionIdentifiers.getVnfId());
137 actionIds.setVfModuleId(actionIdentifiers.getVfModuleId());
138 this.requestContext.setActionIdentifiers(actionIds);
140 ActionLevel actionLevel=ActionLevel.VNF;
141 this.requestContext.setActionLevel(actionLevel);
144 throw new ParseException("Missing action identifier" , 0);