summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service/src/main')
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java40
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java12
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java17
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiOperations.java49
4 files changed, 37 insertions, 81 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
index 240d6b5ca9..82145efc3d 100755
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
@@ -27,13 +27,13 @@ import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum
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;
@@ -50,11 +50,13 @@ import org.onap.cps.ncmp.api.models.PersistenceCmHandlesList;
import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
import org.onap.cps.spi.exceptions.DataValidationException;
import org.onap.cps.spi.model.ModuleReference;
+import org.onap.cps.utils.JsonObjectMapper;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
@Slf4j
@Service
+@RequiredArgsConstructor
public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService {
private static final String NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME = "NFP-Operational";
@@ -65,37 +67,17 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
private static final OffsetDateTime NO_TIMESTAMP = null;
- private CpsDataService cpsDataService;
+ private final CpsDataService cpsDataService;
- private ObjectMapper objectMapper;
+ private final JsonObjectMapper jsonObjectMapper;
- private DmiDataOperations dmiDataOperations;
+ private final DmiDataOperations dmiDataOperations;
- private DmiModelOperations dmiModelOperations;
+ private final DmiModelOperations dmiModelOperations;
- private CpsModuleService cpsModuleService;
+ private final CpsModuleService cpsModuleService;
- private CpsAdminService cpsAdminService;
-
- /**
- * Constructor Injection for Dependencies.
- * @param dmiDataOperations DMI operation
- * @param cpsDataService Data Service Interface
- * @param objectMapper Object Mapper
- */
- public NetworkCmProxyDataServiceImpl(final DmiDataOperations dmiDataOperations,
- final DmiModelOperations dmiModelOperations,
- final CpsModuleService cpsModuleService,
- final CpsDataService cpsDataService,
- final CpsAdminService cpsAdminService,
- final ObjectMapper objectMapper) {
- this.dmiDataOperations = dmiDataOperations;
- this.dmiModelOperations = dmiModelOperations;
- this.cpsModuleService = cpsModuleService;
- this.cpsDataService = cpsDataService;
- this.cpsAdminService = cpsAdminService;
- this.objectMapper = objectMapper;
- }
+ private final CpsAdminService cpsAdminService;
@Override
public void updateDmiRegistrationAndSyncModule(final DmiPluginRegistration dmiPluginRegistration) {
@@ -198,7 +180,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
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);
}
@@ -223,7 +205,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
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);
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java
index 095f677ef8..3bfb424a2e 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
+ * Copyright (C) 2021-2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,10 +25,10 @@ import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum
import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.READ;
import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.DATA;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.onap.cps.ncmp.api.impl.client.DmiRestClient;
import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration;
import org.onap.cps.ncmp.api.models.PersistenceCmHandle;
+import org.onap.cps.utils.JsonObjectMapper;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
@@ -45,10 +45,10 @@ public class DmiDataOperations extends DmiOperations {
* @param dmiRestClient {@code DmiRestClient}
*/
public DmiDataOperations(final PersistenceCmHandleRetriever cmHandlePropertiesRetriever,
- final ObjectMapper objectMapper,
+ final JsonObjectMapper jsonObjectMapper,
final NcmpConfiguration.DmiProperties dmiProperties,
final DmiRestClient dmiRestClient) {
- super(cmHandlePropertiesRetriever, objectMapper, dmiProperties, dmiRestClient);
+ super(cmHandlePropertiesRetriever, jsonObjectMapper, dmiProperties, dmiRestClient);
}
/**
@@ -73,7 +73,7 @@ public class DmiDataOperations extends DmiOperations {
.operation(READ)
.build();
dmiRequestBody.asCmHandleProperties(persistenceCmHandle.getAdditionalProperties());
- final String jsonBody = getDmiRequestBodyAsString(dmiRequestBody);
+ final String jsonBody = jsonObjectMapper.asJsonString(dmiRequestBody);
final var dmiResourceDataUrl = getDmiDatastoreUrlWithOptions(
persistenceCmHandle.resolveDmiServiceName(DATA), cmHandle, resourceId,
@@ -106,7 +106,7 @@ public class DmiDataOperations extends DmiOperations {
.dataType(dataType)
.build();
dmiRequestBody.asCmHandleProperties(persistenceCmHandle.getAdditionalProperties());
- final String jsonBody = getDmiRequestBodyAsString(dmiRequestBody);
+ final String jsonBody = jsonObjectMapper.asJsonString(dmiRequestBody);
final String dmiUrl =
getResourceInDataStoreUrl(persistenceCmHandle.resolveDmiServiceName(DATA),
cmHandle, resourceId, PASSTHROUGH_RUNNING);
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java
index 20a3309d01..1ce6dcfcd5 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
+ * Copyright (C) 2021-2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,6 @@ package org.onap.cps.ncmp.api.impl.operations;
import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.MODEL;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.ArrayList;
@@ -34,10 +33,14 @@ import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration;
import org.onap.cps.ncmp.api.models.PersistenceCmHandle;
import org.onap.cps.ncmp.api.models.YangResource;
import org.onap.cps.spi.model.ModuleReference;
+import org.onap.cps.utils.JsonObjectMapper;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
+/**
+ * Operations class for DMI Model.
+ */
@Component
public class DmiModelOperations extends DmiOperations {
@@ -47,10 +50,10 @@ public class DmiModelOperations extends DmiOperations {
* @param dmiRestClient {@code DmiRestClient}
*/
public DmiModelOperations(final PersistenceCmHandleRetriever cmHandlePropertiesRetriever,
- final ObjectMapper objectMapper,
+ final JsonObjectMapper jsonObjectMapper,
final NcmpConfiguration.DmiProperties dmiProperties,
final DmiRestClient dmiRestClient) {
- super(cmHandlePropertiesRetriever, objectMapper, dmiProperties, dmiRestClient);
+ super(cmHandlePropertiesRetriever, jsonObjectMapper, dmiProperties, dmiRestClient);
}
/**
@@ -65,7 +68,7 @@ public class DmiModelOperations extends DmiOperations {
dmiRequestBody.asCmHandleProperties(persistenceCmHandle.getAdditionalProperties());
final ResponseEntity<Object> dmiFetchModulesResponseEntity = getResourceFromDmiWithJsonData(
persistenceCmHandle.resolveDmiServiceName(MODEL),
- getDmiRequestBodyAsString(dmiRequestBody), persistenceCmHandle.getId(), "modules");
+ jsonObjectMapper.asJsonString(dmiRequestBody), persistenceCmHandle.getId(), "modules");
return toModuleReferences((Map) dmiFetchModulesResponseEntity.getBody());
}
@@ -144,7 +147,7 @@ public class DmiModelOperations extends DmiOperations {
if (moduleReferencesAsList != null) {
moduleReferencesAsList.forEach(moduleReferenceAsMap -> {
final ModuleReference moduleReference =
- objectMapper.convertValue(moduleReferenceAsMap, ModuleReference.class);
+ jsonObjectMapper.convertToValueType(moduleReferenceAsMap, ModuleReference.class);
moduleReferences.add(moduleReference);
});
}
@@ -159,7 +162,7 @@ public class DmiModelOperations extends DmiOperations {
if (yangResourcesAsList != null) {
yangResourcesAsList.forEach(yangResourceAsMap -> {
final YangResource yangResource =
- objectMapper.convertValue(yangResourceAsMap, YangResource.class);
+ jsonObjectMapper.convertToValueType(yangResourceAsMap, YangResource.class);
yangResourcesModuleNameToContentMap.put(yangResource.getModuleName(),
yangResource.getYangSource());
});
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiOperations.java
index 509728061e..2f7376e87c 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiOperations.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiOperations.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
+ * Copyright (C) 2021-2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,17 +20,19 @@
package org.onap.cps.ncmp.api.impl.operations;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import lombok.Getter;
+import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.api.impl.client.DmiRestClient;
import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration;
-import org.onap.cps.ncmp.api.impl.exception.NcmpException;
+import org.onap.cps.utils.JsonObjectMapper;
import org.springframework.http.HttpHeaders;
+import org.springframework.stereotype.Service;
@Slf4j
+@RequiredArgsConstructor
+@Service
public class DmiOperations {
@Getter
@@ -44,28 +46,13 @@ public class DmiOperations {
}
}
- protected ObjectMapper objectMapper;
- protected PersistenceCmHandleRetriever cmHandlePropertiesRetriever;
- protected DmiRestClient dmiRestClient;
- protected NcmpConfiguration.DmiProperties dmiProperties;
+ protected final PersistenceCmHandleRetriever cmHandlePropertiesRetriever;
+ protected final JsonObjectMapper jsonObjectMapper;
+ protected final NcmpConfiguration.DmiProperties dmiProperties;
+ protected final DmiRestClient dmiRestClient;
static final String URL_SEPARATOR = "/";
- /**
- * Constructor for {@code DmiOperations}. This method also manipulates url properties.
- *
- * @param dmiRestClient {@code DmiRestClient}
- */
- public DmiOperations(final PersistenceCmHandleRetriever cmHandlePropertiesRetriever,
- final ObjectMapper objectMapper,
- final NcmpConfiguration.DmiProperties dmiProperties,
- final DmiRestClient dmiRestClient) {
- this.cmHandlePropertiesRetriever = cmHandlePropertiesRetriever;
- this.objectMapper = objectMapper;
- this.dmiRestClient = dmiRestClient;
- this.dmiProperties = dmiProperties;
- }
-
String getCmHandleUrl(final String dmiServiceName, final String cmHandle) {
return dmiServiceName
+ dmiProperties.getDmiBasePath()
@@ -95,20 +82,4 @@ public class DmiOperations {
return httpHeaders;
}
- /**
- * Convert DmiRequestBody to JSON.
- *
- * @param dmiRequestBody the dmi request body
- * @return DmiRequestBody as JSON
- */
- String getDmiRequestBodyAsString(final DmiRequestBody dmiRequestBody) {
- try {
- return objectMapper.writeValueAsString(dmiRequestBody);
- } catch (final JsonProcessingException e) {
- log.error("Parsing error occurred while converting Object to JSON.");
- throw new NcmpException("Parsing error occurred while converting given object to JSON.",
- e.getMessage());
- }
- }
-
}