2 * Copyright (c) 2019 Amdocs
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.nbi.apis.servicecatalog;
18 import org.onap.nbi.apis.servicecatalog.model.ServiceSpecification;
19 import org.onap.nbi.apis.servicecatalog.model.SpecificationInputSchema;
20 import org.onap.nbi.apis.servicecatalog.repositories.ServiceSpecificationRepository;
21 import org.onap.nbi.apis.servicecatalog.repositories.SpecificationInputSchemaRepository;
22 import org.onap.nbi.exceptions.TechnicalException;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.stereotype.Service;
28 import java.util.LinkedHashMap;
30 import java.util.Optional;
33 public class ServiceSpecificationDBManager {
36 ServiceSpecificationRepository serviceSpecificationRepository;
39 SpecificationInputSchemaRepository specificationInputSchemaRepository;
41 private static final Logger LOGGER = LoggerFactory.getLogger(ServiceSpecificationService.class);
43 public void saveCatalogResponse(LinkedHashMap serviceCatalogResponse) {
45 ServiceSpecification serviceSpecification = new ServiceSpecification();
46 serviceSpecification.setId((String) serviceCatalogResponse.get("id"));
47 serviceSpecification.setCatalogResponse(serviceCatalogResponse);
48 serviceSpecificationRepository.save(serviceSpecification);
52 public boolean checkServiceSpecExistence(String serviceSpecId) {
54 return serviceSpecificationRepository.existsById(serviceSpecId);
57 public Map getServiceSpecification(String serviceSpecId) {
59 Optional<ServiceSpecification> optionalServiceSpecification = serviceSpecificationRepository.findById(serviceSpecId);
60 if(!optionalServiceSpecification.isPresent()) {
61 throw new TechnicalException("Unable get service specification");
63 return optionalServiceSpecification.get().getCatalogResponse();
67 public boolean checkInputSchemaExistence(String serviceSpecId) {
68 return specificationInputSchemaRepository.existsById(serviceSpecId);
71 public String getInputSchema(String serviceSpecId) {
72 Optional<SpecificationInputSchema> optionalSpecificationInputSchema = specificationInputSchemaRepository.findById(serviceSpecId);
73 if(!optionalSpecificationInputSchema.isPresent()) {
74 throw new TechnicalException("Unable get specification input schema");
76 return optionalSpecificationInputSchema.get().getSpecificationSchemaJson();
80 public void saveSpecificationInputSchema(String svcCharacteristicsJson, Map serviceCatalogResponse) {
81 SpecificationInputSchema specificationInputSchema = new SpecificationInputSchema();
82 specificationInputSchema.setId((String) serviceCatalogResponse.get("id"));
83 specificationInputSchema.setSpecificationSchemaJson(svcCharacteristicsJson);
84 specificationInputSchemaRepository.save(specificationInputSchema);