From e8a916c229e23ce406cae7d480a201eb505e9261 Mon Sep 17 00:00:00 2001 From: siddharth0905 Date: Wed, 11 Jul 2018 16:34:03 +0530 Subject: Response changed Error Response changed while collaboration changes Change-Id: I1e634c5da3b2bfb3cf385efe1a015bc3c2cd890f Issue-ID: SDC-1496 Signed-off-by: siddharth0905 --- .../org/openecomp/core/util/UniqueValueUtil.java | 35 +++++++++++++++------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java') diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java index 86c3d64d59..0ba7228cce 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java @@ -16,6 +16,9 @@ package org.openecomp.core.util; +import java.util.Optional; + +import org.apache.commons.lang3.ArrayUtils; import org.openecomp.core.dao.UniqueValueDao; import org.openecomp.core.dao.types.UniqueValueEntity; import org.openecomp.core.utilities.CommonMethods; @@ -23,8 +26,6 @@ import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; -import java.util.Optional; - public class UniqueValueUtil { private static final String UNIQUE_VALUE_VIOLATION = "UNIQUE_VALUE_VIOLATION"; @@ -44,10 +45,16 @@ public class UniqueValueUtil { * @param uniqueCombination the unique combination */ public void createUniqueValue(String type, String... uniqueCombination) { - formatValue(uniqueCombination).ifPresent(formattedValue -> { - validateUniqueValue(type, formattedValue, uniqueCombination); - uniqueValueDao.create(new UniqueValueEntity(type, formattedValue)); - }); + String originalEntityName = null; + if (ArrayUtils.isNotEmpty(uniqueCombination)) { + originalEntityName = uniqueCombination[uniqueCombination.length - 1]; + } + + Optional formattedValue = formatValue(uniqueCombination); + if (formattedValue.isPresent()) { + validateUniqueValue(type, formattedValue.get(), originalEntityName); + uniqueValueDao.create(new UniqueValueEntity(type, formattedValue.get())); + } } /** @@ -85,8 +92,15 @@ public class UniqueValueUtil { * @param uniqueCombination the unique combination */ public void validateUniqueValue(String type, String... uniqueCombination) { - formatValue(uniqueCombination) - .ifPresent(formattedValue -> validateUniqueValue(type, formattedValue, uniqueCombination)); + String originalEntityName = null; + if (ArrayUtils.isNotEmpty(uniqueCombination)) { + originalEntityName = uniqueCombination[uniqueCombination.length - 1]; + } + + Optional formattedValue = formatValue(uniqueCombination); + if (formattedValue.isPresent()) { + validateUniqueValue(type, formattedValue.get(), originalEntityName); + } } /** @@ -100,14 +114,13 @@ public class UniqueValueUtil { .orElse(false); } - private void validateUniqueValue(String type, String formattedValue, - String... uniqueCombination) { + private void validateUniqueValue(String type, String formattedValue, String originalEntityName) { if (isUniqueValueOccupied(type, formattedValue)) { throw new CoreException(new ErrorCode.ErrorCodeBuilder() .withCategory(ErrorCategory.APPLICATION) .withId(UNIQUE_VALUE_VIOLATION) .withMessage(String - .format(UNIQUE_VALUE_VIOLATION_MSG, type, getValueWithoutContext(uniqueCombination))) + .format(UNIQUE_VALUE_VIOLATION_MSG, type, originalEntityName)) .build()); } } -- cgit 1.2.3-korg