summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api
diff options
context:
space:
mode:
authorsiddharth0905 <siddharth.singh4@amdocs.com>2018-07-11 16:34:03 +0530
committersiddharth0905 <siddharth.singh4@amdocs.com>2018-07-12 14:37:11 +0530
commite8a916c229e23ce406cae7d480a201eb505e9261 (patch)
treeab03aeb8fba32137f8aa640ccc4743feaac98e1d /openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api
parent04a245ef31b5deb0c1b415b89e22f64887e3a411 (diff)
Response changed
Error Response changed while collaboration changes Change-Id: I1e634c5da3b2bfb3cf385efe1a015bc3c2cd890f Issue-ID: SDC-1496 Signed-off-by: siddharth0905 <siddharth.singh4@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api')
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java35
1 files changed, 24 insertions, 11 deletions
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<String> 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<String> 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());
}
}