Esempio n. 1
0
 public List<Entidad> obtenerEntidadesYaPoliticas(Long idRed) {
   List<Entidad> entidades =
       this.criteriaEntidadesPoliticas(idRed)
           .setProjection(Projections.projectionList().add(Projections.property("entidad")))
           .list();
   return entidades;
 }
Esempio n. 2
0
  public TicketSummary getClosedTicketSummary(Terminal terminal) {

    Session session = null;
    TicketSummary ticketSummary = new TicketSummary();
    try {
      session = getSession();
      Criteria criteria = session.createCriteria(Ticket.class);
      criteria.add(Restrictions.eq(Ticket.PROP_CLOSED, Boolean.TRUE));
      criteria.add(Restrictions.eq(Ticket.PROP_VOIDED, Boolean.FALSE));
      criteria.add(Restrictions.eq(Ticket.PROP_REFUNDED, Boolean.FALSE));
      criteria.add(Restrictions.eq(Ticket.PROP_DRAWER_RESETTED, Boolean.FALSE));
      criteria.add(Restrictions.eq(Ticket.PROP_TERMINAL, terminal));

      ProjectionList projectionList = Projections.projectionList();
      projectionList.add(Projections.count(Ticket.PROP_ID));
      projectionList.add(Projections.sum(Ticket.PROP_TOTAL_AMOUNT));
      criteria.setProjection(projectionList);

      List list = criteria.list();
      if (list.size() > 0) {
        Object[] o = (Object[]) list.get(0);
        ticketSummary.setTotalTicket(((Integer) o[0]).intValue());
        ticketSummary.setTotalPrice(o[1] == null ? 0 : ((Double) o[1]).doubleValue());
      }
      return ticketSummary;
    } finally {
      closeSession(session);
    }
  }
  private DetachedCriteria subquery(SubqueryExpression sqex) {

    String entityName = sqex.getTargetPropertyName();
    String alias = Texts.tos(sqex.getAlias(), null);

    DetachedCriteria dtc;
    if (alias != null) {
      dtc = DetachedCriteria.forEntityName(entityName, alias);
    } else {
      dtc = DetachedCriteria.forEntityName(entityName);
    }
    if (log.isTraceEnabled()) {
      log.trace(
          String.format(
              "Creating detached criteria for entity %s of type %s as %s",
              entityName, sqex.getType(), sqex.getValue()));
    }

    if (sqex.getValue() instanceof Restrictions) {
      Restrictions restr = (Restrictions) sqex.getValue();
      dtc.setProjection(Projections.id());
      dtc.add(parseRestriction(restr));
    } else if (sqex.getValue() instanceof Where) {
      dtc.setProjection(Projections.id());
      DetachedWhereParser whp = new DetachedWhereParser();
      whp.parse((Where) sqex.getValue(), dtc);
    } else {
      throw new IllegalStateException(
          String.format(
              "Subquery must be instance of restrictions or Where, but is %s",
              sqex.getValue().getClass().getName()));
    }

    return dtc;
  }
  @SuppressWarnings("unchecked")
  protected List<Object[]> getSavedSearchDetails(Long savedSearchQueryID, String type) {
    SavedSearchRetriever.AlertType alertType = SavedSearchRetriever.AlertType.valueOf(type);

    DetachedCriteria criteria =
        DetachedCriteria.forClass(UserProfile.class)
            .setProjection(
                Projections.distinct(
                    Projections.projectionList()
                        .add(Projections.property("ss.ID"))
                        .add(Projections.property("email"))
                        .add(Projections.property("ss.searchName"))))
            .createAlias("savedSearches", "ss")
            .createAlias("ss.searchQuery", "q")
            .add(Restrictions.eq("q.ID", savedSearchQueryID));

    if (alertType == SavedSearchRetriever.AlertType.WEEKLY) {
      criteria.add(Restrictions.eq("ss.weekly", true));
    }

    if (alertType == SavedSearchRetriever.AlertType.MONTHLY) {
      criteria.add(Restrictions.eq("ss.monthly", true));
    }

    return (List<Object[]>) hibernateTemplate.findByCriteria(criteria);
  }
Esempio n. 5
0
  private Criteria getCriteriaByThesaurusAndTopConcept(
      Thesaurus thesaurus, boolean topConcept, String like) {
    Criteria criteria = getCurrentSession().createCriteria(ThesaurusConcept.class, "tc");

    if (null != like) {
      criteria =
          getCurrentSession()
              .createCriteria(ThesaurusTerm.class, "tt")
              .add(Restrictions.isNotNull("tt.concept"))
              .createCriteria("concept", "tc", JoinType.RIGHT_OUTER_JOIN);

      criteria
          .setProjection(
              Projections.projectionList()
                  .add(Projections.property("tt.lexicalValue"))
                  .add(Projections.property("tc.identifier").as("identifier")))
          .setResultTransformer(Transformers.aliasToBean(ThesaurusConcept.class));
      conceptNameIsLike(criteria, like);
    }

    selectThesaurus(criteria, thesaurus.getIdentifier());
    selectOrphans(criteria, !topConcept);
    selectNoParents(criteria);
    return criteria;
  }
Esempio n. 6
0
  @Override
  public Long countConceptsAlignedToExtThes(String idThesaurus) {
    DetachedCriteria alignmentCriteria =
        DetachedCriteria.forClass(Alignment.class, "al")
            .add(Restrictions.isNotNull("al.externalTargetThesaurus"))
            .setProjection(
                Projections.projectionList()
                    .add(Projections.property(AL_SOURCE_CONCEPT_IDENTIFIER)));

    DetachedCriteria conceptCriteria =
        DetachedCriteria.forClass(ThesaurusConcept.class, "stc")
            .add(Restrictions.eq("stc.thesaurus.identifier", idThesaurus))
            .setProjection(
                Projections.projectionList().add(Projections.property("stc.identifier")));

    Criteria criteria =
        getCurrentSession()
            .createCriteria(ThesaurusConcept.class, "tc")
            .add(
                Restrictions.and(
                    Subqueries.propertyIn(TC_IDENTIFIER, alignmentCriteria),
                    Subqueries.propertyIn(TC_IDENTIFIER, conceptCriteria)))
            .setProjection(Projections.rowCount());
    return (Long) criteria.list().get(0);
  }
  /**
   * Calculates the sum of all the transactions in a higher date than the end date of the given
   * reconciliation.
   *
   * @param recon Reconciliation.
   * @return Sum of all the transactions in a higher date than the end date of the given
   *     reconciliation.
   */
  private BigDecimal getTransactionsTotalAfterReconciliationEndDate(FIN_Reconciliation recon) {
    BigDecimal balance = BigDecimal.ZERO;
    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.gt(FIN_FinaccTransaction.PROPERTY_TRANSACTIONDATE, recon.getEndingDate()));
      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;
        balance = depositAmt.subtract(paymentAmt);
      }

    } finally {
      OBContext.restorePreviousMode();
    }

    return balance;
  }
Esempio n. 8
0
  @Override
  public int fetchMaxBatchNumber() {
    int maxBatchNumber = 0;
    Session session = null;
    List entities = null;
    try {
      session = sessionFactory.openSession();
      Criteria maxBatchNumberCri = session.createCriteria(CampaignImportModel.class);
      ProjectionList maxBatchNumberProj = Projections.projectionList();
      maxBatchNumberProj.add(Projections.max("batchFileNo"));
      maxBatchNumberCri.setProjection(maxBatchNumberProj);
      entities = maxBatchNumberCri.list();
      maxBatchNumber =
          (null != entities && !entities.isEmpty() && null != entities.get(0))
              ? Integer.valueOf(entities.get(0).toString())
              : 0;
    } catch (HibernateException e) {
      LOGGER.error(" HibernateException fetching max batch number : " + e.getMessage());
    } finally {
      session.close();
    }

    LOGGER.info(" Max Batch Number: " + maxBatchNumber);
    return maxBatchNumber;
  }
  public void prepareDateRange() throws Exception {
    DetachedCriteria criteria = DetachedCriteria.forClass(ConfirmationRecord.class);
    ProjectionList pjl = Projections.projectionList();
    pjl.add(Projections.property("cycleFrom"));
    pjl.add(Projections.property("cycleTo"));
    criteria.setProjection(Projections.distinct(pjl));

    List<?> list = confirmationRecordService.findByCriteria(criteria);
    if (list.size() > 0) {
      Object[] objs = list.toArray();
      selectionCycleFrom = new ArrayList<>();
      selectionCycleFrom.add(new SelectItem(null, "Please Select"));
      cycleTos = new ArrayList<>();

      for (Object obj : objs) {
        if (obj instanceof Object[]) {
          Object[] innerObjs = (Object[]) obj;
          if (innerObjs.length == 2) {
            Date dFrom = DateUtil.convStringToDate(MS_SQL_DATE_PATTERN, innerObjs[0].toString());
            Date dTo = DateUtil.convStringToDate(MS_SQL_DATE_PATTERN, innerObjs[1].toString());
            selectionCycleFrom.add(
                new SelectItem(
                    DateUtil.convDateToString(SIMPLE_DATE_PATTERN, dFrom),
                    DateUtil.convDateToString(DISPLAY_DATE_PATTERN, dFrom)));
            cycleTos.add(DateUtil.convDateToString(SIMPLE_DATE_PATTERN, dTo));
          } else {
            System.err.println("ERR: obj[] length not eq to 2");
          }
        }
      }
    }
  }
  @SuppressWarnings("unchecked")
  private AnnotationView buildAnnotationView(Annotation annotation, boolean loadAllReplies) {
    Object values[];
    try {
      values =
          (Object[])
              hibernateTemplate
                  .findByCriteria(
                      DetachedCriteria.forClass(Article.class)
                          .add(Restrictions.eq("ID", annotation.getArticleID()))
                          .setProjection(
                              Projections.projectionList()
                                  .add(Projections.property("doi"))
                                  .add(Projections.property("title"))),
                      0,
                      1)
                  .get(0);

    } catch (IndexOutOfBoundsException e) {
      // this should never happen
      throw new IllegalStateException(
          "Annotation "
              + annotation.getID()
              + " pointed to an article that didn't exist;"
              + " articleID: "
              + annotation.getArticleID());
    }

    String articleDoi = (String) values[0];
    String articleTitle = (String) values[1];

    return buildAnnotationView(annotation, articleDoi, articleTitle, loadAllReplies);
  }
  public List<UserCountDTO> getCurrentUserCountList(
      String sortField, int order, int start, int gridTableSize, String searchq) throws Exception {
    int count = start;

    List<UserCountDTO> dtoList = null;
    List<UserCountDTO> dtoListCount = new ArrayList<UserCountDTO>();

    Session session = getSession();
    session.getTransaction().begin();

    Criteria criteria =
        session
            .createCriteria(SessionDetails.class, "sessionDetails")
            .add(Restrictions.eq("status", "ACTIVE"));
    criteria.addOrder(Order.asc("SID"));
    criteria.setFirstResult(start).setMaxResults(gridTableSize);
    criteria.setProjection(Projections.projectionList().add(Projections.property("SID").as("sid")));

    dtoList = criteria.setResultTransformer(Transformers.aliasToBean(UserCountDTO.class)).list();
    session.getTransaction().commit();
    session.close();

    if (dtoList.size() > 0) {
      for (UserCountDTO dto : dtoList) {
        dto.setCountId(count + 1);
        dtoListCount.add(dto);
        count += 1;
      }
    }
    return dtoListCount;
  }
  public List<SessionTimeOutDTO> getSessionIDListBySID(Long sid) {
    List<SessionTimeOutDTO> dtoList = null;
    SessionTimeOutDTO dto = null;

    Session session = getSession();
    session.getTransaction().begin();

    Criteria criteria =
        session
            .createCriteria(SessionDetails.class, "sessionDetails")
            .add(Restrictions.eq("SID", sid));
    criteria.setProjection(
        Projections.projectionList()
            .add(Projections.property("SID").as("sid"))
            .add(Projections.property("sessionId").as("sessionId")));
    dto =
        (SessionTimeOutDTO)
            criteria
                .setResultTransformer(Transformers.aliasToBean(SessionTimeOutDTO.class))
                .uniqueResult();

    session.getTransaction().commit();
    session.close();

    dtoList = getList(dto);
    return dtoList;
  }
Esempio n. 13
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();
  }
  @Override
  @Transactional(readOnly = true)
  public AnnotationView[] listAnnotationsNoReplies(
      final Long articleID,
      final Set<AnnotationType> annotationTypes,
      final AnnotationOrder order) {
    if (order == AnnotationOrder.MOST_RECENT_REPLY) {
      throw new IllegalArgumentException(
          "Cannot specify Most Recent Reply order type when replies are not being loaded up");
    }
    // Basic criteria
    DetachedCriteria criteria =
        DetachedCriteria.forClass(Annotation.class)
            .add(Restrictions.eq("articleID", articleID))
            .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    // restrict by type
    if (annotationTypes != null && !annotationTypes.isEmpty()) {
      criteria.add(Restrictions.in("type", annotationTypes));
    }
    switch (order) {
      case OLDEST_TO_NEWEST:
        criteria.addOrder(Order.asc("created"));
        break;
      case NEWEST_TO_OLDEST:
        criteria.addOrder(Order.desc("created"));
        break;
    }
    List annotationResults = hibernateTemplate.findByCriteria(criteria);
    // Don't want to call buildAnnotationView() here because that would involve finding the article
    // title and doi for each annotation,
    // when we only need to do it once. So load up the info we need to build annotation views here
    Object[] articleTitleAndDoi;
    try {
      articleTitleAndDoi =
          (Object[])
              hibernateTemplate
                  .findByCriteria(
                      DetachedCriteria.forClass(Article.class)
                          .add(Restrictions.eq("ID", articleID))
                          .setProjection(
                              Projections.projectionList()
                                  .add(Projections.property("doi"))
                                  .add(Projections.property("title"))),
                      0,
                      1)
                  .get(0);

    } catch (IndexOutOfBoundsException e) {
      throw new IllegalArgumentException("article " + articleID + " didn't exist");
    }
    String articleDoi = (String) articleTitleAndDoi[0];
    String articleTitle = (String) articleTitleAndDoi[1];

    List<AnnotationView> viewResults = new ArrayList<AnnotationView>(annotationResults.size());
    for (Object annotation : annotationResults) {
      viewResults.add(new AnnotationView((Annotation) annotation, articleDoi, articleTitle, null));
    }
    return viewResults.toArray(new AnnotationView[viewResults.size()]);
  }
Esempio n. 15
0
 @SuppressWarnings("unchecked")
 public List<String> listStringByFields(String field) {
   Criteria criteria = getCurrentSession().createCriteria(Titem.class);
   criteria.setProjection(Projections.distinct(Projections.property(field)));
   criteria.addOrder(Order.asc(field));
   List<String> list = criteria.list();
   return list;
 }
 @Override
 public Long getCount(Retirement r, String ks, String js, String eq, String type) {
   Criteria criteria = buildCondition(r, ks, js, eq, type);
   ProjectionList proList = Projections.projectionList(); // 设置投影集合
   proList.add(Projections.property("sfzh"));
   criteria.setProjection(proList);
   return this.getCount(criteria);
 }
Esempio n. 17
0
  public Collection<String> getAllMacs() {
    Criteria criteria = getSession().createCriteria(IpPoolManagement.class);
    ProjectionList projList = Projections.projectionList();
    projList.add(Projections.property(IpPoolManagement.MAC_PROPERTY));

    criteria.setProjection(projList);
    return criteria.list();
  }
Esempio n. 18
0
  @Override
  public int getFormsCount(Person owner) {
    DetachedCriteria criteria = DetachedCriteria.forClass(type);
    criteria.setProjection(Projections.distinct(Projections.countDistinct("formName")));
    if (owner != null) criteria.add(Restrictions.eq("person.personId", owner.getPersonId()));

    return DataAccessUtils.intResult(getHibernateTemplate().findByCriteria(criteria));
  }
Esempio n. 19
0
 @SuppressWarnings("unchecked")
 @Override
 public ResultList getUnique(String key, String query) {
   Criteria criteria = sessionFactory.getCurrentSession().createCriteria(PersonName.class);
   criteria.add(Restrictions.ilike(key, query + "%"));
   criteria.setProjection(Projections.distinct(Projections.property(key)));
   criteria.setMaxResults(20);
   return new ResultList(criteria.list());
 }
Esempio n. 20
0
  @Override
  @SuppressWarnings("unchecked")
  public List<String> getFormNames(Person owner) {
    DetachedCriteria criteria = DetachedCriteria.forClass(type);
    criteria.setProjection(Projections.distinct(Projections.property("formName")));
    if (owner != null) criteria.add(Restrictions.eq("person.personId", owner.getPersonId()));

    return getHibernateTemplate().findByCriteria(criteria);
  }
Esempio n. 21
0
 public List<?> getLoginList() { // 获得管理员和密码的列表
   DetachedCriteria criteria = DetachedCriteria.forClass(Admin.class);
   criteria.setProjection(
       (Projections.projectionList()
           .add(Projections.property("name"))
           .add(Projections.property("password"))));
   List<?> list = getHibernateTemplate().findByCriteria(criteria);
   return list;
 }
 @Transactional
 public Long transactionMaxIdForAccount(OandaAccount account) {
   Criteria criteria =
       getSession()
           .createCriteria(OandaTransaction.class)
           .setProjection(Projections.projectionList().add(Projections.max("transactionId")))
           .add(Restrictions.eq("account", account));
   return (Long) criteria.uniqueResult();
 }
 public List<String> getSharedListUserNames() {
   DetachedCriteria criteria = DetachedCriteria.forClass(CustomSeriesList.class);
   ProjectionList projectionList = Projections.projectionList();
   projectionList.add(Projections.property("userName"));
   criteria.setProjection(Projections.distinct(projectionList));
   List<String> results = new ArrayList<String>();
   results = getHibernateTemplate().findByCriteria(criteria);
   return results;
 }
Esempio n. 24
0
 public Date getUpdatedFromDB() {
   return (Date)
       this.currentSession()
           .createCriteria(Rules.class)
           .setCacheable(true)
           .setCacheRegion(CandlepinCacheRegions.FIVE_SECONDS_QUERY_CACHE)
           .setProjection(Projections.projectionList().add(Projections.max("updated")))
           .uniqueResult();
 }
  /** {@inheritDoc} */
  public long totalLeafStoryPoints(Iteration iteration) {
    Criteria iterationCrit = getCurrentSession().createCriteria(Story.class);

    iterationCrit.add(Restrictions.isEmpty("children"));

    iterationCrit.add(Restrictions.ne("state", StoryState.DEFERRED));

    iterationCrit.setProjection(Projections.projectionList().add(Projections.sum("storyPoints")));
    return sum(0L, (Long) iterationCrit.uniqueResult());
  }
 /** {@inheritDoc} */
 public long totalLeafDoneStoryPoints(Iteration iteration) {
   Criteria iterationCrit = getCurrentSession().createCriteria(Story.class);
   iterationCrit.add(Restrictions.isEmpty("children"));
   iterationCrit.setProjection(Projections.projectionList().add(Projections.sum("storyPoints")));
   iterationCrit.add(Restrictions.eq("state", StoryState.DONE));
   iterationCrit.add(Restrictions.isNotNull("storyPoints"));
   iterationCrit.add(Restrictions.eq("iteration", iteration));
   Long result = (Long) iterationCrit.uniqueResult();
   return result == null ? 0 : result;
 }
 /** {@inheritDoc} */
 public long totalLeafDoneStoryPoints(Project project) {
   Criteria projectCrit = getCurrentSession().createCriteria(Story.class);
   Criteria iterationCrit = getCurrentSession().createCriteria(Story.class);
   this.attachLeafFilters(projectCrit, iterationCrit, project);
   projectCrit.setProjection(Projections.projectionList().add(Projections.sum("storyPoints")));
   iterationCrit.setProjection(Projections.projectionList().add(Projections.sum("storyPoints")));
   projectCrit.add(Restrictions.eq("state", StoryState.DONE));
   iterationCrit.add(Restrictions.eq("state", StoryState.DONE));
   return sum((Long) projectCrit.uniqueResult(), (Long) iterationCrit.uniqueResult());
 }
Esempio n. 28
0
 @SuppressWarnings("unchecked")
 public List<String> getAllHomeDepartments(ObjectStatus status) {
   Criteria criteria = createCriteria();
   if (status != null) criteria.add(Restrictions.eq("objectStatus", status));
   criteria.add(Restrictions.isNotNull("departmentName"));
   criteria.setProjection(
       Projections.projectionList()
           .add(Projections.distinct(Projections.property("departmentName"))));
   return ((List<String>) criteria.list());
 }
  private void setAvgProjection(final Projection projection) {

    // We need to modify the query to pull back not just the average but also
    // the count.  We'll do this by creating a ProjectionList with both the
    // average and the row count.
    final ProjectionList projectionList =
        Projections.projectionList().add(projection).add(Projections.rowCount());

    setCriteriaEvent(new SetProjectionEvent(projectionList));
  }
Esempio n. 30
0
 public List<Facturador> obtenerFacturadoresHabilitados(Long idRed) {
   HibernateEntityManager hem = (HibernateEntityManager) this.getEm().getDelegate();
   List<Facturador> facturadores =
       (List<Facturador>)
           hem.getSession()
               .createCriteria(HabilitacionFactRed.class)
               .add(Restrictions.eq("red", new Red(idRed)))
               .setProjection(Projections.projectionList().add(Projections.property("facturador")))
               .list();
   return facturadores;
 }