From 280f8015d06af1f41a3ef12e8300801c7a5e0d54 Mon Sep 17 00:00:00 2001 From: AviZi Date: Fri, 9 Jun 2017 02:39:56 +0300 Subject: [SDC-29] Amdocs OnBoard 1707 initial commit. Change-Id: Ie4d12a3f574008b792899b368a0902a8b46b5370 Signed-off-by: AviZi --- .../org/openecomp/core/util/UniqueValueUtil.java | 41 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 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 a82c97c51c..d2dee5e512 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 @@ -27,21 +27,18 @@ import org.openecomp.core.utilities.CommonMethods; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; +import org.openecomp.sdc.common.utils.CommonUtil; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; import java.util.Optional; -/** - * The type Unique value util. - */ public class UniqueValueUtil { - /** - * The constant UNIQUE_VALUE_VIOLATION. - */ public static final String UNIQUE_VALUE_VIOLATION = "UNIQUE_VALUE_VIOLATION"; private static final String UNIQUE_VALUE_VIOLATION_MSG = "%s with the value '%s' already exists."; private static final UniqueValueDao uniqueValueDao = UniqueValueDaoFactory.getInstance().createInterface(); + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); /** * Create unique value. @@ -50,12 +47,18 @@ public class UniqueValueUtil { * @param uniqueCombination the unique combination */ public static void createUniqueValue(String type, String... uniqueCombination) { + + + mdcDataDebugMessage.debugEntryMessage(null, null); + Optional value = formatValue(uniqueCombination); if (!value.isPresent()) { return; } validateUniqueValue(type, value.get(), uniqueCombination); uniqueValueDao.create(new UniqueValueEntity(type, value.get())); + + mdcDataDebugMessage.debugExitMessage(null, null); } /** @@ -65,11 +68,17 @@ public class UniqueValueUtil { * @param uniqueCombination the unique combination */ public static void deleteUniqueValue(String type, String... uniqueCombination) { + + + mdcDataDebugMessage.debugEntryMessage(null, null); + Optional value = formatValue(uniqueCombination); if (!value.isPresent()) { return; } uniqueValueDao.delete(new UniqueValueEntity(type, value.get())); + + mdcDataDebugMessage.debugExitMessage(null, null); } /** @@ -82,12 +91,18 @@ public class UniqueValueUtil { */ public static void updateUniqueValue(String type, String oldValue, String newValue, String... uniqueContext) { + + + mdcDataDebugMessage.debugEntryMessage(null, null); + if ((newValue != null && oldValue != null && !newValue.toLowerCase().equals(oldValue.toLowerCase())) || newValue == null || oldValue == null) { createUniqueValue(type, CommonMethods.concat(uniqueContext, new String[]{newValue})); deleteUniqueValue(type, CommonMethods.concat(uniqueContext, new String[]{oldValue})); } + + mdcDataDebugMessage.debugExitMessage(null, null); } /** @@ -97,14 +112,20 @@ public class UniqueValueUtil { * @param uniqueCombination the unique combination */ public static void validateUniqueValue(String type, String... uniqueCombination) { + mdcDataDebugMessage.debugEntryMessage(null, null); + Optional value = formatValue(uniqueCombination); if (!value.isPresent()) { return; } validateUniqueValue(type, value.get(), uniqueCombination); + + mdcDataDebugMessage.debugExitMessage(null, null); } private static void validateUniqueValue(String type, String value, String... uniqueCombination) { + mdcDataDebugMessage.debugEntryMessage(null, null); + if (uniqueValueDao.get(new UniqueValueEntity(type, value)) != null) { throw new CoreException(new ErrorCode.ErrorCodeBuilder() .withCategory(ErrorCategory.APPLICATION) @@ -112,9 +133,15 @@ public class UniqueValueUtil { .withMessage(String.format(UNIQUE_VALUE_VIOLATION_MSG, type, uniqueCombination[uniqueCombination.length - 1])).build()); } + + mdcDataDebugMessage.debugExitMessage(null, null); } private static Optional formatValue(String[] uniqueCombination) { + + + mdcDataDebugMessage.debugEntryMessage(null, null); + if (uniqueCombination == null || uniqueCombination.length == 0 || uniqueCombination[uniqueCombination.length - 1] == null) { return Optional.empty(); @@ -122,6 +149,8 @@ public class UniqueValueUtil { uniqueCombination[uniqueCombination.length - 1] = uniqueCombination[uniqueCombination.length - 1].toLowerCase(); + + mdcDataDebugMessage.debugExitMessage(null, null); return Optional.of(CommonMethods.arrayToSeparatedString(uniqueCombination, '_')); } } -- cgit 1.2.3-korg