Merge "Create CSIT test for VNF delete"
[integration/csit.git] / plans / so / integration-etsi-testing / so-simulators / sdnc-simulator / src / main / java / org / onap / so / sdncsimulator / providers / ServiceOperationsCacheServiceProviderimpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.sdncsimulator.providers;
21
22 import static org.onap.sdnc.northbound.client.model.GenericResourceApiOrderStatusEnumeration.CREATED;
23 import static org.onap.sdnc.northbound.client.model.GenericResourceApiOrderStatusEnumeration.PENDINGCREATE;
24 import static org.onap.sdnc.northbound.client.model.GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE;
25 import static org.onap.so.sdncsimulator.utils.Constants.RESTCONF_CONFIG_END_POINT;
26 import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_DATA_VNFS_VNF;
27 import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_TOPOLOGY_OPERATION;
28 import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_TOPOLOGY_OPERATION_CACHE;
29 import static org.onap.so.sdncsimulator.utils.Constants.VNF_DATA_VNF_TOPOLOGY;
30 import static org.onap.so.sdncsimulator.utils.Constants.YES;
31 import static org.onap.so.sdncsimulator.utils.ObjectUtils.getString;
32 import static org.onap.so.sdncsimulator.utils.ObjectUtils.getStringOrNull;
33 import static org.onap.so.sdncsimulator.utils.ObjectUtils.isValid;
34 import java.time.LocalDateTime;
35 import java.util.ArrayList;
36 import java.util.List;
37 import java.util.Optional;
38 import javax.validation.Valid;
39 import org.onap.sdnc.northbound.client.model.GenericResourceApiInstanceReference;
40 import org.onap.sdnc.northbound.client.model.GenericResourceApiLastActionEnumeration;
41 import org.onap.sdnc.northbound.client.model.GenericResourceApiLastRpcActionEnumeration;
42 import org.onap.sdnc.northbound.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation;
43 import org.onap.sdnc.northbound.client.model.GenericResourceApiOperStatusData;
44 import org.onap.sdnc.northbound.client.model.GenericResourceApiOrderStatusEnumeration;
45 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestinformationRequestInformation;
46 import org.onap.sdnc.northbound.client.model.GenericResourceApiRpcActionEnumeration;
47 import org.onap.sdnc.northbound.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader;
48 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
49 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServiceData;
50 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfs;
51 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnf;
52 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnfVnfData;
53 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceinformationServiceInformation;
54 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicemodelinfrastructureService;
55 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicestatusServiceStatus;
56 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicetopologyServiceTopology;
57 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier;
58 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
59 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfinformationVnfInformation;
60 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfrequestinputVnfRequestInput;
61 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyVnfTopology;
62 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure;
63 import org.onap.so.sdncsimulator.models.Output;
64 import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider;
65 import org.slf4j.Logger;
66 import org.slf4j.LoggerFactory;
67 import org.springframework.beans.factory.annotation.Autowired;
68 import org.springframework.cache.Cache;
69 import org.springframework.cache.CacheManager;
70 import org.springframework.http.HttpStatus;
71 import org.springframework.stereotype.Service;
72
73 /**
74  * @author Waqas Ikram (waqas.ikram@est.tech)
75  *
76  */
77 @Service
78 public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServiceProvider
79         implements ServiceOperationsCacheServiceProvider {
80
81     private static final String EMPTY_STRING = "";
82     private static final Logger LOGGER = LoggerFactory.getLogger(ServiceOperationsCacheServiceProviderimpl.class);
83
84     @Autowired
85     public ServiceOperationsCacheServiceProviderimpl(final CacheManager cacheManager) {
86         super(cacheManager);
87     }
88
89     @Override
90     public Output putServiceOperationInformation(final GenericResourceApiServiceOperationInformation input) {
91
92         final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
93         final String svcRequestId = getSvcRequestId(requestHeader);
94
95         final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
96         if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId())) {
97             final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
98             final String serviceInstanceId = serviceInformation.getServiceInstanceId();
99             LOGGER.info("Adding GenericResourceApiServiceOperationInformation to cache with key: {}",
100                     serviceInstanceId);
101
102             final GenericResourceApiServicemodelinfrastructureService service =
103                     getServiceItem(input, serviceInstanceId);
104             cache.put(serviceInstanceId, service);
105
106             final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus();
107
108             return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator())
109                     .responseCode(serviceStatus.getResponseCode()).responseMessage(serviceStatus.getResponseMessage())
110                     .svcRequestId(svcRequestId).serviceResponseInformation(new GenericResourceApiInstanceReference()
111                             .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId)));
112
113         }
114         LOGGER.error(
115                 "Unable to add GenericResourceApiServiceOperationInformation in cache due to invalid input: {}... ",
116                 input);
117         return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString())
118                 .responseMessage("Service instance not found").svcRequestId(svcRequestId);
119     }
120
121     @Override
122     public Output deleteServiceOperationInformation(final GenericResourceApiServiceOperationInformation input) {
123         final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
124         final String svcRequestId = getSvcRequestId(input.getSdncRequestHeader());
125
126         if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId())) {
127             final String serviceInstanceId = serviceInformation.getServiceInstanceId();
128             final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
129                     getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
130             if (optional.isPresent()) {
131                 final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
132                 LOGGER.info("Deleting GenericResourceApiServiceOperationInformation from cache using key: {}",
133                         serviceInstanceId);
134                 cache.evict(serviceInstanceId);
135                 return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.OK.toString())
136                         .responseMessage(EMPTY_STRING).svcRequestId(svcRequestId).serviceResponseInformation(
137                                 new GenericResourceApiInstanceReference().instanceId(serviceInstanceId));
138             }
139             LOGGER.error(
140                     "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
141                     serviceInstanceId);
142
143         }
144         LOGGER.error("Unable to remove service instance from cache due to invalid input: {}... ", input);
145         return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString())
146                 .responseMessage("Unable to remove service").svcRequestId(svcRequestId);
147     }
148
149     @Override
150     public Optional<GenericResourceApiServicemodelinfrastructureService> getGenericResourceApiServicemodelinfrastructureService(
151             final String serviceInstanceId) {
152         final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
153
154         final GenericResourceApiServicemodelinfrastructureService value =
155                 cache.get(serviceInstanceId, GenericResourceApiServicemodelinfrastructureService.class);
156         if (value != null) {
157             LOGGER.info("Found {} in cahce for service instance id: {}", value, serviceInstanceId);
158             return Optional.of(value);
159         }
160         LOGGER.error("Unable to find GenericResourceApiServiceModelInfrastructure in cache for service instance id: {}",
161                 serviceInstanceId);
162         return Optional.empty();
163     }
164
165     @Override
166     public Output putVnfOperationInformation(final GenericResourceApiVnfOperationInformation input) {
167
168         final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
169         final GenericResourceApiVnfinformationVnfInformation vnfInformation = input.getVnfInformation();
170
171         final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
172         final String svcRequestId = getSvcRequestId(requestHeader);
173
174         if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null
175                 && isValid(vnfInformation.getVnfId())) {
176             final String serviceInstanceId = serviceInformation.getServiceInstanceId();
177             final String vnfId = vnfInformation.getVnfId();
178             final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
179                     getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
180             if (optional.isPresent()) {
181                 final GenericResourceApiServicemodelinfrastructureService service = optional.get();
182                 final GenericResourceApiServicedataServiceData serviceData = service.getServiceData();
183                 if (serviceData != null) {
184                     final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = getVnfs(serviceData);
185                     final GenericResourceApiLastRpcActionEnumeration svcAction =
186                             GenericResourceApiLastRpcActionEnumeration.fromValue(getSvcAction(requestHeader));
187
188                     if (ifVnfNotExists(vnfId, svcAction, vnfsList)) {
189                         vnfsList.add(getGenericResourceApiServicedataVnf(serviceInstanceId, vnfId, input));
190
191                         final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus();
192
193                         return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator())
194                                 .responseCode(serviceStatus.getResponseCode())
195                                 .responseMessage(serviceStatus.getResponseMessage()).svcRequestId(svcRequestId)
196                                 .serviceResponseInformation(new GenericResourceApiInstanceReference()
197                                         .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId)))
198                                 .vnfResponseInformation(new GenericResourceApiInstanceReference().instanceId(vnfId)
199                                         .objectPath(getObjectPath(serviceInstanceId, vnfId)));
200                     }
201                     LOGGER.error("vnfId: {} already exists with SVC Action: {}", vnfId, svcAction);
202                     return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString())
203                             .responseMessage("vnfId: " + vnfId + " already exists").svcRequestId(svcRequestId);
204                 }
205             }
206             LOGGER.error(
207                     "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
208                     serviceInstanceId);
209
210         }
211         LOGGER.error(
212                 "Unable to add GenericResourceApiServiceOperationInformation in cache due to invalid input: {}... ",
213                 input);
214         return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString())
215                 .responseMessage("Unable to add vnf").svcRequestId(svcRequestId);
216     }
217
218     @Override
219     public Output deleteVnfOperationInformation(final GenericResourceApiVnfOperationInformation input) {
220         final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
221         final GenericResourceApiVnfinformationVnfInformation vnfInformation = input.getVnfInformation();
222
223         final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
224         final String svcRequestId = getSvcRequestId(requestHeader);
225
226         if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null
227                 && isValid(vnfInformation.getVnfId())) {
228             final String serviceInstanceId = serviceInformation.getServiceInstanceId();
229             final String vnfId = vnfInformation.getVnfId();
230             final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
231                     getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
232             if (optional.isPresent()) {
233                 final GenericResourceApiServicemodelinfrastructureService service = optional.get();
234                 final GenericResourceApiServicedataServiceData serviceData = service.getServiceData();
235                 if (serviceData != null) {
236                     final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = getVnfs(serviceData);
237                     final Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfInstanceOptional =
238                             getExistingVnf(vnfId, vnfsList);
239
240                     if (vnfInstanceOptional.isPresent()) {
241                         vnfsList.removeIf(vnf -> {
242                             final String existingVnfId = vnf.getVnfId();
243                             if (existingVnfId != null && existingVnfId.equals(vnfId)) {
244                                 LOGGER.info("Remove vnf with id: {} ... ", existingVnfId);
245                                 return true;
246                             }
247                             return false;
248                         });
249
250                         return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.OK.toString())
251                                 .responseMessage(EMPTY_STRING).svcRequestId(svcRequestId)
252                                 .serviceResponseInformation(
253                                         new GenericResourceApiInstanceReference().instanceId(serviceInstanceId))
254                                 .vnfResponseInformation(new GenericResourceApiInstanceReference().instanceId(vnfId));
255                     }
256
257                 }
258             }
259             LOGGER.error(
260                     "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
261                     serviceInstanceId);
262
263         }
264         LOGGER.error("Unable to remove vnf instance from cache due to invalid input: {}... ", input);
265         return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString())
266                 .responseMessage("Unable to remove vnf").svcRequestId(svcRequestId);
267
268     }
269
270     private String getSvcRequestId(final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader) {
271         return requestHeader != null ? requestHeader.getSvcRequestId() : null;
272     }
273
274     @Override
275     public void clearAll() {
276         clearCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
277     }
278
279     private String getObjectPath(final String serviceInstanceId, final String vnfId) {
280         return getObjectPath(serviceInstanceId) + SERVICE_DATA_VNFS_VNF + vnfId + VNF_DATA_VNF_TOPOLOGY;
281     }
282
283     private String getObjectPath(final String serviceInstanceId) {
284         return RESTCONF_CONFIG_END_POINT + serviceInstanceId;
285     }
286
287
288     private boolean ifVnfNotExists(final String vnfId, final GenericResourceApiLastRpcActionEnumeration svcAction,
289             final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList) {
290         final Optional<GenericResourceApiServicedataServicedataVnfsVnf> optional = getExistingVnf(vnfId, vnfsList);
291         if (optional.isPresent()) {
292             final GenericResourceApiServicedataServicedataVnfsVnf existingVnf = optional.get();
293             final GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = existingVnf.getVnfData();
294
295             if (vnfData != null && vnfData.getVnfLevelOperStatus() != null
296                     && vnfData.getVnfLevelOperStatus().getLastRpcAction() != null) {
297                 final GenericResourceApiLastRpcActionEnumeration existingVnflastRpcAction =
298                         vnfData.getVnfLevelOperStatus().getLastRpcAction();
299                 if (existingVnflastRpcAction.equals(svcAction)) {
300                     LOGGER.error("Found vnf with id: {} and LastRpcAction: {} same as SvcAction:  {}", vnfId,
301                             existingVnflastRpcAction, svcAction);
302                     return false;
303                 }
304                 LOGGER.warn("Will remove and replace existing vnf with id: {} as SvcAction is changed from {} to {}",
305                         vnfId, existingVnflastRpcAction, svcAction);
306                 vnfsList.removeIf(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId));
307
308             }
309         }
310
311         return true;
312     }
313
314     private Optional<GenericResourceApiServicedataServicedataVnfsVnf> getExistingVnf(final String vnfId,
315             final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList) {
316         return vnfsList.stream().filter(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId)).findFirst();
317     }
318
319     private List<GenericResourceApiServicedataServicedataVnfsVnf> getVnfs(
320             final GenericResourceApiServicedataServiceData serviceData) {
321         GenericResourceApiServicedataServicedataVnfs vnfs = serviceData.getVnfs();
322         if (vnfs == null) {
323             vnfs = new GenericResourceApiServicedataServicedataVnfs();
324             serviceData.setVnfs(vnfs);
325         }
326
327         List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = vnfs.getVnf();
328         if (vnfsList == null) {
329             vnfsList = new ArrayList<>();
330             vnfs.setVnf(vnfsList);
331         }
332         return vnfsList;
333     }
334
335     private GenericResourceApiServicedataServicedataVnfsVnf getGenericResourceApiServicedataVnf(
336             final String serviceInstanceId, final String vnfId, final GenericResourceApiVnfOperationInformation input) {
337         return new GenericResourceApiServicedataServicedataVnfsVnf().vnfId(vnfId).vnfData(getVnfData(input));
338     }
339
340     private GenericResourceApiServicedataServicedataVnfsVnfVnfData getVnfData(
341             final GenericResourceApiVnfOperationInformation input) {
342
343         final GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData =
344                 new GenericResourceApiServicedataServicedataVnfsVnfVnfData();
345
346         vnfData.vnfLevelOperStatus(
347                 getServiceLevelOperStatus(PENDINGCREATE, input.getRequestInformation(), input.getSdncRequestHeader()));
348         vnfData.serviceInformation(input.getServiceInformation());
349         vnfData.sdncRequestHeader(input.getSdncRequestHeader());
350         vnfData.vnfInformation(input.getVnfInformation());
351         vnfData.requestInformation(input.getRequestInformation());
352         vnfData.vnfRequestInput(input.getVnfRequestInput());
353
354         vnfData.vnfTopology(getVnfTopology(input.getVnfInformation(), input.getVnfRequestInput()));
355
356         return vnfData;
357     }
358
359     private GenericResourceApiVnftopologyVnfTopology getVnfTopology(
360             final GenericResourceApiVnfinformationVnfInformation vnfInformation,
361             final GenericResourceApiVnfrequestinputVnfRequestInput vnfRequestInput) {
362
363         final GenericResourceApiVnftopologyVnfTopology apiVnftopologyVnfTopology =
364                 new GenericResourceApiVnftopologyVnfTopology();
365
366         if (vnfInformation != null) {
367             apiVnftopologyVnfTopology.onapModelInformation(vnfInformation.getOnapModelInformation());
368             apiVnftopologyVnfTopology.vnfTopologyIdentifierStructure(getTopologyIdentifierStructure(vnfInformation));
369         }
370         if (vnfRequestInput != null) {
371             apiVnftopologyVnfTopology.tenant(vnfRequestInput.getTenant());
372             apiVnftopologyVnfTopology.aicClli(vnfRequestInput.getAicClli());
373             apiVnftopologyVnfTopology.aicCloudRegion(vnfRequestInput.getAicCloudRegion());
374         }
375         return apiVnftopologyVnfTopology;
376     }
377
378     private GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure getTopologyIdentifierStructure(
379             @Valid final GenericResourceApiVnfinformationVnfInformation vnfInformation) {
380         return new GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure()
381                 .vnfId(vnfInformation.getVnfId()).vnfName(vnfInformation.getVnfName())
382                 .vnfType(vnfInformation.getVnfType());
383     }
384
385     private GenericResourceApiServicemodelinfrastructureService getServiceItem(
386             final GenericResourceApiServiceOperationInformation input, final String serviceInstanceId) {
387
388         final GenericResourceApiServicedataServiceData apiServicedataServiceData =
389                 new GenericResourceApiServicedataServiceData();
390
391         apiServicedataServiceData.requestInformation(input.getRequestInformation());
392         apiServicedataServiceData.serviceRequestInput(input.getServiceRequestInput());
393         apiServicedataServiceData.serviceInformation(input.getServiceInformation());
394         apiServicedataServiceData.serviceTopology(getServiceTopology(input));
395         apiServicedataServiceData.sdncRequestHeader(input.getSdncRequestHeader());
396         apiServicedataServiceData.serviceLevelOperStatus(getServiceLevelOperStatus(input));
397
398         final GenericResourceApiServicestatusServiceStatus serviceStatus =
399                 getServiceStatus(getSvcAction(input.getSdncRequestHeader()),
400                         getRequestAction(input.getRequestInformation()), HttpStatus.OK.toString());
401
402         return new GenericResourceApiServicemodelinfrastructureService().serviceData(apiServicedataServiceData)
403                 .serviceStatus(serviceStatus).serviceInstanceId(serviceInstanceId);
404     }
405
406     private String getSvcAction(final GenericResourceApiSdncrequestheaderSdncRequestHeader input) {
407         return input != null ? getStringOrNull(input.getSvcAction()) : null;
408     }
409
410     private GenericResourceApiServicestatusServiceStatus getServiceStatus(final String rpcAction, final String action,
411             final String responseCode) {
412         return new GenericResourceApiServicestatusServiceStatus().finalIndicator(YES)
413                 .rpcAction(GenericResourceApiRpcActionEnumeration.fromValue(rpcAction))
414                 .rpcName(SERVICE_TOPOLOGY_OPERATION).responseTimestamp(LocalDateTime.now().toString())
415                 .responseCode(responseCode).requestStatus(SYNCCOMPLETE).responseMessage(EMPTY_STRING).action(action);
416     }
417
418     private GenericResourceApiOperStatusData getServiceLevelOperStatus(
419             final GenericResourceApiServiceOperationInformation input) {
420         return getServiceLevelOperStatus(CREATED, input.getRequestInformation(), input.getSdncRequestHeader());
421     }
422
423     private GenericResourceApiOperStatusData getServiceLevelOperStatus(
424             final GenericResourceApiOrderStatusEnumeration statusEnumeration,
425             final GenericResourceApiRequestinformationRequestInformation requestInformation,
426             final GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader) {
427         return new GenericResourceApiOperStatusData().orderStatus(statusEnumeration)
428                 .lastAction(GenericResourceApiLastActionEnumeration.fromValue(getRequestAction(requestInformation)))
429                 .lastRpcAction(GenericResourceApiLastRpcActionEnumeration.fromValue(getSvcAction(sdncRequestHeader)));
430     }
431
432     private String getRequestAction(final GenericResourceApiRequestinformationRequestInformation input) {
433         return getRequestAction(input, EMPTY_STRING);
434     }
435
436     private String getRequestAction(final GenericResourceApiRequestinformationRequestInformation input,
437             final String defaultValue) {
438         return input != null ? getString(input.getRequestAction(), defaultValue) : defaultValue;
439     }
440
441     private GenericResourceApiServicetopologyServiceTopology getServiceTopology(
442             final GenericResourceApiServiceOperationInformation input) {
443         final GenericResourceApiOnapmodelinformationOnapModelInformation modelInformation =
444                 input.getServiceInformation() != null ? input.getServiceInformation().getOnapModelInformation() : null;
445         return new GenericResourceApiServicetopologyServiceTopology().onapModelInformation(modelInformation)
446                 .serviceTopologyIdentifier(getServiceTopologyIdentifier(input));
447     }
448
449     private GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier getServiceTopologyIdentifier(
450             final GenericResourceApiServiceOperationInformation input) {
451         final GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier identifier =
452                 new GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier();
453
454         if (input.getServiceInformation() != null) {
455             final GenericResourceApiServiceinformationServiceInformation serviceInformation =
456                     input.getServiceInformation();
457             identifier.globalCustomerId(serviceInformation.getGlobalCustomerId())
458                     .serviceType(input.getServiceInformation().getSubscriptionServiceType())
459                     .serviceInstanceId(input.getServiceInformation().getServiceInstanceId());;
460         }
461
462         if (input.getServiceRequestInput() != null) {
463             identifier.serviceInstanceName(input.getServiceRequestInput().getServiceInstanceName());
464         }
465
466         return identifier;
467
468     }
469
470 }