summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api
diff options
context:
space:
mode:
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/dao/BaseDao.java1
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDao.java1
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDaoFactory.java1
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/types/UniqueValueEntity.java3
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java2
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/factory/NoSqlDbFactory.java3
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java56
7 files changed, 19 insertions, 48 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/BaseDao.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/BaseDao.java
index fa23b51742..e46cade267 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/BaseDao.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/BaseDao.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.dao;
import java.util.Collection;
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDao.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDao.java
index 36dfefa840..02db64ec66 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDao.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDao.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.dao;
import org.openecomp.core.dao.types.UniqueValueEntity;
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDaoFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDaoFactory.java
index 022ad8e09d..c653c8dc4f 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDaoFactory.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDaoFactory.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.dao;
import org.openecomp.core.factory.api.AbstractComponentFactory;
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/types/UniqueValueEntity.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/types/UniqueValueEntity.java
index 24038b9b0c..d107c9f388 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/types/UniqueValueEntity.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/types/UniqueValueEntity.java
@@ -17,12 +17,10 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.dao.types;
import com.datastax.driver.mapping.annotations.PartitionKey;
import com.datastax.driver.mapping.annotations.Table;
-
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -37,7 +35,6 @@ public class UniqueValueEntity {
@PartitionKey
private String type;
-
@PartitionKey(value = 1)
private String value;
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java
index ff4661c44d..844ce88265 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.nosqldb.api;
import com.datastax.driver.core.ResultSet;
@@ -26,7 +25,6 @@ import com.datastax.driver.mapping.MappingManager;
public interface NoSqlDb {
//TODO: remove cassandra types from here!! (like done in SDC...).
-
void insert(String tableName, String[] colNames, Object[] values);
ResultSet execute(String statement);
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/factory/NoSqlDbFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/factory/NoSqlDbFactory.java
index 31b6f6a505..e86b64e1aa 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/factory/NoSqlDbFactory.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/factory/NoSqlDbFactory.java
@@ -17,18 +17,15 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.nosqldb.factory;
import org.openecomp.core.factory.api.AbstractComponentFactory;
import org.openecomp.core.factory.api.AbstractFactory;
import org.openecomp.core.nosqldb.api.NoSqlDb;
-
public abstract class NoSqlDbFactory extends AbstractComponentFactory<NoSqlDb> {
public static NoSqlDbFactory getInstance() {
-
return AbstractFactory.getInstance(NoSqlDbFactory.class);
}
}
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 aded1fa99f..a70bc47864 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
@@ -13,11 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
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;
@@ -31,13 +29,24 @@ public class UniqueValueUtil {
private 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 char FORMATTED_UNIQUE_VALUE_SEPARATOR = '_';
-
private final UniqueValueDao uniqueValueDao;
public UniqueValueUtil(UniqueValueDao uniqueValueDao) {
this.uniqueValueDao = uniqueValueDao;
}
+ private static Optional<String> formatValue(String[] uniqueCombination) {
+ if (uniqueCombination == null || uniqueCombination.length == 0 || getValueWithoutContext(uniqueCombination) == null) {
+ return Optional.empty();
+ }
+ uniqueCombination[uniqueCombination.length - 1] = getValueWithoutContext(uniqueCombination).toLowerCase();
+ return Optional.of(CommonMethods.arrayToSeparatedString(uniqueCombination, FORMATTED_UNIQUE_VALUE_SEPARATOR));
+ }
+
+ private static String getValueWithoutContext(String... uniqueCombination) {
+ return uniqueCombination[uniqueCombination.length - 1];
+ }
+
/**
* Create unique value.
*
@@ -49,7 +58,6 @@ public class UniqueValueUtil {
if (ArrayUtils.isNotEmpty(uniqueCombination)) {
originalEntityName = uniqueCombination[uniqueCombination.length - 1];
}
-
Optional<String> formattedValue = formatValue(uniqueCombination);
if (formattedValue.isPresent()) {
validateUniqueValue(type, formattedValue.get(), originalEntityName);
@@ -64,9 +72,7 @@ public class UniqueValueUtil {
* @param uniqueCombination the unique combination
*/
public void deleteUniqueValue(String type, String... uniqueCombination) {
- formatValue(uniqueCombination).ifPresent(
- formattedValue -> uniqueValueDao.delete(new UniqueValueEntity(type, formattedValue)));
-
+ formatValue(uniqueCombination).ifPresent(formattedValue -> uniqueValueDao.delete(new UniqueValueEntity(type, formattedValue)));
}
/**
@@ -77,11 +83,10 @@ public class UniqueValueUtil {
* @param newValue the new value
* @param uniqueContext the unique context
*/
- public void updateUniqueValue(String type, String oldValue, String newValue,
- String... uniqueContext) {
+ public void updateUniqueValue(String type, String oldValue, String newValue, String... uniqueContext) {
if (newValue == null || !newValue.equalsIgnoreCase(oldValue)) {
- createUniqueValue(type, CommonMethods.concat(uniqueContext, new String[] {newValue}));
- deleteUniqueValue(type, CommonMethods.concat(uniqueContext, new String[] {oldValue}));
+ createUniqueValue(type, CommonMethods.concat(uniqueContext, new String[]{newValue}));
+ deleteUniqueValue(type, CommonMethods.concat(uniqueContext, new String[]{oldValue}));
}
}
@@ -96,7 +101,6 @@ public class UniqueValueUtil {
if (ArrayUtils.isNotEmpty(uniqueCombination)) {
originalEntityName = uniqueCombination[uniqueCombination.length - 1];
}
-
Optional<String> formattedValue = formatValue(uniqueCombination);
if (formattedValue.isPresent()) {
validateUniqueValue(type, formattedValue.get(), originalEntityName);
@@ -105,12 +109,8 @@ public class UniqueValueUtil {
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, originalEntityName))
- .build());
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).withId(UNIQUE_VALUE_VIOLATION)
+ .withMessage(String.format(UNIQUE_VALUE_VIOLATION_MSG, type, originalEntityName)).build());
}
}
@@ -120,28 +120,10 @@ public class UniqueValueUtil {
* @return true if the unique value is occupied, false otherwise
*/
public boolean isUniqueValueOccupied(String type, String... uniqueCombination) {
- return formatValue(uniqueCombination)
- .map(formattedValue -> isUniqueValueOccupied(type, formattedValue))
- .orElse(false);
+ return formatValue(uniqueCombination).map(formattedValue -> isUniqueValueOccupied(type, formattedValue)).orElse(false);
}
private boolean isUniqueValueOccupied(String type, String formattedValue) {
return uniqueValueDao.get(new UniqueValueEntity(type, formattedValue)) != null;
}
-
- private static Optional<String> formatValue(String[] uniqueCombination) {
- if (uniqueCombination == null || uniqueCombination.length == 0
- || getValueWithoutContext(uniqueCombination) == null) {
- return Optional.empty();
- }
-
- uniqueCombination[uniqueCombination.length - 1] =
- getValueWithoutContext(uniqueCombination).toLowerCase();
- return Optional.of(CommonMethods
- .arrayToSeparatedString(uniqueCombination, FORMATTED_UNIQUE_VALUE_SEPARATOR));
- }
-
- private static String getValueWithoutContext(String... uniqueCombination) {
- return uniqueCombination[uniqueCombination.length - 1];
- }
}