Search in sources :

Example 1 with Act

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

the class ParameterDAOImpl method findLastActByContractAndScenario.

private Act findLastActByContractAndScenario(Long idContract, String scenarioName) {
    StringBuilder queryString = new StringBuilder();
    queryString.append("SELECT a FROM ");
    queryString.append(Act.class.getName());
    queryString.append(" a");
    queryString.append(" left join a.audit.subject w");
    queryString.append(" WHERE a.contract.id = :idContract");
    queryString.append(" AND (a.status = :completedStatus OR a.status = :errorStatus)");
    queryString.append(" AND a.scope.code =:scope ");
    queryString.append(" AND w.url=:scenarioName");
    queryString.append(" ORDER BY a.id DESC");
    Query query = entityManager.createQuery(queryString.toString());
    query.setParameter("idContract", idContract);
    query.setParameter("completedStatus", ActStatus.COMPLETED);
    query.setParameter("errorStatus", ActStatus.ERROR);
    query.setParameter("scope", ScopeEnum.SCENARIO);
    query.setParameter("scenarioName", scenarioName);
    query.setMaxResults(1);
    query.setHint(CACHEABLE_OPTION, "true");
    try {
        return (Act) query.getSingleResult();
    } catch (NoResultException nre) {
        return null;
    }
}
Also used : Act(org.asqatasun.entity.contract.Act) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 2 with Act

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

the class ManualAuditController method displayManualAuditResultFromContract.

/**
 * General router when receive audit-result request. Regarding the scope of
 * the audit, the returned page may differ.
 *
 * @param auditId
 * @param request
 * @param model
 * @return
 */
@RequestMapping(value = TgolKeyStore.MANUAL_AUDIT_RESULT_CONTRACT_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String displayManualAuditResultFromContract(@RequestParam(TgolKeyStore.AUDIT_ID_KEY) String auditId, HttpServletRequest request, Model model) {
    try {
        Audit audit = auditDataService.read(Long.valueOf(auditId));
        Act act = actDataService.getActFromAudit(audit);
        switch(act.getScope().getCode()) {
            case FILE:
            case PAGE:
                if (!contractDataService.doesContractHaveFunctionality(act.getContract(), manualAuditFunctionalityKey)) {
                    return TgolKeyStore.ACCESS_DENIED_VIEW_NAME;
                }
                model.addAttribute(TgolKeyStore.WEBRESOURCE_ID_KEY, audit.getSubject().getId());
                return TgolKeyStore.MANUAL_AUDIT_RESULT_VIEW_REDIRECT_NAME;
            case DOMAIN:
            case SCENARIO:
            case GROUPOFFILES:
            case GROUPOFPAGES:
            default:
                throw new ForbiddenPageException();
        }
    } catch (NumberFormatException nfe) {
        throw new ForbiddenPageException();
    }
}
Also used : Audit(org.asqatasun.entity.audit.Audit) Act(org.asqatasun.entity.contract.Act) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Act

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

the class ActDAOTest method testFindLastActsByContract.

/**
 * Test of findAllContractsByUser method, of class ContractDAOImpl.
 */
@Test
public void testFindLastActsByContract() {
    Contract contract = contractDAO.read((1L));
    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((2L));
    assertEquals(0, actDAO.findActsByContract(contract, 1, 2, null, false).size());
}
Also used : Act(org.asqatasun.entity.contract.Act) Contract(org.asqatasun.entity.contract.Contract) Date(java.util.Date) Test(org.junit.Test)

Example 4 with Act

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

the class PageListControllerTest method setUpActDataService.

/**
 * @param isActSiteScope
 */
private void setUpActDataService(boolean isActSiteScope) {
    Scope mockGroupOfPagesScope = new Scope();
    mockGroupOfPagesScope.setCode(ScopeEnum.GROUPOFPAGES);
    Scope mockSiteScope = new Scope();
    mockSiteScope.setCode(ScopeEnum.DOMAIN);
    Contract mockContract = new Contract();
    Act mockAct = new Act();
    if (isActSiteScope) {
        mockAct.setScope(mockSiteScope);
    } else {
        mockAct.setScope(mockGroupOfPagesScope);
    }
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.set(2030, 01, 01);
    mockContract.setEndDate(calendar.getTime());
    mockContract.setUser(mockUser);
    mockContract.setLabel("CONTRACT LABEL");
    mockContract.setId(1L);
    mockAct.setContract(mockContract);
    when(mockActDataService.getActFromAudit(mockAudit)).thenReturn(mockAct);
}
Also used : Act(org.asqatasun.entity.contract.Act) Scope(org.asqatasun.entity.contract.Scope) Contract(org.asqatasun.entity.contract.Contract)

Example 5 with Act

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

the class ActFactory method createAct.

public Act createAct(Date date, Contract contract) {
    Act act = create();
    act.setBeginDate(date);
    act.setContract(contract);
    return act;
}
Also used : Act(org.asqatasun.entity.contract.Act)

Aggregations

Act (org.asqatasun.entity.contract.Act)9 NoResultException (javax.persistence.NoResultException)2 Query (javax.persistence.Query)2 Audit (org.asqatasun.entity.audit.Audit)2 Contract (org.asqatasun.entity.contract.Contract)2 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)2 Secured (org.springframework.security.access.annotation.Secured)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Date (java.util.Date)1 Scope (org.asqatasun.entity.contract.Scope)1 Test (org.junit.Test)1