bcac56a51849a6f961b113bcedb204e3a17062da
[so.git] /
1 package org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.builder;
2
3 import org.apache.commons.lang3.StringUtils;
4 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformation;
5 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeader;
6 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.*;
7
8 import java.util.ArrayList;
9 import java.util.List;
10 import java.util.Map;
11
12 /**
13  * Created by 10112215 on 2017/9/20.
14  */
15 public class NetworkRpcInputEntityBuilder implements AbstractBuilder<Map<String, String>, NetworkRpcInputEntity> {
16
17     public static final String SVC_REQUEST_ID = "MSO";
18     public static final String SDC_ACTION = "SDC_ACTION";
19     public static final RequestInformation.RequestAction REQUEST_ACTION = RequestInformation.RequestAction.CreateNetworkInstance;
20
21     protected NetworkRpcInputEntity getSdncEntityInput(Map<String, String> inputs) {
22         NetworkRpcInputEntity networkRpcInputEntity = new NetworkRpcInputEntity();
23         InputEntity inputEntity = new InputEntity();
24         {
25             loadSdncRequestHeaderEntity(inputs, inputEntity);
26             loadRequestInformationEntity(inputEntity);
27
28             ServiceInformationEntity serviceInformationEntity = new ServiceInformationEntity();
29             String serviceId = inputs.get("serviceId");
30             serviceInformationEntity.setServiceId(serviceId);
31
32
33             loadNetwrokRequestInputEntity(inputs, inputEntity);
34         }
35         networkRpcInputEntity.setInput(inputEntity);
36         return networkRpcInputEntity;
37     }
38
39     private void loadNetwrokRequestInputEntity(Map<String, String> inputs, InputEntity inputEntity) {
40         NetworkRequestInputEntity networkRequestInputEntity = new NetworkRequestInputEntity();
41         {
42             NetworkInputPaarametersEntity networkInputPaarametersEntity = new NetworkInputPaarametersEntity();
43             {
44                 List<ParamEntity> paramEntityList = getParamEntities(inputs);
45                 networkInputPaarametersEntity.setParamList(paramEntityList);
46             }
47
48         }
49         inputEntity.setNetworkRequestInput(networkRequestInputEntity);
50     }
51
52     private List<ParamEntity> getParamEntities(Map<String, String> inputs) {
53         List<ParamEntity> paramEntityList = new ArrayList<>();
54         if (inputs != null && !inputs.isEmpty()) {
55             inputs.keySet().forEach(key -> {
56                 ParamEntity paramEntity = new ParamEntity();
57                 paramEntity.setName(key);
58                 paramEntity.setValue(inputs.get(key));
59                 paramEntityList.add(paramEntity);
60             });
61         }
62         return paramEntityList;
63     }
64
65     private void loadRequestInformationEntity(InputEntity inputEntity) {
66         RequestInformationEntity requestInformationEntity = new RequestInformationEntity();
67         {
68             requestInformationEntity.setRequestId(SVC_REQUEST_ID);
69             requestInformationEntity.setRequestAction(REQUEST_ACTION.name());
70         }
71         inputEntity.setRequestInformation(requestInformationEntity);
72     }
73
74     private void loadSdncRequestHeaderEntity(Map<String, String> inputs, InputEntity inputEntity) {
75         SdncRequestHeaderEntity sdncRequestHeaderEntity = new SdncRequestHeaderEntity();
76         {
77             sdncRequestHeaderEntity.setSvcRequestId(SVC_REQUEST_ID);
78             String action = inputs.get(SDC_ACTION);
79             if (!StringUtils.isBlank(action)) {
80                 if (action.toLowerCase().contains("delete")) {
81                     action = SdncRequestHeader.SvcAction.Delete.name();
82                 } else if (action.toLowerCase().contains("create")) {
83                     action = SdncRequestHeader.SvcAction.Create.name();
84                 }
85             }
86             sdncRequestHeaderEntity.setSvcAction(action);
87         }
88         inputEntity.setSdncRequestHeader(sdncRequestHeaderEntity);
89     }
90
91     @Override
92     public NetworkRpcInputEntity build(Map<String, String> input) {
93         return null;
94     }
95 }