Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor project structure from Package by Layer to Package by Feature #74

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package hbp.mip.services;
package hbp.mip.algorithm;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import hbp.mip.models.DTOs.AlgorithmSpecificationDTO;
import hbp.mip.models.DTOs.exareme2.Exareme2AlgorithmSpecificationDTO;
import hbp.mip.utils.CustomResourceLoader;
import hbp.mip.utils.Exareme2AlgorithmsSpecs;
import hbp.mip.utils.HTTPUtil;
import hbp.mip.utils.Logger;
import org.springframework.beans.factory.annotation.Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,162 +1,161 @@
package hbp.mip.models.DTOs;

import hbp.mip.models.DTOs.exareme2.Exareme2AlgorithmSpecificationDTO;
import hbp.mip.utils.Exceptions.InternalServerError;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


public record AlgorithmSpecificationDTO(
String name,
String label,
String desc,
List<AlgorithmParameterSpecificationDTO> parameters,
List<TransformerSpecificationDTO> preprocessing
){
public record TransformerSpecificationDTO(String name, String label, String desc,
List<AlgorithmParameterSpecificationDTO> parameters) {
public TransformerSpecificationDTO(Exareme2AlgorithmSpecificationDTO.Exareme2TransformerSpecificationDTO transformerDTO) {
this(
transformerDTO.name(),
transformerDTO.label(),
transformerDTO.desc(),
getAlgorithmParameterSpecifications(transformerDTO.parameters())
);
}

private static List<AlgorithmParameterSpecificationDTO> getAlgorithmParameterSpecifications(
Map<String, Exareme2AlgorithmSpecificationDTO.Exareme2AlgorithmParameterSpecificationDTO> exareme2Parameters
) {
List<AlgorithmParameterSpecificationDTO> parameters = new ArrayList<>();
exareme2Parameters.forEach((name, parameterDTO)
-> parameters.add(new AlgorithmParameterSpecificationDTO(name, parameterDTO)));
return parameters;
}

}

public record AlgorithmParameterSpecificationDTO(
String name,
String label,
String desc,
String type,
String columnValuesSQLType,
String columnValuesIsCategorical,
String defaultValue,
String valueType,
String valueNotBlank,
String valueMultiple,
String valueMin,
String valueMax,
List<String> valueEnumerations
) {
public AlgorithmParameterSpecificationDTO(String name, Exareme2AlgorithmSpecificationDTO.Exareme2AlgorithmParameterSpecificationDTO parameter) {
this(
name,
parameter.label(),
parameter.desc(),
"other",
"",
"",
parameter.default_value(),
parameter.types().get(0),
parameter.notblank(),
parameter.multiple(),
parameter.min(),
parameter.max(),
parameter.enums() != null ? parameter.enums().source() : null
);
}

public AlgorithmParameterSpecificationDTO(String name, Exareme2AlgorithmSpecificationDTO.Exareme2AlgorithmInputDataDetailSpecificationDTO inputDataDetail) {
this(
name,
inputDataDetail.label(),
inputDataDetail.desc(),
getParameterType(name),
getParameterColumnValuesSQLType(name, inputDataDetail.types()),
getParameterColumnValuesIsCategorical(name, inputDataDetail.stattypes()),
"",
getParameterValueType(name, inputDataDetail.types()),
inputDataDetail.notblank(),
inputDataDetail.multiple(),
"",
"",
null
);
}

private static String getParameterType(String inputDataDetailName){
if (inputDataDetailName.equals("dataset") || inputDataDetailName.equals("filter") || inputDataDetailName.equals("pathology")) {
return inputDataDetailName;
}
return "column";
}

private static String getParameterValueType(String inputDataDetailName, List<String> types){
if (inputDataDetailName.equals("dataset") || inputDataDetailName.equals("filter") || inputDataDetailName.equals("pathology")) {
return types.get(0);
}
return "";
}

private static String getParameterColumnValuesSQLType(String inputDataDetailName, List<String> types){
if (inputDataDetailName.equals("dataset") || inputDataDetailName.equals("filter") || inputDataDetailName.equals("pathology")) {
return "";
}
return String.join(", ", types);
}

private static String getParameterColumnValuesIsCategorical(String inputDataDetailName, List<String> stattypes){
if (inputDataDetailName.equals("dataset") || inputDataDetailName.equals("filter") || inputDataDetailName.equals("pathology")) {
return "";
}

if (stattypes.contains("nominal") && stattypes.contains("numerical")) {
return "";
} else if (stattypes.contains("nominal")) {
return "true";
} else if (stattypes.contains("numerical")) {
return "false";
} else {
throw new InternalServerError("Invalid stattypes: " + stattypes);
}
}
}

public AlgorithmSpecificationDTO(Exareme2AlgorithmSpecificationDTO exareme2Algorithm){
this(
exareme2Algorithm.name(),
exareme2Algorithm.label(),
exareme2Algorithm.desc(),
getAlgorithmParameters(exareme2Algorithm),
getTransformers(exareme2Algorithm.preprocessing())
);
}

private static List<AlgorithmParameterSpecificationDTO> getAlgorithmParameters(Exareme2AlgorithmSpecificationDTO exareme2Algorithm){
List<AlgorithmParameterSpecificationDTO> parameters = new ArrayList<>();
if (exareme2Algorithm.inputdata().y() != null) {
parameters.add(new AlgorithmParameterSpecificationDTO("y", exareme2Algorithm.inputdata().y()));
}
if (exareme2Algorithm.inputdata().x() != null) {
parameters.add(new AlgorithmParameterSpecificationDTO("x", exareme2Algorithm.inputdata().x()));
}
parameters.add(new AlgorithmParameterSpecificationDTO("pathology", exareme2Algorithm.inputdata().data_model()));
parameters.add(new AlgorithmParameterSpecificationDTO("dataset", exareme2Algorithm.inputdata().datasets()));
parameters.add(new AlgorithmParameterSpecificationDTO("filter", exareme2Algorithm.inputdata().filter()));
exareme2Algorithm.parameters().forEach((name, parameterDTO)
-> parameters.add(new AlgorithmParameterSpecificationDTO(name, parameterDTO)));
return parameters;
}

private static List<TransformerSpecificationDTO> getTransformers(List<Exareme2AlgorithmSpecificationDTO.Exareme2TransformerSpecificationDTO> exareme2Transformers){
List<TransformerSpecificationDTO> preprocessing = new ArrayList<>();
exareme2Transformers.forEach(exareme2TransformerSpecificationDTO
-> preprocessing.add(new TransformerSpecificationDTO(exareme2TransformerSpecificationDTO)));
return preprocessing;
}

}
package hbp.mip.algorithm;

import hbp.mip.utils.Exceptions.InternalServerError;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


public record AlgorithmSpecificationDTO(
String name,
String label,
String desc,
List<AlgorithmParameterSpecificationDTO> parameters,
List<TransformerSpecificationDTO> preprocessing
){
public record TransformerSpecificationDTO(String name, String label, String desc,
List<AlgorithmParameterSpecificationDTO> parameters) {
public TransformerSpecificationDTO(Exareme2AlgorithmSpecificationDTO.Exareme2TransformerSpecificationDTO transformerDTO) {
this(
transformerDTO.name(),
transformerDTO.label(),
transformerDTO.desc(),
getAlgorithmParameterSpecifications(transformerDTO.parameters())
);
}

private static List<AlgorithmParameterSpecificationDTO> getAlgorithmParameterSpecifications(
Map<String, Exareme2AlgorithmSpecificationDTO.Exareme2AlgorithmParameterSpecificationDTO> exareme2Parameters
) {
List<AlgorithmParameterSpecificationDTO> parameters = new ArrayList<>();
exareme2Parameters.forEach((name, parameterDTO)
-> parameters.add(new AlgorithmParameterSpecificationDTO(name, parameterDTO)));
return parameters;
}

}

public record AlgorithmParameterSpecificationDTO(
String name,
String label,
String desc,
String type,
String columnValuesSQLType,
String columnValuesIsCategorical,
String defaultValue,
String valueType,
String valueNotBlank,
String valueMultiple,
String valueMin,
String valueMax,
List<String> valueEnumerations
) {
public AlgorithmParameterSpecificationDTO(String name, Exareme2AlgorithmSpecificationDTO.Exareme2AlgorithmParameterSpecificationDTO parameter) {
this(
name,
parameter.label(),
parameter.desc(),
"other",
"",
"",
parameter.default_value(),
parameter.types().get(0),
parameter.notblank(),
parameter.multiple(),
parameter.min(),
parameter.max(),
parameter.enums() != null ? parameter.enums().source() : null
);
}

public AlgorithmParameterSpecificationDTO(String name, Exareme2AlgorithmSpecificationDTO.Exareme2AlgorithmInputDataDetailSpecificationDTO inputDataDetail) {
this(
name,
inputDataDetail.label(),
inputDataDetail.desc(),
getParameterType(name),
getParameterColumnValuesSQLType(name, inputDataDetail.types()),
getParameterColumnValuesIsCategorical(name, inputDataDetail.stattypes()),
"",
getParameterValueType(name, inputDataDetail.types()),
inputDataDetail.notblank(),
inputDataDetail.multiple(),
"",
"",
null
);
}

private static String getParameterType(String inputDataDetailName){
if (inputDataDetailName.equals("dataset") || inputDataDetailName.equals("filter") || inputDataDetailName.equals("pathology")) {
return inputDataDetailName;
}
return "column";
}

private static String getParameterValueType(String inputDataDetailName, List<String> types){
if (inputDataDetailName.equals("dataset") || inputDataDetailName.equals("filter") || inputDataDetailName.equals("pathology")) {
return types.get(0);
}
return "";
}

private static String getParameterColumnValuesSQLType(String inputDataDetailName, List<String> types){
if (inputDataDetailName.equals("dataset") || inputDataDetailName.equals("filter") || inputDataDetailName.equals("pathology")) {
return "";
}
return String.join(", ", types);
}

private static String getParameterColumnValuesIsCategorical(String inputDataDetailName, List<String> stattypes){
if (inputDataDetailName.equals("dataset") || inputDataDetailName.equals("filter") || inputDataDetailName.equals("pathology")) {
return "";
}

if (stattypes.contains("nominal") && stattypes.contains("numerical")) {
return "";
} else if (stattypes.contains("nominal")) {
return "true";
} else if (stattypes.contains("numerical")) {
return "false";
} else {
throw new InternalServerError("Invalid stattypes: " + stattypes);
}
}
}

public AlgorithmSpecificationDTO(Exareme2AlgorithmSpecificationDTO exareme2Algorithm){
this(
exareme2Algorithm.name(),
exareme2Algorithm.label(),
exareme2Algorithm.desc(),
getAlgorithmParameters(exareme2Algorithm),
getTransformers(exareme2Algorithm.preprocessing())
);
}

private static List<AlgorithmParameterSpecificationDTO> getAlgorithmParameters(Exareme2AlgorithmSpecificationDTO exareme2Algorithm){
List<AlgorithmParameterSpecificationDTO> parameters = new ArrayList<>();
if (exareme2Algorithm.inputdata().y() != null) {
parameters.add(new AlgorithmParameterSpecificationDTO("y", exareme2Algorithm.inputdata().y()));
}
if (exareme2Algorithm.inputdata().x() != null) {
parameters.add(new AlgorithmParameterSpecificationDTO("x", exareme2Algorithm.inputdata().x()));
}
parameters.add(new AlgorithmParameterSpecificationDTO("pathology", exareme2Algorithm.inputdata().data_model()));
parameters.add(new AlgorithmParameterSpecificationDTO("dataset", exareme2Algorithm.inputdata().datasets()));
parameters.add(new AlgorithmParameterSpecificationDTO("filter", exareme2Algorithm.inputdata().filter()));
exareme2Algorithm.parameters().forEach((name, parameterDTO)
-> parameters.add(new AlgorithmParameterSpecificationDTO(name, parameterDTO)));
return parameters;
}

private static List<TransformerSpecificationDTO> getTransformers(List<Exareme2AlgorithmSpecificationDTO.Exareme2TransformerSpecificationDTO> exareme2Transformers){
List<TransformerSpecificationDTO> preprocessing = new ArrayList<>();
exareme2Transformers.forEach(exareme2TransformerSpecificationDTO
-> preprocessing.add(new TransformerSpecificationDTO(exareme2TransformerSpecificationDTO)));
return preprocessing;
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package hbp.mip.controllers;
package hbp.mip.algorithm;

import hbp.mip.models.DTOs.AlgorithmSpecificationDTO;
import hbp.mip.services.ActiveUserService;
import hbp.mip.services.AlgorithmService;
import hbp.mip.user.ActiveUserService;
import hbp.mip.utils.Logger;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hbp.mip.models.DTOs.exareme2;
package hbp.mip.algorithm;

import com.google.gson.JsonSyntaxException;
import hbp.mip.models.DTOs.ExperimentExecutionDTO;
import hbp.mip.experiment.ExperimentExecutionDTO;
import hbp.mip.utils.Exceptions.InternalServerError;
import hbp.mip.utils.JsonConverters;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hbp.mip.models.DTOs.exareme2;
package hbp.mip.algorithm;

import com.google.gson.annotations.SerializedName;

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/hbp/mip/algorithm/Exareme2AlgorithmsSpecs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package hbp.mip.algorithm;

import lombok.Getter;
import lombok.Setter;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
@Component
public class Exareme2AlgorithmsSpecs {
private List<Exareme2AlgorithmSpecificationDTO> algorithms = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package hbp.mip.controllers;
package hbp.mip.experiment;


import hbp.mip.models.DTOs.ExperimentDTO;
import hbp.mip.models.DTOs.ExperimentExecutionDTO;
import hbp.mip.models.DTOs.ExperimentsDTO;
import hbp.mip.services.ActiveUserService;
import hbp.mip.services.ExperimentService;
import hbp.mip.user.ActiveUserService;
import hbp.mip.utils.JsonConverters;
import hbp.mip.utils.Logger;
import org.springframework.http.HttpStatus;
Expand Down
Loading