Merge "Simplify AbstractOperation methods"
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AbstractOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AbstractOperation.java
index 0f36f09..2847367 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AbstractOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AbstractOperation.java
@@ -21,11 +21,11 @@
package org.openecomp.sdc.be.model.operations.impl;
import java.lang.reflect.Type;
-import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
+import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
@@ -118,7 +118,6 @@
log.debug("Before adding {} to graph. data = {}", defName, someData);
- @SuppressWarnings("unchecked")
Either<TitanVertex, TitanOperationStatus> eitherSomeData = titanGenericDao.createNode(someData);
log.debug("After adding {} to graph. status is = {}", defName, eitherSomeData);
@@ -284,27 +283,15 @@
PropertyTypeValidator validator = type.getValidator();
- boolean isValid = validator.isValid(value, innerType, dataTypes);
- if (true == isValid) {
- return true;
- } else {
- return false;
- }
-
+ return validator.isValid(value, innerType, dataTypes);
}
public boolean isEmptyValue(String value) {
- if (value == null) {
- return true;
- }
- return false;
+ return value == null;
}
public boolean isNullParam(String value) {
- if (value == null) {
- return true;
- }
- return false;
+ return value == null;
}
protected StorageOperationStatus validateAndUpdateComplexValue(IComplexDefaultValue propertyDefinition, String propertyType,
@@ -339,11 +326,7 @@
if (jsonElement == null || jsonElement.isJsonNull()) {
value = EMPTY_VALUE;
} else {
- if (jsonElement.toString().isEmpty()) {
- value = "";
- } else {
- value = jsonElement.toString();
- }
+ value = jsonElement.toString();
}
return value;
@@ -376,18 +359,11 @@
*/
public List<String> convertConstraintsToString(List<PropertyConstraint> constraints) {
- List<String> result = null;
-
- if (constraints != null && false == constraints.isEmpty()) {
- result = new ArrayList<String>();
- for (PropertyConstraint propertyConstraint : constraints) {
- String constraint = gson.toJson(propertyConstraint);
- result.add(constraint);
- }
-
+ if (constraints == null || constraints.isEmpty()) {
+ return null;
}
- return result;
+ return constraints.stream().map(gson::toJson).collect(Collectors.toList());
}
public List<PropertyConstraint> convertConstraints(List<String> constraints) {
@@ -396,18 +372,13 @@
return null;
}
- List<PropertyConstraint> list = new ArrayList<PropertyConstraint>();
Type constraintType = new TypeToken<PropertyConstraint>() {
}.getType();
Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
- for (String constraintJson : constraints) {
- PropertyConstraint propertyConstraint = gson.fromJson(constraintJson, constraintType);
- list.add(propertyConstraint);
- }
+ return constraints.stream().map(c -> gson.fromJson(c, PropertyConstraint.class)).collect(Collectors.toList());
- return list;
}
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
index 2fcdf69..f905721 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
@@ -25,7 +25,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.function.Function;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
@@ -155,8 +154,7 @@
@Override
public Either<GroupTypeDefinition, StorageOperationStatus> getGroupType(String uniqueId, boolean inTransaction) {
- Function<String, Either<GroupTypeDefinition, TitanOperationStatus>> groupTypeGetter = uId -> getGroupTypeByUid(uId);
- return getElementType(groupTypeGetter, uniqueId, inTransaction);
+ return getElementType(this::getGroupTypeByUid, uniqueId, inTransaction);
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
index 796fc8d..adea89b 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
@@ -23,7 +23,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.function.Function;
import javax.annotation.Resource;
@@ -167,8 +166,7 @@
@Override
public Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyType(String uniqueId, boolean inTransaction) {
- Function<String, Either<PolicyTypeDefinition, TitanOperationStatus>> policyTypeGetter = uId -> getPolicyTypeByUid(uId);
- return getElementType(policyTypeGetter, uniqueId, inTransaction);
+ return getElementType(this::getPolicyTypeByUid, uniqueId, inTransaction);
}