summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2023-02-01 17:56:35 +0000
committerMichael Morris <michael.morris@est.tech>2023-02-02 12:05:26 +0000
commite61d26cb2a74813b526e10864af4d73f04df2650 (patch)
tree972a74ffc58c0b24da5af586bbbcec1f66150d97 /catalog-be/src/main/java
parent5da0b3c1454ac557e0b01eb678abaf882fb08243 (diff)
Fix 'in_range constraints missing from TOSCA template'-bug
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: Icec2183849a8852621ec98f3ca1d94ac7c4dae31 Issue-ID: SDC-4357
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java51
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java9
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java3
3 files changed, 21 insertions, 42 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java
index b6f031bd41..c58c43db52 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java
@@ -50,7 +50,6 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datamodel.utils.PropertyValueConstraintValidationUtil;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.resources.data.EntryData;
import org.openecomp.sdc.common.api.Constants;
@@ -262,21 +261,19 @@ public class ComponentPropertyServlet extends BeGenericServlet {
try {
Either<Map<String, PropertyDefinition>, ActionStatus> propertyDefinition = getPropertyModel(componentId, data);
if (propertyDefinition.isRight()) {
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(propertyDefinition.right().value());
- return buildErrorResponse(responseFormat);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(propertyDefinition.right().value()));
}
Map<String, PropertyDefinition> properties = propertyDefinition.left().value();
if (properties == null || properties.size() != 1) {
log.info("Property content is invalid - {}", data);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
- return buildErrorResponse(responseFormat);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
}
Map.Entry<String, PropertyDefinition> entry = properties.entrySet().iterator().next();
PropertyDefinition newPropertyDefinition = entry.getValue();
newPropertyDefinition.setParentUniqueId(componentId);
newPropertyDefinition.setUserCreated(true);
- Either<EntryData<String, PropertyDefinition>, ResponseFormat> addPropertyEither = propertyBusinessLogic
- .addPropertyToComponent(componentId, newPropertyDefinition, userId);
+ Either<EntryData<String, PropertyDefinition>, ResponseFormat> addPropertyEither =
+ propertyBusinessLogic.addPropertyToComponent(componentId, newPropertyDefinition, userId);
if (addPropertyEither.isRight()) {
return buildErrorResponse(addPropertyEither.right().value());
}
@@ -285,8 +282,7 @@ public class ComponentPropertyServlet extends BeGenericServlet {
} catch (Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE_PROPERTY);
log.debug("create property failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}
@@ -294,23 +290,18 @@ public class ComponentPropertyServlet extends BeGenericServlet {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug("Start handle request of {}", url);
loggerSupportability.log(LoggerSupportabilityActions.UPDATE_PROPERTIES, StatusCode.STARTED, "UPDATE_PROPERTIES by user {} ", userId);
- // get modifier id
- User modifier = new User();
- modifier.setUserId(userId);
log.debug("modifier id is {}", userId);
-//
+
try {
// convert json to PropertyDefinition
Either<Map<String, PropertyDefinition>, ActionStatus> propertiesListEither = getPropertiesListForUpdate(data);
if (propertiesListEither.isRight()) {
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(propertiesListEither.right().value());
- return buildErrorResponse(responseFormat);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(propertiesListEither.right().value()));
}
Map<String, PropertyDefinition> properties = propertiesListEither.left().value();
if (properties == null) {
log.info("Property content is invalid - {}", data);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
- return buildErrorResponse(responseFormat);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
}
//Validate value and Constraint of property and Fetch all data types from cache
Either<Boolean, ResponseFormat> constraintValidatorResponse = new PropertyValueConstraintValidationUtil()
@@ -328,18 +319,14 @@ public class ComponentPropertyServlet extends BeGenericServlet {
log.info("Failed to update Property. Reason - {}", status.right().value());
return buildErrorResponse(status.right().value());
}
- EntryData<String, PropertyDefinition> property = status.left().value();
- PropertyDefinition updatedPropertyDefinition = property.getValue();
- log.debug("Property id {} updated successfully ", updatedPropertyDefinition.getUniqueId());
+ log.debug("Property id {} updated successfully ", status.left().value().getValue().getUniqueId());
}
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
loggerSupportability.log(LoggerSupportabilityActions.UPDATE_PROPERTIES, StatusCode.COMPLETE, "UPDATE_PROPERTIES by user {} ", userId);
- return buildOkResponse(responseFormat, properties);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
} catch (Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Property");
log.debug("update property failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}
@@ -356,8 +343,7 @@ public class ComponentPropertyServlet extends BeGenericServlet {
} catch (Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE_PROPERTY);
log.debug("get property failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}
@@ -373,8 +359,7 @@ public class ComponentPropertyServlet extends BeGenericServlet {
} catch (Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE_PROPERTY);
log.debug("get property failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}
@@ -390,16 +375,12 @@ public class ComponentPropertyServlet extends BeGenericServlet {
return buildErrorResponse(status.right().value());
}
Map.Entry<String, PropertyDefinition> property = status.left().value();
- String name = property.getKey();
- PropertyDefinition propertyDefinition = property.getValue();
- log.debug("Property {} deleted successfully with id {}", name, propertyDefinition.getUniqueId());
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
- return buildOkResponse(responseFormat, propertyToJson(property));
+ log.debug("Property {} deleted successfully with id {}", property.getKey(), property.getValue().getUniqueId());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), propertyToJson(property));
} catch (Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Property");
log.debug("delete property failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
index cecb131caa..d603e795c8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
@@ -202,15 +202,12 @@ public class PropertyConvertor {
inRangeConstraint.changeConstraintValueTypeTo(propertyType);
}
- List<Object> range = new ArrayList<>();
- range.add(inRangeConstraint.getMin());
- range.add(inRangeConstraint.getMax());
- convertedConstraints.add(new ToscaPropertyConstraintInRange(range));
+ convertedConstraints.add(new ToscaPropertyConstraintInRange(inRangeConstraint.getInRange()));
}
if (constraint instanceof ValidValuesConstraint) {
ValidValuesConstraint validValues = ((ValidValuesConstraint) constraint);
- if (propertyType.equals(ToscaType.INTEGER.toString()) || propertyType.equals(ToscaType.FLOAT.toString())) {
+ if (doesPropertyTypeNeedConverted(propertyType)) {
validValues.changeConstraintValueTypeTo(propertyType);
}
@@ -234,7 +231,7 @@ public class PropertyConvertor {
}
private boolean doesPropertyTypeNeedConverted(String propertyType) {
- return propertyType.equals(ToscaType.INTEGER.getType()) || propertyType.equals(ToscaType.FLOAT.getType());
+ return ToscaType.INTEGER.getType().equals(propertyType) || ToscaType.FLOAT.getType().equals(propertyType);
}
public Object convertToToscaObject(PropertyDataDefinition property, String value, Map<String, DataTypeDefinition> dataTypes,
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java
index 91e1f553f5..43cc0e3a55 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java
@@ -18,10 +18,11 @@
*/
package org.openecomp.sdc.be.tosca.model;
+import java.util.LinkedList;
+import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
-import java.util.List;
import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
/**