Example usage for org.springframework.web.servlet ModelAndView addAllObjects

List of usage examples for org.springframework.web.servlet ModelAndView addAllObjects

Introduction

In this page you can find the example usage for org.springframework.web.servlet ModelAndView addAllObjects.

Prototype

public ModelAndView addAllObjects(@Nullable Map<String, ?> modelMap) 

Source Link

Document

Add all attributes contained in the provided Map to the model.

Usage

From source file:org.jtalks.jcommune.web.controller.UserController.java

/**
 * Register {@link org.jtalks.jcommune.model.entity.JCUser} from populated in form {@link RegisterUserDto}.
 * <p/>/*from   w  ww. j a  v  a2 s .  c  om*/
 * todo: redirect to the latest url we came from instead of root
 *
 * @param registerUserDto {@link RegisterUserDto} populated in form
 * @param request         Servlet request.
 * @param locale          to set currently selected language as user's default
 * @return redirect to / if registration successful or back to "/registration" if failed
 */
@RequestMapping(value = "/user/new", method = RequestMethod.POST)
public ModelAndView registerUser(@ModelAttribute("newUser") RegisterUserDto registerUserDto,
        HttpServletRequest request, Locale locale) {
    if (isHoneypotCaptchaFilled(registerUserDto, getClientIpAddress(request))) {
        return new ModelAndView(REG_SERVICE_HONEYPOT_FILLED_ERROR_URL);
    }
    Map<String, String> registrationPlugins = getRegistrationPluginsHtml(request, locale);
    BindingResult errors;
    try {
        registerUserDto.getUserDto().setLanguage(Language.byLocale(locale));
        errors = authenticator.register(registerUserDto);
    } catch (NoConnectionException e) {
        return new ModelAndView(REG_SERVICE_CONNECTION_ERROR_URL);
    } catch (UnexpectedErrorException e) {
        return new ModelAndView(REG_SERVICE_UNEXPECTED_ERROR_URL);
    }
    if (errors.hasErrors()) {
        ModelAndView mav = new ModelAndView(REGISTRATION);
        mav.addObject("registrationPlugins", registrationPlugins);
        mav.addAllObjects(errors.getModel());
        return mav;
    }
    return new ModelAndView(AFTER_REGISTRATION);
}

From source file:org.numiton.nwp.NumitonController.java

protected ModelAndView doFinalizeBlocks() {
    if (!StringUtils.isEmpty(getViewName())) {
        finalizeBlocks();/*ww w  . ja  v a2s.  c om*/

        ModelAndView mav = new ModelAndView();
        mav.setViewName(getViewName());
        mav.addAllObjects(__blockContents);

        return mav;
    } else {
        return null;
    }
}

From source file:org.orcid.frontend.web.controllers.ManageProfileController.java

@RequestMapping(value = { "/security-question", "/change-security-question" }, method = RequestMethod.POST)
public ModelAndView updateWithChangedSecurityQuestion(
        @ModelAttribute("changeSecurityQuestionForm") @Valid ChangeSecurityQuestionForm changeSecurityQuestionForm,
        BindingResult bindingResult) {// www  . j a  v a 2s.  com

    if (bindingResult.hasErrors()) {
        ModelAndView changeSecurityDetailsView = new ModelAndView("change_security_question");
        changeSecurityDetailsView.addAllObjects(bindingResult.getModel());
        changeSecurityDetailsView.addObject(changeSecurityQuestionForm);
        return changeSecurityDetailsView;
    }
    OrcidProfile profile = getEffectiveProfile();
    profile.setSecurityQuestionAnswer(changeSecurityQuestionForm.getSecurityQuestionAnswer());
    profile.getOrcidInternal().getSecurityDetails()
            .setSecurityQuestionId(new SecurityQuestionId(changeSecurityQuestionForm.getSecurityQuestionId()));
    orcidProfileManager.updateSecurityQuestionInformation(profile);
    ModelAndView changeSecurityDetailsView = populateChangeSecurityDetailsViewFromUserProfile(
            changeSecurityQuestionForm);
    changeSecurityDetailsView.addObject("securityQuestionSaved", true);
    return changeSecurityDetailsView;

}

From source file:org.orcid.frontend.web.controllers.ManageProfileController.java

@RequestMapping(value = "/save-bio-settings", method = RequestMethod.POST)
public ModelAndView saveEditedBio(HttpServletRequest request,
        @Valid @ModelAttribute("changePersonalInfoForm") ChangePersonalInfoForm changePersonalInfoForm,
        BindingResult bindingResult, RedirectAttributes redirectAttributes) {
    ModelAndView manageBioView = new ModelAndView("redirect:/account/manage-bio-settings");

    for (String keyword : changePersonalInfoForm.getKeywordsAsList()) {
        if (keyword.length() > ChangePersonalInfoForm.KEYWORD_MAX_LEN) {
            bindingResult.rejectValue("keywordsDelimited", "Length.changePersonalInfoForm.keywordsDelimited");
            break;
        }/*from w ww. j ava2  s  .c o m*/
    }

    if (bindingResult.hasErrors()) {
        ModelAndView erroredView = new ModelAndView("manage_bio_settings");

        // If an error happens and the user doesnt have any website,
        // the privacy selector for websites dissapears.
        // In order to fix this, if the ChangePersonalInfoForm doesnt have
        // any researcher url, we add a new one with an empty list, which
        // is different than null ResearcherUrls
        Map<String, Object> model = bindingResult.getModel();

        if (changePersonalInfoForm.getSavedResearcherUrls() == null) {
            changePersonalInfoForm.setSavedResearcherUrls(new ResearcherUrls());
        }

        model.put("changePersonalInfoForm", changePersonalInfoForm);

        erroredView.addAllObjects(bindingResult.getModel());
        return erroredView;
    }

    OrcidProfile profile = getEffectiveProfile();
    // Update profile with values that comes from user request
    changePersonalInfoForm.mergeOrcidBioDetails(profile);

    // Update profile on database
    profileEntityManager.updateProfile(profile);

    String orcid = profile.getOrcidIdentifier().getPath();

    // Update other names on database
    OtherNames otherNames = profile.getOrcidBio().getPersonalDetails().getOtherNames();
    otherNameManager.updateOtherNames(orcid, otherNames);

    // Update keywords on database
    Keywords keywords = profile.getOrcidBio().getKeywords();
    profileKeywordManager.updateProfileKeyword(orcid, keywords);

    // Update researcher urls on database
    ResearcherUrls researcherUrls = profile.getOrcidBio().getResearcherUrls();
    boolean hasErrors = researcherUrlManager.updateResearcherUrls(orcid, researcherUrls);
    // TODO: The researcherUrlManager will not store any duplicated
    // researcher url on database,
    // however there is no way to tell the controller that some of the
    // researcher urls were not
    // saved, so, if an error occurs, we need to reload researcher ids from
    // database and update
    // cached profile. A more efficient way to fix this might be used.
    if (hasErrors) {
        ResearcherUrls upToDateResearcherUrls = getUpToDateResearcherUrls(orcid,
                researcherUrls.getVisibility());
        profile.getOrcidBio().setResearcherUrls(upToDateResearcherUrls);
    }

    redirectAttributes.addFlashAttribute("changesSaved", true);
    return manageBioView;
}

From source file:org.orcid.frontend.web.controllers.RegistrationController.java

@RequestMapping(value = "/reset-password", method = RequestMethod.POST)
public ModelAndView issuePasswordResetRequest(HttpServletRequest request,
        @ModelAttribute @Valid EmailAddressForm resetPasswordForm, BindingResult bindingResult) {

    String submittedEmail = resetPasswordForm.getUserEmailAddress();

    ModelAndView mav = new ModelAndView("reset_password");

    // if the email doesn't exist, or any other form errors.. don't bother
    // hitting db
    if (bindingResult.hasErrors()) {
        mav.addAllObjects(bindingResult.getModel());
        return mav;
    }/*from  w w w . j  av a 2  s  . c  om*/

    OrcidProfile profile = orcidProfileManager.retrieveOrcidProfileByEmail(submittedEmail,
            LoadOptions.BIO_ONLY);
    // if the email can't be found on the system, then add to errors
    if (profile == null) {

        String[] codes = { "orcid.frontend.reset.password.email_not_found" };
        String[] args = { submittedEmail };
        bindingResult.addError(new FieldError("userEmailAddress", "userEmailAddress", submittedEmail, false,
                codes, args, "Email not found"));
        mav.addAllObjects(bindingResult.getModel());
        return mav;
    }

    else {
        if (profile.isDeactivated()) {
            mav.addObject("disabledAccount", true);
            return mav;
        } else {
            registrationManager.resetUserPassword(submittedEmail, profile);
            mav.addObject("passwordResetSuccessful", true);
            return mav;
        }
    }
}

From source file:org.orcid.frontend.web.controllers.RegistrationController.java

@RequestMapping(value = "/resend-claim", method = RequestMethod.POST)
public ModelAndView resendClaimEmail(HttpServletRequest request,
        @ModelAttribute @Valid EmailAddressForm emailAddressForm, BindingResult bindingResult) {
    String userEmailAddress = emailAddressForm.getUserEmailAddress();
    ModelAndView mav = new ModelAndView("resend_claim");
    // if the email doesn't exist, or any other form errors.. don't bother
    // hitting db
    if (bindingResult.hasErrors()) {
        mav.addAllObjects(bindingResult.getModel());
        return mav;
    }//from  w  ww .  j  a v  a  2 s.c  o m
    OrcidProfile profile = orcidProfileManager.retrieveOrcidProfileByEmail(userEmailAddress);
    // if the email can't be found on the system, then add to errors
    if (profile == null) {

        String[] codes = { "orcid.frontend.reset.password.email_not_found" };
        String[] args = { userEmailAddress };
        bindingResult.addError(new FieldError("userEmailAddress", "userEmailAddress", userEmailAddress, false,
                codes, args, "Email not found"));
        mav.addAllObjects(bindingResult.getModel());
        return mav;
    } else {
        if (profile.getOrcidHistory() != null && profile.getOrcidHistory().isClaimed()) {
            mav.addObject("alreadyClaimed", true);
            return mav;
        } else {
            notificationManager.sendApiRecordCreationEmail(userEmailAddress, profile);
            mav.addObject("claimResendSuccessful", true);
            return mav;
        }
    }
}

From source file:org.orcid.frontend.web.controllers.RegistrationController.java

@RequestMapping(value = "/answer-security-question/{encryptedEmail}", method = RequestMethod.POST)
public ModelAndView submitSecurityAnswer(@PathVariable("encryptedEmail") String encryptedEmail,
        @Valid ChangeSecurityQuestionForm changeSecurityQuestionForm, BindingResult bindingResult,
        RedirectAttributes redirectAttributes) {

    PasswordResetToken passwordResetToken = buildResetTokenFromEncryptedLink(encryptedEmail);
    OrcidProfile retrievedProfile = orcidProfileManager
            .retrieveOrcidProfileByEmail(passwordResetToken.getEmail(), LoadOptions.INTERNAL_ONLY);

    if (bindingResult.hasErrors()) {
        ModelAndView errorView = buildAnswerSecurityQuestionView(encryptedEmail, redirectAttributes);
        errorView.addAllObjects(bindingResult.getModel());
        return errorView;
    }// w w w  .j  a  v a2  s.c om

    String securityAnswer = retrievedProfile.getSecurityQuestionAnswer();
    if (!changeSecurityQuestionForm.getSecurityQuestionAnswer().trim()
            .equalsIgnoreCase(securityAnswer.trim())) {
        ModelAndView errorView = buildAnswerSecurityQuestionView(encryptedEmail, redirectAttributes);
        errorView.addObject("securityQuestionIncorrect", true);
        return errorView;
    }
    // build password standalone view
    return new ModelAndView("redirect:/one-time-password/" + encryptedEmail);
}

From source file:org.orcid.frontend.web.controllers.RegistrationController.java

@RequestMapping(value = "/one-time-password/{encryptedEmail}", method = RequestMethod.POST)
public ModelAndView confirmPasswordOneTimeResetView(HttpServletRequest request, HttpServletResponse response,
        @PathVariable("encryptedEmail") String encryptedEmail,
        @Valid PasswordTypeAndConfirmForm passwordTypeAndConfirmForm, BindingResult bindingResult,
        RedirectAttributes redirectAttributes) {

    PasswordResetToken passwordResetToken = buildResetTokenFromEncryptedLink(encryptedEmail);
    if (isTokenExpired(passwordResetToken)) {
        redirectAttributes.addFlashAttribute("passwordResetLinkExpired", true);
        return new ModelAndView("redirect:/reset-password");
    }/*  ww  w. j  a v a 2  s . c  o  m*/

    if (bindingResult.hasErrors()) {
        ModelAndView errorView = buildPasswordOneTimeResetView(encryptedEmail);
        errorView.addAllObjects(bindingResult.getModel());
        return errorView;
    }

    OrcidProfile passwordOnlyProfileUpdate = orcidProfileManager
            .retrieveOrcidProfileByEmail(passwordResetToken.getEmail(), LoadOptions.INTERNAL_ONLY);
    passwordOnlyProfileUpdate.setPassword(passwordTypeAndConfirmForm.getPassword() == null ? null
            : passwordTypeAndConfirmForm.getPassword().getValue());
    return updatePasswordAndGoToAccountsPage(request, response, passwordOnlyProfileUpdate);
}

From source file:org.orcid.frontend.web.controllers.RegistrationController.java

@RequestMapping(value = "/reset-password-email/{encryptedEmail}", method = RequestMethod.POST)
public ModelAndView submitPasswordReset(HttpServletRequest request, HttpServletResponse response,
        @PathVariable("encryptedEmail") String encryptedEmail,
        @Valid OneTimeResetPasswordForm oneTimeResetPasswordForm, BindingResult bindingResult,
        RedirectAttributes redirectAttributes) {

    PasswordResetToken passwordResetToken = buildResetTokenFromEncryptedLink(encryptedEmail);
    // double check link not expired - someone could send a curl request..
    if (isTokenExpired(passwordResetToken)) {
        redirectAttributes.addFlashAttribute("passwordResetLinkExpired", true);
        return new ModelAndView("redirect:/reset-password");
    }/*w  w w  . j  a v a  2 s .co m*/

    // validate the form and redirect back to the reset view
    if (bindingResult.hasErrors()) {
        ModelAndView errorView = buildPasswordScreenWithOptionalSecurityQuestion(oneTimeResetPasswordForm);
        errorView.addAllObjects(bindingResult.getModel());
        return errorView;

    }
    // update password, and optionally question and answer
    OrcidProfile profileToUpdate = orcidProfileManager
            .retrieveOrcidProfileByEmail(passwordResetToken.getEmail(), LoadOptions.INTERNAL_ONLY);
    profileToUpdate.setPassword(oneTimeResetPasswordForm.getPassword().getValue());
    if (oneTimeResetPasswordForm.isSecurityDetailsPopulated()) {
        profileToUpdate.getOrcidInternal().getSecurityDetails().setSecurityQuestionId(
                new SecurityQuestionId(oneTimeResetPasswordForm.getSecurityQuestionId()));
        profileToUpdate.setSecurityQuestionAnswer(oneTimeResetPasswordForm.getSecurityQuestionAnswer());
    }

    return updatePasswordAndGoToAccountsPage(request, response, profileToUpdate);

}

From source file:org.orcid.frontend.web.controllers.WorksUpdateController.java

/**
 * Helper for saving a work manually. Doesn't actually save the work!
 *///  ww  w  . j av a2  s  .  co  m
@RequestMapping(value = "/save-work-manually", method = RequestMethod.POST)
public ModelAndView saveWorkManually(HttpServletRequest request,
        @ModelAttribute("manualWork") @Valid CurrentWork manualWork, BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        ModelAndView mav = new ModelAndView("manual_work_form_contents");
        mav.addAllObjects(bindingResult.getModel());
        return mav;
    }
    OrcidProfile currentUser = getCurrentUser().getEffectiveProfile();
    String currentUserOrcid = currentUser.getOrcid().getValue();
    CreditName currentUserCreditName = currentUser.getOrcidBio().getPersonalDetails().getCreditName();
    List<CurrentWorkContributor> currentWorkContributors = manualWork.getCurrentWorkContributors();
    if (currentWorkContributors != null) {
        for (CurrentWorkContributor currentWorkContributor : currentWorkContributors) {
            currentWorkContributor.setOrcid(currentUserOrcid);
            if (currentUserCreditName != null) {
                currentWorkContributor.setCreditName(currentUserCreditName.getContent());
            }
        }
    }
    CurrentWorksForm currentWorksForm = new CurrentWorksForm();
    List<CurrentWork> currentWorksList = new ArrayList<CurrentWork>(1);
    currentWorksForm.setCurrentWorks(currentWorksList);
    currentWorksList.add(manualWork);
    // Just contains the added work not all works in the current list!
    ModelAndView mav = new ModelAndView("current_works_list");
    mav.addObject("showPrivacy", false);
    mav.addObject(currentWorksForm);
    return mav;
}