コード例 #1
0
 /** @see com.ixora.rms.ui.artefacts.ArtefactSelectorPanel#handleRemoveArtefact() */
 protected void handleRemoveArtefact() {
   try {
     JTable table = getJTableArtefacts();
     int[] sel = table.getSelectedRows();
     if (Utils.isEmptyArray(sel)) {
       return;
     }
     for (int idx : sel) {
       DashboardInfo gi = (DashboardInfo) table.getModel().getValueAt(idx, 1);
       DashboardMap map = fDashboardRepository.getDashboardMap(fContext);
       if (map == null) {
         logger.error("Couldn't find query gruop map for context: " + this.fContext);
         return;
       }
       // ask for confitmation
       if (!UIUtils.getBooleanOkCancelInput(
           this.fViewContainer.getAppFrame(),
           MessageRepository.get(Msg.TITLE_CONFIRM_REMOVE_DASHBOARD),
           MessageRepository.get(
               Msg.TEXT_CONFIRM_REMOVE_DASHBOARD, new String[] {gi.getTranslatedName()}))) {
         return;
       }
       // remove the dashboard only for the current fSUOVersion
       map.remove(gi.getDashboard().getName(), fSUOVersion);
       fDashboardRepository.setDashboardMap(fContext, map);
       fDashboardRepository.save();
       // update model
       fSessionData.getDashboardHelper().removeDashboard(fContext, gi.getDashboard().getName());
       // refresh table model
       refreshTableModel();
     }
   } catch (Exception ex) {
     UIExceptionMgr.userException(ex);
   }
 }
コード例 #2
0
  /**
   * Sets the flag for the given dashboard.
   *
   * @param flag
   * @param context
   * @param dbName
   * @param value
   * @param commit
   */
  public void setDashboardFlag(
      int flag, ResourceId context, String dbName, boolean value, boolean commit) {
    // get views first
    DataViewInfoData[] data = getDataViewInfoData(context, dbName);
    if (data != null) {
      ResourceId rid;
      DataViewInfoData d;
      DataViewInfo dvinfo;
      for (int i = 0; i < data.length; i++) {
        d = data[i];
        dvinfo = d.getInfo();
        rid = d.getContext();
        model
            .getDataViewHelper()
            .setDataViewFlag(flag, rid, dvinfo.getDataView().getName(), value, commit);
      }
    }

    // now work with counters
    CounterInfoData[] counters = getCounterInfoData(context, dbName);
    if (!Utils.isEmptyArray(counters)) {
      // check that all counters are present
      for (CounterInfoData cid : counters) {
        ResourceInfo cInfo = model.getCounterHelper().getCounterInfo(cid.counterId);
        if (cInfo != null) {
          switch (flag) {
            case DashboardInfo.ENABLED:
              // if enabled is false then change the flag only for
              // counters which are not committed (this is to avoid a query
              // disabling the commited counters of another one)
              // @see QueryRealizerLiveSession for an excuse
              if (value || !cInfo.getCounterInfo().isCommitted()) {
                model
                    .getCounterHelper()
                    .setCounterFlag(cid.counterId, CounterInfo.ENABLED, value, true);
              }
              break;
            case DashboardInfo.ACTIVATED:
              model
                  .getCounterHelper()
                  .setCounterFlag(cid.counterId, CounterInfo.ACTIVATED, value, true);
          }
        }
      }
    }

    ArtefactInfoContainerImpl ac = model.getArtefactContainerImplForResource(context, true);
    if (ac == null) {
      if (logger.isTraceEnabled()) {
        logger.error("Couldn't find container for dashboard " + context);
      }
      return;
    }

    // enable the dashboard
    ac.setDashboardFlag(flag, dbName, value, commit);
    // refresh context node
    model.refreshNode(context);
  }
コード例 #3
0
  /** @see com.ixora.rms.ui.artefacts.ArtefactSelectorPanel#handlePlotArtefact() */
  protected void handlePlotArtefact() {
    try {
      final JTable table = getJTableArtefacts();
      final int[] sel = table.getSelectedRows();
      if (Utils.isEmptyArray(sel)) {
        return;
      }

      this.fViewContainer
          .getAppWorker()
          .runJobSynch(
              new UIWorkerJobDefault(
                  fViewContainer.getAppFrame(),
                  Cursor.WAIT_CURSOR,
                  MessageRepository.get(Msg.TEXT_PLOTTING_DASHBOARD)) {
                public void work() throws Exception {
                  for (int idx : sel) {
                    DashboardInfo di = (DashboardInfo) table.getModel().getValueAt(idx, 1);

                    Dashboard dtls = di.getDashboard();
                    if (dtls == null) {
                      logger.error("No dashboard");
                      return;
                    }

                    DataViewId[] members = dtls.getViews();
                    ResourceId[] counters = dtls.getCounters();
                    if (Utils.isEmptyArray(members) && Utils.isEmptyArray(counters)) {
                      // TODO localize
                      throw new RMSException(
                          "Dashboard " + di.getTranslatedName() + " has no data views.");
                    }

                    if (!di.getFlag(DataViewInfo.ENABLED) && di.isCommitted()) {
                      // enable it first
                      ((DashboardTableModel) fTableModelArtefacts).enableDashboard(idx);
                      applyChangesLocally();
                    }

                    callback.plot(new DashboardId(fContext, dtls.getName()));
                  }
                }

                public void finished(Throwable ex) {
                  ; // nothing, synched job
                }
              });
    } catch (Exception ex) {
      UIExceptionMgr.userException(ex);
    }
  }
コード例 #4
0
  /**
   * @see
   *     com.ixora.rms.client.model.DashboardModelHelper#isDashboardReady(com.ixora.rms.internal.ResourceId,
   *     com.ixora.rms.repository.QueryGroup)
   */
  public boolean isDashboardReady(ResourceId context, Dashboard dashboard) {
    boolean ready = true;
    ResourceId[] counters = dashboard.getCounters();
    if (!Utils.isEmptyArray(counters)) {
      // check that all counters are present
      for (ResourceId c : counters) {
        if (context != null) {
          c = c.complete(context);
        }
        CounterInfo cinfo = model.getCounterInfo(c, true);
        if (cinfo == null) {
          return false;
        }
      }
    }

    // now check that all views are ready
    DataViewId[] views = dashboard.getViews();
    if (ready && !Utils.isEmptyArray(views)) {
      // find now query info on every member query
      for (DataViewId m : views) {
        if (context != null) {
          m = m.complete(context);
        }
        DataViewInfo dvinfo = model.getDataViewInfo(m, true);
        if (dvinfo == null) {
          return false;
        }
        if (!model
            .getQueryHelper()
            .isQueryReady(m.getContext(), dvinfo.getDataView().getQueryDef())) {
          return false;
        }
      }
    }
    return ready;
  }
コード例 #5
0
  /** @param context */
  public void rollbackDashboards(ResourceId context) {
    // rollback data views
    DataViewInfoData[] data = getDataViewInfoData(context);
    if (data != null) {
      ResourceId rid;
      DataViewInfoData d;
      DataViewInfo dvinfo;
      for (int i = 0; i < data.length; i++) {
        d = data[i];
        dvinfo = d.getInfo();
        rid = d.getContext();
        if (!dvinfo.isCommitted()) {
          model.getDataViewHelper().rollbackDataView(rid, dvinfo.getDataView().getName());
        }
      }
    }

    // rollback counters
    CounterInfoData[] counters = getCounterInfoData(context);
    if (!Utils.isEmptyArray(counters)) {
      // check that all counters are present
      for (CounterInfoData cid : counters) {
        model.getCounterHelper().rollbackCounter(cid.counterId, true);
      }
    }

    ArtefactInfoContainerImpl qc = model.getArtefactContainerImplForResource(context, true);
    if (qc == null) {
      if (logger.isTraceEnabled()) {
        logger.error("Couldn't find container for: " + context);
      }
      return;
    }
    Collection<DashboardInfoImpl> dis = qc.getDashboardInfoImpl();
    if (!Utils.isEmptyCollection(dis)) {
      for (DashboardInfoImpl di : dis) {
        di.rollback();
      }
    }
  }
コード例 #6
0
  /** Applies only changes made to the current context. */
  private void applyChangesLocally() {
    // get all dashboards  to realize
    Collection<DashboardInfo> dashboards = getDashboardTableModel().getDashboardsToRealize();
    if (dashboards != null) {
      for (DashboardInfo dinfo : dashboards) {
        // register views with the query realizer
        DataViewId[] views = dinfo.getDashboard().getViews();
        if (!Utils.isEmptyArray(views)) {
          for (DataViewId view : views) {
            if (fContext != null) {
              view = view.complete(fContext);
            }
            // ask the locator for info on the required data view
            final SessionDataViewInfo dvInfo = this.fArtefactInfoLocator.getDataViewInfo(view);
            if (dvInfo == null) {
              if (logger.isTraceEnabled()) {
                logger.error("Couldn't find data view info for: " + view + ". Skipping...");
              }
              continue;
            }
            final DataViewId fv = view;
            // Note: this method is reading from the session model
            // and as a result it can only be used safely from
            // the event dispatching thread
            this.fViewContainer
                .getAppWorker()
                .runJobSynch(
                    new UIWorkerJobDefault(
                        fViewContainer.getAppFrame(),
                        Cursor.WAIT_CURSOR,
                        MessageRepository.get(
                            Msg.TEXT_REALIZING_DATAVIEW,
                            new String[] {dvInfo.getTranslatedName()})) {
                      public void work() throws Exception {
                        fQueryRealizer.realizeQuery(
                            fv.getContext(),
                            dvInfo.getDataView().getQueryDef(),
                            new QueryRealizer.Callback() {
                              public boolean acceptIncreaseInMonitoringLevel(
                                  List<ResourceInfo> counters) {
                                boolean ret =
                                    UIUtils.getBooleanYesNoInput(
                                        fViewContainer.getAppFrame(),
                                        MessageRepository.get(
                                            Msg.TITLE_CONFIRM_MONITORING_LEVEL_INCREASE),
                                        MessageRepository.get(
                                            Msg
                                                .TEXT_CONFIRM_MONITORING_LEVEL_INCREASE_FOR_DATA_VIEW,
                                            new String[] {dvInfo.getTranslatedName()}));
                                if (!ret) {
                                  // undo changes
                                  fSessionData
                                      .getDataViewHelper()
                                      .rollbackDataView(fv.getContext(), fv.getName());
                                }
                                return ret;
                              }
                            });
                      }

                      public void finished(Throwable ex) {}
                    });
          }
        }
        // register counters with the query realizer
        // for every counter create a query and register it
        ResourceId[] counters = dinfo.getDashboard().getCounters();
        if (!Utils.isEmptyArray(counters)) {
          for (ResourceId counter : counters) {
            if (fContext != null) {
              counter = counter.complete(fContext);
            }
            final SingleCounterQueryDef query = new SingleCounterQueryDef(counter, null, null);
            final ResourceId counterContext = counter.getSubResourceId(ResourceId.ENTITY);

            // add query to the model
            fSessionData.getQueryHelper().addQuery(counterContext, query);

            String translatedCounterName = counter.getCounterId().toString();
            // ask the locator for info on this counter
            SessionResourceInfo rInfo = this.fArtefactInfoLocator.getResourceInfo(counter);
            if (rInfo != null && rInfo.getCounterInfo() != null) {
              translatedCounterName = rInfo.getCounterInfo().getTranslatedName();
            }
            final String finalTranslatedCounterName = translatedCounterName;
            final ResourceId fc = counter;
            // Note: this method is reading from the session model
            // and as a result it can only be used safely from
            // the event dispatching thread
            this.fViewContainer
                .getAppWorker()
                .runJobSynch(
                    new UIWorkerJobDefault(
                        fViewContainer.getAppFrame(),
                        Cursor.WAIT_CURSOR,
                        MessageRepository.get(
                            Msg.TEXT_REALIZING_DATAVIEW, new String[] {translatedCounterName})) {
                      public void work() throws Exception {
                        fQueryRealizer.realizeQuery(
                            counterContext,
                            query,
                            new QueryRealizer.Callback() {
                              public boolean acceptIncreaseInMonitoringLevel(
                                  List<ResourceInfo> counters) {
                                boolean ret =
                                    UIUtils.getBooleanYesNoInput(
                                        fViewContainer.getAppFrame(),
                                        MessageRepository.get(
                                            Msg.TITLE_CONFIRM_MONITORING_LEVEL_INCREASE),
                                        MessageRepository.get(
                                            Msg.TEXT_CONFIRM_MONITORING_LEVEL_INCREASE_FOR_COUNTER,
                                            new String[] {finalTranslatedCounterName}));
                                if (!ret) {
                                  // undo changes
                                  fSessionData.getCounterHelper().rollbackCounter(fc, true);
                                }
                                return ret;
                              }
                            });
                      }

                      public void finished(Throwable ex) {
                        if (ex != null) {
                          UIExceptionMgr.userException(ex);
                        }
                      }
                    });
          }
        }
      }
    }

    // get all dashboards to unrealize
    dashboards = getDashboardTableModel().getDashboardsToUnRealize();
    if (dashboards != null) {
      for (DashboardInfo dinfo : dashboards) {
        // unregister views with the query realizer
        DataViewId[] views = dinfo.getDashboard().getViews();
        // get views
        if (!Utils.isEmptyArray(views)) {
          for (DataViewId view : views) {
            if (fContext != null) {
              view = view.complete(fContext);
            }
            // ask the locator for info on the required data view
            String viewTranslatedName = view.getName();
            final SessionDataViewInfo dvInfo = this.fArtefactInfoLocator.getDataViewInfo(view);
            if (dvInfo == null) {
              if (logger.isTraceEnabled()) {
                logger.error("Couldn't find data view info for: " + view);
              }
            } else {
              viewTranslatedName = dvInfo.getTranslatedName();
            }
            final DataViewId fv = view;
            // Note: this method is reading from the session model
            // and as a result it can only be used safely from
            // the event dispatching thread
            this.fViewContainer
                .getAppWorker()
                .runJobSynch(
                    new UIWorkerJobDefault(
                        fViewContainer.getAppFrame(),
                        Cursor.WAIT_CURSOR,
                        MessageRepository.get(
                            Msg.TEXT_REALIZING_DATAVIEW, new String[] {viewTranslatedName})) {
                      public void work() throws Exception {
                        QueryId qid = new QueryId(fv.getContext(), fv.getName());
                        fQueryRealizer.unrealizeQuery(qid, false);
                      }

                      public void finished(Throwable ex) {
                        if (ex != null) {
                          UIExceptionMgr.userException(ex);
                        }
                      }
                    });
          }

          // unregister counters with the query realizer
          ResourceId[] counters = dinfo.getDashboard().getCounters();
          if (!Utils.isEmptyArray(counters)) {
            for (ResourceId counter : counters) {
              if (fContext != null) {
                counter = counter.complete(fContext);
              }
              final ResourceId counterContext = counter.getSubResourceId(ResourceId.ENTITY);
              String translatedCounterName = counter.getCounterId().toString();
              // ask the locator for info on this counter
              SessionResourceInfo rInfo = this.fArtefactInfoLocator.getResourceInfo(counter);
              if (rInfo != null && rInfo.getCounterInfo() != null) {
                translatedCounterName = rInfo.getCounterInfo().getTranslatedName();
              }
              final ResourceId finalCounter = counter;
              // Note: this method is reading from the session model
              // and as a result it can only be used safely from
              // the event dispatching thread
              this.fViewContainer
                  .getAppWorker()
                  .runJobSynch(
                      new UIWorkerJobDefault(
                          fViewContainer.getAppFrame(),
                          Cursor.WAIT_CURSOR,
                          MessageRepository.get(
                              Msg.TEXT_REALIZING_DATAVIEW, new String[] {translatedCounterName})) {
                        public void work() throws Exception {
                          QueryId queryId =
                              new QueryId(counterContext, finalCounter.getCounterId().toString());
                          fQueryRealizer.unrealizeQuery(queryId, false);
                        }

                        public void finished(Throwable ex) {
                          if (ex != null) {
                            UIExceptionMgr.userException(ex);
                          }
                        }
                      });
            }
          }

          String dashboardName = dinfo.getDashboard().getName();
          fSessionData
              .getDashboardHelper()
              .setDashboardFlag(ArtefactInfo.ENABLED, fContext, dashboardName, false, true);
        }
      }
    }
    fSessionData.getDashboardHelper().recalculateDashboardsStatus(fContext);
    getDashboardTableModel().fireTableDataChanged();
    fActionApply.setEnabled(false);
    fActionCancel.setEnabled(false);
  }
コード例 #7
0
  // the behaviour is as follows:
  // if the dashboard is not commited, the state will not be changed
  // else the state of the dasboard will be updated only if there is at least
  // one view already in the session model that belongs to this dashboard and
  // it is not enabled
  public void recalculateDashboardsStatus(ResourceId context) {
    ArtefactInfoContainerImpl acimpl = model.getArtefactContainerImplForResource(context, true);
    if (acimpl == null) {
      if (logger.isTraceEnabled()) {
        logger.error("Couldn't find container for: " + context);
      }
      return;
    }
    Collection<DashboardInfoImpl> cs = acimpl.getDashboardInfoImpl();
    if (cs == null) {
      return;
    }

    for (DashboardInfoImpl dinfo : cs) {
      if (dinfo.isCommitted()) {
        Dashboard db = dinfo.getDashboard();
        // flags to update
        boolean enabled = dinfo.getFlag(DashboardInfo.ENABLED);
        boolean plotted = dinfo.getFlag(DashboardInfo.ACTIVATED);
        boolean committed = dinfo.isCommitted();

        // check counters
        ResourceId[] counters = db.getCounters();
        if (!Utils.isEmptyArray(counters)) {
          // disable this dashboard only if one of it's counters
          // exists in the model and it's disabled
          for (ResourceId c : counters) {
            if (context != null) {
              c = c.complete(context);
            }
            CounterInfo cinfo = model.getCounterInfo(c, false);
            if (cinfo == null) {
              if (logger.isTraceEnabled()) {
                logger.error("Couldn't find counter: " + c);
              }
              break;
            }
            if (!cinfo.getFlag(CounterInfo.ENABLED)) {
              enabled = false;
            }
            if (!cinfo.getFlag(CounterInfo.ACTIVATED)) {
              plotted = false;
            }
            if (!cinfo.isCommitted()) {
              committed = false;
            }
          }
        }

        // check data views
        DataViewId[] views = db.getViews();
        if (!Utils.isEmptyArray(views)) {
          // disable this dashboard only if one of it's queries
          // exists in the model and it's disabled

          // find now info on every member
          DataViewId m;
          DataViewInfo dvinfo;
          for (int i = 0; i < views.length; i++) {
            m = views[i];
            if (context != null) {
              m = m.complete(context);
            }
            // refresh data views first
            model.getDataViewHelper().recalculateDataViewsStatus(m.getContext());
            dvinfo = model.getDataViewInfo(m, false);
            if (dvinfo == null) {
              // this query no longer exists...
              // ignore it with a warning in logs
              if (logger.isInfoEnabled()) {
                logger.error(
                    "Couldn't find view info for: "
                        + m
                        + ". Dashboard "
                        + dinfo.getTranslatedName()
                        + " will be incomplete.");
              }
              break;
            }
            // query exists and it will contribute to the state
            // of this dashboard
            if (!dvinfo.getFlag(QueryInfo.ENABLED)) {
              enabled = false;
            }
            if (!dvinfo.getFlag(QueryInfo.ACTIVATED)) {
              plotted = false;
            }
            if (!dvinfo.isCommitted()) {
              committed = false;
            }
          }
        }

        dinfo.setFlag(DashboardInfo.ENABLED, enabled);
        dinfo.setFlag(DashboardInfo.ACTIVATED, plotted);
        if (committed) {
          dinfo.commit();
        }
      } else {
        // just commit it
        dinfo.commit();
      }
    }
  }