2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.ncmp.api.impl.inventory;
23 import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED;
24 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
26 import io.micrometer.core.annotation.Timed;
27 import java.util.Collection;
28 import lombok.RequiredArgsConstructor;
29 import lombok.extern.slf4j.Slf4j;
30 import org.onap.cps.api.CpsDataService;
31 import org.onap.cps.api.CpsModuleService;
32 import org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence;
33 import org.onap.cps.spi.FetchDescendantsOption;
34 import org.onap.cps.spi.exceptions.SchemaSetNotFoundException;
35 import org.onap.cps.spi.model.DataNode;
36 import org.onap.cps.spi.utils.CpsValidator;
37 import org.onap.cps.utils.JsonObjectMapper;
38 import org.springframework.stereotype.Component;
41 @RequiredArgsConstructor
43 public class NcmpPersistenceImpl implements NcmpPersistence {
45 protected final JsonObjectMapper jsonObjectMapper;
46 protected final CpsDataService cpsDataService;
47 private final CpsModuleService cpsModuleService;
48 private final CpsValidator cpsValidator;
51 public void deleteListOrListElement(final String listElementXpath) {
52 cpsDataService.deleteListOrListElement(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, listElementXpath,
57 @Timed(value = "cps.ncmp.inventory.persistence.schemaset.delete",
58 description = "Time taken to delete a schemaset")
59 public void deleteSchemaSetWithCascade(final String schemaSetName) {
61 cpsValidator.validateNameCharacters(schemaSetName);
62 cpsModuleService.deleteSchemaSet(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetName,
63 CASCADE_DELETE_ALLOWED);
64 } catch (final SchemaSetNotFoundException schemaSetNotFoundException) {
65 log.warn("Schema set {} does not exist or already deleted", schemaSetName);
70 @Timed(value = "cps.ncmp.inventory.persistence.schemaset.delete.batch",
71 description = "Time taken to delete multiple schemaset")
72 public void deleteSchemaSetsWithCascade(final Collection<String> schemaSetNames) {
73 cpsValidator.validateNameCharacters(schemaSetNames);
74 cpsModuleService.deleteSchemaSetsWithCascade(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetNames);
78 @Timed(value = "cps.ncmp.inventory.persistence.datanode.get",
79 description = "Time taken to get a data node (from ncmp dmi registry)")
80 public Collection<DataNode> getDataNode(final String xpath) {
81 return getDataNode(xpath, INCLUDE_ALL_DESCENDANTS);
85 @Timed(value = "cps.ncmp.inventory.persistence.datanode.get",
86 description = "Time taken to get a data node (from ncmp dmi registry)")
87 public Collection<DataNode> getDataNode(final String xpath, final FetchDescendantsOption fetchDescendantsOption) {
88 return cpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpath,
89 fetchDescendantsOption);
93 public Collection<DataNode> getDataNodes(final Collection<String> xpaths) {
94 return getDataNodes(xpaths, INCLUDE_ALL_DESCENDANTS);
98 public Collection<DataNode> getDataNodes(final Collection<String> xpaths,
99 final FetchDescendantsOption fetchDescendantsOption) {
100 return cpsDataService.getDataNodesForMultipleXpaths(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpaths,
101 fetchDescendantsOption);
105 public void replaceListContent(final String parentNodeXpath, final Collection<DataNode> dataNodes) {
106 cpsDataService.replaceListContent(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, parentNodeXpath, dataNodes,
111 public void deleteDataNode(final String dataNodeXpath) {
112 cpsDataService.deleteDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, dataNodeXpath, NO_TIMESTAMP);
116 public void deleteDataNodes(final Collection<String> dataNodeXpaths) {
117 cpsDataService.deleteDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, dataNodeXpaths, NO_TIMESTAMP);