10326413c320595cf2ac265d8277340948647157
[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.Collection;
25 import java.util.List;
26 import java.util.Map;
27 import org.onap.cps.api.CpsModuleService;
28 import org.onap.cps.spi.CascadeDeleteAllowed;
29 import org.onap.cps.spi.CpsModulePersistenceService;
30 import org.onap.cps.spi.model.ModuleReference;
31 import org.onap.cps.spi.model.SchemaSet;
32 import org.onap.cps.yang.YangTextSchemaSourceSetBuilder;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Service;
35
36 @Service("CpsModuleServiceImpl")
37 public class CpsModuleServiceImpl implements CpsModuleService {
38
39     @Autowired
40     private CpsModulePersistenceService cpsModulePersistenceService;
41
42     @Autowired
43     private YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache;
44
45     @Override
46     public void createSchemaSet(final String dataspaceName, final String schemaSetName,
47         final Map<String, String> yangResourcesNameToContentMap) {
48         final var yangTextSchemaSourceSet
49             = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap);
50         cpsModulePersistenceService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap);
51         yangTextSchemaSourceSetCache.updateCache(dataspaceName, schemaSetName, yangTextSchemaSourceSet);
52     }
53
54     @Override
55     public void createSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
56                                            final Map<String, String> newYangResourcesModuleNameToContentMap,
57                                            final List<ModuleReference> moduleReferences) {
58         cpsModulePersistenceService.storeSchemaSetFromModules(dataspaceName, schemaSetName,
59                 newYangResourcesModuleNameToContentMap, moduleReferences);
60
61     }
62
63     @Override
64     public SchemaSet getSchemaSet(final String dataspaceName, final String schemaSetName) {
65         final var yangTextSchemaSourceSet = yangTextSchemaSourceSetCache
66             .get(dataspaceName, schemaSetName);
67         return SchemaSet.builder().name(schemaSetName).dataspaceName(dataspaceName)
68             .extendedModuleReferences(yangTextSchemaSourceSet.getModuleReferences()).build();
69     }
70
71     @Override
72     public void deleteSchemaSet(final String dataspaceName, final String schemaSetName,
73         final CascadeDeleteAllowed cascadeDeleteAllowed) {
74         cpsModulePersistenceService.deleteSchemaSet(dataspaceName, schemaSetName, cascadeDeleteAllowed);
75     }
76
77     @Override
78     public Collection<ModuleReference> getYangResourceModuleReferences(final String dataspaceName) {
79         return cpsModulePersistenceService.getYangResourceModuleReferences(dataspaceName);
80     }
81
82     @Override
83     public Collection<ModuleReference> getYangResourcesModuleReferences(final String dataspaceName,
84         final String anchorName) {
85         return cpsModulePersistenceService.getYangResourceModuleReferences(dataspaceName, anchorName);
86     }
87 }