Search in sources :

Example 1 with HttpStatusCodeFamily

use of org.asqatasun.webapp.util.HttpStatusCodeFamily in project Asqatasun by Asqatasun.

the class PageListController method pageLinkDispatcher.

/**
 * This method dispatches the result depending on the parameters passed to
 * the request. Only multi-pages audit are considered here.
 *
 * @param request
 * @param model
 * @return
 * @throws Exception
 */
private String pageLinkDispatcher(HttpServletRequest request, Audit audit, Model model) throws Exception {
    if (audit.getSubject() instanceof Page) {
        throw new ForbiddenPageException();
    }
    String status = ServletRequestUtils.getStringParameter(request, STATUS_KEY);
    HttpStatusCodeFamily httpStatusCode = getHttpStatusCodeFamily(status);
    // the repartion of the pages regarding the httpStatusCode
    if (httpStatusCode == null) {
        if (!isAuthorizedScopeForPageList(audit)) {
            throw new ForbiddenScopeException();
        }
        try {
            Contract currentContract = retrieveContractFromAudit(audit);
            model.addAttribute(CONTRACT_NAME_KEY, currentContract.getLabel());
            model.addAttribute(CONTRACT_ID_KEY, currentContract.getId());
            String testLabel = ServletRequestUtils.getStringParameter(request, TEST_KEY);
            if (StringUtils.isNotBlank(testLabel)) {
                model.addAttribute(TEST_CODE_KEY, testDataService.getTestFromAuditAndLabel(audit, testLabel));
            }
            return this.preparePageListData(audit, model);
        } catch (ServletRequestBindingException e) {
            return OUPS_VIEW_REDIRECT_NAME;
        }
    } else {
        boolean isAuthorizedScopeForPageList = isAuthorizedScopeForPageList(audit);
        Contract currentContract = retrieveContractFromAudit(audit);
        model.addAttribute(CONTRACT_NAME_KEY, currentContract.getLabel());
        model.addAttribute(CONTRACT_ID_KEY, currentContract.getId());
        // used in the jsp
        if (!isAuthorizedScopeForPageList) {
            model.addAttribute(AUDIT_NUMBER_KEY, true);
        }
        String testLabel = ServletRequestUtils.getStringParameter(request, TEST_KEY);
        if (StringUtils.isNotBlank(testLabel)) {
            model.addAttribute(TEST_CODE_KEY, testDataService.getTestFromAuditAndLabel(audit, testLabel));
        }
        return this.preparePageListStatsByHttpStatusCode(audit, model, httpStatusCode, request, false);
    }
}
Also used : ServletRequestBindingException(org.springframework.web.bind.ServletRequestBindingException) HttpStatusCodeFamily(org.asqatasun.webapp.util.HttpStatusCodeFamily) Page(org.asqatasun.entity.subject.Page) ForbiddenScopeException(org.asqatasun.webapp.exception.ForbiddenScopeException) Contract(org.asqatasun.entity.contract.Contract) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Aggregations

Contract (org.asqatasun.entity.contract.Contract)1 Page (org.asqatasun.entity.subject.Page)1 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)1 ForbiddenScopeException (org.asqatasun.webapp.exception.ForbiddenScopeException)1 HttpStatusCodeFamily (org.asqatasun.webapp.util.HttpStatusCodeFamily)1 ServletRequestBindingException (org.springframework.web.bind.ServletRequestBindingException)1