Search in sources :

Example 1 with ScopeEnum

use of org.asqatasun.entity.contract.ScopeEnum in project Asqatasun by Asqatasun.

the class ActDAO method findNumberOfActByScope.

public int findNumberOfActByScope(Contract contract, Collection<ScopeEnum> scopes) {
    StringBuilder strb = new StringBuilder();
    strb.append("SELECT count(a.id) FROM ");
    strb.append(getEntityClass().getName());
    strb.append(" a");
    strb.append(" left join a.audit au");
    strb.append(" WHERE a.contract = :contract");
    strb.append(" AND a.status = :completedStatus");
    strb.append(" AND au.status = :auditStatus");
    strb.append(" AND (");
    int index = 0;
    Iterator<ScopeEnum> iter = scopes.iterator();
    while (iter.hasNext()) {
        strb.append("a.scope.code = :auditScope");
        strb.append(index);
        iter.next();
        index++;
        if (iter.hasNext()) {
            strb.append(" OR ");
        }
    }
    strb.append(")");
    Query query = entityManager.createQuery(strb.toString());
    query.setParameter("contract", contract);
    query.setParameter("completedStatus", ActStatus.COMPLETED);
    query.setParameter("auditStatus", AuditStatus.COMPLETED);
    iter = scopes.iterator();
    index = 0;
    while (iter.hasNext()) {
        query.setParameter("auditScope" + index, iter.next());
        index++;
    }
    return ((Long) query.getSingleResult()).intValue();
}
Also used : ScopeEnum(org.asqatasun.entity.contract.ScopeEnum) Query(javax.persistence.Query)

Example 2 with ScopeEnum

use of org.asqatasun.entity.contract.ScopeEnum in project Asqatasun by Asqatasun.

the class AuditLauncherController method launchAudit.

/**
 * This methods enables an authenticated user to launch an audit.
 *
 * @param auditSetUpCommand
 * @param locale
 * @param model
 * @return
 */
public String launchAudit(final AuditSetUpCommand auditSetUpCommand, final Locale locale, Model model) {
    Contract contract = contractDataService.read(auditSetUpCommand.getContractId());
    if (isContractExpired(contract)) {
        return displayContractView(contract, model);
    } else {
        // before launching the audit, we check whether any restriction on the
        // contract forbids it.
        ScopeEnum scope = auditSetUpCommand.getScope();
        String checkResult = restrictionHandler.checkRestriction(contract, getClientIpAddress(), scope);
        if (!checkResult.equalsIgnoreCase(TgolKeyStore.ACT_ALLOWED)) {
            return checkResult;
        }
        if (scope.equals(ScopeEnum.PAGE) || scope.equals(ScopeEnum.FILE)) {
            return preparePageAudit(auditSetUpCommand, contract, locale, scope, model);
        }
        String url = contractDataService.getUrlFromContractOption(contract);
        if (scope.equals(ScopeEnum.DOMAIN)) {
            asqatasunOrchestrator.auditSite(contract, url, getClientIpAddress(), getUserParamSet(auditSetUpCommand, contract.getId(), -1, url), locale);
            model.addAttribute(TgolKeyStore.TESTED_URL_KEY, url);
        } else if (scope.equals(ScopeEnum.SCENARIO)) {
            asqatasunOrchestrator.auditScenario(contract, auditSetUpCommand.getScenarioId(), getClientIpAddress(), getUserParamSet(auditSetUpCommand, contract.getId(), -1, url), locale);
            model.addAttribute(TgolKeyStore.SCENARIO_NAME_KEY, auditSetUpCommand.getScenarioName());
            model.addAttribute(TgolKeyStore.SCENARIO_ID_KEY, auditSetUpCommand.getScenarioId());
        }
        model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
        model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
        return TgolKeyStore.AUDIT_IN_PROGRESS_VIEW_NAME;
    }
}
Also used : ScopeEnum(org.asqatasun.entity.contract.ScopeEnum) Contract(org.asqatasun.entity.contract.Contract)

Example 3 with ScopeEnum

use of org.asqatasun.entity.contract.ScopeEnum in project Asqatasun by Asqatasun.

the class AuditResultController method displaySourceCodeFromContract.

/**
 * @param webresourceId
 * @param request
 * @param response
 * @param model
 * @return
 */
@RequestMapping(value = TgolKeyStore.SOURCE_CODE_CONTRACT_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String displaySourceCodeFromContract(@RequestParam(TgolKeyStore.WEBRESOURCE_ID_KEY) String webresourceId, HttpServletRequest request, HttpServletResponse response, Model model) {
    WebResource webResource;
    try {
        webResource = webResourceDataService.ligthRead(Long.valueOf(webresourceId));
    } catch (NumberFormatException nfe) {
        throw new ForbiddenPageException();
    }
    if (webResource instanceof Site) {
        throw new ForbiddenPageException();
    }
    Audit audit = getAuditFromWebResource(webResource);
    if (isUserAllowedToDisplayResult(audit)) {
        Page page = (Page) webResource;
        SSP ssp = contentDataService.findSSP(page, page.getURL());
        model.addAttribute(TgolKeyStore.SOURCE_CODE_KEY, highlightSourceCode(ssp));
        ScopeEnum scope = actDataService.getActFromAudit(audit).getScope().getCode();
        if (scope.equals(ScopeEnum.GROUPOFPAGES) || scope.equals(ScopeEnum.PAGE)) {
            model.addAttribute(TgolKeyStore.IS_GENERATED_HTML_KEY, true);
        }
        return TgolKeyStore.SOURCE_CODE_PAGE_VIEW_NAME;
    } else {
        throw new ForbiddenUserException(getCurrentUser());
    }
}
Also used : Site(org.asqatasun.entity.subject.Site) Audit(org.asqatasun.entity.audit.Audit) SSP(org.asqatasun.entity.audit.SSP) ScopeEnum(org.asqatasun.entity.contract.ScopeEnum) WebResource(org.asqatasun.entity.subject.WebResource) Page(org.asqatasun.entity.subject.Page) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ScopeEnum

use of org.asqatasun.entity.contract.ScopeEnum in project Asqatasun by Asqatasun.

the class AuditSetUpCommandFactory method extractAndSetLevelValueFromAuditSetUpFormFieldList.

/**
 * The way to set and retrieve the referential and the level is always the
 * same, regardless the auditType.
 *
 * @return
 */
private boolean extractAndSetLevelValueFromAuditSetUpFormFieldList(Contract contract, List<SelectFormField> levelFormFieldList, AuditSetUpCommand auditSetUpCommand) {
    // We retrieve the default value of the Parameter associated
    // with the level ParameterElement
    String defaultValue = parameterDataService.getDefaultLevelParameter().getValue();
    LOGGER.debug("default level value " + defaultValue);
    ScopeEnum scope = auditSetUpCommand.getScope();
    boolean isDefaultValue = true;
    if (scope == ScopeEnum.DOMAIN || scope == ScopeEnum.SCENARIO) {
        String lastUserValue = retrieveParameterValueFromLastAudit(contract, getLevelParameterElement(), auditSetUpCommand);
        LOGGER.debug("lastUserValue " + lastUserValue);
        if (lastUserValue != null && !StringUtils.equals(lastUserValue, defaultValue)) {
            // we override the auditParameter with the last user value
            defaultValue = lastUserValue;
            // If the level is overidden from the parameters of the last audit,
            // we need to update the UI elements regarding this value (set this
            // element as default)
            auditSetUpFormFieldHelper.selectDefaultLevelFromLevelValue(levelFormFieldList, defaultValue);
            isDefaultValue = false;
        }
    }
    auditSetUpCommand.setLevel(defaultValue);
    return isDefaultValue;
}
Also used : ScopeEnum(org.asqatasun.entity.contract.ScopeEnum)

Example 5 with ScopeEnum

use of org.asqatasun.entity.contract.ScopeEnum in project Asqatasun by Asqatasun.

the class AbstractAuditSetUpController method displayFormWithErrors.

/**
 * @param model
 * @param contract
 * @param auditSetUpCommand
 * @param authorisedReferentialList
 * @param parametersMap
 * @return
 */
private String displayFormWithErrors(Model model, Contract contract, AuditSetUpCommand auditSetUpCommand, Collection<String> authorisedReferentialList, Map<String, List<AuditSetUpFormField>> parametersMap) {
    model.addAttribute(TgolKeyStore.EXPANDED_KEY, TgolKeyStore.EXPANDED_VALUE);
    model.addAttribute(TgolKeyStore.AUDIT_SET_UP_COMMAND_KEY, auditSetUpCommand);
    model.addAttribute(TgolKeyStore.PARAMETERS_MAP_KEY, parametersMap);
    // Get a fresh list of the auditSetUpFormField that handles the choice
    // of the referential and its level
    List<SelectFormField> refAndLevelFormFieldList = this.getFreshRefAndLevelSetUpFormFieldList(authorisedReferentialList, referentialAndLevelFormFieldBuilderList);
    // Otherwise it corresponds to the default behaviour;
    // The selection of default level is delegated to the helper.
    // When the form is on error, the default level value corresponds to the
    // one the user has chosen.
    auditSetUpFormFieldHelper.selectDefaultLevelFromLevelValue(refAndLevelFormFieldList, auditSetUpCommand.getLevel());
    model.addAttribute(TgolKeyStore.LEVEL_LIST_KEY, refAndLevelFormFieldList);
    // if the user is authenticated, the url of the form is under
    // /home/contract/. To display error pages, we need to precise the
    // backward relative path and to add the breadCrumb.
    model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
    ScopeEnum auditScope = auditSetUpCommand.getScope();
    switch(auditScope) {
        case DOMAIN:
            return TgolKeyStore.AUDIT_SITE_SET_UP_VIEW_NAME;
        case PAGE:
            return TgolKeyStore.AUDIT_PAGE_SET_UP_VIEW_NAME;
        case FILE:
            return TgolKeyStore.AUDIT_UPLOAD_SET_UP_VIEW_NAME;
    }
    return TgolKeyStore.OUPS_VIEW_NAME;
}
Also used : ScopeEnum(org.asqatasun.entity.contract.ScopeEnum) SelectFormField(org.asqatasun.webapp.ui.form.SelectFormField)

Aggregations

ScopeEnum (org.asqatasun.entity.contract.ScopeEnum)5 Query (javax.persistence.Query)1 Audit (org.asqatasun.entity.audit.Audit)1 SSP (org.asqatasun.entity.audit.SSP)1 Contract (org.asqatasun.entity.contract.Contract)1 Page (org.asqatasun.entity.subject.Page)1 Site (org.asqatasun.entity.subject.Site)1 WebResource (org.asqatasun.entity.subject.WebResource)1 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)1 ForbiddenUserException (org.asqatasun.webapp.exception.ForbiddenUserException)1 SelectFormField (org.asqatasun.webapp.ui.form.SelectFormField)1 Secured (org.springframework.security.access.annotation.Secured)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1