Search in sources :

Example 1 with KrashAuditException

use of org.asqatasun.webapp.exception.KrashAuditException in project Asqatasun by Asqatasun.

the class AuditLauncherController method preparePageAudit.

/**
     * This methods controls the validity of the form and launch an audit with
     * values populated by the user. In case of audit failure, an appropriate
     * message is displayed
     *
     * @param pageAuditSetUpCommand
     * @param contract
     * @param locale
     * @param auditScope
     * @param model
     * @return
     */
private String preparePageAudit(final AuditSetUpCommand auditSetUpCommand, final Contract contract, final Locale locale, final ScopeEnum auditScope, Model model) {
    Audit audit;
    boolean isPageAudit = true;
    // if the form is correct, we launch the audit
    try {
        if (auditScope.equals(ScopeEnum.FILE)) {
            audit = launchUploadAudit(contract, auditSetUpCommand, locale);
            isPageAudit = false;
        } else {
            audit = launchPageAudit(contract, auditSetUpCommand, locale);
        }
    } catch (KrashAuditException kae) {
        return TgolKeyStore.OUPS_VIEW_NAME;
    }
    // page and send an email when it's ready
    if (audit == null) {
        model.addAttribute(TgolKeyStore.TESTED_URL_KEY, auditSetUpCommand.getUrlList().get(0));
        model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
        model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
        model.addAttribute(TgolKeyStore.IS_PAGE_AUDIT_KEY, isPageAudit);
        if (!getEmailSentToUserExclusionList().contains(contract.getUser().getEmail1())) {
            model.addAttribute(TgolKeyStore.IS_USER_NOTIFIED_KEY, true);
        }
        return TgolKeyStore.GREEDY_AUDIT_VIEW_NAME;
    }
    if (audit.getStatus() != AuditStatus.COMPLETED) {
        return prepareFailedAuditData(audit, model);
    }
    if (audit.getSubject() instanceof Site) {
        // in case of group of page, we display the list of audited pages
        model.addAttribute(TgolKeyStore.AUDIT_ID_KEY, audit.getId());
        model.addAttribute(TgolKeyStore.STATUS_KEY, HttpStatusCodeFamily.f2xx);
        return TgolKeyStore.PAGE_LIST_XXX_VIEW_REDIRECT_NAME;
    } else if (audit.getSubject() instanceof Page) {
        model.addAttribute(TgolKeyStore.WEBRESOURCE_ID_KEY, audit.getSubject().getId());
        return TgolKeyStore.RESULT_PAGE_VIEW_REDIRECT_NAME;
    }
    throw new LostInSpaceException(getCurrentUser());
}
Also used : Site(org.asqatasun.entity.subject.Site) Audit(org.asqatasun.entity.audit.Audit) KrashAuditException(org.asqatasun.webapp.exception.KrashAuditException) LostInSpaceException(org.asqatasun.webapp.exception.LostInSpaceException) Page(org.asqatasun.entity.subject.Page)

Aggregations

Audit (org.asqatasun.entity.audit.Audit)1 Page (org.asqatasun.entity.subject.Page)1 Site (org.asqatasun.entity.subject.Site)1 KrashAuditException (org.asqatasun.webapp.exception.KrashAuditException)1 LostInSpaceException (org.asqatasun.webapp.exception.LostInSpaceException)1