2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.sdnc.apps.ms.gra.controllers;
23 import com.fasterxml.jackson.annotation.JsonInclude;
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import org.onap.ccsdk.apps.services.RestApplicationException;
27 import org.onap.ccsdk.apps.services.RestException;
28 import org.onap.ccsdk.apps.services.RestProtocolError;
29 import org.onap.ccsdk.apps.services.RestProtocolException;
30 import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadData;
31 import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadDataRepository;
32 import org.onap.sdnc.apps.ms.gra.data.ConfigServices;
33 import org.onap.sdnc.apps.ms.gra.data.ConfigServicesRepository;
34 import org.onap.sdnc.apps.ms.gra.swagger.ConfigApi;
35 import org.onap.sdnc.apps.ms.gra.swagger.model.*;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.boot.autoconfigure.domain.EntityScan;
40 import org.springframework.context.annotation.ComponentScan;
41 import org.springframework.http.HttpStatus;
42 import org.springframework.http.ResponseEntity;
43 import org.springframework.stereotype.Controller;
45 import javax.servlet.http.HttpServletRequest;
46 import javax.validation.Valid;
47 import java.util.Iterator;
48 import java.util.LinkedList;
49 import java.util.List;
50 import java.util.Optional;
51 import java.util.concurrent.atomic.AtomicBoolean;
54 @ComponentScan(basePackages = {"org.onap.sdnc.apps.ms.gra.*"})
55 @EntityScan("org.onap.sdnc.apps.ms.gra.springboot.*")
56 public class ConfigApiController implements ConfigApi {
57 private static final Logger log = LoggerFactory.getLogger(ConfigApiController.class);
59 private final ObjectMapper objectMapper;
61 private final HttpServletRequest request;
64 private ConfigPreloadDataRepository configPreloadDataRepository;
67 private ConfigServicesRepository configServicesRepository;
70 public ConfigApiController(ObjectMapper objectMapper, HttpServletRequest request) {
71 objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
72 objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
73 this.objectMapper = objectMapper;
74 this.request = request;
78 public Optional<ObjectMapper> getObjectMapper() {
79 return Optional.ofNullable(objectMapper);
83 public Optional<HttpServletRequest> getRequest() {
84 return Optional.ofNullable(request);
88 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationDelete() {
89 configPreloadDataRepository.deleteAll();
90 return (new ResponseEntity<>(HttpStatus.NO_CONTENT));
94 public ResponseEntity<GenericResourceApiPreloadModelInformation> configGENERICRESOURCEAPIpreloadInformationGet() throws RestApplicationException {
95 GenericResourceApiPreloadModelInformation genericResourceApiPreloadModelInformation = new GenericResourceApiPreloadModelInformation();
97 if (configPreloadDataRepository.count() == 0) {
98 throw new RestApplicationException("data-missing", "Request could not be completed because the relevant data model content does not exist", HttpStatus.NOT_FOUND.value());
101 for (ConfigPreloadData configPreloadData : configPreloadDataRepository.findAll()) {
102 GenericResourceApiPreloadmodelinformationPreloadList preloadListItem = new GenericResourceApiPreloadmodelinformationPreloadList();
104 preloadListItem.setPreloadId(configPreloadData.getPreloadId());
105 preloadListItem.setPreloadType(configPreloadData.getPreloadType());
107 preloadListItem.setPreloadData(objectMapper.readValue(configPreloadData.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class));
108 } catch (JsonProcessingException e) {
109 log.error("Could not convert preload data", e);
110 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
112 genericResourceApiPreloadModelInformation.addPreloadListItem(preloadListItem);
116 return new ResponseEntity<>(genericResourceApiPreloadModelInformation, HttpStatus.OK);
120 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPost(@Valid GenericResourceApiPreloadModelInformation graPreloadModelInfo) throws RestApplicationException, RestProtocolException {
122 List<GenericResourceApiPreloadmodelinformationPreloadList> preloadList = graPreloadModelInfo.getPreloadList();
123 List<ConfigPreloadData> newPreloadData = new LinkedList<>();
125 if (preloadList != null) {
126 // Verification pass - if any items already exist, return an error
127 for (GenericResourceApiPreloadmodelinformationPreloadList curItem : preloadList) {
129 List<ConfigPreloadData> curPreloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(curItem.getPreloadId(), curItem.getPreloadType());
130 if ((curPreloadData != null) && (!curPreloadData.isEmpty())) {
131 log.error("Preload data already exists for {}:{}", curItem.getPreloadId(), curItem.getPreloadType());
132 throw new RestProtocolException("data-exists", "Data already exists for " + curItem.getPreloadId() + ":" + curItem.getPreloadType(), HttpStatus.CONFLICT.value());
135 newPreloadData.add(new ConfigPreloadData(curItem.getPreloadId(), curItem.getPreloadType(), objectMapper.writeValueAsString(curItem.getPreloadData())));
136 } catch (JsonProcessingException e) {
137 log.error("Cannot convert preload data");
138 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
145 for (ConfigPreloadData newDataItem : newPreloadData) {
146 log.info("Adding preload data for {}:{}", newDataItem.getPreloadId(), newDataItem.getPreloadType());
147 configPreloadDataRepository.save(newDataItem);
150 throw new RestProtocolException("data-missing", "No preload-list entries found to add", HttpStatus.CONFLICT.value());
153 return new ResponseEntity<>(HttpStatus.CREATED);
157 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPut(@Valid GenericResourceApiPreloadModelInformation graPreloadModelInfo) throws RestApplicationException {
159 boolean addedNew = false;
160 List<GenericResourceApiPreloadmodelinformationPreloadList> preloadList = graPreloadModelInfo.getPreloadList();
162 if (preloadList != null) {
163 Iterator<GenericResourceApiPreloadmodelinformationPreloadList> iter = preloadList.iterator();
164 while (iter.hasNext()) {
165 GenericResourceApiPreloadmodelinformationPreloadList curItem = iter.next();
166 List<ConfigPreloadData> curPreloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(curItem.getPreloadId(), curItem.getPreloadType());
167 if ((curPreloadData == null) || curPreloadData.isEmpty()) {
172 configPreloadDataRepository.save(new ConfigPreloadData(curItem.getPreloadId(), curItem.getPreloadType(), objectMapper.writeValueAsString(curItem.getPreloadData())));
173 } catch (JsonProcessingException e) {
174 log.error("Cannot convert preload data", e);
175 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
182 return new ResponseEntity<>(HttpStatus.CREATED);
184 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
190 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPost(@Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) throws RestProtocolException {
192 throw new RestProtocolException("data-missing", "Missing key for list \"preload-list\"", HttpStatus.NOT_FOUND.value());
197 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeDelete(String preloadId, String preloadType) {
198 configPreloadDataRepository.deleteByPreloadIdAndPreloadType(preloadId, preloadType);
199 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
203 public ResponseEntity<GenericResourceApiPreloadmodelinformationPreloadList> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeGet(String preloadId, String preloadType) throws RestApplicationException {
204 List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
205 if (preloadData != null) {
206 if (!preloadData.isEmpty()) {
207 ConfigPreloadData preloadDataItem = preloadData.get(0);
208 GenericResourceApiPreloadmodelinformationPreloadList preloadDataList = new GenericResourceApiPreloadmodelinformationPreloadList();
209 preloadDataList.setPreloadId(preloadDataItem.getPreloadId());
210 preloadDataList.setPreloadType(preloadDataItem.getPreloadType());
212 preloadDataList.setPreloadData(objectMapper.readValue(preloadDataItem.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class));
213 } catch (JsonProcessingException e) {
214 log.error("Cannot convert preload data", e);
215 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
217 return new ResponseEntity<>(preloadDataList, HttpStatus.OK);
220 return new ResponseEntity<>(HttpStatus.NOT_FOUND);
224 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypePost(String preloadId, String preloadType, @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) throws RestApplicationException, RestProtocolException {
225 List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
227 if ((preloadDataItems != null) && !preloadDataItems.isEmpty()) {
228 log.error("Preload data already exists for {}:{}", preloadId, preloadType);
229 throw new RestProtocolException("data-exists", "Data already exists for " + preloadId + ":" + preloadType, HttpStatus.CONFLICT.value());
233 log.info("Adding preload data for {}:{}", preloadId, preloadType);
234 configPreloadDataRepository.save(new ConfigPreloadData(preloadId, preloadType, objectMapper.writeValueAsString(preloadListItem.getPreloadData())));
235 } catch (JsonProcessingException e) {
236 log.error("Cannot convert preload data", e);
237 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
240 return new ResponseEntity<>(HttpStatus.CREATED);
244 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypePut(String preloadId, String preloadType, @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) throws RestApplicationException, RestProtocolException {
245 List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
246 boolean dataExists = false;
247 if ((preloadDataItems != null) && !preloadDataItems.isEmpty()) {
251 if ((preloadListItem.getPreloadId() == null) ||
252 (preloadListItem.getPreloadType() == null) ||
253 (preloadListItem.getPreloadData() == null)) {
254 log.error("Invalid list item received: {}", preloadListItem);
255 throw new RestProtocolException("bad-attribute", "Invalid data received", HttpStatus.BAD_REQUEST.value());
260 log.info("Updating preload data for {}:{} -> {}", preloadId, preloadType, objectMapper.writeValueAsString(preloadListItem));
263 log.info("Adding preload data for {}:{}", preloadId, preloadType);
266 configPreloadDataRepository.save(new ConfigPreloadData(preloadId, preloadType, objectMapper.writeValueAsString(preloadListItem.getPreloadData())));
267 } catch (JsonProcessingException e) {
268 log.error("Cannot convert preload data", e);
269 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
274 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
276 return new ResponseEntity<>(HttpStatus.CREATED);
282 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeGENERICRESOURCEAPIpreloadDataDelete(String preloadId, String preloadType) throws RestProtocolException {
283 List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
285 if ((preloadData == null) || preloadData.isEmpty()) {
286 throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
289 ConfigPreloadData preloadDataItem = preloadData.get(0);
291 if (preloadDataItem.getPreloadData() == null) {
292 throw new RestProtocolException("data-missing", "No preload-data found", HttpStatus.NOT_FOUND.value());
294 preloadDataItem.setPreloadData(null);
295 configPreloadDataRepository.save(preloadDataItem);
298 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
303 public ResponseEntity<GenericResourceApiPreloaddataPreloadData> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeGENERICRESOURCEAPIpreloadDataGet(String preloadId, String preloadType) throws RestApplicationException, RestProtocolException {
304 List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
306 if ((preloadData == null) || preloadData.isEmpty()) {
307 throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
310 ConfigPreloadData preloadDataItem = preloadData.get(0);
312 if (preloadDataItem.getPreloadData() == null) {
313 throw new RestProtocolException("data-missing", "No preload-data found", HttpStatus.NOT_FOUND.value());
316 return new ResponseEntity<>(objectMapper.readValue(preloadDataItem.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class), HttpStatus.OK);
317 } catch (JsonProcessingException e) {
318 log.error("Cannot convert preload data", e);
319 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
324 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeGENERICRESOURCEAPIpreloadDataPost(String preloadId, String preloadType, @Valid GenericResourceApiPreloaddataPreloadData preloadData) throws RestApplicationException, RestProtocolException {
325 List<ConfigPreloadData> preloadDataEntries = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
327 List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
328 if ((preloadDataItems == null) || (preloadDataItems.isEmpty())) {
329 throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
332 if ((preloadData == null) ||
333 (preloadData.getPreloadNetworkTopologyInformation() == null)) {
334 throw new RestProtocolException("bad-attribute", "Invalid preloadData received", HttpStatus.BAD_REQUEST.value());
337 ConfigPreloadData preloadDataItem = preloadDataItems.get(0);
339 if (preloadDataItem.getPreloadData() != null) {
340 log.error("Preload data already exists for {}:{} ", preloadId, preloadType);
341 throw new RestProtocolException("data-exists", "Data already exists for " + preloadId + ":" + preloadType, HttpStatus.CONFLICT.value());
345 preloadDataItem.setPreloadData(objectMapper.writeValueAsString(preloadData));
346 configPreloadDataRepository.save(preloadDataItem);
347 } catch (JsonProcessingException e) {
348 log.error("Cannot convert preload data", e);
349 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
352 return new ResponseEntity<>(HttpStatus.CREATED);
356 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeGENERICRESOURCEAPIpreloadDataPut(String preloadId, String preloadType, @Valid GenericResourceApiPreloaddataPreloadData preloadData) throws RestApplicationException, RestProtocolException {
357 boolean dataExists = false;
358 List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
359 if ((preloadDataItems == null) || (preloadDataItems.isEmpty())) {
360 throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
363 if ((preloadData == null) ||
364 (preloadData.getPreloadNetworkTopologyInformation() == null)) {
365 throw new RestProtocolException("bad-attribute", "Invalid preloadData received", HttpStatus.BAD_REQUEST.value());
368 ConfigPreloadData preloadDataItem = preloadDataItems.get(0);
370 if (preloadDataItem.getPreloadData() != null) {
375 preloadDataItem.setPreloadData(objectMapper.writeValueAsString(preloadData));
376 configPreloadDataRepository.save(preloadDataItem);
377 } catch (JsonProcessingException e) {
378 log.error("Cannot convert preload data", e);
379 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
383 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
385 return new ResponseEntity<>(HttpStatus.CREATED);
390 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesDelete() {
391 configServicesRepository.deleteAll();
392 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
396 public ResponseEntity<GenericResourceApiServiceModelInfrastructure> configGENERICRESOURCEAPIservicesGet() throws RestApplicationException {
397 GenericResourceApiServiceModelInfrastructure modelInfrastructure = new GenericResourceApiServiceModelInfrastructure();
399 if (configServicesRepository.count() == 0) {
400 throw new RestApplicationException("data-missing", "Request could not be completed because the relevant data model content does not exist", HttpStatus.NOT_FOUND.value());
403 for (ConfigServices service : configServicesRepository.findAll()) {
404 GenericResourceApiServicemodelinfrastructureService serviceItem = new GenericResourceApiServicemodelinfrastructureService();
405 serviceItem.setServiceInstanceId(service.getSvcInstanceId());
407 serviceItem.setServiceData(objectMapper.readValue(service.getSvcData(), GenericResourceApiServicedataServiceData.class));
408 } catch (JsonProcessingException e) {
409 log.error("Could not deserialize service data for {}", service.getSvcInstanceId(), e);
410 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
413 serviceItem.setServiceStatus(service.getServiceStatus());
414 modelInfrastructure.addServiceItem(serviceItem);
418 return new ResponseEntity<>(modelInfrastructure, HttpStatus.OK);
423 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPost(@Valid GenericResourceApiServiceModelInfrastructure modelInfrastructure) throws RestApplicationException, RestProtocolException {
424 List<ConfigServices> newServices = new LinkedList<>();
426 for (GenericResourceApiServicemodelinfrastructureService serviceItem : modelInfrastructure.getService()) {
427 String svcInstanceId = serviceItem.getServiceInstanceId();
428 List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
429 if ((existingService != null) && !existingService.isEmpty()) {
430 log.error("Service data already exists for {}", svcInstanceId);
431 throw new RestProtocolException("data-exists", "Data already exists for service-instance-id " + svcInstanceId, HttpStatus.CONFLICT.value());
433 ConfigServices service = new ConfigServices();
434 service.setSvcInstanceId(svcInstanceId);
436 service.setSvcData(objectMapper.writeValueAsString(serviceItem.getServiceData()));
437 } catch (JsonProcessingException e) {
438 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
439 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
442 service.setServiceStatus(serviceItem.getServiceStatus());
443 newServices.add(service);
446 for (ConfigServices service : newServices) {
447 configServicesRepository.save(service);
450 return new ResponseEntity<>(HttpStatus.CREATED);
455 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPut(@Valid GenericResourceApiServiceModelInfrastructure modelInfrastructure) throws RestApplicationException {
457 List<ConfigServices> newServices = new LinkedList<>();
458 boolean dataExists = false;
460 for (GenericResourceApiServicemodelinfrastructureService serviceItem : modelInfrastructure.getService()) {
461 String svcInstanceId = serviceItem.getServiceInstanceId();
462 List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
463 if ((existingService != null) && !existingService.isEmpty()) {
466 ConfigServices service = new ConfigServices();
467 service.setSvcInstanceId(svcInstanceId);
469 service.setSvcData(objectMapper.writeValueAsString(serviceItem.getServiceData()));
470 } catch (JsonProcessingException e) {
471 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
472 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
475 service.setServiceStatus(serviceItem.getServiceStatus());
476 newServices.add(service);
479 for (ConfigServices service : newServices) {
480 configServicesRepository.save(service);
484 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
486 return new ResponseEntity<>(HttpStatus.CREATED);
492 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIservicePost(@Valid GenericResourceApiServicemodelinfrastructureService servicesData) throws RestApplicationException {
493 String svcInstanceId = servicesData.getServiceInstanceId();
495 String svcData = objectMapper.writeValueAsString(servicesData.getServiceData());
496 ConfigServices configService = new ConfigServices(svcInstanceId, svcData, servicesData.getServiceStatus());
497 configServicesRepository.deleteBySvcInstanceId(svcInstanceId);
498 configServicesRepository.save(configService);
499 } catch (JsonProcessingException e) {
500 log.error("Cannot convert service data", e);
501 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
504 return new ResponseEntity<>(HttpStatus.OK);
508 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdDelete(String serviceInstanceId) {
509 configServicesRepository.deleteBySvcInstanceId(serviceInstanceId);
510 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
514 public ResponseEntity<GenericResourceApiServicemodelinfrastructureService> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGet(String serviceInstanceId) throws RestApplicationException {
515 GenericResourceApiServicemodelinfrastructureService retval = null;
517 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
519 if (services.isEmpty()) {
520 return new ResponseEntity<>(HttpStatus.NOT_FOUND);
522 ConfigServices service = services.get(0);
523 retval = new GenericResourceApiServicemodelinfrastructureService();
524 retval.setServiceInstanceId(serviceInstanceId);
525 retval.setServiceStatus(service.getServiceStatus());
527 retval.setServiceData(objectMapper.readValue(service.getSvcData(), GenericResourceApiServicedataServiceData.class));
528 } catch (JsonProcessingException e) {
529 log.error("Could not deserialize service data for service instance id {}", serviceInstanceId, e);
530 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
536 return new ResponseEntity<>(retval, HttpStatus.OK);
541 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdPost(String svcInstanceId, @Valid GenericResourceApiServicemodelinfrastructureService newService) throws RestApplicationException, RestProtocolException {
543 List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
544 if ((existingService != null) && !existingService.isEmpty()) {
545 log.error("Service data already exists for {}", svcInstanceId);
546 throw new RestProtocolException("data-exists", "Data already exists for service-instance-id " + svcInstanceId, HttpStatus.CONFLICT.value());
548 ConfigServices service = new ConfigServices();
549 service.setSvcInstanceId(svcInstanceId);
551 service.setSvcData(objectMapper.writeValueAsString(newService.getServiceData()));
552 } catch (JsonProcessingException e) {
553 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
554 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
557 service.setServiceStatus(newService.getServiceStatus());
558 configServicesRepository.save(service);
560 return new ResponseEntity<>(HttpStatus.CREATED);
564 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdPut(String serviceInstanceId, @Valid GenericResourceApiServicemodelinfrastructureService newService) throws RestApplicationException {
566 boolean dataExists = false;
568 String svcInstanceId = newService.getServiceInstanceId();
570 ConfigServices service = null;
571 List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
572 if ((existingService != null) && !existingService.isEmpty()) {
574 service = existingService.get(0);
576 service = new ConfigServices();
577 service.setSvcInstanceId(svcInstanceId);
581 service.setSvcData(objectMapper.writeValueAsString(newService.getServiceData()));
582 } catch (JsonProcessingException e) {
583 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
584 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
587 service.setServiceStatus(newService.getServiceStatus());
588 configServicesRepository.save(service);
591 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
593 return new ResponseEntity<>(HttpStatus.CREATED);
599 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataDelete(String serviceInstanceId) throws RestProtocolException {
600 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
602 if ((services == null) || (services.isEmpty())) {
603 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
606 ConfigServices service = services.get(0);
607 if (service.getSvcData() == null) {
608 throw new RestProtocolException("data-missing", "No service-data found", HttpStatus.NOT_FOUND.value());
610 service.setSvcData(null);
611 configServicesRepository.save(service);
613 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
617 public ResponseEntity<GenericResourceApiServicedataServiceData> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataGet(String serviceInstanceId) throws RestApplicationException, RestProtocolException {
618 GenericResourceApiServicedataServiceData serviceData = null;
620 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
621 if ((services == null) || (services.isEmpty())) {
622 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
626 serviceData = objectMapper.readValue(services.get(0).getSvcData(), GenericResourceApiServicedataServiceData.class);
627 return new ResponseEntity<>(serviceData, HttpStatus.OK);
628 } catch (JsonProcessingException e) {
629 log.error("Could not parse service data", e);
630 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
636 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataPost(String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData serviceData) throws RestApplicationException, RestProtocolException {
637 ConfigServices service;
638 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
639 if ((services == null) || (services.isEmpty())) {
640 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
643 if ((serviceData == null) ||
644 (serviceData.getServiceInformation() == null)) {
645 throw new RestProtocolException("bad-attribute", "Invalid service-data received", HttpStatus.BAD_REQUEST.value());
648 service = services.get(0);
650 if ((service.getSvcData() != null) && (service.getSvcData().length() > 0)){
651 log.error("service-data already exists for svcInstanceId {}", serviceInstanceId);
652 throw new RestProtocolException("data-exists", "Data already exists for " + serviceInstanceId, HttpStatus.CONFLICT.value());
657 service.setSvcData(objectMapper.writeValueAsString(serviceData));
658 configServicesRepository.save(service);
659 } catch (JsonProcessingException e) {
660 log.error("Could not serialize service data for svc instance id {}", serviceInstanceId, e);
661 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
665 return new ResponseEntity<>(HttpStatus.CREATED);
670 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataPut(String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData serviceData) throws RestApplicationException, RestProtocolException {
671 ConfigServices service;
672 boolean dataExists = false;
674 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
675 if ((services == null) || (services.isEmpty())) {
676 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
679 if ((serviceData == null) ||
680 (serviceData.getServiceInformation() == null)) {
681 throw new RestProtocolException("bad-attribute", "Invalid service-data received", HttpStatus.BAD_REQUEST.value());
684 service = services.get(0);
686 if ((service.getSvcData() != null) && (service.getSvcData().length() > 0)) {
691 service.setSvcData(objectMapper.writeValueAsString(serviceData));
692 configServicesRepository.save(service);
693 } catch (JsonProcessingException e) {
694 log.error("Could not serialize service data for svc instance id {}", serviceInstanceId, e);
695 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
699 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
701 return new ResponseEntity<>(HttpStatus.CREATED);
706 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusDelete(String serviceInstanceId) throws RestProtocolException {
707 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
709 if ((services == null) || (services.isEmpty())) {
710 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
713 ConfigServices service = services.get(0);
714 if (service.getServiceStatus() == null) {
715 throw new RestProtocolException("data-missing", "No service-status found", HttpStatus.NOT_FOUND.value());
717 service.setServiceStatus(null);
718 configServicesRepository.save(service);
720 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
725 public ResponseEntity<GenericResourceApiServicestatusServiceStatus> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusGet(String serviceInstanceId) throws RestApplicationException, RestProtocolException {
726 GenericResourceApiServicestatusServiceStatus serviceStatus = null;
728 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
729 if ((services == null) || (services.isEmpty())) {
730 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
733 serviceStatus = services.get(0).getServiceStatus();
734 return new ResponseEntity<>(serviceStatus, HttpStatus.OK);
738 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusPost(String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus serviceStatus) throws RestProtocolException {
739 ConfigServices service;
740 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
741 if ((services == null) || (services.isEmpty())) {
742 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
745 if ((serviceStatus == null) ||
746 (serviceStatus.getAction() == null)) {
747 throw new RestProtocolException("bad-attribute", "Invalid service-status received", HttpStatus.BAD_REQUEST.value());
750 service = services.get(0);
752 if (service.getServiceStatus() != null) {
753 log.error("service-status already exists for svcInstanceId {}", serviceInstanceId);
754 throw new RestProtocolException("data-exists", "Data already exists for " + serviceInstanceId, HttpStatus.CONFLICT.value());
758 service.setServiceStatus(serviceStatus);
759 configServicesRepository.save(service);
762 return new ResponseEntity<>(HttpStatus.CREATED);
767 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusPut(String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus serviceStatus) throws RestProtocolException {
768 ConfigServices service;
769 boolean dataExists = false;
771 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
772 if ((services == null) || (services.isEmpty())) {
773 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
776 if ((serviceStatus == null) ||
777 (serviceStatus.getAction() == null)) {
778 throw new RestProtocolException("bad-attribute", "Invalid service-status received", HttpStatus.BAD_REQUEST.value());
781 service = services.get(0);
783 if (service.getServiceStatus() != null) {
788 service.setServiceStatus(serviceStatus);
789 configServicesRepository.save(service);
792 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
794 return new ResponseEntity<>(HttpStatus.CREATED);