+ ImmutablePair<String, Boolean> pair = propertyOperation
+ .validateAndUpdateRules(propertyType, ((ComponentInstanceProperty) property).getRules(), innerType, allDataTypes, true);
+ if (pair.getRight() != null && Boolean.FALSE.equals(pair.getRight())) {
+ BeEcompErrorManager.getInstance().logBeInvalidValueError("Add property value", pair.getLeft(), property.getName(), propertyType);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
+ DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.ILLEGAL_ARGUMENT))));
+ }
+ return Either.left(newValue);
+ }
+
+ private <T extends AttributeDefinition> Either<String, ResponseFormat> updateAttributeObjectValue(final T attribute) {
+ String innerType = null;
+ final String attributeType = attribute.getType();
+ final ToscaPropertyType type = ToscaPropertyType.isValidType(attributeType);
+ log.debug("The type of the attribute {} is {}", attribute.getUniqueId(), attributeType);
+
+ if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) {
+ final SchemaDefinition def = attribute.getSchema();
+ if (def == null) {
+ log.debug("Schema doesn't exists for attribute of type {}", type);
+ return Either
+ .right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)));
+ }
+ PropertyDataDefinition propDef = def.getProperty();
+ if (propDef == null) {
+ log.debug("Property in Schema Definition inside attribute of type {} doesn't exist", type);
+ return Either
+ .right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)));
+ }
+ innerType = propDef.getType();
+ }
+
+ // Specific Update Logic
+ String newValue = attribute.getValue();
+
+ final var isValid = attributeOperation.validateAndUpdateAttributeValue(attribute, innerType,
+ componentsUtils.getAllDataTypes(applicationDataTypeCache, attribute.getModel()));
+ if (isValid.isRight()) {
+ final Boolean res = isValid.right().value();
+ if (!Boolean.TRUE.equals(res)) {
+ log.debug("validate and update attribute value has failed with value: {}", newValue);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(
+ DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.ILLEGAL_ARGUMENT)));
+ }
+ } else {
+ final Object object = isValid.left().value();
+ if (object != null) {
+ newValue = object.toString();
+ }
+ }
+ return Either.left(newValue);
+ }
+
+ private <T extends PropertyDefinition> void validateToscaGetFunction(T property, Component parentComponent) {
+ final ToscaGetFunctionDataDefinition toscaGetFunction = (ToscaGetFunctionDataDefinition) property.getToscaFunction();
+ validateGetToscaFunctionAttributes(toscaGetFunction);
+ validateGetPropertySource(toscaGetFunction.getFunctionType(), toscaGetFunction.getPropertySource());
+ if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_INPUT) {
+ validateGetFunction(property, parentComponent.getInputs(), parentComponent.getModel());
+ return;
+ }
+ if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_PROPERTY) {
+ if (toscaGetFunction.getPropertySource() == PropertySource.SELF) {
+ validateGetFunction(property, parentComponent.getProperties(), parentComponent.getModel());
+ } else if (toscaGetFunction.getPropertySource() == PropertySource.INSTANCE) {
+ final ComponentInstance componentInstance =
+ parentComponent.getComponentInstanceById(toscaGetFunction.getSourceUniqueId())
+ .orElseThrow(ToscaGetFunctionExceptionSupplier.instanceNotFound(toscaGetFunction.getSourceName()));
+ validateGetFunction(property, componentInstance.getProperties(), parentComponent.getModel());
+ }
+
+ return;
+ }
+ if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_ATTRIBUTE) {
+ if (toscaGetFunction.getPropertySource() == PropertySource.SELF) {
+ validateGetFunction(property, parentComponent.getAttributes(), parentComponent.getModel());
+ } else if (toscaGetFunction.getPropertySource() == PropertySource.INSTANCE) {
+ final ComponentInstance componentInstance =
+ parentComponent.getComponentInstanceById(toscaGetFunction.getSourceUniqueId())
+ .orElseThrow(ToscaGetFunctionExceptionSupplier.instanceNotFound(toscaGetFunction.getSourceName()));
+ validateGetFunction(property, componentInstance.getAttributes(), parentComponent.getModel());
+ }
+
+ return;
+ }
+
+ throw ToscaGetFunctionExceptionSupplier.functionNotSupported(toscaGetFunction.getFunctionType()).get();
+ }
+
+ private <T extends PropertyDefinition> void validateGetFunction(final T property,
+ final List<? extends ToscaPropertyData> parentProperties,
+ final String model) {
+ final ToscaGetFunctionDataDefinition toscaGetFunction = (ToscaGetFunctionDataDefinition) property.getToscaFunction();
+ if (CollectionUtils.isEmpty(parentProperties)) {
+ throw ToscaGetFunctionExceptionSupplier
+ .propertyNotFoundOnTarget(toscaGetFunction.getPropertyName(), toscaGetFunction.getPropertySource(),
+ toscaGetFunction.getFunctionType()
+ ).get();
+ }
+ final String getFunctionPropertyUniqueId = toscaGetFunction.getPropertyUniqueId();
+ ToscaPropertyData referredProperty = parentProperties.stream()
+ .filter(property1 -> getFunctionPropertyUniqueId.equals(property1.getUniqueId()))
+ .findFirst()
+ .orElseThrow(ToscaGetFunctionExceptionSupplier
+ .propertyNotFoundOnTarget(toscaGetFunction.getPropertyName(), toscaGetFunction.getPropertySource()
+ , toscaGetFunction.getFunctionType())
+ );
+ if (toscaGetFunction.isSubProperty()) {
+ referredProperty = findSubProperty(referredProperty, toscaGetFunction, model);
+ }
+
+ if (!property.getType().equals(referredProperty.getType()) && !"list".equalsIgnoreCase(referredProperty.getType())) {
+ throw ToscaGetFunctionExceptionSupplier
+ .propertyTypeDiverge(toscaGetFunction.getType(), referredProperty.getType(), property.getType()).get();
+ }
+ if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getType())
+ && !"list".equalsIgnoreCase(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getSchemaType())) {
+ throw ToscaGetFunctionExceptionSupplier
+ .propertySchemaDiverge(toscaGetFunction.getType(), referredProperty.getSchemaType(), property.getSchemaType()).get();
+ }
+ }
+
+ private ToscaPropertyData findSubProperty(final ToscaPropertyData referredProperty,
+ final ToscaGetFunctionDataDefinition toscaGetFunction,
+ final String model) {
+ final Map<String, DataTypeDefinition> dataTypeMap = loadDataTypes(model);
+ final List<String> propertyPathFromSource = toscaGetFunction.getPropertyPathFromSource();
+ DataTypeDefinition dataType = dataTypeMap.get(referredProperty.getType());
+ if (dataType == null) {
+ throw ToscaGetFunctionExceptionSupplier
+ .propertyDataTypeNotFound(propertyPathFromSource.get(0), referredProperty.getType(), toscaGetFunction.getFunctionType()).get();
+ }
+ ToscaPropertyData foundProperty = referredProperty;
+ for (int i = 1; i < propertyPathFromSource.size(); i++) {
+ final String currentPropertyName = propertyPathFromSource.get(i);
+ foundProperty = dataType.getProperties().stream()
+ .filter(propertyDefinition -> currentPropertyName.equals(propertyDefinition.getName())).findFirst()
+ .orElseThrow(
+ ToscaGetFunctionExceptionSupplier
+ .propertyNotFoundOnTarget(propertyPathFromSource.subList(0, i), toscaGetFunction.getPropertySource(),
+ toscaGetFunction.getFunctionType())
+ );
+ dataType = dataTypeMap.get(foundProperty.getType());
+ if (dataType == null) {
+ throw ToscaGetFunctionExceptionSupplier
+ .propertyDataTypeNotFound(propertyPathFromSource.subList(0, i), foundProperty.getType(),
+ toscaGetFunction.getFunctionType()).get();
+ }
+ }
+ return foundProperty;
+ }
+
+ private Map<String, DataTypeDefinition> loadDataTypes(String model) {
+ final Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> dataTypeEither =
+ applicationDataTypeCache.getAll(model);
+ if (dataTypeEither.isRight()) {
+ throw ToscaGetFunctionExceptionSupplier.couldNotLoadDataTypes(model).get();
+ }
+ return dataTypeEither.left().value();
+ }
+
+ private void validateGetPropertySource(final ToscaGetFunctionType functionType, final PropertySource propertySource) {
+ if (functionType == ToscaGetFunctionType.GET_INPUT && propertySource != PropertySource.SELF) {
+ throw ToscaGetFunctionExceptionSupplier
+ .targetSourceNotSupported(functionType, propertySource).get();
+ }
+ if (functionType == ToscaGetFunctionType.GET_PROPERTY && !List.of(PropertySource.SELF, PropertySource.INSTANCE).contains(propertySource)) {
+ throw ToscaGetFunctionExceptionSupplier
+ .targetSourceNotSupported(functionType, propertySource).get();
+ }
+ }
+
+ private void validateGetToscaFunctionAttributes(final ToscaGetFunctionDataDefinition toscaGetFunction) {
+ if (toscaGetFunction.getFunctionType() == null) {
+ throw ToscaGetFunctionExceptionSupplier.targetFunctionTypeNotFound().get();
+ }
+ if (toscaGetFunction.getPropertySource() == null) {
+ throw ToscaGetFunctionExceptionSupplier.targetPropertySourceNotFound(toscaGetFunction.getFunctionType()).get();
+ }
+ if (CollectionUtils.isEmpty(toscaGetFunction.getPropertyPathFromSource())) {
+ throw ToscaGetFunctionExceptionSupplier
+ .targetSourcePathNotFound(toscaGetFunction.getFunctionType()).get();
+ }
+ if (StringUtils.isEmpty(toscaGetFunction.getSourceName()) || StringUtils.isBlank(toscaGetFunction.getSourceName())) {
+ throw ToscaGetFunctionExceptionSupplier.sourceNameNotFound(toscaGetFunction.getPropertySource()).get();
+ }
+ if (StringUtils.isEmpty(toscaGetFunction.getSourceUniqueId()) || StringUtils.isBlank(toscaGetFunction.getSourceUniqueId())) {
+ throw ToscaGetFunctionExceptionSupplier.sourceIdNotFound(toscaGetFunction.getPropertySource()).get();
+ }
+ if (StringUtils.isEmpty(toscaGetFunction.getPropertyName()) || StringUtils.isBlank(toscaGetFunction.getPropertyName())) {
+ throw ToscaGetFunctionExceptionSupplier.propertyNameNotFound(toscaGetFunction.getPropertySource()).get();
+ }
+ if (StringUtils.isEmpty(toscaGetFunction.getPropertyUniqueId()) || StringUtils.isBlank(toscaGetFunction.getPropertyUniqueId())) {
+ throw ToscaGetFunctionExceptionSupplier.propertyIdNotFound(toscaGetFunction.getPropertySource()).get();