* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.openecomp.sdc.be.components.impl;
import static org.openecomp.sdc.be.components.attribute.GetOutputUtils.isGetOutputValueForOutput;
private static final String CREATE_OR_UPDATE_PROPERTY_VALUE = "CreateOrUpdatePropertyValue";
private static final String FAILED_TO_COPY_COMP_INSTANCE_TO_CANVAS = "Failed to copy the component instance to the canvas";
private static final String COPY_COMPONENT_INSTANCE_OK = "Copy component instance OK";
- private static final String CANNOT_ATTACH_RESOURCE_INSTANCES_TO_CONTAINER_RESOURCE_OF_TYPE = "Cannot attach resource instances to container resource of type {}";
+ private static final String CANNOT_ATTACH_RESOURCE_INSTANCES_TO_CONTAINER_RESOURCE_OF_TYPE =
+ "Cannot attach resource instances to container resource of type {}";
private static final String FAILED_TO_UPDATE_COMPONENT_INSTANCE_CAPABILITY = "Failed to update component instance capability on instance {} in "
+ "container {}";
private static final String SERVICE_PROXY = "serviceProxy";
private final ComponentInstanceChangeOperationOrchestrator onChangeInstanceOperationOrchestrator;
private final ForwardingPathOperation forwardingPathOperation;
private final NodeFilterOperation nodeFilterOperation;
+ private final ToscaFunctionValidator toscaFunctionValidator;
+ private final PropertyBusinessLogic propertyBusinessLogic;
@Autowired
private CompositionBusinessLogic compositionBusinessLogic;
@Autowired
private ContainerInstanceTypesData containerInstanceTypesData;
- private final ToscaFunctionValidator toscaFunctionValidator;
- private final PropertyBusinessLogic propertyBusinessLogic;
@Autowired
public ComponentInstanceBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation,
}
if (CollectionUtils.isNotEmpty(filteredGroups)) {
filteredGroups.stream()
- .filter(g -> g.getArtifacts() != null && g.getArtifacts().stream().anyMatch(p -> p.equals(artifactDefinition.getGeneratedFromId()))).findFirst()
+ .filter(g -> g.getArtifacts() != null &&
+ g.getArtifacts().stream().anyMatch(p -> p.equals(artifactDefinition.getGeneratedFromId()))).findFirst()
.ifPresent(g -> fillInstanceArtifactMap(groupInstancesArtifacts, artifactDefinition, g));
}
}
ComponentInstance foundResourceInstance = resourceInstanceStatus.left().value();
// Validate instance property against it's constrains
- Either<Boolean, ResponseFormat> constraintValidatorResponse = validatePropertyValueConstraint(properties,componentId);
+ Either<Boolean, ResponseFormat> constraintValidatorResponse = validatePropertyValueConstraint(properties, componentId);
if (constraintValidatorResponse.isRight()) {
log.error("Failed validation value and constraint of property: {}", constraintValidatorResponse.right().value());
return Either.right(constraintValidatorResponse.right().value());
for (ComponentInstanceProperty property : properties) {
validateMandatoryFields(property);
validatePropertyExistsOnComponent(property, containerComponent, foundResourceInstance);
- // validatePropertyConstraintsNotChanged(properties, foundResourceInstance);
+ validatePropertyConstraintsNotChanged(properties, foundResourceInstance);
String propertyParentUniqueId = property.getParentUniqueId();
if (property.isToscaFunction()) {
toscaFunctionValidator.validate(property, containerComponent);
jsonArray.put(Integer.parseInt(path.get(0)), valueAsObject);
} else {
if (objectForPath instanceof JSONObject) {
- addE((JSONObject)objectForPath, path.subList(1, path.size()), value);
+ addE((JSONObject) objectForPath, path.subList(1, path.size()), value);
} else {
- addE((JSONArray)objectForPath, path.subList(1, path.size()), value);
+ addE((JSONArray) objectForPath, path.subList(1, path.size()), value);
}
}
}
Object objectForPath = null;
if (jsonObject.has(path.get(0))) {
- objectForPath = jsonObject.get(path.get(0));
+ objectForPath = jsonObject.get(path.get(0));
} else {
if (StringUtils.isNumeric(path.get(0))) {
objectForPath = new JSONArray();
jsonObject.put(path.get(0), valueAsObject);
} else {
if (objectForPath instanceof JSONObject) {
- addE((JSONObject)objectForPath, path.subList(1, path.size()), value);
+ addE((JSONObject) objectForPath, path.subList(1, path.size()), value);
} else {
- addE((JSONArray)objectForPath, path.subList(1, path.size()), value);
+ addE((JSONArray) objectForPath, path.subList(1, path.size()), value);
}
}
}
propertyDefinition.setUniqueId(componentInstanceAttribute.getUniqueId());
attributesToValidate.add(propertyDefinition);
});
- Either<Boolean, ResponseFormat> constraintValidatorResponse = validatePropertyValueConstraint(attributesToValidate,componentId);
+ Either<Boolean, ResponseFormat> constraintValidatorResponse = validatePropertyValueConstraint(attributesToValidate, componentId);
if (constraintValidatorResponse.isRight()) {
log.error("Failed validation value and constraint of attribute: {}", constraintValidatorResponse.right().value());
return Either.right(constraintValidatorResponse.right().value());
}
private void validatePropertyExistsOnComponent(ComponentInstanceProperty property, Component containerComponent,
- ComponentInstance foundResourceInstance) {
+ ComponentInstance foundResourceInstance) {
List<ComponentInstanceProperty> instanceProperties = containerComponent.getComponentInstancesProperties()
.get(foundResourceInstance.getUniqueId());
final boolean hasProperty = instanceProperties.stream().anyMatch(p -> p.getName().equals(property.getName()));
}
private void maintainNodeFilters(
- ComponentInstance currentResourceInstance,
- ComponentInstance newComponentInstance,
- String containerComponentId) {
+ ComponentInstance currentResourceInstance,
+ ComponentInstance newComponentInstance,
+ String containerComponentId) {
CINodeFilterDataDefinition filterToMaintain = currentResourceInstance.getNodeFilter();
if (null != filterToMaintain) {
nodeFilterOperation.addNodeFilterData(
- containerComponentId.toLowerCase(),
- newComponentInstance.getUniqueId(),
- filterToMaintain);
+ containerComponentId.toLowerCase(),
+ newComponentInstance.getUniqueId(),
+ filterToMaintain);
}
}
private void checkForExternalReqAndCapabilities(Component component, ComponentInstance resResourceInfo) {
if (MapUtils.isNotEmpty(component.getRequirements())) {
component.getRequirements().entrySet().forEach(requirementsMap -> {
- if (MapUtils.isNotEmpty(resResourceInfo.getRequirements()) && resResourceInfo.getRequirements().containsKey(requirementsMap.getKey())) {
+ if (MapUtils.isNotEmpty(resResourceInfo.getRequirements()) &&
+ resResourceInfo.getRequirements().containsKey(requirementsMap.getKey())) {
List<RequirementDefinition> resourceReqList = resResourceInfo.getRequirements().get(requirementsMap.getKey());
for (RequirementDefinition requirements : requirementsMap.getValue()) {
String requirementName = requirements.getName();
private void validatePropertyConstraintsNotChanged(List<ComponentInstanceProperty> newProperties, ComponentInstance originalResourceInstance) {
for (ComponentInstanceProperty newProperty : newProperties) {
Optional<PropertyDefinition> originalProperty = originalResourceInstance.getProperties().stream()
- .filter(prop -> prop.getUniqueId().equals(newProperty.getUniqueId())).findAny();
+ .filter(prop -> prop.getUniqueId().equals(newProperty.getUniqueId())).findAny();
if (originalProperty.isPresent()) {
List<PropertyConstraint> originalConstraints = originalProperty.get().getConstraints();
List<PropertyConstraint> newConstraints = newProperty.getConstraints();
* 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;
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;
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";
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);
return je.getAsBoolean();
}
if (je.isNumber()) {
- double number = je.getAsNumber().floatValue();
+ float number = je.getAsNumber().floatValue();
if ((number % 1) == 0) {
return je.getAsNumber().intValue();
}
} 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);
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);