2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.builder;
23 import org.apache.commons.lang3.StringUtils;
24 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformation;
25 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeader;
26 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.*;
28 import java.util.ArrayList;
29 import java.util.List;
33 * Created by 10112215 on 2017/9/20.
35 public class NetworkRpcInputEntityBuilder implements AbstractBuilder<Map<String, String>, NetworkRpcInputEntity> {
37 public static final String SVC_REQUEST_ID = "MSO";
38 public static final String SDC_ACTION = "SDC_ACTION";
39 public static final RequestInformation.RequestAction REQUEST_ACTION = RequestInformation.RequestAction.CreateNetworkInstance;
41 protected NetworkRpcInputEntity getSdncEntityInput(Map<String, String> inputs) {
42 NetworkRpcInputEntity networkRpcInputEntity = new NetworkRpcInputEntity();
43 InputEntity inputEntity = new InputEntity();
45 loadSdncRequestHeaderEntity(inputs, inputEntity);
46 loadRequestInformationEntity(inputEntity);
48 ServiceInformationEntity serviceInformationEntity = new ServiceInformationEntity();
49 String serviceId = inputs.get("serviceId");
50 serviceInformationEntity.setServiceId(serviceId);
53 loadNetwrokRequestInputEntity(inputs, inputEntity);
55 networkRpcInputEntity.setInput(inputEntity);
56 return networkRpcInputEntity;
59 private void loadNetwrokRequestInputEntity(Map<String, String> inputs, InputEntity inputEntity) {
60 NetworkRequestInputEntity networkRequestInputEntity = new NetworkRequestInputEntity();
62 NetworkInputPaarametersEntity networkInputPaarametersEntity = new NetworkInputPaarametersEntity();
64 List<ParamEntity> paramEntityList = getParamEntities(inputs);
65 networkInputPaarametersEntity.setParamList(paramEntityList);
69 inputEntity.setNetworkRequestInput(networkRequestInputEntity);
72 private List<ParamEntity> getParamEntities(Map<String, String> inputs) {
73 List<ParamEntity> paramEntityList = new ArrayList<>();
74 if (inputs != null && !inputs.isEmpty()) {
75 inputs.keySet().forEach(key -> {
76 ParamEntity paramEntity = new ParamEntity();
77 paramEntity.setName(key);
78 paramEntity.setValue(inputs.get(key));
79 paramEntityList.add(paramEntity);
82 return paramEntityList;
85 private void loadRequestInformationEntity(InputEntity inputEntity) {
86 RequestInformationEntity requestInformationEntity = new RequestInformationEntity();
88 requestInformationEntity.setRequestId(SVC_REQUEST_ID);
89 requestInformationEntity.setRequestAction(REQUEST_ACTION.name());
91 inputEntity.setRequestInformation(requestInformationEntity);
94 private void loadSdncRequestHeaderEntity(Map<String, String> inputs, InputEntity inputEntity) {
95 SdncRequestHeaderEntity sdncRequestHeaderEntity = new SdncRequestHeaderEntity();
97 sdncRequestHeaderEntity.setSvcRequestId(SVC_REQUEST_ID);
98 String action = inputs.get(SDC_ACTION);
99 if (!StringUtils.isBlank(action)) {
100 if (action.toLowerCase().contains("delete")) {
101 action = SdncRequestHeader.SvcAction.Delete.name();
102 } else if (action.toLowerCase().contains("create")) {
103 action = SdncRequestHeader.SvcAction.Create.name();
106 sdncRequestHeaderEntity.setSvcAction(action);
108 inputEntity.setSdncRequestHeader(sdncRequestHeaderEntity);
112 public NetworkRpcInputEntity build(Map<String, String> input) {