Format Java code with respect to ONAP Code Style
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / servicecatalog / ServiceSpecificationDBManager.java
1 /**
2  *     Copyright (c) 2019 Amdocs
3  *
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
7  *
8  *         http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.nbi.apis.servicecatalog;
18
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;
28
29 import java.util.LinkedHashMap;
30 import java.util.Map;
31 import java.util.Optional;
32
33 @Service
34 public class ServiceSpecificationDBManager {
35
36     @Autowired
37     ServiceSpecificationRepository serviceSpecificationRepository;
38
39     @Autowired
40     SpecificationInputSchemaRepository specificationInputSchemaRepository;
41
42     private static final Logger LOGGER = LoggerFactory.getLogger(ServiceSpecificationService.class);
43
44     public void saveCatalogResponse(LinkedHashMap serviceCatalogResponse) {
45
46         ServiceSpecification serviceSpecification = new ServiceSpecification();
47         serviceSpecification.setId((String) serviceCatalogResponse.get("id"));
48         serviceSpecification.setCatalogResponse(serviceCatalogResponse);
49         serviceSpecificationRepository.save(serviceSpecification);
50
51     }
52
53     public boolean checkServiceSpecExistence(String serviceSpecId) {
54
55         return serviceSpecificationRepository.existsById(serviceSpecId);
56     }
57
58     public Map getServiceSpecification(String serviceSpecId) {
59
60         Optional<ServiceSpecification> optionalServiceSpecification =
61                 serviceSpecificationRepository.findById(serviceSpecId);
62         if (!optionalServiceSpecification.isPresent()) {
63             throw new TechnicalException("Unable get service specification");
64         } else {
65             return optionalServiceSpecification.get().getCatalogResponse();
66         }
67     }
68
69     public boolean checkInputSchemaExistence(String serviceSpecId) {
70         return specificationInputSchemaRepository.existsById(serviceSpecId);
71     }
72
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");
78         } else {
79             return optionalSpecificationInputSchema.get().getSpecificationSchemaJson();
80         }
81     }
82
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);
88
89     }
90 }