Example usage for org.springframework.ui Model asMap

List of usage examples for org.springframework.ui Model asMap

Introduction

In this page you can find the example usage for org.springframework.ui Model asMap.

Prototype

Map<String, Object> asMap();

Source Link

Document

Return the current set of model attributes as a Map.

Usage

From source file:net.longfalcon.web.InstallController.java

@RequestMapping(value = "/install", method = RequestMethod.GET)
public String startInstallProcess(Model model) {

    // check if site is already configured
    if (userDAO.countUsers() > 0) {
        if (!config.getDefaultSite().getNzbPath().equals("/your/path/to/nzbs/")) {
            model.asMap().clear();
            return "redirect:/";
        }//from  w ww.j a v a 2 s. com
        model.asMap().clear();
        return "redirect:/install2";
    }

    String title = INSTALL_STEP_1_TITLE;
    UserRegistrationVO registerForm = new UserRegistrationVO();

    model.addAttribute("title", title);
    model.addAttribute("registerForm", registerForm);
    return "install";
}

From source file:net.longfalcon.web.InstallController.java

@RequestMapping(value = "/install2", method = RequestMethod.POST)
public String installStepTwo(@ModelAttribute("installerForm") InstallerVO installerForm, Model model) {

    String nzbFileLocation = installerForm.getNzbFileLocation();
    Set<String> errorSet = new HashSet<>();

    File file = new File(nzbFileLocation);
    if (file.exists()) {
        if (!file.canRead() || !file.canWrite()) {
            errorSet.add(String.format("Location %s is not readable and/or writeable.", nzbFileLocation));
        }/*from  w  ww .  jav a 2  s . c  om*/
        if (!file.isDirectory()) {
            errorSet.add(String.format("Location %s is not a directory.", nzbFileLocation));
        }
    } else {
        errorSet.add(String.format("Location %s does not exist.", nzbFileLocation));
    }

    if (errorSet.size() > 0) {
        model.addAttribute("title", INSTALL_STEP_2_TITLE);
        model.addAttribute("nzbPath", nzbFileLocation);
        model.addAttribute("installerForm", installerForm);
        model.addAttribute("errorSet", errorSet);
        return "install2";
    }

    try {
        installerService.initializeNzbStorage(nzbFileLocation);
    } catch (Exception e) {
        _log.error(e, e);
        errorSet.add(e.toString());
        model.addAttribute("title", INSTALL_STEP_2_TITLE);
        model.addAttribute("nzbPath", nzbFileLocation);
        model.addAttribute("installerForm", installerForm);
        model.addAttribute("errorSet", errorSet);
        return "install2";
    }

    model.asMap().clear();
    return "redirect:/";
}

From source file:net.longfalcon.web.LoginController.java

@RequestMapping(method = RequestMethod.POST)
public String loginPost(@ModelAttribute("loginVO") LoginVO loginVO, HttpServletRequest httpServletRequest,
        HttpSession httpSession, HttpServletResponse httpServletResponse, Model model) {
    String username = loginVO.getUsername();
    String password = loginVO.getPassword();
    String host = httpServletRequest.getRemoteHost();
    boolean rememberMe = loginVO.isRememberMe();
    loginVO.setPassword("");
    model.addAttribute("loginForm", loginVO);

    if (ValidatorUtil.isNull(username) || ValidatorUtil.isNull(password)) {
        model.addAttribute("error", "Please enter your username and password.");
        return "login";
    }/*from w  ww  . j ava 2 s  . c om*/

    User user = userDAO.findByUsername(username);

    if (user == null) {
        model.addAttribute("error", "Incorrect username or password.");
        return "login";
    }

    if (user.getRole() == UserService.ROLE_DISABLED) {
        model.addAttribute("error", "Your account has been disabled.");
        return "login";
    }

    String correctHash = user.getPassword();
    try {
        if (PasswordHash.validatePassword(password, correctHash)) {
            login(httpSession, httpServletResponse, host, rememberMe, user);
            String redirect = loginVO.getRedirect();
            if (ValidatorUtil.isNotNull(redirect)) {
                _log.error("I dont know if redirects work yet, redirect: " + redirect);
                // return "redirect:"+redirect;
            }
            model.asMap().clear();
            return "redirect:/";
        } else {
            model.addAttribute("error", "Incorrect username or password.");
        }
    } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
        _log.error(e, e);
        model.addAttribute("error", "An Unexpected error has occurred.");

    }

    return "login";
}

From source file:net.longfalcon.web.LogoutController.java

@RequestMapping("/logout")
public String logout(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
        HttpSession httpSession, Model model) {
    try {//  w w  w  .  jav a  2s. co m
        httpSession.invalidate();
        Cookie uidCookie = new Cookie("uid", "");
        uidCookie.setMaxAge(-1);
        Cookie idhCookie = new Cookie("idh", "");
        idhCookie.setMaxAge(-1);
        httpServletResponse.addCookie(uidCookie);
        httpServletResponse.addCookie(idhCookie);
    } catch (Exception e) {
        _log.error(e, e);
    }
    model.asMap().clear();
    return "redirect:/";
}

From source file:np.com.drose.studentmanagementsystem.controller.ProjectController.java

@RequestMapping(value = "/admin/project/edit/{id}", method = RequestMethod.GET)
public String editProject(@PathVariable Integer id, Model model) {
    model.addAttribute("org.springframework.validation.BindingResult.project",
            model.asMap().get("editProject"));
    try {/*from ww w  . j  ava 2  s .co  m*/

        model.addAttribute("project", new Project());
        model.addAttribute("projectObject", this.projectService.getProjectById(id));
        model.addAttribute("skill", this.teamServices.getTeamList());
        model.addAttribute("projectRes", new Project().getProjectResource().values());
        model.addAttribute("projectStat", new Project().getProjectStatus().values());

    } catch (Exception E) {
        log.info("error " + E);
    }
    return "/admin/project/project/edit";
}

From source file:org.ambraproject.wombat.controller.ArticleController.java

/**
 * Serves the peer review tab content for an article.
 *
 * @param model     data to pass to the view
 * @param site      current site/*w  w  w.  j  a v a 2 s.  c o m*/
 * @param articleId specifies the article
 * @return path to the template
 * @throws IOException
 */
@RequestMapping(name = "articlePeerReview", value = "/article/peerReview")
public String renderArticlePeerReview(HttpServletRequest request, Model model, @SiteParam Site site,
        RequestedDoiVersion articleId) throws IOException {
    articleMetadataFactory.get(site, articleId).validateVisibility("articlePeerReview").populate(request,
            model);

    throwIfPeerReviewNotFound(model.asMap());

    return site + "/ftl/article/peerReview";
}

From source file:org.ambraproject.wombat.controller.SearchController.java

private String collateCsvResults(HttpServletRequest request, Model model, Site site,
        MultiValueMap<String, String> params, Integer totalRows) throws IOException {
    StringBuilder resultsBuilder = new StringBuilder();
    for (Integer start = 0; start < totalRows; start += MAXIMUM_SOLR_RESULT_COUNT) {
        final String rows = ((Integer) Math.min(MAXIMUM_SOLR_RESULT_COUNT, totalRows - start)).toString();
        params.set("rows", rows);
        params.set("start", start.toString());
        if (!performValidSearch(request, model, site, params, true)) {
            throw new IOException("Invalid solr query. Please alter and try again.");
        }//w  w w.j a  v a  2s  . c om
        // TODO: 10/24/17 decouple search results from the model
        final Map<String, ?> searchResults = (Map<String, ?>) model.asMap().get("searchResults");
        resultsBuilder.append(searchResults.get("stringResponse"));
    }
    return resultsBuilder.toString();
}

From source file:org.asqatasun.webapp.controller.AbstractAuditResultController.java

/**
 * This method prepares the data to be displayed in the sort (referential,
 * theme, result types) console of the result page.
 *
 * @param webResourceId/*from w  ww .  j  av a  2 s .com*/
 * @param displayScope
 * @param auditResultSortCommand
 * @param model
 * @param isManualAudit
 */
private void prepareDataForSortConsole(Long webResourceId, String displayScope,
        AuditResultSortCommand auditResultSortCommand, Model model, boolean isManualAudit) {
    // Meta-statistics have been added to the method previously
    String referentialParameter = ((AuditStatistics) model.asMap().get(TgolKeyStore.STATISTICS_KEY))
            .getParametersMap().get(TgolKeyStore.REFERENTIAL_PARAM_KEY);

    AuditResultSortCommand asuc;
    List<FormField> formFieldList;
    if (auditResultSortCommand == null) {
        formFieldList = AuditResultSortCommandFactory.getInstance()
                .getFormFieldBuilderCopy(referentialParameter, sortFormFieldBuilderList);
        if (isManualAudit) {
            CheckboxFormFieldImpl ObjectList = (CheckboxFormFieldImpl) formFieldList.get(1);
            List<CheckboxElement> checkboxElementList = ObjectList.getCheckboxElementList();
            for (CheckboxElement checkboxElement : checkboxElementList) {
                if (checkboxElement.getI18nKey().equals("nt")) {
                    checkboxElement.setSelected(true);
                }
            }
        }
        asuc = AuditResultSortCommandFactory.getInstance().getInitialisedAuditResultSortCommand(webResourceId,
                displayScope, isCriterionViewAccessible(webResourceId, referentialParameter), formFieldList);
    } else {
        formFieldList = AuditResultSortCommandFactory.getInstance().getFormFieldBuilderCopy(
                referentialParameter, sortFormFieldBuilderList, auditResultSortCommand);
        asuc = auditResultSortCommand;
    }
    model.addAttribute(TgolKeyStore.AUDIT_RESULT_SORT_FIELD_LIST_KEY, formFieldList);
    model.addAttribute(TgolKeyStore.AUDIT_RESULT_SORT_COMMAND_KEY, asuc);
}

From source file:org.asqatasun.webapp.controller.AbstractAuditResultController.java

/**
 * This methods handles audit data in case of the audit is of site type
 *
 * @param site/*from ww w.  ja  v  a  2 s . com*/
 * @param audit
 * @param model
 * @return
 * @throws IOException
 */
private String prepareSuccessfullSiteData(Site site, Audit audit, Model model) {
    AuditResultSortCommand asuc = ((AuditResultSortCommand) model.asMap()
            .get(TgolKeyStore.AUDIT_RESULT_SORT_COMMAND_KEY));
    model.addAttribute(TgolKeyStore.TEST_RESULT_LIST_KEY,
            TestResultFactory.getInstance().getTestResultSortedByThemeMap(site, getSiteScope(),
                    asuc.getSortOptionMap().get(themeSortKey).toString(), getTestResultSortSelection(asuc)));

    // Attributes for breadcrumb
    Contract contract = retrieveContractFromAudit(audit);
    model.addAttribute(TgolKeyStore.AUDIT_ID_KEY, audit.getId());
    model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
    model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
    model.addAttribute(TgolKeyStore.RESULT_ACTION_LIST_KEY, actionHandler.getActionList("EXPORT"));
    return TgolKeyStore.RESULT_SITE_VIEW_NAME;
}

From source file:org.asqatasun.webapp.controller.AbstractAuditResultController.java

/**
 * This methods handles audit data in case of page type audit
 *
 * @param page//from ww w  .j a v a2 s  .c om
 * @param audit
 * @param model
 * @param displayScope
 * @param isManualAudit
 * @param manualAuditCommand
 * @return the success audit page result view name
 */
protected String prepareSuccessfullPageData(Page page, Audit audit, Model model, String displayScope,
        boolean isManualAudit, ManualAuditCommand manualAuditCommand) {

    Contract contract = retrieveContractFromAudit(audit);

    if (!audit.getStatus().equals(AuditStatus.COMPLETED)
            && !audit.getStatus().equals(AuditStatus.MANUAL_ANALYSE_IN_PROGRESS)
            && !audit.getStatus().equals(AuditStatus.MANUAL_COMPLETED)
            && !audit.getStatus().equals(AuditStatus.MANUAL_INITIALIZING)) {
        return prepareFailedAuditData(audit, model);
    }

    model.addAttribute(TgolKeyStore.STATUS_KEY, computeAuditStatus(audit));
    model.addAttribute(TgolKeyStore.RESULT_ACTION_LIST_KEY, actionHandler.getActionList("EXPORT"));
    // Attributes for breadcrumb
    model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
    model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
    model.addAttribute(TgolKeyStore.AUDIT_ID_KEY, audit.getId());

    // Add a boolean used to display the breadcrumb.
    model.addAttribute(TgolKeyStore.AUTHORIZED_SCOPE_FOR_PAGE_LIST, isAuthorizedScopeForPageList(audit));

    // Add a command to relaunch the audit from the result page
    model.addAttribute(TgolKeyStore.AUDIT_SET_UP_COMMAND_KEY,
            AuditSetUpCommandFactory.getInstance().getPageAuditSetUpCommand(contract, page.getURL(),
                    getParameterDataService().getParameterSetFromAudit(audit)));

    if (StringUtils.equalsIgnoreCase(displayScope, TgolKeyStore.TEST_DISPLAY_SCOPE_VALUE)) {
        AuditResultSortCommand asuc = ((AuditResultSortCommand) model.asMap()
                .get(TgolKeyStore.AUDIT_RESULT_SORT_COMMAND_KEY));

        model.addAttribute(TgolKeyStore.TEST_RESULT_LIST_KEY,
                TestResultFactory.getInstance().getTestResultSortedByThemeMap(page, getPageScope(),
                        asuc.getSortOptionMap().get(themeSortKey).toString(),
                        getTestResultSortSelection(asuc)));
        if (isManualAudit) {
            if (manualAuditCommand == null) {
                manualAuditCommand = new ManualAuditCommand();
            }
            manualAuditCommand.setModifedManualResultMap(TestResultFactory.getInstance().getTestResultMap(page,
                    getPageScope(), asuc.getSortOptionMap().get(themeSortKey).toString(),
                    getTestResultSortSelection(asuc)));
            model.addAttribute(TgolKeyStore.MANUAL_AUDIT_COMMAND_KEY, manualAuditCommand);
        }

        return TgolKeyStore.RESULT_PAGE_VIEW_NAME;
    } else {
        AuditResultSortCommand asuc = ((AuditResultSortCommand) model.asMap()
                .get(TgolKeyStore.AUDIT_RESULT_SORT_COMMAND_KEY));
        model.addAttribute(TgolKeyStore.CRITERION_RESULT_LIST_KEY,
                CriterionResultFactory.getInstance().getCriterionResultSortedByThemeMap(page,
                        asuc.getSortOptionMap().get(themeSortKey).toString(),
                        getTestResultSortSelection(asuc)));
        return TgolKeyStore.RESULT_PAGE_BY_CRITERION_VIEW_NAME;
    }
}