DM-285: added componentLog sorting in ComponentLogService #158

Merged
kilian.schuettler1 merged 1 commits from DM-285 into master 2023-10-05 14:37:01 +02:00
3 changed files with 87 additions and 71 deletions

View File

@ -2,7 +2,6 @@ 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.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
@ -76,7 +75,7 @@ public class RSSComponentLogController implements RSSResource {
Map<String, String> results = new LinkedHashMap<>();
componentLog.getComponentLogEntries().stream().sorted(new ComponentOrderComparator()).forEach(entry -> {
componentLog.getComponentLogEntries().forEach(entry -> {
if (entry.getComponentValues().size() <= 1) {
results.put(entry.getName(), entry.getComponentValues().get(0).getValue());
return;
@ -116,7 +115,7 @@ public class RSSComponentLogController implements RSSResource {
Map<String, SCMComponent> results = new LinkedHashMap<>();
componentLog.getComponentLogEntries().stream().sorted(new ComponentOrderComparator()).forEach(entry -> {
componentLog.getComponentLogEntries().forEach(entry -> {
if (entry.getComponentValues().size() <= 1) {
results.put(entry.getName(), toSCMComponent(entry.getComponentValues().get(0)));
return;
@ -262,70 +261,4 @@ public class RSSComponentLogController implements RSSResource {
.orElse("");
}
private static class ComponentOrderComparator implements Comparator<ComponentLogEntry> {
private static final List<String> 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);
}
}
}

View File

@ -1,5 +1,6 @@
package com.iqser.red.service.persistence.management.v1.processor.service;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
@ -9,7 +10,9 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.componentlog.ComponentLogEntry;
import com.iqser.red.service.persistence.service.v1.api.shared.model.component.ComponentsOverrides;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
@Service
@RequiredArgsConstructor
@ -18,10 +21,51 @@ public class ComponentLogService {
private final FileManagementStorageService fileManagementStorageService;
private final ComponentOverrideService componentOverrideService;
// TODO: make this DB changeable!
private static final List<String> 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");
public ComponentLog getComponentLog(String dossierId, String fileId, boolean includeOverrides) {
ComponentLog componentLog = fileManagementStorageService.getComponentLog(dossierId, fileId);
ComponentLog componentLog = sortComponentLogEntriesByOrderList(fileManagementStorageService.getComponentLog(dossierId, fileId), ORDER);
if (!includeOverrides) {
return componentLog;
}
@ -42,6 +86,14 @@ public class ComponentLogService {
}
private ComponentLog sortComponentLogEntriesByOrderList(ComponentLog componentLog, List<String> order) {
return new ComponentLog(componentLog.getAnalysisNumber(),
componentLog.getComponentRulesVersion(),
componentLog.getComponentLogEntries().stream().sorted(new ComponentOrderComparator(order)).toList());
}
public ComponentLog getComponentLog(String dossierId, String fileId) {
return getComponentLog(dossierId, fileId, true);
@ -58,4 +110,35 @@ public class ComponentLogService {
return componentLogEntry;
}
@RequiredArgsConstructor
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
private static class ComponentOrderComparator implements Comparator<ComponentLogEntry> {
List<String> order;
@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);
}
}
}

View File

@ -17,7 +17,7 @@ GIT_BRANCH=$(git symbolic-ref --short HEAD)
# Get the first 5 characters of the commit hash
GIT_COMMIT_HASH=$(git rev-parse --short=5 HEAD)
# Create the image tag by combining branch and commit hash
IMAGE_TAG="${GIT_BRANCH}-${GIT_COMMIT_HASH}"
IMAGE_TAG="${USER}-${GIT_BRANCH}-${GIT_COMMIT_HASH}"
IMAGE_NAME="$NEXUS_REPO/$IMAGE_NAME:$IMAGE_TAG"
echo "Building docker image: {$IMAGE_NAME}"