+ } else {
+ allGood = false;
+ final String missingProperty =
+ SOURCE.equals(source) ? filterConstraint.getValue().toString() : filterConstraint.getPropertyName();
+ responseFormat =
+ componentsUtils.getResponseFormat(ActionStatus.FILTER_PROPERTY_NOT_FOUND, source, missingProperty);
+ break;
+ }
+ } else {
+ allGood = false;
+ final String missingProperty =
+ SOURCE.equals(source) ? filterConstraint.getValue().toString() : filterConstraint.getPropertyName();
+ responseFormat =
+ componentsUtils.getResponseFormat(ActionStatus.FILTER_PROPERTY_NOT_FOUND, source, missingProperty);
+ break;
+ }
+ }
+ if (allGood) {
+ return Either.left(true);
+ }
+ return Either.right(responseFormat);
+ }
+
+ private Optional<? extends ToscaPropertyData> findPropertyFromGetFunction(final Component parentComponent,
+ final ToscaGetFunctionDataDefinition toscaGetFunction) {
+ List<? extends ToscaPropertyData> sourcePropertyDefinitions;
+ if (PropertySource.SELF == toscaGetFunction.getPropertySource()) {
+ sourcePropertyDefinitions = getSelfPropertyFromGetFunction(parentComponent, toscaGetFunction);
+ } else {
+ sourcePropertyDefinitions = getInstancePropertiesBasedOnGetFunctionSource(parentComponent, toscaGetFunction);
+ }
+ final List<String> propertyPath = toscaGetFunction.getPropertyPathFromSource();
+ final Optional<? extends ToscaPropertyData> sourceProperty = sourcePropertyDefinitions.stream()
+ .filter(propertyDefinition -> propertyDefinition.getName().equals(propertyPath.get(0))).findFirst();
+ if (sourceProperty.isEmpty() || propertyPath.size() == 1) {
+ return sourceProperty;
+ }
+ final Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypesEither =
+ applicationDataTypeCache.getAll(parentComponent.getModel());
+ if (allDataTypesEither.isRight()) {
+ return Optional.empty();
+ }
+ return findSubProperty(propertyPath.subList(1, propertyPath.size()), sourceProperty.get().getType(), allDataTypesEither.left().value());
+ }
+
+ private List<? extends ToscaPropertyData> getInstancePropertiesBasedOnGetFunctionSource(final Component parentComponent,
+ final ToscaGetFunctionDataDefinition toscaGetFunction) {
+ final ComponentInstance componentInstance = parentComponent.getComponentInstances().stream()
+ .filter(componentInstance1 -> componentInstance1.getName().equals(toscaGetFunction.getSourceName()))
+ .findFirst()
+ .orElse(null);
+ if (componentInstance == null) {
+ return List.of();
+ }
+ final List<? extends ToscaPropertyData> instanceProperties;
+ switch (toscaGetFunction.getFunctionType()) {
+ case GET_PROPERTY:
+ instanceProperties = parentComponent.getComponentInstancesProperties().get(componentInstance.getUniqueId());
+ break;
+ case GET_ATTRIBUTE:
+ instanceProperties = parentComponent.getComponentInstancesAttributes().get(componentInstance.getUniqueId());
+ break;
+ default:
+ instanceProperties = List.of();
+ }
+ if (instanceProperties == null) {
+ return List.of();
+ }
+ return instanceProperties;
+ }
+
+ private Optional<PropertyDefinition> findSubProperty(final List<String> propertyPath, final String parentPropertyType,
+ final Map<String, DataTypeDefinition> modelDataTypes) {
+ final DataTypeDefinition dataTypeDefinition = modelDataTypes.get(parentPropertyType);
+ if (CollectionUtils.isEmpty(dataTypeDefinition.getProperties())) {
+ return Optional.empty();
+ }
+ final PropertyDefinition propertyDefinition = dataTypeDefinition.getProperties().stream()
+ .filter(propertyDefinition1 -> propertyDefinition1.getName().equals(propertyPath.get(0))).findFirst().orElse(null);
+ if (propertyDefinition == null) {
+ return Optional.empty();
+ }
+ if (propertyPath.size() == 1) {
+ return Optional.of(propertyDefinition);
+ }
+ return findSubProperty(propertyPath.subList(1, propertyPath.size()), propertyDefinition.getType(), modelDataTypes);
+ }
+
+ private Optional<? extends PropertyDefinition> getInstanceProperties(final Component parentComponent, final String componentInstanceId,
+ final String capabilityName, final FilterConstraintDto filterConstraint) {
+ if (StringUtils.isEmpty(capabilityName)) {
+ OriginTypeEnum componentInstanceType = getComponentInstanceOriginType(parentComponent, componentInstanceId);
+ if (componentInstanceType == null) {
+ return Optional.empty();
+ }
+ PropertyDefinition componentInstanceProperty =
+ getComponentInstanceProperty(componentInstanceType, parentComponent, componentInstanceId, filterConstraint);
+ if (componentInstanceProperty == null) {
+ throw new ByActionStatusComponentException(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT, filterConstraint.getPropertyName());
+ }
+ if (componentInstanceProperty instanceof ComponentInstanceInput) {
+ return parentComponent.getComponentInstancesInputs().get(componentInstanceId).stream()
+ .filter(property -> filterConstraint.getPropertyName().equals(property.getName())).findFirst();
+ }
+ return parentComponent.getComponentInstancesProperties().get(componentInstanceId).stream()
+ .filter(property -> filterConstraint.getPropertyName().equals(property.getName())).findFirst();
+ } else {
+ final Optional<ComponentInstance> componentInstanceOptional = parentComponent.getComponentInstances().stream()
+ .filter(componentInstance -> componentInstance.getUniqueId().equals(componentInstanceId)).findAny();
+ if (componentInstanceOptional.isPresent()) {
+ for (final List<CapabilityDefinition> listOfCaps : componentInstanceOptional.get().getCapabilities().values()) {
+ final Optional<CapabilityDefinition> capDef = listOfCaps.stream().filter(cap -> cap.getName().equals(capabilityName)).findAny();
+ if (capDef.isPresent()) {
+ return capDef.get().getProperties().stream().filter(property -> filterConstraint.getPropertyName().equals(property.getName()))
+ .findFirst();
+ }
+ }