diff options
author | DylanB95EST <dylan.byrne@est.tech> | 2021-12-14 16:34:38 +0000 |
---|---|---|
committer | DylanB95EST <dylan.byrne@est.tech> | 2022-01-28 14:32:11 +0000 |
commit | 63132cec2c18363a8224646039cc23b6144d8e6c (patch) | |
tree | 0821e401a14655ecba60d213f5dbacac12e8f0b4 /cps-ncmp-service/src/main/java | |
parent | a5ce86d02493f141848f9d609c65883d2198894a (diff) |
Support 'public' Cm Handle Properties
Add support for new Public Additional Properties list to Register CM Handles API
Issue-ID: CPS-677
Change-Id: I6efc88734da2416f72f71a403622e519398b502d
Signed-off-by: DylanB95EST <dylan.byrne@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main/java')
6 files changed, 74 insertions, 79 deletions
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 3bfb424a2e..bce3ac3847 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 @@ -68,11 +68,11 @@ public class DmiDataOperations extends DmiOperations { final String acceptParamInHeader, final DataStoreEnum dataStore) { final PersistenceCmHandle persistenceCmHandle = - cmHandlePropertiesRetriever.retrieveCmHandleDmiServiceNameAndProperties(cmHandle); + cmHandlePropertiesRetriever.retrieveCmHandleDmiServiceNameAndDmiProperties(cmHandle); final DmiRequestBody dmiRequestBody = DmiRequestBody.builder() .operation(READ) .build(); - dmiRequestBody.asCmHandleProperties(persistenceCmHandle.getAdditionalProperties()); + dmiRequestBody.asDmiProperties(persistenceCmHandle.getDmiProperties()); final String jsonBody = jsonObjectMapper.asJsonString(dmiRequestBody); final var dmiResourceDataUrl = getDmiDatastoreUrlWithOptions( @@ -99,13 +99,13 @@ public class DmiDataOperations extends DmiOperations { final String requestData, final String dataType) { final PersistenceCmHandle persistenceCmHandle = - cmHandlePropertiesRetriever.retrieveCmHandleDmiServiceNameAndProperties(cmHandle); + cmHandlePropertiesRetriever.retrieveCmHandleDmiServiceNameAndDmiProperties(cmHandle); final DmiRequestBody dmiRequestBody = DmiRequestBody.builder() .operation(operation) .data(requestData) .dataType(dataType) .build(); - dmiRequestBody.asCmHandleProperties(persistenceCmHandle.getAdditionalProperties()); + dmiRequestBody.asDmiProperties(persistenceCmHandle.getDmiProperties()); final String jsonBody = jsonObjectMapper.asJsonString(dmiRequestBody); final String dmiUrl = getResourceInDataStoreUrl(persistenceCmHandle.resolveDmiServiceName(DATA), 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 1ce6dcfcd5..657b0b4740 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 @@ -49,11 +49,11 @@ public class DmiModelOperations extends DmiOperations { * * @param dmiRestClient {@code DmiRestClient} */ - public DmiModelOperations(final PersistenceCmHandleRetriever cmHandlePropertiesRetriever, + public DmiModelOperations(final PersistenceCmHandleRetriever dmiPropertiesRetriever, final JsonObjectMapper jsonObjectMapper, final NcmpConfiguration.DmiProperties dmiProperties, final DmiRestClient dmiRestClient) { - super(cmHandlePropertiesRetriever, jsonObjectMapper, dmiProperties, dmiRestClient); + super(dmiPropertiesRetriever, jsonObjectMapper, dmiProperties, dmiRestClient); } /** @@ -65,7 +65,7 @@ public class DmiModelOperations extends DmiOperations { public List<ModuleReference> getModuleReferences(final PersistenceCmHandle persistenceCmHandle) { final DmiRequestBody dmiRequestBody = DmiRequestBody.builder() .build(); - dmiRequestBody.asCmHandleProperties(persistenceCmHandle.getAdditionalProperties()); + dmiRequestBody.asDmiProperties(persistenceCmHandle.getDmiProperties()); final ResponseEntity<Object> dmiFetchModulesResponseEntity = getResourceFromDmiWithJsonData( persistenceCmHandle.resolveDmiServiceName(MODEL), jsonObjectMapper.asJsonString(dmiRequestBody), persistenceCmHandle.getId(), "modules"); @@ -81,11 +81,11 @@ public class DmiModelOperations extends DmiOperations { */ public Map<String, String> getNewYangResourcesFromDmi(final PersistenceCmHandle persistenceCmHandle, final List<ModuleReference> unknownModuleReferences) { - final String jsonDataWithDataAndCmHandleProperties = getRequestBodyToFetchYangResources( - unknownModuleReferences, persistenceCmHandle.getAdditionalProperties()); + final String jsonWithDataAndDmiProperties = getRequestBodyToFetchYangResources( + unknownModuleReferences, persistenceCmHandle.getDmiProperties()); final ResponseEntity<Object> responseEntity = getResourceFromDmiWithJsonData( persistenceCmHandle.resolveDmiServiceName(MODEL), - jsonDataWithDataAndCmHandleProperties, + jsonWithDataAndDmiProperties, persistenceCmHandle.getId(), "moduleResources"); return asModuleNameToYangResourceMap(responseEntity); @@ -109,13 +109,13 @@ public class DmiModelOperations extends DmiOperations { } private static String getRequestBodyToFetchYangResources(final List<ModuleReference> unknownModuleReferences, - final List<PersistenceCmHandle.AdditionalProperty> cmHandleProperties) { + final List<PersistenceCmHandle.Property> dmiProperties) { final JsonArray moduleReferencesAsJson = getModuleReferencesAsJson(unknownModuleReferences); final JsonObject data = new JsonObject(); data.add("modules", moduleReferencesAsJson); final JsonObject jsonRequestObject = new JsonObject(); jsonRequestObject.add("data", data); - jsonRequestObject.add("cmHandleProperties", toJsonObject(cmHandleProperties)); + jsonRequestObject.add("cmHandleProperties", toJsonObject(dmiProperties)); return jsonRequestObject.toString(); } @@ -131,9 +131,10 @@ public class DmiModelOperations extends DmiOperations { return moduleReferences; } - private static JsonObject toJsonObject(final List<PersistenceCmHandle.AdditionalProperty> cmHandleProperties) { + private static JsonObject toJsonObject(final List<PersistenceCmHandle.Property> + dmiProperties) { final JsonObject asJsonObject = new JsonObject(); - for (final PersistenceCmHandle.AdditionalProperty additionalProperty : cmHandleProperties) { + for (final PersistenceCmHandle.Property additionalProperty : dmiProperties) { asJsonObject.addProperty(additionalProperty.getName(), additionalProperty.getValue()); } return asJsonObject; diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiRequestBody.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiRequestBody.java index 26feeeaf40..1066eacf71 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiRequestBody.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiRequestBody.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. @@ -21,8 +21,8 @@ package org.onap.cps.ncmp.api.impl.operations; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -40,7 +40,7 @@ public class DmiRequestBody { UPDATE("update"), PATCH("patch"), DELETE("delete"); - private String value; + private final String value; OperationEnum(final String value) { this.value = value; @@ -56,25 +56,19 @@ public class DmiRequestBody { private OperationEnum operation; private String dataType; private String data; - private Map<String, String> cmHandleProperties; + @JsonProperty("cmHandleProperties") + private Map<String, String> dmiProperties; /** - * Set CmHandleProperties by converting a list of PersistenceCmHandle.AdditionalProperty objects. + * Set DMI Properties by converting a list of PersistenceCmHandle.Property objects. * - * @param cmHandlePropertiesAsList the cm handle additional properties + * @param dmiPropertiesAsList list of cm handle dmi properties */ - public void asCmHandleProperties( - final List<PersistenceCmHandle.AdditionalProperty> cmHandlePropertiesAsList) { - final boolean isCmHandlePropertiesNullOrEmpty = - cmHandlePropertiesAsList == null || cmHandlePropertiesAsList.isEmpty(); - if (isCmHandlePropertiesNullOrEmpty) { - cmHandleProperties = Collections.emptyMap(); - } else { - cmHandleProperties = new LinkedHashMap<>(); - for (final PersistenceCmHandle.AdditionalProperty additionalProperty : cmHandlePropertiesAsList) { - cmHandleProperties.put(additionalProperty.getName(), - additionalProperty.getValue()); - } + public void asDmiProperties( + final List<PersistenceCmHandle.Property> dmiPropertiesAsList) { + dmiProperties = new LinkedHashMap<>(); + for (final PersistenceCmHandle.Property dmiProperty : dmiPropertiesAsList) { + dmiProperties.put(dmiProperty.getName(), dmiProperty.getValue()); } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/PersistenceCmHandleRetriever.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/PersistenceCmHandleRetriever.java index 78b5c318d8..c489eef8e9 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/PersistenceCmHandleRetriever.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/PersistenceCmHandleRetriever.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,9 +20,9 @@ package org.onap.cps.ncmp.api.impl.operations; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; +import lombok.AllArgsConstructor; import org.onap.cps.api.CpsDataService; import org.onap.cps.ncmp.api.models.CmHandle; import org.onap.cps.ncmp.api.models.PersistenceCmHandle; @@ -34,30 +34,24 @@ import org.springframework.stereotype.Component; * Retrieves PersistenceCmHandles & properties. */ @Component +@AllArgsConstructor public class PersistenceCmHandleRetriever { private static final String NCMP_DATASPACE_NAME = "NCMP-Admin"; private static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry"; - private CpsDataService cpsDataService; + private final CpsDataService cpsDataService; /** - * Constructor for PersistenceCmHandleRetriever. - * - * @param cpsDataService the cps data service. - */ - public PersistenceCmHandleRetriever(final CpsDataService cpsDataService) { - this.cpsDataService = cpsDataService; - } - - /** - * This method retieves dmi service name and properties for a given cm handle. + * This method retrieves DMI service name and DMI properties for a given cm handle. * @param cmHandleId the id of the cm handle * @return persistence cm handle */ - public PersistenceCmHandle retrieveCmHandleDmiServiceNameAndProperties(final String cmHandleId) { + public PersistenceCmHandle retrieveCmHandleDmiServiceNameAndDmiProperties(final String cmHandleId) { final DataNode cmHandleDataNode = getCmHandleDataNode(cmHandleId); - final CmHandle cmHandle = new CmHandle(cmHandleId, getCmHandleProperties(cmHandleDataNode)); + final CmHandle cmHandle = new CmHandle(); + cmHandle.setCmHandleID(cmHandleId); + populateCmHandleDmiProperties(cmHandleDataNode, cmHandle); return PersistenceCmHandle.toPersistenceCmHandle( String.valueOf(cmHandleDataNode.getLeaves().get("dmi-service-name")), String.valueOf(cmHandleDataNode.getLeaves().get("dmi-data-service-name")), @@ -74,16 +68,19 @@ public class PersistenceCmHandleRetriever { FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); } - private static Map<String, String> getCmHandleProperties(final DataNode cmHandleDataNode) { - if (cmHandleDataNode.getChildDataNodes().isEmpty()) { - return Collections.emptyMap(); - } - final Map<String, String> cmHandlePropertiesAsMap = new LinkedHashMap<>(); + private static void populateCmHandleDmiProperties(final DataNode cmHandleDataNode, final CmHandle cmHandle) { + final Map<String, String> dmiProperties = new LinkedHashMap<>(); for (final DataNode childDataNode: cmHandleDataNode.getChildDataNodes()) { - cmHandlePropertiesAsMap.put(String.valueOf(childDataNode.getLeaves().get("name")), - String.valueOf(childDataNode.getLeaves().get("value"))); + if (childDataNode.getXpath().contains("/additional-properties[@name=")) { + addProperty(childDataNode, dmiProperties); + } } - return cmHandlePropertiesAsMap; + cmHandle.setDmiProperties(dmiProperties); + } + + private static void addProperty(final DataNode propertyDataNode, final Map<String, String> propertiesAsMap) { + propertiesAsMap.put(String.valueOf(propertyDataNode.getLeaves().get("name")), + String.valueOf(propertyDataNode.getLeaves().get("value"))); } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandle.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandle.java index a38442b099..9a9b6faaf9 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandle.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandle.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. @@ -21,8 +21,10 @@ package org.onap.cps.ncmp.api.models; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; +import java.util.Collections; import java.util.Map; -import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -34,13 +36,18 @@ import org.springframework.validation.annotation.Validated; @Validated @Getter @Setter -@AllArgsConstructor @NoArgsConstructor public class CmHandle { @JsonProperty("cmHandle") private String cmHandleID; - private Map<String, String> cmHandleProperties; + @JsonSetter(nulls = Nulls.AS_EMPTY) + @JsonProperty("cmHandleProperties") + private Map<String, String> dmiProperties = Collections.emptyMap(); + + @JsonSetter(nulls = Nulls.AS_EMPTY) + @JsonProperty("publicCmHandleProperties") + private Map<String, String> publicProperties = Collections.emptyMap(); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/PersistenceCmHandle.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/PersistenceCmHandle.java index 8b959e3277..cc32bb75c0 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/PersistenceCmHandle.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/PersistenceCmHandle.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. @@ -24,7 +24,6 @@ package org.onap.cps.ncmp.api.models; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Strings; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; import lombok.AllArgsConstructor; @@ -54,7 +53,10 @@ public class PersistenceCmHandle { private String dmiModelServiceName; @JsonProperty("additional-properties") - private List<AdditionalProperty> additionalProperties; + private List<Property> dmiProperties; + + @JsonProperty("public-properties") + private List<Property> publicProperties; /** * Create a persistenceCmHandle. @@ -73,26 +75,12 @@ public class PersistenceCmHandle { persistenceCmHandle.setDmiServiceName(dmiServiceName); persistenceCmHandle.setDmiDataServiceName(dmiDataServiceName); persistenceCmHandle.setDmiModelServiceName(dmiModelServiceName); - if (cmHandle.getCmHandleProperties() == null) { - persistenceCmHandle.asAdditionalProperties(Collections.emptyMap()); - } else { - persistenceCmHandle.asAdditionalProperties(cmHandle.getCmHandleProperties()); - } + persistenceCmHandle.setDmiProperties(asPersistenceCmHandleProperties(cmHandle.getDmiProperties())); + persistenceCmHandle.setPublicProperties(asPersistenceCmHandleProperties(cmHandle.getPublicProperties())); return persistenceCmHandle; } /** - * Set Additional Properties map, key and value pair. - * @param additionalPropertiesAsMap Map of Additional Properties - */ - public void asAdditionalProperties(final Map<String, String> additionalPropertiesAsMap) { - additionalProperties = new ArrayList<>(additionalPropertiesAsMap.size()); - for (final Map.Entry<String, String> entry : additionalPropertiesAsMap.entrySet()) { - additionalProperties.add(new AdditionalProperty(entry.getKey(), entry.getValue())); - } - } - - /** * Resolve a dmi service name. * @param requiredService indicates what typo of service is required * @return dmi service name @@ -107,13 +95,21 @@ public class PersistenceCmHandle { return dmiServiceName; } + private static List<Property> asPersistenceCmHandleProperties(final Map<String, String> propertiesAsMap) { + final List<Property> persistenceCmHandleProperties = new ArrayList<>(propertiesAsMap.size()); + for (final Map.Entry<String, String> entry : propertiesAsMap.entrySet()) { + persistenceCmHandleProperties.add(new PersistenceCmHandle.Property(entry.getKey(), entry.getValue())); + } + return persistenceCmHandleProperties; + } + private static boolean isNullEmptyOrBlank(final String serviceName) { return Strings.isNullOrEmpty(serviceName) || serviceName.isBlank(); } @AllArgsConstructor @Data - public static class AdditionalProperty { + public static class Property { @JsonProperty() private final String name; |