summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/nbi/apis/servicecatalog/ServiceSpecificationService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap/nbi/apis/servicecatalog/ServiceSpecificationService.java')
-rw-r--r--src/main/java/org/onap/nbi/apis/servicecatalog/ServiceSpecificationService.java55
1 files changed, 34 insertions, 21 deletions
diff --git a/src/main/java/org/onap/nbi/apis/servicecatalog/ServiceSpecificationService.java b/src/main/java/org/onap/nbi/apis/servicecatalog/ServiceSpecificationService.java
index 5e3e4cf..8f0829b 100644
--- a/src/main/java/org/onap/nbi/apis/servicecatalog/ServiceSpecificationService.java
+++ b/src/main/java/org/onap/nbi/apis/servicecatalog/ServiceSpecificationService.java
@@ -50,33 +50,39 @@ public class ServiceSpecificationService {
@Autowired
private ServiceCatalogUrl serviceCatalogUrl;
+ @Autowired
+ ServiceSpecificationDBManager serviceSpecificationDBManager;
private static final Logger LOGGER = LoggerFactory.getLogger(ServiceSpecificationService.class);
-
public Map get(String serviceSpecId) {
- Map sdcResponse = sdcClient.callGet(serviceSpecId);
- LinkedHashMap serviceCatalogResponse =
- (LinkedHashMap) getServiceSpecJsonTransformer.transform(sdcResponse);
- String toscaModelUrl = (String) sdcResponse.get("toscaModelURL");
- String serviceId = (String) sdcResponse.get("id");
- File toscaFile = sdcClient.callGetWithAttachment(toscaModelUrl);
- Path pathToToscaCsar = toscaFile.toPath().toAbsolutePath();
- try {
- toscaInfosProcessor.buildResponseWithSdcToscaParser(pathToToscaCsar, serviceCatalogResponse);
- } catch (SdcToscaParserException e) {
- LOGGER.debug("unable to build response from tosca csar using sdc-parser, partial response : "
- + pathToToscaCsar.toString() + " " + e.getMessage());
- }
- try {
- if (toscaFile != null) {
- LOGGER.debug("deleting tosca archive : " + toscaFile.getName());
- FileUtils.forceDelete(toscaFile);
+ if(serviceSpecificationDBManager.checkServiceSpecExistence(serviceSpecId)) {
+ return serviceSpecificationDBManager.getServiceSpecification(serviceSpecId);
+ }else {
+ Map sdcResponse = sdcClient.callGet(serviceSpecId);
+ LinkedHashMap serviceCatalogResponse =
+ (LinkedHashMap) getServiceSpecJsonTransformer.transform(sdcResponse);
+ String toscaModelUrl = (String) sdcResponse.get("toscaModelURL");
+ String serviceId = (String) sdcResponse.get("id");
+ File toscaFile = sdcClient.callGetWithAttachment(toscaModelUrl);
+ Path pathToToscaCsar = toscaFile.toPath().toAbsolutePath();
+ try {
+ toscaInfosProcessor.buildAndSaveResponseWithSdcToscaParser(pathToToscaCsar, serviceCatalogResponse);
+ serviceSpecificationDBManager.saveCatalogResponse(serviceCatalogResponse);
+ } catch (SdcToscaParserException e) {
+ LOGGER.debug("unable to build response from tosca csar using sdc-parser, partial response : "
+ + pathToToscaCsar.toString() + " " + e.getMessage());
+ }
+ try {
+ if (toscaFile != null) {
+ LOGGER.debug("deleting tosca archive : " + toscaFile.getName());
+ FileUtils.forceDelete(toscaFile);
+ }
+ } catch (IOException e) {
+ LOGGER.error("unable to delete temp directory tosca file for id : " + serviceId, e);
}
- } catch (IOException e) {
- LOGGER.error("unable to delete temp directory tosca file for id : " + serviceId, e);
+ return serviceCatalogResponse;
}
- return serviceCatalogResponse;
}
public List<LinkedHashMap> find(MultiValueMap<String, String> parametersMap) {
@@ -87,4 +93,11 @@ public class ServiceSpecificationService {
}
return serviceCatalogResponse;
}
+ public String getInputSchema(String serviceSpecId) {
+ if(serviceSpecificationDBManager.checkInputSchemaExistence(serviceSpecId)) {
+ return serviceSpecificationDBManager.getInputSchema(serviceSpecId);
+ } else {
+ return null;
+ }
+ }
}