/* (non-Javadoc)
   * @see edu.ku.brc.af.ui.forms.validation.TypeSearchForQueryFactory#getDOMFromResource(java.lang.String, java.lang.String)
   */
  public Element getDOMFromResource(final String name, final String localPath) {
    SpecifyAppContextMgr acMgr = (SpecifyAppContextMgr) AppContextMgr.getInstance();
    DataProviderSessionIFace session = null;
    try {
      session = DataProviderFactory.getInstance().createSession();

      String[] dirs = {SpecifyAppContextMgr.COMMONDIR, SpecifyAppContextMgr.BACKSTOPDIR};
      for (String dirName : dirs) {
        SpAppResourceDir appResDir = acMgr.getSpAppResourceDirByName(dirName);
        if (appResDir != null) {
          SpAppResource appRes = appResDir.getResourceByName(name);
          if (appRes != null) {
            session.close();
            session = null;

            return AppContextMgr.getInstance().getResourceAsDOM(appRes);
          }
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
      edu.ku.brc.exceptions.ExceptionTracker.getInstance()
          .capture(SpecifyUIFieldFormatterMgr.class, ex);

    } finally {
      if (session != null) {
        session.close();
      }
    }

    return XMLHelper.readDOMFromConfigDir(localPath); // $NON-NLS-1$
  }
  public SpecifyQueryAdjusterForDomain() {
    permsOKForGlobalSearch =
        !AppContextMgr.isSecurityOn() || SpecifyUser.isCurrentUserType(UserType.Manager);

    // This kicks Global Search into gear if there is just one, but only for that one
    // divisionCnt   = BasicSQLUtils.getCountAsInt(CNT_TBL_SQL+"division");
    // disciplineCnt = BasicSQLUtils.getCountAsInt(CNT_TBL_SQL+"discipline");
    // collectionCnt = BasicSQLUtils.getCountAsInt(CNT_TBL_SQL+"collection");

  }
  /* (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!");
    }
  }
  /**
   * Saves an Discipline level XML document to a Database Resource.
   *
   * @param resName the name of the resource
   * @param xml the XML to be saved.
   */
  public void saveResource(final String resName, final String xml) {
    // System.out.println("Saved");
    // System.out.println(xml);
    // System.out.println();

    SpecifyAppContextMgr acMgr = (SpecifyAppContextMgr) AppContextMgr.getInstance();
    DataProviderSessionIFace session = null;
    try {
      session = DataProviderFactory.getInstance().createSession();

      SpAppResource appRes = null;
      SpAppResourceDir commonResDir =
          acMgr.getSpAppResourceDirByName(SpecifyAppContextMgr.COMMONDIR);
      if (commonResDir != null) {
        appRes = commonResDir.getResourceByName(resName);
        if (appRes == null) {
          SpAppResourceDir backStopResDir =
              acMgr.getSpAppResourceDirByName(SpecifyAppContextMgr.BACKSTOPDIR);
          appRes = backStopResDir.getResourceByName(resName);
          if (appRes != null) {
            backStopResDir.getSpAppResources().remove(appRes);
            commonResDir.getSpAppResources().add(appRes);
            appRes.setSpAppResourceDir(commonResDir);
          } else {
            // major error
            UIRegistry.showError("Major Error");
          }
        }

        if (appRes != null) {
          session.close();
          session = null;

          appRes.setDataAsString(xml);
          AppContextMgr.getInstance().saveResource(appRes);

        } else {
          UIRegistry.showError("Major Error #2");
        }
      }

      /*if (appRes == null)
      {
          SpAppResource backStopDir = acMgr.getSpAppResourceDirByName(BACKSTOPDIR).getResourceByName(resName);
          if (appResDir != null)
          {
              SpAppResource newAppRes  = new SpAppResource();
              newAppRes.initialize();
              if (diskAppRes != null)
              {
                  newAppRes.setMetaData(diskAppRes.getMetaData());
                  newAppRes.setDescription(diskAppRes.getDescription());
                  newAppRes.setFileName(diskAppRes.getFileName());
                  newAppRes.setMimeType(diskAppRes.getMimeType());
                  newAppRes.setName(diskAppRes.getName());

                  newAppRes.setLevel(diskAppRes.getLevel());
              } else
              {
                  newAppRes.setName(resName);
                  newAppRes.setLevel((short)0);
                  newAppRes.setMimeType("text/xml");
              }

              Agent agent = AppContextMgr.getInstance().getClassObject(Agent.class);
              newAppRes.setCreatedByAgent(agent);
              newAppRes.setSpecifyUser(user);

              newAppRes.setSpAppResourceDir(appResDir);
              appResDir.getSpAppResources().add(newAppRes);
              newAppRes.setDataAsString(xml);

              session.close();
              session = null;
              ((SpecifyAppContextMgr) AppContextMgr.getInstance()).saveResource(newAppRes);

          } else
          {
              AppContextMgr.getInstance().putResourceAsXML(resName, xml); //$NON-NLS-1$
          }
      }*/

    } catch (Exception ex) {
      ex.printStackTrace();
      edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
      edu.ku.brc.exceptions.ExceptionTracker.getInstance()
          .capture(SpecifyUIFieldFormatterMgr.class, ex);

    } finally {
      if (session != null) {
        session.close();
      }
    }
  }
Beispiel #5
0
  protected boolean setup() {
    String pathStr =
        AppContextMgr.getInstance().getClassObject(Discipline.class) != null
            ? AppContextMgr.getInstance().getClassObject(Discipline.class).getType()
            : ""; //$NON-NLS-1$
    pathStr +=
        "_"
            + UIHelper.getOSType().toString()
            + "_"
            + (doAll ? "all" : "user"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    baseDir = new File(getUserHomeDir() + File.separator + "FormImages"); // $NON-NLS-1$
    outputDir = new File(baseDir.getAbsoluteFile() + File.separator + pathStr);

    if (!baseDir.exists()) {
      if (!baseDir.mkdir()) {
        UIRegistry.showError(
            String.format(
                getResourceString("FormDisplayer.OUTPUT_ERROR"), baseDir.getAbsoluteFile()));
      }
    }

    if (!outputDir.exists()) {
      if (!outputDir.mkdir()) {
        UIRegistry.showError(
            String.format(
                getResourceString("FormDisplayer.OUTPUT_ERROR"), outputDir.getAbsoluteFile()));
      }
    } else {
      try {
        FileUtils.cleanDirectory(outputDir);

      } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormDisplayer.class, ex);
        ex.printStackTrace();
      }
    }

    String dstDirPath = UIRegistry.getDefaultUserHomeDir() + File.separator + "Specify/site";
    try {
      File tmplateFile = checkForTemplateFiles(dstDirPath);
      mapTemplate = FileUtils.readFileToString(tmplateFile);
      mapTemplate =
          StringUtils.replace(
              mapTemplate,
              "Database Schema",
              getResourceString("FormDisplayer.FORMS")); // $NON-NLS-1$ //$NON-NLS-2$

    } catch (IOException ex) {
      ex.printStackTrace();
      JOptionPane.showMessageDialog(
          null, "You are missing the template that is needed to run this tool.");
      return false;
    }

    if (StringUtils.isEmpty(mapTemplate)) {
      System.err.println("The template file is empty!"); // $NON-NLS-1$
    }

    try {
      File srcDir = new File(dstDirPath); // $NON-NLS-1$
      for (File f : srcDir.listFiles()) {
        if (!f.getName().startsWith(".")) // $NON-NLS-1$
        {
          File dst =
              new File(outputDir.getAbsolutePath() + File.separator + f.getName()); // $NON-NLS-1$
          if (!FilenameUtils.getExtension(f.getName()).toLowerCase().equals("html")) // $NON-NLS-1$
          {
            FileUtils.copyFile(f, dst);
          }

          dst = new File(baseDir.getAbsolutePath() + File.separator + f.getName()); // $NON-NLS-1$
          if (!FilenameUtils.getExtension(f.getName()).toLowerCase().equals("html")) // $NON-NLS-1$
          {
            FileUtils.copyFile(f, dst);
          }
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
      edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormDisplayer.class, ex);
      ex.printStackTrace();
      return false;
    }
    return true;
  }
Beispiel #6
0
  public void generateFormImages() {
    if (setup()) {
      createFormImagesIndexFile();
    }

    int userChoice =
        JOptionPane.showConfirmDialog(
            getTopWindow(),
            getResourceString("FormDisplayer.CHOOSE_VIEWLIST"), // $NON-NLS-1$
            getResourceString("FormDisplayer.CHOOSE_VIEWLIST_TITLE"), // $NON-NLS-1$
            JOptionPane.YES_NO_OPTION);

    doAll = userChoice == JOptionPane.YES_OPTION ? true : false;

    if (setup()) {

      SpecifyAppContextMgr appContext = (SpecifyAppContextMgr) AppContextMgr.getInstance();

      viewList = doAll ? appContext.getEntirelyAllViews() : appContext.getAllViews();
      SwingUtilities.invokeLater(
          new Runnable() {

            /* (non-Javadoc)
             * @see java.lang.Runnable#run()
             */
            public void run() {
              showView();
            }
          });
    }

    JButton stopBtn = UIHelper.createButton("Stop Generating Images");
    PanelBuilder pb = new PanelBuilder(new FormLayout("p", "p"));
    pb.add(stopBtn, (new CellConstraints()).xy(1, 1));
    pb.setDefaultDialogBorder();
    cancelDlg =
        new CustomDialog(
            (Frame) null, "Stop Image Generation", false, CustomDialog.OK_BTN, pb.getPanel());
    cancelDlg.setOkLabel(getResourceString("CLOSE"));

    cancelDlg.setAlwaysOnTop(true);
    cancelDlg.setVisible(true);

    // Insets    screenInsets =
    // Toolkit.getDefaultToolkit().getScreenInsets(cancelDlg.getGraphicsConfiguration());;
    Rectangle screenRect = cancelDlg.getGraphicsConfiguration().getBounds();
    int y = screenRect.height - (cancelDlg.getSize().height * 2);
    cancelDlg.setLocation(screenRect.x, y);

    stopBtn.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    synchronized (okToProc) {
                      okToProc.set(false);
                      viewInx = viewList.size();
                    }
                  }
                });
          }
        });
  }
Beispiel #7
0
 @Transient
 @Override
 protected TaxonTreeDef getCurrentTreeDef() {
   return (TaxonTreeDef)
       ((SpecifyAppContextMgr) AppContextMgr.getInstance()).getTreeDefForClass(Taxon.class);
 }