ae1b92c8e9313cd0193967d72e9524dfb51fac82
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.builder;
22
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.*;
27
28 import java.util.ArrayList;
29 import java.util.List;
30 import java.util.Map;
31
32 /**
33  * Created by 10112215 on 2017/9/20.
34  */
35 public class NetworkRpcInputEntityBuilder implements AbstractBuilder<Map<String, String>, NetworkRpcInputEntity> {
36
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;
40
41     protected NetworkRpcInputEntity getSdncEntityInput(Map<String, String> inputs) {
42         NetworkRpcInputEntity networkRpcInputEntity = new NetworkRpcInputEntity();
43         InputEntity inputEntity = new InputEntity();
44         {
45             loadSdncRequestHeaderEntity(inputs, inputEntity);
46             loadRequestInformationEntity(inputEntity);
47
48             ServiceInformationEntity serviceInformationEntity = new ServiceInformationEntity();
49             String serviceId = inputs.get("serviceId");
50             serviceInformationEntity.setServiceId(serviceId);
51
52
53             loadNetwrokRequestInputEntity(inputs, inputEntity);
54         }
55         networkRpcInputEntity.setInput(inputEntity);
56         return networkRpcInputEntity;
57     }
58
59     private void loadNetwrokRequestInputEntity(Map<String, String> inputs, InputEntity inputEntity) {
60         NetworkRequestInputEntity networkRequestInputEntity = new NetworkRequestInputEntity();
61         {
62             NetworkInputPaarametersEntity networkInputPaarametersEntity = new NetworkInputPaarametersEntity();
63             {
64                 List<ParamEntity> paramEntityList = getParamEntities(inputs);
65                 networkInputPaarametersEntity.setParamList(paramEntityList);
66             }
67
68         }
69         inputEntity.setNetworkRequestInput(networkRequestInputEntity);
70     }
71
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);
80             });
81         }
82         return paramEntityList;
83     }
84
85     private void loadRequestInformationEntity(InputEntity inputEntity) {
86         RequestInformationEntity requestInformationEntity = new RequestInformationEntity();
87         {
88             requestInformationEntity.setRequestId(SVC_REQUEST_ID);
89             requestInformationEntity.setRequestAction(REQUEST_ACTION.name());
90         }
91         inputEntity.setRequestInformation(requestInformationEntity);
92     }
93
94     private void loadSdncRequestHeaderEntity(Map<String, String> inputs, InputEntity inputEntity) {
95         SdncRequestHeaderEntity sdncRequestHeaderEntity = new SdncRequestHeaderEntity();
96         {
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();
104                 }
105             }
106             sdncRequestHeaderEntity.setSvcAction(action);
107         }
108         inputEntity.setSdncRequestHeader(sdncRequestHeaderEntity);
109     }
110
111     @Override
112     public NetworkRpcInputEntity build(Map<String, String> input) {
113         return null;
114     }
115 }