432399b1b8abf1db739c0786d9890e14108b6d99
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / client / sdnc / mapper / GeneralTopologyObjectMapper.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 org.onap.sdnc.northbound.client.model.*;
24 import org.onap.so.bpmn.servicedecomposition.bbobjects.*;
25 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
26 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
27 import org.springframework.stereotype.Component;
28 import org.onap.so.client.exception.MapperException;
29
30 @Component
31 public class GeneralTopologyObjectMapper {
32
33         /*
34          * Build GenericResourceApiRequestinformationRequestInformation
35          */
36         public GenericResourceApiRequestinformationRequestInformation buildGenericResourceApiRequestinformationRequestInformation(String sdncReqId, GenericResourceApiRequestActionEnumeration requestAction){
37
38                 GenericResourceApiRequestinformationRequestInformation requestInformation = new GenericResourceApiRequestinformationRequestInformation();
39                 requestInformation.setRequestId(sdncReqId);
40                 requestInformation.setRequestAction(requestAction);
41                 requestInformation.setSource("MSO");
42                 return requestInformation;
43         }
44         /*
45          * Build GenericResourceApiServiceinformationServiceInformation
46          */
47         public GenericResourceApiServiceinformationServiceInformation buildServiceInformation(ServiceInstance serviceInstance, RequestContext requestContext, Customer customer, boolean includeModelInformation){
48                 GenericResourceApiServiceinformationServiceInformation serviceInformation = new GenericResourceApiServiceinformationServiceInformation();
49                 serviceInformation.serviceId(serviceInstance.getServiceInstanceId());
50                 if (requestContext != null) {
51                         serviceInformation.setSubscriptionServiceType(requestContext.getProductFamilyId());
52                 }
53                 if (includeModelInformation) {
54                         GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation = new GenericResourceApiOnapmodelinformationOnapModelInformation();
55                         onapModelInformation.setModelInvariantUuid(serviceInstance.getModelInfoServiceInstance().getModelInvariantUuid());
56                         onapModelInformation.setModelVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion());
57                         onapModelInformation.setModelName(serviceInstance.getModelInfoServiceInstance().getModelName());
58                         onapModelInformation.setModelUuid(serviceInstance.getModelInfoServiceInstance().getModelUuid());
59                         serviceInformation.setOnapModelInformation(onapModelInformation );
60                 }
61                 serviceInformation.setServiceInstanceId(serviceInstance.getServiceInstanceId());
62
63                 if (customer != null) {
64                         serviceInformation.setGlobalCustomerId(customer.getGlobalCustomerId());
65                         if(customer.getServiceSubscription() != null){
66                                 serviceInformation.setSubscriptionServiceType(customer.getServiceSubscription().getServiceType());
67                         }
68
69                 }
70                 return serviceInformation;
71         }
72         /*
73          * Build GenericResourceApiNetworkinformationNetworkInformation
74          */
75         public GenericResourceApiNetworkinformationNetworkInformation buildNetworkInformation(L3Network network){
76                 GenericResourceApiNetworkinformationNetworkInformation networkInformation = new GenericResourceApiNetworkinformationNetworkInformation();
77                 GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation = new GenericResourceApiOnapmodelinformationOnapModelInformation();
78                 if (network.getModelInfoNetwork() != null) {
79                         onapModelInformation.setModelInvariantUuid(network.getModelInfoNetwork().getModelInvariantUUID());
80                         onapModelInformation.setModelName(network.getModelInfoNetwork().getModelName());
81                         onapModelInformation.setModelVersion(network.getModelInfoNetwork().getModelVersion());
82                         onapModelInformation.setModelUuid(network.getModelInfoNetwork().getModelUUID());
83                         onapModelInformation.setModelCustomizationUuid(network.getModelInfoNetwork().getModelCustomizationUUID());
84                         networkInformation.setOnapModelInformation(onapModelInformation);
85                 }
86
87                 networkInformation.setFromPreload(null);
88                 networkInformation.setNetworkId(network.getNetworkId());
89                 //TODO fix this after network type filed included in L3Network object type
90                 //networkInformation.setNetworkType(network.getNetwork);
91                 return networkInformation;
92         }
93         /*
94          * Build GenericResourceApiVnfinformationVnfInformation
95          */
96         public GenericResourceApiVnfinformationVnfInformation buildVnfInformation(GenericVnf vnf, ServiceInstance serviceInstance, boolean includeModelInformation){
97                 GenericResourceApiVnfinformationVnfInformation vnfInformation = new GenericResourceApiVnfinformationVnfInformation();
98                 if (includeModelInformation && vnf.getModelInfoGenericVnf() != null) {
99                         GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation = new GenericResourceApiOnapmodelinformationOnapModelInformation();
100                         onapModelInformation.setModelInvariantUuid(vnf.getModelInfoGenericVnf().getModelInvariantUuid());
101                         onapModelInformation.setModelName(vnf.getModelInfoGenericVnf().getModelName());
102                         onapModelInformation.setModelVersion(vnf.getModelInfoGenericVnf().getModelVersion());
103                         onapModelInformation.setModelUuid(vnf.getModelInfoGenericVnf().getModelUuid());
104                         onapModelInformation.setModelCustomizationUuid(vnf.getModelInfoGenericVnf().getModelCustomizationUuid());
105                         vnfInformation.setOnapModelInformation(onapModelInformation);
106                 }
107                 vnfInformation.setVnfId(vnf.getVnfId());
108                 vnfInformation.setVnfType(vnf.getVnfType());
109                 vnfInformation.setVnfName(vnf.getVnfName());
110                 return vnfInformation;
111         }
112         /*
113          * Build GenericResourceApiVfModuleinformationVfModuleInformation
114          */
115         public GenericResourceApiVfmoduleinformationVfModuleInformation buildVfModuleInformation(VfModule vfModule, GenericVnf vnf, ServiceInstance serviceInstance, boolean includeModelInformation) throws MapperException {
116                 GenericResourceApiVfmoduleinformationVfModuleInformation vfModuleInformation = new GenericResourceApiVfmoduleinformationVfModuleInformation();
117                 if (includeModelInformation) {
118                         if (vfModule.getModelInfoVfModule() == null) {
119                                 throw new MapperException("VF Module model info is null for " + vfModule.getVfModuleId());
120                         }
121                         else {
122                                 GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation = new GenericResourceApiOnapmodelinformationOnapModelInformation();
123                                 onapModelInformation.setModelInvariantUuid(vfModule.getModelInfoVfModule().getModelInvariantUUID());
124                                 onapModelInformation.setModelName(vfModule.getModelInfoVfModule().getModelName());
125                                 onapModelInformation.setModelVersion(vfModule.getModelInfoVfModule().getModelVersion());
126                                 onapModelInformation.setModelUuid(vfModule.getModelInfoVfModule().getModelUUID());
127                                 onapModelInformation.setModelCustomizationUuid(vfModule.getModelInfoVfModule().getModelCustomizationUUID());
128                                 vfModuleInformation.setOnapModelInformation(onapModelInformation);
129                         }
130                 }
131                 if (vfModule.getModelInfoVfModule() != null) {
132                         vfModuleInformation.setVfModuleType(vfModule.getModelInfoVfModule().getModelName());
133                 }
134                 vfModuleInformation.setVfModuleId(vfModule.getVfModuleId());
135                 vfModuleInformation.setFromPreload(null);
136                 return vfModuleInformation;
137         }
138         public GenericResourceApiSdncrequestheaderSdncRequestHeader buildSdncRequestHeader(SDNCSvcAction svcAction, String sdncReqId){
139                 GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = new GenericResourceApiSdncrequestheaderSdncRequestHeader();
140                 sdncRequestHeader.setSvcAction(svcAction.getSdncApiAction());
141                 sdncRequestHeader.setSvcRequestId(sdncReqId);
142                 return sdncRequestHeader;
143         }
144
145     /**
146          * Build ConfigurationInformation
147      * @param configuration
148      * @param includeModelInformation
149      * @return
150      */
151     public GenericResourceApiConfigurationinformationConfigurationInformation buildConfigurationInformation(Configuration configuration, boolean includeModelInformation) {
152         GenericResourceApiConfigurationinformationConfigurationInformation configurationInformation = new GenericResourceApiConfigurationinformationConfigurationInformation();
153         configurationInformation.setConfigurationId(configuration.getConfigurationId());
154         configurationInformation.setConfigurationName(configuration.getConfigurationName());
155         configurationInformation.setConfigurationType(configuration.getConfigurationType());
156         if(includeModelInformation) {
157             GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation = new GenericResourceApiOnapmodelinformationOnapModelInformation();
158             onapModelInformation.setModelInvariantUuid(configuration.getModelInfoConfiguration().getModelInvariantId());
159             onapModelInformation.setModelUuid(configuration.getModelInfoConfiguration().getModelVersionId());
160             onapModelInformation.setModelCustomizationUuid(configuration.getModelInfoConfiguration().getModelCustomizationId());
161             configurationInformation.setOnapModelInformation(onapModelInformation);
162         }
163         return configurationInformation;
164     }
165
166
167     /**
168          * Build GcRequestInformation
169      * @param vnf
170      * @param genericResourceApiParam
171      * @return
172      */
173     public GenericResourceApiGcrequestinputGcRequestInput buildGcRequestInformation(GenericVnf vnf,GenericResourceApiParam genericResourceApiParam) {
174         GenericResourceApiGcrequestinputGcRequestInput gcRequestInput = new GenericResourceApiGcrequestinputGcRequestInput();
175         gcRequestInput.setVnfId(vnf.getVnfId());
176         if(genericResourceApiParam != null) {
177             gcRequestInput.setInputParameters(genericResourceApiParam);
178         }
179             return gcRequestInput;
180         }
181 }