FINERACT-2326: Rework business date validation and dto handling

This commit is contained in:
Adam Saghy
2025-08-19 13:18:40 +02:00
parent f41d986b2a
commit 942ad0183c
24 changed files with 296 additions and 168 deletions
@@ -0,0 +1,42 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.validation.constraints;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Documented
@Constraint(validatedBy = EnumValueValidator.class)
@Target({ ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
public @interface EnumValue {
String message() default "{org.apache.fineract.validation.enum}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
Class<? extends Enum<?>> enumClass();
}
@@ -0,0 +1,41 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.validation.constraints;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
public class EnumValueValidator implements ConstraintValidator<EnumValue, String> {
private Set<String> acceptedValues;
@Override
public void initialize(EnumValue annotation) {
acceptedValues = Arrays.stream(annotation.enumClass().getEnumConstants()).map(e -> e.name().toLowerCase())
.collect(Collectors.toSet());
}
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
return value != null && acceptedValues.contains(value.toLowerCase());
}
}
@@ -21,11 +21,13 @@
org.apache.fineract.validation.local-date=Wrong local date fields.
org.apache.fineract.validation.locale=The parameter `locale` has an invalid language value: `${validatedValue}`.
org.apache.fineract.validation.enum=The parameter has an invalid enum value: `${validatedValue}`.
## Business Date
org.apache.fineract.businessdate.date-format.not-blank=The parameter 'dateFormat' is mandatory.
org.apache.fineract.businessdate.type.not-null=The parameter 'type' is mandatory.
org.apache.fineract.businessdate.type.not-blank=The parameter 'type' is mandatory.
org.apache.fineract.businessdate.type.invalid=The parameter 'type' must be valid BusinessDateType value. Provided value: '${validatedValue}'.
org.apache.fineract.businessdate.date.not-blank=The parameter 'date' is mandatory.
org.apache.fineract.businessdate.locale.not-blank=The parameter 'locale' is mandatory.