Search in sources :

Example 11 with Contract

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

the class AuditSynthesisController method displayAuditTestSynthesisFromContract.

/**
     *
     * @param auditId
     * @param request
     * @param response
     * @param model
     * @return
     */
@RequestMapping(value = TgolKeyStore.FAILED_TEST_LIST_CONTRACT_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String displayAuditTestSynthesisFromContract(@RequestParam(TgolKeyStore.AUDIT_ID_KEY) String auditId, HttpServletRequest request, HttpServletResponse response, Model model) {
    Long aId;
    try {
        aId = Long.valueOf(auditId);
    } catch (NumberFormatException nfe) {
        throw new ForbiddenPageException();
    }
    Audit audit = getAuditDataService().read(aId);
    if (isUserAllowedToDisplayResult(audit)) {
        if (isAuthorizedScopeForSynthesis(audit)) {
            Contract contract = retrieveContractFromAudit(audit);
            model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
            model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
            model.addAttribute(TgolKeyStore.AUDIT_ID_KEY, auditId);
            model.addAttribute(TgolKeyStore.REFERENTIAL_CD_KEY, getParameterDataService().getReferentialKeyFromAudit(audit));
            model.addAttribute(TgolKeyStore.WEBRESOURCE_ID_KEY, audit.getSubject().getId());
            Site site = (Site) audit.getSubject();
            //TODO cas manual
            addAuditStatisticsToModel(site, model, TgolKeyStore.TEST_DISPLAY_SCOPE_VALUE);
            model.addAttribute(TgolKeyStore.FAILED_TEST_INFO_BY_OCCURRENCE_SET_KEY, getStatisticsDataService().getFailedTestByOccurrence(site, audit, -1));
            model.addAttribute(TgolKeyStore.HAS_SITE_SCOPE_TEST_KEY, processResultDataService.hasAuditSiteScopeResult(site, getSiteScope()));
            model.addAttribute(TgolKeyStore.STATUS_KEY, computeAuditStatus(site.getAudit()));
            return TgolKeyStore.FAILED_TEST_LIST_VIEW_NAME;
        } else {
            throw new ForbiddenPageException();
        }
    } else {
        throw new ForbiddenUserException();
    }
}
Also used : Site(org.asqatasun.entity.subject.Site) Audit(org.asqatasun.entity.audit.Audit) Contract(org.asqatasun.webapp.entity.contract.Contract) 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 12 with Contract

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

the class AbstractAuditResultController method prepareSuccessfullPageData.

/**
     * This methods handles audit data in case of page type audit
     *
     * @param page
     * @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;
    }
}
Also used : ManualAuditCommand(org.asqatasun.webapp.command.ManualAuditCommand) Contract(org.asqatasun.webapp.entity.contract.Contract) AuditResultSortCommand(org.asqatasun.webapp.command.AuditResultSortCommand)

Example 13 with Contract

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

the class AbstractAuditResultController method prepareSuccessfullSiteData.

/**
     * This methods handles audit data in case of the audit is of site type
     *
     * @param site
     * @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;
}
Also used : AuditResultSortCommand(org.asqatasun.webapp.command.AuditResultSortCommand) Contract(org.asqatasun.webapp.entity.contract.Contract)

Example 14 with Contract

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

the class AuditScenarioController method getScenarioFile.

@RequestMapping(value = TgolKeyStore.DOWNLOAD_SCENARIO_URL_CONTRACT_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public void getScenarioFile(@RequestParam(TgolKeyStore.CONTRACT_ID_KEY) String contractId, @RequestParam(TgolKeyStore.SCENARIO_ID_KEY) String scenarioId, HttpServletResponse response) {
    Contract contract = getContractDataService().read(Long.valueOf(contractId));
    if (contract.getUser().getId().equals(getCurrentUser().getId())) {
        try {
            for (Scenario scenario : contract.getScenarioSet()) {
                if (scenario.getId().equals(Long.valueOf(scenarioId))) {
                    InputStream is = IOUtils.toInputStream(scenario.getContent());
                    IOUtils.copy(is, response.getOutputStream());
                    response.setContentType(TgolKeyStore.CONTENT_TYPE);
                    StringBuilder strb = new StringBuilder(TgolKeyStore.ATTACHMENT);
                    strb.append(scenario.getLabel());
                    strb.append(TgolKeyStore.JSON_EXTENSION);
                    response.setHeader(TgolKeyStore.CONTENT_DISPOSITION, strb.toString());
                    response.flushBuffer();
                    break;
                }
            }
            throw new ForbiddenPageException(getCurrentUser());
        } catch (IOException ex) {
            throw new RuntimeException("IOError writing file to output stream");
        }
    } else {
        throw new ForbiddenPageException(getCurrentUser());
    }
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) Contract(org.asqatasun.webapp.entity.contract.Contract) Scenario(org.asqatasun.webapp.entity.scenario.Scenario) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with Contract

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

the class AuditScenarioController method submitForm.

@RequestMapping(value = TgolKeyStore.AUDIT_SCENARIO_SET_UP_CONTRACT_URL, method = RequestMethod.POST)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
protected String submitForm(@ModelAttribute(TgolKeyStore.ADD_SCENARIO_COMMAND_KEY) AuditSetUpCommand auditSetUpCommand, BindingResult result, Model model, HttpServletRequest request) {
    Contract contract = getContractDataService().read(auditSetUpCommand.getContractId());
    Map<String, List<AuditSetUpFormField>> formFielMap = getFreshAuditSetUpFormFieldMap(contract, getScenarioOptionFormFieldBuilderMap());
    AuditSetUpFormValidator auditSetUpFormValidator = getAuditSiteSetUpFormValidator();
    return submitForm(contract, auditSetUpCommand, formFielMap, auditSetUpFormValidator, model, result, request);
}
Also used : AuditSetUpFormValidator(org.asqatasun.webapp.validator.AuditSetUpFormValidator) Contract(org.asqatasun.webapp.entity.contract.Contract) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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