public List<TaskInstance> findTaskInstances(
      long processInstanceId,
      long tokenId,
      String[] actorIds,
      boolean pooledActors,
      Boolean completed,
      int start,
      int end,
      OrderByComparator orderByComparator) {

    if ((actorIds != null) && (actorIds.length == 0)) {
      return Collections.emptyList();
    }

    try {
      Criteria criteria = _session.createCriteria(TaskInstance.class);

      criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

      if (processInstanceId > 0) {
        criteria.add(Restrictions.eq("processInstance.id", processInstanceId));
      } else if (tokenId > 0) {
        criteria.add(Restrictions.eq("token.id", tokenId));
      }

      if (actorIds != null) {
        if (pooledActors) {
          Criteria subcriteria = criteria.createCriteria("pooledActors");

          subcriteria.add(Restrictions.in("actorId", actorIds));

          criteria.add(Restrictions.isNull("actorId"));
        } else {
          criteria.add(Restrictions.in("actorId", actorIds));
        }
      }

      if (completed != null) {
        if (completed.booleanValue()) {
          criteria.add(Restrictions.isNotNull("end"));
        } else {
          criteria.add(Restrictions.isNull("end"));
        }
      }

      addPagination(criteria, start, end);
      addOrder(criteria, orderByComparator);

      return criteria.list();
    } catch (Exception e) {
      throw new JbpmException(e);
    }
  }
 /**
  * get an in-restriction. Eventually concatenated with an isNull-restriction if criteria-set
  * contains a null-value.
  *
  * @param criteria criteria to put in in-restriction
  * @param fieldName field-name for in-restriction
  * @return Criterion
  */
 private static Criterion getInRestrictions(
     final Collection<String> criteria, final String fieldName) {
   if (criteria.contains("")) {
     criteria.remove("");
     return criteria.isEmpty()
         ? Restrictions.isNull(fieldName)
         : Restrictions.or(
             Restrictions.isNull(fieldName), Restrictions.in(fieldName, criteria.toArray()));
   } else {
     return Restrictions.in(fieldName, criteria.toArray());
   }
 }
  public List<ProcessInstance> findProcessInstances(
      long processDefinitionId,
      Boolean completed,
      int start,
      int end,
      OrderByComparator orderByComparator) {

    try {
      Criteria criteria = _session.createCriteria(ProcessInstance.class);

      criteria.add(Restrictions.eq("processDefinition.id", processDefinitionId));

      if (completed != null) {
        if (completed.booleanValue()) {
          criteria.add(Restrictions.isNotNull("end"));
        } else {
          criteria.add(Restrictions.isNull("end"));
        }
      }

      addPagination(criteria, start, end);
      addOrder(criteria, orderByComparator);

      return criteria.list();
    } catch (Exception e) {
      throw new JbpmException(e);
    }
  }
  protected Criteria buildProcessInstanceExtensionSearchCriteria(
      long companyId, Long userId, String assetClassName, Long assetClassPK, Boolean completed) {

    Criteria criteria = _session.createCriteria(ProcessInstanceExtensionImpl.class);

    criteria.add(Restrictions.eq("companyId", companyId));

    if (userId != null) {
      criteria.add(Restrictions.eq("userId", userId));
    }

    if (Validator.isNotNull(assetClassName)) {
      criteria.add(Restrictions.like("className", assetClassName));
    }

    if (Validator.isNotNull(assetClassPK)) {
      criteria.add(Restrictions.eq("classPK", assetClassPK));
    }

    if (completed != null) {
      Criteria completionCriteria = criteria.createCriteria("processInstance");

      if (completed) {
        completionCriteria.add(Restrictions.isNotNull("end"));
      } else {
        completionCriteria.add(Restrictions.isNull("end"));
      }
    }

    return criteria;
  }
 private Criteria createCriteriaByCriteres(CritereRechercheContratDto criteres) {
   final Criteria crit = createCriteria(Contrat.class);
   crit.createAlias("statut", "statut");
   if (criteres != null && criteres.getIdAssure() != null) {
     crit.add(Restrictions.eq("uidAssure", criteres.getIdAssure()));
   }
   if (criteres != null && criteres.getIdSouscripteur() != null) {
     crit.add(Restrictions.eq("uidSouscripteur", criteres.getIdSouscripteur()));
   }
   if (criteres != null && criteres.isIdAssureNull()) {
     crit.add(Restrictions.isNull("uidAssure"));
   }
   if (criteres != null && StringUtils.isNotBlank(criteres.getNumeroContrat())) {
     crit.add(Restrictions.ilike("numeroContrat", criteres.getNumeroContrat() + "%"));
   }
   if (criteres != null
       && criteres.getHasContratEnCours() != null
       && criteres.getHasContratEnCours()) {
     crit.add(Restrictions.eq("statut.id", adherentMappingService.getIdStatutContratEnCours()));
   }
   if (criteres != null
       && criteres.getContratEid() != null
       && StringUtils.isNotBlank(criteres.getContratEid())) {
     crit.add(Restrictions.like("identifiantExterieur", "%" + criteres.getContratEid() + "%"));
   }
   crit.add(Restrictions.eq("isVisible", true));
   return crit;
 }
Esempio n. 6
0
  /**
   * Perform a search over all child and sub orgs within the given organisation
   *
   * <p>If a search query is given it will be split by space and the key words searched in the
   * title, orgid, address, addressLine2 and postcode fields.
   *
   * @param q - search query, which is a space seperated list of key words. Optional
   * @param organisation - search is for orgs inside this
   * @param orgType - optional, if given results are limited to organisations of this type
   * @param session
   * @return
   */
  public static List<Organisation> search(
      String q, Organisation organisation, OrgType orgType, Session session) {
    Criteria crit = session.createCriteria(Organisation.class);
    crit.setCacheable(true);
    Disjunction notDeleted = Restrictions.disjunction();
    notDeleted.add(Restrictions.isNull("deleted"));
    notDeleted.add(Restrictions.eq("deleted", Boolean.FALSE));
    crit.add(notDeleted);

    if (q != null) {
      String[] arr = q.split(" ");
      Conjunction con = Restrictions.conjunction();
      for (String queryPart : arr) {
        Disjunction dis = Restrictions.disjunction();
        String s = "%" + queryPart + "%";
        dis.add(Restrictions.ilike("title", s));
        dis.add(Restrictions.ilike("orgId", s));
        dis.add(Restrictions.ilike("address", s));
        dis.add(Restrictions.ilike("addressLine2", s));
        dis.add(Restrictions.ilike("postcode", s));
        con.add(dis);
      }
      crit.add(con);
    }

    if (orgType != null) {
      crit.add(Restrictions.eq("orgType", orgType));
    }
    // TODO: add other properties like address
    Criteria critParentLink = crit.createCriteria("parentOrgLinks");
    critParentLink.add(Restrictions.eq("owner", organisation));
    crit.addOrder(Order.asc("title"));
    return DbUtils.toList(crit, Organisation.class);
  }
Esempio n. 7
0
  @Override
  public List<ThesaurusConcept> getPaginatedAvailableConceptsOfGroup(
      Integer startIndex,
      Integer limit,
      String groupId,
      String thesaurusId,
      Boolean onlyValidatedConcepts,
      String like) {

    DetachedCriteria dc = DetachedCriteria.forClass(ThesaurusConceptGroup.class, "gr");
    dc.createCriteria("concepts", "tc", JoinType.RIGHT_OUTER_JOIN);
    dc.setProjection(Projections.projectionList().add(Projections.property("tc.identifier")));
    dc.add(Restrictions.eq("gr.identifier", groupId));

    Criteria criteria = selectPaginatedConceptsByAlphabeticalOrder(startIndex, limit);
    criteria.add(Subqueries.propertyNotIn("tc.identifier", dc));

    selectThesaurus(criteria, thesaurusId);
    criteria.add(
        Restrictions.not(
            Restrictions.and(
                Restrictions.eq("topConcept", false),
                Restrictions.or(
                    Restrictions.isNull("tc.parentConcepts"),
                    Restrictions.isEmpty("tc.parentConcepts")))));

    if (null != like) {
      conceptNameIsLike(criteria, like);
    }
    onlyValidatedConcepts(criteria, onlyValidatedConcepts);

    return criteria.list();
  }
  /**
   * See Interface for functional description.
   *
   * @see UserAccountDaoInterface #retrieveCurrentGrant(java.lang.String, EscidocRole,
   *     java.lang.String)
   */
  @Override
  public RoleGrant retrieveCurrentGrant(
      final UserAccount userAccount, final EscidocRole role, final String objId)
      throws SqlDatabaseSystemException {

    RoleGrant result = null;
    if (userAccount != null && role != null) {

      try {
        DetachedCriteria criteria =
            DetachedCriteria.forClass(RoleGrant.class)
                .add(Restrictions.eq("userAccountByUserId", userAccount))
                .add(Restrictions.eq("escidocRole", role))
                .add(Restrictions.isNull("revocationDate"));
        if (objId != null) {
          criteria = criteria.add(Restrictions.eq("objectId", objId));
        }
        result = (RoleGrant) getUniqueResult(getHibernateTemplate().findByCriteria(criteria));
      } catch (final DataAccessException e) {
        throw new SqlDatabaseSystemException(e);
      } catch (final IllegalStateException e) {
        throw new SqlDatabaseSystemException(e);
      } catch (final HibernateException e) {
        //noinspection ThrowableResultOfMethodCallIgnored
        throw new SqlDatabaseSystemException(convertHibernateAccessException(e)); // Ignore FindBugs
      }
    }
    return result;
  }
Esempio n. 9
0
 @SuppressWarnings("unchecked")
 @Override
 public List<Sales> getPendingSalesBetween(Date startDate, Date endDate) throws Exception {
   Session session = HibernateUtil.startSession();
   Criteria criteria = session.createCriteria(Sales.class);
   criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
   List<Sales> sales = new ArrayList<Sales>();
   try {
     Date lowerBound = DateTool.getTomorrowDate(DateTool.getDateWithoutTime(startDate));
     Date upperBound = DateTool.getDateWithoutTime(endDate);
     sales =
         criteria
             .add(Restrictions.ge("date", lowerBound))
             .add(Restrictions.lt("date", upperBound))
             .add(Restrictions.eq("valid", true))
             .add(Restrictions.isNull("inventorySheetData"))
             .addOrder(Order.desc("date"))
             .list();
   } catch (HibernateException ex) {
     ex.printStackTrace();
   } finally {
     session.close();
   }
   return sales;
 }
Esempio n. 10
0
 private void filtroPorStatus(Emprestimo filtro, Criteria criteria) {
   if (filtro.getOpFiltro() == 2) {
     criteria.add(Restrictions.isNull("c.dataDevolucao"));
   } else if (filtro.getOpFiltro() == 3) {
     criteria.add(Restrictions.isNotNull("c.dataDevolucao"));
   }
 }
Esempio n. 11
0
  public DmFolder getByName(String folderName, String accountId, String folderIdParent) {
    DmFolder folderParent = null;
    if ((folderIdParent != null) && (!folderIdParent.isEmpty())) {
      folderParent = new DmFolder();
      folderParent.setId(folderIdParent);
    }

    DmAccount accountOwner = null;
    if (folderParent == null) {
      if ((accountId != null) && (!accountId.isEmpty())) {
        accountOwner = new DmAccount();
        accountOwner.setId(accountId);
      }
    }

    Criteria crit = getSession().createCriteria(DmFolder.class);
    crit.add(Restrictions.eq("name", folderName).ignoreCase());
    if (accountOwner != null) {
      crit.add(Restrictions.eq("owner", accountOwner));
    }
    if (folderParent != null) {
      crit.add(Restrictions.eq("parent", folderParent));
    } else {
      crit.add(Restrictions.isNull("parent"));
    }
    return (DmFolder) crit.uniqueResult();
  }
Esempio n. 12
0
  public int getNumDocuments(String folderId) {
    DmFolder folder = null;
    if (folderId != null) {
      folder = new DmFolder();
      folder.setId(folderId);
    }

    if (folder != null) {
      Disjunction disjunction = Restrictions.disjunction();
      disjunction.add(Restrictions.isNull("docApproval.id"));
      disjunction.add(
          Restrictions.ne("docApproval.status", ApplicationConstants.APPROVAL_STATUS_REJECTED));

      Criteria crit = getSession().createCriteria(DmDocumentFolder.class);
      crit.createAlias("document", "docInfo");
      crit.createAlias("docInfo.approval", "docApproval", CriteriaSpecification.LEFT_JOIN);
      crit.add(Restrictions.eq("folder", folder));
      //            crit.add(Restrictions.eq("docInfo.approved", true));
      crit.add(disjunction);

      return crit.list().size();
    }

    return 0;
  }
Esempio n. 13
0
  public List<DmFolder> getFirstLevelList(String accountId) {
    DmAccount accountOwner = null;
    if (accountId != null) {
      accountOwner = new DmAccount();
      accountOwner.setId(accountId);
    }

    List<DmFolder> folderList = null;
    if (accountOwner != null) {
      Criteria crit = getSession().createCriteria(DmFolder.class);
      crit.add(Restrictions.eq("owner", accountOwner));
      crit.add(Restrictions.isNull("parent"));
      crit.addOrder(Order.asc("name"));
      folderList = crit.list();

      // start - get children for each child (trigger lazy fetch)
      for (DmFolder folderTmp : folderList) {
        if (folderTmp.getChildList() != null) {
          folderTmp.getChildList().size();
        }
      }
      // end - get children for each child (trigger lazy fetch)
    }

    return folderList;
  }
Esempio n. 14
0
  public static Criterion sameEnterpriseOrNull(final Enterprise enterprise) {
    Disjunction filterDisjunction = Restrictions.disjunction();

    filterDisjunction.add(Restrictions.eq(Role.ENTERPRISE_PROPERTY, enterprise));
    filterDisjunction.add(Restrictions.isNull(Role.ENTERPRISE_PROPERTY));

    return filterDisjunction;
  }
Esempio n. 15
0
  @SuppressWarnings("rawtypes")
  public List<Criterion> restrict(Object[]... values) {

    List<Criterion> criterions = new ArrayList<Criterion>();
    switch (valueOf(type)) {
      case IN:
        for (Object[] value : values)
          criterions.add(Restrictions.in((String) value[0], (Collection) value[1]));

        break;
      case NOTIN:
        for (Object[] value : values)
          criterions.add(
              Restrictions.not(Restrictions.in((String) value[0], (Collection) value[1])));
        break;
      case EQ:
        for (Object[] value : values) criterions.add(Restrictions.eq((String) value[0], value[1]));
        break;
      case NOTEQ:
        for (Object[] value : values) criterions.add(Restrictions.ne((String) value[0], value[1]));
        break;
      case GE:
        for (Object[] value : values) criterions.add(Restrictions.ge((String) value[0], value[1]));
        break;
      case LE:
        for (Object[] value : values) criterions.add(Restrictions.le((String) value[0], value[1]));
        break;
      case BETWEEN:
        for (Object[] value : values)
          criterions.add(Restrictions.between((String) value[0], value[1], value[2]));
        break;
      case GT:
        for (Object[] value : values) criterions.add(Restrictions.gt((String) value[0], value[1]));
        break;
      case LT:
        for (Object[] value : values) criterions.add(Restrictions.lt((String) value[0], value[1]));
        break;
      case AND:
        for (Object[] value : values)
          criterions.add(Restrictions.and((Criterion) value[0], (Criterion) value[1]));
        break;
      case OR:
        for (Object[] value : values)
          criterions.add(Restrictions.or((Criterion) value[0], (Criterion) value[1]));
        break;
      case NULL:
        for (Object[] value : values) criterions.add(Restrictions.isNull((String) value[0]));
        break;
      case NOTNULL:
        for (Object[] value : values) criterions.add(Restrictions.isNotNull((String) value[0]));
        break;
      case LIKE:
        for (Object[] value : values)
          criterions.add(Restrictions.like((String) value[0], value[1]));
        break;
    }
    return criterions;
  }
  private void attachRootFilters(
      Criteria projectCrit,
      Criteria iterationCrit,
      Criteria standaloneIterationCrit,
      int projectId) {
    LogicalExpression parentInProductBacklog =
        Restrictions.and(
            Restrictions.isNotNull("parent"),
            Restrictions.eqProperty("parentStory.backlog", "project.parent"));
    // stories attached to the project
    projectCrit.add(Restrictions.eq("backlog.id", projectId));
    projectCrit.createAlias("backlog", "project");

    projectCrit.createAlias("parent", "parentStory", CriteriaSpecification.LEFT_JOIN);
    Criterion parentFilter = Restrictions.or(Restrictions.isNull("parent"), parentInProductBacklog);

    projectCrit.add(parentFilter);
    projectCrit.add(Restrictions.isNull("iteration"));

    // Stories attached to iterations under the project
    iterationCrit.createAlias("parent", "parentStory", CriteriaSpecification.LEFT_JOIN);
    iterationCrit
        .createCriteria("iteration")
        .add(Restrictions.eq("parent.id", projectId))
        .createAlias("parent", "project");
    iterationCrit.add(parentFilter);

    // Stories in standalone iterations and this project
    if (standaloneIterationCrit != null) {
      // story's backlog is this project
      standaloneIterationCrit.add(Restrictions.eq("backlog.id", projectId));

      // story's iteration is not null
      standaloneIterationCrit.add(Restrictions.isNotNull("iteration"));

      // story's iteration doesn't have a parent
      standaloneIterationCrit.createCriteria("iteration").add(Restrictions.isNull("parent"));

      standaloneIterationCrit.createAlias("backlog", "project");

      // story doesn't have a parent OR parent in product
      standaloneIterationCrit.createAlias("parent", "parentStory", CriteriaSpecification.LEFT_JOIN);
      standaloneIterationCrit.add(parentFilter);
    }
  }
  @Override
  public Condition buildCondition(
      String conditionField, ConditionType conditionType, Iterator argsIterator) {
    Condition condition = new Condition();

    condition.setField(conditionField);

    switch (conditionType) {
      case Between:
        condition.setConstraint(
            Restrictions.between(conditionField, argsIterator.next(), argsIterator.next()));
        break;

      case Equal:
        condition.setConstraint(Restrictions.eq(conditionField, argsIterator.next()));
        break;

      case GreaterThan:
        condition.setConstraint(Restrictions.gt(conditionField, argsIterator.next()));
        break;

      case GreaterThanEqual:
        condition.setConstraint(Restrictions.ge(conditionField, argsIterator.next()));
        break;

      case IsNotNull:
        condition.setConstraint(Restrictions.isNotNull(conditionField));
        break;

      case IsNull:
        condition.setConstraint(Restrictions.isNull(conditionField));
        break;

      case LessThan:
        condition.setConstraint(Restrictions.lt(conditionField, argsIterator.next()));
        break;

      case LessThanEqual:
        condition.setConstraint(Restrictions.le(conditionField, argsIterator.next()));
        break;

      case NotEqual:
        condition.setConstraint(Restrictions.ne(conditionField, argsIterator.next()));
        break;

      case NotWithin:
        condition.setConstraint(
            Restrictions.not(Restrictions.in(conditionField, (Collection) argsIterator.next())));
        break;

      case Within:
        condition.setConstraint(Restrictions.in(conditionField, (Collection) argsIterator.next()));
        break;
    }

    return condition;
  }
Esempio n. 18
0
 @Override
 public List<Dept> findDepts(Dept dept, boolean parentIsNull) {
   DetachedCriteria detachedCriteria = createDetachedCriteria();
   detachedCriteria.add(Example.create(dept));
   if (parentIsNull) {
     detachedCriteria.add(Restrictions.isNull("parent"));
   }
   return findDatas(detachedCriteria);
 }
 public static void findReportCentreByAccessCriteria(Criteria criteria) {
   Integer centre = SecurityUtil.getInstance().getCentre();
   if (centre != null && centre != 0) {
     // have just country access to restrict to all centres in that country
     criteria
         .createCriteria("centre", CriteriaSpecification.LEFT_JOIN)
         .add(Restrictions.or(Restrictions.eq("id", new Long(centre)), Restrictions.isNull("id")));
   }
 }
  /**
   * Calculates the sum of outstanding payments/deposits applying the following filters:
   *
   * <p>- They belong to the financial account of the reconciliation.
   *
   * <p>- The transaction date must be lower than the ending date of the reconciliation.
   *
   * <p>- They do not belong to any reconciliation.
   *
   * @param recon Reconciliation
   * @return List with 2 values. The first one is the sum of outstanding payments (transactions) and
   *     the second is the sum of outstanding deposits (transactions).
   */
  private List<BigDecimal> getOutstandingPaymentAndDepositTotal(FIN_Reconciliation recon) {
    List<BigDecimal> outList = new ArrayList<BigDecimal>();
    OBContext.setAdminMode(true);
    try {
      OBCriteria<FIN_FinaccTransaction> obcTrans =
          OBDal.getInstance().createCriteria(FIN_FinaccTransaction.class);
      obcTrans.add(Restrictions.eq(FIN_FinaccTransaction.PROPERTY_ACCOUNT, recon.getAccount()));
      obcTrans.add(
          Restrictions.le(FIN_FinaccTransaction.PROPERTY_TRANSACTIONDATE, recon.getEndingDate()));
      List<FIN_Reconciliation> afterReconciliations =
          MatchTransactionDao.getReconciliationListAfterDate(recon);
      if (afterReconciliations.size() > 0) {
        obcTrans.add(
            Restrictions.or(
                Restrictions.isNull(FIN_FinaccTransaction.PROPERTY_RECONCILIATION),
                Restrictions.in(
                    FIN_FinaccTransaction.PROPERTY_RECONCILIATION, afterReconciliations)));
      } else {
        obcTrans.add(Restrictions.isNull(FIN_FinaccTransaction.PROPERTY_RECONCILIATION));
      }

      ProjectionList projections = Projections.projectionList();
      projections.add(Projections.sum(FIN_FinaccTransaction.PROPERTY_PAYMENTAMOUNT));
      projections.add(Projections.sum(FIN_FinaccTransaction.PROPERTY_DEPOSITAMOUNT));
      obcTrans.setProjection(projections);

      if (obcTrans.list() != null && obcTrans.list().size() > 0) {
        @SuppressWarnings("rawtypes")
        List o = obcTrans.list();
        Object[] resultSet = (Object[]) o.get(0);
        BigDecimal paymentAmt =
            (resultSet[0] != null) ? (BigDecimal) resultSet[0] : BigDecimal.ZERO;
        BigDecimal depositAmt =
            (resultSet[1] != null) ? (BigDecimal) resultSet[1] : BigDecimal.ZERO;
        outList.add(paymentAmt);
        outList.add(depositAmt);
      }

    } finally {
      OBContext.restorePreviousMode();
    }

    return outList;
  }
  /**
   * Calculates the sum of un-reconciled bank statement lines applying the following filters:
   *
   * <p>- They belong to the financial account of the reconciliation.
   *
   * <p>- The transaction date must be lower than the ending date of the reconciliation.
   *
   * <p>- They are not matched with any transaction.
   *
   * @param recon Reconciliation
   * @return Sum of the un-reconciled bank statement lines.
   */
  private BigDecimal getUnreconciledBankStatmentLinesTotal(FIN_Reconciliation recon) {
    BigDecimal total = BigDecimal.ZERO;
    OBContext.setAdminMode(true);
    try {
      OBCriteria<FIN_BankStatementLine> obcBsl =
          OBDal.getInstance().createCriteria(FIN_BankStatementLine.class);
      obcBsl.createAlias(FIN_BankStatementLine.PROPERTY_BANKSTATEMENT, "bs");
      obcBsl.createAlias(
          FIN_BankStatementLine.PROPERTY_FINANCIALACCOUNTTRANSACTION, "tr", OBCriteria.LEFT_JOIN);
      obcBsl.add(
          Restrictions.le(FIN_BankStatementLine.PROPERTY_TRANSACTIONDATE, recon.getEndingDate()));
      List<FIN_Reconciliation> afterReconciliations =
          MatchTransactionDao.getReconciliationListAfterDate(recon);
      if (afterReconciliations.size() > 0) {
        obcBsl.add(
            Restrictions.or(
                Restrictions.isNull(FIN_BankStatementLine.PROPERTY_FINANCIALACCOUNTTRANSACTION),
                Restrictions.in(
                    "tr." + FIN_FinaccTransaction.PROPERTY_RECONCILIATION, afterReconciliations)));
      } else {
        obcBsl.add(Restrictions.isNull(FIN_BankStatementLine.PROPERTY_FINANCIALACCOUNTTRANSACTION));
      }
      obcBsl.add(Restrictions.eq("bs." + FIN_BankStatement.PROPERTY_ACCOUNT, recon.getAccount()));
      obcBsl.add(Restrictions.eq("bs." + FIN_BankStatement.PROPERTY_PROCESSED, true));
      ProjectionList projections = Projections.projectionList();
      projections.add(Projections.sum(FIN_BankStatementLine.PROPERTY_CRAMOUNT));
      projections.add(Projections.sum(FIN_BankStatementLine.PROPERTY_DRAMOUNT));
      obcBsl.setProjection(projections);

      if (obcBsl.list() != null && obcBsl.list().size() > 0) {
        @SuppressWarnings("rawtypes")
        List o = obcBsl.list();
        Object[] resultSet = (Object[]) o.get(0);
        BigDecimal credit = (resultSet[0] != null) ? (BigDecimal) resultSet[0] : BigDecimal.ZERO;
        BigDecimal debit = (resultSet[1] != null) ? (BigDecimal) resultSet[1] : BigDecimal.ZERO;
        total = credit.subtract(debit);
      }

    } finally {
      OBContext.restorePreviousMode();
    }

    return total;
  }
Esempio n. 22
0
 public static Organisation getRootOrg(Session session) {
   Criteria crit = session.createCriteria(Organisation.class);
   crit.setCacheable(true);
   crit.add(Restrictions.isNull("organisation"));
   List<Organisation> list = DbUtils.toList(crit, Organisation.class);
   if (!list.isEmpty()) {
     return list.get(0);
   }
   return null;
 }
Esempio n. 23
0
 @Override
 public List<Participation> getParticipationsWithoutGroup(Lecture lecture) {
   return getSession()
       .createCriteria(Participation.class)
       .add(Restrictions.eq("lecture", lecture))
       .add(Restrictions.isNull("group"))
       .createCriteria("user")
       .addOrder(Order.asc("lastName"))
       .addOrder(Order.asc("firstName"))
       .list();
 }
Esempio n. 24
0
 @Override
 public List<Tag> retrieveAllApplicationTags() {
   return getSession()
       .createCriteria(getClassReference())
       .add(Restrictions.eq("active", true))
       .add(
           Restrictions.or(
               Restrictions.isNull("type"), Restrictions.eq("type", TagType.APPLICATION)))
       .addOrder(getOrder())
       .list();
 }
  @Override
  public int count(Program program, OrganisationUnit organisationUnit) {
    Number rs =
        (Number)
            getCriteria(Restrictions.eq("program", program), Restrictions.isNull("endDate"))
                .createAlias("entityInstance", "entityInstance")
                .add(Restrictions.eq("entityInstance.organisationUnit", organisationUnit))
                .setProjection(Projections.rowCount())
                .uniqueResult();

    return rs != null ? rs.intValue() : 0;
  }
Esempio n. 26
0
 @Override
 public Tag retrieveAppTagByName(String name) {
   return (Tag)
       getSession()
           .createCriteria(getClassReference())
           .add(Restrictions.eq("active", true))
           .add(Restrictions.eq("name", name))
           .add(
               Restrictions.or(
                   Restrictions.isNull("type"), Restrictions.eq("type", TagType.APPLICATION)))
           .uniqueResult();
 }
Esempio n. 27
0
  public static List<Milestone> listNotExpired() {
    DataHelperRike<Milestone> helper = new DataHelperRike<Milestone>(Milestone.class);

    return helper.list(
        helper
            .filter()
            .add(
                Restrictions.or(
                    Restrictions.gt("dueDate", new Date()), Restrictions.isNull("dueDate")))
            .addOrder(Order.asc("dueDate"))
            .addOrder(Order.asc("title")));
  }
Esempio n. 28
0
 @SuppressWarnings("unchecked")
 @Override
 public List<AjustementTarif> getListeAjustementsFromContrat(Long uidContrat) {
   final Criteria crit = createCriteria(AjustementTarif.class);
   crit.createAlias("contrat", "contrat");
   crit.add(Restrictions.eq("contrat.id", uidContrat));
   crit.add(Restrictions.eq("contrat.isVisible", true));
   crit.add(
       Restrictions.or(
           Restrictions.ltProperty("dateDebut", "dateFin"), Restrictions.isNull("dateFin")));
   return crit.list();
 }
 private Criteria getRootStoryCriteria(int productId) {
   Criteria rootFilter = getCurrentSession().createCriteria(Story.class);
   rootFilter
       .createAlias("backlog.parent", "secondParent", CriteriaSpecification.LEFT_JOIN)
       .createAlias("secondParent.parent", "thirdParent", CriteriaSpecification.LEFT_JOIN);
   rootFilter.add(
       Restrictions.or(
           Restrictions.or(
               Restrictions.eq("backlog.id", productId),
               Restrictions.eq("secondParent.id", productId)),
           Restrictions.eq("thirdParent.id", productId)));
   rootFilter.add(Restrictions.isNull("parent"));
   return rootFilter;
 }
Esempio n. 30
0
 @Override
 @SuppressWarnings("unchecked")
 public List<Contrat> getListeContratsPersonneMorale(Long uidPersonneMorale) {
   final Criteria crit = createCriteria(Contrat.class);
   crit.createAlias("statut", "statut");
   crit.createAlias("nature", "nature");
   crit.add(Restrictions.eq("uidSouscripteur", uidPersonneMorale));
   crit.add(Restrictions.isNull("uidAssure"));
   crit.add(Restrictions.eq("isVisible", true));
   crit.addOrder(Order.asc("statut.ordre"));
   crit.addOrder(Order.asc("nature.ordre"));
   crit.addOrder(Order.desc("dateSignature"));
   return crit.list();
 }