Skip to content

Commit

Permalink
Merge pull request #100 from PDCMFinder/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mauroz77 authored Nov 6, 2023
2 parents fbd3037 + 3d39675 commit 03b8e04
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ public class ModelSummary {
private String treatmentList;
private String modelTreatmentList;
private String scores;
private Boolean paediatric;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.cancermodels.pdcm_admin.persistance;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;

import javax.persistence.*;
import java.time.LocalDateTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

public interface ReleaseRepository extends JpaRepository<Release, Long>,
JpaSpecificationExecutor<Release> {
List<Release> findAllByOrderByDateDesc();
Optional<Release> findById(long id);
Optional<Release> findByNameAndDate(String name, LocalDateTime dateTime);
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ public class SearchIndex {
private String treatmentList;
private String modelTreatmentList;
private String scores;
private Boolean paediatric;
}
1 change: 1 addition & 0 deletions data-model/src/main/resources/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ CREATE TABLE admin_app.model_summary (
treatment_list TEXT,
model_treatment_list TEXT,
scores TEXT,
paediatric BOOLEAN,
release_id INTEGER NOT NULL
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ public ReleaseAnalysisController(ReleaseAnalyserService releaseAnalyserService)
}

/**
* List all releases that have been executed in the ETL
* List all releases that have been executed in the ETL. They are returned sorted by date
* (desc)
* @return List of {@link Release} objects.
*/
@GetMapping("")
public List<Release> listAllReleases()
public List<Release> listAllReleasesSortedByDate()
{
return releaseAnalyserService.getAllReleases();
return releaseAnalyserService.getAllReleasesSortedByDate();
}

/**
Expand Down Expand Up @@ -64,19 +65,34 @@ public ResponseEntity<?> getModelsByRelease(@PathVariable Long releaseId, Pageab
public List<Facet> getFiltersForModels(@PathVariable Long releaseId) {
return releaseAnalyserService.getFacetsForModels(releaseId);
}


/**
* Retrieves a list of models based on the provided parameters for a specific release.
*
* @param releaseId The ID of the release for which models should be retrieved.
* @param pageable The pageable information for controlling the pagination of the results.
* @param viewName The name of the view to be used for filtering the models (default is "allModels").
* Possible values:
* - "allModels": All models in the release
* - "paediatricModels": Paediatric models in the release
* @param modelTypes A list of model types to filter the models (optional).
* @return A ResponseEntity containing a list of models that match the given criteria.
*/
@GetMapping("models/search/{releaseId}")
public ResponseEntity<?> search(
@PathVariable Long releaseId,
Pageable pageable,
@RequestParam(value = "model_type", required = false) List<String> modelTypes) {
@RequestParam(
value = "viewName", required = false, defaultValue = "allModels") String viewName,
@RequestParam(
value = "modelType", required = false) List<String> modelTypes) {

ModelSummaryFilter filter = ModelSummaryFilterBuilder.getInstance()
.withModelType(modelTypes)
.withReleaseId(Collections.singletonList(String.valueOf(releaseId)))
.build();

Page<ModelSummary> models = releaseAnalyserService.search(pageable, filter);
Page<ModelSummary> models = releaseAnalyserService.search(viewName, pageable, filter);
return ResponseEntity.ok(models);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public ReleaseAnalyserService(
this.searchIndexRepository = searchIndexRepository;
}

public List<Release> getAllReleases() {
return releaseService.getAllReleases();
public List<Release> getAllReleasesSortedByDate() {
return releaseService.getAllReleasesSortedByDate();
}

/**
Expand Down Expand Up @@ -149,7 +149,8 @@ public List<Facet> getFacetsForModels(long releaseId) {
return modelSummaryService.getFacetsForModels(release);
}

public Page<ModelSummary> search(Pageable pageable, ModelSummaryFilter modelSummaryFilter) {
return modelSummaryService.search(pageable, modelSummaryFilter);
public Page<ModelSummary> search(
String viewName, Pageable pageable, ModelSummaryFilter modelSummaryFilter) {
return modelSummaryService.search(viewName, pageable, modelSummaryFilter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public Release getReleaseByIdOrFail(long id) {
return releaseOpt.get();
}

public List<Release> getAllReleases() {
return releaseRepository.findAll();
public List<Release> getAllReleasesSortedByDate() {
return releaseRepository.findAllByOrderByDateDesc();
}

public Release save(Release release) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,31 @@ public ModelSummaryQueryService(ModelSummaryRepository modelSummaryRepository) {
this.modelSummaryRepository = modelSummaryRepository;
}

public Page<ModelSummary> search(Pageable pageable, ModelSummaryFilter modelSummaryFilter) {
Specification<ModelSummary> specs = buildSpecifications(modelSummaryFilter);
/**
* Searches for ModelSummary entities based on the provided view name, pagination settings, and filtering criteria.
*
* @param viewName An identifier to decide what data to show (not a real view in the db).
* - "allModels": All models in the release
* - "paediatricModels": Paediatric models in the release
* @param pageable Pageable object containing pagination settings (page number, page size, sort order).
* @param modelSummaryFilter Filter criteria to apply to the search query.
* @return A Page of ModelSummary entities that match the specified criteria.
*/
public Page<ModelSummary> search(String viewName, Pageable pageable, ModelSummaryFilter modelSummaryFilter) {
Specification<ModelSummary> specs = buildSpecifications(viewName, modelSummaryFilter);
return modelSummaryRepository.findAll(specs, pageable);
}

private Specification<ModelSummary> buildSpecifications(ModelSummaryFilter modelSummaryFilter) {
return Specification.where(
private Specification<ModelSummary> buildSpecifications(String viewName, ModelSummaryFilter modelSummaryFilter) {
Specification<ModelSummary> specification;
specification = Specification.where(
ModelSummarySpecs.withModelType(modelSummaryFilter.getModelTypes()).and(
ModelSummarySpecs.withReleaseId(modelSummaryFilter.getReleaseIds())
)
);
if ("paediatricModels".equals(viewName)) {
specification = specification.and(ModelSummarySpecs.paediatricModels());
}
return specification;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public Page<ModelSummary> findByReleaseId(Long releaseId, Pageable pageable) {
return modelSummaryRepository.findByReleaseId(releaseId, pageable);
}

public Page<ModelSummary> search(Pageable pageable, ModelSummaryFilter modelSummaryFilter) {
return modelSummaryQueryService.search(pageable, modelSummaryFilter);
public Page<ModelSummary> search(
String viewName, Pageable pageable, ModelSummaryFilter modelSummaryFilter) {
return modelSummaryQueryService.search(viewName, pageable, modelSummaryFilter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.stereotype.Component;

import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -15,16 +17,33 @@
*/
@Component
public class ModelSummarySpecs {

public static Specification<ModelSummary> allModels()
{
return Specification.where(null);
}

public static Specification<ModelSummary> paediatricModels() {
Specification.where(null);
Specification<ModelSummary> specification;
specification = (root, query, criteriaBuilder) -> {
Path<String> paediatricPath = root.get(ModelSummary_.PAEDIATRIC);
query.distinct(true);
return criteriaBuilder.equal(paediatricPath, true);
};

return specification;
}
public static Specification<ModelSummary> withModelType(List<String> modelType)
{
Specification<ModelSummary> specification = Specification.where(null);
if (modelType != null)
{
specification = (Specification<ModelSummary>) (root, query, criteriaBuilder) -> {
Path<String> statusPath = root.get(ModelSummary_.MODEL_TYPE);
specification = (root, query, criteriaBuilder) -> {
Path<String> modelTypePath = root.get(ModelSummary_.MODEL_TYPE);
query.distinct(true);
return PredicateBuilder.addLowerInPredicates(
criteriaBuilder, statusPath, modelType);
criteriaBuilder, modelTypePath, modelType);
};
}
return specification;
Expand Down

0 comments on commit 03b8e04

Please sign in to comment.