Containerization feature of SO
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / client / sdnc / mapper / ServiceTopologyOperationMapper.java
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.onap.so.client.sdnc.mapper;
22
23 import java.util.Map;
24 import java.util.UUID;
25
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
28 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
29 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
30 import org.onap.so.client.sdnc.beans.SDNCSvcOperation;
31 import org.springframework.stereotype.Component;
32
33 import org.onap.sdnc.apps.client.model.GenericResourceApiParam;
34 import org.onap.sdnc.apps.client.model.GenericResourceApiParamParam;
35 import org.onap.sdnc.apps.client.model.GenericResourceApiRequestActionEnumeration;
36 import org.onap.sdnc.apps.client.model.GenericResourceApiRequestinformationRequestInformation;
37 import org.onap.sdnc.apps.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader;
38 import org.onap.sdnc.apps.client.model.GenericResourceApiServiceOperationInformation;
39 import org.onap.sdnc.apps.client.model.GenericResourceApiServiceinformationServiceInformation;
40 import org.onap.sdnc.apps.client.model.GenericResourceApiServicerequestinputServiceRequestInput;
41
42 @Component
43 public class ServiceTopologyOperationMapper{
44
45         static GeneralTopologyObjectMapper generalTopologyObjectMapper = new GeneralTopologyObjectMapper();
46         
47         public GenericResourceApiServiceOperationInformation reqMapper (SDNCSvcOperation svcOperation,
48                         SDNCSvcAction svcAction, GenericResourceApiRequestActionEnumeration resourceAction,ServiceInstance serviceInstance, Customer customer, RequestContext requestContext) {
49
50                 String sdncReqId = UUID.randomUUID().toString();
51                 GenericResourceApiServiceOperationInformation servOpInput = new GenericResourceApiServiceOperationInformation();
52                 GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = generalTopologyObjectMapper.buildSdncRequestHeader(svcAction, sdncReqId);
53                 GenericResourceApiRequestinformationRequestInformation reqInfo = generalTopologyObjectMapper.buildGenericResourceApiRequestinformationRequestInformation(sdncReqId, resourceAction);
54                 GenericResourceApiServiceinformationServiceInformation servInfo = generalTopologyObjectMapper.buildServiceInformation(serviceInstance, requestContext, customer, true);
55                 GenericResourceApiServicerequestinputServiceRequestInput servReqInfo = new GenericResourceApiServicerequestinputServiceRequestInput();
56         
57                 servReqInfo.setServiceInstanceName(serviceInstance.getServiceInstanceId());
58                 
59                 servOpInput.setSdncRequestHeader(sdncRequestHeader);
60                 servOpInput.setRequestInformation(reqInfo);
61                 servOpInput.setServiceInformation(servInfo);
62                 servOpInput.setServiceRequestInput(servReqInfo);
63                 
64                 if(requestContext.getUserParams()!=null){
65                         for (Map.Entry<String, String> entry : requestContext.getUserParams().entrySet()) {
66                                 GenericResourceApiServicerequestinputServiceRequestInput serviceRequestInput = new GenericResourceApiServicerequestinputServiceRequestInput(); 
67                                 serviceRequestInput.setServiceInstanceName(serviceInstance.getServiceInstanceId()); 
68                                 GenericResourceApiParam serviceInputParameters = new GenericResourceApiParam(); 
69                                 GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam(); 
70                                 paramItem.setName(entry.getKey()); 
71                                 paramItem.setValue(entry.getValue()); 
72                                 serviceInputParameters.addParamItem(paramItem ); 
73                                 serviceRequestInput.serviceInputParameters(serviceInputParameters); 
74                                 servOpInput.setServiceRequestInput(serviceRequestInput ); 
75                         }
76                 }
77                 return servOpInput;             
78         }
79 }