コード例 #1
0
  @SuppressWarnings("unchecked")
  public List<MeasurementBaseline> findBaselinesForResource(Subject subject, int resourceId) {
    if (authorizationManager.canViewResource(subject, resourceId) == false) {
      throw new PermissionException(
          "User["
              + subject.getName()
              + " ] does not have permission to view baselines for resource[id="
              + resourceId
              + "]");
    }

    Query query = entityManager.createNamedQuery(MeasurementBaseline.QUERY_FIND_BY_RESOURCE);
    query.setParameter("resourceId", resourceId);
    List<MeasurementBaseline> results = query.getResultList();
    return results;
  }
コード例 #2
0
  @SuppressWarnings("unchecked")
  public PageList<CallTimeDataComposite> findCallTimeDataForResource(
      Subject subject, int scheduleId, long beginTime, long endTime, PageControl pageControl) {
    pageControl.initDefaultOrderingField(
        "SUM(value.total)/SUM(value.count)",
        PageOrdering.DESC); // only set if no ordering yet specified
    pageControl.addDefaultOrderingField(
        "key.callDestination", PageOrdering.ASC); // add this to sort, if not already specified

    MeasurementSchedule schedule = entityManager.find(MeasurementSchedule.class, scheduleId);
    int resourceId = schedule.getResource().getId();
    if (authorizationManager.canViewResource(subject, resourceId) == false) {
      throw new PermissionException(
          "User ["
              + subject
              + "] does not have permission to view call time data for measurementSchedule[id="
              + scheduleId
              + "] and resource[id="
              + resourceId
              + "]");
    }

    String query = CallTimeDataValue.QUERY_FIND_COMPOSITES_FOR_RESOURCE;

    Query queryWithOrderBy =
        PersistenceUtility.createQueryWithOrderBy(entityManager, query, pageControl);
    Query queryCount = PersistenceUtility.createCountQuery(this.entityManager, query);

    queryWithOrderBy.setParameter("scheduleId", scheduleId);
    queryWithOrderBy.setParameter("beginTime", beginTime);
    queryWithOrderBy.setParameter("endTime", endTime);

    List<CallTimeDataComposite> results = queryWithOrderBy.getResultList();

    queryCount.setParameter("scheduleId", scheduleId);
    queryCount.setParameter("beginTime", beginTime);
    queryCount.setParameter("endTime", endTime);

    // Because of the use of the GROUP BY clause, the result list count will be returned as
    // the number of rows, rather than as a single number.
    long count = queryCount.getResultList().size();

    return new PageList<CallTimeDataComposite>(results, (int) count, pageControl);
  }