aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib')
-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());
}
}