summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service
diff options
context:
space:
mode:
authorPriyank Maheshwari <priyank.maheshwari@est.tech>2024-08-21 13:18:49 +0000
committerGerrit Code Review <gerrit@onap.org>2024-08-21 13:18:49 +0000
commit9541da2c3ac0c1afc6c86e526cd86088d2d00666 (patch)
treec0a66a90fe328c21157d6ed583299e4befa4acf5 /cps-ncmp-service
parentde1aaf34503726c923a9b9e29598c7e817e492e7 (diff)
parent8d6f9eb63315fc77e85ace9ddca7f2017da7e115 (diff)
Merge "[BUG] Blank alternateId overwrites existing"
Diffstat (limited to 'cps-ncmp-service')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java3
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServicePropertyHandler.java16
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/models/YangModelCmHandle.java8
3 files changed, 16 insertions, 11 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java
index d6ddd108ea..d6bda3beee 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java
@@ -215,7 +215,8 @@ public class CmHandleRegistrationService {
final DmiPluginRegistrationResponse dmiPluginRegistrationResponse) {
final List<String> cmHandleIds = dmiPluginRegistration.getUpgradedCmHandles().getCmHandles();
- final String upgradedModuleSetTag = dmiPluginRegistration.getUpgradedCmHandles().getModuleSetTag();
+ final String upgradedModuleSetTag =
+ StringUtils.trimToEmpty(dmiPluginRegistration.getUpgradedCmHandles().getModuleSetTag());
final Map<YangModelCmHandle, CmHandleState> acceptedCmHandleStatePerCmHandle
= new HashMap<>(cmHandleIds.size());
final List<CmHandleRegistrationResponse> cmHandleUpgradeResponses = new ArrayList<>(cmHandleIds.size());
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServicePropertyHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServicePropertyHandler.java
index c9981dba9a..308ead1270 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServicePropertyHandler.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServicePropertyHandler.java
@@ -44,6 +44,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.ncmp.api.inventory.models.CmHandleRegistrationResponse;
import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle;
@@ -56,7 +57,6 @@ import org.onap.cps.spi.model.DataNodeBuilder;
import org.onap.cps.utils.ContentType;
import org.onap.cps.utils.JsonObjectMapper;
import org.springframework.stereotype.Service;
-import org.springframework.util.StringUtils;
@Slf4j
@Service
@@ -112,8 +112,7 @@ public class CmHandleRegistrationServicePropertyHandler {
private void processUpdates(final DataNode existingCmHandleDataNode,
final NcmpServiceCmHandle updatedNcmpServiceCmHandle) {
- setAndUpdateCmHandleField(
- updatedNcmpServiceCmHandle.getCmHandleId(), "alternate-id", updatedNcmpServiceCmHandle.getAlternateId());
+ updateAlternateId(updatedNcmpServiceCmHandle);
updateDataProducerIdentifier(existingCmHandleDataNode, updatedNcmpServiceCmHandle);
if (!updatedNcmpServiceCmHandle.getPublicProperties().isEmpty()) {
updateProperties(existingCmHandleDataNode, PUBLIC_PROPERTY,
@@ -124,13 +123,20 @@ public class CmHandleRegistrationServicePropertyHandler {
}
}
+ private void updateAlternateId(final NcmpServiceCmHandle ncmpServiceCmHandle) {
+ final String newAlternateId = ncmpServiceCmHandle.getAlternateId();
+ if (StringUtils.isNotBlank(newAlternateId)) {
+ setAndUpdateCmHandleField(ncmpServiceCmHandle.getCmHandleId(), "alternate-id", newAlternateId);
+ }
+ }
+
private void updateDataProducerIdentifier(final DataNode cmHandleDataNode,
final NcmpServiceCmHandle ncmpServiceCmHandle) {
final String newDataProducerIdentifier = ncmpServiceCmHandle.getDataProducerIdentifier();
- if (StringUtils.hasText(newDataProducerIdentifier)) {
+ if (StringUtils.isNotBlank(newDataProducerIdentifier)) {
final YangModelCmHandle yangModelCmHandle = YangDataConverter.toYangModelCmHandle(cmHandleDataNode);
final String existingDataProducerIdentifier = yangModelCmHandle.getDataProducerIdentifier();
- if (StringUtils.hasText(existingDataProducerIdentifier)) {
+ if (StringUtils.isNotBlank(existingDataProducerIdentifier)) {
if (!existingDataProducerIdentifier.equals(newDataProducerIdentifier)) {
log.warn("Unable to update dataProducerIdentifier for cmHandle {}. "
+ "Value for dataProducerIdentifier has been set previously.",
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/models/YangModelCmHandle.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/models/YangModelCmHandle.java
index b10155c4a9..76ee286635 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/models/YangModelCmHandle.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/models/YangModelCmHandle.java
@@ -18,7 +18,6 @@
* ============LICENSE_END=========================================================
*/
-
package org.onap.cps.ncmp.impl.inventory.models;
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -126,10 +125,9 @@ public class YangModelCmHandle {
yangModelCmHandle.setDmiServiceName(dmiServiceName);
yangModelCmHandle.setDmiDataServiceName(dmiDataServiceName);
yangModelCmHandle.setDmiModelServiceName(dmiModelServiceName);
- yangModelCmHandle.setModuleSetTag(moduleSetTag == null ? StringUtils.EMPTY : moduleSetTag);
- yangModelCmHandle.setAlternateId(alternateId == null ? StringUtils.EMPTY : alternateId);
- yangModelCmHandle.setDataProducerIdentifier(
- dataProducerIdentifier == null ? StringUtils.EMPTY : dataProducerIdentifier);
+ yangModelCmHandle.setModuleSetTag(StringUtils.trimToEmpty(moduleSetTag));
+ yangModelCmHandle.setAlternateId(StringUtils.trimToEmpty(alternateId));
+ yangModelCmHandle.setDataProducerIdentifier(StringUtils.trimToEmpty(dataProducerIdentifier));
yangModelCmHandle.setDmiProperties(asYangModelCmHandleProperties(ncmpServiceCmHandle.getDmiProperties()));
yangModelCmHandle.setPublicProperties(asYangModelCmHandleProperties(
ncmpServiceCmHandle.getPublicProperties()));