diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org')
7 files changed, 146 insertions, 167 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 c7623f8181..fa23b51742 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,13 +24,13 @@ import java.util.Collection; public interface BaseDao<T> { - Collection<T> list(T entity); + Collection<T> list(T entity); - void create(T entity); + void create(T entity); - void update(T entity); + void update(T entity); - T get(T entity); + T get(T entity); - void delete(T entity); + void delete(T entity); } 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 1fa4bb23fe..36dfefa840 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,7 +20,6 @@ package org.openecomp.core.dao; - import org.openecomp.core.dao.types.UniqueValueEntity; public interface UniqueValueDao extends BaseDao<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 9f57e4fadd..022ad8e09d 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,7 +24,8 @@ import org.openecomp.core.factory.api.AbstractComponentFactory; import org.openecomp.core.factory.api.AbstractFactory; public abstract class UniqueValueDaoFactory extends AbstractComponentFactory<UniqueValueDao> { - public static UniqueValueDaoFactory getInstance() { - return AbstractFactory.getInstance(UniqueValueDaoFactory.class); - } + + public static UniqueValueDaoFactory getInstance() { + return AbstractFactory.getInstance(UniqueValueDaoFactory.class); + } } 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 c53280ed7a..24038b9b0c 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,42 +23,21 @@ 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; +import lombok.Setter; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter @Table(name = "unique_value") public class UniqueValueEntity { - @PartitionKey - private String type; - - @PartitionKey(value = 1) - private String value; - - /** - * Every entity class must have a default constructor according to - * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/"> - * Definition of mapped classes</a>. - */ - public UniqueValueEntity() { - // Don't delete! Default constructor is required by DataStax driver - } - - public UniqueValueEntity(String type, String value) { - this.type = type; - this.value = value; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getValue() { - return value; - } + @PartitionKey + private String type; - public void setValue(String value) { - this.value = value; - } + @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 56d15a88d4..ff4661c44d 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -25,15 +25,15 @@ import com.datastax.driver.mapping.MappingManager; public interface NoSqlDb { - //TODO: remove cassandra types from here!! (like done in SDC...). + //TODO: remove cassandra types from here!! (like done in SDC...). - void insert(String tableName, String[] colNames, Object[] values); + void insert(String tableName, String[] colNames, Object[] values); - ResultSet execute(String statement); + ResultSet execute(String statement); - ResultSet execute(String statementName, Object... values); + ResultSet execute(String statementName, Object... values); - MappingManager getMappingManager(); + MappingManager getMappingManager(); - String getVersion(); + String getVersion(); } 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 ede264f288..31b6f6a505 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -27,8 +27,8 @@ import org.openecomp.core.nosqldb.api.NoSqlDb; public abstract class NoSqlDbFactory extends AbstractComponentFactory<NoSqlDb> { - public static NoSqlDbFactory getInstance() { + public static NoSqlDbFactory getInstance() { - return AbstractFactory.getInstance(NoSqlDbFactory.class); - } + 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 0ba7228cce..aded1fa99f 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 @@ -28,120 +28,120 @@ import org.openecomp.sdc.common.errors.ErrorCode; 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; - } - - /** - * Create unique value. - * - * @param type the type - * @param uniqueCombination the unique combination - */ - public void createUniqueValue(String type, String... uniqueCombination) { - String originalEntityName = null; - if (ArrayUtils.isNotEmpty(uniqueCombination)) { - originalEntityName = uniqueCombination[uniqueCombination.length - 1]; + 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; } - Optional<String> formattedValue = formatValue(uniqueCombination); - if (formattedValue.isPresent()) { - validateUniqueValue(type, formattedValue.get(), originalEntityName); - uniqueValueDao.create(new UniqueValueEntity(type, formattedValue.get())); + /** + * Create unique value. + * + * @param type the type + * @param uniqueCombination the unique combination + */ + public void createUniqueValue(String type, String... 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); + uniqueValueDao.create(new UniqueValueEntity(type, formattedValue.get())); + } } - } - - /** - * Delete unique value. - * - * @param type the type - * @param uniqueCombination the unique combination - */ - public void deleteUniqueValue(String type, String... uniqueCombination) { - formatValue(uniqueCombination).ifPresent( - formattedValue -> uniqueValueDao.delete(new UniqueValueEntity(type, formattedValue))); - - } - - /** - * Update unique value. - * - * @param type the type - * @param oldValue the old value - * @param newValue the new value - * @param uniqueContext the unique context - */ - public void updateUniqueValue(String type, String oldValue, String newValue, - String... uniqueContext) { - if (newValue == null || oldValue == null || !newValue.equalsIgnoreCase(oldValue)) { - createUniqueValue(type, CommonMethods.concat(uniqueContext, new String[]{newValue})); - deleteUniqueValue(type, CommonMethods.concat(uniqueContext, new String[]{oldValue})); + + /** + * Delete unique value. + * + * @param type the type + * @param uniqueCombination the unique combination + */ + public void deleteUniqueValue(String type, String... uniqueCombination) { + formatValue(uniqueCombination).ifPresent( + formattedValue -> uniqueValueDao.delete(new UniqueValueEntity(type, formattedValue))); + } - } - - /** - * Validate unique value. - * - * @param type the type - * @param uniqueCombination the unique combination - */ - public void validateUniqueValue(String type, String... uniqueCombination) { - String originalEntityName = null; - if (ArrayUtils.isNotEmpty(uniqueCombination)) { - originalEntityName = uniqueCombination[uniqueCombination.length - 1]; + + /** + * Update unique value. + * + * @param type the type + * @param oldValue the old value + * @param newValue the new value + * @param uniqueContext the unique context + */ + 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})); + } } - Optional<String> formattedValue = formatValue(uniqueCombination); - if (formattedValue.isPresent()) { - validateUniqueValue(type, formattedValue.get(), originalEntityName); + /** + * Validate unique value. + * + * @param type the type + * @param uniqueCombination the unique combination + */ + public void validateUniqueValue(String type, String... 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); + } } - } - - /** - * Checks if a unique value is taken. - * - * @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); - } - - 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()); + + 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()); + } } - } - private boolean isUniqueValueOccupied(String type, String formattedValue) { - return uniqueValueDao.get(new UniqueValueEntity(type, formattedValue)) != null; - } + /** + * Checks if a unique value is taken. + * + * @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); + } - private static Optional<String> formatValue(String[] uniqueCombination) { - if (uniqueCombination == null || uniqueCombination.length == 0 - || getValueWithoutContext(uniqueCombination) == null) { - return Optional.empty(); + private boolean isUniqueValueOccupied(String type, String formattedValue) { + return uniqueValueDao.get(new UniqueValueEntity(type, formattedValue)) != null; } - uniqueCombination[uniqueCombination.length - 1] = - getValueWithoutContext(uniqueCombination).toLowerCase(); - return Optional.of(CommonMethods - .arrayToSeparatedString(uniqueCombination, FORMATTED_UNIQUE_VALUE_SEPARATOR)); - } + private static Optional<String> formatValue(String[] uniqueCombination) { + if (uniqueCombination == null || uniqueCombination.length == 0 + || getValueWithoutContext(uniqueCombination) == null) { + return Optional.empty(); + } - private static String getValueWithoutContext(String... uniqueCombination) { - return uniqueCombination[uniqueCombination.length - 1]; - } + 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]; + } } |