-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
Signed-off-by: maissa SOUISSI <[email protected]>
Signed-off-by: maissa SOUISSI <[email protected]>
Signed-off-by: maissa SOUISSI <[email protected]>
} | ||
return ruleBuilder.build(); | ||
} | ||
default -> throw new PowsyblException("Unknown rule data type: " + filterEntity.getDataType() + ", supported data types are: COMBINATOR, BOOLEAN, NUMBER, STRING, ENUM"); |
There was a problem hiding this comment.
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(", "))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} 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() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
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"); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
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()); | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= getBuilder(rule).parentRule(parentRuleEntity)
There was a problem hiding this comment.
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]>
Signed-off-by: maissa SOUISSI <[email protected]>
Signed-off-by: maissa SOUISSI <[email protected]>
Quality Gate passedIssues Measures |
No description provided.