Editing of Nordix Licenses to ONAP guidelines
[cps.git] / cps-service / src / main / java / org / onap / cps / api / impl / CpsModuleServiceImpl.java
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2020-2021 Nordix Foundation
4  *  Modifications Copyright (C) 2020-2021 Pantheon.tech
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.onap.cps.api.impl;
23
24 import java.util.Map;
25 import org.onap.cps.api.CpsModuleService;
26 import org.onap.cps.spi.CascadeDeleteAllowed;
27 import org.onap.cps.spi.CpsModulePersistenceService;
28 import org.onap.cps.spi.model.SchemaSet;
29 import org.onap.cps.yang.YangTextSchemaSourceSetBuilder;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Service;
32
33 @Service("CpsModuleServiceImpl")
34 public class CpsModuleServiceImpl implements CpsModuleService {
35
36     @Autowired
37     private CpsModulePersistenceService cpsModulePersistenceService;
38
39     @Autowired
40     private YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache;
41
42     @Override
43     public void createSchemaSet(final String dataspaceName, final String schemaSetName,
44         final Map<String, String> yangResourcesNameToContentMap) {
45         final var yangTextSchemaSourceSet
46             = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap);
47         cpsModulePersistenceService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap);
48         yangTextSchemaSourceSetCache.updateCache(dataspaceName, schemaSetName, yangTextSchemaSourceSet);
49     }
50
51     @Override
52     public SchemaSet getSchemaSet(final String dataspaceName, final String schemaSetName) {
53         final var yangTextSchemaSourceSet = yangTextSchemaSourceSetCache
54             .get(dataspaceName, schemaSetName);
55         return SchemaSet.builder().name(schemaSetName).dataspaceName(dataspaceName)
56             .moduleReferences(yangTextSchemaSourceSet.getModuleReferences()).build();
57     }
58
59     @Override
60     public void deleteSchemaSet(final String dataspaceName, final String schemaSetName,
61         final CascadeDeleteAllowed cascadeDeleteAllowed) {
62         cpsModulePersistenceService.deleteSchemaSet(dataspaceName, schemaSetName, cascadeDeleteAllowed);
63     }
64 }