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);
}
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());
}
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;
}
}
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";
}
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";
}
}
Aggregations