Search in sources :

Example 31 with Contract

use of org.asqatasun.webapp.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(getContractOptionFormFieldBuilderMap());
    getCreateContractFormValidator().setContractOptionFormFieldMap(optionFormFieldMap);
    // We check whether the form is valid
    getCreateContractFormValidator().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 = getContractDataService().create();
            contract.setUser(user);
            contract = CreateContractCommandFactory.getInstance().updateContractFromCommand(ccc, contract);
            getContractDataService().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.webapp.entity.user.User) List(java.util.List) Contract(org.asqatasun.webapp.entity.contract.Contract) Secured(org.springframework.security.access.annotation.Secured)

Example 32 with Contract

use of org.asqatasun.webapp.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(method = RequestMethod.POST)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
protected String submitAuditSetUpForm(@ModelAttribute(TgolKeyStore.AUDIT_SET_UP_COMMAND_KEY) AuditSetUpCommand auditSetUpCommand, BindingResult result, Model model, HttpServletRequest request) {
    Contract contract = getContractDataService().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, getSiteOptionFormFieldBuilderMap());
            auditSetUpFormValidator = getAuditSiteSetUpFormValidator();
            break;
        case PAGE:
            formFielMap = getFreshAuditSetUpFormFieldMap(contract, getPageOptionFormFieldBuilderMap());
            auditSetUpFormValidator = getAuditPageSetUpFormValidator();
            break;
        case FILE:
            formFielMap = getFreshAuditSetUpFormFieldMap(contract, getUploadOptionFormFieldBuilderMap());
            auditSetUpFormValidator = getAuditUploadSetUpFormValidator();
            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.webapp.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.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.

the class AuditSynthesisController method displayAuditSynthesisFromContract.

/**
     *
     * @param auditId
     * @param request
     * @param response
     * @param model
     * @return
     */
@RequestMapping(value = TgolKeyStore.AUDIT_SYNTHESIS_CONTRACT_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String displayAuditSynthesisFromContract(@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.WEBRESOURCE_ID_KEY, audit.getSubject().getId());
            return prepareSynthesisSiteData(audit, model);
        } else {
            throw new ForbiddenPageException();
        }
    } else {
        throw new ForbiddenUserException();
    }
}
Also used : 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 34 with Contract

use of org.asqatasun.webapp.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 = getContractDataService().read(contractId);
    if (isContractExpired(contract)) {
        throw new ForbiddenUserException(getCurrentUser());
    }
    //                model.addAttribute(TgolKeyStore.CONTRACT_ACTION_LIST_KEY, actionHandler.getActionList(contract));
    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.webapp.entity.contract.Contract) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException)

Example 35 with Contract

use of org.asqatasun.webapp.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 = getUserDataService().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.webapp.entity.user.User) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) Contract(org.asqatasun.webapp.entity.contract.Contract) Secured(org.springframework.security.access.annotation.Secured)

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