@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()); }
@SuppressWarnings("unchecked") public Collection<Act> findActsByContract( Contract contract, int nbOfActs, int sortDirection, ScopeEnum scopeEnum, boolean onlyCompleted) { StringBuilder queryString = new StringBuilder(); queryString.append("SELECT a FROM "); queryString.append(getEntityClass().getName()); queryString.append(" a"); queryString.append(" WHERE a.contract = :contract"); queryString.append(" AND "); if (!onlyCompleted) { queryString.append("("); } queryString.append("a.status = :completedStatus"); if (!onlyCompleted) { queryString.append(" OR a.status = :errorStatus)"); } if (scopeEnum != null) { queryString.append(" AND a.scope.code = :scopeCode"); } queryString.append(" ORDER BY a.endDate"); if (sortDirection == 2) { queryString.append(DESC_STR); } else { queryString.append(ASC_STR); } Query query = entityManager.createQuery(queryString.toString()); query.setParameter("contract", contract); query.setParameter("completedStatus", ActStatus.COMPLETED); if (!onlyCompleted) { query.setParameter("errorStatus", ActStatus.ERROR); } if (scopeEnum != null) { query.setParameter("scopeCode", scopeEnum); } if (nbOfActs != -1) { query.setMaxResults(nbOfActs); } query.setHint(CACHEABLE_OPTION, "true"); return new LinkedHashSet<Act>(query.getResultList()); }
ActDAO extends AbstractJPADAO<Act, Long> { @SuppressWarnings("unchecked") public Collection<Act> findActsByContract( Contract contract, int nbOfActs, int sortDirection, ScopeEnum scopeEnum, boolean onlyCompleted) { StringBuilder queryString = new StringBuilder(); queryString.append("SELECT a FROM "); queryString.append(getEntityClass().getName()); queryString.append(" a"); queryString.append(" WHERE a.contract = :contract"); queryString.append(" AND "); if (!onlyCompleted) { queryString.append("("); } queryString.append("a.status = :completedStatus"); if (!onlyCompleted) { queryString.append(" OR a.status = :errorStatus)"); } if (scopeEnum != null) { queryString.append(" AND a.scope.code = :scopeCode"); } queryString.append(" ORDER BY a.endDate"); if (sortDirection == 2) { queryString.append(DESC_STR); } else { queryString.append(ASC_STR); } Query query = entityManager.createQuery(queryString.toString()); query.setParameter("contract", contract); query.setParameter("completedStatus", ActStatus.COMPLETED); if (!onlyCompleted) { query.setParameter("errorStatus", ActStatus.ERROR); } if (scopeEnum != null) { query.setParameter("scopeCode", scopeEnum); } if (nbOfActs != -1) { query.setMaxResults(nbOfActs); } query.setHint(CACHEABLE_OPTION, "true"); return new LinkedHashSet<Act>(query.getResultList()); } }
ActDAO extends AbstractJPADAO<Act, Long> { @SuppressWarnings("unchecked") public Collection<Act> findActsByContract( Contract contract, int nbOfActs, int sortDirection, ScopeEnum scopeEnum, boolean onlyCompleted) { StringBuilder queryString = new StringBuilder(); queryString.append("SELECT a FROM "); queryString.append(getEntityClass().getName()); queryString.append(" a"); queryString.append(" WHERE a.contract = :contract"); queryString.append(" AND "); if (!onlyCompleted) { queryString.append("("); } queryString.append("a.status = :completedStatus"); if (!onlyCompleted) { queryString.append(" OR a.status = :errorStatus)"); } if (scopeEnum != null) { queryString.append(" AND a.scope.code = :scopeCode"); } queryString.append(" ORDER BY a.endDate"); if (sortDirection == 2) { queryString.append(DESC_STR); } else { queryString.append(ASC_STR); } Query query = entityManager.createQuery(queryString.toString()); query.setParameter("contract", contract); query.setParameter("completedStatus", ActStatus.COMPLETED); if (!onlyCompleted) { query.setParameter("errorStatus", ActStatus.ERROR); } if (scopeEnum != null) { query.setParameter("scopeCode", scopeEnum); } if (nbOfActs != -1) { query.setMaxResults(nbOfActs); } query.setHint(CACHEABLE_OPTION, "true"); return new LinkedHashSet<Act>(query.getResultList()); } ActDAO(); }
ActDAO extends AbstractJPADAO<Act, Long> { @SuppressWarnings("unchecked") public Collection<Act> findActsByContract( Contract contract, int nbOfActs, int sortDirection, ScopeEnum scopeEnum, boolean onlyCompleted) { StringBuilder queryString = new StringBuilder(); queryString.append("SELECT a FROM "); queryString.append(getEntityClass().getName()); queryString.append(" a"); queryString.append(" WHERE a.contract = :contract"); queryString.append(" AND "); if (!onlyCompleted) { queryString.append("("); } queryString.append("a.status = :completedStatus"); if (!onlyCompleted) { queryString.append(" OR a.status = :errorStatus)"); } if (scopeEnum != null) { queryString.append(" AND a.scope.code = :scopeCode"); } queryString.append(" ORDER BY a.endDate"); if (sortDirection == 2) { queryString.append(DESC_STR); } else { queryString.append(ASC_STR); } Query query = entityManager.createQuery(queryString.toString()); query.setParameter("contract", contract); query.setParameter("completedStatus", ActStatus.COMPLETED); if (!onlyCompleted) { query.setParameter("errorStatus", ActStatus.ERROR); } if (scopeEnum != null) { query.setParameter("scopeCode", scopeEnum); } if (nbOfActs != -1) { query.setMaxResults(nbOfActs); } query.setHint(CACHEABLE_OPTION, "true"); return new LinkedHashSet<Act>(query.getResultList()); } ActDAO(); int findNumberOfAct(Contract contract); @SuppressWarnings("unchecked") Collection<Act> findAllActsByContract(Contract contract); @SuppressWarnings("unchecked") Collection<Act> findActsByContract(
            Contract contract,
            int nbOfActs,
            int sortDirection,
            ScopeEnum scopeEnum,
            boolean onlyCompleted); @SuppressWarnings("unchecked") Collection<Act> findRunningActsByContract(Contract contract); Act findActFromAudit(Long auditId); int findNumberOfActByPeriodAndIp(Contract contract, Date limitDate, String ip); int findNumberOfActByScope(Contract contract, Collection<ScopeEnum> scopes); }
ActDAO extends AbstractJPADAO<Act, Long> { @SuppressWarnings("unchecked") public Collection<Act> findActsByContract( Contract contract, int nbOfActs, int sortDirection, ScopeEnum scopeEnum, boolean onlyCompleted) { StringBuilder queryString = new StringBuilder(); queryString.append("SELECT a FROM "); queryString.append(getEntityClass().getName()); queryString.append(" a"); queryString.append(" WHERE a.contract = :contract"); queryString.append(" AND "); if (!onlyCompleted) { queryString.append("("); } queryString.append("a.status = :completedStatus"); if (!onlyCompleted) { queryString.append(" OR a.status = :errorStatus)"); } if (scopeEnum != null) { queryString.append(" AND a.scope.code = :scopeCode"); } queryString.append(" ORDER BY a.endDate"); if (sortDirection == 2) { queryString.append(DESC_STR); } else { queryString.append(ASC_STR); } Query query = entityManager.createQuery(queryString.toString()); query.setParameter("contract", contract); query.setParameter("completedStatus", ActStatus.COMPLETED); if (!onlyCompleted) { query.setParameter("errorStatus", ActStatus.ERROR); } if (scopeEnum != null) { query.setParameter("scopeCode", scopeEnum); } if (nbOfActs != -1) { query.setMaxResults(nbOfActs); } query.setHint(CACHEABLE_OPTION, "true"); return new LinkedHashSet<Act>(query.getResultList()); } ActDAO(); int findNumberOfAct(Contract contract); @SuppressWarnings("unchecked") Collection<Act> findAllActsByContract(Contract contract); @SuppressWarnings("unchecked") Collection<Act> findActsByContract(
            Contract contract,
            int nbOfActs,
            int sortDirection,
            ScopeEnum scopeEnum,
            boolean onlyCompleted); @SuppressWarnings("unchecked") Collection<Act> findRunningActsByContract(Contract contract); Act findActFromAudit(Long auditId); int findNumberOfActByPeriodAndIp(Contract contract, Date limitDate, String ip); int findNumberOfActByScope(Contract contract, Collection<ScopeEnum> scopes);  }