use of org.springframework.web.servlet.mvc.support.RedirectAttributes in project goci by EBISPOT.
the class AssociationController method validateUnapproved.
/**
- * Run mapping pipeline on all SNPs in a study
- *
- * @param studyId Study ID in database
- * @param redirectAttributes attributes for a redirect scenario
- */
@RequestMapping(value = "/studies/{studyId}/associations/validate_unapproved", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String validateUnapproved(@PathVariable Long studyId, RedirectAttributes redirectAttributes, Model model, HttpServletRequest request) throws // @RequestParam(required = false) Long associationId)
EnsemblMappingException {
Study study = studyRepository.findOne(studyId);
// For the study get all associations
Collection<Association> studyAssociations = associationRepository.findByStudyId(studyId);
for (Association associationToValidate : studyAssociations) {
if (!associationToValidate.getSnpApproved()) {
String measurementType = associationOperationsService.determineIfAssociationIsOrType(associationToValidate);
List<AssociationValidationView> criticalErrors = new ArrayList<>();
if (associationToValidate.getSnpInteraction()) {
criticalErrors = associationOperationsService.checkSnpAssociationInteractionFormErrors((SnpAssociationInteractionForm) associationOperationsService.generateForm(associationToValidate), measurementType);
} else {
criticalErrors = associationOperationsService.checkSnpAssociationFormErrors((SnpAssociationStandardMultiForm) associationOperationsService.generateForm(associationToValidate), measurementType);
}
//if an association has critical errors, go straight to that association
if (!criticalErrors.isEmpty()) {
model.addAttribute("study", study);
model.addAttribute("measurementType", measurementType);
// Get mapping details
model.addAttribute("mappingDetails", associationOperationsService.createMappingDetails(associationToValidate));
// Return any association errors
model.addAttribute("errors", criticalErrors);
model.addAttribute("criticalErrorsFound", true);
if (associationToValidate.getSnpInteraction()) {
model.addAttribute("form", associationOperationsService.generateForm(associationToValidate));
return "redirect:/associations/" + associationToValidate.getId();
// return "edit_snp_interaction_association";
} else {
model.addAttribute("form", associationOperationsService.generateForm(associationToValidate));
// Determine view
if (associationToValidate.getMultiSnpHaplotype()) {
return "redirect:/associations/" + associationToValidate.getId();
// return "edit_multi_snp_association";
} else {
// return "edit_standard_snp_association";
return "redirect:/associations/" + associationToValidate.getId();
}
}
} else // if there are no criticial errors, save the validation and go to the next association
{
// Save and validate form
String eRelease = ensemblRestTemplateService.getRelease();
Collection<AssociationValidationView> errors = associationOperationsService.validateAndSaveAssociation(study, associationToValidate, currentUserDetailsService.getUserFromRequest(request), eRelease);
// Determine if we have any errors rather than warnings
long errorCount = errors.stream().filter(validationError -> !validationError.getWarning()).count();
//if there are errors rather than warnings, go straight to the page to edit
if (errorCount > 0) {
model.addAttribute("study", study);
model.addAttribute("measurementType", measurementType);
// Get mapping details for association we're editing
model.addAttribute("mappingDetails", associationOperationsService.createMappingDetails(associationToValidate));
model.addAttribute("errors", errors);
model.addAttribute("criticalErrorsFound", true);
if (associationToValidate.getSnpInteraction()) {
model.addAttribute("form", associationOperationsService.generateForm(associationToValidate));
// return "edit_snp_interaction_association";
return "redirect:/associations/" + associationToValidate.getId();
} else {
model.addAttribute("form", associationOperationsService.generateForm(associationToValidate));
// Determine view
if (associationToValidate.getMultiSnpHaplotype()) {
// return "edit_multi_snp_association";
return "redirect:/associations/" + associationToValidate.getId();
} else {
// return "edit_standard_snp_association";
return "redirect:/associations/" + associationToValidate.getId();
}
}
}
}
}
}
String message = "Mapping complete, please check for any errors displayed in the 'Errors' column";
redirectAttributes.addFlashAttribute("mappingComplete", message);
return "redirect:/studies/" + studyId + "/associations";
}
use of org.springframework.web.servlet.mvc.support.RedirectAttributes in project ORCID-Source by ORCID.
the class PasswordResetControllerTest method testPasswordResetLinkValidLinkDirectsToConsolidatedScreenDirectlyWhenNoSecurityQuestion.
@Test
public void testPasswordResetLinkValidLinkDirectsToConsolidatedScreenDirectlyWhenNoSecurityQuestion() throws Exception {
HttpServletRequest servletRequest = mock(HttpServletRequest.class);
RedirectAttributes redirectAttributes = mock(RedirectAttributes.class);
when(encryptionManager.decryptForExternalUse(any(String.class))).thenReturn("email=any@orcid.org&issueDate=2070-05-29T17:04:27");
when(orcidProfileManager.retrieveOrcidProfileByEmail(eq("any@orcid.org"), Matchers.<LoadOptions>any())).thenReturn(new OrcidProfile());
ModelAndView modelAndView = passwordResetController.resetPasswordEmail(servletRequest, "randomString", redirectAttributes);
assertEquals("password_one_time_reset_optional_security_questions", modelAndView.getViewName());
verify(redirectAttributes, never()).addFlashAttribute("passwordResetLinkExpired", true);
}
use of org.springframework.web.servlet.mvc.support.RedirectAttributes in project alf.io by alfio-event.
the class ReservationFlowIntegrationTest method reserveTicket.
private String reserveTicket(String eventName) {
ReservationForm reservationForm = new ReservationForm();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
ServletWebRequest servletWebRequest = new ServletWebRequest(request);
BindingResult bindingResult = new BeanPropertyBindingResult(reservationForm, "reservation");
Model model = new BindingAwareModelMap();
RedirectAttributes redirectAttributes = new RedirectAttributesModelMap();
TicketReservationModification ticketReservation = new TicketReservationModification();
ticketReservation.setAmount(1);
ticketReservation.setTicketCategoryId(ticketCategoryRepository.findByEventId(event.getId()).stream().findFirst().map(TicketCategory::getId).orElseThrow(IllegalStateException::new));
reservationForm.setReservation(Collections.singletonList(ticketReservation));
return eventController.reserveTicket(eventName, reservationForm, bindingResult, model, servletWebRequest, redirectAttributes, Locale.ENGLISH);
}
use of org.springframework.web.servlet.mvc.support.RedirectAttributes in project alf.io by alfio-event.
the class ReservationFlowIntegrationTest method payOffline.
private String payOffline(String eventName, String reservationIdentifier) {
PaymentForm paymentForm = new PaymentForm();
paymentForm.setPaymentMethod(PaymentProxy.OFFLINE);
paymentForm.setEmail("test@test.com");
paymentForm.setBillingAddress("my billing address");
paymentForm.setFirstName("full");
paymentForm.setLastName("name");
paymentForm.setTermAndConditionsAccepted(true);
paymentForm.setPostponeAssignment(true);
BindingResult bindingResult = new BeanPropertyBindingResult(paymentForm, "paymentForm");
Model model = new BindingAwareModelMap();
MockHttpServletRequest request = new MockHttpServletRequest();
RedirectAttributes redirectAttributes = new RedirectAttributesModelMap();
return reservationController.handleReservation(eventName, reservationIdentifier, paymentForm, bindingResult, model, request, Locale.ENGLISH, redirectAttributes);
}
use of org.springframework.web.servlet.mvc.support.RedirectAttributes in project spring-framework by spring-projects.
the class RequestMappingHandlerAdapter method getModelAndView.
@Nullable
private ModelAndView getModelAndView(ModelAndViewContainer mavContainer, ModelFactory modelFactory, NativeWebRequest webRequest) throws Exception {
modelFactory.updateModel(webRequest, mavContainer);
if (mavContainer.isRequestHandled()) {
return null;
}
ModelMap model = mavContainer.getModel();
ModelAndView mav = new ModelAndView(mavContainer.getViewName(), model, mavContainer.getStatus());
if (!mavContainer.isViewReference()) {
mav.setView((View) mavContainer.getView());
}
if (model instanceof RedirectAttributes) {
Map<String, ?> flashAttributes = ((RedirectAttributes) model).getFlashAttributes();
HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
if (request != null) {
RequestContextUtils.getOutputFlashMap(request).putAll(flashAttributes);
}
}
return mav;
}
Aggregations