Skip to content

Commit

Permalink
add wildcard handling for validation
Browse files Browse the repository at this point in the history
  • Loading branch information
lkemperman-cfa committed Oct 26, 2023
1 parent c9f9ce1 commit b2244bb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/main/java/formflow/library/ValidationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;

import java.lang.reflect.WildcardType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -17,7 +19,10 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
//import org.springframework.util.StringUtils;
import org.apache.commons.lang3.StringUtils;

import static org.apache.commons.lang3.StringUtils.substringAfterLast;

/**
* A service that validates flow inputs based on input definition.
Expand Down Expand Up @@ -102,6 +107,13 @@ private Map<String, List<String>> performFieldLevelValidation(String flowName, F
key = key.replace("[]", "");
}

String originalKey = key;

if (key.contains("_wildcard")){
key = StringUtils.substringBefore(key, "_wildcard");

}

try {
annotationNames = Arrays.stream(flowClass.getDeclaredField(key).getDeclaredAnnotations())
.map(annotation -> annotation.annotationType().getName()).toList();
Expand All @@ -118,7 +130,8 @@ private Map<String, List<String>> performFieldLevelValidation(String flowName, F
.forEach(violation -> messages.add(violation.getMessage()));

if (!messages.isEmpty()) {
validationMessages.put(key, messages);
// uses original key to accommodate dynamic input names
validationMessages.put(originalKey, messages);
}
});

Expand Down

0 comments on commit b2244bb

Please sign in to comment.