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;
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;
33 @Service("CpsModuleServiceImpl")
34 public class CpsModuleServiceImpl implements CpsModuleService {
37 private CpsModulePersistenceService cpsModulePersistenceService;
40 private YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache;
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);
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();
60 public void deleteSchemaSet(final String dataspaceName, final String schemaSetName,
61 final CascadeDeleteAllowed cascadeDeleteAllowed) {
62 cpsModulePersistenceService.deleteSchemaSet(dataspaceName, schemaSetName, cascadeDeleteAllowed);