From 2792e210a64e1dd44c860094fd6c17ec087147b8 Mon Sep 17 00:00:00 2001 From: kfilippopolitis <kostasfilippop@gmail.com> Date: Thu, 10 Nov 2022 18:09:04 +0200 Subject: [PATCH 1/2] Properly formatted the enumerations on the CommonDataElements. --- .../hbp/mip/controllers/PathologiesAPI.java | 27 ++++++---- .../models/DTOs/MIPEngineAttributesDTO.java | 18 ++++++- .../mip/models/DTOs/MetadataHierarchyDTO.java | 51 +++++++++++++++++-- .../eu/hbp/mip/models/DTOs/PathologyDTO.java | 7 ++- .../java/eu/hbp/mip/utils/ClaimUtils.java | 4 +- 5 files changed, 84 insertions(+), 23 deletions(-) diff --git a/src/main/java/eu/hbp/mip/controllers/PathologiesAPI.java b/src/main/java/eu/hbp/mip/controllers/PathologiesAPI.java index e53d8d354..e6a2de685 100644 --- a/src/main/java/eu/hbp/mip/controllers/PathologiesAPI.java +++ b/src/main/java/eu/hbp/mip/controllers/PathologiesAPI.java @@ -15,8 +15,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import java.io.IOException; -import java.net.ConnectException; import java.util.*; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @@ -49,17 +47,14 @@ public class PathologiesAPI { Logger logger = new Logger(activeUserService.getActiveUser().getUsername(), "(GET) /pathologies"); logger.LogUserAction("Loading pathologies ..."); - Map<String, List<PathologyDTO.PathologyDatasetDTO>> datasetsPerPathology = getMIPEngineDatasetsPerPathology(logger); - System.out.println(datasetsPerPathology); + Map<String, List<PathologyDTO.EnumerationDTO>> datasetsPerPathology = getMIPEngineDatasetsPerPathology(logger); Map<String, MIPEngineAttributesDTO> mipEnginePathologyAttributes = getMIPEnginePathologyAttributes(logger); - System.out.println(mipEnginePathologyAttributes); List<PathologyDTO> pathologyDTOS = new ArrayList<>(); for (String pathology : mipEnginePathologyAttributes.keySet()) { pathologyDTOS.add(new PathologyDTO(pathology, mipEnginePathologyAttributes.get(pathology), datasetsPerPathology.get(pathology))); } - System.out.println(pathologyDTOS); // If authentication is disabled return everything if (!authenticationIsEnabled) { @@ -71,7 +66,7 @@ public class PathologiesAPI { return ResponseEntity.ok().body(gson.toJson(ClaimUtils.getAuthorizedPathologies(logger, authentication, pathologyDTOS))); } - public Map<String, List<PathologyDTO.PathologyDatasetDTO>> getMIPEngineDatasetsPerPathology(Logger logger) { + public Map<String, List<PathologyDTO.EnumerationDTO>> getMIPEngineDatasetsPerPathology(Logger logger) { Map<String, Map<String, MetadataHierarchyDTO.CommonDataElement>> mipEngineCDEsMetadata; // Get MIPEngine algorithms try { @@ -87,15 +82,17 @@ public class PathologiesAPI { return null; } - Map<String, List<PathologyDTO.PathologyDatasetDTO>> datasetsPerPathology = new HashMap<>(); + Map<String, List<PathologyDTO.EnumerationDTO>> datasetsPerPathology = new HashMap<>(); mipEngineCDEsMetadata.forEach( (pathology, cdePerDataset) -> { - List<PathologyDTO.PathologyDatasetDTO> pathologyDatasetDTOS = new ArrayList<>(); - cdePerDataset.forEach((dataset, cde) -> pathologyDatasetDTOS.add(new PathologyDTO.PathologyDatasetDTO(dataset, cde.getLabel()))); + List<PathologyDTO.EnumerationDTO> pathologyDatasetDTOS = new ArrayList<>(); + Map datasetEnumerations = (Map) cdePerDataset.get("dataset").getEnumerations(); + datasetEnumerations.forEach((code, label) -> pathologyDatasetDTOS.add(new PathologyDTO.EnumerationDTO((String) code, (String) label))); datasetsPerPathology.put(pathology, pathologyDatasetDTOS); }); + return datasetsPerPathology; } @@ -115,6 +112,14 @@ public class PathologiesAPI { return null; } - return mipEnginePathologyAttributes; + Map<String, MIPEngineAttributesDTO> mipEnginePathologyAttributesWithProperEnums = new HashMap<>(); + for (Map.Entry<String, MIPEngineAttributesDTO> entry : mipEnginePathologyAttributes.entrySet()) { + String pathology = entry.getKey(); + MIPEngineAttributesDTO attributes = entry.getValue(); + attributes.updateAttributesWithProperEnums(); + mipEnginePathologyAttributesWithProperEnums.put(pathology, attributes); + } + + return mipEnginePathologyAttributesWithProperEnums; } } diff --git a/src/main/java/eu/hbp/mip/models/DTOs/MIPEngineAttributesDTO.java b/src/main/java/eu/hbp/mip/models/DTOs/MIPEngineAttributesDTO.java index 2f81aee6a..2c4794d7e 100644 --- a/src/main/java/eu/hbp/mip/models/DTOs/MIPEngineAttributesDTO.java +++ b/src/main/java/eu/hbp/mip/models/DTOs/MIPEngineAttributesDTO.java @@ -1,10 +1,11 @@ package eu.hbp.mip.models.DTOs; import com.google.gson.annotations.SerializedName; -import eu.hbp.mip.models.DTOs.MetadataHierarchyDTO; import lombok.AllArgsConstructor; import lombok.Data; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -17,4 +18,19 @@ public class MIPEngineAttributesDTO { @SerializedName("tags") private Object tags; + public void updateAttributesWithProperEnums(){ + Map<String, List<MetadataHierarchyDTO>> updated_properties = new HashMap<>(); + for (Map.Entry<String, List<MetadataHierarchyDTO>> entry : this.properties.entrySet()) { + String pathology = entry.getKey(); + List<MetadataHierarchyDTO> hierarchyDTOS = entry.getValue(); + List<MetadataHierarchyDTO> updatedHierarchyDTOS = new ArrayList<>(); + + for (MetadataHierarchyDTO hierarchyDTO : hierarchyDTOS) { + hierarchyDTO.updateGroupWithProperEnums(); + updatedHierarchyDTOS.add(hierarchyDTO); + } + updated_properties.put(pathology,updatedHierarchyDTOS); + } + this.properties = updated_properties; + } } diff --git a/src/main/java/eu/hbp/mip/models/DTOs/MetadataHierarchyDTO.java b/src/main/java/eu/hbp/mip/models/DTOs/MetadataHierarchyDTO.java index e0db0c70d..200523a91 100644 --- a/src/main/java/eu/hbp/mip/models/DTOs/MetadataHierarchyDTO.java +++ b/src/main/java/eu/hbp/mip/models/DTOs/MetadataHierarchyDTO.java @@ -4,9 +4,9 @@ import com.google.gson.annotations.SerializedName; import lombok.AllArgsConstructor; import lombok.Data; -import java.util.Hashtable; +import java.util.ArrayList; import java.util.List; -import java.util.Optional; +import java.util.Map; @Data @AllArgsConstructor @@ -19,15 +19,15 @@ public class MetadataHierarchyDTO { private String code; @SerializedName("groups") - private Object groups; + private List<MetadataHierarchyDTO> groups; @SerializedName("label") private String label; @Data @AllArgsConstructor public static class CommonDataElement { - @SerializedName("isCategorical") - private Boolean isCategorical; + @SerializedName("is_categorical") + private Boolean is_categorical; @SerializedName("code") private String code; @@ -53,5 +53,46 @@ public class MetadataHierarchyDTO { @SerializedName("methodology") private String methodology; + @SerializedName("min") + private String min; + + @SerializedName("max") + private String max; + + private void updateEnumerations(){ + if (this.enumerations != null){ + Map old_enumeration = (Map) this.enumerations; + List<PathologyDTO.EnumerationDTO> enumerationDTOS = new ArrayList<>(); + old_enumeration.forEach((cdeCode, cdeLabel) -> { + enumerationDTOS.add(new PathologyDTO.EnumerationDTO((String) cdeCode, (String) cdeLabel)); + }); + setEnumerations(enumerationDTOS); + } + } + } + + public void updateVariableWithProperEnums(){ + List<CommonDataElement> updated_variables = new ArrayList<>(); + this.variables.forEach(commonDataElement -> { + commonDataElement.updateEnumerations(); + updated_variables.add(commonDataElement); + }); + setVariables(updated_variables); + } + + public void updateGroupWithProperEnums(){ + List<MetadataHierarchyDTO> updated_groups = new ArrayList<>(); + for (MetadataHierarchyDTO hierarchyDTO : this.groups) { + + if (hierarchyDTO.getVariables() != null) { + hierarchyDTO.updateVariableWithProperEnums(); + } + + if (hierarchyDTO.getGroups() != null) { + hierarchyDTO.updateGroupWithProperEnums(); + } + updated_groups.add(hierarchyDTO); + } + this.groups = updated_groups; } } diff --git a/src/main/java/eu/hbp/mip/models/DTOs/PathologyDTO.java b/src/main/java/eu/hbp/mip/models/DTOs/PathologyDTO.java index 8771aefd1..e47a27a9f 100644 --- a/src/main/java/eu/hbp/mip/models/DTOs/PathologyDTO.java +++ b/src/main/java/eu/hbp/mip/models/DTOs/PathologyDTO.java @@ -6,7 +6,6 @@ import lombok.Data; import java.util.Arrays; import java.util.List; -import java.util.Optional; @Data @AllArgsConstructor @@ -26,14 +25,14 @@ public class PathologyDTO { private MetadataHierarchyDTO metadataHierarchyDTO; @SerializedName("datasets") - private List<PathologyDatasetDTO> datasets; + private List<EnumerationDTO> datasets; public PathologyDTO(){ } - public PathologyDTO(String pathology, MIPEngineAttributesDTO mipEngineAttributesDTO, List<PathologyDatasetDTO> pathologyDatasetDTOS) { + public PathologyDTO(String pathology, MIPEngineAttributesDTO mipEngineAttributesDTO, List<EnumerationDTO> pathologyDatasetDTOS) { MetadataHierarchyDTO metadataHierarchyDTO = mipEngineAttributesDTO.getProperties().get("cdes").get(0); List<MetadataHierarchyDTO.CommonDataElement> variables = metadataHierarchyDTO.getVariables(); variables.stream().filter(cde -> cde.getCode().equals("dataset")). @@ -50,7 +49,7 @@ public class PathologyDTO { @Data @AllArgsConstructor - public static class PathologyDatasetDTO { + public static class EnumerationDTO { @SerializedName("code") private String code; diff --git a/src/main/java/eu/hbp/mip/utils/ClaimUtils.java b/src/main/java/eu/hbp/mip/utils/ClaimUtils.java index df2a75abf..650ac9c65 100644 --- a/src/main/java/eu/hbp/mip/utils/ClaimUtils.java +++ b/src/main/java/eu/hbp/mip/utils/ClaimUtils.java @@ -68,8 +68,8 @@ public class ClaimUtils { List<PathologyDTO> userPathologies = new ArrayList<>(); for (PathologyDTO curPathology : allPathologies) { - List<PathologyDTO.PathologyDatasetDTO> userPathologyDatasets = new ArrayList<>(); - for (PathologyDTO.PathologyDatasetDTO dataset : curPathology.getDatasets()) { + List<PathologyDTO.EnumerationDTO> userPathologyDatasets = new ArrayList<>(); + for (PathologyDTO.EnumerationDTO dataset : curPathology.getDatasets()) { if (hasRoleAccess(authorities, ClaimUtils.getDatasetClaim(dataset.getCode()), logger)) { logger.LogUserAction("Added dataset: " + dataset.getCode()); userPathologyDatasets.add(dataset); -- GitLab From ac6d020311bc10019f4da385e187121fe33b4ce3 Mon Sep 17 00:00:00 2001 From: kfilippopolitis <kostasfilippop@gmail.com> Date: Wed, 16 Nov 2022 19:06:49 +0200 Subject: [PATCH 2/2] Now the dataset enumeration will be updated even if it not present in the first level variables. --- .../hbp/mip/controllers/PathologiesAPI.java | 12 ++++++- .../mip/models/DTOs/MetadataHierarchyDTO.java | 33 +++++++++++++++++++ .../eu/hbp/mip/models/DTOs/PathologyDTO.java | 7 ++-- .../hbp/mip/services/ExperimentService.java | 6 ++-- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/hbp/mip/controllers/PathologiesAPI.java b/src/main/java/eu/hbp/mip/controllers/PathologiesAPI.java index e6a2de685..8949e9c5d 100644 --- a/src/main/java/eu/hbp/mip/controllers/PathologiesAPI.java +++ b/src/main/java/eu/hbp/mip/controllers/PathologiesAPI.java @@ -7,6 +7,7 @@ import eu.hbp.mip.models.DTOs.MetadataHierarchyDTO; import eu.hbp.mip.models.DTOs.PathologyDTO; import eu.hbp.mip.services.ActiveUserService; import eu.hbp.mip.utils.*; +import eu.hbp.mip.utils.Exceptions.InternalServerError; import io.swagger.annotations.Api; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; @@ -53,7 +54,16 @@ public class PathologiesAPI { List<PathologyDTO> pathologyDTOS = new ArrayList<>(); for (String pathology : mipEnginePathologyAttributes.keySet()) { - pathologyDTOS.add(new PathologyDTO(pathology, mipEnginePathologyAttributes.get(pathology), datasetsPerPathology.get(pathology))); + PathologyDTO newPathology; + try { + newPathology = new PathologyDTO(pathology, mipEnginePathologyAttributes.get(pathology), datasetsPerPathology.get(pathology)); + } + catch(InternalServerError e) { + logger.LogUserAction(e.getMessage()); + continue; + } + + pathologyDTOS.add(newPathology); } // If authentication is disabled return everything diff --git a/src/main/java/eu/hbp/mip/models/DTOs/MetadataHierarchyDTO.java b/src/main/java/eu/hbp/mip/models/DTOs/MetadataHierarchyDTO.java index 200523a91..fbfd8bd34 100644 --- a/src/main/java/eu/hbp/mip/models/DTOs/MetadataHierarchyDTO.java +++ b/src/main/java/eu/hbp/mip/models/DTOs/MetadataHierarchyDTO.java @@ -95,4 +95,37 @@ public class MetadataHierarchyDTO { } this.groups = updated_groups; } + + public boolean isDatasetCDEPresent(){ + if (this.variables != null) { + for (CommonDataElement variable : this.variables) { + if (variable.code.equals("dataset")){ + return true; + } + } + + } + if (this.groups != null) { + for (MetadataHierarchyDTO group: this.groups){ + if (group.isDatasetCDEPresent()){ + return true; + } + } + } + return false; + } + + public void updateDatasetCde(List<PathologyDTO.EnumerationDTO> pathologyDatasetDTOS){ + if (this.variables != null) { + List<MetadataHierarchyDTO.CommonDataElement> variables = this.variables; + variables.stream().filter(cde -> cde.getCode().equals("dataset")). + findAny().ifPresent(cde -> cde.setEnumerations(pathologyDatasetDTOS)); + } + + if (this.groups != null) { + for (MetadataHierarchyDTO group: this.groups){ + group.updateDatasetCde(pathologyDatasetDTOS); + } + } + } } diff --git a/src/main/java/eu/hbp/mip/models/DTOs/PathologyDTO.java b/src/main/java/eu/hbp/mip/models/DTOs/PathologyDTO.java index e47a27a9f..de85a0fa2 100644 --- a/src/main/java/eu/hbp/mip/models/DTOs/PathologyDTO.java +++ b/src/main/java/eu/hbp/mip/models/DTOs/PathologyDTO.java @@ -1,6 +1,7 @@ package eu.hbp.mip.models.DTOs; import com.google.gson.annotations.SerializedName; +import eu.hbp.mip.utils.Exceptions.InternalServerError; import lombok.AllArgsConstructor; import lombok.Data; @@ -34,10 +35,8 @@ public class PathologyDTO { public PathologyDTO(String pathology, MIPEngineAttributesDTO mipEngineAttributesDTO, List<EnumerationDTO> pathologyDatasetDTOS) { MetadataHierarchyDTO metadataHierarchyDTO = mipEngineAttributesDTO.getProperties().get("cdes").get(0); - List<MetadataHierarchyDTO.CommonDataElement> variables = metadataHierarchyDTO.getVariables(); - variables.stream().filter(cde -> cde.getCode().equals("dataset")). - findAny().ifPresent(cde -> cde.setEnumerations(pathologyDatasetDTOS)); - metadataHierarchyDTO.setVariables(variables); + if (!metadataHierarchyDTO.isDatasetCDEPresent()) throw new InternalServerError("CommonDataElement Dataset was not present in the pathology:" + pathology); + metadataHierarchyDTO.updateDatasetCde(pathologyDatasetDTOS); List<String> pathology_info = Arrays.asList(pathology.split(":", 2)); this.code = pathology_info.get(0); diff --git a/src/main/java/eu/hbp/mip/services/ExperimentService.java b/src/main/java/eu/hbp/mip/services/ExperimentService.java index de27f46fe..a1c16a546 100644 --- a/src/main/java/eu/hbp/mip/services/ExperimentService.java +++ b/src/main/java/eu/hbp/mip/services/ExperimentService.java @@ -152,7 +152,7 @@ public class ExperimentService { //Checking if check (POST) /experiments has proper input. checkPostExperimentProperInput(experimentDTO, logger); - // Get the type and name of algorithm + // Get the type of algorithm String algorithmType = experimentDTO.getAlgorithm().getType(); if (algorithmType == null) { @@ -190,9 +190,11 @@ public class ExperimentService { //Checking if check (POST) /experiments has proper input. checkPostExperimentProperInput(experimentDTO, logger); - // Get the type and name of algorithm + // Get the type of algorithm String algorithmType = experimentDTO.getAlgorithm().getType(); + experimentDTO.setUuid(UUID.randomUUID()); + if (algorithmType.equals("workflow")) { logger.LogUserAction("You can not run workflow algorithms transiently."); throw new BadRequestException("You can not run workflow algorithms transiently."); -- GitLab