Search in sources :

Example 36 with Contract

use of org.asqatasun.webapp.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 = getContractDataService().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.webapp.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.webapp.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 = getContractDataService().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.webapp.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.webapp.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 = getContractDataService().read(lContractId);
    getContractDataService().delete(contractToDelete.getId());
    // to be updated
    if (getAuthenticatedUsername().equals(contractToDelete.getUser().getEmail1())) {
        updateCurrentUser(getUserDataService().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.webapp.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.webapp.entity.contract.Contract in project Asqatasun by Asqatasun.

the class ActDAOImplTest method testFindLastActsByContract.

/**
     * Test of findAllContractsByUser method, of class ContractDAOImpl.
     */
public void testFindLastActsByContract() {
    System.out.println("findLastActsByContract");
    Contract contract = contractDAO.read((Long.valueOf(1)));
    assertEquals(1, actDAO.findActsByContract(contract, 1, 2, null, false).size());
    assertEquals(Long.valueOf(7), actDAO.findActsByContract(contract, 1, 2, null, false).iterator().next().getId());
    Collection<Act> actSet = actDAO.findActsByContract(contract, 3, 2, null, false);
    Iterator<Act> iter = actSet.iterator();
    Date currentDate = null;
    while (iter.hasNext()) {
        Act act = iter.next();
        if (currentDate != null) {
            assertTrue(act.getBeginDate().before(currentDate));
        }
        currentDate = act.getBeginDate();
    }
    contract = contractDAO.read((Long.valueOf(2)));
    assertEquals(0, actDAO.findActsByContract(contract, 1, 2, null, false).size());
}
Also used : Act(org.asqatasun.webapp.entity.contract.Act) Contract(org.asqatasun.webapp.entity.contract.Contract) Date(java.util.Date)

Example 40 with Contract

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

the class ContractDAOImplTest method testRead.

/**
     * Test of read method, of class ContractDAOImpl.
     */
public void testRead() {
    System.out.println("read");
    Contract contract = contractDAO.read(Long.valueOf(1));
    assertNotNull(contract);
    assertEquals("http://www.contract1.com/", contractDataService.getUrlFromContractOption(contract));
    assertEquals(Long.valueOf("1"), contract.getUser().getId());
    Set<String> functionalityCodeSet = new HashSet<String>();
    for (Functionality functionality : contract.getFunctionalitySet()) {
        functionalityCodeSet.add(functionality.getCode());
    }
    assertTrue(functionalityCodeSet.contains("PAGES_AUDIT"));
    assertTrue(!functionalityCodeSet.contains("SITE_AUDIT"));
    assertEquals(1, contract.getReferentialSet().size());
    assertTrue(contract.getScenarioSet().isEmpty());
    contract = contractDAO.read(Long.valueOf(2));
    assertNotNull(contract);
    assertEquals("http://www.contract2.com/", contractDataService.getUrlFromContractOption(contract));
    assertEquals(Long.valueOf("1"), contract.getUser().getId());
    functionalityCodeSet = new HashSet<String>();
    for (Functionality functionality : contract.getFunctionalitySet()) {
        functionalityCodeSet.add(functionality.getCode());
    }
    assertTrue(functionalityCodeSet.contains("PAGES_AUDIT"));
    assertTrue(functionalityCodeSet.contains("SITE_AUDIT"));
    assertEquals(2, contract.getReferentialSet().size());
    assertEquals(2, contract.getScenarioSet().size());
    contract = contractDAO.read(Long.valueOf(3));
    assertNull(contract);
}
Also used : Functionality(org.asqatasun.webapp.entity.functionality.Functionality) Contract(org.asqatasun.webapp.entity.contract.Contract) HashSet(java.util.HashSet)

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