Пример #1
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);
  }
  @Scheduled(fixedDelay = 60000)
  public void changeSessionStatus() {

    List<CurrentUsersDTO> allList = null;
    List<CurrentUsersDTO> activeList = null;

    String currentTime = getTime();
    String beforeTime = getBeforeTime();
    String beforeHeartBeatTime = getBeforeHeartBeatTime();

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

    Criteria criteria =
        session
            .createCriteria(SessionDetails.class, "sessionDetails")
            .add(
                Restrictions.between(
                    "sessionDetails.heartBeatTime", beforeHeartBeatTime, currentTime))
            .add(Restrictions.between("sessionDetails.lastAccessTime", beforeTime, currentTime));
    criteria.addOrder(Order.asc("SID"));
    criteria.setProjection(
        Projections.projectionList()
            .add(Projections.property("SID").as("sid"))
            .add(Projections.property("lastAccessTime").as("lastAccessTime")));
    activeList =
        criteria.setResultTransformer(Transformers.aliasToBean(CurrentUsersDTO.class)).list();

    Criteria criteria1 = session.createCriteria(SessionDetails.class, "sessionDetails");
    criteria1.addOrder(Order.asc("SID"));
    criteria1.setProjection(
        Projections.projectionList()
            .add(Projections.property("SID").as("sid"))
            .add(Projections.property("lastAccessTime").as("lastAccessTime")));
    allList =
        criteria1.setResultTransformer(Transformers.aliasToBean(CurrentUsersDTO.class)).list();

    for (CurrentUsersDTO dto : allList) {
      try {
        SessionDetails sd = getById(dto.getSid());
        sd.setStatus("INACTIVE");
        saveSessionDetails(sd);
      } catch (Exception e) {
        System.out.println("E :" + e);
      }
    }

    for (CurrentUsersDTO dto : activeList) {
      try {
        SessionDetails sd = getById(dto.getSid());
        sd.setStatus("ACTIVE");
        saveSessionDetails(sd);
      } catch (Exception e) {
        System.out.println("E :" + e);
      }
    }
    session.getTransaction().commit();
    session.close();
  }
 /** {@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());
 }
Пример #4
0
  @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;
  }
Пример #7
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;
  }
Пример #8
0
 public List<Entidad> obtenerEntidadesYaPoliticas(Long idRed) {
   List<Entidad> entidades =
       this.criteriaEntidadesPoliticas(idRed)
           .setProjection(Projections.projectionList().add(Projections.property("entidad")))
           .list();
   return entidades;
 }
Пример #9
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);
    }
  }
Пример #10
0
  private List<HashMap<String, Object>> getQuestionAnswerData(ExamResult examResult) {
    DetachedCriteria criteria =
        DetachedCriteria.forClass(ExamResultAnswer.class, "examResultAnswer");
    criteria.createAlias("examResultAnswer.question", "question");
    criteria.createAlias("examResultAnswer.answer1", "answer1");
    criteria.createAlias("examResultAnswer.answer2", "answer2");
    criteria.createAlias("examResultAnswer.answer3", "answer3");
    criteria.createAlias("examResultAnswer.answer4", "answer4");

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("question.questionId"), "questionId");
    projectionList.add(Projections.property("question.questionText"), "questionText");
    projectionList.add(Projections.property("answer1.answerId"), "answer1Id");
    projectionList.add(Projections.property("answer1.answerText"), "answer1Text");
    projectionList.add(Projections.property("answer2.answerId"), "answer2Id");
    projectionList.add(Projections.property("answer2.answerText"), "answer2Text");
    projectionList.add(Projections.property("answer3.answerId"), "answer3Id");
    projectionList.add(Projections.property("answer3.answerText"), "answer3Text");
    projectionList.add(Projections.property("answer4.answerId"), "answer4Id");
    projectionList.add(Projections.property("answer4.answerText"), "answer4Text");
    projectionList.add(
        Projections.property("examResultAnswer.examResultAnswerId"), "examResultAnswerId");
    projectionList.add(Projections.property("examResultAnswer.answerId"), "answerId");
    criteria.setProjection(projectionList);
    criteria.add(Restrictions.eq("examResultAnswer.examResultId", examResult.getExamResultId()));
    criteria.addOrder(Order.asc("examResultAnswer.ordinal"));
    criteria.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);

    return basicFinderService.findByCriteria(criteria);
  }
Пример #11
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();
  }
Пример #12
0
  @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);
  }
Пример #13
0
  private Criteria buildCriteria(QueryModel queryModel) {
    Criteria criteria = getCurrentSession().createCriteria(persistentClass);

    if (queryModel.getConditions() != null) {
      for (Condition condition : queryModel.getConditions()) {
        criteria.add((Criterion) condition.getConstraint());
      }
    }

    for (Map.Entry<String, List<Condition>> associationCriteriaEntry :
        queryModel.getAssociationConditions().entrySet()) {
      Criteria associationCriteria = criteria.createCriteria(associationCriteriaEntry.getKey());

      criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

      for (Condition condition : associationCriteriaEntry.getValue()) {
        associationCriteria.add((Criterion) condition.getConstraint());
      }
    }

    if (queryModel.getProjection() != null) {
      ProjectionList projectionList = Projections.projectionList();

      projectionList.add(
          (org.hibernate.criterion.Projection) queryModel.getProjection().getDetails());

      criteria.setProjection(projectionList);
    }

    return criteria;
  }
Пример #14
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;
  }
  private static void populateHibernateDetachedCriteria(
      AbstractHibernateQuery hibernateQuery,
      org.hibernate.criterion.DetachedCriteria detachedCriteria,
      QueryableCriteria<?> queryableCriteria) {
    List<Query.Criterion> criteriaList = queryableCriteria.getCriteria();
    for (Query.Criterion criterion : criteriaList) {
      Criterion hibernateCriterion =
          HibernateQuery.HIBERNATE_CRITERION_ADAPTER.toHibernateCriterion(
              hibernateQuery, criterion, null);
      if (hibernateCriterion != null) {
        detachedCriteria.add(hibernateCriterion);
      }
    }

    List<Query.Projection> projections = queryableCriteria.getProjections();
    ProjectionList projectionList = Projections.projectionList();
    for (Query.Projection projection : projections) {
      Projection hibernateProjection =
          new HibernateProjectionAdapter(projection).toHibernateProjection();
      if (hibernateProjection != null) {
        projectionList.add(hibernateProjection);
      }
    }
    detachedCriteria.setProjection(projectionList);
  }
  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");
          }
        }
      }
    }
  }
  /**
   * 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;
  }
  @SuppressWarnings("unchecked")
  @Override
  public Collection<FuncionarioAreaTrabajoDTO> consultarFuncionarioAreaTrabajoPorAreaTrabajo(
      Integer codigoAreaTrabajo, String userId, Integer codigoCompania, String usuarioSesion)
      throws SICException {
    try {

      Criteria criteria =
          sessionFactory.getCurrentSession().createCriteria(FuncionarioAreaTrabajoDTO.class);
      criteria.setProjection(
          Projections.projectionList()
              .add(Projections.property("usuarioDTO.userId"), "funcionarioDTO.usuarioDTO.userId")
              .add(
                  Projections.property("usuarioDTO.userCompleteName"),
                  "funcionarioDTO.usuarioDTO.userCompleteName")
              .add(
                  Projections.property("usuarioDTO.userName"), "funcionarioDTO.usuarioDTO.userName")
              .add(
                  Projections.property("areaTrabajoDTO.nombreAreaTrabajo"),
                  "areaTrabajoDTO.nombreAreaTrabajo")
              .add(Projections.property("id.codigoCompania"), "id.codigoCompania")
              .add(Projections.property("id.codigoFuncionario"), "id.codigoFuncionario")
              .add(Projections.property("id.codigoAreaTrabajo"), "id.codigoAreaTrabajo"));

      criteria.createAlias("funcionarioDTO", "funcionarioDTO");
      criteria.createAlias("funcionarioDTO.usuarioDTO", "usuarioDTO");

      criteria.createAlias("areaTrabajoDTO", "areaTrabajoDTO");

      criteria.add(Restrictions.eq("estado", SICConstantes.ESTADO_ACTIVO_LITERAL));
      criteria.add(
          Restrictions.eq("funcionarioDTO.estadoFuncionario", SICConstantes.ESTADO_ACTIVO_LITERAL));
      criteria.add(
          Restrictions.eq("areaTrabajoDTO.estadoAreaTrabajo", SICConstantes.ESTADO_ACTIVO_LITERAL));

      criteria.add(Restrictions.eq("id.codigoCompania", codigoCompania));
      criteria.add(Restrictions.eq("areaTrabajoDTO.id.codigoAreaTrabajo", codigoAreaTrabajo));
      criteria.add(Restrictions.ne("usuarioDTO.userName", usuarioSesion));

      // si el usuario ingresa un nombre o usuario de un funcionario
      if (StringUtils.isNotEmpty(userId)) {
        Disjunction disjunction = Restrictions.disjunction();
        disjunction.add(Restrictions.ilike("usuarioDTO.userName", userId, MatchMode.ANYWHERE));
        disjunction.add(
            Restrictions.ilike("usuarioDTO.userCompleteName", userId, MatchMode.ANYWHERE));
        criteria.add(disjunction);
      }
      criteria.setResultTransformer(new DtoResultTransformer(FuncionarioAreaTrabajoDTO.class));

      Collection<FuncionarioAreaTrabajoDTO> funcionarioAreaTrabajoDTOCol = criteria.list();

      return funcionarioAreaTrabajoDTOCol;

    } catch (HibernateException e) {
      throw new SICException("Error consultarFuncionarioAreaTrabajoPorAreaTrabajo: ", e);
    } catch (Exception e) {
      throw new SICException("Error consultarFuncionarioAreaTrabajoPorAreaTrabajo ", e);
    }
  }
Пример #19
0
  @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()]);
  }
Пример #20
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();
  }
 @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);
 }
  /** {@inheritDoc} */
  public long totalRootStoryPoints(Project project) {
    Criteria projectCrit = getCurrentSession().createCriteria(Story.class);
    Criteria iterationCrit = getCurrentSession().createCriteria(Story.class);
    Criteria standaloneIterationCrit = getCurrentSession().createCriteria(Story.class);
    this.attachRootFilters(projectCrit, iterationCrit, standaloneIterationCrit, project.getId());

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

    projectCrit.setProjection(Projections.projectionList().add(Projections.sum("storyPoints")));
    iterationCrit.setProjection(Projections.projectionList().add(Projections.sum("storyPoints")));
    standaloneIterationCrit.setProjection(
        Projections.projectionList().add(Projections.sum("storyPoints")));
    long sum = sum((Long) projectCrit.uniqueResult(), (Long) iterationCrit.uniqueResult());
    return sum((Long) standaloneIterationCrit.uniqueResult(), sum);
  }
Пример #23
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;
 }
 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;
 }
Пример #25
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();
 }
 @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();
 }
  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));
  }
  /** {@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());
  }
Пример #29
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());
 }
 /** {@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;
 }