summaryrefslogtreecommitdiffstats
path: root/catalog-model
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2023-01-31 13:25:38 +0000
committerMichael Morris <michael.morris@est.tech>2023-02-01 12:05:20 +0000
commit1653c7e2ad69abf94f8738ed94c233860da22c56 (patch)
treeca4438e850fc87eb0cdfa90ba783cca53953e154 /catalog-model
parent46a9238f48695d25066e2e351c275f0594f2eb9a (diff)
Revert and fix temporary fix of SDC-4352
Revert https://gerrit.onap.org/r/c/sdc/+/133049 and fix initial issue described by SDC-4352 Fix floats not being imported correctly Fix not being able to use equal constraint with bool type Issue-ID: SDC-4352 Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech> Change-Id: I90641838aa40bea211f57f47fe65d09bf0573453
Diffstat (limited to 'catalog-model')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java45
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java15
2 files changed, 45 insertions, 15 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
index d5f7ccbcbb..3d2e701a34 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
@@ -17,15 +17,16 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.openecomp.sdc.be.model.operations.impl;
-import static org.openecomp.sdc.be.model.tosca.constraints.ConstraintUtil.convertToComparable;
import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.JsonArray;
@@ -93,7 +94,6 @@ import org.openecomp.sdc.be.model.operations.api.DerivedFromOperation;
import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
-import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.EqualConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.GreaterOrEqualConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.GreaterThanConstraint;
@@ -125,7 +125,8 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
private static final String DATA_TYPE_CANNOT_BE_FOUND_IN_GRAPH_STATUS_IS = "Data type {} cannot be found in graph. status is {}";
private static final String GOING_TO_EXECUTE_COMMIT_ON_GRAPH = "Going to execute commit on graph.";
private static final String GOING_TO_EXECUTE_ROLLBACK_ON_GRAPH = "Going to execute rollback on graph.";
- private static final String FAILED_TO_ASSOCIATE_RESOURCE_TO_PROPERTY_IN_GRAPH_STATUS_IS = "Failed to associate resource {} to property {} in graph. status is {}";
+ private static final String FAILED_TO_ASSOCIATE_RESOURCE_TO_PROPERTY_IN_GRAPH_STATUS_IS =
+ "Failed to associate resource {} to property {} in graph. status is {}";
private static final String AFTER_ADDING_PROPERTY_TO_GRAPH = "After adding property to graph {}";
private static final String BEFORE_ADDING_PROPERTY_TO_GRAPH = "Before adding property to graph {}";
private static final String THE_VALUE_OF_PROPERTY_FROM_TYPE_IS_INVALID = "The value {} of property from type {} is invalid";
@@ -1268,14 +1269,14 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
return Either.right(operationStatus);
}
propertiesData.put(propertyName, addPropertyToNodeType.left().value());
- }
+ }
DataTypeData dataTypeData = new DataTypeData();
Either<DataTypeDefinition, StorageOperationStatus> existingNode = getDataTypeByUidWithoutDerived(uniqueId, true);
if (existingNode.isLeft()) {
dataTypeData.getDataTypeDataDefinition().setNormative(existingNode.left().value().isNormative());
}
dataTypeData.getDataTypeDataDefinition().setUniqueId(uniqueId);
-
+
long modificationTime = System.currentTimeMillis();
dataTypeData.getDataTypeDataDefinition().setModificationTime(modificationTime);
Either<DataTypeData, JanusGraphOperationStatus> updateNode = janusGraphGenericDao.updateNode(dataTypeData, DataTypeData.class);
@@ -2319,7 +2320,7 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
return je.getAsBoolean();
}
if (je.isNumber()) {
- double number = je.getAsNumber().floatValue();
+ float number = je.getAsNumber().floatValue();
if ((number % 1) == 0) {
return je.getAsNumber().intValue();
}
@@ -2354,22 +2355,22 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
} else {
switch (constraintType) {
case EQUAL:
- propertyConstraint = deserializeConstraintWithStringOperand(value, EqualConstraint.class);
+ propertyConstraint = deserializeConstraint(value, EqualConstraint.class);
break;
case IN_RANGE:
propertyConstraint = deserializeInRangeConstraintConstraint(value);
break;
case GREATER_THAN:
- propertyConstraint = deserializeConstraintWithStringOperand(value, GreaterThanConstraint.class);
+ propertyConstraint = deserializeConstraint(value, GreaterThanConstraint.class);
break;
case LESS_THAN:
- propertyConstraint = deserializeConstraintWithStringOperand(value, LessThanConstraint.class);
+ propertyConstraint = deserializeConstraint(value, LessThanConstraint.class);
break;
case GREATER_OR_EQUAL:
- propertyConstraint = deserializeConstraintWithStringOperand(value, GreaterOrEqualConstraint.class);
+ propertyConstraint = deserializeConstraint(value, GreaterOrEqualConstraint.class);
break;
case LESS_OR_EQUAL:
- propertyConstraint = deserializeConstraintWithStringOperand(value, LessOrEqualConstraint.class);
+ propertyConstraint = deserializeConstraint(value, LessOrEqualConstraint.class);
break;
case VALID_VALUES:
propertyConstraint = deserializeValidValuesConstraint(value);
@@ -2396,11 +2397,25 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
return propertyConstraint;
}
- private PropertyConstraint deserializeConstraintWithStringOperand(JsonNode value, Class<? extends PropertyConstraint> constraintClass) {
- String asString = value.asText();
- log.debug("Before adding value to {} object. value = {}", constraintClass, asString);
+ private PropertyConstraint deserializeConstraint(JsonNode value, Class<? extends PropertyConstraint> constraintClass) {
+ JsonNodeType type = value.getNodeType();
+ if (type.equals(JsonNodeType.NUMBER)) {
+ float asFloat = (float) value.asDouble();
+ if ((asFloat % 1) == 0) {
+ return deserializeConstraintWithObjectOperand(value.asInt(), constraintClass);
+ }
+ return deserializeConstraintWithObjectOperand(asFloat, constraintClass);
+ } else if (type.equals(JsonNodeType.BOOLEAN)) {
+ return deserializeConstraintWithObjectOperand(value.asBoolean(), constraintClass);
+ } else {
+ return deserializeConstraintWithObjectOperand(value.asText(), constraintClass);
+ }
+ }
+
+ private PropertyConstraint deserializeConstraintWithObjectOperand(Object value, Class<? extends PropertyConstraint> constraintClass) {
+ log.debug("Before adding value to {} object. value = {}", constraintClass, value);
try {
- return constraintClass.getConstructor(Object.class).newInstance(asString);
+ return constraintClass.getConstructor(Object.class).newInstance(value);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
| SecurityException exception) {
log.error("Error deserializing constraint", exception);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java
index 7462a7276a..8ba6da514c 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.openecomp.sdc.be.model.tosca.constraints;
import javax.validation.constraints.NotNull;
@@ -51,6 +52,9 @@ public class EqualConstraint extends AbstractComparablePropertyConstraint {
public void initialize(ToscaType propertyType) throws ConstraintValueDoNotMatchPropertyTypeException {
if (propertyType.isValidValue(String.valueOf(equal))) {
typed = propertyType.convert(String.valueOf(equal));
+ if (propertyType.equals(ToscaType.BOOLEAN)) {
+ return;
+ }
initialize(String.valueOf(equal), propertyType);
} else {
throw new ConstraintValueDoNotMatchPropertyTypeException(
@@ -95,6 +99,17 @@ public class EqualConstraint extends AbstractComparablePropertyConstraint {
return String.valueOf(equal);
}
+ @Override
+ public void validate(Object propertyValue) throws ConstraintViolationException {
+ if (propertyValue == null) {
+ throw new ConstraintViolationException("Value to check is null");
+ }
+ if (!(propertyValue instanceof Boolean)) {
+ super.validate(propertyValue);
+ }
+ doValidate(propertyValue);
+ }
+
public boolean validateValueType(String propertyType) throws ConstraintValueDoNotMatchPropertyTypeException {
ToscaType toscaType = ToscaType.getToscaType(propertyType);
if (toscaType == null) {