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.java51
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java8
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java23
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java4
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java52
5 files changed, 74 insertions, 64 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 62a0922d03..7ded95fa06 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
@@ -28,10 +28,6 @@ import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.gson.Gson;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Collection;
@@ -52,7 +48,6 @@ import org.onap.cps.ncmp.api.models.CmHandle;
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.ncmp.api.models.YangResource;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
import org.onap.cps.spi.exceptions.DataValidationException;
@@ -316,9 +311,8 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
}
private void syncAndCreateSchemaSet(final PersistenceCmHandle persistenceCmHandle) {
-
final List<ModuleReference> moduleReferencesFromCmHandle =
- toModuleReferences(dmiModelOperations.getModuleReferences(persistenceCmHandle));
+ dmiModelOperations.getModuleReferences(persistenceCmHandle);
final List<ModuleReference> existingModuleReferences = new ArrayList<>();
final List<ModuleReference> unknownModuleReferences = new ArrayList<>();
prepareModuleSubsets(moduleReferencesFromCmHandle, existingModuleReferences, unknownModuleReferences);
@@ -327,7 +321,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
if (unknownModuleReferences.isEmpty()) {
newYangResourcesModuleNameToContentMap = new HashMap<>();
} else {
- newYangResourcesModuleNameToContentMap = getNewYangResourcesFromDmi(persistenceCmHandle,
+ newYangResourcesModuleNameToContentMap = dmiModelOperations.getNewYangResourcesFromDmi(persistenceCmHandle,
unknownModuleReferences);
}
cpsModuleService
@@ -356,47 +350,6 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
persistenceCmHandle.getId());
}
- private Map<String, String> getNewYangResourcesFromDmi(final PersistenceCmHandle persistenceCmHandle,
- final List<ModuleReference> unknownModuleReferences) {
- final ResponseEntity<String> responseEntity =
- dmiModelOperations.getNewYangResourcesFromDmi(persistenceCmHandle, unknownModuleReferences);
-
- final JsonArray moduleResources = new Gson().fromJson(responseEntity.getBody(),
- JsonArray.class);
- final Map<String, String> newYangResourcesModuleNameToContentMap = new HashMap<>();
-
- for (final JsonElement moduleResource : moduleResources) {
- final YangResource yangResource = toYangResource((JsonObject) moduleResource);
- newYangResourcesModuleNameToContentMap.put(yangResource.getModuleName(), yangResource.getYangSource());
- }
- return newYangResourcesModuleNameToContentMap;
- }
-
- private static YangResource toYangResource(final JsonObject yangResourceAsJson) {
- final YangResource yangResource = new YangResource();
- yangResource.setModuleName(yangResourceAsJson.get("moduleName").getAsString());
- yangResource.setRevision(yangResourceAsJson.get("revision").getAsString());
- yangResource.setYangSource(yangResourceAsJson.get("yangSource").getAsString());
- return yangResource;
- }
- private static List<ModuleReference> toModuleReferences(
- final ResponseEntity<String> dmiFetchModulesResponseEntity) {
- final List<ModuleReference> moduleReferences = new ArrayList<>();
- final JsonObject bodyAsJsonObject = new Gson().fromJson(dmiFetchModulesResponseEntity.getBody(),
- JsonObject.class);
- final JsonArray moduleReferencesAsJson = bodyAsJsonObject.getAsJsonArray("schemas");
- for (final JsonElement moduleReferenceAsJson : moduleReferencesAsJson) {
- final ModuleReference moduleReference = toModuleReference((JsonObject) moduleReferenceAsJson);
- moduleReferences.add(moduleReference);
- }
- return moduleReferences;
- }
- private static ModuleReference toModuleReference(final JsonObject moduleReferenceAsJson) {
- final ModuleReference moduleReference = new ModuleReference();
- moduleReference.setModuleName(moduleReferenceAsJson.get("moduleName").getAsString());
- moduleReference.setRevision(moduleReferenceAsJson.get("revision").getAsString());
- return moduleReference;
- }
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java
index 9f3df6b9a5..94faa557fa 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java
@@ -53,11 +53,11 @@ public class DmiRestClient {
* @param httpHeaders http headers
* @return response entity of type String
*/
- public ResponseEntity<String> postOperationWithJsonData(final String dmiResourceUrl,
+ public ResponseEntity<Object> postOperationWithJsonData(final String dmiResourceUrl,
final String jsonData,
final HttpHeaders httpHeaders) {
final var httpEntity = new HttpEntity<>(jsonData, configureHttpHeaders(httpHeaders));
- return restTemplate.postForEntity(dmiResourceUrl, httpEntity, String.class);
+ return restTemplate.postForEntity(dmiResourceUrl, httpEntity, Object.class);
}
private HttpHeaders configureHttpHeaders(final HttpHeaders httpHeaders) {
@@ -72,8 +72,8 @@ public class DmiRestClient {
* @param httpHeaders http headers
* @return response entity of type String
*/
- public ResponseEntity<String> postOperation(final String dmiResourceUrl, final HttpHeaders httpHeaders) {
+ public ResponseEntity<Object> postOperation(final String dmiResourceUrl, final HttpHeaders httpHeaders) {
final var httpEntity = new HttpEntity<>(configureHttpHeaders(httpHeaders));
- return restTemplate.exchange(dmiResourceUrl, HttpMethod.POST, httpEntity, String.class);
+ return restTemplate.exchange(dmiResourceUrl, HttpMethod.POST, httpEntity, Object.class);
}
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java
index 81c9dff402..60b44c2461 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java
@@ -20,11 +20,15 @@
package org.onap.cps.ncmp.api.impl.config;
+import java.util.Arrays;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Scope;
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
@@ -42,8 +46,25 @@ public class NcmpConfiguration {
private String dmiBasePath;
}
+ /**
+ * Rest template bean.
+ *
+ * @param restTemplateBuilder the rest template builder
+ * @return rest template instance
+ */
@Bean
+ @Scope("singleton")
public static RestTemplate restTemplate(final RestTemplateBuilder restTemplateBuilder) {
- return restTemplateBuilder.build();
+ final RestTemplate restTemplate = restTemplateBuilder.build();
+ setRestTemplateMessageConverters(restTemplate);
+ return restTemplate;
+ }
+
+ private static void setRestTemplateMessageConverters(final RestTemplate restTemplate) {
+ final MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter =
+ new MappingJackson2HttpMessageConverter();
+ mappingJackson2HttpMessageConverter.setSupportedMediaTypes(
+ Arrays.asList(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN));
+ restTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter);
}
}
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 eccb9a0987..095f677ef8 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
@@ -62,7 +62,7 @@ public class DmiDataOperations extends DmiOperations {
* @param dataStore data store enum
* @return {@code ResponseEntity} response entity
*/
- public ResponseEntity<String> getResourceDataFromDmi(final String cmHandle,
+ public ResponseEntity<Object> getResourceDataFromDmi(final String cmHandle,
final String resourceId,
final String optionsParamInQuery,
final String acceptParamInHeader,
@@ -93,7 +93,7 @@ public class DmiDataOperations extends DmiOperations {
* @param dataType data type
* @return {@code ResponseEntity} response entity
*/
- public ResponseEntity<String> writeResourceDataPassThroughRunningFromDmi(final String cmHandle,
+ public ResponseEntity<Object> writeResourceDataPassThroughRunningFromDmi(final String cmHandle,
final String resourceId,
final OperationEnum operation,
final String requestData,
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 c582584667..f74616ab30 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
@@ -25,10 +25,14 @@ 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;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
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.ncmp.api.models.YangResource;
import org.onap.cps.spi.model.ModuleReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
@@ -55,12 +59,14 @@ public class DmiModelOperations extends DmiOperations {
* @param persistenceCmHandle the persistence cm handle
* @return module references
*/
- public ResponseEntity<String> getModuleReferences(final PersistenceCmHandle persistenceCmHandle) {
+ public List<ModuleReference> getModuleReferences(final PersistenceCmHandle persistenceCmHandle) {
final DmiRequestBody dmiRequestBody = DmiRequestBody.builder()
.build();
dmiRequestBody.asCmHandleProperties(persistenceCmHandle.getAdditionalProperties());
- return getResourceFromDmiWithJsonData(persistenceCmHandle.resolveDmiServiceName(MODEL),
+ final ResponseEntity<Object> dmiFetchModulesResponseEntity = getResourceFromDmiWithJsonData(
+ persistenceCmHandle.resolveDmiServiceName(MODEL),
getDmiRequestBodyAsString(dmiRequestBody), persistenceCmHandle.getId(), "modules");
+ return toModuleReferences((Map) dmiFetchModulesResponseEntity.getBody());
}
/**
@@ -68,17 +74,18 @@ public class DmiModelOperations extends DmiOperations {
*
* @param persistenceCmHandle the persistenceCmHandle
* @param unknownModuleReferences the unknown module references
- * @return yang resources
+ * @return yang resources as map of module name to yang(re)source
*/
- public ResponseEntity<String> getNewYangResourcesFromDmi(final PersistenceCmHandle persistenceCmHandle,
- final List<ModuleReference> unknownModuleReferences) {
+ public Map<String, String> getNewYangResourcesFromDmi(final PersistenceCmHandle persistenceCmHandle,
+ final List<ModuleReference> unknownModuleReferences) {
final String jsonDataWithDataAndCmHandleProperties = getRequestBodyToFetchYangResources(
unknownModuleReferences, persistenceCmHandle.getAdditionalProperties());
- return getResourceFromDmiWithJsonData(
+ final ResponseEntity<Object> responseEntity = getResourceFromDmiWithJsonData(
persistenceCmHandle.resolveDmiServiceName(MODEL),
jsonDataWithDataAndCmHandleProperties,
persistenceCmHandle.getId(),
"moduleResources");
+ return asModuleNameToYangResourceMap(responseEntity);
}
/**
@@ -90,7 +97,7 @@ public class DmiModelOperations extends DmiOperations {
* @param resourceName name of the resource(s)
* @return {@code ResponseEntity} response entity
*/
- private ResponseEntity<String> getResourceFromDmiWithJsonData(final String dmiServiceName,
+ private ResponseEntity<Object> getResourceFromDmiWithJsonData(final String dmiServiceName,
final String jsonData,
final String cmHandle,
final String resourceName) {
@@ -122,7 +129,6 @@ public class DmiModelOperations extends DmiOperations {
}
private static JsonObject toJsonObject(final List<PersistenceCmHandle.AdditionalProperty> cmHandleProperties) {
- //TODO Toine/Joe Double check format with existing test data
final JsonObject asJsonObject = new JsonObject();
for (final PersistenceCmHandle.AdditionalProperty additionalProperty : cmHandleProperties) {
asJsonObject.addProperty(additionalProperty.getName(), additionalProperty.getValue());
@@ -130,4 +136,34 @@ public class DmiModelOperations extends DmiOperations {
return asJsonObject;
}
+ private List<ModuleReference> toModuleReferences(final Map dmiFetchModulesResponseAsMap) {
+ final List<ModuleReference> moduleReferences = new ArrayList<>();
+
+ if (dmiFetchModulesResponseAsMap != null) {
+ final List moduleReferencesAsList = (List) dmiFetchModulesResponseAsMap.get("schemas");
+ if (moduleReferencesAsList != null) {
+ moduleReferencesAsList.forEach(moduleReferenceAsMap -> {
+ final ModuleReference moduleReference =
+ objectMapper.convertValue(moduleReferenceAsMap, ModuleReference.class);
+ moduleReferences.add(moduleReference);
+ });
+ }
+ }
+ return moduleReferences;
+ }
+
+ private Map<String, String> asModuleNameToYangResourceMap(final ResponseEntity<Object> responseEntity) {
+ final Map<String, String> yangResourcesModuleNameToContentMap = new HashMap<>();
+ final List<Map<String, String>> yangResourcesAsList = (List) responseEntity.getBody();
+
+ if (yangResourcesAsList != null) {
+ yangResourcesAsList.forEach(yangResourceAsMap -> {
+ final YangResource yangResource =
+ objectMapper.convertValue(yangResourceAsMap, YangResource.class);
+ yangResourcesModuleNameToContentMap.put(yangResource.getModuleName(),
+ yangResource.getYangSource());
+ });
+ }
+ return yangResourcesModuleNameToContentMap;
+ }
}