Search in sources :

Example 6 with Contract

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

the class AuditScenarioController method prepareScenarioManagementData.

/**
 * Prepare data to be displayed on the scenario management page
 *
 * @param model
 * @param contractId
 */
private void prepareScenarioManagementData(Model model, String contractId) {
    Long contractIdValue;
    try {
        contractIdValue = Long.valueOf(contractId);
    } catch (NumberFormatException nfe) {
        throw new ForbiddenPageException(getCurrentUser());
    }
    Contract contract = contractDataService.read(contractIdValue);
    if (isUserAllowedToDisplaySetUpPage(contract, TgolKeyStore.AUDIT_SCENARIO_SET_UP_VIEW_NAME)) {
        // add the AddScenarioCommand instance to the model
        model.addAttribute(TgolKeyStore.ADD_SCENARIO_COMMAND_KEY, addScenarioCommandFactory.getAddScenarioCommand(contract));
        // add the contract label to the model
        model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
        // add the list of scenario to the model
        addScenarioListToModel(contract, model);
    }
}
Also used : Contract(org.asqatasun.entity.contract.Contract) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Example 7 with Contract

use of org.asqatasun.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 = auditDataService.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, parameterDataService.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, statisticsDataService.getFailedTestByOccurrence(site, audit, -1));
            model.addAttribute(TgolKeyStore.HAS_SITE_SCOPE_TEST_KEY, processResultDataService.hasAuditSiteScopeResult(site, siteScope));
            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.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 8 with Contract

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

the class ContractManagementController method submitAddContractAdminPage.

/**
 * @param createContractCommand
 * @param result
 * @param request
 * @param response
 * @param model
 * @return The pages audit set-up form page
 */
@RequestMapping(value = TgolKeyStore.ADD_CONTRACT_FROM_CONTRACT_MNGT_URL, method = RequestMethod.POST)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String submitAddContractAdminPage(@ModelAttribute(TgolKeyStore.CREATE_CONTRACT_COMMAND_KEY) CreateContractCommand createContractCommand, BindingResult result, HttpServletRequest request, HttpServletResponse response, Model model) {
    Object userId = request.getSession().getAttribute(TgolKeyStore.USER_ID_KEY);
    Long lUserId;
    if (userId instanceof Long) {
        lUserId = (Long) userId;
    } else {
        try {
            lUserId = Long.valueOf(userId.toString());
        } catch (NumberFormatException nfe) {
            throw new ForbiddenUserException();
        }
    }
    Map<String, List<ContractOptionFormField>> optionFormFieldMap = ContractOptionFormFieldHelper.getFreshContractOptionFormFieldMap(contractOptionFormFieldBuilderMap);
    createContractFormValidator.setContractOptionFormFieldMap(optionFormFieldMap);
    // We check whether the form is valid
    createContractFormValidator.validate(createContractCommand, result);
    // If the form has some errors, we display it again with errors' details
    User currentModifiedUser = userDataService.read(lUserId);
    if (result.hasErrors()) {
        return displayFormWithErrors(model, createContractCommand, currentModifiedUser.getEmail1(), lUserId, optionFormFieldMap, TgolKeyStore.EDIT_CONTRACT_VIEW_NAME);
    }
    Contract contract = contractDataService.create();
    contract.setUser(currentModifiedUser);
    contract = createContractCommandFactory.updateContractFromCommand(createContractCommand, contract);
    saveOrUpdateContract(contract);
    request.getSession().setAttribute(TgolKeyStore.ADDED_CONTRACT_NAME_KEY, contract.getLabel());
    model.addAttribute(TgolKeyStore.USER_ID_KEY, contract.getUser().getId());
    request.getSession().removeAttribute(TgolKeyStore.USER_ID_KEY);
    return TgolKeyStore.MANAGE_CONTRACTS_VIEW_REDIRECT_NAME;
}
Also used : User(org.asqatasun.entity.user.User) List(java.util.List) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) Contract(org.asqatasun.entity.contract.Contract) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with Contract

use of org.asqatasun.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 = contractDataService.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(contractOptionFormFieldBuilderMap), TgolKeyStore.EDIT_CONTRACT_VIEW_NAME);
}
Also used : ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) Contract(org.asqatasun.entity.contract.Contract) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with Contract

use of org.asqatasun.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.getTestResultSortedByThemeMap(site, siteScope, asuc.getSortOptionMap().get(THEME_SORT_KEY).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.entity.contract.Contract)

Aggregations

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