Search in sources :

Example 36 with Contract

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

the class ContractManagementController method submitDeleteContractConfirmation.

/**
 * @param request
 * @param response
 * @param model
 * @return
 */
@RequestMapping(value = TgolKeyStore.DELETE_CONTRACT_URL, method = RequestMethod.POST)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String submitDeleteContractConfirmation(HttpServletRequest request, HttpServletResponse response, Model model) {
    Object contractId = request.getSession().getAttribute(TgolKeyStore.CONTRACT_ID_TO_DELETE_KEY);
    Long lContractId;
    if (contractId instanceof Long) {
        lContractId = (Long) contractId;
    } else {
        try {
            lContractId = Long.valueOf(contractId.toString());
        } catch (NumberFormatException nfe) {
            throw new ForbiddenUserException();
        }
    }
    Contract contractToDelete = contractDataService.read(lContractId);
    contractDataService.delete(contractToDelete.getId());
    // to be updated
    if (getAuthenticatedUsername().equals(contractToDelete.getUser().getEmail1())) {
        updateCurrentUser(userDataService.read(contractToDelete.getUser().getId()));
    }
    request.getSession().removeAttribute(TgolKeyStore.CONTRACT_ID_TO_DELETE_KEY);
    request.getSession().setAttribute(TgolKeyStore.DELETED_CONTRACT_NAME_KEY, contractToDelete.getLabel());
    model.addAttribute(TgolKeyStore.USER_ID_KEY, contractToDelete.getUser().getId());
    return TgolKeyStore.MANAGE_CONTRACTS_VIEW_REDIRECT_NAME;
}
Also used : 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 37 with Contract

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

the class ContractManagementController method deleteContractPage.

/**
 * @param contractId
 * @param request
 * @param response
 * @param model
 * @return The pages audit set-up form page
 */
@RequestMapping(value = TgolKeyStore.DELETE_CONTRACT_URL, method = RequestMethod.GET)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String deleteContractPage(@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 contractToDelete = contractDataService.read(lContractId);
    request.getSession().setAttribute(TgolKeyStore.CONTRACT_ID_TO_DELETE_KEY, contractToDelete.getId());
    model.addAttribute(TgolKeyStore.CONTRACT_NAME_TO_DELETE_KEY, contractToDelete.getLabel());
    model.addAttribute(TgolKeyStore.USER_ID_KEY, contractToDelete.getUser().getId());
    model.addAttribute(TgolKeyStore.USER_NAME_KEY, contractToDelete.getUser().getEmail1());
    return TgolKeyStore.DELETE_CONTRACT_VIEW_NAME;
}
Also used : 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 38 with Contract

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

the class ContractManagementController method deleteContractAuditsConfirmationPage.

/**
 * @param request
 * @param response
 * @param model
 * @return
 */
@RequestMapping(value = TgolKeyStore.DELETE_CONTRACT_AUDITS_URL, method = RequestMethod.POST)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String deleteContractAuditsConfirmationPage(HttpServletRequest request, HttpServletResponse response, Model model) {
    Object contractId = request.getSession().getAttribute(TgolKeyStore.CONTRACT_ID_TO_DELETE_KEY);
    Long lContractId;
    if (contractId instanceof Long) {
        lContractId = (Long) contractId;
    } else {
        try {
            lContractId = Long.valueOf(contractId.toString());
        } catch (NumberFormatException nfe) {
            throw new ForbiddenUserException();
        }
    }
    Contract contractToDelete = contractDataService.read(lContractId);
    deleteAllAuditsFromContract(contractToDelete);
    request.getSession().removeAttribute(TgolKeyStore.CONTRACT_ID_TO_DELETE_KEY);
    request.getSession().setAttribute(TgolKeyStore.DELETED_CONTRACT_AUDITS_NAME_KEY, contractToDelete.getLabel());
    model.addAttribute(TgolKeyStore.USER_ID_KEY, contractToDelete.getUser().getId());
    return TgolKeyStore.MANAGE_CONTRACTS_VIEW_REDIRECT_NAME;
}
Also used : 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 39 with Contract

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

the class ContractManagementController method submitEditContractAdminPage.

/**
 * @param createContractCommand
 * @param result
 * @param request
 * @param response
 * @param model
 * @return The pages audit set-up form page
 */
@RequestMapping(value = TgolKeyStore.EDIT_CONTRACT_URL, method = RequestMethod.POST)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String submitEditContractAdminPage(@ModelAttribute(TgolKeyStore.CREATE_CONTRACT_COMMAND_KEY) CreateContractCommand createContractCommand, BindingResult result, HttpServletRequest request, HttpServletResponse response, Model model) {
    Object contractId = request.getSession().getAttribute(TgolKeyStore.CONTRACT_ID_KEY);
    Long lContractId;
    if (contractId instanceof Long) {
        lContractId = (Long) contractId;
    } else {
        try {
            lContractId = Long.valueOf(contractId.toString());
        } catch (NumberFormatException nfe) {
            throw new ForbiddenUserException();
        }
    }
    Contract contract = contractDataService.read(lContractId);
    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
    if (result.hasErrors()) {
        return displayFormWithErrors(model, createContractCommand, contract.getUser().getEmail1(), contract.getUser().getId(), optionFormFieldMap, TgolKeyStore.EDIT_CONTRACT_VIEW_NAME);
    }
    contract = createContractCommandFactory.updateContractFromCommand(createContractCommand, contract);
    saveOrUpdateContract(contract);
    request.getSession().setAttribute(TgolKeyStore.UPDATED_CONTRACT_NAME_KEY, contract.getLabel());
    model.addAttribute(TgolKeyStore.USER_ID_KEY, contract.getUser().getId());
    request.getSession().removeAttribute(TgolKeyStore.CONTRACT_ID_KEY);
    return TgolKeyStore.MANAGE_CONTRACTS_VIEW_REDIRECT_NAME;
}
Also used : 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 40 with Contract

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

the class ContractManagementController method deleteContractAuditsPage.

/**
 * @param contractId
 * @param request
 * @param response
 * @param model
 * @return
 */
@RequestMapping(value = TgolKeyStore.DELETE_CONTRACT_AUDITS_URL, method = RequestMethod.GET)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String deleteContractAuditsPage(@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 contractToDelete = contractDataService.read(lContractId);
    model.addAttribute(TgolKeyStore.CONTRACT_NAME_TO_DELETE_KEY, contractToDelete.getLabel());
    model.addAttribute(TgolKeyStore.USER_ID_KEY, contractToDelete.getUser().getId());
    model.addAttribute(TgolKeyStore.USER_NAME_KEY, contractToDelete.getUser().getEmail1());
    request.getSession().setAttribute(TgolKeyStore.CONTRACT_ID_TO_DELETE_KEY, contractToDelete.getId());
    return TgolKeyStore.DELETE_AUDITS_VIEW_NAME;
}
Also used : 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)

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