diff --git a/src/main/java/eu/hbp/mip/controllers/PathologiesAPI.java b/src/main/java/eu/hbp/mip/controllers/PathologiesAPI.java index e6a2de6856ad2efc5c9b9d445ee9f720933956ea..8949e9c5d081d57ec0e4f1bc69f2882383e4efd9 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 200523a91b2fd6a821606ac3c32380c73ace214e..fbfd8bd348a92230c82d77d564528a3037b1ec32 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 e47a27a9fd0516c1b30d951e22b93eaa3ce37152..de85a0fa22bea20e9f8f2892ab0e27ecee422ae4 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 de27f46fef43aae8426668f6227549c1238bd76d..a1c16a546d20079e89887aa5f647a8518b090386 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.");