Search in sources :

Example 6 with Contract

use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.

the class ContractManagementController method editContractAdminPage.

/**
     * @param contractId
     * @param request
     * @param response
     * @param model
     * @return The pages audit set-up form page
     */
@RequestMapping(value = TgolKeyStore.EDIT_CONTRACT_URL, method = RequestMethod.GET)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String editContractAdminPage(@RequestParam(TgolKeyStore.CONTRACT_ID_KEY) String contractId, HttpServletRequest request, HttpServletResponse response, Model model) {
    Long lContractId;
    try {
        lContractId = Long.valueOf(contractId);
    } catch (NumberFormatException nfe) {
        throw new ForbiddenUserException();
    }
    Contract contract = getContractDataService().read(lContractId);
    if (contract == null) {
        throw new ForbiddenPageException();
    }
    request.getSession().setAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
    return prepateDataAndReturnCreateContractView(model, contract.getUser(), contract, ContractOptionFormFieldHelper.getFreshContractOptionFormFieldMap(getContractOptionFormFieldBuilderMap()), TgolKeyStore.EDIT_CONTRACT_VIEW_NAME);
}
Also used : ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) Contract(org.asqatasun.webapp.entity.contract.Contract) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with Contract

use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.

the class ContractSortCommandHelper method prepareContract.

/**
     * This methods retrieves and prepare contract info
     * 
     * @param user
     * @param csc the ContractSortCommand
     * @param displayOptionFieldsBuilderList
     * @param model
     * @return 
     */
public static Collection<Contract> prepareContract(User user, ContractSortCommand csc, List<FormFieldBuilder> displayOptionFieldsBuilderList, Model model) {
    csc = prepareDataForSortConsole(user.getId(), csc, displayOptionFieldsBuilderList, model);
    List<Contract> contractSet = new LinkedList();
    List<String> inclusionSortOccurence = Arrays.asList(csc.getSortOptionMap().get(inclusionContractSortKey).toString().split(";"));
    List<String> exclusionSortOccurence = Arrays.asList(csc.getSortOptionMap().get(exclusionContractSortKey).toString().split(";"));
    for (Contract contract : user.getContractSet()) {
        if (isContractLabelIncluded(inclusionSortOccurence, contract.getLabel()) && !isContractLabelExcluded(exclusionSortOccurence, contract.getLabel())) {
            contractSet.add(contract);
        }
    }
    sortContractSetRegardingCommand(contractSet, csc);
    return contractSet;
}
Also used : Contract(org.asqatasun.webapp.entity.contract.Contract)

Example 8 with Contract

use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.

the class ContractSortCommandHelper method prepareContractInfo.

/**
     * This methods retrieves and prepare contract info
     * 
     * @param user
     * @param csc the ContractSortCommand
     * @param displayOptionFieldsBuilderList
     * @param model
     * @return 
     */
public static Collection<ContractInfo> prepareContractInfo(User user, ContractSortCommand csc, List<FormFieldBuilder> displayOptionFieldsBuilderList, Model model) {
    csc = prepareDataForSortConsole(user.getId(), csc, displayOptionFieldsBuilderList, model);
    List<ContractInfo> contractInfoSet = new LinkedList();
    List<String> inclusionSortOccurence;
    if (csc.getSortOptionMap().containsKey(inclusionContractSortKey)) {
        inclusionSortOccurence = Arrays.asList(csc.getSortOptionMap().get(inclusionContractSortKey).toString().split(";"));
    } else {
        inclusionSortOccurence = new ArrayList();
    }
    List<String> exclusionSortOccurence;
    if (csc.getSortOptionMap().containsKey(exclusionContractSortKey)) {
        exclusionSortOccurence = Arrays.asList(csc.getSortOptionMap().get(exclusionContractSortKey).toString().split(";"));
    } else {
        exclusionSortOccurence = new ArrayList();
    }
    for (Contract contract : user.getContractSet()) {
        if (isContractLabelIncluded(inclusionSortOccurence, contract.getLabel()) && !isContractLabelExcluded(exclusionSortOccurence, contract.getLabel())) {
            contractInfoSet.add(ContractInfoFactory.getInstance().getContractInfo(contract));
        }
    }
    if (csc.getSortOptionMap().containsKey(sortOrderKey)) {
        sortContractInfoSetRegardingCommand(contractInfoSet, csc);
    }
    return contractInfoSet;
}
Also used : ContractInfo(org.asqatasun.webapp.presentation.data.ContractInfo) Contract(org.asqatasun.webapp.entity.contract.Contract)

Example 9 with Contract

use of org.asqatasun.webapp.entity.contract.Contract 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 = getContractDataService().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 = getContractDataService().getUrlFromContractOption(contract);
        if (scope.equals(ScopeEnum.DOMAIN)) {
            asqatasunExecutor.auditSite(contract, url, getClientIpAddress(), getUserParamSet(auditSetUpCommand, contract.getId(), -1, url), locale);
            model.addAttribute(TgolKeyStore.TESTED_URL_KEY, url);
        } else if (scope.equals(ScopeEnum.SCENARIO)) {
            asqatasunExecutor.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.webapp.entity.contract.ScopeEnum) Contract(org.asqatasun.webapp.entity.contract.Contract)

Example 10 with Contract

use of org.asqatasun.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.

the class AbstractAuditSetUpController method displayAuditSetUpView.

/**
     * 
     * @param viewName
     * @param contractId
     * @param scenarioId
     * @param optionFormFieldBuilderMap
     * @param scope
     * @param model
     * @return 
     */
protected String displayAuditSetUpView(String viewName, String contractId, String scenarioId, Map<String, List<AuditSetUpFormFieldBuilderImpl>> optionFormFieldBuilderMap, ScopeEnum scope, Model model) {
    Long contractIdValue;
    try {
        contractIdValue = Long.valueOf(contractId);
    } catch (NumberFormatException nfe) {
        throw new ForbiddenPageException(getCurrentUser());
    }
    Contract contract = getContractDataService().read(contractIdValue);
    if (isUserAllowedToDisplaySetUpPage(contract, viewName)) {
        Collection<String> authorisedReferentialList = getAuthorisedReferentialCodeFromContract(contract);
        // Get a fresh list of the auditSetUpFormField that handles the choice
        // of the referential and its level
        List<SelectFormField> refAndLevelFormFieldList = this.getFreshRefAndLevelSetUpFormFieldList(authorisedReferentialList, referentialAndLevelFormFieldBuilderList);
        String defaultRef = getDefaultReferential(authorisedReferentialList);
        AuditSetUpFormFieldHelper.selectDefaultLevelFromRefValue(refAndLevelFormFieldList, defaultRef);
        // Get a fresh map of auditSetUpFormField. The value of the field is
        // them set by Parameter mapping handled by the AuditSetUpCommandObject
        Map<String, List<AuditSetUpFormField>> optionFormFieldMap = this.getFreshAuditSetUpFormFieldMap(contract, optionFormFieldBuilderMap);
        AuditSetUpCommand asuc;
        // instance of AuditSetUpCommand
        switch(scope) {
            case DOMAIN:
                asuc = AuditSetUpCommandFactory.getInstance().getSiteAuditSetUpCommand(contract, refAndLevelFormFieldList, optionFormFieldMap);
                break;
            case FILE:
            case GROUPOFFILES:
                asuc = AuditSetUpCommandFactory.getInstance().getUploadAuditSetUpCommand(contract, refAndLevelFormFieldList, optionFormFieldMap);
                break;
            case SCENARIO:
                asuc = AuditSetUpCommandFactory.getInstance().getScenarioAuditSetUpCommand(contract, scenarioId, refAndLevelFormFieldList, optionFormFieldMap);
                break;
            case PAGE:
            case GROUPOFPAGES:
            default:
                asuc = AuditSetUpCommandFactory.getInstance().getPageAuditSetUpCommand(contract, refAndLevelFormFieldList, optionFormFieldMap);
        }
        model.addAttribute(TgolKeyStore.AUDIT_SET_UP_COMMAND_KEY, asuc);
        model.addAttribute(TgolKeyStore.DEFAULT_PARAM_SET_KEY, asuc.isDefaultParamSet());
        this.prepareFormModel(model, contract, refAndLevelFormFieldList, optionFormFieldMap);
        return viewName;
    } else {
        return TgolKeyStore.ACCESS_DENIED_VIEW_NAME;
    }
}
Also used : AuditSetUpCommand(org.asqatasun.webapp.command.AuditSetUpCommand) Contract(org.asqatasun.webapp.entity.contract.Contract) SelectFormField(org.asqatasun.webapp.form.SelectFormField) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Aggregations

Contract (org.asqatasun.webapp.entity.contract.Contract)43 Secured (org.springframework.security.access.annotation.Secured)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)17 ForbiddenUserException (org.asqatasun.webapp.exception.ForbiddenUserException)15 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)12 Audit (org.asqatasun.entity.audit.Audit)5 User (org.asqatasun.webapp.entity.user.User)5 List (java.util.List)4 Scenario (org.asqatasun.webapp.entity.scenario.Scenario)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 Site (org.asqatasun.entity.subject.Site)3 WebResource (org.asqatasun.entity.subject.WebResource)3 Functionality (org.asqatasun.webapp.entity.functionality.Functionality)3 AuditResultSortCommand (org.asqatasun.webapp.command.AuditResultSortCommand)2 AuditSetUpFormValidator (org.asqatasun.webapp.validator.AuditSetUpFormValidator)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1