Search in sources :

Example 31 with Contract

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

the class AuditResultController method displayTestResult.

/**
 * @param webresourceId
 * @param testId
 * @param model
 * @return the test-result view name
 */
@RequestMapping(value = TgolKeyStore.TEST_RESULT_CONTRACT_URL, method = RequestMethod.GET)
public String displayTestResult(@RequestParam(TgolKeyStore.WEBRESOURCE_ID_KEY) String webresourceId, @RequestParam(TgolKeyStore.TEST_CODE_KEY) String testId, Model model) {
    Long wrId;
    Long tstId;
    try {
        wrId = Long.valueOf(webresourceId);
        tstId = Long.valueOf(testId);
    } catch (NumberFormatException nfe) {
        throw new ForbiddenUserException(getCurrentUser());
    }
    WebResource webResource = webResourceDataService.ligthRead(wrId);
    if (webResource == null) {
        throw new ForbiddenPageException();
    }
    Audit audit = getAuditFromWebResource(webResource);
    if (isUserAllowedToDisplayResult(audit)) {
        Contract contract = retrieveContractFromAudit(audit);
        // Attributes for breadcrumb
        model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
        model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
        model.addAttribute(TgolKeyStore.URL_KEY, webResource.getURL());
        Test test = testDataService.read(tstId);
        model.addAttribute(TgolKeyStore.TEST_LABEL_KEY, test.getLabel());
        model.addAttribute(TgolKeyStore.AUDIT_ID_KEY, audit.getId());
        if (!test.getScope().equals(pageScope)) {
            model.addAttribute(TgolKeyStore.SITE_SCOPE_TEST_DETAILS_KEY, true);
        } else {
            // Add a boolean used to display the breadcrumb.
            model.addAttribute(TgolKeyStore.AUTHORIZED_SCOPE_FOR_PAGE_LIST, isAuthorizedScopeForPageList(audit));
        }
        model.addAttribute(TgolKeyStore.TEST_RESULT_LIST_KEY, testResultFactory.getTestResultListFromTest(webResource, test));
        return TgolKeyStore.TEST_RESULT_VIEW_NAME;
    } else {
        throw new ForbiddenPageException();
    }
}
Also used : Audit(org.asqatasun.entity.audit.Audit) Test(org.asqatasun.entity.reference.Test) WebResource(org.asqatasun.entity.subject.WebResource) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) Contract(org.asqatasun.entity.contract.Contract) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 32 with Contract

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

the class AuditSetUpController method submitAuditSetUpForm.

/**
 * Submit in case of site audit
 * @param auditSetUpCommand
 * @param result
 * @param model
 * @param request
 * @return
 */
@RequestMapping(value = { AUDIT_PAGE_SET_UP_CONTRACT_URL, AUDIT_SITE_SET_UP_CONTRACT_URL, AUDIT_UPLOAD_SET_UP_CONTRACT_URL }, method = RequestMethod.POST)
@Secured({ ROLE_USER_KEY, ROLE_ADMIN_KEY })
public String submitAuditSetUpForm(@ModelAttribute(AUDIT_SET_UP_COMMAND_KEY) AuditSetUpCommand auditSetUpCommand, BindingResult result, Model model, HttpServletRequest request) {
    Contract contract = contractDataService.read(auditSetUpCommand.getContractId());
    Map<String, List<AuditSetUpFormField>> formFielMap = null;
    AuditSetUpFormValidator auditSetUpFormValidator = null;
    if (auditSetUpCommand.getRelaunch()) {
        return launchAudit(contract, auditSetUpCommand, model, request);
    }
    switch(auditSetUpCommand.getScope()) {
        case DOMAIN:
            formFielMap = getFreshAuditSetUpFormFieldMap(contract, siteOptionFormFieldBuilderMap);
            auditSetUpFormValidator = auditSiteSetUpFormValidator;
            break;
        case PAGE:
            formFielMap = getFreshAuditSetUpFormFieldMap(contract, pageOptionFormFieldBuilderMap);
            auditSetUpFormValidator = auditPageSetUpFormValidator;
            break;
        case FILE:
            formFielMap = getFreshAuditSetUpFormFieldMap(contract, uploadOptionFormFieldBuilderMap);
            auditSetUpFormValidator = auditUploadSetUpFormValidator;
            break;
    }
    return submitForm(contract, auditSetUpCommand, formFielMap, auditSetUpFormValidator, model, result, request);
}
Also used : AuditSetUpFormValidator(org.asqatasun.webapp.validator.AuditSetUpFormValidator) List(java.util.List) Contract(org.asqatasun.entity.contract.Contract) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with Contract

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

the class ContractController method displayContractPage.

/**
 * @param request
 * @param model
 * @param contractId
 * @return
 */
private String displayContractPage(HttpServletRequest request, Model model, Long contractId) {
    model.addAttribute(TgolKeyStore.LOCALE_KEY, localeResolver.resolveLocale(request));
    Contract contract = contractDataService.read(contractId);
    if (isContractExpired(contract)) {
        throw new ForbiddenUserException(getCurrentUser());
    }
    if (isContractHasFunctionalityAllowingTrend(contract)) {
        model.addAttribute(TgolKeyStore.DISPLAY_RESULT_TREND_KEY, true);
    }
    if (isContractHasFunctionalityAllowingManualAudit(contract)) {
        model.addAttribute(TgolKeyStore.CONTRACT_WITH_MANUAL_AUDIT_KEY, true);
    }
    return displayContractView(contract, model);
}
Also used : Contract(org.asqatasun.entity.contract.Contract) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException)

Example 34 with Contract

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

the class UserManagementController method submitAddContractAdminPage.

/**
 * @param ccc the CreateContractCommand
 * @param result
 * @param request
 * @param response
 * @param model
 * @return The pages audit set-up form page
 */
@RequestMapping(value = TgolKeyStore.ADD_CONTRACT_URL, method = RequestMethod.POST)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String submitAddContractAdminPage(@ModelAttribute(TgolKeyStore.CREATE_CONTRACT_COMMAND_KEY) CreateContractCommand ccc, BindingResult result, HttpServletRequest request, HttpServletResponse response, Model model) {
    Map<String, List<ContractOptionFormField>> optionFormFieldMap = ContractOptionFormFieldHelper.getFreshContractOptionFormFieldMap(contractOptionFormFieldBuilderMap);
    createContractFormValidator.setContractOptionFormFieldMap(optionFormFieldMap);
    // We check whether the form is valid
    createContractFormValidator.validateMultipleUsers(ccc, result);
    if (result.hasErrors()) {
        return displayFormWithErrors(model, ccc, null, null, optionFormFieldMap, TgolKeyStore.ADD_CONTRACT_VIEW_NAME);
    }
    Collection<User> userList = ccc.getUserList();
    StringBuilder strb = new StringBuilder();
    for (User user : userList) {
        if (user != null) {
            Contract contract = contractDataService.create();
            contract.setUser(user);
            contract = createContractCommandFactory.updateContractFromCommand(ccc, contract);
            contractDataService.saveOrUpdate(contract);
            strb.append(user.getEmail1());
            strb.append(", ");
        }
    }
    request.getSession().setAttribute(TgolKeyStore.ADDED_CONTRACT_NAME_KEY, ccc.getLabel());
    request.getSession().setAttribute(TgolKeyStore.ADDED_CONTRACT_USERS_NAME_KEY, strb.toString());
    return TgolKeyStore.ADMIN_VIEW_REDIRECT_NAME;
}
Also used : User(org.asqatasun.entity.user.User) List(java.util.List) Contract(org.asqatasun.entity.contract.Contract) Secured(org.springframework.security.access.annotation.Secured)

Example 35 with Contract

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

the class UserManagementController method displayDeleteUserAuditsConfirmationPage.

/**
 * @param request
 * @param response
 * @param model
 * @return the name of the view that displays the confirmation page
 * when trying to delete all the audits of a user
 */
@RequestMapping(value = TgolKeyStore.DELETE_USER_AUDITS_URL, method = RequestMethod.POST)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String displayDeleteUserAuditsConfirmationPage(HttpServletRequest request, HttpServletResponse response, Model model) {
    Object userId = request.getSession().getAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY);
    Long lUserId;
    if (userId instanceof Long) {
        lUserId = (Long) userId;
    } else {
        try {
            lUserId = Long.valueOf(userId.toString());
        } catch (NumberFormatException nfe) {
            throw new ForbiddenUserException();
        }
    }
    User userToDelete = userDataService.read(lUserId);
    for (Contract contract : userToDelete.getContractSet()) {
        deleteAllAuditsFromContract(contract);
    }
    request.getSession().removeAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY);
    request.getSession().setAttribute(TgolKeyStore.DELETED_USER_AUDITS_KEY, userToDelete.getEmail1());
    return TgolKeyStore.ADMIN_VIEW_REDIRECT_NAME;
}
Also used : User(org.asqatasun.entity.user.User) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) Contract(org.asqatasun.entity.contract.Contract) Secured(org.springframework.security.access.annotation.Secured)

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