Skip to content

Commit daf2144

Browse files
fix: Updated extractAllInputPaths logic to return unique FormPaths. (#294)
1 parent 54a01e5 commit daf2144

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

builder-api/src/main/java/org/acme/controller/ScreenerResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public Response getScreenerFormPaths(@Context SecurityIdentity identity,
285285

286286
try {
287287
List<Benefit> benefits = screenerRepository.getBenefitsInScreener(screener);
288-
List<FormPath> paths = new ArrayList<>(inputSchemaService.extractAllInputPaths(benefits));
288+
List<FormPath> paths = new ArrayList<>(inputSchemaService.extractUniqueInputPaths(benefits));
289289
Collections.sort(paths, new Comparator<FormPath>() {
290290
public int compare(FormPath fp1, FormPath fp2) {
291291
// compare two instance of `Score` and return `int` as result.

builder-api/src/main/java/org/acme/service/InputSchemaService.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,29 @@ public class InputSchemaService {
2323
* Extracts all unique input paths from all benefits in a screener.
2424
*
2525
* @param benefits List of benefits containing checks with inputDefinitions
26-
* @return Set of unique dot-separated paths (e.g., "people.applicant.dateOfBirth")
26+
* @return List of unique FormPath objects
2727
*/
28-
public Set<FormPath> extractAllInputPaths(List<Benefit> benefits) {
29-
Set<FormPath> pathSet = new HashSet<>();
28+
public List<FormPath> extractUniqueInputPaths(List<Benefit> benefits) {
29+
Map<String, String> pathTypeMap = new HashMap<>();
3030

3131
for (Benefit benefit : benefits) {
3232
List<CheckConfig> checks = benefit.getChecks();
3333
if (checks == null) continue;
3434

3535
for (CheckConfig check : checks) {
3636
JsonNode transformedSchema = transformInputDefinitionSchema(check);
37-
List<FormPath> paths = extractJsonSchemaPaths(transformedSchema);
38-
pathSet.addAll(paths);
37+
List<FormPath> checkFormPaths = extractJsonSchemaPaths(transformedSchema);
38+
for (FormPath checkFormPath : checkFormPaths) {
39+
// If the same path exists with different types, keep the first one found
40+
pathTypeMap.putIfAbsent(checkFormPath.getPath(), checkFormPath.getType());
41+
}
3942
}
4043
}
4144

42-
return pathSet;
45+
// Convert to sorted list of FormPath objects
46+
return pathTypeMap.entrySet().stream()
47+
.map(entry -> new FormPath(entry.getKey(), entry.getValue()))
48+
.toList();
4349
}
4450

4551
/**

0 commit comments

Comments
 (0)