X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-ncmp-service%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fcps%2Fncmp%2Fapi%2Fimpl%2FNetworkCmProxyDataServicePropertyHandler.java;h=f861910024a90b12815e004ed65ded8103dc0113;hb=a927b20ce1a6d5792ed41e0a98eb475606e8f35a;hp=3d152916339106e120913cf06c4533b5ddb9950e;hpb=215b40aecaefdd8b523ea6ef72b14011adba3490;p=cps.git diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java index 3d1529163..f86191002 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java @@ -47,6 +47,8 @@ import lombok.extern.slf4j.Slf4j; import org.onap.cps.api.CpsDataService; import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence; import org.onap.cps.ncmp.api.impl.utils.AlternateIdChecker; +import org.onap.cps.ncmp.api.impl.utils.YangDataConverter; +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse; import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; import org.onap.cps.spi.exceptions.DataNodeNotFoundException; @@ -55,6 +57,7 @@ import org.onap.cps.spi.model.DataNode; import org.onap.cps.spi.model.DataNodeBuilder; import org.onap.cps.utils.JsonObjectMapper; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; @Slf4j @Service @@ -110,7 +113,9 @@ public class NetworkCmProxyDataServicePropertyHandler { private void processUpdates(final DataNode existingCmHandleDataNode, final NcmpServiceCmHandle updatedNcmpServiceCmHandle) { - updateAlternateId(updatedNcmpServiceCmHandle); + setAndUpdateCmHandleField( + updatedNcmpServiceCmHandle.getCmHandleId(), "alternate-id", updatedNcmpServiceCmHandle.getAlternateId()); + updateDataProducerIdentifier(existingCmHandleDataNode, updatedNcmpServiceCmHandle); if (!updatedNcmpServiceCmHandle.getPublicProperties().isEmpty()) { updateProperties(existingCmHandleDataNode, PUBLIC_PROPERTY, updatedNcmpServiceCmHandle.getPublicProperties()); @@ -120,17 +125,24 @@ public class NetworkCmProxyDataServicePropertyHandler { } } - private void updateAlternateId(final NcmpServiceCmHandle updatedNcmpServiceCmHandle) { - final String updatedAlternateId = updatedNcmpServiceCmHandle.getAlternateId(); - final String cmHandleId = updatedNcmpServiceCmHandle.getCmHandleId(); - final Map cmHandleProperties = new HashMap<>(2); - cmHandleProperties.put("id", cmHandleId); - cmHandleProperties.put("alternate-id", updatedAlternateId); - final Map> dmiRegistryProperties = new HashMap<>(1); - dmiRegistryProperties.put("cm-handles", cmHandleProperties); - cpsDataService.updateNodeLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT, - jsonObjectMapper.asJsonString(dmiRegistryProperties), OffsetDateTime.now()); - log.debug("Updating alternateId for cmHandle {} with value : {})", cmHandleId, updatedAlternateId); + private void updateDataProducerIdentifier(final DataNode cmHandleDataNode, + final NcmpServiceCmHandle ncmpServiceCmHandle) { + final String newDataProducerIdentifier = ncmpServiceCmHandle.getDataProducerIdentifier(); + if (StringUtils.hasText(newDataProducerIdentifier)) { + final YangModelCmHandle yangModelCmHandle = + YangDataConverter.convertCmHandleToYangModel(cmHandleDataNode); + final String existingDataProducerIdentifier = yangModelCmHandle.getDataProducerIdentifier(); + if (StringUtils.hasText(existingDataProducerIdentifier)) { + if (!existingDataProducerIdentifier.equals(newDataProducerIdentifier)) { + log.warn("Unable to update dataProducerIdentifier for cmHandle {}. " + + "Value for dataProducerIdentifier has been set previously.", + ncmpServiceCmHandle.getCmHandleId()); + } + } else { + setAndUpdateCmHandleField( + yangModelCmHandle.getId(), "data-producer-identifier", newDataProducerIdentifier); + } + } } private void updateProperties(final DataNode existingCmHandleDataNode, final PropertyType propertyType, @@ -202,6 +214,18 @@ public class NetworkCmProxyDataServicePropertyHandler { return new DataNodeBuilder().withXpath(xpath).withLeaves(ImmutableMap.copyOf(updatedLeaves)).build(); } + private void setAndUpdateCmHandleField(final String cmHandleIdToUpdate, final String fieldName, + final String newFieldValue) { + final Map> dmiRegistryData = new HashMap<>(1); + final Map cmHandleData = new HashMap<>(2); + cmHandleData.put("id", cmHandleIdToUpdate); + cmHandleData.put(fieldName, newFieldValue); + dmiRegistryData.put("cm-handles", cmHandleData); + cpsDataService.updateNodeLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT, + jsonObjectMapper.asJsonString(dmiRegistryData), OffsetDateTime.now()); + log.debug("Updating {} for cmHandle {} with value : {})", fieldName, cmHandleIdToUpdate, newFieldValue); + } + enum PropertyType { DMI_PROPERTY("additional-properties"), PUBLIC_PROPERTY("public-properties");