2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation
4 * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
5 * Modifications Copyright (C) 2021 Pantheon.tech
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * 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 org.onap.cps.api.CpsAdminService;
25 import org.onap.cps.api.CpsDataService;
26 import org.onap.cps.api.CpsModuleService;
27 import org.onap.cps.spi.CpsDataPersistenceService;
28 import org.onap.cps.spi.FetchDescendantsOption;
29 import org.onap.cps.spi.model.Anchor;
30 import org.onap.cps.spi.model.DataNode;
31 import org.onap.cps.spi.model.DataNodeBuilder;
32 import org.onap.cps.utils.YangUtils;
33 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
34 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Service;
39 public class CpsDataServiceImpl implements CpsDataService {
42 private CpsDataPersistenceService cpsDataPersistenceService;
45 private CpsAdminService cpsAdminService;
48 private CpsModuleService cpsModuleService;
51 private YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache;
54 public void saveData(final String dataspaceName, final String anchorName, final String jsonData) {
55 final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
56 final SchemaContext schemaContext = getSchemaContext(dataspaceName, anchor.getSchemaSetName());
57 final NormalizedNode normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext);
58 final DataNode dataNode = new DataNodeBuilder().withNormalizedNodeTree(normalizedNode).build();
59 cpsDataPersistenceService.storeDataNode(dataspaceName, anchor.getName(), dataNode);
62 private SchemaContext getSchemaContext(final String dataspaceName, final String schemaSetName) {
63 return yangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName).getSchemaContext();
67 public DataNode getDataNode(final String dataspaceName, final String anchorName, final String xpath,
68 final FetchDescendantsOption fetchDescendantsOption) {
69 return cpsDataPersistenceService.getDataNode(dataspaceName, anchorName, xpath, fetchDescendantsOption);