2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 highstreet technologies GmbH
4 * Modifications Copyright (C) 2021 Nordix Foundation
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
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.cps.ncmp.api.impl;
25 import com.fasterxml.jackson.core.JsonProcessingException;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import java.util.ArrayList;
28 import java.util.Collection;
29 import java.util.List;
30 import lombok.extern.slf4j.Slf4j;
31 import org.onap.cps.api.CpsDataService;
32 import org.onap.cps.api.CpsQueryService;
33 import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
34 import org.onap.cps.ncmp.api.models.CmHandle;
35 import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
36 import org.onap.cps.ncmp.api.models.PersistenceCmHandle;
37 import org.onap.cps.ncmp.api.models.PersistenceCmHandlesList;
38 import org.onap.cps.spi.FetchDescendantsOption;
39 import org.onap.cps.spi.exceptions.DataValidationException;
40 import org.onap.cps.spi.model.DataNode;
41 import org.springframework.stereotype.Service;
42 import org.springframework.util.StringUtils;
46 public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService {
48 private static final String NF_PROXY_DATASPACE_NAME = "NFP-Operational";
50 private static final String NCMP_DATASPACE_NAME = "NCMP-Admin";
52 private static final String NCMP_ANCHOR_NAME = "ncmp-dmi-registry";
54 private CpsDataService cpsDataService;
56 private ObjectMapper objectMapper;
58 private CpsQueryService cpsQueryService;
61 * Constructor Injection for Dependencies.
62 * @param cpsDataService Data Service Interface
63 * @param cpsQueryService Query Service Interface
64 * @param objectMapper Object Mapper
66 public NetworkCmProxyDataServiceImpl(final CpsDataService cpsDataService,
67 final CpsQueryService cpsQueryService, final ObjectMapper objectMapper) {
68 this.cpsDataService = cpsDataService;
69 this.cpsQueryService = cpsQueryService;
70 this.objectMapper = objectMapper;
73 private String getDataspaceName() {
74 return NF_PROXY_DATASPACE_NAME;
78 public DataNode getDataNode(final String cmHandle, final String xpath,
79 final FetchDescendantsOption fetchDescendantsOption) {
80 return cpsDataService.getDataNode(getDataspaceName(), cmHandle, xpath, fetchDescendantsOption);
84 public Collection<DataNode> queryDataNodes(final String cmHandle, final String cpsPath,
85 final FetchDescendantsOption fetchDescendantsOption) {
86 return cpsQueryService.queryDataNodes(getDataspaceName(), cmHandle, cpsPath, fetchDescendantsOption);
90 public void createDataNode(final String cmHandle, final String parentNodeXpath, final String jsonData) {
91 if (!StringUtils.hasText(parentNodeXpath) || "/".equals(parentNodeXpath)) {
92 cpsDataService.saveData(getDataspaceName(), cmHandle, jsonData);
94 cpsDataService.saveData(getDataspaceName(), cmHandle, parentNodeXpath, jsonData);
99 public void addListNodeElements(final String cmHandle, final String parentNodeXpath, final String jsonData) {
100 cpsDataService.saveListNodeData(getDataspaceName(), cmHandle, parentNodeXpath, jsonData);
104 public void updateNodeLeaves(final String cmHandle, final String parentNodeXpath, final String jsonData) {
105 cpsDataService.updateNodeLeaves(getDataspaceName(), cmHandle, parentNodeXpath, jsonData);
109 public void replaceNodeTree(final String cmHandle, final String parentNodeXpath, final String jsonData) {
110 cpsDataService.replaceNodeTree(getDataspaceName(), cmHandle, parentNodeXpath, jsonData);
114 public void updateDmiPluginRegistration(final DmiPluginRegistration dmiPluginRegistration) {
116 final List<PersistenceCmHandle> persistenceCmHandles =
118 for (final CmHandle cmHandle: dmiPluginRegistration.getCreatedCmHandles()) {
119 final var persistenceCmHandle = new PersistenceCmHandle();
120 persistenceCmHandle.setDmiServiceName(dmiPluginRegistration.getDmiPlugin());
121 persistenceCmHandle.setId(cmHandle.getCmHandleID());
122 persistenceCmHandle.setAdditionalProperties(cmHandle.getCmHandleProperties());
123 persistenceCmHandles.add(persistenceCmHandle);
125 final var persistenceCmHandlesList = new PersistenceCmHandlesList();
126 persistenceCmHandlesList.setCmHandles(persistenceCmHandles);
127 final var cmHandleJsonData = objectMapper.writeValueAsString(persistenceCmHandlesList);
128 cpsDataService.saveListNodeData(NCMP_DATASPACE_NAME, NCMP_ANCHOR_NAME, "/dmi-registry",
130 } catch (final JsonProcessingException e) {
131 throw new DataValidationException(
132 "Parsing error occurred while processing DMI Plugin Registration" + dmiPluginRegistration, e