예제 #1
0
  public PageList<Dashboard> findDashboardsByCriteria(Subject subject, DashboardCriteria criteria) {
    if (criteria.isInventoryManagerRequired()) {
      if (!authorizationManager.isInventoryManager(subject)) {
        throw new PermissionException(
            "Subject ["
                + subject.getName()
                + "] requires InventoryManager permission for requested query criteria.");
      }

      Integer ownerId = criteria.getFilterOwnerId();
      if (null != ownerId && 0 == ownerId.intValue()) {
        criteria.addFilterOwnerId(null);
      }
    } else {
      criteria.addFilterOwnerId(subject.getId());
    }

    if (null == criteria.getFilterCategory()) {
      criteria.addFilterCategory(DashboardCategory.INVENTORY);
    }

    CriteriaQueryGenerator generator = new CriteriaQueryGenerator(subject, criteria);

    CriteriaQueryRunner<Dashboard> queryRunner =
        new CriteriaQueryRunner<Dashboard>(criteria, generator, entityManager);
    return queryRunner.execute();
  }
예제 #2
0
파일: SearchBar.java 프로젝트: galderz/rhq
  private void activeSavedSearchByIdOrName(Integer savedSearchId, String savedSearchName) {
    Subject subject = UserSessionManager.getSessionSubject();
    SavedSearchCriteria criteria = new SavedSearchCriteria();
    criteria.addFilterSubjectId(subject.getId());
    criteria.addFilterId(savedSearchId); // null OK
    criteria.addFilterName(savedSearchName); // null OK

    GWTServiceLookup.getSearchService()
        .findSavedSearchesByCriteria(
            criteria,
            new AsyncCallback<List<SavedSearch>>() {
              @Override
              public void onFailure(Throwable caught) {
                CoreGUI.getErrorHandler().handleError("Failure to select saved search", caught);
              }

              @Override
              public void onSuccess(List<SavedSearch> results) {
                if (results.size() != 1) {
                  CoreGUI.getMessageCenter()
                      .notify(new Message("Error selecting saved search", Severity.Error));
                } else {
                  SavedSearch savedSearch = results.get(0);
                  activateSavedSearch(savedSearch);
                }
              }
            });
  }
예제 #3
0
 /** Throws a permission exception if the user is not allowed to access this functionality. */
 private void hasPermission() {
   Subject subject = EnterpriseFacesContextUtility.getSubject();
   if (!LookupUtil.getAuthorizationManager()
       .hasGlobalPermission(subject, Permission.MANAGE_INVENTORY)) {
     throw new PermissionException(
         "User ["
             + subject.getName()
             + "] does not have the proper permissions to view or manage agents");
   }
 }
  @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
  public MeasurementBaseline calculateAutoBaselineForGroupInNewTransaction(
      Subject subject, int groupId, int definitionId, long startDate, long endDate, boolean save)
      throws BaselineCreationException, MeasurementNotFoundException {

    if (save
        && !authorizationManager.hasGroupPermission(
            subject, Permission.MANAGE_MEASUREMENTS, groupId)) {
      throw new PermissionException(
          "User["
              + subject.getName()
              + "] does not have permission to calculate and set baselines for group[id="
              + groupId
              + "]");
    }

    MeasurementBaseline baseline;
    try {
      baseline = calculateBaselineForGroup(groupId, definitionId, true, startDate, endDate, save);
      if (save) {
        // We have changed the baseline information for the schedule, so remove the now outdated OOB
        // info.
        oobManager.removeOOBsForGroupAndDefinition(subject, groupId, definitionId);
      }
    } catch (DataNotAvailableException e) {
      throw new BaselineCreationException(
          "Error fetching data for baseline calculation for group[id="
              + groupId
              + "], definition[id="
              + definitionId
              + "]");
    }

    return baseline;
  }
예제 #5
0
  public void removeDashboard(Subject subject, int dashboardId) {

    Dashboard toDelete = entityManager.find(Dashboard.class, dashboardId);

    if (!authorizationManager.hasGlobalPermission(subject, Permission.MANAGE_SETTINGS)
        && toDelete.getOwner().getId() != subject.getId()) {
      throw new PermissionException("You may only delete dashboards you own.");
    }

    entityManager.remove(toDelete);
  }
예제 #6
0
 public Dashboard storeDashboard(Subject subject, Dashboard dashboard) {
   Dashboard d = null;
   if ((d = entityManager.find(Dashboard.class, dashboard.getId())) == null) {
     dashboard.setOwner(subject);
     entityManager.persist(dashboard);
     return dashboard;
   } else {
     if (!authorizationManager.hasGlobalPermission(subject, Permission.MANAGE_SETTINGS)
         && d.getOwner().getId() != subject.getId()) {
       throw new PermissionException("You may only alter dashboards you own.");
     }
     return entityManager.merge(dashboard);
   }
 }
  @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;
  }
  protected Dashboard getDefaultDashboard() {
    Subject sessionSubject = UserSessionManager.getSessionSubject();
    Resource resource = resourceComposite.getResource();

    Dashboard dashboard = new Dashboard();

    dashboard.setName(DASHBOARD_NAME_PREFIX + sessionSubject.getId() + "_" + resource.getId());
    dashboard.setCategory(DashboardCategory.RESOURCE);
    dashboard.setResource(resource);
    dashboard.setColumns(2);

    // TODO, add real portlets
    // set leftmost column and let the rest be equally divided
    dashboard.setColumnWidths("40%");
    dashboard.getConfiguration().put(new PropertySimple(Dashboard.CFG_BACKGROUND, "#F1F2F3"));

    // figure out which portlets to display and how
    HashMap<String, String> resKeyNameMap =
        DashboardView.processPortletNameMapForResource(resourceComposite);
    int colLeft = 0;
    int colRight = 1;
    int rowLeft = 0;
    int rowRight = 0;
    // Left Column
    if (resKeyNameMap.containsKey(
        ResourceMetricsPortlet.KEY)) { // measurments top left if available
      DashboardPortlet measurements =
          new DashboardPortlet(ResourceMetricsPortlet.NAME, ResourceMetricsPortlet.KEY, 220);
      dashboard.addPortlet(measurements, colLeft, rowLeft++);
      resKeyNameMap.remove(ResourceMetricsPortlet.KEY);
    }

    // right Column(approx 60%. As larger more room to display table and N rows.)
    if (resKeyNameMap.containsKey(ResourceAlertsPortlet.KEY)) { // alerts top right if available
      DashboardPortlet alerts =
          new DashboardPortlet(ResourceAlertsPortlet.NAME, ResourceAlertsPortlet.KEY, 220);
      dashboard.addPortlet(alerts, colRight, rowRight++);
      resKeyNameMap.remove(ResourceAlertsPortlet.KEY);
    }
    if (resKeyNameMap.containsKey(ResourceOperationsPortlet.KEY)) { // operations if available
      DashboardPortlet ops =
          new DashboardPortlet(ResourceOperationsPortlet.NAME, ResourceOperationsPortlet.KEY, 220);
      dashboard.addPortlet(ops, colRight, rowRight++);
      resKeyNameMap.remove(ResourceOperationsPortlet.KEY);
    }
    if (resKeyNameMap.containsKey(
        ResourceConfigurationUpdatesPortlet.KEY)) { // configuration if available
      DashboardPortlet ops =
          new DashboardPortlet(
              ResourceConfigurationUpdatesPortlet.NAME,
              ResourceConfigurationUpdatesPortlet.KEY,
              220);
      dashboard.addPortlet(ops, colRight, rowRight++);
      resKeyNameMap.remove(ResourceConfigurationUpdatesPortlet.KEY);
    }

    // Fill out left column(typically smaller portlets) then alternate cols with remaining
    boolean displayLeft = false;
    for (String key : resKeyNameMap.keySet()) {
      DashboardPortlet portlet = new DashboardPortlet(resKeyNameMap.get(key), key, 100);
      if (rowLeft < 4) {
        dashboard.addPortlet(portlet, colLeft, rowLeft++);
      } else { // alternate
        if (!displayLeft) {
          dashboard.addPortlet(portlet, colRight, rowRight++);
        } else {
          dashboard.addPortlet(portlet, colLeft, rowLeft++);
        }
        // toggle
        displayLeft = !displayLeft;
      }
    }

    return dashboard;
  }
예제 #9
0
  public PageList<CallTimeDataComposite> findCallTimeDataForContext(
      Subject subject,
      EntityContext context,
      long beginTime,
      long endTime,
      String destination,
      PageControl pageControl) {

    // lookup measurement definition id

    CallTimeDataCriteria criteria = new CallTimeDataCriteria();
    criteria.addFilterBeginTime(beginTime);
    criteria.addFilterEndTime(endTime);
    if (destination != null && !destination.trim().equals("")) {
      criteria.addFilterDestination(destination);
    }

    pageControl.initDefaultOrderingField(
        "SUM(calltimedatavalue.total)/SUM(calltimedatavalue.count)",
        PageOrdering.DESC); // only set if no ordering yet specified
    pageControl.addDefaultOrderingField(
        "calltimedatavalue.key.callDestination",
        PageOrdering.ASC); // add this to sort, if not already specified
    criteria.setPageControl(pageControl);

    // criteria.addSortAverage(PageOrdering.DESC);

    if (context.type == EntityContext.Type.Resource) {
      criteria.addFilterResourceId(context.resourceId);
    } else if (context.type == EntityContext.Type.ResourceGroup) {
      criteria.addFilterResourceGroupId(context.groupId);
    } else if (context.type == EntityContext.Type.AutoGroup) {
      criteria.addFilterAutoGroupParentResourceId(context.parentResourceId);
      criteria.addFilterAutoGroupResourceTypeId(context.resourceTypeId);
    }

    CriteriaQueryGenerator generator = new CriteriaQueryGenerator(subject, criteria);
    ;
    String replacementSelectList =
        "" //
            + " new org.rhq.core.domain.measurement.calltime.CallTimeDataComposite( " //
            + "   calltimedatavalue.key.callDestination, " //
            + "   MIN(calltimedatavalue.minimum), " //
            + "   MAX(calltimedatavalue.maximum), " //
            + "   SUM(calltimedatavalue.total), " //
            + "   SUM(calltimedatavalue.count), " //
            + "   SUM(calltimedatavalue.total) / SUM(calltimedatavalue.count) ) ";
    generator.alterProjection(replacementSelectList);
    generator.setGroupByClause("calltimedatavalue.key.callDestination");

    if (authorizationManager.isInventoryManager(subject) == false) {
      generator.setAuthorizationResourceFragment(
          CriteriaQueryGenerator.AuthorizationTokenType.RESOURCE,
          "key.schedule.resource",
          subject.getId());
    }

    // log.info(generator.getParameterReplacedQuery(false));
    // log.info(generator.getParameterReplacedQuery(true));

    CriteriaQueryRunner<CallTimeDataComposite> queryRunner =
        new CriteriaQueryRunner<CallTimeDataComposite>(criteria, generator, entityManager);
    PageList<CallTimeDataComposite> results = queryRunner.execute();
    return results;
  }