/* (non-Javadoc)
   * @see edu.ku.brc.af.core.expresssearch.QueryAdjusterForDomain#adjustSQL(java.lang.String, boolean)
   */
  @Override
  public String adjustSQL(final String sql) {
    AppPreferences locPrefs = AppPreferences.getLocalPrefs();
    boolean doGlobalSearch =
        permsOKForGlobalSearch
            && locPrefs.getBoolean("GLOBAL_SEARCH_AVAIL", false)
            && locPrefs.getBoolean("GLOBAL_SEARCH", false);
    // divisionCnt++;
    // disciplineCnt++;
    // collectionCnt++;

    // SpecifyUser should NEVER be null nor the Id !
    SpecifyUser user = AppContextMgr.getInstance().getClassObject(SpecifyUser.class);
    if (user != null) {
      Integer id = user.getId();
      if (id != null) {
        String adjSQL = sql;
        if (StringUtils.contains(adjSQL, SPECIFYUSERID)) {
          adjSQL = StringUtils.replace(adjSQL, SPECIFYUSERID, Integer.toString(id));
        }

        if (StringUtils.contains(adjSQL, DIVID)) {
          String adjustedSQL = null;
          if (doGlobalSearch || divisionCnt == 1) {
            adjustedSQL = removeSpecialFilter(adjSQL, DIVID);
          }

          if (adjustedSQL == null) {
            Integer divId = null;
            Division division = AppContextMgr.getInstance().getClassObject(Division.class);
            if (division != null) {
              divId = division.getId();
            } else {
              divId =
                  Agent.getUserAgent().getDivision() != null
                      ? Agent.getUserAgent().getDivision().getDivisionId()
                      : null;
            }

            if (divId != null) {
              adjSQL = StringUtils.replace(adjSQL, DIVID, Integer.toString(divId));
            }
          } else {
            adjSQL = adjustedSQL;
          }
        }

        // System.out.println(adjSQL);
        if (StringUtils.contains(adjSQL, COLMEMID)) {
          String adjustedSQL = null;
          if (doGlobalSearch || collectionCnt == 1) {
            adjustedSQL = removeSpecialFilter(adjSQL, COLMEMID);
          }

          if (adjustedSQL == null) {
            Collection collection = AppContextMgr.getInstance().getClassObject(Collection.class);
            if (collection != null) {
              adjSQL =
                  StringUtils.replace(
                      adjSQL, COLMEMID, Integer.toString(collection.getCollectionId()));
            }
          } else {
            adjSQL = adjustedSQL;
          }
        }

        if (StringUtils.contains(adjSQL, COLLID)) {
          String adjustedSQL = null;
          if (doGlobalSearch || collectionCnt == 1) {
            adjustedSQL = removeSpecialFilter(adjSQL, COLLID);
          }

          if (adjustedSQL == null) {
            Collection collection = AppContextMgr.getInstance().getClassObject(Collection.class);
            if (collection != null) {
              adjSQL =
                  StringUtils.replace(
                      adjSQL, COLLID, Integer.toString(collection.getCollectionId()));
            }
          } else {
            adjSQL = adjustedSQL;
          }
        }

        if (StringUtils.contains(adjSQL, DSPLNID)) {
          String adjustedSQL = null;
          if (doGlobalSearch || disciplineCnt == 1) {
            adjustedSQL = removeSpecialFilter(adjSQL, DSPLNID);
          }

          if (adjustedSQL == null) {
            Discipline discipline = AppContextMgr.getInstance().getClassObject(Discipline.class);
            if (discipline != null) {
              adjSQL =
                  StringUtils.replace(
                      adjSQL, DSPLNID, Integer.toString(discipline.getDisciplineId()));
            }
          } else {
            adjSQL = adjustedSQL;
          }
        }

        if (StringUtils.contains(adjSQL, TAXTREEDEFID)) {
          TaxonTreeDef taxonTreeDef =
              AppContextMgr.getInstance().getClassObject(TaxonTreeDef.class);
          if (taxonTreeDef != null) {
            adjSQL =
                StringUtils.replace(
                    adjSQL, TAXTREEDEFID, Integer.toString(taxonTreeDef.getTaxonTreeDefId()));
          }
        }

        if (StringUtils.contains(adjSQL, GTPTREEDEFID)) {
          GeologicTimePeriodTreeDef gtpTreeDef =
              AppContextMgr.getInstance().getClassObject(GeologicTimePeriodTreeDef.class);
          if (gtpTreeDef != null) {
            adjSQL =
                StringUtils.replace(
                    adjSQL,
                    GTPTREEDEFID,
                    Integer.toString(gtpTreeDef.getGeologicTimePeriodTreeDefId()));
          } else {
            return null;
          }
        }

        if (StringUtils.contains(adjSQL, STORTREEDEFID)) {
          StorageTreeDef locTreeDef =
              AppContextMgr.getInstance().getClassObject(StorageTreeDef.class);
          if (locTreeDef != null) {
            adjSQL =
                StringUtils.replace(
                    adjSQL, STORTREEDEFID, Integer.toString(locTreeDef.getStorageTreeDefId()));
          }
        }

        if (StringUtils.contains(adjSQL, LITHOTREEDEFID)) {
          LithoStratTreeDef lithoTreeDef =
              AppContextMgr.getInstance().getClassObject(LithoStratTreeDef.class);
          if (lithoTreeDef != null) {
            adjSQL =
                StringUtils.replace(
                    adjSQL,
                    LITHOTREEDEFID,
                    Integer.toString(lithoTreeDef.getLithoStratTreeDefId()));
          } else {
            return null;
          }
        }

        if (StringUtils.contains(adjSQL, GEOTREEDEFID)) {
          GeographyTreeDef lithoTreeDef =
              AppContextMgr.getInstance().getClassObject(GeographyTreeDef.class);
          if (lithoTreeDef != null) {
            adjSQL =
                StringUtils.replace(
                    adjSQL, GEOTREEDEFID, Integer.toString(lithoTreeDef.getGeographyTreeDefId()));
          }
        }

        return adjSQL;
      }
      throw new RuntimeException("The SpecifyUser ID cannot be null!");

    } else {
      throw new RuntimeException("The SpecifyUser cannot be null!");
    }
  }
Ejemplo n.º 2
0
  protected void showView() {
    boolean done = false;

    synchronized (okToProc) {
      if (okToProc.get()) {
        if (frame != null) {
          generateViewImage(viewList.get(viewInx));
          frame.dispose();
        }

        viewInx++;

        ViewIFace view = viewList.get(viewInx);
        System.out.println(view.getName());

        if (!view.getViewSetName().equals("Editor")) // $NON-NLS-1$
        {
          Object data = null;
          try {
            ViewDefIFace viewDef = view.getAltViews().get(0).getViewDef();
            if (!(viewDef.getDataGettable()
                instanceof edu.ku.brc.af.ui.forms.DataGetterForHashMap)) {
              Class<?> dataCls = Class.forName(viewDef.getClassName());
              if (dataCls != null) {
                System.err.println(dataCls);
                data = dataCls.newInstance();
                if (data instanceof FormDataObjIFace) {
                  ((FormDataObjIFace) data).initialize();
                }
              }
            }
          } catch (Exception ex) {
          }

          if (data instanceof Discipline) {
            ((Discipline) data).setType("fish");
          }
          FormPane formPane =
              new FormPane(
                  view.getName(),
                  null,
                  null,
                  view.getName(),
                  "edit",
                  data,
                  MultiView.IS_NEW_OBJECT | MultiView.HIDE_SAVE_BTN,
                  true); //$NON-NLS-1$
          frame = new JFrame();
          frame.setFocusable(false);
          frame.setContentPane(formPane);
          frame.setSize(1024, 768);
          frame.setVisible(true);

          frame.setLocation(0, 0);

          Dimension size = frame.getContentPane().getPreferredSize();
          size.height += 40;
          size.width += 30;
          frame.setSize(size);

          String str = String.format("%d of %d", viewInx + 1, viewList.size());
          System.out.println(str); // $NON-NLS-1$
          getStatusBar().setText(str); // $NON-NLS-1$

        } else if (frame != null) {
          frame.setVisible(false);
          frame.dispose();
          frame = null;
        }

        if (viewInx < viewList.size() - 1) {
          SwingUtilities.invokeLater(
              new Runnable() {
                @Override
                public void run() {
                  try {
                    Thread.sleep(500);
                  } catch (Exception ex) {
                    edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                    edu.ku.brc.exceptions.ExceptionTracker.getInstance()
                        .capture(FormDisplayer.class, ex);
                  }
                  showView();
                }
              });
        } else {
          done = true;
        }
      } else {
        done = true;
      }
    }

    if (done) {
      if (cancelDlg != null) cancelDlg.setVisible(false);
      if (frame != null) {
        frame.setVisible(false);
        frame.dispose();
      }

      createIndexFile();

      getStatusBar().setText("Done"); // $NON-NLS-1$
    }
  }