Search in sources :

Example 16 with DiseaseTrait

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

the class DiseaseTraitController method addDiseaseTraits.

@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<DiseaseTraitDto> addDiseaseTraits(@Valid @RequestBody DiseaseTraitDto diseaseTrait1) {
    DiseaseTrait diseaseTrait = DiseaseTraitDtoAssembler.disassemble(diseaseTrait1);
    diseaseTrait = diseaseTraitService.createDiseaseTrait(diseaseTrait);
    URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(diseaseTrait1.getId()).toUri();
    diseaseTrait1.setId(diseaseTrait.getId());
    return new ResponseEntity<>(diseaseTrait1, ResponseEntity.created(location).build().getHeaders(), HttpStatus.CREATED);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) URI(java.net.URI)

Example 17 with DiseaseTrait

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

the class DiseaseTraitDocumentCache method initCache.

private void initCache() {
    System.out.println("caching disease traits...");
    List<DiseaseTrait> traits = diseaseTraitRepository.findAll();
    for (DiseaseTrait trait : traits) {
        DiseaseTraitDocument document = new DiseaseTraitDocument(trait);
        documentMap.put(trait.getTrait(), document);
    }
    System.out.println("disease traits cached: " + documentMap.size());
}
Also used : DiseaseTraitDocument(uk.ac.ebi.spot.goci.model.DiseaseTraitDocument) DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait)

Example 18 with DiseaseTrait

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

the class SolrIndexer method mapTraits.

Integer mapTraits(Collection<String> pubmedIds) {
    if (runTraits) {
        Sort sort = new Sort(new Sort.Order("trait"));
        Pageable pager = new PageRequest(0, pageSize);
        Page<DiseaseTrait> diseaseTraitPage = null;
        int totalElements = 0;
        if (!pubmedIds.isEmpty()) {
            for (String pmid : pubmedIds) {
                diseaseTraitPage = diseaseTraitRepository.findByStudiesPublicationIdPubmedId(pmid, pager);
                totalElements += _mapPagedTraits(pmid, diseaseTraitPage, pager);
            }
        } else {
            diseaseTraitPage = diseaseTraitRepository.findAll(pager);
            totalElements = _mapPagedTraits(null, diseaseTraitPage, pager);
        }
        return totalElements;
    } else {
        return 0;
    }
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) Sort(org.springframework.data.domain.Sort)

Example 19 with DiseaseTrait

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

the class OldDiseaseTraitController method viewDiseaseTrait.

// Edit disease trait
@RequestMapping(value = "/{diseaseTraitId}", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String viewDiseaseTrait(Model model, @PathVariable Long diseaseTraitId) {
    DiseaseTrait diseaseTraitToView = diseaseTraitRepository.findOne(diseaseTraitId);
    model.addAttribute("diseaseTrait", diseaseTraitToView);
    return "edit_disease_trait";
}
Also used : DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with DiseaseTrait

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

the class OldDiseaseTraitController method addDiseaseTrait.

// Add a new disease trait
@RequestMapping(produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST)
public String addDiseaseTrait(@Valid @ModelAttribute DiseaseTrait diseaseTrait, BindingResult bindingResult, Model model, RedirectAttributes redirectAttributes) {
    // Check if it exists already
    DiseaseTrait existingDiseaseTrait = diseaseTraitRepository.findByTraitIgnoreCase(diseaseTrait.getTrait());
    String existingTrait = null;
    if (existingDiseaseTrait != null) {
        existingTrait = existingDiseaseTrait.getTrait();
    }
    // Catch a null or empty value being entered
    if (bindingResult.hasErrors()) {
        model.addAttribute("diseaseTraits", diseaseTraitRepository.findAll(sortByTraitAsc()));
        return "disease_traits";
    } else if (existingTrait != null && !existingTrait.isEmpty()) {
        String message = "Trait already exists in database: database value = " + existingTrait + ", value entered = " + diseaseTrait.getTrait();
        redirectAttributes.addFlashAttribute("diseaseTraitExists", message);
        return "redirect:/diseasetraits";
    } else // Save disease trait
    {
        diseaseTraitRepository.save(diseaseTrait);
        String message = "Trait " + diseaseTrait.getTrait() + " added to database";
        redirectAttributes.addFlashAttribute("diseaseTraitSaved", message);
        return "redirect:/diseasetraits";
    }
}
Also used : DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DiseaseTrait (uk.ac.ebi.spot.goci.model.DiseaseTrait)22 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 PageRequest (org.springframework.data.domain.PageRequest)4 Pageable (org.springframework.data.domain.Pageable)4 Sort (org.springframework.data.domain.Sort)4 Study (uk.ac.ebi.spot.goci.model.Study)4 ControllerLinkBuilder (org.springframework.hateoas.mvc.ControllerLinkBuilder)2 ResponseEntity (org.springframework.http.ResponseEntity)2 DiseaseTraitDto (uk.ac.ebi.spot.goci.curation.dto.DiseaseTraitDto)2 CsvMapper (com.fasterxml.jackson.dataformat.csv.CsvMapper)1 CsvSchema (com.fasterxml.jackson.dataformat.csv.CsvSchema)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 CosineDistance (org.apache.commons.text.similarity.CosineDistance)1 LevenshteinDistance (org.apache.commons.text.similarity.LevenshteinDistance)1