7508eb89ce84b25ea89dd9f1ed9e0b9419fc8fbd
[sdnc/apps.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SDNC
4  * ================================================================================
5  * Copyright (C) 2020 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.sdnc.apps.ms.gra.controllers;
22
23 import java.util.ArrayList;
24 import java.util.Iterator;
25 import java.util.LinkedList;
26 import java.util.List;
27 import java.util.Optional;
28
29 import javax.servlet.http.HttpServletRequest;
30 import javax.validation.Valid;
31
32 import com.fasterxml.jackson.annotation.JsonInclude;
33 import com.fasterxml.jackson.core.JsonProcessingException;
34 import com.fasterxml.jackson.databind.ObjectMapper;
35
36 import org.onap.ccsdk.apps.services.RestApplicationException;
37 import org.onap.ccsdk.apps.services.RestException;
38 import org.onap.ccsdk.apps.services.RestProtocolException;
39 import org.onap.sdnc.apps.ms.gra.controllers.ServiceDataHelper.ServiceDataTransaction;
40 import org.onap.sdnc.apps.ms.gra.data.ConfigContrailRouteAllottedResources;
41 import org.onap.sdnc.apps.ms.gra.data.ConfigContrailRouteAllottedResourcesRepository;
42 import org.onap.sdnc.apps.ms.gra.data.ConfigNetworksRepository;
43 import org.onap.sdnc.apps.ms.gra.data.ConfigPortMirrorConfigurations;
44 import org.onap.sdnc.apps.ms.gra.data.ConfigPortMirrorConfigurationsRepository;
45 import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadData;
46 import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadDataRepository;
47 import org.onap.sdnc.apps.ms.gra.data.ConfigServices;
48 import org.onap.sdnc.apps.ms.gra.data.ConfigServicesRepository;
49 import org.onap.sdnc.apps.ms.gra.data.ConfigVfModules;
50 import org.onap.sdnc.apps.ms.gra.data.ConfigVfModulesRepository;
51 import org.onap.sdnc.apps.ms.gra.data.ConfigVnfsRepository;
52 import org.onap.sdnc.apps.ms.gra.swagger.ConfigApi;
53 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource;
54 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiContrailrouteallottedresourcesContrailrouteallottedresourceAllottedResourceData;
55 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiContrailroutetopologyContrailRouteTopology;
56 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiOnapmodelinformationOnapModelInformation;
57 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiOperStatusData;
58 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration;
59 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPortmirrorconfigurationsPortmirrorconfigurationConfigurationData;
60 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPortmirrorconfigurationtopologyPortMirrorConfigurationTopology;
61 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPreloadModelInformation;
62 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPreloaddataPreloadData;
63 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPreloadmodelinformationPreloadList;
64 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPreloadnetworktopologyinformationPreloadNetworkTopologyInformation;
65 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServiceModelInfrastructure;
66 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServiceData;
67 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServicedataVnfsVnf;
68 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServicedataVnfsVnfVnfData;
69 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule;
70 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicemodelinfrastructureService;
71 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicestatusServiceStatus;
72 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicetopologyServiceTopology;
73 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVfmoduletopologyVfModuleTopology;
74 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVnfNetworkData;
75 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVnfresourceassignmentsVnfResourceAssignments;
76 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks;
77 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVnftopologyVnfTopology;
78 import org.slf4j.Logger;
79 import org.slf4j.LoggerFactory;
80 import org.springframework.beans.factory.annotation.Autowired;
81 import org.springframework.boot.autoconfigure.domain.EntityScan;
82 import org.springframework.context.annotation.ComponentScan;
83 import org.springframework.http.HttpStatus;
84 import org.springframework.http.ResponseEntity;
85 import org.springframework.stereotype.Controller;
86
87 @Controller
88 @ComponentScan(basePackages = { "org.onap.sdnc.apps.ms.gra.*" })
89 @EntityScan("org.onap.sdnc.apps.ms.gra.springboot.*")
90 public class ConfigApiController implements ConfigApi {
91     private static final Logger log = LoggerFactory.getLogger(ConfigApiController.class);
92
93     private final ObjectMapper objectMapper;
94
95     private final HttpServletRequest request;
96
97     @Autowired
98     private ConfigPreloadDataRepository configPreloadDataRepository;
99
100     @Autowired
101     private ConfigServicesRepository configServicesRepository;
102
103     @Autowired
104     private ConfigNetworksRepository configNetworksRepository;
105     
106     @Autowired
107     private ConfigVnfsRepository configVnfsRepository;
108
109     @Autowired
110     private ConfigVfModulesRepository configVfModulesRepository;
111     
112     @Autowired
113     private ConfigPortMirrorConfigurationsRepository configPortMirrorConfigurationsRepository;
114
115     @Autowired
116     private ConfigContrailRouteAllottedResourcesRepository configContrailRouteAllottedResourcesRepository;
117     
118     @Autowired
119     private ServiceDataHelper serviceDataHelper;
120
121     @Autowired
122     public ConfigApiController(ObjectMapper objectMapper, HttpServletRequest request) {
123         objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
124         objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
125         this.objectMapper = objectMapper;
126         this.request = request;
127     }
128
129     @Override
130     public Optional<ObjectMapper> getObjectMapper() {
131         return Optional.ofNullable(objectMapper);
132     }
133
134     @Override
135     public Optional<HttpServletRequest> getRequest() {
136         return Optional.ofNullable(request);
137     }
138
139     @Override
140     public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationDelete() {
141         configPreloadDataRepository.deleteAll();
142         return (new ResponseEntity<>(HttpStatus.NO_CONTENT));
143     }
144
145     /**
146      * Extracts port-mirror configuration data from CONFIG_GRA_PORT_MIRROR_CONFIGURATIONS for a given, configuration-id
147      * <p>
148      * Maps to /config/GENERIC-RESOURCE-API:port-mirror-configurations/port-mirror-configuration/{configuration-id}/
149      * @param configurationId the configuration ID for a port-mirror
150      * @return HttpStatus.OK (200) if the data is found.
151      * @throws RestException if the data does not exist.
152      */
153     public ResponseEntity<GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration>
154                 configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdGet(
155                     String configurationId) throws RestApplicationException {
156         GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration retval = null;
157
158         List<ConfigPortMirrorConfigurations> pmConfigurations = configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
159
160         if (pmConfigurations.isEmpty()) {
161             log.info("No configuration data found with id [{}]",configurationId);
162             throw new RestApplicationException("data-missing",
163                     "Request could not be completed because the relevant data model content does not exist",
164                     HttpStatus.NOT_FOUND.value());
165         } else {
166             ConfigPortMirrorConfigurations pmConfiguration = pmConfigurations.get(0);
167             retval = new GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration();
168             retval.setConfigurationId(configurationId);
169             retval.setConfigurationStatus(pmConfiguration.getPortMirrorConfigurationStatus());
170             try {
171                 retval.setConfigurationData(objectMapper.readValue(pmConfiguration.getPmcData(), GenericResourceApiPortmirrorconfigurationsPortmirrorconfigurationConfigurationData.class));
172             } catch (JsonProcessingException e) {
173                 log.error("Could not deserialize service data for service instance id {}", configurationId, e);
174                 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
175             }
176         }
177         return new ResponseEntity<>(retval, HttpStatus.OK);
178     }
179
180     @Override
181     public ResponseEntity<Void> configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdPut(
182             String configurationId, @Valid GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration newConfiguration)
183                 throws RestApplicationException {
184
185         boolean dataExists = false;
186
187         String newConfigurationId = newConfiguration.getConfigurationId();
188
189         ConfigPortMirrorConfigurations portMirrorConfiguration = null;
190         List<ConfigPortMirrorConfigurations> existingConfiguration = configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
191         if ((existingConfiguration != null) && !existingConfiguration.isEmpty()) {
192             dataExists = true;
193             portMirrorConfiguration = existingConfiguration.get(0);
194         } else {
195             portMirrorConfiguration = new ConfigPortMirrorConfigurations();
196             portMirrorConfiguration.setConfigureationId(configurationId);
197         }
198
199         try {
200             portMirrorConfiguration.setPmcData(objectMapper.writeValueAsString(newConfiguration.getConfigurationData()));
201         } catch (JsonProcessingException e) {
202             log.error("Could not serialize porr-mirror configuration data for {}", portMirrorConfiguration.getConfigureationId(), e);
203             throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
204
205         }
206         portMirrorConfiguration.setPortMirrorConfigurationStatus(newConfiguration.getConfigurationStatus());
207         configPortMirrorConfigurationsRepository.save(portMirrorConfiguration);
208
209         if (dataExists) {
210             return new ResponseEntity<>(HttpStatus.NO_CONTENT);
211         } else {
212             return new ResponseEntity<>(HttpStatus.CREATED);
213         }
214     }
215
216     @Override
217     public ResponseEntity<GenericResourceApiPortmirrorconfigurationtopologyPortMirrorConfigurationTopology>
218             configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdConfigurationDataPortMirrorConfigurationTopologyGet(
219                     String configurationId) throws RestApplicationException, RestProtocolException {
220         @Valid GenericResourceApiPortmirrorconfigurationtopologyPortMirrorConfigurationTopology portMirrorConfigurationTopology = null;
221         GenericResourceApiPortmirrorconfigurationsPortmirrorconfigurationConfigurationData portMirrorConfigurationData = null;
222
223         List<ConfigPortMirrorConfigurations> configPortMirrorConfigurations = configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
224         if ((configPortMirrorConfigurations == null) || (configPortMirrorConfigurations.isEmpty())) {
225             log.info("No configuration data found with id [{}]", configurationId);
226             throw new RestApplicationException("data-missing",
227                     "Request could not be completed because the relevant data model content does not exist",
228                     HttpStatus.NOT_FOUND.value());
229         }
230
231         try {
232             if ( configPortMirrorConfigurations.get(0).getPmcData().isEmpty()) {
233                 throw new RestProtocolException("data-missing", "No configuration-data entry found", HttpStatus.NOT_FOUND.value());
234             } else {
235                 portMirrorConfigurationData = objectMapper.readValue(configPortMirrorConfigurations.get(0).getPmcData(), GenericResourceApiPortmirrorconfigurationsPortmirrorconfigurationConfigurationData.class);
236                 portMirrorConfigurationTopology = portMirrorConfigurationData.getPortMirrorConfigurationTopology();
237             }
238             if (portMirrorConfigurationTopology == null) {
239                 throw new RestProtocolException("data-missing", "No service-topology entry found", HttpStatus.NOT_FOUND.value());
240             }
241             return new ResponseEntity<>(portMirrorConfigurationTopology, HttpStatus.OK);
242         } catch (JsonProcessingException e) {
243             log.error("Could not parse service data", e);
244             throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
245         }
246     }
247
248
249     @Override
250     public ResponseEntity<Void> configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdDelete(String configurationId) {
251         configPortMirrorConfigurationsRepository.deleteByConfigurationId(configurationId);
252         return new ResponseEntity<>(HttpStatus.NO_CONTENT);
253     }
254
255     /**
256      * Extracts contrail-route-allotted-resource data from CONFIG_GRA_CONTRAIL_ROUTE_ALLOTTED_RESOURCES for a given allottedResourceId
257      * <p>
258      * Maps to /config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/contrail-route-allotted-resource/{allotted-resource-id}
259      * @param allottedResourceId the allotted-resource-id for a contrail-route
260      * @return HttpStatus.OK (200) if the data is found.
261      * @throws RestException if the data does not exist.
262      */
263     public ResponseEntity<GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource>
264                 configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdGet(
265                         String allottedResourceId) throws RestApplicationException {
266         GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource retval = null;
267
268         List<ConfigContrailRouteAllottedResources> allottedResources = configContrailRouteAllottedResourcesRepository.findByAllottedResourceId(allottedResourceId);
269
270         if (allottedResources.isEmpty()) {
271             log.info("No contrail-route-allotted-resource found with id [{}]", allottedResourceId);
272             throw new RestApplicationException("data-missing",
273                     "Request could not be completed because the relevant data model content does not exist",
274                     HttpStatus.NOT_FOUND.value());
275         }
276         else {
277             ConfigContrailRouteAllottedResources allottedResource = allottedResources.get(0);
278             retval = new GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource();
279             retval.setAllottedResourceId(allottedResourceId);
280             retval.setAllottedResourceStatus(allottedResource.getAllottedResourceStatus());
281             try {
282                 retval.setAllottedResourceData(objectMapper.readValue(allottedResource.getArData(),
283                         GenericResourceApiContrailrouteallottedresourcesContrailrouteallottedresourceAllottedResourceData.class));
284             } catch (JsonProcessingException e) {
285                 log.error("Could not deserialize service data for service instance id {}", allottedResourceId, e);
286                 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
287             }
288         }
289         return new ResponseEntity<>(retval, HttpStatus.OK);
290     }
291
292     /**
293      * PUT contrail-route-allotted-resource data from CONFIG_GRA_CONTRAIL_ROUTE_ALLOTTED_RESOURCES for a given allottedResourceId
294      * <p>
295      * Maps to /config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/contrail-route-allotted-resource/{allotted-resource-id}
296      * @param allottedResourceId the allotted-resource-id for a contrail-route
297      * @return HttpStatus.OK (200) if the data is found.
298      * @throws RestException if the data does not exist.
299      */
300     @Override
301     public ResponseEntity<Void> configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdPut(
302             String allottedResourceId, @Valid GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource newAllottedResource)
303             throws RestApplicationException {
304
305         boolean dataExists = false;
306
307         String newAllottedResourceId = newAllottedResource.getAllottedResourceId();
308
309         ConfigContrailRouteAllottedResources allottedResource = null;
310         List<ConfigContrailRouteAllottedResources> existingAllottedResource =
311                 configContrailRouteAllottedResourcesRepository.findByAllottedResourceId(allottedResourceId);
312
313         if ((existingAllottedResource != null) && !existingAllottedResource.isEmpty()) {
314             dataExists = true;
315             allottedResource = existingAllottedResource.get(0);
316         } else {
317             allottedResource = new ConfigContrailRouteAllottedResources();
318             allottedResource.setAllottedResourceId(allottedResourceId);
319         }
320
321         try {
322             allottedResource.setArData(objectMapper.writeValueAsString(newAllottedResource.getAllottedResourceData()));
323         } catch (JsonProcessingException e) {
324             log.error("Could not serialize porr-mirror configuration data for {}", allottedResource.getAllottedResourceId(), e);
325             throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
326
327         }
328         allottedResource.setAllottedResourceStatus(newAllottedResource.getAllottedResourceStatus());
329         configContrailRouteAllottedResourcesRepository.save(allottedResource);
330
331         if (dataExists) {
332             return new ResponseEntity<>(HttpStatus.NO_CONTENT);
333         } else {
334             return new ResponseEntity<>(HttpStatus.CREATED);
335         }
336     }
337
338     /**
339      * Extracts contrail-route-topology data from CONFIG_GRA_CONTRAIL_ROUTE_ALLOTTED_RESOURCES for a given allottedResourceId
340      * <p>
341      * Maps to /config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/contrail-route-allotted-resource/{allotted-resource-id}/allotted-resource-data/contrail-route-topology/
342      * @param allottedResourceId the allotted-resource-id for a contrail-route
343      * @return HttpStatus.OK (200) if the data is found.
344      * @throws RestException if the data does not exist.
345      */
346     @Override
347     public ResponseEntity<GenericResourceApiContrailroutetopologyContrailRouteTopology>
348             configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdAllottedResourceDataContrailRouteTopologyGet(
349                 String allottedResourceId) throws RestApplicationException, RestProtocolException {
350         @Valid GenericResourceApiContrailroutetopologyContrailRouteTopology contrailRouteTopology = null;
351         GenericResourceApiContrailrouteallottedresourcesContrailrouteallottedresourceAllottedResourceData allottedResourceData = null;
352
353         List<ConfigContrailRouteAllottedResources> configContrailRouteAllottedResources =
354                 configContrailRouteAllottedResourcesRepository.findByAllottedResourceId(allottedResourceId);
355
356         if ((configContrailRouteAllottedResources == null) || (configContrailRouteAllottedResources.isEmpty())) {
357             log.info("No contrail-route-allotted-resoure data found with id [{}]", allottedResourceId);
358             throw new RestApplicationException("data-missing",
359                     "Request could not be completed because the relevant data model content does not exist",
360                     HttpStatus.NOT_FOUND.value());
361         }
362
363         try {
364             if ( configContrailRouteAllottedResources.get(0).getArData().isEmpty()) {
365                 throw new RestProtocolException("data-missing", "No allotted-resource-data entry found", HttpStatus.NOT_FOUND.value());
366             } else {
367                 allottedResourceData = objectMapper.readValue(configContrailRouteAllottedResources.get(0).getArData(),
368                         GenericResourceApiContrailrouteallottedresourcesContrailrouteallottedresourceAllottedResourceData.class);
369
370                 contrailRouteTopology = allottedResourceData.getContrailRouteTopology();
371             }
372             if (contrailRouteTopology == null) {
373                 throw new RestProtocolException("data-missing", "No contrail-route-topology entry found", HttpStatus.NOT_FOUND.value());
374             }
375             return new ResponseEntity<>(contrailRouteTopology, HttpStatus.OK);
376         } catch (JsonProcessingException e) {
377             log.error("Could not parse port-mirror-configuration data", e);
378             throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
379         }
380     }
381
382
383     /**
384      * DELETE allotted-resource data from CONFIG_GRA_CONTRAIL_ROUTE_ALLOTTED_RESOURCES for a given allottedResourceId
385      * <p>
386      * Maps to /config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/contrail-route-allotted-resource/{allotted-resource-id}
387      * @param allottedResourceId the allotted-resource-id for a contrail-route
388      * @return HttpStatus.NO_CONTENT (204) if the data is found.
389      */
390     @Override
391     public ResponseEntity<Void> configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdDelete(
392             String allottedResourceId) {
393         configContrailRouteAllottedResourcesRepository.deleteByAllottedResourceId(allottedResourceId);
394         return new ResponseEntity<>(HttpStatus.NO_CONTENT);
395     }
396
397
398     @Override
399     public ResponseEntity<GenericResourceApiPreloadModelInformation> configGENERICRESOURCEAPIpreloadInformationGet()
400             throws RestApplicationException {
401         GenericResourceApiPreloadModelInformation genericResourceApiPreloadModelInformation = new GenericResourceApiPreloadModelInformation();
402
403         if (configPreloadDataRepository.count() == 0) {
404             throw new RestApplicationException("data-missing",
405                     "Request could not be completed because the relevant data model content does not exist",
406                     HttpStatus.NOT_FOUND.value());
407         }
408
409         for (ConfigPreloadData configPreloadData : configPreloadDataRepository.findAll()) {
410             GenericResourceApiPreloadmodelinformationPreloadList preloadListItem = new GenericResourceApiPreloadmodelinformationPreloadList();
411
412             preloadListItem.setPreloadId(configPreloadData.getPreloadId());
413             preloadListItem.setPreloadType(configPreloadData.getPreloadType());
414             try {
415                 preloadListItem.setPreloadData(objectMapper.readValue(configPreloadData.getPreloadData(),
416                         GenericResourceApiPreloaddataPreloadData.class));
417             } catch (JsonProcessingException e) {
418                 log.error("Could not convert preload data", e);
419                 throw new RestApplicationException("data-conversion",
420                         "Request could not be completed due to internal error", e,
421                         HttpStatus.INTERNAL_SERVER_ERROR.value());
422             }
423             genericResourceApiPreloadModelInformation.addPreloadListItem(preloadListItem);
424         }
425
426         return new ResponseEntity<>(genericResourceApiPreloadModelInformation, HttpStatus.OK);
427     }
428
429     @Override
430     public ResponseEntity<GenericResourceApiPreloadnetworktopologyinformationPreloadNetworkTopologyInformation> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataPreloadNetworkTopologyInformationGet(
431             String preloadId, String preloadType) throws RestException {
432         GenericResourceApiPreloadnetworktopologyinformationPreloadNetworkTopologyInformation netTopoInfo = null;
433
434         if (configPreloadDataRepository.count() == 0) {
435             throw new RestApplicationException("data-missing",
436                     "Request could not be completed because the relevant data model content does not exist",
437                     HttpStatus.NOT_FOUND.value());
438         }
439
440         for (ConfigPreloadData configPreloadData : configPreloadDataRepository.findAll()) {
441
442             try {
443                 GenericResourceApiPreloaddataPreloadData preloadDataItem = objectMapper
444                         .readValue(configPreloadData.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class);
445                 netTopoInfo = preloadDataItem.getPreloadNetworkTopologyInformation();
446             } catch (JsonProcessingException e) {
447                 log.error("Could not convert preload data", e);
448                 throw new RestApplicationException("data-conversion",
449                         "Request could not be completed due to internal error", e,
450                         HttpStatus.INTERNAL_SERVER_ERROR.value());
451             }
452         }
453         
454         return new ResponseEntity<>(netTopoInfo, HttpStatus.OK);
455     }
456
457
458     @Override
459     public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPost(
460             @Valid GenericResourceApiPreloadModelInformation graPreloadModelInfo)
461             throws RestApplicationException, RestProtocolException {
462
463         List<GenericResourceApiPreloadmodelinformationPreloadList> preloadList = graPreloadModelInfo.getPreloadList();
464         List<ConfigPreloadData> newPreloadData = new LinkedList<>();
465
466         if (preloadList != null) {
467             // Verification pass - if any items already exist, return an error
468             for (GenericResourceApiPreloadmodelinformationPreloadList curItem : preloadList) {
469
470                 List<ConfigPreloadData> curPreloadData = configPreloadDataRepository
471                         .findByPreloadIdAndPreloadType(curItem.getPreloadId(), curItem.getPreloadType());
472                 if ((curPreloadData != null) && (!curPreloadData.isEmpty())) {
473                     log.error("Preload data already exists for {}:{}", curItem.getPreloadId(),
474                             curItem.getPreloadType());
475                     throw new RestProtocolException("data-exists",
476                             "Data already exists for " + curItem.getPreloadId() + ":" + curItem.getPreloadType(),
477                             HttpStatus.CONFLICT.value());
478                 } else {
479                     try {
480                         newPreloadData.add(new ConfigPreloadData(curItem.getPreloadId(), curItem.getPreloadType(),
481                                 objectMapper.writeValueAsString(curItem.getPreloadData())));
482                     } catch (JsonProcessingException e) {
483                         log.error("Cannot convert preload data");
484                         throw new RestApplicationException("data-conversion",
485                                 "Request could not be completed due to internal error", e,
486                                 HttpStatus.INTERNAL_SERVER_ERROR.value());
487
488                     }
489                 }
490             }
491
492             // Update pass
493             for (ConfigPreloadData newDataItem : newPreloadData) {
494                 log.info("Adding preload data for {}:{}", newDataItem.getPreloadId(), newDataItem.getPreloadType());
495                 configPreloadDataRepository.save(newDataItem);
496             }
497         } else {
498             throw new RestProtocolException("data-missing", "No preload-list entries found to add",
499                     HttpStatus.CONFLICT.value());
500         }
501
502         return new ResponseEntity<>(HttpStatus.CREATED);
503     }
504
505     @Override
506     public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPut(
507             @Valid GenericResourceApiPreloadModelInformation graPreloadModelInfo) throws RestApplicationException {
508
509         boolean addedNew = false;
510         List<GenericResourceApiPreloadmodelinformationPreloadList> preloadList = graPreloadModelInfo.getPreloadList();
511
512         if (preloadList != null) {
513             Iterator<GenericResourceApiPreloadmodelinformationPreloadList> iter = preloadList.iterator();
514             while (iter.hasNext()) {
515                 GenericResourceApiPreloadmodelinformationPreloadList curItem = iter.next();
516                 List<ConfigPreloadData> curPreloadData = configPreloadDataRepository
517                         .findByPreloadIdAndPreloadType(curItem.getPreloadId(), curItem.getPreloadType());
518                 if ((curPreloadData == null) || curPreloadData.isEmpty()) {
519                     addedNew = true;
520                 }
521
522                 try {
523                     configPreloadDataRepository.save(new ConfigPreloadData(curItem.getPreloadId(),
524                             curItem.getPreloadType(), objectMapper.writeValueAsString(curItem.getPreloadData())));
525                 } catch (JsonProcessingException e) {
526                     log.error("Cannot convert preload data", e);
527                     throw new RestApplicationException("data-conversion",
528                             "Request could not be completed due to internal error", e,
529                             HttpStatus.INTERNAL_SERVER_ERROR.value());
530
531                 }
532             }
533         }
534
535         if (addedNew) {
536             return new ResponseEntity<>(HttpStatus.CREATED);
537         } else {
538             return new ResponseEntity<>(HttpStatus.NO_CONTENT);
539         }
540
541     }
542
543     @Override
544     public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPost(
545             @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) throws RestProtocolException {
546
547         throw new RestProtocolException("data-missing", "Missing key for list \"preload-list\"",
548                 HttpStatus.NOT_FOUND.value());
549     }
550
551     @Override
552     public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypeDelete(
553             String preloadId, String preloadType) {
554         configPreloadDataRepository.deleteByPreloadIdAndPreloadType(preloadId, preloadType);
555         return new ResponseEntity<>(HttpStatus.NO_CONTENT);
556     }
557
558     @Override
559     public ResponseEntity<GenericResourceApiPreloadmodelinformationPreloadList> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypeGet(
560             String preloadId, String preloadType) throws RestApplicationException {
561         List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
562                 preloadType);
563         if (preloadData != null) {
564             if (!preloadData.isEmpty()) {
565                 ConfigPreloadData preloadDataItem = preloadData.get(0);
566                 GenericResourceApiPreloadmodelinformationPreloadList preloadDataList = new GenericResourceApiPreloadmodelinformationPreloadList();
567                 preloadDataList.setPreloadId(preloadDataItem.getPreloadId());
568                 preloadDataList.setPreloadType(preloadDataItem.getPreloadType());
569                 try {
570                     preloadDataList.setPreloadData(objectMapper.readValue(preloadDataItem.getPreloadData(),
571                             GenericResourceApiPreloaddataPreloadData.class));
572                 } catch (JsonProcessingException e) {
573                     log.error("Cannot convert preload data", e);
574                     throw new RestApplicationException("data-conversion",
575                             "Request could not be completed due to internal error", e,
576                             HttpStatus.INTERNAL_SERVER_ERROR.value());
577                 }
578                 return new ResponseEntity<>(preloadDataList, HttpStatus.OK);
579             }
580         }
581         return new ResponseEntity<>(HttpStatus.NOT_FOUND);
582     }
583
584     @Override
585     public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePost(
586             String preloadId, String preloadType,
587             @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem)
588             throws RestApplicationException, RestProtocolException {
589         List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
590                 preloadType);
591
592         if ((preloadDataItems != null) && !preloadDataItems.isEmpty()) {
593             log.error("Preload data already exists for {}:{}", preloadId, preloadType);
594             throw new RestProtocolException("data-exists", "Data already exists for " + preloadId + ":" + preloadType,
595                     HttpStatus.CONFLICT.value());
596         }
597
598         try {
599             log.info("Adding preload data for {}:{}", preloadId, preloadType);
600             configPreloadDataRepository.save(new ConfigPreloadData(preloadId, preloadType,
601                     objectMapper.writeValueAsString(preloadListItem.getPreloadData())));
602         } catch (JsonProcessingException e) {
603             log.error("Cannot convert preload data", e);
604             throw new RestApplicationException("data-conversion",
605                     "Request could not be completed due to internal error", e,
606                     HttpStatus.INTERNAL_SERVER_ERROR.value());
607
608         }
609         return new ResponseEntity<>(HttpStatus.CREATED);
610     }
611
612     @Override
613     public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePut(
614             String preloadId, String preloadType,
615             @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem)
616             throws RestApplicationException, RestProtocolException {
617         List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
618                 preloadType);
619         boolean dataExists = false;
620         if ((preloadDataItems != null) && !preloadDataItems.isEmpty()) {
621             dataExists = true;
622         }
623
624         if ((preloadListItem.getPreloadId() == null) || (preloadListItem.getPreloadType() == null)
625                 || (preloadListItem.getPreloadData() == null)) {
626             log.error("Invalid list item received: {}", preloadListItem);
627             throw new RestProtocolException("bad-attribute", "Invalid data received", HttpStatus.BAD_REQUEST.value());
628         }
629
630         try {
631             if (dataExists) {
632                 log.info("Updating preload data for {}:{} -> {}", preloadId, preloadType,
633                         objectMapper.writeValueAsString(preloadListItem));
634
635             } else {
636                 log.info("Adding preload data for {}:{}", preloadId, preloadType);
637             }
638
639             configPreloadDataRepository.save(new ConfigPreloadData(preloadId, preloadType,
640                     objectMapper.writeValueAsString(preloadListItem.getPreloadData())));
641         } catch (JsonProcessingException e) {
642             log.error("Cannot convert preload data", e);
643             throw new RestApplicationException("data-conversion",
644                     "Request could not be completed due to internal error", e,
645                     HttpStatus.INTERNAL_SERVER_ERROR.value());
646
647         }
648
649         if (dataExists) {
650             return new ResponseEntity<>(HttpStatus.NO_CONTENT);
651         } else {
652             return new ResponseEntity<>(HttpStatus.CREATED);
653         }
654     }
655
656     @Override
657     public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataDelete(
658             String preloadId, String preloadType) throws RestProtocolException {
659         List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
660                 preloadType);
661
662         if ((preloadData == null) || preloadData.isEmpty()) {
663             throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
664         }
665
666         ConfigPreloadData preloadDataItem = preloadData.get(0);
667
668         if (preloadDataItem.getPreloadData() == null) {
669             throw new RestProtocolException("data-missing", "No preload-data found", HttpStatus.NOT_FOUND.value());
670         }
671         preloadDataItem.setPreloadData(null);
672         configPreloadDataRepository.save(preloadDataItem);
673
674         return new ResponseEntity<>(HttpStatus.NO_CONTENT);
675     }
676
677     @Override
678     public ResponseEntity<GenericResourceApiPreloaddataPreloadData> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataGet(
679             String preloadId, String preloadType) throws RestApplicationException, RestProtocolException {
680         List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
681                 preloadType);
682
683         if ((preloadData == null) || preloadData.isEmpty()) {
684             throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
685         }
686
687         ConfigPreloadData preloadDataItem = preloadData.get(0);
688
689         if (preloadDataItem.getPreloadData() == null) {
690             throw new RestProtocolException("data-missing", "No preload-data found", HttpStatus.NOT_FOUND.value());
691         }
692         try {
693             return new ResponseEntity<>(objectMapper.readValue(preloadDataItem.getPreloadData(),
694                     GenericResourceApiPreloaddataPreloadData.class), HttpStatus.OK);
695         } catch (JsonProcessingException e) {
696             log.error("Cannot convert preload data", e);
697             throw new RestApplicationException("data-conversion",
698                     "Request could not be completed due to internal error", e,
699                     HttpStatus.INTERNAL_SERVER_ERROR.value());
700         }
701     }
702
703     @Override
704     public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataPost(
705             String preloadId, String preloadType, @Valid GenericResourceApiPreloaddataPreloadData preloadData)
706             throws RestApplicationException, RestProtocolException {
707
708
709         List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
710                 preloadType);
711         if ((preloadDataItems == null) || (preloadDataItems.isEmpty())) {
712             throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
713         }
714
715         if ((preloadData == null) || (preloadData.getPreloadNetworkTopologyInformation() == null)) {
716             throw new RestProtocolException("bad-attribute", "Invalid preloadData received",
717                     HttpStatus.BAD_REQUEST.value());
718         }
719
720         ConfigPreloadData preloadDataItem = preloadDataItems.get(0);
721
722         if (preloadDataItem.getPreloadData() != null) {
723             log.error("Preload data already exists for {}:{} ", preloadId, preloadType);
724             throw new RestProtocolException("data-exists", "Data already exists for " + preloadId + ":" + preloadType,
725                     HttpStatus.CONFLICT.value());
726         }
727
728         try {
729             preloadDataItem.setPreloadData(objectMapper.writeValueAsString(preloadData));
730             configPreloadDataRepository.save(preloadDataItem);
731         } catch (JsonProcessingException e) {
732             log.error("Cannot convert preload data", e);
733             throw new RestApplicationException("data-conversion",
734                     "Request could not be completed due to internal error", e,
735                     HttpStatus.INTERNAL_SERVER_ERROR.value());
736         }
737
738         return new ResponseEntity<>(HttpStatus.CREATED);
739     }
740
741     @Override
742     public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataPut(
743             String preloadId, String preloadType, @Valid GenericResourceApiPreloaddataPreloadData preloadData)
744             throws RestApplicationException, RestProtocolException {
745         boolean dataExists = false;
746         List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
747                 preloadType);
748         if ((preloadDataItems == null) || (preloadDataItems.isEmpty())) {
749             throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
750         }
751
752         if ((preloadData == null) || (preloadData.getPreloadNetworkTopologyInformation() == null)) {
753             throw new RestProtocolException("bad-attribute", "Invalid preloadData received",
754                     HttpStatus.BAD_REQUEST.value());
755         }
756
757         ConfigPreloadData preloadDataItem = preloadDataItems.get(0);
758
759         if (preloadDataItem.getPreloadData() != null) {
760             dataExists = true;
761         }
762
763         try {
764             preloadDataItem.setPreloadData(objectMapper.writeValueAsString(preloadData));
765             configPreloadDataRepository.save(preloadDataItem);
766         } catch (JsonProcessingException e) {
767             log.error("Cannot convert preload data", e);
768             throw new RestApplicationException("data-conversion",
769                     "Request could not be completed due to internal error", e,
770                     HttpStatus.INTERNAL_SERVER_ERROR.value());
771         }
772
773         if (dataExists) {
774             return new ResponseEntity<>(HttpStatus.NO_CONTENT);
775         } else {
776             return new ResponseEntity<>(HttpStatus.CREATED);
777         }
778     }
779
780     @Override
781     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesDelete() {
782         configVfModulesRepository.deleteAll();
783         configVnfsRepository.deleteAll();
784         configNetworksRepository.deleteAll();
785         configServicesRepository.deleteAll();
786         return new ResponseEntity<>(HttpStatus.NO_CONTENT);
787     }
788
789     @Override
790     public ResponseEntity<GenericResourceApiServiceModelInfrastructure> configGENERICRESOURCEAPIservicesGet()
791             throws RestApplicationException {
792         GenericResourceApiServiceModelInfrastructure modelInfrastructure = new GenericResourceApiServiceModelInfrastructure();
793
794         if (configServicesRepository.count() == 0) {
795             throw new RestApplicationException("data-missing",
796                     "Request could not be completed because the relevant data model content does not exist",
797                     HttpStatus.NOT_FOUND.value());
798         }
799
800         for (ConfigServices service : configServicesRepository.findAll()) {
801             GenericResourceApiServicemodelinfrastructureService serviceItem = new GenericResourceApiServicemodelinfrastructureService();
802             String svcInstanceId = service.getSvcInstanceId();
803
804             serviceItem.setServiceInstanceId(svcInstanceId);
805             serviceItem.setServiceStatus(service.getServiceStatus());
806
807             // Construct service data from networks/vnfs/vfModules
808             GenericResourceApiServicedataServiceData serviceItemSvcData;
809             try {
810                 serviceItemSvcData = serviceDataHelper.getServiceData(service);
811             } catch (JsonProcessingException e) {
812                 log.error("Could not deserialize service data for {}", service.getSvcInstanceId(), e);
813                 throw new RestApplicationException("data-conversion",
814                         "Request could not be completed due to internal error", e,
815                         HttpStatus.INTERNAL_SERVER_ERROR.value());
816             }
817
818             
819             if (serviceItemSvcData != null) {
820                 serviceItem.setServiceData(serviceItemSvcData);
821             }
822             modelInfrastructure.addServiceItem(serviceItem);
823         }
824
825         return new ResponseEntity<>(modelInfrastructure, HttpStatus.OK);
826
827     }
828
829     @Override
830     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPost(@Valid GenericResourceApiServiceModelInfrastructure modelInfrastructure)
831             throws RestApplicationException, RestProtocolException {
832         
833         ServiceDataTransaction transaction = serviceDataHelper.createTransaction();
834
835         for (GenericResourceApiServicemodelinfrastructureService serviceItem : modelInfrastructure.getService()) {
836             String svcInstanceId = serviceItem.getServiceInstanceId();
837             List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
838             if ((existingService != null) && !existingService.isEmpty()) {
839                 log.error("Service data already exists for {}", svcInstanceId);
840                 throw new RestProtocolException("data-exists",
841                         "Data already exists for service-instance-id " + svcInstanceId, HttpStatus.CONFLICT.value());
842             }
843             ConfigServices service = new ConfigServices();
844             service.setSvcInstanceId(svcInstanceId);
845             service.setServiceStatus(serviceItem.getServiceStatus());
846
847             try {
848                 serviceDataHelper.saveService(service, serviceItem.getServiceData(), transaction);
849             } catch (JsonProcessingException e) {
850                 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
851                 throw new RestApplicationException("data-conversion",
852                         "Request could not be completed due to internal error", e,
853                         HttpStatus.INTERNAL_SERVER_ERROR.value());
854
855             }
856         }
857
858         transaction.commit();
859
860         return new ResponseEntity<>(HttpStatus.CREATED);
861
862     }
863
864     @Override
865     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPut(
866             @Valid GenericResourceApiServiceModelInfrastructure modelInfrastructure) throws RestApplicationException {
867
868         ServiceDataTransaction transaction = serviceDataHelper.createTransaction();
869         boolean dataExists = false;
870
871         for (GenericResourceApiServicemodelinfrastructureService serviceItem : modelInfrastructure.getService()) {
872             String svcInstanceId = serviceItem.getServiceInstanceId();
873             List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
874             if ((existingService != null) && !existingService.isEmpty()) {
875                 dataExists = true;
876             }
877             ConfigServices service = new ConfigServices();
878             service.setSvcInstanceId(svcInstanceId);
879             service.setServiceStatus(serviceItem.getServiceStatus());
880             try {
881                 serviceDataHelper.saveService(service, serviceItem.getServiceData(), transaction);
882             } catch (JsonProcessingException e) {
883                 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
884                 throw new RestApplicationException("data-conversion",
885                         "Request could not be completed due to internal error", e,
886                         HttpStatus.INTERNAL_SERVER_ERROR.value());
887
888             }
889         }
890
891         transaction.commit();
892
893         if (dataExists) {
894             return new ResponseEntity<>(HttpStatus.NO_CONTENT);
895         } else {
896             return new ResponseEntity<>(HttpStatus.CREATED);
897         }
898
899     }
900
901     @Override
902     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServicePost(
903             @Valid GenericResourceApiServicemodelinfrastructureService servicesData) throws RestApplicationException {
904         String svcInstanceId = servicesData.getServiceInstanceId();
905         try {
906             ConfigServices configService = new ConfigServices(svcInstanceId, servicesData.getServiceStatus());
907             serviceDataHelper.saveService(configService, servicesData.getServiceData());
908         } catch (JsonProcessingException e) {
909             log.error("Cannot convert service data", e);
910             throw new RestApplicationException("data-conversion",
911                     "Request could not be completed due to internal error", e,
912                     HttpStatus.INTERNAL_SERVER_ERROR.value());
913
914         }
915         return new ResponseEntity<>(HttpStatus.OK);
916     }
917
918     @Override
919     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdDelete(
920             String serviceInstanceId) {
921         serviceDataHelper.deleteService(serviceInstanceId);  
922         return new ResponseEntity<>(HttpStatus.NO_CONTENT);
923     }
924
925     @Override
926     public ResponseEntity<GenericResourceApiServicemodelinfrastructureService> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdGet(
927             String serviceInstanceId) throws RestApplicationException {
928         GenericResourceApiServicemodelinfrastructureService retval = null;
929
930         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
931
932         if (services.isEmpty()) {
933             return new ResponseEntity<>(HttpStatus.NOT_FOUND);
934         } else {
935             ConfigServices service = services.get(0);
936             retval = new GenericResourceApiServicemodelinfrastructureService();
937             retval.setServiceInstanceId(serviceInstanceId);
938             retval.setServiceStatus(service.getServiceStatus());
939             try {
940                 retval.setServiceData(serviceDataHelper.getServiceData(service));
941             } catch (JsonProcessingException e) {
942                 log.error("Could not deserialize service data for service instance id {}", serviceInstanceId, e);
943                 throw new RestApplicationException("data-conversion",
944                         "Request could not be completed due to internal error", e,
945                         HttpStatus.INTERNAL_SERVER_ERROR.value());
946
947             }
948         }
949
950         return new ResponseEntity<>(retval, HttpStatus.OK);
951
952     }
953
954     @Override
955     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdPost(String svcInstanceId,
956             @Valid GenericResourceApiServicemodelinfrastructureService newService)
957             throws RestApplicationException, RestProtocolException {
958
959         List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
960         if ((existingService != null) && !existingService.isEmpty()) {
961             log.error("Service data already exists for {}", svcInstanceId);
962             throw new RestProtocolException("data-exists",
963                     "Data already exists for service-instance-id " + svcInstanceId, HttpStatus.CONFLICT.value());
964         }
965         ConfigServices service = new ConfigServices();
966         service.setSvcInstanceId(svcInstanceId);
967         service.setServiceStatus(newService.getServiceStatus());
968         try {
969             serviceDataHelper.saveService(service, newService.getServiceData());
970         } catch (JsonProcessingException e) {
971             log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
972             throw new RestApplicationException("data-conversion",
973                     "Request could not be completed due to internal error", e,
974                     HttpStatus.INTERNAL_SERVER_ERROR.value());
975
976         }
977
978         return new ResponseEntity<>(HttpStatus.CREATED);
979     }
980
981     @Override
982     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdPut(String serviceInstanceId,
983             @Valid GenericResourceApiServicemodelinfrastructureService newService) throws RestApplicationException {
984
985         boolean dataExists = false;
986
987         String svcInstanceId = newService.getServiceInstanceId();
988
989         ConfigServices service = null;
990         List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
991         if ((existingService != null) && !existingService.isEmpty()) {
992             dataExists = true;
993             service = existingService.get(0);
994         } else {
995             service = new ConfigServices();
996             service.setSvcInstanceId(svcInstanceId);
997         }
998
999         service.setServiceStatus(newService.getServiceStatus());
1000         try {
1001             serviceDataHelper.saveService(service, newService.getServiceData());
1002         } catch (JsonProcessingException e) {
1003             log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
1004             throw new RestApplicationException("data-conversion",
1005                     "Request could not be completed due to internal error", e,
1006                     HttpStatus.INTERNAL_SERVER_ERROR.value());
1007
1008         }
1009
1010         if (dataExists) {
1011             return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1012         } else {
1013             return new ResponseEntity<>(HttpStatus.CREATED);
1014         }
1015     }
1016
1017     @Override
1018     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataDelete(
1019             String serviceInstanceId) throws RestProtocolException {
1020         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1021
1022         if ((services == null) || (services.isEmpty())) {
1023             throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1024         }
1025
1026         ConfigServices service = services.get(0);
1027         if (!serviceDataHelper.hasServiceData(service)) {
1028             throw new RestProtocolException("data-missing", "No service-data found", HttpStatus.NOT_FOUND.value());
1029         }
1030         serviceDataHelper.clearServiceData(service);
1031
1032         return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1033     }
1034
1035     @Override
1036     public ResponseEntity<GenericResourceApiServicedataServiceData> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataGet(
1037             String serviceInstanceId) throws RestApplicationException, RestProtocolException {
1038         GenericResourceApiServicedataServiceData serviceData = null;
1039
1040         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1041         if ((services == null) || (services.isEmpty())) {
1042             throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1043         }
1044
1045         try {
1046             serviceData = serviceDataHelper.getServiceData(services.get(0));
1047             return new ResponseEntity<>(serviceData, HttpStatus.OK);
1048         } catch (JsonProcessingException e) {
1049             log.error("Could not parse service data", e);
1050             throw new RestApplicationException("data-conversion",
1051                     "Request could not be completed due to internal error", e,
1052                     HttpStatus.INTERNAL_SERVER_ERROR.value());
1053         }
1054
1055     }
1056
1057     @Override
1058     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataPost(
1059             String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData serviceData)
1060             throws RestApplicationException, RestProtocolException {
1061         ConfigServices service;
1062         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1063         if ((services == null) || (services.isEmpty())) {
1064             throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1065         }
1066
1067         if ((serviceData == null) || (serviceData.getServiceInformation() == null)) {
1068             throw new RestProtocolException("bad-attribute", "Invalid service-data received",
1069                     HttpStatus.BAD_REQUEST.value());
1070
1071         }
1072         service = services.get(0);
1073
1074         if (serviceDataHelper.hasServiceData(service)) {
1075             log.error("service-data already exists for svcInstanceId {}", serviceInstanceId);
1076             throw new RestProtocolException("data-exists", "Data already exists for " + serviceInstanceId,
1077                     HttpStatus.CONFLICT.value());
1078         }
1079
1080         try {
1081             serviceDataHelper.saveService(service, serviceData);
1082         } catch (JsonProcessingException e) {
1083             log.error("Could not serialize service data for svc instance id {}", serviceInstanceId, e);
1084             throw new RestApplicationException("data-conversion",
1085                     "Request could not be completed due to internal error", e,
1086                     HttpStatus.INTERNAL_SERVER_ERROR.value());
1087         }
1088
1089         return new ResponseEntity<>(HttpStatus.CREATED);
1090
1091     }
1092
1093     @Override
1094     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataPut(
1095             String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData serviceData)
1096             throws RestApplicationException, RestProtocolException {
1097         ConfigServices service;
1098         boolean dataExists = false;
1099
1100         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1101         if ((services == null) || (services.isEmpty())) {
1102             throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1103         }
1104
1105         if ((serviceData == null) || (serviceData.getServiceInformation() == null)) {
1106             throw new RestProtocolException("bad-attribute", "Invalid service-data received",
1107                     HttpStatus.BAD_REQUEST.value());
1108
1109         }
1110         service = services.get(0);
1111
1112         dataExists = serviceDataHelper.hasServiceData(service);
1113
1114         try {
1115             serviceDataHelper.saveService(service, serviceData);
1116         } catch (JsonProcessingException e) {
1117             log.error("Could not serialize service data for svc instance id {}", serviceInstanceId, e);
1118             throw new RestApplicationException("data-conversion",
1119                     "Request could not be completed due to internal error", e,
1120                     HttpStatus.INTERNAL_SERVER_ERROR.value());
1121         }
1122
1123         if (dataExists) {
1124             return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1125         } else {
1126             return new ResponseEntity<>(HttpStatus.CREATED);
1127         }
1128     }
1129
1130     @Override
1131     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusDelete(
1132             String serviceInstanceId) throws RestProtocolException {
1133         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1134
1135         if ((services == null) || (services.isEmpty())) {
1136             throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1137         }
1138
1139         ConfigServices service = services.get(0);
1140         if (service.getServiceStatus() == null) {
1141             throw new RestProtocolException("data-missing", "No service-status found", HttpStatus.NOT_FOUND.value());
1142         }
1143         service.setServiceStatus(null);
1144         configServicesRepository.save(service);
1145
1146         return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1147
1148     }
1149
1150     @Override
1151     public ResponseEntity<GenericResourceApiServicestatusServiceStatus> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusGet(
1152             String serviceInstanceId) throws RestApplicationException, RestProtocolException {
1153         GenericResourceApiServicestatusServiceStatus serviceStatus = null;
1154
1155         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1156         if ((services == null) || (services.isEmpty())) {
1157             throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1158         }
1159
1160         serviceStatus = services.get(0).getServiceStatus();
1161         return new ResponseEntity<>(serviceStatus, HttpStatus.OK);
1162     }
1163
1164     @Override
1165     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusPost(
1166             String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus serviceStatus)
1167             throws RestProtocolException {
1168         ConfigServices service;
1169         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1170         if ((services == null) || (services.isEmpty())) {
1171             throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1172         }
1173
1174         if ((serviceStatus == null) || (serviceStatus.getAction() == null)) {
1175             throw new RestProtocolException("bad-attribute", "Invalid service-status received",
1176                     HttpStatus.BAD_REQUEST.value());
1177
1178         }
1179         service = services.get(0);
1180
1181         if (service.getServiceStatus() != null) {
1182             log.error("service-status already exists for svcInstanceId {}", serviceInstanceId);
1183             throw new RestProtocolException("data-exists", "Data already exists for " + serviceInstanceId,
1184                     HttpStatus.CONFLICT.value());
1185         }
1186
1187         service.setServiceStatus(serviceStatus);
1188         configServicesRepository.save(service);
1189
1190         return new ResponseEntity<>(HttpStatus.CREATED);
1191
1192     }
1193
1194     @Override
1195     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusPut(
1196             String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus serviceStatus)
1197             throws RestProtocolException {
1198         ConfigServices service;
1199         boolean dataExists = false;
1200
1201         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1202         if ((services == null) || (services.isEmpty())) {
1203             throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1204         }
1205
1206         if ((serviceStatus == null) || (serviceStatus.getAction() == null)) {
1207             throw new RestProtocolException("bad-attribute", "Invalid service-status received",
1208                     HttpStatus.BAD_REQUEST.value());
1209
1210         }
1211         service = services.get(0);
1212
1213         if (service.getServiceStatus() != null) {
1214             dataExists = true;
1215         }
1216
1217         service.setServiceStatus(serviceStatus);
1218         configServicesRepository.save(service);
1219
1220         if (dataExists) {
1221             return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1222         } else {
1223             return new ResponseEntity<>(HttpStatus.CREATED);
1224         }
1225     }
1226
1227     /**
1228      * Deletes VNF data from the Config table specified Service Instance.
1229      * <p>
1230      * Maps to
1231      * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/
1232      * 
1233      * @param serviceInstanceId the Service Instance ID to perform the delete on
1234      * @param vnfId             the VNF ID of the VNF to delete
1235      * @return HttpStatus.NO_CONTENT (204) on successful delete
1236      *         <p>
1237      *         HttpStatus.BAD_REQUEST (400) if unmarshalling Service Data from the
1238      *         database fails, there is no VNF data for {@code vnfId}, or writing
1239      *         Service Data back to the database fails.
1240      *         <p>
1241      *         HttpStatus.NOT_FOUND (404) if {@code serviceInstanceId} does not
1242      *         exist.
1243      */
1244     @Override
1245     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdDelete(
1246             String serviceInstanceId, String vnfId) throws RestException {
1247         log.info("DELETE | VNF Data for ({})", vnfId);
1248
1249         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1250         ConfigServices data;
1251         if ((services == null) || (services.isEmpty())) {
1252             log.info("Could not find data for ({}).", serviceInstanceId);
1253             // Or throw the data not found error?
1254             throw new RestProtocolException("data-missing", "Service Instance ID not found.",
1255                     HttpStatus.NOT_FOUND.value());
1256         } else {
1257             data = services.get(0);
1258         }
1259
1260         if (!serviceDataHelper.hasServiceData(data)) {
1261             log.info("Could not find Service Data for ({}).", serviceInstanceId);
1262             throw new RestProtocolException("data-missing", "Service data not found.", HttpStatus.NOT_FOUND.value());
1263         }
1264
1265         if (serviceDataHelper.deleteVnf(serviceInstanceId, vnfId) > 0) {
1266             return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1267         } else {
1268             // Data was not found
1269             log.error("Did not find VNF ({}) in data.", vnfId);
1270             throw new RestProtocolException("data-missing", "VNF ID not found.", HttpStatus.NOT_FOUND.value());
1271         }
1272     }
1273
1274     /**
1275      * Extracts VNF data from the Config table specified Service Instance.
1276      * <p>
1277      * Maps to
1278      * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/
1279      * 
1280      * @param serviceInstanceId the Service Instance ID to lookup data for
1281      * @param vnfId             the VNF ID of the VNF to return
1282      * @return HttpStatus.OK (200) if the data is found.
1283      * @throws RestException if the data does not exist.
1284      */
1285     @Override
1286     public ResponseEntity<GenericResourceApiServicedataServicedataVnfsVnf> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdGet(
1287             String serviceInstanceId, String vnfId) throws RestException {
1288         log.info("GET | VNF Data for ({})", vnfId);
1289
1290         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1291         if ((services == null) || (services.isEmpty())) {
1292             throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1293         }
1294
1295         GenericResourceApiServicedataServicedataVnfsVnf vnf = null;
1296         try {
1297             vnf = serviceDataHelper.getVnf(serviceInstanceId, vnfId);
1298         } catch (JsonProcessingException e) {
1299             log.error("Could not parse service data", e);
1300             throw new RestApplicationException("data-conversion",
1301                     "Request could not be completed due to internal error", e,
1302                     HttpStatus.INTERNAL_SERVER_ERROR.value());
1303         }
1304
1305         if (vnf != null) {
1306             return new ResponseEntity<>(vnf, HttpStatus.OK);
1307         } else {
1308             log.info("No information found for {}", vnfId);
1309             throw new RestApplicationException("data-missing",
1310                     "Request could not be completed because the relevant data model content does not exist",
1311                     HttpStatus.NOT_FOUND.value());
1312         }
1313     }
1314
1315     /**
1316      * Creates or updates VNF data in the Config table for a specified Service
1317      * Instance. If it is a new Service Instance or a new VNF, creates all necessary
1318      * parent data containers, then performs the updates.
1319      * <p>
1320      * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/
1321      * @param serviceInstanceId the Service Instance ID to perform the delete on
1322      * @param vnfId the VNF ID of the VNF to delete
1323      * @param genericResourceApiServicedataServicedataVnfsVnfBodyParam the playload
1324      * @return HttpStatus.CREATED (201) on successful create
1325      * <p>
1326      * HttpStatus.NO_CONTENT (204) on successful update
1327      * <p>
1328      * HttpStatus.BAD_REQUEST (400) if {@code vnfId} does not match what is specified in the
1329      * {@code genericResourceApiServicedataServicedataVnfsVnfBodyParam} , or if updating the database fails.
1330      * @throws RestException
1331      */
1332     @Override
1333     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdPut(
1334             String serviceInstanceId, String vnfId,
1335             GenericResourceApiServicedataServicedataVnfsVnf vnf)
1336             throws RestException {
1337         log.info("PUT | VNF Data for ({})", vnfId);
1338         if (!vnfId.equals(vnf.getVnfId())) {
1339             throw new RestProtocolException("bad-attribute", "vnf-id mismatch", HttpStatus.BAD_REQUEST.value());
1340         }
1341
1342         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1343         ConfigServices data;
1344         ServiceDataTransaction transaction = serviceDataHelper.createTransaction();
1345         if ((services == null) || (services.isEmpty())) {
1346             log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1347             data = new ConfigServices();
1348             data.setSvcInstanceId(serviceInstanceId);
1349             transaction.save(data);
1350         } else {
1351             data = services.get(0);
1352         }
1353
1354         try {
1355             HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1356             if (serviceDataHelper.getVnf(serviceInstanceId, vnfId) == null) {
1357                 responseStatus = HttpStatus.CREATED;
1358             }
1359             serviceDataHelper.saveVnf(serviceInstanceId, vnf, transaction);
1360             transaction.commit();
1361             return new ResponseEntity<>(responseStatus);
1362         } catch (JsonProcessingException e) {
1363             log.error("Error saving vnf", e);
1364             return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1365         }
1366     }
1367
1368     /**
1369      * Extracts VNF Topology data from the Config table specified Service Instance
1370      * and VNF ID.
1371      * <p>
1372      * Maps to
1373      * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/
1374      * 
1375      * @param serviceInstanceId the Service Instance ID to lookup data for
1376      * @param vnfId             the VNF ID of the VNF to extract topology data from.
1377      * @return HttpStatus.OK (200) if the data is found.
1378      * @throws RestException if the data does not exist.
1379      */
1380     @Override
1381     public ResponseEntity<GenericResourceApiVnftopologyVnfTopology> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyGet(
1382             String serviceInstanceId, String vnfId) throws RestException {
1383         log.info("GET | VNF Topology for ({})", vnfId);
1384
1385         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1386         if ((services == null) || (services.isEmpty())) {
1387             throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1388         }
1389
1390         GenericResourceApiServicedataServicedataVnfsVnf vnf = null;
1391         
1392         try {
1393             vnf = serviceDataHelper.getVnf(serviceInstanceId, vnfId);
1394         } catch (JsonProcessingException e) {
1395             log.error("Could not parse service data", e);
1396             throw new RestApplicationException("data-conversion",
1397                     "Request could not be completed due to internal error", e,
1398                     HttpStatus.INTERNAL_SERVER_ERROR.value());
1399         }
1400
1401         // Drill down to find the data
1402         if (vnf != null && vnf.getVnfData() != null && vnf.getVnfData().getVnfTopology() != null) {
1403             return new ResponseEntity<>(vnf.getVnfData().getVnfTopology(), HttpStatus.OK);
1404         } else {
1405             log.info("No information found for {}", vnfId);
1406             throw new RestApplicationException("data-missing",
1407                     "Request could not be completed because the relevant data model content does not exist",
1408                     HttpStatus.NOT_FOUND.value());
1409         }
1410     }
1411
1412     /**
1413      * Creates or updates VNF Level Operation Status data in the Config table for a
1414      * specified Service Instance. If it is a new Service Instance or a new VNF,
1415      * creates all necessary parent data containers, then performs the updates.
1416      * <p>
1417      * Maps to
1418      * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-level-oper-status/
1419      * 
1420      * @param serviceInstanceId                         the Service Instance ID to
1421      *                                                  perform the delete on
1422      * @param vnfId                                     the VNF ID of the VNF to
1423      *                                                  delete
1424      * @param genericResourceApiOperStatusDataBodyParam the payload
1425      * @return HttpStatus.CREATED (201) on successful create.
1426      *         <p>
1427      *         HttpStatus.NO_CONTENT (204) on successful update.
1428      *         <p>
1429      *         HttpStatus.BAD_REQUEST (400) if updating the database fails.
1430      * @throws RestException
1431      */
1432     @Override
1433     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfLevelOperStatusPut(
1434             String serviceInstanceId, String vnfId,
1435             GenericResourceApiOperStatusData genericResourceApiOperStatusDataBodyParam) throws RestException {
1436         log.info("PUT | VNF Level Oper Status ({})", vnfId);
1437         ServiceDataTransaction transaction = serviceDataHelper.createTransaction();
1438
1439         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1440         ConfigServices data;
1441         if ((services == null) || (services.isEmpty())) {
1442             log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1443             data = new ConfigServices();
1444             data.setSvcInstanceId(serviceInstanceId);
1445             transaction.save(data);
1446         } else {
1447             data = services.get(0);
1448         }
1449
1450         HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1451
1452         try {
1453             GenericResourceApiServicedataServicedataVnfsVnf vnf = serviceDataHelper.getVnf(serviceInstanceId, vnfId);
1454             if (vnf == null) {
1455                 responseStatus = HttpStatus.CREATED;
1456                 vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1457                 vnf.setVnfId(vnfId);
1458             } 
1459             GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = vnf.getVnfData();
1460             if (vnfData == null) {
1461                 vnfData = new GenericResourceApiServicedataServicedataVnfsVnfVnfData();
1462             }
1463             vnfData.setVnfLevelOperStatus(genericResourceApiOperStatusDataBodyParam);
1464             vnf.setVnfData(vnfData);
1465             serviceDataHelper.saveVnf(serviceInstanceId, vnf, transaction);
1466             transaction.commit();
1467             return new ResponseEntity<>(responseStatus);
1468         } catch (JsonProcessingException e) {
1469             log.error("Error saving vnf", e);
1470             return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1471         }
1472     }
1473
1474     /**
1475      * Creates or updates VNF Onap Model Information data in the Config table for a
1476      * specified Service Instance. If it is a new Service Instance or a new VNF,
1477      * creates all necessary parent data containers, then performs the updates.
1478      * <p>
1479      * Maps to
1480      * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/onap-model-information/
1481      * 
1482      * @param serviceInstanceId                                                   the
1483      *                                                                            Service
1484      *                                                                            Instance
1485      *                                                                            ID
1486      *                                                                            to
1487      *                                                                            perform
1488      *                                                                            the
1489      *                                                                            delete
1490      *                                                                            on
1491      * @param vnfId                                                               the
1492      *                                                                            VNF
1493      *                                                                            ID
1494      *                                                                            of
1495      *                                                                            the
1496      *                                                                            VNF
1497      *                                                                            to
1498      *                                                                            delete
1499      * @param genericResourceApiOnapmodelinformationOnapModelInformationBodyParam the
1500      *                                                                            payload
1501      * @return HttpStatus.CREATED (201) on successful create.
1502      *         <p>
1503      *         HttpStatus.NO_CONTENT (204) on successful update.
1504      *         <p>
1505      *         HttpStatus.BAD_REQUEST (400) if updating the database fails.
1506      * @throws RestException
1507      */
1508     @Override
1509     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyOnapModelInformationPut(
1510             String serviceInstanceId, String vnfId,
1511             GenericResourceApiOnapmodelinformationOnapModelInformation genericResourceApiOnapmodelinformationOnapModelInformationBodyParam)
1512             throws RestException {
1513         log.info("PUT | VNF Topology Onap Model Information ({})", vnfId);
1514         ServiceDataTransaction transaction = serviceDataHelper.createTransaction();
1515
1516         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1517         ConfigServices data;
1518         if ((services == null) || (services.isEmpty())) {
1519             log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1520             data = new ConfigServices();
1521             data.setSvcInstanceId(serviceInstanceId);
1522             transaction.save(data);
1523         } else {
1524             data = services.get(0);
1525         }
1526
1527
1528         GenericResourceApiServicedataServicedataVnfsVnf vnf = null;
1529         HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1530         
1531         try {
1532             vnf = serviceDataHelper.getVnf(serviceInstanceId, vnfId);
1533         } catch(JsonProcessingException e) {
1534
1535             log.error("Could not parse service data", e);
1536             throw new RestApplicationException("data-conversion",
1537                     "Request could not be completed due to internal error", e,
1538                     HttpStatus.INTERNAL_SERVER_ERROR.value());
1539         }
1540
1541         if (vnf == null) {
1542             responseStatus = HttpStatus.CREATED;
1543             vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1544             vnf.setVnfId(vnfId);
1545             vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1546             vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology());
1547         }
1548
1549         vnf.getVnfData().getVnfTopology()
1550                 .setOnapModelInformation(genericResourceApiOnapmodelinformationOnapModelInformationBodyParam);
1551
1552         // Save the updated VNF (and service, if new)
1553         try {
1554             serviceDataHelper.saveVnf(serviceInstanceId, vnf, transaction);
1555             transaction.commit();
1556             return new ResponseEntity<>(responseStatus);
1557         } catch (JsonProcessingException e) {
1558             log.error("Error mapping object to JSON", e);
1559             // Should probably be a 500 INTERNAL_SERVICE_ERROR
1560             return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1561         }
1562     }
1563
1564     /**
1565      * Creates or updates VNF Network data in the Config table for a specified
1566      * Service Instance. If it is a new Service Instance or a new VNF, creates all
1567      * necessary parent data containers, then performs the updates.
1568      * <p>
1569      * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/vnf-resource-assignments/vnf-networks/
1570      * @param serviceInstanceId the Service Instance ID to perform the delete on
1571      * @param vnfId the VNF ID of the VNF to delete
1572      * @param genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam the * payload
1573      * @return HttpStatus.CREATED (201) on successful create.
1574      * <p>
1575      * HttpStatus.NO_CONTENT (204) on successful update.
1576      * <p>
1577      * HttpStatus.BAD_REQUEST (400) if updating the database fails.
1578      * @throws RestException
1579      */
1580     @Override
1581     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksPut(
1582             String serviceInstanceId, String vnfId,
1583             GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam)
1584             throws RestException {
1585         log.info("PUT | VNF Topology VNF Resource Assignments VNF Networks ({})", vnfId);
1586
1587         ServiceDataTransaction transaction = serviceDataHelper.createTransaction();
1588         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1589         ConfigServices data;
1590         if ((services == null) || (services.isEmpty())) {
1591             log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1592             data = new ConfigServices();
1593             data.setSvcInstanceId(serviceInstanceId);
1594             transaction.save(data);
1595         } else {
1596             data = services.get(0);
1597         }
1598
1599         HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1600         GenericResourceApiServicedataServicedataVnfsVnf vnf = null;
1601
1602         try {
1603             vnf = serviceDataHelper.getVnf(serviceInstanceId, vnfId);
1604         } catch(JsonProcessingException e) {
1605
1606             log.error("Could not parse service data", e);
1607             throw new RestApplicationException("data-conversion",
1608                     "Request could not be completed due to internal error", e,
1609                     HttpStatus.INTERNAL_SERVER_ERROR.value());
1610         }
1611
1612         if (vnf == null) {
1613             log.info("Creating VNF data for ({})", vnfId);
1614             vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1615             vnf.setVnfId(vnfId);
1616             responseStatus = HttpStatus.CREATED;
1617         }
1618         GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = vnf.getVnfData();
1619         if (vnfData == null) {
1620             vnfData = new GenericResourceApiServicedataServicedataVnfsVnfVnfData();
1621         }
1622
1623         GenericResourceApiVnftopologyVnfTopology vnfTopology = vnfData.getVnfTopology();
1624         if (vnfTopology == null) {
1625             vnfTopology = new GenericResourceApiVnftopologyVnfTopology();
1626         }
1627
1628         GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments = vnfTopology.getVnfResourceAssignments();
1629         if (vnfResourceAssignments == null) {
1630             vnfResourceAssignments = new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments();
1631         }
1632         vnfResourceAssignments.setVnfNetworks(genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam);
1633         vnfTopology.setVnfResourceAssignments(vnfResourceAssignments);
1634         vnfData.setVnfTopology(vnfTopology);
1635         vnf.setVnfData(vnfData);
1636
1637         // Map and save the new data
1638         try {
1639             serviceDataHelper.saveVnf(serviceInstanceId, vnf, transaction);
1640             transaction.commit();
1641             return new ResponseEntity<>(responseStatus);
1642         } catch (JsonProcessingException e) {
1643             log.error("Error mapping object to JSON", e);
1644             // Should probably be a 500 INTERNAL_SERVICE_ERROR
1645             return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1646         }
1647     }
1648
1649     /**
1650      * Creates or updates VNF Network Role data in the Config table for a specified
1651      * Service Instance. If it is a new Service Instance or a new VNF, creates all
1652      * necessary parent data containers, then performs the updates.
1653      * <p>
1654      * Maps to
1655      * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/vnf-resource-assignments/vnf-networks/vnf-network/{network-role}/
1656      * 
1657      * @param serviceInstanceId                         the Service Instance ID to
1658      *                                                  perform the delete on
1659      * @param vnfId                                     the VNF ID of the VNF to
1660      *                                                  delete
1661      * @param genericResourceApiVnfNetworkDataBodyParam the payload
1662      * @return HttpStatus.CREATED (201) on successful create.
1663      *         <p>
1664      *         HttpStatus.NO_CONTENT (204) on successful update.
1665      *         <p>
1666      *         HttpStatus.BAD_REQUEST (400) if updating the database fails.
1667      * @throws RestException
1668      */
1669     @Override
1670     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksVnfNetworkNetworkRolePut(
1671             String serviceInstanceId, String vnfId, String networkRole,
1672             GenericResourceApiVnfNetworkData genericResourceApiVnfNetworkDataBodyParam) throws RestException {
1673         log.info("PUT | VNF Network Network Role ({})", vnfId);
1674         if (!networkRole.equals(genericResourceApiVnfNetworkDataBodyParam.getNetworkRole())) {
1675             throw new RestProtocolException("bad-attribute", "network-role mismatch", HttpStatus.BAD_REQUEST.value());
1676         }
1677
1678         ServiceDataTransaction transaction = serviceDataHelper.createTransaction();
1679
1680         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1681         ConfigServices data;
1682         if ((services == null) || (services.isEmpty())) {
1683             log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1684             data = new ConfigServices();
1685             data.setSvcInstanceId(serviceInstanceId);
1686             transaction.save(data);
1687         } else {
1688             data = services.get(0);
1689         }
1690
1691         HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1692         GenericResourceApiServicedataServicedataVnfsVnf vnf = null;
1693
1694         try {
1695             vnf = serviceDataHelper.getVnf(serviceInstanceId, vnfId);
1696         } catch(JsonProcessingException e) {
1697
1698             log.error("Could not parse service data", e);
1699             throw new RestApplicationException("data-conversion",
1700                     "Request could not be completed due to internal error", e,
1701                     HttpStatus.INTERNAL_SERVER_ERROR.value());
1702         }
1703
1704         if (vnf == null) {
1705             log.info("Creating VNF data for ({})", vnfId);
1706             vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1707             vnf.setVnfId(vnfId);
1708             responseStatus = HttpStatus.CREATED;
1709         }
1710         GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = vnf.getVnfData();
1711         if (vnfData == null) {
1712             vnfData = new GenericResourceApiServicedataServicedataVnfsVnfVnfData();
1713         }
1714
1715         GenericResourceApiVnftopologyVnfTopology vnfTopology = vnfData.getVnfTopology();
1716         if (vnfTopology == null) {
1717             vnfTopology = new GenericResourceApiVnftopologyVnfTopology();
1718         }
1719
1720         GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments = vnfTopology.getVnfResourceAssignments();
1721         if (vnfResourceAssignments == null) {
1722             vnfResourceAssignments = new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments();
1723         }
1724
1725         GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks vnfNetworks = vnfResourceAssignments.getVnfNetworks();
1726         if (vnfNetworks == null) {
1727             vnfNetworks = new GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks();
1728             vnfNetworks.setVnfNetwork(new ArrayList<>());
1729         }
1730
1731
1732         if (vnfNetworks.getVnfNetwork().isEmpty()) {
1733             vnfNetworks.addVnfNetworkItem(genericResourceApiVnfNetworkDataBodyParam);
1734         } else {
1735             GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks vnfNetworksNew = new GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks();
1736             vnfNetworksNew.setVnfNetwork(new ArrayList<>());
1737             vnfNetworks.getVnfNetwork().stream()
1738               .filter(targetNetwork -> !targetNetwork.getNetworkRole().equals(networkRole)).forEach(vnfNetworksNew::addVnfNetworkItem);
1739
1740             vnfNetworksNew.addVnfNetworkItem(genericResourceApiVnfNetworkDataBodyParam);
1741             vnfNetworks = vnfNetworksNew;
1742         }
1743
1744         vnfResourceAssignments.setVnfNetworks(vnfNetworks);
1745         vnfTopology.setVnfResourceAssignments(vnfResourceAssignments);
1746         vnfData.setVnfTopology(vnfTopology);
1747         vnf.setVnfData(vnfData);
1748         try {
1749             serviceDataHelper.saveVnf(serviceInstanceId, vnf, transaction);
1750             transaction.commit();        
1751             return new ResponseEntity<>(responseStatus);
1752         } catch (JsonProcessingException e) {
1753             log.error("Error mapping object to JSON", e);
1754             // Should probably be a 500 INTERNAL_SERVICE_ERROR
1755             return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1756         }
1757     }
1758
1759
1760     @Override
1761     public ResponseEntity<GenericResourceApiServicetopologyServiceTopology> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataServiceTopologyGet(
1762             String serviceInstanceId) throws RestApplicationException, RestProtocolException {
1763         GenericResourceApiServicetopologyServiceTopology serviceTopology = null;
1764         GenericResourceApiServicedataServiceData serviceData = null;
1765
1766         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1767         if ((services == null) || (services.isEmpty())) {
1768             throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1769         }
1770
1771         ConfigServices service = services.get(0);
1772
1773         try {
1774             if ( (service.getSvcData() == null) || service.getSvcData().isEmpty()) {
1775                 throw new RestProtocolException("data-missing", "No service-data entry found",
1776                         HttpStatus.NOT_FOUND.value());
1777             } else {
1778                 serviceData = serviceDataHelper.getServiceData(service);
1779                 serviceTopology = serviceData.getServiceTopology();
1780             }
1781             if (serviceTopology == null) {
1782                 throw new RestProtocolException("data-missing", "No service-topology entry found",
1783                         HttpStatus.NOT_FOUND.value());
1784             }
1785             return new ResponseEntity<>(serviceTopology, HttpStatus.OK);
1786         } catch (JsonProcessingException e) {
1787             log.error("Could not parse service data", e);
1788             throw new RestApplicationException("data-conversion",
1789                     "Request could not be completed due to internal error", e,
1790                     HttpStatus.INTERNAL_SERVER_ERROR.value());
1791         }
1792
1793     }
1794
1795     /**
1796      * Extracts VF MODULE data from CONFIG_GRA_SERVICES for a given, service-instance-id, vnf-id, and vf-module-id
1797      * <p>
1798      * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vf-modules/vf-module/{vf-module-id}/
1799      * @param serviceInstanceId the Service Instance ID to lookup data for
1800      * @param vnfId the VNF ID of the VNF to return
1801      * @param vfModuleId the vf-moudle ID of a specific VNF to return
1802      * @return HttpStatus.OK (200) if the data is found.
1803      * @throws RestException if the data does not exist.
1804      */
1805     @Override
1806     public ResponseEntity<GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule>
1807     configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdGet(
1808             String serviceInstanceId, String vnfId, String vfModuleId) throws RestException {
1809
1810         log.info("GET | Vf Module Data for ({})", vfModuleId);
1811
1812
1813         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1814         if((services == null) || (services.isEmpty())) {
1815             throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1816         }
1817
1818         GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule vfModule;
1819         try {
1820             vfModule = serviceDataHelper.getVfModule(serviceInstanceId, vnfId, vfModuleId);
1821         } catch (JsonProcessingException e) {
1822             log.error("Could not parse service data", e);
1823             throw new RestApplicationException("data-conversion",
1824                     "Request could not be completed due to internal error", e,
1825                     HttpStatus.INTERNAL_SERVER_ERROR.value());
1826         }
1827
1828         if(vfModule != null) {
1829             return new ResponseEntity<>(vfModule, HttpStatus.OK);
1830         } else {
1831             log.info("No vf-module found for [{}]", vfModuleId);
1832             throw new RestApplicationException("data-missing",
1833                     "Request could not be completed because the relevant data model content does not exist",
1834                     HttpStatus.NOT_FOUND.value());
1835         }
1836     }
1837
1838     /**
1839      * PUT VF MODULE data into CONFIG_GRA_SERVICES of a given, service-instance-id, vnf-id
1840      * <p>
1841      * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vf-modules/vf-module/{vf-module-id}/
1842      * @param serviceInstanceId the Service Instance ID
1843      * @param vnfId the VNF ID as the parent of the specified vf-module-id and child of the specified service-instance
1844      * @param vfModuleId the vf-moudle ID as a child of the specified VNF
1845      * @return HttpStatus.OK (200) if the data is found.
1846      * @throws RestException if the data does not exist.
1847      */
1848     @Override
1849     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdPut(
1850             String serviceInstanceId, String vnfId, String vfModuleId,
1851             GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule genericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModuleBodyParam)
1852             throws RestException {
1853         log.info("PUT | vf-module Data of ({}) for vnf ({}) in service({})", vfModuleId, vnfId, serviceInstanceId);
1854
1855         if(! vfModuleId.equals(genericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModuleBodyParam.getVfModuleId())) {
1856             throw new RestProtocolException("bad-attribute", "vf-module-id mismatch", HttpStatus.BAD_REQUEST.value());
1857         }
1858
1859
1860         HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1861         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1862
1863         if((services == null) || (services.isEmpty())) {
1864             log.error("service-instance-id ({}) not found in SDN.", serviceInstanceId);
1865             return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1866         } 
1867
1868
1869         GenericResourceApiServicedataServicedataVnfsVnf vnf;
1870         try {
1871             vnf = serviceDataHelper.getVnf(serviceInstanceId, vnfId);
1872         } catch (JsonProcessingException e1) {
1873             log.error("Could not parse service data", e1);
1874             throw new RestApplicationException("data-conversion",
1875                     "Request could not be completed due to internal error", e1,
1876                     HttpStatus.INTERNAL_SERVER_ERROR.value());
1877         }
1878
1879         if(vnf == null) {
1880             log.error("vnf-id ({}) not found in SDN.", vnfId);
1881             return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1882         }
1883
1884         // See if this is the first vf module being added
1885         List<ConfigVfModules> configVfModules = configVfModulesRepository.findBySvcInstanceIdAndVnfId(serviceInstanceId, vnfId);
1886
1887         if ((configVfModules == null) || configVfModules.isEmpty()) {
1888             responseStatus = HttpStatus.CREATED;
1889         }
1890
1891         // Add vf module
1892         try {
1893             serviceDataHelper.saveVfModule(serviceInstanceId, vnfId, genericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModuleBodyParam, null);
1894             return new ResponseEntity<>(responseStatus);
1895         } catch(JsonProcessingException e) {
1896             log.error("Error mapping object to JSON", e);
1897             // Should probably be a 500 INTERNAL_SERVICE_ERROR
1898             return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1899         }
1900     }
1901
1902     /**
1903      * Extracts VF MODULE Topology data from the Config table specified Service
1904      * Instance and VNF ID.
1905      * <p>
1906      * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vf-modules/vf-module/{vf-module-id}/vf-module-data/vf-module-topology/
1907      * @param serviceInstanceId the Service Instance ID to lookup data for
1908      * @param vnfId the VNF ID of the VNF to extract topology data from.
1909      * @param vfModuleId the vf-module-idof the vf-module to extract topology data from.
1910      * @return HttpStatus.OK (200) if the data is found.
1911      * @throws RestException if the data does not exist.
1912      */
1913     @Override
1914     public ResponseEntity<GenericResourceApiVfmoduletopologyVfModuleTopology>
1915     configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdVfModuleDataVfModuleTopologyGet(
1916             String serviceInstanceId, String vnfId, String vfModuleId) throws RestException {
1917         log.info("GET | vf-module-topology for ({})", vfModuleId);
1918
1919         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1920         if((services == null) || (services.isEmpty())) {
1921             throw new RestApplicationException("data-missing",
1922                     "Request could not be completed because the relevant data model content does not exist",
1923                     HttpStatus.NOT_FOUND.value());
1924         }
1925
1926         GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule vfModule;
1927         try {
1928             vfModule = serviceDataHelper.getVfModule(serviceInstanceId, vnfId, vfModuleId);
1929         } catch (JsonProcessingException e) {
1930             log.error("Could not parse service data", e);
1931             throw new RestApplicationException("data-conversion",
1932                     "Request could not be completed due to internal error", e,
1933                     HttpStatus.INTERNAL_SERVER_ERROR.value());
1934         }
1935         if (vfModule != null
1936                 && vfModule.getVfModuleData() != null
1937                 && vfModule.getVfModuleData().getVfModuleTopology() != null) {
1938             return new ResponseEntity<>(vfModule.getVfModuleData().getVfModuleTopology(), HttpStatus.OK);
1939         } else {
1940             log.info("No information found for {}", vfModuleId);
1941             throw new RestApplicationException("data-missing",
1942                     "Request could not be completed because the relevant data model content does not exist",
1943                     HttpStatus.NOT_FOUND.value());
1944         }
1945     }
1946
1947     @Override
1948     public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdDelete(
1949             String serviceInstanceId, String vnfId, String vfModuleId) throws RestProtocolException {
1950
1951         log.info("DELETE | vf-module Data for ({})", vfModuleId);
1952
1953
1954  
1955         List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1956
1957         if((services == null) || (services.isEmpty())) {
1958             log.error("service-instance-id ({}) not found in SDN.", serviceInstanceId);
1959             return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1960         } 
1961
1962
1963
1964         serviceDataHelper.deleteVfModule(serviceInstanceId, vnfId, vfModuleId);
1965         return new ResponseEntity<>(HttpStatus.OK);
1966         
1967     }
1968 }
1969