use of org.springframework.validation.BindingResult in project goci by EBISPOT.
the class AssociationController method addSnpInteraction.
@RequestMapping(value = "/studies/{studyId}/associations/add_interaction", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST)
public String addSnpInteraction(@ModelAttribute("form") @Valid SnpAssociationInteractionForm snpAssociationInteractionForm, BindingResult bindingResult, @PathVariable Long studyId, Model model, @RequestParam(required = true) String measurementType, HttpServletRequest request) throws EnsemblMappingException {
Study study = studyRepository.findOne(studyId);
model.addAttribute("study", study);
model.addAttribute("measurementType", measurementType);
// Binding vs Validator issue. File: messages.properties
if (bindingResult.hasErrors()) {
model.addAttribute("form", snpAssociationInteractionForm);
return "add_snp_interaction_association";
}
// Check for errors in form that would prevent saving an association
List<AssociationValidationView> colErrors = associationOperationsService.checkSnpAssociationInteractionFormErrors(snpAssociationInteractionForm, measurementType);
if (!colErrors.isEmpty()) {
model.addAttribute("errors", colErrors);
model.addAttribute("form", snpAssociationInteractionForm);
model.addAttribute("criticalErrorsFound", true);
return "add_snp_interaction_association";
} else {
// Create an association object from details in returned form
Association newAssociation = snpInteractionAssociationService.createAssociation(snpAssociationInteractionForm);
// Save and validate form
Collection<AssociationValidationView> errors = null;
String eRelease = ensemblRestTemplateService.getRelease();
try {
errors = associationOperationsService.saveAssociationCreatedFromForm(study, newAssociation, currentUserDetailsService.getUserFromRequest(request), eRelease);
} catch (EnsemblMappingException e) {
return "ensembl_mapping_failure";
}
// Determine if we have any errors rather than warnings
long errorCount = errors.stream().filter(validationError -> !validationError.getWarning()).count();
if (errorCount > 0) {
model.addAttribute("errors", errors);
model.addAttribute("form", snpAssociationInteractionForm);
model.addAttribute("criticalErrorsFound", true);
return "add_snp_interaction_association";
} else {
return "redirect:/associations/" + newAssociation.getId();
}
}
}
Aggregations