Hi
In my apps I tend to use lots of configuration and among them, configuration of properties that are enumerations or dates. Examples given below.
It could be interesting to have such values implemented natively.
@Property("busy.rounding.mode.for.factor")
@DefaultString("HALF_UP")
String getRoundingModeForFactorString();
default RoundingMode getRoundingModeForFactor() {
return RoundingMode.valueOf(getRoundingModeForFactorString());
}
@Property("busy.rounding.scale.for.price")
@DefaultInt(2)
int getRoundingScaleForPrice();
@Property("busy.rounding.mode.for.price")
@DefaultString("HALF_UP")
String getRoundingModeForPriceString();
default RoundingMode getRoundingModeForPrice() {
return RoundingMode.valueOf(getRoundingModeForPriceString());
}
@Property("busy.accounting.movements.sending.startDate")
@DefaultString("2022-06-04")
String getMovementsSendingStartDateString();
default LocalDate getMovementsSendingStartDate() {
return DateUtils.DATE_FORMAT_AAAA_MM_JJ.parse(getMovementsSendingStartDateString()).query(TemporalQueries.localDate());
}
@Property("busy.accounting.planEnrichmentFormula")
@DefaultString("servreg7chars")
String getPlanEnrichmentFormulaString();
void setPlanEnrichmentFormulaString(String plan);
default AccountingPlanEnrichmentFormula getPlanEnrichmentFormula() {
AccountingPlanEnrichmentFormula formula = AccountingPlanEnrichmentFormula.fromId(getPlanEnrichmentFormulaString());
return formula != null ? formula : AccountingPlanEnrichmentFormula.WITH_SERVICE_AND_REGION;
}
Also for the last example I would like to be able to write a setter using the enum value like below.
default void setPlanEnrichmentFormula(AccountingPlanEnrichmentFormula val) {
setPlanEnrichmentFormulaString(val.getId());
}
But doing so will rise an exception.
java.lang.RuntimeException: Invalid config interface method: public default void com.ibusy2.config.AccountingConfig.setPlanEnrichmentFormula(com.ibusy2.entity.AccountingPlanEnrichmentFormula)
at com.haulmont.cuba.core.config.ConfigMethods.newInstance(ConfigMethods.java:41)
at com.haulmont.cuba.core.config.ConfigMethods.getInstance(ConfigMethods.java:69)
Setters are quite useful in my case because apps are auto-configuring themselves once deployed according to customer specific setup, and doing so using configuration setters (among other mechanisms).
I admit such improvements become more and more useful in big apps where you have to write a lot of configuration, but anyway that would help.
Regards
Michael