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.
17 package org.onap.nbi.apis.servicecatalog;
19 import org.onap.nbi.apis.servicecatalog.model.ServiceSpecification;
20 import org.onap.nbi.apis.servicecatalog.model.SpecificationInputSchema;
21 import org.onap.nbi.apis.servicecatalog.repositories.ServiceSpecificationRepository;
22 import org.onap.nbi.apis.servicecatalog.repositories.SpecificationInputSchemaRepository;
23 import org.onap.nbi.exceptions.TechnicalException;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.stereotype.Service;
29 import java.util.LinkedHashMap;
31 import java.util.Optional;
34 public class ServiceSpecificationDBManager {
37 ServiceSpecificationRepository serviceSpecificationRepository;
40 SpecificationInputSchemaRepository specificationInputSchemaRepository;
42 private static final Logger LOGGER = LoggerFactory.getLogger(ServiceSpecificationService.class);
44 public void saveCatalogResponse(LinkedHashMap serviceCatalogResponse) {
46 ServiceSpecification serviceSpecification = new ServiceSpecification();
47 serviceSpecification.setId((String) serviceCatalogResponse.get("id"));
48 serviceSpecification.setCatalogResponse(serviceCatalogResponse);
49 serviceSpecificationRepository.save(serviceSpecification);
53 public boolean checkServiceSpecExistence(String serviceSpecId) {
55 return serviceSpecificationRepository.existsById(serviceSpecId);
58 public Map getServiceSpecification(String serviceSpecId) {
60 Optional<ServiceSpecification> optionalServiceSpecification =
61 serviceSpecificationRepository.findById(serviceSpecId);
62 if (!optionalServiceSpecification.isPresent()) {
63 throw new TechnicalException("Unable get service specification");
65 return optionalServiceSpecification.get().getCatalogResponse();
69 public boolean checkInputSchemaExistence(String serviceSpecId) {
70 return specificationInputSchemaRepository.existsById(serviceSpecId);
73 public String getInputSchema(String serviceSpecId) {
74 Optional<SpecificationInputSchema> optionalSpecificationInputSchema =
75 specificationInputSchemaRepository.findById(serviceSpecId);
76 if (!optionalSpecificationInputSchema.isPresent()) {
77 throw new TechnicalException("Unable get specification input schema");
79 return optionalSpecificationInputSchema.get().getSpecificationSchemaJson();
83 public void saveSpecificationInputSchema(String svcCharacteristicsJson, Map serviceCatalogResponse) {
84 SpecificationInputSchema specificationInputSchema = new SpecificationInputSchema();
85 specificationInputSchema.setId((String) serviceCatalogResponse.get("id"));
86 specificationInputSchema.setSpecificationSchemaJson(svcCharacteristicsJson);
87 specificationInputSchemaRepository.save(specificationInputSchema);