public void actionPerformed(ActionEvent e) {
   try {
     String scannedDestination = ((JTextField) e.getSource()).getText().toUpperCase();
     validateDestinationScan(scannedDestination);
     DefaultListModel listModel = (DefaultListModel) destinationsList.getModel();
     int lastPosition = listModel.getSize();
     int seedsCount = 0;
     // todo: do we have to worry about more trays than required..?
     for (int i = 0; i < seedPlates.length; i++) {
       if (seedPlates[i].getSeedPlateBarcode() != null
           && SCANNED.equals(seedPlates[i].getStatus())
           && !isContainedInList(seedPlates[i].getSeedPlateBarcode(), failedPlatesList)) {
         seedsCount++;
       }
     }
     if (lastPosition >= seedsCount) {
       throw new ChippingManagerException(DESTINATIONS_LIMIT_EXCEEDED);
     }
     addDestination(scannedDestination);
   } catch (Throwable cmException) {
     logger.error("Unable to scan destination ", cmException);
     JOptionPane.showMessageDialog(
         new JFrame(),
         cmException.getMessage(),
         TITLE_CHIPPING_MANAGER,
         JOptionPane.WARNING_MESSAGE);
   }
   scanDestination.setText(BLANK);
 }
 public void actionPerformed(ActionEvent e) {
   try {
     validateUnloadPlatesDialog();
     unloadPlates();
   } catch (Throwable cmException) {
     logger.error("error to unload to multiple destinations", cmException);
     JOptionPane.showMessageDialog(
         new JFrame(),
         cmException.getMessage(),
         TITLE_CHIPPING_MANAGER,
         JOptionPane.WARNING_MESSAGE);
   }
 }
Esempio n. 3
0
  public static void main(String[] argv) throws InterruptedException {
    // Arguments:
    // 1st = Mode
    // 2nd = Parent Path  -- (Parent path must have children /data  and /output

    System.out.println("+----------------------------------+");
    System.out.println("| Running Athena Pallas Processor  |");
    System.out.println("|             9/12/12              |");
    System.out.println("+----------------------------------+");

    Athena_Server_Obj = new ATHENA_Server_Local();

    BasicConfigurator.configure();
    Logger.getRootLogger().setLevel(Level.WARN);

    // Get and verify parameters
    if (argv.length < 2) {
      System.out.println("Not enough parameters.");
      System.out.println("Expected 2 parameters: 1st is MODE, 2nd is path to working directory.");
      System.out.println("Exiting.");
      System.exit(0);
    }

    String mode = argv[0];
    String parentPath = argv[1];
    File inFilePath = new File(parentPath + "astronautdata/");
    File outFilePath = new File(parentPath + "output/");
    File kbFilePath = new File(parentPath + "kbs/");

    if (mode.equals("")) {
      System.out.println("Parameter 1 is empty.  Should be RUNMODE (e.g. 'HTN'). Exiting");
      System.exit(0);
    }

    if (inFilePath.isDirectory() == false) {
      System.out.println(inFilePath.getName() + " directory is missing. Exiting");
      System.exit(0);
    }

    if (outFilePath.isDirectory() == false) {
      System.out.println(outFilePath.getName() + " directory is missing. Exiting");
      System.exit(0);
    }

    if (kbFilePath.isDirectory() == false) {
      System.out.println(kbFilePath.getName() + " directory is missing. Exiting");
      System.exit(0);
    }

    String kbID = "";
    TStringList IgnoredFileNames = new TStringList();

    // Main Loop
    while (mainLoopRunning) {
      if (Verbose == true) {
        // System.out.println("New Loop");
      }
      fileProcessed = false;
      if (Verbose == true) {
        // System.out.println("Ignoring #" + IgnoredFileNames.Count() + " files.");
      }

      // (re)load if needed
      if (loadKB == true) {
        String[] kbInfo = Athena_Server_Obj.loadKBInfo(mode, parentPath);
        String kbFilenamePath = kbInfo[0];
        kbID = kbInfo[1];

        Athena_Server_Obj.loadKB(kbFilenamePath, kbID);
        loadKB = false;
      }

      File[] listOfFiles = inFilePath.listFiles();
      // for (File child : inFilePath.listFiles()) {
      for (int i = 0; i < listOfFiles.length; i++) {
        File child = listOfFiles[i];
        if (".".equals(child.getName()) || "..".equals(child.getName())) {
          continue;
        }
        if (child.getName().toUpperCase().equals(mode + "-CMD.TXT")) {
          try {
            handleCommands(child.getPath(), outFilePath, mode);
            // fileProcessed = true;
            if (child.delete() == false) {
              System.out.println("Unable to delete: " + child.getPath());
              Thread.sleep(1000);
            }
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          // continue;
        }
        if (IgnoredFileNames.IndexOf(child.getName()) > -1) {
          // if (Verbose == true) {System.out.print("~");}
          continue;
        }
        if (Verbose == true) {
          System.out.println("Considering file: [" + child.getName() + "]");
        }
        String[] namePieces = child.getName().split("_");
        //  (should only open filenames with format of <MODE>_<DFN>.xml)
        if (Verbose == true) {
          System.out.println("File Name Is: " + child.getName());
        }
        String fileExt = GetFileExtension(child.getName());
        if (Verbose == true) {
          System.out.println("File Ext Is: " + fileExt);
        }
        // At times, there seems to be a race condition, where this java process
        //   tries to load in the file before the mump process is done writting
        // So I have modified the mumps process to that it outputs TWO files.
        //  1st the <MODE>_<DFN>.xml file
        //  2nd, after finished with above, it outputs <MODE>_<DFN>_READY.TXT
        // So the 2nd file must exist before opening the <MODE>_<DFN>.xml
        //  The 2nd file need not be opened or processed.  Just the fact that
        //  it exists on in the directory is signal that it is OK to process.
        if (fileExt.equals("xml") == false) {
          if (Verbose == true) {
            System.out.println("Skipping file due to wrong extension.");
          }
          IgnoredFileNames.Add(child.getName());
          continue;
        }
        if (((namePieces.length > 1) && (namePieces[0].equals(mode))) == false) {
          if (Verbose == true) {
            System.out.println("Skipping file due to wrong mode.");
          }
          IgnoredFileNames.Add(child.getName());
          continue;
        }
        Boolean finishFileExists = finishFileExist(child.getPath());
        if (Verbose == true) {
          System.out.println("Ready File Exists?: " + finishFileExists);
        }
        // NOTE: after processing the <MODE>_<DFN>.xml, both files should be deleted
        // NOTE: in java, one can't use '=' to compare strings -- that just compares a pointer to
        // the string.  Must use ".equals()"
        if (finishFileExists == true) {
          System.out.println("Found File to Process: [" + child.getName() + "]");
          fileProcessed = true;
          String patientID = namePieces[1];
          patientID = patientID.split("\\.")[0];
          File outFileName =
              new File(outFilePath.getPath() + "/" + mode + "_" + patientID + ".xml");
          String htmlFile = outFilePath.getPath() + "/" + mode + "_" + patientID + ".html";
          System.out.println("SENDING TO: [" + outFileName.getPath() + "]");
          String readyFileName;
          readyFileName = outFileName.getPath();
          try {
            processFile(patientID, child, outFileName, kbID, htmlFile);
          } catch (Throwable t) {
            try {
              FileWriter fwrite = new FileWriter(outFileName);
              fwrite.write(
                  "-1^CDSS/Clinical Decision Support Engine(Athena) Error. " + t.getMessage());
              fwrite.flush();
              fwrite.close();
            } catch (IOException e3) {
              System.out.println("Could not create error message");
            }
            System.out.println("Error Processing Recommendation: " + t.getMessage());
            // return;
          }
          System.out.println("Ready.TXT File Name Is: " + readyFileName); // Remove
          File readyFile = new File(readyFileName.replace(".xml", "_READY.TXT"));
          try {
            readyFile.createNewFile();
            FileWriter fstream = new FileWriter(readyFile);
            BufferedWriter out = new BufferedWriter(fstream);
            out.write("DONE");
            out.close();
            System.out.println("****SUCCESS****" + readyFile.getPath());
          } catch (java.io.IOException e0) {
            System.out.println("Error creating READY file");
          }
          if (child.delete() == false) {
            System.out.println("Unable to delete: " + child.getName());
            Thread.sleep(1000);
          }
          // Delete completed file
          File f = new File(getFinishFileName(child.getPath()));
          if (f.delete() == false) {
            System.out.println("Unable to delete: " + f.getName());
            Thread.sleep(1000);
          }
        }
      }
      if (fileProcessed == false) {
        Thread.sleep(1000);
        if (Verbose == true) {
          System.out.print(".");
        }
      } else {
        if (Verbose == true) {
          System.out.println("Found process, so won't sleep...");
        }
      }
      mainLoopRunning = false;
    } // for loop
    System.out.println("Finished with run.");
    System.exit(0);
  } // Main routine
  public void _jspService(HttpServletRequest request, HttpServletResponse response)
      throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
      response.setContentType("text/html");
      pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n\r\n");

      final DisplayState theDisplayState = (DisplayState) request.getAttribute(MasterServlet.STATE);
      final Frame frame = (Frame) request.getAttribute(AbstractChip.FRAME_KEY);

      /*
       //to be definitive NOT serializable
      InputStream noser = (InputStream)session.getAttribute( "NOT_SERIALIZABLE");
      if( noser==null )
      {
      	session.setAttribute( "NOT_SERIALIZABLE", new ByteArrayInputStream( new byte[0] ));
      }
      */

      out.write('\r');
      out.write('\n');

      final AbstractItemTreeNodeChip theChip =
          (AbstractItemTreeNodeChip) request.getAttribute(AbstractChip.CHIP_KEY);

      out.write("\r\n<input type=\"hidden\" name=\"");
      out.print(theChip.getEventID(AbstractTreeNodeChip.EDIT));
      out.write("\" value=\"");
      out.print(AbstractChip.FALSE);
      out.write(
          "\" />\r\n<table class=\"abstractItemTreeNodeChip\" cellspacing=\"0\" cellpadding=\"0\">\r\n\t<tr>\r\n\t\t<td class=\"aitncIcon\">\r\n\t\t\t<div onclick=\"document.editorForm.elements['");
      out.print(theChip.getEventID(AbstractTreeNodeChip.EDIT));
      out.write("'].value='");
      out.print(AbstractChip.TRUE);
      out.write("';setScrollAndSubmit();\">\r\n\t\t\t\t<img src=\"");
      out.print(theChip.getIcon());
      out.write(
          "\" border=\"0\">\r\n\t\t\t</div>\r\n\t\t</td>\r\n\t\t<td class=\"aitncName\">\r\n\t\t\t<div onclick=\"document.editorForm.elements['");
      out.print(theChip.getEventID(AbstractTreeNodeChip.EDIT));
      out.write("'].value='");
      out.print(AbstractChip.TRUE);
      out.write("';setScrollAndSubmit();\">\r\n\t\t\t\t");
      out.print(theChip.getName());
      out.write("\r\n\t\t\t</div>\r\n\t\t</td>\r\n\t</tr>\r\n\t");

      if (theChip.isExpanded()) {
        for (final Iterator it = theChip.getAllChildren().iterator(); it.hasNext(); ) {
          final AbstractTreeNodeChip child = (AbstractTreeNodeChip) it.next();

          out.write("\r\n\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t<td class=\"aitncTreeIMG\" background=\"");
          out.print(it.hasNext() ? "images/vert.gif" : "");
          out.write("\">\r\n\t\t\t\t\t\t\t");

          if (child.hasChildren()) {
            if (child.isExpanded()) {

              out.write("<input type=\"hidden\" name=\"");
              out.print(child.getEventID(AbstractTreeNodeChip.COLLAPSE));
              out.write("\" value=\"");
              out.print(AbstractChip.FALSE);
              out.write("\" /><div onclick=\"document.editorForm.elements['");
              out.print(child.getEventID(AbstractTreeNodeChip.COLLAPSE));
              out.write("'].value='");
              out.print(AbstractChip.TRUE);
              out.write("';setScrollAndSubmit();\">");

              if (it.hasNext()) {

                out.write("<img src=\"images/minus.gif\"></td>");

              } else {

                out.write("<img src=\"images/minusend.gif\"></td>");
              }

              out.write("</div>");

            } else {

              out.write("<input type=\"hidden\" name=\"");
              out.print(child.getEventID(AbstractTreeNodeChip.EXPAND));
              out.write("\" value=\"");
              out.print(AbstractChip.FALSE);
              out.write("\" /><div onclick=\"document.editorForm.elements['");
              out.print(child.getEventID(AbstractTreeNodeChip.EXPAND));
              out.write("'].value='");
              out.print(AbstractChip.TRUE);
              out.write("';setScrollAndSubmit();\">");

              if (it.hasNext()) {

                out.write("<img src=\"images/plus.gif\"></td>");

              } else {

                out.write("<img src=\"images/plusend.gif\"></td>");
              }

              out.write("</div>");
            }
          } else {
            if (it.hasNext()) {

              out.write("<img src=\"images/horiz.gif\"></td>");

            } else {

              out.write("<img src=\"images/end.gif\"></td>");
            }
          }

          out.write("\r\n\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t<td class=\"aitncContext\">");
          child.render(pageContext);
          out.write("</td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t");
        }
      }

      out.write("\r\n</table>\r\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)) {
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try {
            out.clearBuffer();
          } catch (java.io.IOException e) {
          }
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else log(t.getMessage(), t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }