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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.cps.api.impl;
24 import java.util.Collection;
25 import java.util.List;
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;
36 @Service("CpsModuleServiceImpl")
37 public class CpsModuleServiceImpl implements CpsModuleService {
40 private CpsModulePersistenceService cpsModulePersistenceService;
43 private YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache;
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);
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);
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();
72 public void deleteSchemaSet(final String dataspaceName, final String schemaSetName,
73 final CascadeDeleteAllowed cascadeDeleteAllowed) {
74 cpsModulePersistenceService.deleteSchemaSet(dataspaceName, schemaSetName, cascadeDeleteAllowed);
78 public Collection<ModuleReference> getYangResourceModuleReferences(final String dataspaceName) {
79 return cpsModulePersistenceService.getYangResourceModuleReferences(dataspaceName);
83 public Collection<ModuleReference> getYangResourcesModuleReferences(final String dataspaceName,
84 final String anchorName) {
85 return cpsModulePersistenceService.getYangResourceModuleReferences(dataspaceName, anchorName);