Search in sources :

Example 1 with DiseaseTraitProjection

use of uk.ac.ebi.spot.goci.model.projection.DiseaseTraitProjection in project goci by EBISPOT.

the class ViewController method masterdetailPage.

@GetMapping("/disease-traits")
public String masterdetailPage(Model model) {
    List<Map<String, Object>> dataList = new ArrayList<>();
    List<DiseaseTraitProjection> projections = diseaseTraitRepository.findAllOrOrderByStudiesLargest(new PageRequest(0, 30));
    projections.forEach(x -> {
        Map<String, Object> result = new HashMap<>();
        result.put("trait", x.getTrait());
        result.put("studies", x.getStudiesCount());
        dataList.add(result);
    });
    List<Long> ids = new ArrayList<>();
    AtomicInteger count = new AtomicInteger(1);
    projections.forEach(projection -> {
        if (count.get() <= 4) {
            ids.add(projection.getId());
            count.getAndIncrement();
        }
    });
    List<DiseaseTrait> diseaseTraits = diseaseTraitRepository.findAllByIdIsIn(ids);
    List<Object> parents = new ArrayList<>();
    diseaseTraits.forEach(diseaseTrait -> {
        String trait = diseaseTrait.getTrait();
        List<Map<String, Object>> children = new ArrayList<>();
        diseaseTrait.getStudies().forEach(study -> {
            Map<String, Object> child = new HashMap<>();
            child.put("name", study.getPublicationId().getPubmedId());
            child.put(VALUE, 40);
            children.add(child);
        });
        Map<String, Object> parent = new LinkedHashMap<>();
        parent.put("name", trait + " (" + children.size() + ")");
        parent.put(VALUE, 102);
        parent.put("children", children);
        parents.add(parent);
    });
    List<Object> parents2 = new ArrayList<>();
    Map<String, Object> parenta = new LinkedHashMap<>();
    parenta.put("name", "core");
    parenta.put(VALUE, "10");
    parenta.put("children", parents);
    parents2.add(parenta);
    model.addAttribute("dataList", dataList);
    model.addAttribute("mapData", parents2);
    return "disease-traits";
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) DiseaseTraitProjection(uk.ac.ebi.spot.goci.model.projection.DiseaseTraitProjection) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 PageRequest (org.springframework.data.domain.PageRequest)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 DiseaseTrait (uk.ac.ebi.spot.goci.model.DiseaseTrait)1 DiseaseTraitProjection (uk.ac.ebi.spot.goci.model.projection.DiseaseTraitProjection)1