diff --git a/persistence-service-v1/persistence-service-external-api-impl-v1/src/main/java/com/iqser/red/persistence/service/v1/external/api/impl/controller/RSSComponentLogController.java b/persistence-service-v1/persistence-service-external-api-impl-v1/src/main/java/com/iqser/red/persistence/service/v1/external/api/impl/controller/RSSComponentLogController.java index f29e51ec4..6d2e6538c 100644 --- a/persistence-service-v1/persistence-service-external-api-impl-v1/src/main/java/com/iqser/red/persistence/service/v1/external/api/impl/controller/RSSComponentLogController.java +++ b/persistence-service-v1/persistence-service-external-api-impl-v1/src/main/java/com/iqser/red/persistence/service/v1/external/api/impl/controller/RSSComponentLogController.java @@ -2,8 +2,10 @@ package com.iqser.red.persistence.service.v1.external.api.impl.controller; import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.GET_RSS; -import java.util.HashMap; +import java.util.Comparator; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.Set; @@ -72,12 +74,12 @@ public class RSSComponentLogController implements RSSResource { var componentLog = componentLogService.getComponentLog(file.getDossierId(), file.getId(), true); - Map results = new HashMap<>(); + Map results = new LinkedHashMap<>(); - for (var entry : componentLog.getComponentLogEntries()) { + componentLog.getComponentLogEntries().stream().sorted(new ComponentOrderComparator()).forEach(entry -> { if (entry.getComponentValues().size() <= 1) { results.put(entry.getName(), entry.getComponentValues().get(0).getValue()); - continue; + return; } List componentValues = entry.getComponentValues(); @@ -85,7 +87,7 @@ public class RSSComponentLogController implements RSSResource { ComponentLogEntryValue v = componentValues.get(i); results.put(entry.getName() + "_" + (i + 1), v.getValue()); } - } + }); return RSSFileResponse.builder().filename(file.getFilename()).result(results).build(); @@ -112,12 +114,12 @@ public class RSSComponentLogController implements RSSResource { var componentLog = componentLogService.getComponentLog(file.getDossierId(), file.getId(), true); - Map results = new HashMap<>(); + Map results = new LinkedHashMap<>(); - for (var entry : componentLog.getComponentLogEntries()) { + componentLog.getComponentLogEntries().stream().sorted(new ComponentOrderComparator()).forEach(entry -> { if (entry.getComponentValues().size() <= 1) { results.put(entry.getName(), toSCMComponent(entry.getComponentValues().get(0))); - continue; + return; } List componentValues = entry.getComponentValues(); @@ -125,7 +127,7 @@ public class RSSComponentLogController implements RSSResource { ComponentLogEntryValue v = componentValues.get(i); results.put(entry.getName() + "_" + (i + 1), toSCMComponent(v)); } - } + }); return DetailedRSSFileResponse.builder().filename(file.getFilename()).result(results).build(); } @@ -144,7 +146,13 @@ public class RSSComponentLogController implements RSSResource { private ScmAnnotation toScmAnnotation(ComponentLogEntityReference er) { - return ScmAnnotation.builder().type(er.getType()).pages(Set.of(er.getPage())).ruleIdentifier(er.getEntityRuleId()).reason("").build(); + return ScmAnnotation.builder().type(er.getType()).pages(Set.of(er.getPage())).ruleIdentifier(er.getEntityRuleId()).reason(formatType(er.getType())).build(); + } + + + private static String formatType(String type) { + + return type.substring(0, 1).toUpperCase(Locale.ENGLISH) + type.substring(1).toLowerCase(Locale.ENGLISH).replaceAll("_", " "); } @@ -254,4 +262,70 @@ public class RSSComponentLogController implements RSSResource { .orElse(""); } + + private static class ComponentOrderComparator implements Comparator { + + private static final List ORDER = List.of("Study_Title", + "Performing_Laboratory", + "Report_Number", + "GLP_Study", + "Test_Guidelines_1", + "Test_Guidelines_2", + "Experimental_Starting_Date", + "Experimental_Completion_Date", + "Certificate_of_Analysis_Batch_Identification", + "Species", + "Strain", + "Was_the_definitive_study_conducted_with_positive_control", + "Results_Main_Study", + "Preliminary_Test_Results", + "What_was_the_approach_used", + "Sex", + "Number_of_Animals", + "Study_Design", + "Test_Results", + "Results_and_Conclusions", + "Conducted_with_4_Hours_of_Exposure", + "Dosages", + "Doses_mg_per_kg_bw", + "Mortality", + "Dose_Mortality", + "Mortality_Statement", + "Weight_Behavior_Changes", + "Clinical_Observations", + "Clinical_Signs", + "Body_Weight_Changes", + "Necropsy_Findings", + "Detailing_of_Reported_Changes", + "Deviation_from_the_Guideline", + "Conclusion_LD50_Greater_than", + "Conclusion_LD50_mg_per_kg", + "Conclusion_Minimum_Confidence", + "Conclusion_Maximum_Confidence", + "Study_Conclusion"); + + + @Override + public int compare(ComponentLogEntry entry1, ComponentLogEntry entry2) { + + String name1 = entry1.getName(); + String name2 = entry2.getName(); + boolean thisInList = ORDER.contains(name1); + boolean otherInList = ORDER.contains(name2); + + // Compare the types + if (thisInList && !otherInList) { + return -1; + } else if (!thisInList && otherInList) { + return 1; + } else if (thisInList && otherInList) { + int thisIndex = ORDER.indexOf(name1); + int otherIndex = ORDER.indexOf(name2); + return Integer.compare(thisIndex, otherIndex); + } + return String.CASE_INSENSITIVE_ORDER.compare(name1, name2); + } + + } + }