summaryrefslogtreecommitdiffstats
path: root/ms/generic-resource-api/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'ms/generic-resource-api/src/main')
-rwxr-xr-xms/generic-resource-api/src/main/dc/docker-compose.yaml3
-rw-r--r--ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiController.java647
-rw-r--r--ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/OperationalApiController.java213
-rw-r--r--ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/core/GenericResourceMsApp.java2
-rw-r--r--ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/core/WebConfig.java2
-rw-r--r--ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/ConfigPreloadData.java1
-rw-r--r--ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/ConfigServices.java37
-rw-r--r--ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/OperationalPreloadData.java1
-rw-r--r--ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/OperationalServices.java7
-rw-r--r--ms/generic-resource-api/src/main/resources/startGra.sh35
-rw-r--r--ms/generic-resource-api/src/main/templates/api.mustache136
11 files changed, 961 insertions, 123 deletions
diff --git a/ms/generic-resource-api/src/main/dc/docker-compose.yaml b/ms/generic-resource-api/src/main/dc/docker-compose.yaml
index da3d98d..9d85c39 100755
--- a/ms/generic-resource-api/src/main/dc/docker-compose.yaml
+++ b/ms/generic-resource-api/src/main/dc/docker-compose.yaml
@@ -9,6 +9,9 @@ services:
environment:
- MYSQL_ROOT_PASSWORD=openECOMP1.0
- MYSQL_ROOT_HOST=%
+ - MYSQL_USER=sdnc
+ - MYSQL_PASSWORD=abc123
+ - MYSQL_DATABASE=sdnctl
logging:
driver: "json-file"
options:
diff --git a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiController.java b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiController.java
index 59d082b..e3d084e 100644
--- a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiController.java
+++ b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiController.java
@@ -23,6 +23,10 @@ package org.onap.sdnc.apps.ms.gra.controllers;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.onap.ccsdk.apps.services.RestApplicationException;
+import org.onap.ccsdk.apps.services.RestException;
+import org.onap.ccsdk.apps.services.RestProtocolError;
+import org.onap.ccsdk.apps.services.RestProtocolException;
import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadData;
import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadDataRepository;
import org.onap.sdnc.apps.ms.gra.data.ConfigServices;
@@ -41,8 +45,10 @@ import org.springframework.stereotype.Controller;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
+import java.util.concurrent.atomic.AtomicBoolean;
@Controller
@ComponentScan(basePackages = {"org.onap.sdnc.apps.ms.gra.*"})
@@ -81,14 +87,18 @@ public class ConfigApiController implements ConfigApi {
@Override
public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationDelete() {
configPreloadDataRepository.deleteAll();
- return (new ResponseEntity<>(HttpStatus.OK));
+ return (new ResponseEntity<>(HttpStatus.NO_CONTENT));
}
@Override
- public ResponseEntity<GenericResourceApiPreloadModelInformation> configGENERICRESOURCEAPIpreloadInformationGet() {
+ public ResponseEntity<GenericResourceApiPreloadModelInformation> configGENERICRESOURCEAPIpreloadInformationGet() throws RestApplicationException {
GenericResourceApiPreloadModelInformation genericResourceApiPreloadModelInformation = new GenericResourceApiPreloadModelInformation();
- configPreloadDataRepository.findAll().forEach(configPreloadData -> {
+ if (configPreloadDataRepository.count() == 0) {
+ throw new RestApplicationException("data-missing", "Request could not be completed because the relevant data model content does not exist", HttpStatus.NOT_FOUND.value());
+ }
+
+ for (ConfigPreloadData configPreloadData : configPreloadDataRepository.findAll()) {
GenericResourceApiPreloadmodelinformationPreloadList preloadListItem = new GenericResourceApiPreloadmodelinformationPreloadList();
preloadListItem.setPreloadId(configPreloadData.getPreloadId());
@@ -97,60 +107,100 @@ public class ConfigApiController implements ConfigApi {
preloadListItem.setPreloadData(objectMapper.readValue(configPreloadData.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class));
} catch (JsonProcessingException e) {
log.error("Could not convert preload data", e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
}
genericResourceApiPreloadModelInformation.addPreloadListItem(preloadListItem);
- });
+ }
return new ResponseEntity<>(genericResourceApiPreloadModelInformation, HttpStatus.OK);
}
@Override
- public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPost(@Valid GenericResourceApiPreloadModelInformation graPreloadModelInfo) {
+ public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPost(@Valid GenericResourceApiPreloadModelInformation graPreloadModelInfo) throws RestApplicationException, RestProtocolException {
+
+ List<GenericResourceApiPreloadmodelinformationPreloadList> preloadList = graPreloadModelInfo.getPreloadList();
+ List<ConfigPreloadData> newPreloadData = new LinkedList<>();
+
+ if (preloadList != null) {
+ // Verification pass - if any items already exist, return an error
+ for (GenericResourceApiPreloadmodelinformationPreloadList curItem : preloadList) {
+
+ List<ConfigPreloadData> curPreloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(curItem.getPreloadId(), curItem.getPreloadType());
+ if ((curPreloadData != null) && (!curPreloadData.isEmpty())) {
+ log.error("Preload data already exists for {}:{}", curItem.getPreloadId(), curItem.getPreloadType());
+ throw new RestProtocolException("data-exists", "Data already exists for " + curItem.getPreloadId() + ":" + curItem.getPreloadType(), HttpStatus.CONFLICT.value());
+ } else {
+ try {
+ newPreloadData.add(new ConfigPreloadData(curItem.getPreloadId(), curItem.getPreloadType(), objectMapper.writeValueAsString(curItem.getPreloadData())));
+ } catch (JsonProcessingException e) {
+ log.error("Cannot convert preload data");
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
+
+ }
+ }
+ }
+
+ // Update pass
+ for (ConfigPreloadData newDataItem : newPreloadData) {
+ log.info("Adding preload data for {}:{}", newDataItem.getPreloadId(), newDataItem.getPreloadType());
+ configPreloadDataRepository.save(newDataItem);
+ }
+ } else {
+ throw new RestProtocolException("data-missing", "No preload-list entries found to add", HttpStatus.CONFLICT.value());
+ }
+
+ return new ResponseEntity<>(HttpStatus.CREATED);
+ }
+
+ @Override
+ public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPut(@Valid GenericResourceApiPreloadModelInformation graPreloadModelInfo) throws RestApplicationException {
+ boolean addedNew = false;
List<GenericResourceApiPreloadmodelinformationPreloadList> preloadList = graPreloadModelInfo.getPreloadList();
if (preloadList != null) {
Iterator<GenericResourceApiPreloadmodelinformationPreloadList> iter = preloadList.iterator();
while (iter.hasNext()) {
GenericResourceApiPreloadmodelinformationPreloadList curItem = iter.next();
-
- // Remove any entries already existing for this preloadId/preloadType
- configPreloadDataRepository.deleteByPreloadIdAndPreloadType(curItem.getPreloadId(), curItem.getPreloadType());
+ List<ConfigPreloadData> curPreloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(curItem.getPreloadId(), curItem.getPreloadType());
+ if ((curPreloadData == null) || curPreloadData.isEmpty()) {
+ addedNew = true;
+ }
try {
configPreloadDataRepository.save(new ConfigPreloadData(curItem.getPreloadId(), curItem.getPreloadType(), objectMapper.writeValueAsString(curItem.getPreloadData())));
} catch (JsonProcessingException e) {
log.error("Cannot convert preload data", e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
+
}
}
}
- return new ResponseEntity<>(HttpStatus.OK);
+ if (addedNew) {
+ return new ResponseEntity<>(HttpStatus.CREATED);
+ } else {
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+ }
+
}
@Override
- public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPost(@Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) {
+ public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPost(@Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) throws RestProtocolException {
- // Remove any entries already existing for this preloadId/preloadType
- configPreloadDataRepository.deleteByPreloadIdAndPreloadType(preloadListItem.getPreloadId(), preloadListItem.getPreloadType());
-
- try {
- configPreloadDataRepository.save(new ConfigPreloadData(preloadListItem.getPreloadId(), preloadListItem.getPreloadType(), objectMapper.writeValueAsString(preloadListItem.getPreloadData())));
- } catch (JsonProcessingException e) {
- log.error("Cannot convert preload data", e);
- }
- return new ResponseEntity<>(HttpStatus.OK);
+ throw new RestProtocolException("data-missing", "Missing key for list \"preload-list\"", HttpStatus.NOT_FOUND.value());
}
+
@Override
public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeDelete(String preloadId, String preloadType) {
configPreloadDataRepository.deleteByPreloadIdAndPreloadType(preloadId, preloadType);
- return new ResponseEntity<>(HttpStatus.OK);
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Override
- public ResponseEntity<GenericResourceApiPreloadmodelinformationPreloadList> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeGet(String preloadId, String preloadType) {
+ public ResponseEntity<GenericResourceApiPreloadmodelinformationPreloadList> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeGet(String preloadId, String preloadType) throws RestApplicationException {
List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
if (preloadData != null) {
if (!preloadData.isEmpty()) {
@@ -162,6 +212,7 @@ public class ConfigApiController implements ConfigApi {
preloadDataList.setPreloadData(objectMapper.readValue(preloadDataItem.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class));
} catch (JsonProcessingException e) {
log.error("Cannot convert preload data", e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
}
return new ResponseEntity<>(preloadDataList, HttpStatus.OK);
}
@@ -170,71 +221,275 @@ public class ConfigApiController implements ConfigApi {
}
@Override
- public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypePost(String preloadId, String preloadType, @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) {
- configPreloadDataRepository.deleteByPreloadIdAndPreloadType(preloadId, preloadType);
+ public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypePost(String preloadId, String preloadType, @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) throws RestApplicationException, RestProtocolException {
+ List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
+
+ if ((preloadDataItems != null) && !preloadDataItems.isEmpty()) {
+ log.error("Preload data already exists for {}:{}", preloadId, preloadType);
+ throw new RestProtocolException("data-exists", "Data already exists for " + preloadId + ":" + preloadType, HttpStatus.CONFLICT.value());
+ }
+
try {
+ log.info("Adding preload data for {}:{}", preloadId, preloadType);
configPreloadDataRepository.save(new ConfigPreloadData(preloadId, preloadType, objectMapper.writeValueAsString(preloadListItem.getPreloadData())));
} catch (JsonProcessingException e) {
log.error("Cannot convert preload data", e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
+
}
- return new ResponseEntity<>(HttpStatus.OK);
+ return new ResponseEntity<>(HttpStatus.CREATED);
}
-
@Override
- public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeGENERICRESOURCEAPIpreloadDataDelete(String preloadId, String preloadType) {
- List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
+ public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypePut(String preloadId, String preloadType, @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) throws RestApplicationException, RestProtocolException {
+ List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
+ boolean dataExists = false;
+ if ((preloadDataItems != null) && !preloadDataItems.isEmpty()) {
+ dataExists = true;
+ }
- if (preloadData != null) {
- Iterator<ConfigPreloadData> iter = preloadData.iterator();
+ if ((preloadListItem.getPreloadId() == null) ||
+ (preloadListItem.getPreloadType() == null) ||
+ (preloadListItem.getPreloadData() == null)) {
+ log.error("Invalid list item received: {}", preloadListItem);
+ throw new RestProtocolException("bad-attribute", "Invalid data received", HttpStatus.BAD_REQUEST.value());
+ }
- while (iter.hasNext()) {
- configPreloadDataRepository.delete(iter.next());
+ try {
+ if (dataExists) {
+ log.info("Updating preload data for {}:{} -> {}", preloadId, preloadType, objectMapper.writeValueAsString(preloadListItem));
+
+ } else {
+ log.info("Adding preload data for {}:{}", preloadId, preloadType);
}
+
+ configPreloadDataRepository.save(new ConfigPreloadData(preloadId, preloadType, objectMapper.writeValueAsString(preloadListItem.getPreloadData())));
+ } catch (JsonProcessingException e) {
+ log.error("Cannot convert preload data", e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
+
+ }
+
+ if (dataExists) {
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+ } else {
+ return new ResponseEntity<>(HttpStatus.CREATED);
}
- return new ResponseEntity<>(HttpStatus.OK);
}
+
@Override
- public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPut(@Valid GenericResourceApiPreloadModelInformation genericResourceApiPreloadModelInformationBodyParam) {
- return null;
+ public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeGENERICRESOURCEAPIpreloadDataDelete(String preloadId, String preloadType) throws RestProtocolException {
+ List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
+
+ if ((preloadData == null) || preloadData.isEmpty()) {
+ throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
+ }
+
+ ConfigPreloadData preloadDataItem = preloadData.get(0);
+
+ if (preloadDataItem.getPreloadData() == null) {
+ throw new RestProtocolException("data-missing", "No preload-data found", HttpStatus.NOT_FOUND.value());
+ }
+ preloadDataItem.setPreloadData(null);
+ configPreloadDataRepository.save(preloadDataItem);
+
+
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
+
@Override
- public ResponseEntity<GenericResourceApiPreloaddataPreloadData> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeGENERICRESOURCEAPIpreloadDataGet(String preloadId, String preloadType) {
+ public ResponseEntity<GenericResourceApiPreloaddataPreloadData> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeGENERICRESOURCEAPIpreloadDataGet(String preloadId, String preloadType) throws RestApplicationException, RestProtocolException {
List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
- if (preloadData != null) {
- if (!preloadData.isEmpty()) {
- ConfigPreloadData preloadDataItem = preloadData.get(0);
- try {
- return new ResponseEntity<>(objectMapper.readValue(preloadDataItem.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class), HttpStatus.OK);
- } catch (JsonProcessingException e) {
- log.error("Cannot convert preload data", e);
- }
- }
+
+ if ((preloadData == null) || preloadData.isEmpty()) {
+ throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
+ }
+
+ ConfigPreloadData preloadDataItem = preloadData.get(0);
+
+ if (preloadDataItem.getPreloadData() == null) {
+ throw new RestProtocolException("data-missing", "No preload-data found", HttpStatus.NOT_FOUND.value());
+ }
+ try {
+ return new ResponseEntity<>(objectMapper.readValue(preloadDataItem.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class), HttpStatus.OK);
+ } catch (JsonProcessingException e) {
+ log.error("Cannot convert preload data", e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
}
- return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
@Override
- public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeGENERICRESOURCEAPIpreloadDataPost(String preloadId, String preloadType, @Valid GenericResourceApiPreloaddataPreloadData preloadData) {
- configPreloadDataRepository.deleteByPreloadIdAndPreloadType(preloadId, preloadType);
+ public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeGENERICRESOURCEAPIpreloadDataPost(String preloadId, String preloadType, @Valid GenericResourceApiPreloaddataPreloadData preloadData) throws RestApplicationException, RestProtocolException {
+ List<ConfigPreloadData> preloadDataEntries = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
+
+ List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
+ if ((preloadDataItems == null) || (preloadDataItems.isEmpty())) {
+ throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
+ }
+
+ if ((preloadData == null) ||
+ (preloadData.getPreloadNetworkTopologyInformation() == null)) {
+ throw new RestProtocolException("bad-attribute", "Invalid preloadData received", HttpStatus.BAD_REQUEST.value());
+ }
+
+ ConfigPreloadData preloadDataItem = preloadDataItems.get(0);
+
+ if (preloadDataItem.getPreloadData() != null) {
+ log.error("Preload data already exists for {}:{} ", preloadId, preloadType);
+ throw new RestProtocolException("data-exists", "Data already exists for " + preloadId + ":" + preloadType, HttpStatus.CONFLICT.value());
+ }
+
try {
- configPreloadDataRepository.save(new ConfigPreloadData(preloadId, preloadType, objectMapper.writeValueAsString(preloadData)));
+ preloadDataItem.setPreloadData(objectMapper.writeValueAsString(preloadData));
+ configPreloadDataRepository.save(preloadDataItem);
} catch (JsonProcessingException e) {
log.error("Cannot convert preload data", e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
+ }
+
+ return new ResponseEntity<>(HttpStatus.CREATED);
+ }
+
+ @Override
+ public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeGENERICRESOURCEAPIpreloadDataPut(String preloadId, String preloadType, @Valid GenericResourceApiPreloaddataPreloadData preloadData) throws RestApplicationException, RestProtocolException {
+ boolean dataExists = false;
+ List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
+ if ((preloadDataItems == null) || (preloadDataItems.isEmpty())) {
+ throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
+ }
+
+ if ((preloadData == null) ||
+ (preloadData.getPreloadNetworkTopologyInformation() == null)) {
+ throw new RestProtocolException("bad-attribute", "Invalid preloadData received", HttpStatus.BAD_REQUEST.value());
+ }
+
+ ConfigPreloadData preloadDataItem = preloadDataItems.get(0);
+
+ if (preloadDataItem.getPreloadData() != null) {
+ dataExists = true;
+ }
+
+ try {
+ preloadDataItem.setPreloadData(objectMapper.writeValueAsString(preloadData));
+ configPreloadDataRepository.save(preloadDataItem);
+ } catch (JsonProcessingException e) {
+ log.error("Cannot convert preload data", e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
+ }
+
+ if (dataExists) {
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+ } else {
+ return new ResponseEntity<>(HttpStatus.CREATED);
}
- return new ResponseEntity<>(HttpStatus.OK);
}
@Override
public ResponseEntity<Void> configGENERICRESOURCEAPIservicesDelete() {
configServicesRepository.deleteAll();
- return new ResponseEntity<>(HttpStatus.OK);
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Override
- public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIservicePost(@Valid GenericResourceApiServicemodelinfrastructureService servicesData) {
+ public ResponseEntity<GenericResourceApiServiceModelInfrastructure> configGENERICRESOURCEAPIservicesGet() throws RestApplicationException {
+ GenericResourceApiServiceModelInfrastructure modelInfrastructure = new GenericResourceApiServiceModelInfrastructure();
+
+ if (configServicesRepository.count() == 0) {
+ throw new RestApplicationException("data-missing", "Request could not be completed because the relevant data model content does not exist", HttpStatus.NOT_FOUND.value());
+ }
+
+ for (ConfigServices service : configServicesRepository.findAll()) {
+ GenericResourceApiServicemodelinfrastructureService serviceItem = new GenericResourceApiServicemodelinfrastructureService();
+ serviceItem.setServiceInstanceId(service.getSvcInstanceId());
+ try {
+ serviceItem.setServiceData(objectMapper.readValue(service.getSvcData(), GenericResourceApiServicedataServiceData.class));
+ } catch (JsonProcessingException e) {
+ log.error("Could not deserialize service data for {}", service.getSvcInstanceId(), e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
+
+ }
+ serviceItem.setServiceStatus(service.getServiceStatus());
+ modelInfrastructure.addServiceItem(serviceItem);
+ }
+
+
+ return new ResponseEntity<>(modelInfrastructure, HttpStatus.OK);
+
+ }
+
+ @Override
+ public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPost(@Valid GenericResourceApiServiceModelInfrastructure modelInfrastructure) throws RestApplicationException, RestProtocolException {
+ List<ConfigServices> newServices = new LinkedList<>();
+
+ for (GenericResourceApiServicemodelinfrastructureService serviceItem : modelInfrastructure.getService()) {
+ String svcInstanceId = serviceItem.getServiceInstanceId();
+ List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
+ if ((existingService != null) && !existingService.isEmpty()) {
+ log.error("Service data already exists for {}", svcInstanceId);
+ throw new RestProtocolException("data-exists", "Data already exists for service-instance-id " + svcInstanceId, HttpStatus.CONFLICT.value());
+ }
+ ConfigServices service = new ConfigServices();
+ service.setSvcInstanceId(svcInstanceId);
+ try {
+ service.setSvcData(objectMapper.writeValueAsString(serviceItem.getServiceData()));
+ } catch (JsonProcessingException e) {
+ log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
+
+ }
+ service.setServiceStatus(serviceItem.getServiceStatus());
+ newServices.add(service);
+ }
+
+ for (ConfigServices service : newServices) {
+ configServicesRepository.save(service);
+ }
+
+ return new ResponseEntity<>(HttpStatus.CREATED);
+
+ }
+
+ @Override
+ public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPut(@Valid GenericResourceApiServiceModelInfrastructure modelInfrastructure) throws RestApplicationException {
+
+ List<ConfigServices> newServices = new LinkedList<>();
+ boolean dataExists = false;
+
+ for (GenericResourceApiServicemodelinfrastructureService serviceItem : modelInfrastructure.getService()) {
+ String svcInstanceId = serviceItem.getServiceInstanceId();
+ List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
+ if ((existingService != null) && !existingService.isEmpty()) {
+ dataExists = true;
+ }
+ ConfigServices service = new ConfigServices();
+ service.setSvcInstanceId(svcInstanceId);
+ try {
+ service.setSvcData(objectMapper.writeValueAsString(serviceItem.getServiceData()));
+ } catch (JsonProcessingException e) {
+ log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
+
+ }
+ service.setServiceStatus(serviceItem.getServiceStatus());
+ newServices.add(service);
+ }
+
+ for (ConfigServices service : newServices) {
+ configServicesRepository.save(service);
+ }
+
+ if (dataExists) {
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+ } else {
+ return new ResponseEntity<>(HttpStatus.CREATED);
+ }
+
+ }
+
+ @Override
+ public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIservicePost(@Valid GenericResourceApiServicemodelinfrastructureService servicesData) throws RestApplicationException {
String svcInstanceId = servicesData.getServiceInstanceId();
try {
String svcData = objectMapper.writeValueAsString(servicesData.getServiceData());
@@ -242,7 +497,9 @@ public class ConfigApiController implements ConfigApi {
configServicesRepository.deleteBySvcInstanceId(svcInstanceId);
configServicesRepository.save(configService);
} catch (JsonProcessingException e) {
- log.error("Cannot convert service data", e);
+ log.error("Cannot convert service data", e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
+
}
return new ResponseEntity<>(HttpStatus.OK);
}
@@ -250,76 +507,292 @@ public class ConfigApiController implements ConfigApi {
@Override
public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdDelete(String serviceInstanceId) {
configServicesRepository.deleteBySvcInstanceId(serviceInstanceId);
- return new ResponseEntity<>(HttpStatus.OK);
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Override
- public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataDelete(String serviceInstanceId) {
- return null;
- }
+ public ResponseEntity<GenericResourceApiServicemodelinfrastructureService> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGet(String serviceInstanceId) throws RestApplicationException {
+ GenericResourceApiServicemodelinfrastructureService retval = null;
+
+ List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
+
+ if (services.isEmpty()) {
+ return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+ } else {
+ ConfigServices service = services.get(0);
+ retval = new GenericResourceApiServicemodelinfrastructureService();
+ retval.setServiceInstanceId(serviceInstanceId);
+ retval.setServiceStatus(service.getServiceStatus());
+ try {
+ retval.setServiceData(objectMapper.readValue(service.getSvcData(), GenericResourceApiServicedataServiceData.class));
+ } catch (JsonProcessingException e) {
+ log.error("Could not deserialize service data for service instance id {}", serviceInstanceId, e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
- @Override
- public ResponseEntity<GenericResourceApiServicedataServiceData> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataGet(String serviceInstanceId) {
- return null;
- }
+ }
+ }
- @Override
- public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataPost(String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData genericResourceApiServicedataServiceDataBodyParam) {
- return null;
- }
- @Override
- public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataPut(String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData genericResourceApiServicedataServiceDataBodyParam) {
- return null;
+ return new ResponseEntity<>(retval, HttpStatus.OK);
+
}
@Override
- public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusDelete(String serviceInstanceId) {
- return null;
+ public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdPost(String svcInstanceId, @Valid GenericResourceApiServicemodelinfrastructureService newService) throws RestApplicationException, RestProtocolException {
+
+ List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
+ if ((existingService != null) && !existingService.isEmpty()) {
+ log.error("Service data already exists for {}", svcInstanceId);
+ throw new RestProtocolException("data-exists", "Data already exists for service-instance-id " + svcInstanceId, HttpStatus.CONFLICT.value());
+ }
+ ConfigServices service = new ConfigServices();
+ service.setSvcInstanceId(svcInstanceId);
+ try {
+ service.setSvcData(objectMapper.writeValueAsString(newService.getServiceData()));
+ } catch (JsonProcessingException e) {
+ log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
+
+ }
+ service.setServiceStatus(newService.getServiceStatus());
+ configServicesRepository.save(service);
+
+ return new ResponseEntity<>(HttpStatus.CREATED);
}
@Override
- public ResponseEntity<GenericResourceApiServicestatusServiceStatus> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusGet(String serviceInstanceId) {
- return null;
+ public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdPut(String serviceInstanceId, @Valid GenericResourceApiServicemodelinfrastructureService newService) throws RestApplicationException {
+
+ boolean dataExists = false;
+
+ String svcInstanceId = newService.getServiceInstanceId();
+
+ ConfigServices service = null;
+ List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
+ if ((existingService != null) && !existingService.isEmpty()) {
+ dataExists = true;
+ service = existingService.get(0);
+ } else {
+ service = new ConfigServices();
+ service.setSvcInstanceId(svcInstanceId);
+ }
+
+ try {
+ service.setSvcData(objectMapper.writeValueAsString(newService.getServiceData()));
+ } catch (JsonProcessingException e) {
+ log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
+
+ }
+ service.setServiceStatus(newService.getServiceStatus());
+ configServicesRepository.save(service);
+
+ if (dataExists) {
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+ } else {
+ return new ResponseEntity<>(HttpStatus.CREATED);
+ }
}
+
@Override
- public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusPost(String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus genericResourceApiServicestatusServiceStatusBodyParam) {
- return null;
+ public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataDelete(String serviceInstanceId) throws RestProtocolException {
+ List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
+
+ if ((services == null) || (services.isEmpty())) {
+ throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
+ }
+
+ ConfigServices service = services.get(0);
+ if (service.getSvcData() == null) {
+ throw new RestProtocolException("data-missing", "No service-data found", HttpStatus.NOT_FOUND.value());
+ }
+ service.setSvcData(null);
+ configServicesRepository.save(service);
+
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Override
- public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusPut(String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus genericResourceApiServicestatusServiceStatusBodyParam) {
- return null;
+ public ResponseEntity<GenericResourceApiServicedataServiceData> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataGet(String serviceInstanceId) throws RestApplicationException, RestProtocolException {
+ GenericResourceApiServicedataServiceData serviceData = null;
+
+ List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
+ if ((services == null) || (services.isEmpty())) {
+ throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
+ }
+
+ try {
+ serviceData = objectMapper.readValue(services.get(0).getSvcData(), GenericResourceApiServicedataServiceData.class);
+ return new ResponseEntity<>(serviceData, HttpStatus.OK);
+ } catch (JsonProcessingException e) {
+ log.error("Could not parse service data", e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
+ }
+
}
@Override
- public ResponseEntity<GenericResourceApiServicemodelinfrastructureService> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGet(String serviceInstanceId) {
- return null;
+ public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataPost(String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData serviceData) throws RestApplicationException, RestProtocolException {
+ ConfigServices service;
+ List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
+ if ((services == null) || (services.isEmpty())) {
+ throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
+ }
+
+ if ((serviceData == null) ||
+ (serviceData.getServiceInformation() == null)) {
+ throw new RestProtocolException("bad-attribute", "Invalid service-data received", HttpStatus.BAD_REQUEST.value());
+
+ }
+ service = services.get(0);
+
+ if ((service.getSvcData() != null) && (service.getSvcData().length() > 0)){
+ log.error("service-data already exists for svcInstanceId {}", serviceInstanceId);
+ throw new RestProtocolException("data-exists", "Data already exists for " + serviceInstanceId, HttpStatus.CONFLICT.value());
+ }
+
+
+ try {
+ service.setSvcData(objectMapper.writeValueAsString(serviceData));
+ configServicesRepository.save(service);
+ } catch (JsonProcessingException e) {
+ log.error("Could not serialize service data for svc instance id {}", serviceInstanceId, e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
+ }
+
+
+ return new ResponseEntity<>(HttpStatus.CREATED);
+
}
@Override
- public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdPost(String serviceInstanceId, @Valid GenericResourceApiServicemodelinfrastructureService genericResourceApiServicemodelinfrastructureServiceBodyParam) {
- return null;
+ public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataPut(String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData serviceData) throws RestApplicationException, RestProtocolException {
+ ConfigServices service;
+ boolean dataExists = false;
+
+ List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
+ if ((services == null) || (services.isEmpty())) {
+ throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
+ }
+
+ if ((serviceData == null) ||
+ (serviceData.getServiceInformation() == null)) {
+ throw new RestProtocolException("bad-attribute", "Invalid service-data received", HttpStatus.BAD_REQUEST.value());
+
+ }
+ service = services.get(0);
+
+ if ((service.getSvcData() != null) && (service.getSvcData().length() > 0)) {
+ dataExists = true;
+ }
+
+ try {
+ service.setSvcData(objectMapper.writeValueAsString(serviceData));
+ configServicesRepository.save(service);
+ } catch (JsonProcessingException e) {
+ log.error("Could not serialize service data for svc instance id {}", serviceInstanceId, e);
+ throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
+ }
+
+ if (dataExists) {
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+ } else {
+ return new ResponseEntity<>(HttpStatus.CREATED);
+ }
}
@Override
- public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdPut(String serviceInstanceId, @Valid GenericResourceApiServicemodelinfrastructureService genericResourceApiServicemodelinfrastructureServiceBodyParam) {
- return null;
+ public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusDelete(String serviceInstanceId) throws RestProtocolException {
+ List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
+
+ if ((services == null) || (services.isEmpty())) {
+ throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
+ }
+
+ ConfigServices service = services.get(0);
+ if (service.getServiceStatus() == null) {
+ throw new RestProtocolException("data-missing", "No service-status found", HttpStatus.NOT_FOUND.value());
+ }
+ service.setServiceStatus(null);
+ configServicesRepository.save(service);
+
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+
}
@Override
- public ResponseEntity<GenericResourceApiServiceModelInfrastructure> configGENERICRESOURCEAPIservicesGet() {
- return null;
+ public ResponseEntity<GenericResourceApiServicestatusServiceStatus> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusGet(String serviceInstanceId) throws RestApplicationException, RestProtocolException {
+ GenericResourceApiServicestatusServiceStatus serviceStatus = null;
+
+ List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
+ if ((services == null) || (services.isEmpty())) {
+ throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
+ }
+
+ serviceStatus = services.get(0).getServiceStatus();
+ return new ResponseEntity<>(serviceStatus, HttpStatus.OK);
}
@Override
- public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPost(@Valid GenericResourceApiServiceModelInfrastructure genericResourceApiServiceModelInfrastructureBodyParam) {
- return null;
+ public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusPost(String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus serviceStatus) throws RestProtocolException {
+ ConfigServices service;
+ List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
+ if ((services == null) || (services.isEmpty())) {
+ throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
+ }
+
+ if ((serviceStatus == null) ||
+ (serviceStatus.getAction() == null)) {
+ throw new RestProtocolException("bad-attribute", "Invalid service-status received", HttpStatus.BAD_REQUEST.value());
+
+ }
+ service = services.get(0);
+
+ if (service.getServiceStatus() != null) {
+ log.error("service-status already exists for svcInstanceId {}", serviceInstanceId);
+ throw new RestProtocolException("data-exists", "Data already exists for " + serviceInstanceId, HttpStatus.CONFLICT.value());
+ }
+
+
+ service.setServiceStatus(serviceStatus);
+ configServicesRepository.save(service);
+
+
+ return new ResponseEntity<>(HttpStatus.CREATED);
+
}
@Override
- public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPut(@Valid GenericResourceApiServiceModelInfrastructure genericResourceApiServiceModelInfrastructureBodyParam) {
- return null;
+ public ResponseEntity<Void> configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusPut(String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus serviceStatus) throws RestProtocolException {
+ ConfigServices service;
+ boolean dataExists = false;
+
+ List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
+ if ((services == null) || (services.isEmpty())) {
+ throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
+ }
+
+ if ((serviceStatus == null) ||
+ (serviceStatus.getAction() == null)) {
+ throw new RestProtocolException("bad-attribute", "Invalid service-status received", HttpStatus.BAD_REQUEST.value());
+
+ }
+ service = services.get(0);
+
+ if (service.getServiceStatus() != null) {
+ dataExists = true;
+ }
+
+
+ service.setServiceStatus(serviceStatus);
+ configServicesRepository.save(service);
+
+ if (dataExists) {
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+ } else {
+ return new ResponseEntity<>(HttpStatus.CREATED);
+ }
}
+
}
diff --git a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/OperationalApiController.java b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/OperationalApiController.java
new file mode 100644
index 0000000..14e285f
--- /dev/null
+++ b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/OperationalApiController.java
@@ -0,0 +1,213 @@
+package org.onap.sdnc.apps.ms.gra.controllers;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.onap.sdnc.apps.ms.gra.data.*;
+import org.onap.sdnc.apps.ms.gra.swagger.OperationalApi;
+import org.onap.sdnc.apps.ms.gra.swagger.model.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.domain.EntityScan;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Controller;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.validation.Valid;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+@Controller
+@ComponentScan(basePackages = {"org.onap.sdnc.apps.ms.gra.*"})
+@EntityScan("org.onap.sdnc.apps.ms.gra.springboot.*")
+public class OperationalApiController implements OperationalApi {
+ private static final Logger log = LoggerFactory.getLogger(ConfigApiController.class);
+
+ private final ObjectMapper objectMapper;
+
+ private final HttpServletRequest request;
+
+ @Autowired
+ private OperationalPreloadDataRepository operationalPreloadDataRepository;
+
+ @Autowired
+ private OperationalServicesRepository operationalServicesRepository;
+
+ @Autowired
+ public OperationalApiController(ObjectMapper objectMapper, HttpServletRequest request) {
+ objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
+ objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ this.objectMapper = objectMapper;
+ this.request = request;
+ }
+
+ @Override
+ public Optional<ObjectMapper> getObjectMapper() {
+ return Optional.ofNullable(objectMapper);
+ }
+
+ @Override
+ public Optional<HttpServletRequest> getRequest() {
+ return Optional.ofNullable(request);
+ }
+
+
+ @Override
+ public ResponseEntity<GenericResourceApiPreloadModelInformation> operationalGENERICRESOURCEAPIpreloadInformationGet() {
+ GenericResourceApiPreloadModelInformation genericResourceApiPreloadModelInformation = new GenericResourceApiPreloadModelInformation();
+
+ operationalPreloadDataRepository.findAll().forEach(configPreloadData -> {
+ GenericResourceApiPreloadmodelinformationPreloadList preloadListItem = new GenericResourceApiPreloadmodelinformationPreloadList();
+
+ preloadListItem.setPreloadId(configPreloadData.getPreloadId());
+ preloadListItem.setPreloadType(configPreloadData.getPreloadType());
+ try {
+ preloadListItem.setPreloadData(objectMapper.readValue(configPreloadData.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class));
+ } catch (JsonProcessingException e) {
+ log.error("Could not convert preload data", e);
+ }
+ genericResourceApiPreloadModelInformation.addPreloadListItem(preloadListItem);
+ });
+
+
+ return new ResponseEntity<>(genericResourceApiPreloadModelInformation, HttpStatus.OK);
+ }
+
+
+ @Override
+ public ResponseEntity<GenericResourceApiPreloadmodelinformationPreloadList> operationalGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeGet(String preloadId, String preloadType) {
+ List<OperationalPreloadData> preloadData = operationalPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
+ if (preloadData != null) {
+ if (!preloadData.isEmpty()) {
+ OperationalPreloadData preloadDataItem = preloadData.get(0);
+ GenericResourceApiPreloadmodelinformationPreloadList preloadDataList = new GenericResourceApiPreloadmodelinformationPreloadList();
+ preloadDataList.setPreloadId(preloadDataItem.getPreloadId());
+ preloadDataList.setPreloadType(preloadDataItem.getPreloadType());
+ try {
+ preloadDataList.setPreloadData(objectMapper.readValue(preloadDataItem.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class));
+ } catch (JsonProcessingException e) {
+ log.error("Cannot convert preload data", e);
+ }
+ return new ResponseEntity<>(preloadDataList, HttpStatus.OK);
+ }
+ }
+ return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+ }
+
+
+ @Override
+ public ResponseEntity<GenericResourceApiPreloaddataPreloadData> operationalGENERICRESOURCEAPIpreloadInformationGENERICRESOURCEAPIpreloadListPreloadIdPreloadTypeGENERICRESOURCEAPIpreloadDataGet(String preloadId, String preloadType) {
+ List<OperationalPreloadData> preloadData = operationalPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType);
+ if (preloadData != null) {
+ if (!preloadData.isEmpty()) {
+ OperationalPreloadData preloadDataItem = preloadData.get(0);
+ try {
+ return new ResponseEntity<>(objectMapper.readValue(preloadDataItem.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class), HttpStatus.OK);
+ } catch (JsonProcessingException e) {
+ log.error("Cannot convert preload data", e);
+ }
+ }
+ }
+ return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+ }
+
+
+ @Override
+ public ResponseEntity<GenericResourceApiServiceModelInfrastructure> operationalGENERICRESOURCEAPIservicesGet() {
+ GenericResourceApiServiceModelInfrastructure modelInfrastructure = new GenericResourceApiServiceModelInfrastructure();
+
+ AtomicBoolean caughtError = new AtomicBoolean(false);
+ operationalServicesRepository.findAll().forEach(service ->
+ {
+ GenericResourceApiServicemodelinfrastructureService serviceItem = new GenericResourceApiServicemodelinfrastructureService();
+ serviceItem.setServiceInstanceId(service.getSvcInstanceId());
+ try {
+ serviceItem.setServiceData(objectMapper.readValue(service.getSvcData(), GenericResourceApiServicedataServiceData.class));
+ } catch (JsonProcessingException e) {
+ log.error("Could not deserialize service data for {}", service.getSvcInstanceId(), e);
+ caughtError.set(true);
+ }
+ serviceItem.setServiceStatus(service.getServiceStatus());
+ modelInfrastructure.addServiceItem(serviceItem);
+ });
+
+ if (caughtError.get()) {
+ return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ } else {
+ return new ResponseEntity<>(modelInfrastructure, HttpStatus.OK);
+ }
+ }
+
+
+
+ @Override
+ public ResponseEntity<GenericResourceApiServicemodelinfrastructureService> operationalGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGet(String serviceInstanceId) {
+ GenericResourceApiServicemodelinfrastructureService retval = null;
+
+ List<OperationalServices> services = operationalServicesRepository.findBySvcInstanceId(serviceInstanceId);
+
+ if (services.isEmpty()) {
+ return new ResponseEntity<> (HttpStatus.NOT_FOUND);
+ } else {
+ OperationalServices service = services.get(0);
+ retval = new GenericResourceApiServicemodelinfrastructureService();
+ retval.setServiceInstanceId(serviceInstanceId);
+ retval.setServiceStatus(service.getServiceStatus());
+ try {
+ retval.setServiceData(objectMapper.readValue(service.getSvcData(), GenericResourceApiServicedataServiceData.class));
+ } catch (JsonProcessingException e) {
+ log.error("Could not deserialize service data for service instance id {}", serviceInstanceId, e);
+ retval = null;
+ }
+ }
+
+ if (retval == null) {
+ return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ } else {
+ return new ResponseEntity<>(retval, HttpStatus.OK);
+ }
+ }
+
+
+ @Override
+ public ResponseEntity<GenericResourceApiServicedataServiceData> operationalGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataGet(String serviceInstanceId) {
+ GenericResourceApiServicedataServiceData serviceData = null;
+
+ List<OperationalServices> services = operationalServicesRepository.findBySvcInstanceId(serviceInstanceId);
+ if (services.isEmpty()) {
+ return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+ } else {
+ try {
+ serviceData = objectMapper.readValue(services.get(0).getSvcData(), GenericResourceApiServicedataServiceData.class);
+ return new ResponseEntity<>(serviceData, HttpStatus.OK);
+ } catch (JsonProcessingException e) {
+ log.error("Could not parse service data", e);
+ return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ }
+ }
+
+ @Override
+ public ResponseEntity<GenericResourceApiServicestatusServiceStatus> operationalGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusGet(String serviceInstanceId) {
+ GenericResourceApiServicestatusServiceStatus serviceStatus = null;
+ List<OperationalServices> services = operationalServicesRepository.findBySvcInstanceId(serviceInstanceId);
+
+ if (!services.isEmpty()) {
+ OperationalServices service = services.get(0);
+ serviceStatus = service.getServiceStatus();
+ }
+
+ if (serviceStatus == null) {
+ return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+ } else {
+ return new ResponseEntity<>(serviceStatus, HttpStatus.OK);
+ }
+
+ }
+
+}
diff --git a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/core/GenericResourceMsApp.java b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/core/GenericResourceMsApp.java
index a195c0c..e3a2bd7 100644
--- a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/core/GenericResourceMsApp.java
+++ b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/core/GenericResourceMsApp.java
@@ -34,7 +34,7 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
-@SpringBootApplication(scanBasePackages= { "org.onap.sdnc.apps.ms.gra.*" })
+@SpringBootApplication(scanBasePackages= { "org.onap.sdnc.apps.ms.gra.*", "org.onap.ccsdk.apps.services"})
@EnableSwagger2
public class GenericResourceMsApp {
diff --git a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/core/WebConfig.java b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/core/WebConfig.java
index c71ac98..5c1a923 100644
--- a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/core/WebConfig.java
+++ b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/core/WebConfig.java
@@ -45,7 +45,7 @@ import javax.sql.DataSource;
@Configuration
@EnableJpaRepositories("org.onap.sdnc.apps.ms.gra.*")
-@ComponentScan(basePackages={"org.onap.sdnc.apps.ms.gra.*"})
+@ComponentScan(basePackages={"org.onap.sdnc.apps.ms.gra.*", "org.onap.ccsdk.apps.services"})
@EntityScan("org.onap.sdnc.apps.ms.gra.*")
@EnableTransactionManagement
public class WebConfig implements WebMvcConfigurer {
diff --git a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/ConfigPreloadData.java b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/ConfigPreloadData.java
index 4d0f9da..a23884d 100644
--- a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/ConfigPreloadData.java
+++ b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/ConfigPreloadData.java
@@ -39,6 +39,7 @@ public class ConfigPreloadData {
private String preloadType;
@Lob
+ @Column(length=10000)
private String preloadData;
public ConfigPreloadData() {
diff --git a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/ConfigServices.java b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/ConfigServices.java
index 187169a..ca22fff 100644
--- a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/ConfigServices.java
+++ b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/ConfigServices.java
@@ -5,10 +5,7 @@ import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiRequestStatusEn
import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServiceStatus;
import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicestatusServiceStatus;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Lob;
-import javax.persistence.Table;
+import javax.persistence.*;
@Entity(name="CONFIG_GRA_SERVICES")
@Table(name="CONFIG_GRA_SERVICES")
@@ -17,6 +14,7 @@ public class ConfigServices {
String svcInstanceId;
@Lob
+ @Column(columnDefinition = "clob")
String svcData;
// Service status fields
@@ -142,6 +140,16 @@ public class ConfigServices {
}
public GenericResourceApiServicestatusServiceStatus getServiceStatus() {
+
+ if ((serviceStatusAction == null) &&
+ (serviceStatusFinalIndicator == null) &&
+ (serviceStatusRequestStatus == null) &&
+ (serviceStatusResponseCode == null) &&
+ (serviceStatusResponseMessage == null) &&
+ (serviceStatusResponseTimestamp == null)) {
+ return null;
+ }
+
GenericResourceApiServicestatusServiceStatus serviceStatus = new GenericResourceApiServicestatusServiceStatus();
serviceStatus.setAction(serviceStatusAction);
serviceStatus.setFinalIndicator(serviceStatusFinalIndicator);
@@ -154,11 +162,20 @@ public class ConfigServices {
}
public void setServiceStatus(GenericResourceApiServicestatusServiceStatus serviceStatus) {
- this.serviceStatusAction = serviceStatus.getAction();
- this.serviceStatusFinalIndicator = serviceStatus.getFinalIndicator();
- this.serviceStatusRequestStatus = serviceStatus.getRequestStatus().toString();
- this.serviceStatusResponseCode = serviceStatus.getResponseCode();
- this.serviceStatusResponseMessage = serviceStatus.getResponseMessage();
- this.serviceStatusResponseTimestamp = serviceStatus.getResponseTimestamp();
+ if (serviceStatus == null) {
+ this.serviceStatusAction = null;
+ this.serviceStatusFinalIndicator = null;
+ this.serviceStatusRequestStatus = null;
+ this.serviceStatusResponseCode = null;
+ this.serviceStatusResponseMessage = null;
+ this.serviceStatusResponseTimestamp = null;
+ } else {
+ this.serviceStatusAction = serviceStatus.getAction();
+ this.serviceStatusFinalIndicator = serviceStatus.getFinalIndicator();
+ this.serviceStatusRequestStatus = serviceStatus.getRequestStatus().toString();
+ this.serviceStatusResponseCode = serviceStatus.getResponseCode();
+ this.serviceStatusResponseMessage = serviceStatus.getResponseMessage();
+ this.serviceStatusResponseTimestamp = serviceStatus.getResponseTimestamp();
+ }
}
} \ No newline at end of file
diff --git a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/OperationalPreloadData.java b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/OperationalPreloadData.java
index 936d2f7..c39e24f 100644
--- a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/OperationalPreloadData.java
+++ b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/OperationalPreloadData.java
@@ -39,6 +39,7 @@ public class OperationalPreloadData {
private String preloadType;
@Lob
+ @Column(columnDefinition = "clob")
private String preloadData;
public OperationalPreloadData() {
diff --git a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/OperationalServices.java b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/OperationalServices.java
index eb46816..aab5246 100644
--- a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/OperationalServices.java
+++ b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/data/OperationalServices.java
@@ -4,10 +4,7 @@ import org.hibernate.validator.constraints.Length;
import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiRequestStatusEnumeration;
import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicestatusServiceStatus;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Lob;
-import javax.persistence.Table;
+import javax.persistence.*;
@Entity(name="OPERATIONAL_GRA_SERVICES")
@Table(name="OPERATIONAL_GRA_SERVICES")
@@ -16,7 +13,9 @@ public class OperationalServices {
String svcInstanceId;
@Lob
+ @Column(columnDefinition = "clob")
String svcData;
+
// Service status fields
String serviceStatusResponseCode;
diff --git a/ms/generic-resource-api/src/main/resources/startGra.sh b/ms/generic-resource-api/src/main/resources/startGra.sh
index 42ef339..5f04e33 100644
--- a/ms/generic-resource-api/src/main/resources/startGra.sh
+++ b/ms/generic-resource-api/src/main/resources/startGra.sh
@@ -36,8 +36,7 @@ export MYSQL_DB_HOST=${MYSQL_DB_HOST:-dbhost}
# Wait for database
#
echo "Waiting for database"
-until mysqladmin ping -h ${MYSQL_DB_HOST} --silent
-do
+until mysqladmin ping -h ${MYSQL_DB_HOST} --silent; do
printf "."
sleep 1
done
@@ -45,30 +44,26 @@ echo -e "\nDatabase ready"
# Create tablespace and user account
-mysql -h ${MYSQL_DB_HOST} -u root -p${MYSQL_ROOT_PASSWORD} mysql <<-END
-CREATE DATABASE ${MYSQL_DB_DATABASE};
-CREATE USER '${MYSQL_DB_USER}'@'localhost' IDENTIFIED BY '${MYSQL_DB_PASSWD}';
-CREATE USER '${MYSQL_DB_USER}'@'%' IDENTIFIED BY '${MYSQL_DB_PASSWD}';
-GRANT ALL PRIVILEGES ON ${MYSQL_DB_DATABASE}.* TO '${MYSQL_DB_USER}'@'localhost' WITH GRANT OPTION;
-GRANT ALL PRIVILEGES ON ${MYSQL_DB_DATABASE}.* TO '${MYSQL_DB_USER}'@'%' WITH GRANT OPTION;
-commit;
-END
+#mysql -h ${MYSQL_DB_HOST} -u root -p${MYSQL_ROOT_PASSWORD} mysql <<-END
+#CREATE DATABASE ${MYSQL_DB_DATABASE};
+#CREATE USER '${MYSQL_DB_USER}'@'localhost' IDENTIFIED BY '${MYSQL_DB_PASSWD}';
+#CREATE USER '${MYSQL_DB_USER}'@'%' IDENTIFIED BY '${MYSQL_DB_PASSWD}';
+#GRANT ALL PRIVILEGES ON ${MYSQL_DB_DATABASE}.* TO '${MYSQL_DB_USER}'@'localhost' WITH GRANT OPTION;
+#GRANT ALL PRIVILEGES ON ${MYSQL_DB_DATABASE}.* TO '${MYSQL_DB_USER}'@'%' WITH GRANT OPTION;
+#commit;
+#END
# Initialize schema
#mysql -h ${MYSQL_DB_HOST} -u ${MYSQL_DB_USER} -p${MYSQL_DB_PASSWD} ${MYSQL_DB_DATABASE} < ${SDNC_HOME}/config/schema.sql
-if [ ! -f ${SDNC_CERT_DIR}/${TRUSTSTORE} ]
-then
- echo "${SDNC_CERT_DIR}/${TRUSTSTORE} not found ... cannot install ONAP CA certs"
-elif [ -z "$TRUSTSTORE_PASSWORD" ]
-then
- echo "TRUSTSTORE_PASSWORD unset - cannot install ONAP CA certs"
+if [ ! -f ${SDNC_CERT_DIR}/${TRUSTSTORE} ]; then
+ echo "${SDNC_CERT_DIR}/${TRUSTSTORE} not found ... cannot install ONAP CA certs"
+elif [ -z "$TRUSTSTORE_PASSWORD" ]; then
+ echo "TRUSTSTORE_PASSWORD unset - cannot install ONAP CA certs"
else
- sudo keytool -importkeystore -srckeystore ${SDNC_CERT_DIR}/${TRUSTSTORE} -srcstorepass ${TRUSTSTORE_PASSWORD} -destkeystore ${JAVA_SECURITY_DIR}/cacerts -deststorepass ${CACERT_PASSWORD}
- echo -e "\nCerts ready"
+ sudo keytool -importkeystore -srckeystore ${SDNC_CERT_DIR}/${TRUSTSTORE} -srcstorepass ${TRUSTSTORE_PASSWORD} -destkeystore ${JAVA_SECURITY_DIR}/cacerts -deststorepass ${CACERT_PASSWORD}
+ echo -e "\nCerts ready"
fi
-
cd $SDNC_HOME
java -DserviceLogicDirectory=${SVCLOGIC_DIR} -DLOG_PATH=${LOG_PATH} -jar ${SDNC_HOME}/lib/${GRA_JAR}
-
diff --git a/ms/generic-resource-api/src/main/templates/api.mustache b/ms/generic-resource-api/src/main/templates/api.mustache
new file mode 100644
index 0000000..c28642c
--- /dev/null
+++ b/ms/generic-resource-api/src/main/templates/api.mustache
@@ -0,0 +1,136 @@
+/**
+* NOTE: This class is auto generated by the swagger code generator program ({{{generatorVersion}}}).
+* https://github.com/swagger-api/swagger-codegen
+* Do not edit the class manually.
+*/
+package {{package}};
+
+{{#imports}}import {{import}};
+{{/imports}}
+{{#jdk8-no-delegate}}
+ import com.fasterxml.jackson.databind.ObjectMapper;
+{{/jdk8-no-delegate}}
+import io.swagger.annotations.*;
+{{#jdk8-no-delegate}}
+ import org.slf4j.Logger;
+ import org.slf4j.LoggerFactory;
+ import org.springframework.http.HttpStatus;
+{{/jdk8-no-delegate}}
+import org.springframework.http.ResponseEntity;
+{{#useBeanValidation}}
+ import org.springframework.validation.annotation.Validated;
+{{/useBeanValidation}}
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RequestPart;
+import org.springframework.web.multipart.MultipartFile;
+import org.onap.ccsdk.apps.services.RestException;
+
+{{#jdk8-no-delegate}}
+ import javax.servlet.http.HttpServletRequest;
+{{/jdk8-no-delegate}}
+{{#useBeanValidation}}
+ import javax.validation.Valid;
+ import javax.validation.constraints.*;
+{{/useBeanValidation}}
+{{#jdk8-no-delegate}}
+ import java.io.IOException;
+{{/jdk8-no-delegate}}
+import java.util.List;
+{{#jdk8-no-delegate}}
+ import java.util.Optional;
+{{/jdk8-no-delegate}}
+{{^jdk8-no-delegate}}
+ {{#useOptional}}
+ import java.util.Optional;
+ {{/useOptional}}
+{{/jdk8-no-delegate}}
+{{#async}}
+ import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture{{/jdk8}};
+{{/async}}
+{{>generatedAnnotation}}
+@Api(value = "{{{baseName}}}", description = "the {{{baseName}}} API")
+{{#operations}}
+ public interface {{classname}} {
+ {{#jdk8}}
+
+ {{^isDelegate}}
+ Logger log = LoggerFactory.getLogger({{classname}}.class);
+
+ default Optional<ObjectMapper> getObjectMapper() {
+ return Optional.empty();
+ }
+
+ default Optional<HttpServletRequest> getRequest() {
+ return Optional.empty();
+ }
+
+ default Optional<String> getAcceptHeader() {
+ return getRequest().map(r -> r.getHeader("Accept"));
+ }
+ {{/isDelegate}}
+ {{#isDelegate}}
+ {{classname}}Delegate getDelegate();
+ {{/isDelegate}}
+ {{/jdk8}}
+ {{#operation}}
+
+ @ApiOperation(value = "{{{summary}}}", nickname = "{{{operationId}}}", notes = "{{{notes}}}"{{#returnBaseType}}, response = {{{returnBaseType}}}.class{{/returnBaseType}}{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = {
+ {{#authMethods}}@Authorization(value = "{{name}}"{{#isOAuth}}, scopes = {
+ {{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}},
+ {{/hasMore}}{{/scopes}}
+ }{{/isOAuth}}){{#hasMore}},
+ {{/hasMore}}{{/authMethods}}
+ }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} })
+ @ApiResponses(value = { {{#responses}}
+ @ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{baseType}}}.class{{/baseType}}{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{#hasMore}},{{/hasMore}}{{/responses}} })
+ {{#implicitHeaders}}
+ @ApiImplicitParams({
+ {{#headerParams}}
+ {{>implicitHeader}}
+ {{/headerParams}}
+ })
+ {{/implicitHeaders}}
+ @RequestMapping(value = "{{{path}}}",{{#singleContentTypes}}
+ produces = "{{{vendorExtensions.x-accepts}}}",
+ consumes = "{{{vendorExtensions.x-contentType}}}",{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}}
+ produces = { {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}{{#hasConsumes}}
+ consumes = { {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}{{/singleContentTypes}}
+ method = RequestMethod.{{httpMethod}})
+ {{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{#delegate-method}}_{{/delegate-method}}{{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}){{^jdk8}};{{/jdk8}}{{#jdk8}} throws RestException {
+ {{#delegate-method}}
+ return {{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
+ }
+
+ // Override this method
+ default {{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{^isFile}}{{{dataType}}}{{/isFile}}{{#isFile}}MultipartFile{{/isFile}} {{paramName}}{{#hasMore}},{{/hasMore}}{{/allParams}}) throws RestException {
+ {{/delegate-method}}
+ {{^isDelegate}}
+ if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
+ {{#examples}}
+ if (getAcceptHeader().get().contains("{{{contentType}}}")) {
+ try {
+ return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<>(getObjectMapper().get().readValue("{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{example}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}", {{>exampleReturnTypes}}.class), HttpStatus.NOT_IMPLEMENTED){{#async}}){{/async}};
+ } catch (IOException e) {
+ log.error("Couldn't serialize response for content type {{{contentType}}}", e);
+ return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR){{#async}}){{/async}};
+ }
+ }
+ {{/examples}}
+ } else {
+ log.warn("ObjectMapper or HttpServletRequest not configured in default {{classname}} interface so no example is generated");
+ }
+ return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED){{#async}}){{/async}};
+ {{/isDelegate}}
+ {{#isDelegate}}
+ return getDelegate().{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
+ {{/isDelegate}}
+ }{{/jdk8}}
+
+ {{/operation}}
+ }
+{{/operations}} \ No newline at end of file