Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expert filter properties #106

Merged
merged 7 commits into from
Apr 19, 2024
Merged

Expert filter properties #106

merged 7 commits into from
Apr 19, 2024

Conversation

souissimai
Copy link
Contributor

No description provided.

@souissimai souissimai requested a review from thangqp April 15, 2024 06:49
}
return ruleBuilder.build();
}
default -> throw new PowsyblException("Unknown rule data type: " + filterEntity.getDataType() + ", supported data types are: COMBINATOR, BOOLEAN, NUMBER, STRING, ENUM");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add FILTER_UUID and PROPERTIES in the list? or make something more generic like: Arrays.stream(DataType.values()).map(Enum::name).collect(Collectors.joining(", "))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 210 to 211
} else if (filter.getDataType() == DataType.BOOLEAN || filter.getDataType() == DataType.NUMBER || filter.getDataType() == DataType.STRING || filter.getDataType() == DataType.ENUM || filter.getDataType() == DataType.FILTER_UUID) {
expertRuleEntityBuilder = ExpertRuleValueEntity.builder()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so long, should line by line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 68 to 78
if (filterEntity instanceof ExpertRuleValueEntity booleanFilterEntity) {
return BooleanExpertRule.builder()
.field(booleanFilterEntity.getField())
.operator(booleanFilterEntity.getOperator())
.value(Boolean.parseBoolean(booleanFilterEntity.getValue()))
.build();
} else {
throw new PowsyblException("Invalid entity type for BOOLEAN rule");
}

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, we can use casting directly, this situation does normally never occur.. idem for others

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 190 to 221
ExpertRuleEntity.ExpertRuleEntityBuilder<?, ?> expertRuleEntityBuilder = null;
if (filter.getDataType() == DataType.COMBINATOR) {
expertRuleEntityBuilder = ExpertRuleEntity.builder()
.id(UUID.randomUUID())
.combinator(filter.getCombinator())
.operator(filter.getOperator())
.dataType(filter.getDataType())
.field(filter.getField());
}
if (filter.getDataType() == DataType.PROPERTIES) {
PropertiesExpertRule propertiesRule = (PropertiesExpertRule) filter;
expertRuleEntityBuilder = ExpertRulePropertiesEntity.builder()
.id(UUID.randomUUID())
.combinator(filter.getCombinator())
.operator(filter.getOperator())
.dataType(filter.getDataType())
.field(filter.getField())
.propertyValues(propertiesRule.getPropertyValues())
.propertyName(propertiesRule.getPropertyName());

} else if (filter.getDataType() == DataType.BOOLEAN || filter.getDataType() == DataType.NUMBER || filter.getDataType() == DataType.STRING || filter.getDataType() == DataType.ENUM || filter.getDataType() == DataType.FILTER_UUID) {
expertRuleEntityBuilder = ExpertRuleValueEntity.builder()
.id(UUID.randomUUID())
.combinator(filter.getCombinator())
.operator(filter.getOperator())
.dataType(filter.getDataType())
.field(filter.getField())
.value(filter.getStringValue());
}
if (expertRuleEntityBuilder == null) {
throw new PowsyblException("Unsupported data type: " + filter.getDataType());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, we can extract to a method: getBuilder(rule) which return a builder in order to reuse in dtoToEntity and in the map() in dtoToEntities.

public static ExpertRuleEntity.ExpertRuleEntityBuilder<?, ?> getBuilder(AbstractExpertRule filter) {
    ExpertRuleEntity.ExpertRuleEntityBuilder<?, ?> expertRuleEntityBuilder = null;
    if (filter.getDataType() == DataType.COMBINATOR) {
        expertRuleEntityBuilder = ExpertRuleEntity.builder()
                .id(UUID.randomUUID())
                .combinator(filter.getCombinator())
                .operator(filter.getOperator())
                .dataType(filter.getDataType())
                .field(filter.getField());
    }
    if (filter.getDataType() == DataType.PROPERTIES) {
        PropertiesExpertRule propertiesRule = (PropertiesExpertRule) filter;
        expertRuleEntityBuilder = ExpertRulePropertiesEntity.builder()
                .id(UUID.randomUUID())
                .combinator(filter.getCombinator())
                .operator(filter.getOperator())
                .dataType(filter.getDataType())
                .field(filter.getField())
                .propertyValues(propertiesRule.getPropertyValues())
                .propertyName(propertiesRule.getPropertyName());

    } else if (filter.getDataType() == DataType.BOOLEAN || filter.getDataType() == DataType.NUMBER || filter.getDataType() == DataType.STRING || filter.getDataType() == DataType.ENUM || filter.getDataType() == DataType.FILTER_UUID) {
        expertRuleEntityBuilder = ExpertRuleValueEntity.builder()
                .id(UUID.randomUUID())
                .combinator(filter.getCombinator())
                .operator(filter.getOperator())
                .dataType(filter.getDataType())
                .field(filter.getField())
                .value(filter.getStringValue());
    }
    if (expertRuleEntityBuilder == null) {
        throw new PowsyblException("Unsupported data type: " + filter.getDataType());
    }

    return expertRuleEntityBuilder;
}

That can avoid duplication of code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 236 to 256
ExpertRuleEntity.ExpertRuleEntityBuilder<?, ?> expertRuleEntityBuilder;
if (rule.getDataType().equals(DataType.PROPERTIES)) {
expertRuleEntityBuilder = ExpertRulePropertiesEntity.builder()
.propertyValues(((PropertiesExpertRule) rule).getPropertyValues())
.propertyName(((PropertiesExpertRule) rule).getPropertyName())
.id(UUID.randomUUID())
.combinator(rule.getCombinator())
.operator(rule.getOperator())
.dataType(rule.getDataType())
.field(rule.getField())
.parentRule(parentRuleEntity);
} else {
expertRuleEntityBuilder = ExpertRuleValueEntity.builder()
.id(UUID.randomUUID())
.combinator(rule.getCombinator())
.operator(rule.getOperator())
.dataType(rule.getDataType())
.field(rule.getField())
.value(rule.getStringValue())
.parentRule(parentRuleEntity);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= getBuilder(rule).parentRule(parentRuleEntity)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Signed-off-by: maissa SOUISSI <[email protected]>
@souissimai souissimai requested a review from thangqp April 15, 2024 14:53
Signed-off-by: maissa SOUISSI <[email protected]>
@ayolab ayolab self-requested a review April 17, 2024 07:01
Signed-off-by: maissa SOUISSI <[email protected]>
Copy link

@souissimai souissimai merged commit 8982868 into main Apr 19, 2024
3 checks passed
@souissimai souissimai deleted the expert_filter-properties branch April 19, 2024 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants