/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 highstreet technologies GmbH
- * Modifications Copyright (C) 2021 Nordix Foundation
+ * Modifications Copyright (C) 2021-2022 Nordix Foundation
* Modifications Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2021 Bell Canada
* ================================================================================
import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED;
import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.api.CpsModuleService;
-import org.onap.cps.api.CpsQueryService;
import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
-import org.onap.cps.ncmp.api.impl.exception.NcmpException;
+import org.onap.cps.ncmp.api.impl.exception.ServerNcmpException;
import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations;
import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations;
import org.onap.cps.ncmp.api.impl.operations.DmiOperations;
import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
import org.onap.cps.ncmp.api.models.PersistenceCmHandle;
import org.onap.cps.ncmp.api.models.PersistenceCmHandlesList;
-import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
import org.onap.cps.spi.exceptions.DataValidationException;
-import org.onap.cps.spi.model.DataNode;
import org.onap.cps.spi.model.ModuleReference;
+import org.onap.cps.utils.JsonObjectMapper;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
-import org.springframework.util.StringUtils;
@Slf4j
@Service
+@RequiredArgsConstructor
public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService {
private static final String NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME = "NFP-Operational";
private static final OffsetDateTime NO_TIMESTAMP = null;
- private CpsDataService cpsDataService;
+ private final CpsDataService cpsDataService;
- private ObjectMapper objectMapper;
+ private final JsonObjectMapper jsonObjectMapper;
- private CpsQueryService cpsQueryService;
+ private final DmiDataOperations dmiDataOperations;
- private DmiDataOperations dmiDataOperations;
+ private final DmiModelOperations dmiModelOperations;
- private DmiModelOperations dmiModelOperations;
+ private final CpsModuleService cpsModuleService;
- private CpsModuleService cpsModuleService;
-
- private CpsAdminService cpsAdminService;
-
- /**
- * Constructor Injection for Dependencies.
- * @param dmiDataOperations DMI operation
- * @param cpsDataService Data Service Interface
- * @param cpsQueryService Query Service Interface
- * @param objectMapper Object Mapper
- */
- public NetworkCmProxyDataServiceImpl(final DmiDataOperations dmiDataOperations,
- final DmiModelOperations dmiModelOperations,
- final CpsModuleService cpsModuleService,
- final CpsDataService cpsDataService,
- final CpsQueryService cpsQueryService,
- final CpsAdminService cpsAdminService,
- final ObjectMapper objectMapper) {
- this.dmiDataOperations = dmiDataOperations;
- this.dmiModelOperations = dmiModelOperations;
- this.cpsModuleService = cpsModuleService;
- this.cpsDataService = cpsDataService;
- this.cpsQueryService = cpsQueryService;
- this.cpsAdminService = cpsAdminService;
- this.objectMapper = objectMapper;
- }
-
- @Override
- public DataNode getDataNode(final String cmHandle, final String xpath,
- final FetchDescendantsOption fetchDescendantsOption) {
- return cpsDataService
- .getDataNode(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle, xpath, fetchDescendantsOption);
- }
-
- @Override
- public Collection<DataNode> queryDataNodes(final String cmHandle, final String cpsPath,
- final FetchDescendantsOption fetchDescendantsOption) {
- return cpsQueryService
- .queryDataNodes(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle, cpsPath, fetchDescendantsOption);
- }
-
- @Override
- public void createDataNode(final String cmHandle, final String parentNodeXpath, final String jsonData) {
- if (!StringUtils.hasText(parentNodeXpath) || "/".equals(parentNodeXpath)) {
- cpsDataService.saveData(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle, jsonData, NO_TIMESTAMP);
- } else {
- cpsDataService
- .saveData(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle, parentNodeXpath, jsonData, NO_TIMESTAMP);
- }
- }
-
- @Override
- public void addListNodeElements(final String cmHandle, final String parentNodeXpath, final String jsonData) {
- cpsDataService.saveListElements(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle, parentNodeXpath, jsonData,
- NO_TIMESTAMP);
- }
-
- @Override
- public void updateNodeLeaves(final String cmHandle, final String parentNodeXpath, final String jsonData) {
- cpsDataService
- .updateNodeLeaves(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle, parentNodeXpath, jsonData,
- NO_TIMESTAMP);
- }
-
- @Override
- public void replaceNodeTree(final String cmHandle, final String parentNodeXpath, final String jsonData) {
- cpsDataService.replaceNodeTree(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle, parentNodeXpath, jsonData,
- NO_TIMESTAMP);
- }
+ private final CpsAdminService cpsAdminService;
@Override
public void updateDmiRegistrationAndSyncModule(final DmiPluginRegistration dmiPluginRegistration) {
if (responseEntity.getStatusCode().is2xxSuccessful()) {
return responseEntity.getBody();
} else {
- throw new NcmpException(exceptionMessage,
+ throw new ServerNcmpException(exceptionMessage,
"DMI status code: " + responseEntity.getStatusCodeValue()
+ ", DMI response body: " + responseEntity.getBody());
}
throws JsonProcessingException {
final PersistenceCmHandlesList updatedPersistenceCmHandlesList =
getUpdatedPersistenceCmHandlesList(dmiPluginRegistration, dmiPluginRegistration.getUpdatedCmHandles());
- final String cmHandlesAsJson = objectMapper.writeValueAsString(updatedPersistenceCmHandlesList);
+ final String cmHandlesAsJson = jsonObjectMapper.asJsonString(updatedPersistenceCmHandlesList);
cpsDataService.updateNodeLeavesAndExistingDescendantLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
"/dmi-registry", cmHandlesAsJson, NO_TIMESTAMP);
}
private void registerAndSyncNewCmHandles(final PersistenceCmHandlesList persistenceCmHandlesList)
throws JsonProcessingException {
- final String cmHandleJsonData = objectMapper.writeValueAsString(persistenceCmHandlesList);
+ final String cmHandleJsonData = jsonObjectMapper.asJsonString(persistenceCmHandlesList);
cpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, "/dmi-registry",
cmHandleJsonData, NO_TIMESTAMP);