예제 #1
0
  ///////////////////////////////////////////////////////////////////////
  // Data logging
  ///////////////////////////////////////////////////////////////////////
  public void tickPrice(int tickerId, int field, double price, int canAutoExecute) {
    Hashtable f = new Hashtable();
    f.put(TickType.getField(field), String.valueOf(price));
    f.put("canAutoExecute", String.valueOf(canAutoExecute));

    EventBus.publish(new MktDataEvent(tickerId, f));
  }
예제 #2
0
 /**
  * Adds a single {@link AddeEntry} to {@link #trie}.
  *
  * @param entry Entry to add. Cannot be {@code null}.
  * @throws NullPointerException if {@code entry} is {@code null}.
  */
 public void addEntry(final AddeEntry entry) {
   notNull(entry, "Cannot add a null entry");
   trie.put(entry.asStringId(), entry);
   saveEntries();
   lastAdded.clear();
   lastAdded.add(entry);
   EventBus.publish(Event.ADDITION);
 }
  private String downloadManifestAndMediaFiles(File mediaDir, FormStatus fs) {
    RemoteFormDefinition fd = (RemoteFormDefinition) fs.getFormDefinition();
    if (fd.getManifestUrl() == null) return null;
    fs.setStatusString("Fetching form manifest", true);
    EventBus.publish(new FormStatusEvent(fs));

    List<MediaFile> files = new ArrayList<MediaFile>();
    AggregateUtils.DocumentFetchResult result;
    try {
      DocumentDescription formManifestDescription =
          new DocumentDescription(
              "Fetch of manifest failed. Detailed reason: ",
              "Fetch of manifest failed ",
              "form manifest",
              terminationFuture);
      result =
          AggregateUtils.getXmlDocument(
              fd.getManifestUrl(), serverInfo, false, formManifestDescription, null);
    } catch (XmlDocumentFetchException e) {
      return e.getMessage();
    }

    try {
      files = XmlManipulationUtils.parseFormManifestResponse(result.isOpenRosaResponse, result.doc);
    } catch (ParsingException e) {
      return e.getMessage();
    }
    // OK we now have the full set of files to download...
    logger.info("Downloading " + files.size() + " media files.");
    int mCount = 0;
    if (files.size() > 0) {
      for (MediaFile m : files) {
        ++mCount;
        fs.setStatusString(
            String.format(" (getting %1$d of %2$d media files)", mCount, files.size()), true);
        EventBus.publish(new FormStatusEvent(fs));
        try {
          downloadMediaFileIfChanged(mediaDir, m, fs);
        } catch (Exception e) {
          return e.getLocalizedMessage();
        }
      }
    }
    return null;
  }
예제 #4
0
 @EventSubscriber
 public void onHistoryEvent(@Nonnull final HistoryEvent e) {
   if (e.isUndo()) {
     undo();
   } else {
     redo();
   }
   EventBus.publish(new RepaintRequestEvent());
 }
예제 #5
0
 /**
  * Removes a single {@link AddeEntry} from the set of available entries.
  *
  * @param entry Entry to remove. Cannot be {@code null}.
  * @return {@code true} if something was removed, {@code false} otherwise.
  */
 public boolean removeEntry(final AddeEntry entry) {
   notNull(entry);
   boolean val = trie.remove(entry.asStringId()) != null;
   logger.trace("attempted remove={} status={}", entry, val);
   Event evt = val ? Event.REMOVAL : Event.FAILURE;
   saveEntries();
   EventBus.publish(evt);
   return val;
 }
예제 #6
0
 /**
  * Adds a {@link Set} of {@link AddeEntry}s to {@link #trie}.
  *
  * @param newEntries New entries to add to the server manager. Cannot be {@code null}.
  * @throws NullPointerException if {@code newEntries} is {@code null}.
  */
 public void addEntries(final Collection<? extends AddeEntry> newEntries) {
   notNull(newEntries, "Cannot add a null set");
   for (AddeEntry newEntry : newEntries) {
     trie.put(newEntry.asStringId(), newEntry);
   }
   saveEntries();
   lastAdded.clear();
   lastAdded.addAll(newEntries);
   EventBus.publish(Event.ADDITION);
 }
예제 #7
0
  public void updateMktDepth(
      int tickerId, int position, int operation, int side, double price, int size) {
    Hashtable f = new Hashtable();
    f.put("position", String.valueOf(position));
    f.put("operation", String.valueOf(operation));
    f.put("side", String.valueOf(side));
    f.put("price", String.valueOf(price));
    f.put("size", String.valueOf(size));

    EventBus.publish(new MktDepthEvent(tickerId, f));
  }
  private void init() {
    JPanel quickSearchPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));

    final TreeModel treeModel = explorer.getTreeModel();
    final QuickTreeFilterField field =
        new QuickTreeFilterField(treeModel) {
          protected FilterableTreeModel createDisplayTreeModel(TreeModel treeModel) {
            return new FilterableTreeModel(treeModel) {
              @Override
              protected void configureListModelWrapper(ListModelWrapper wrapper, Object node) {

                if (node instanceof DefaultMutableTreeNode) {
                  // ImageFileExplorer.LazyNode inode = (ImageFileExplorer.LazyNode) node;
                  DefaultMutableTreeNode inode = (DefaultMutableTreeNode) node;
                  boolean expanded = explorer.getJTree().isExpanded(new TreePath(inode.getPath()));
                  if (inode.isLeaf() || expanded) {
                    super.configureListModelWrapper(wrapper, node);
                  }
                }
              }
            };
          }
        };

    field.setSearchingDelay(200);
    quickSearchPanel.add(field);

    JPanel treePanel = new JPanel(new BorderLayout(2, 2));

    field.setTree(explorer.getJTree());
    SearchableUtils.installSearchable(field.getTree());

    JTree tree = field.getTree();
    tree.setModel(field.getDisplayTreeModel());
    DataTipManager.get().register(tree);

    treePanel.add(explorer.getComponent());

    mainPanel.add(treePanel);
    mainPanel.add(quickSearchPanel, BorderLayout.BEFORE_FIRST_LINE);

    EventBus.subscribeStrongly(
        DataSourceStatusEvent.class,
        new EventSubscriber<DataSourceStatusEvent>() {
          @Override
          public void onEvent(DataSourceStatusEvent event) {
            explorer.getJTree().repaint();
          }
        });

    mainPanel.putClientProperty(IActionProvider.KEY, this);
  }
예제 #9
0
  /** Stops the local server thread if it is running. */
  public void stopLocalServer() {
    if (checkLocalServer()) {
      // TODO: stopProcess (actually Process.destroy()) hangs on Macs...
      //      doesn't seem to kill the children properly
      if (!McIDASV.isMac()) {
        thread.stopProcess();
      }

      thread.interrupt();
      thread = null;
      EventBus.publish(McservEvent.STOPPED);
      logger.debug("stopped mcservl? checkLocalServer={}", checkLocalServer());
    } else {
      logger.debug("mcservl is not running.");
    }
  }
  /**
   * Add a new data access controller
   *
   * @param controller new data access controller
   * @param foreground true will set this data access controller to foreground
   */
  public synchronized void addDataAccessController(
      DataAccessController controller, boolean foreground) {
    // new controller should always be added to the end of the list
    List<DataAccessController> oldControllers, newControllers;

    if (!controllers.contains(controller)) {
      oldControllers = new ArrayList<DataAccessController>(controllers);
      controllers.add(controller);
      newControllers = new ArrayList<DataAccessController>(controllers);
      EventBus.publish(
          new AddDataSourceEvent<DataAccessController>(this, oldControllers, newControllers));
      if (foreground) {
        setForegroundDataAccessController(controller);
      }
    }
  }
예제 #11
0
  /**
   * Replaces the {@link AddeEntry}s within {@code trie} with the contents of {@code newEntries}.
   *
   * @param oldEntries Entries to be replaced. Cannot be {@code null}.
   * @param newEntries Entries to use as replacements. Cannot be {@code null}.
   * @throws NullPointerException if either of {@code oldEntries} or {@code newEntries} is {@code
   *     null}.
   */
  public void replaceEntries(
      final Collection<? extends AddeEntry> oldEntries,
      final Collection<? extends AddeEntry> newEntries) {
    notNull(oldEntries, "Cannot replace a null set");
    notNull(newEntries, "Cannot add a null set");

    for (AddeEntry oldEntry : oldEntries) {
      trie.remove(oldEntry.asStringId());
    }
    for (AddeEntry newEntry : newEntries) {
      trie.put(newEntry.asStringId(), newEntry);
    }
    lastAdded.clear();
    lastAdded.addAll(newEntries); // should probably be more thorough
    saveEntries();
    EventBus.publish(Event.REPLACEMENT);
  }
  public synchronized void removeDataAccessController(DataAccessController controller) {
    List<DataAccessController> oldControllers, newControllers;

    int index = controllers.indexOf(controller);
    if (index >= 0) {
      oldControllers = new ArrayList<DataAccessController>(controllers);
      // get the next available controller's index
      int nextIndex = controllers.size() - 1 > index ? index : index - 1;
      controllers.remove(controller);
      if (foregroundController != null && foregroundController.equals(controller)) {
        setForegroundDataAccessController(nextIndex >= 0 ? controllers.get(nextIndex) : null);
      }
      controller.close();
      newControllers = new ArrayList<DataAccessController>(controllers);

      EventBus.publish(
          new RemoveDataSourceEvent<DataAccessController>(this, oldControllers, newControllers));
    }
  }
예제 #13
0
  public boolean removeEntries(final Collection<? extends AddeEntry> removedEntries) {
    notNull(removedEntries);

    boolean val = true;
    boolean tmpVal = true;
    for (AddeEntry entry : removedEntries) {
      if (entry.getEntrySource() != EntrySource.SYSTEM) {
        tmpVal = trie.remove(entry.asStringId()) != null;
        logger.trace("attempted bulk remove={} status={}", entry, tmpVal);
        if (!tmpVal) {
          val = tmpVal;
        }
      }
    }
    Event evt = (val) ? Event.REMOVAL : Event.FAILURE;
    saveEntries();
    EventBus.publish(evt);
    return val;
  }
예제 #14
0
  /**
   * Remove a character from the game list and recycle the character reference for later usage. Also
   * clean up everything related to this character such as the attacking marker.
   *
   * @param id the ID of the character that shall be removed
   */
  public void removeCharacter(final CharacterId id) {
    throwPlayerCharacter(id);

    charsLock.writeLock().lock();
    try {
      final Char chara = chars.get(id);
      if (chara != null) {
        EventBus.publish(new CharRemovedEvent(id));
        // cancel attack when character is removed
        if (CombatHandler.getInstance().isAttacking(chara)) {
          CombatHandler.getInstance().standDown();
        }
        chars.remove(id);
        chara.recycle();
      }
    } finally {
      charsLock.writeLock().unlock();
    }
  }
  public synchronized void setForegroundDataAccessController(DataAccessController controller) {
    DataAccessController oldController, newController;

    oldController = this.foregroundController;
    foregroundController = controller;
    newController = controller;

    ForegroundDataSourceEvent.Status status = ForegroundDataSourceEvent.Status.DATA;
    if (newController instanceof EmptyDataAccessController) {
      status = ForegroundDataSourceEvent.Status.DUMMY;
    } else if (oldController instanceof EmptyDataAccessController) {
      status = ForegroundDataSourceEvent.Status.DUMMY_TO_DATA;
    } else if (newController == null) {
      status = ForegroundDataSourceEvent.Status.EMPTY;
    }

    EventBus.publish(
        new ForegroundDataSourceEvent<DataAccessController>(
            this, status, oldController, newController));
  }
예제 #16
0
 /** Starts the local server thread (if it isn't already running). */
 public void startLocalServer() {
   if (new File(ADDE_MCSERVL).exists()) {
     // Create and start the thread if there isn't already one running
     if (!checkLocalServer()) {
       if (!testLocalServer()) {
         LogUtil.userErrorMessage("Local servers cannot write to userpath:\n" + USER_DIRECTORY);
         logger.info("Local servers cannot write to userpath");
         return;
       }
       thread = new AddeThread(this);
       thread.start();
       EventBus.publish(McservEvent.STARTED);
       logger.debug("started mcservl? checkLocalServer={}", checkLocalServer());
     } else {
       logger.debug("mcservl is already running");
     }
   } else {
     logger.debug("invalid path='{}'", ADDE_MCSERVL);
   }
 }
  /**
   * Set the selected link
   *
   * @param link
   */
  public void setLink(final ILink link) {
    WaitIndicator waitIndicator =
        new LabeledSpinningDialWaitIndicator(this, "Loading " + link.getToConcept() + " ...");
    getLinkNameTextField().setText(link.getLinkName());
    getLinkValueTextField().setText(link.getLinkValue());
    final HierachicalConceptNameComboBox comboBox = getToConceptComboBox();
    comboBox.hidePopup();
    getLinksComboBox().hidePopup();
    String conceptName = link.getToConcept();

    if (conceptName.equals(ILink.VALUE_NIL) || conceptName.equals(ILink.VALUE_SELF)) {
      SortedComboBoxModel<String> model = (SortedComboBoxModel<String>) comboBox.getModel();
      model.clear();
      model.addElement(conceptName);
    } else {

      // Retrieve the child concepts and add to gui
      try {
        final Concept c =
            (Concept)
                Worker.post(
                    new Task() {
                      @Override
                      public Object run() throws Exception {
                        return annotationPersistenceService.findConceptByName(link.getToConcept());
                      }
                    });
        comboBox.setConcept(c);
        conceptName = c.getPrimaryConceptName().getName();

      } catch (final Exception e) {
        EventBus.publish(GlobalLookup.TOPIC_NONFATAL_ERROR, e);
        comboBox.addItem(conceptName);
      }
    }

    comboBox.setSelectedItem(conceptName);
    waitIndicator.dispose();
    repaint();
  }
  /**
   * Replace one data access controller with another, and retain the position in the
   * DataAccessMonitor.
   *
   * @param original original data access controller
   * @param replacement replacement data access controller
   */
  public synchronized void replaceDataAccessController(
      DataAccessController original, DataAccessController replacement) {
    List<DataAccessController> oldControllers, newControllers;

    int index = controllers.indexOf(original);
    if (index >= 0) {
      oldControllers = new ArrayList<DataAccessController>(controllers);
      controllers.add(index, replacement);
      controllers.remove(original);
      if (foregroundController != null && foregroundController.equals(original)) {
        setForegroundDataAccessController(replacement);
      }
      original.close();
      newControllers = new ArrayList<DataAccessController>(controllers);
      // notify others
      EventBus.publish(
          new AddDataSourceEvent<DataAccessController>(this, oldControllers, newControllers));
    } else {
      // add as a new data access controller
      addDataAccessController(replacement);
    }
  }
  private void downloadMediaFileIfChanged(File mediaDir, MediaFile m, FormStatus fs)
      throws Exception {

    File mediaFile = new File(mediaDir, m.filename);

    if (m.hash.startsWith(MD5_COLON_PREFIX)) {
      // see if the file exists and has the same hash
      String hashToMatch = m.hash.substring(MD5_COLON_PREFIX.length());
      if (mediaFile.exists()) {
        String hash = FileSystemUtils.getMd5Hash(mediaFile);
        if (hash.equalsIgnoreCase(hashToMatch)) return;
        mediaFile.delete();
      }
    }

    if (isCancelled()) {
      fs.setStatusString("aborting fetch of media file...", true);
      EventBus.publish(new FormStatusEvent(fs));
      throw new TransmissionException("Transfer cancelled by user.");
    }

    AggregateUtils.commonDownloadFile(serverInfo, mediaFile, m.downloadUrl);
  }
예제 #20
0
 @Override
 public void actionPerformed(ActionEvent e) {
   EventBus.publish(new LoadWorkspaceEvent());
 }
  private boolean downloadAllSubmissionsForForm(
      File formInstancesDir,
      DatabaseUtils formDatabase,
      BriefcaseFormDefinition lfd,
      FormStatus fs) {
    boolean allSuccessful = true;

    RemoteFormDefinition fd = (RemoteFormDefinition) fs.getFormDefinition();

    int count = 1;
    String baseUrl = serverInfo.getUrl() + "/view/submissionList";

    String oldWebsafeCursorString = "not-empty";
    String websafeCursorString = "";
    for (; !oldWebsafeCursorString.equals(websafeCursorString); ) {
      if (isCancelled()) {
        fs.setStatusString("aborting fetching submissions...", true);
        EventBus.publish(new FormStatusEvent(fs));
        return false;
      }

      fs.setStatusString("retrieving next chunk of instances from server...", true);
      EventBus.publish(new FormStatusEvent(fs));

      Map<String, String> params = new HashMap<String, String>();
      params.put("numEntries", Integer.toString(MAX_ENTRIES));
      params.put("formId", fd.getFormId());
      params.put("cursor", websafeCursorString);
      String fullUrl = WebUtils.createLinkWithProperties(baseUrl, params);
      oldWebsafeCursorString = websafeCursorString; // remember what we had...
      AggregateUtils.DocumentFetchResult result;
      try {
        DocumentDescription submissionChunkDescription =
            new DocumentDescription(
                "Fetch of submission download chunk failed.  Detailed error: ",
                "Fetch of submission download chunk failed.",
                "submission download chunk",
                terminationFuture);
        result =
            AggregateUtils.getXmlDocument(
                fullUrl, serverInfo, false, submissionChunkDescription, null);
      } catch (XmlDocumentFetchException e) {
        fs.setStatusString(
            "NOT ALL SUBMISSIONS RETRIEVED: Error fetching list of submissions: " + e.getMessage(),
            false);
        EventBus.publish(new FormStatusEvent(fs));
        return false;
      }

      SubmissionDownloadChunk chunk;
      try {
        chunk = XmlManipulationUtils.parseSubmissionDownloadListResponse(result.doc);
      } catch (ParsingException e) {
        fs.setStatusString(
            "NOT ALL SUBMISSIONS RETRIEVED: Error parsing the list of submissions: "
                + e.getMessage(),
            false);
        EventBus.publish(new FormStatusEvent(fs));
        return false;
      }
      websafeCursorString = chunk.websafeCursorString;

      for (String uri : chunk.uriList) {
        if (isCancelled()) {
          fs.setStatusString("aborting fetching submissions...", true);
          EventBus.publish(new FormStatusEvent(fs));
          return false;
        }

        try {
          fs.setStatusString("fetching instance " + count++ + " ...", true);
          EventBus.publish(new FormStatusEvent(fs));

          downloadSubmission(formInstancesDir, formDatabase, lfd, fs, uri);
        } catch (Exception e) {
          e.printStackTrace();
          allSuccessful = false;
          fs.setStatusString(
              "SUBMISSION NOT RETRIEVED: Error fetching submission uri: "
                  + uri
                  + " details: "
                  + e.getMessage(),
              false);
          EventBus.publish(new FormStatusEvent(fs));
          // but try to get the next one...
        }
      }
    }
    return allSuccessful;
  }
  private void downloadSubmission(
      File formInstancesDir,
      DatabaseUtils formDatabase,
      BriefcaseFormDefinition lfd,
      FormStatus fs,
      String uri)
      throws Exception {

    if (formDatabase.hasRecordedInstance(uri) != null) {
      logger.info("already present - skipping fetch: " + uri);
      return;
    }

    String formId = lfd.getSubmissionKey(uri);

    if (isCancelled()) {
      fs.setStatusString("aborting fetch of submission...", true);
      EventBus.publish(new FormStatusEvent(fs));
      throw new SubmissionDownloadException("Transfer cancelled by user.");
    }

    String baseUrl = serverInfo.getUrl() + "/view/downloadSubmission";

    Map<String, String> params = new HashMap<String, String>();
    params.put("formId", formId);
    String fullUrl = WebUtils.createLinkWithProperties(baseUrl, params);
    AggregateUtils.DocumentFetchResult result;
    try {
      DocumentDescription submissionDescription =
          new DocumentDescription(
              "Fetch of a submission failed.  Detailed error: ",
              "Fetch of a submission failed.",
              "submission",
              terminationFuture);
      result =
          AggregateUtils.getXmlDocument(fullUrl, serverInfo, false, submissionDescription, null);
    } catch (XmlDocumentFetchException e) {
      throw new SubmissionDownloadException(e.getMessage());
    }

    // and parse the document...
    SubmissionManifest submissionManifest;
    try {
      submissionManifest = XmlManipulationUtils.parseDownloadSubmissionResponse(result.doc);
    } catch (ParsingException e) {
      throw new SubmissionDownloadException(e.getMessage());
    }

    String msg = "Fetched instanceID=" + submissionManifest.instanceID;
    logger.info(msg);

    if (FileSystemUtils.hasFormSubmissionDirectory(
        formInstancesDir, submissionManifest.instanceID)) {
      // create instance directory...
      File instanceDir =
          FileSystemUtils.assertFormSubmissionDirectory(
              formInstancesDir, submissionManifest.instanceID);

      // fetch attachments
      for (MediaFile m : submissionManifest.attachmentList) {
        downloadMediaFileIfChanged(instanceDir, m, fs);
      }

      // write submission file -- we rely on instanceId being unique...
      File submissionFile = new File(instanceDir, "submission.xml");
      OutputStreamWriter fo = new OutputStreamWriter(new FileOutputStream(submissionFile), "UTF-8");
      fo.write(submissionManifest.submissionXml);
      fo.close();

      // if we get here and it was a legacy server (0.9.x), we don't
      // actually know whether the submission was complete.  Otherwise,
      // if we get here, we know that this is a completed submission
      // (because it was in /view/submissionList) and that we safely
      // copied it into the storage area (because we didn't get any
      // exceptions).
      if (serverInfo.isOpenRosaServer()) {
        formDatabase.assertRecordedInstanceDirectory(uri, instanceDir);
      }
    } else {
      // create instance directory...
      File instanceDir =
          FileSystemUtils.assertFormSubmissionDirectory(
              formInstancesDir, submissionManifest.instanceID);

      // fetch attachments
      for (MediaFile m : submissionManifest.attachmentList) {
        downloadMediaFileIfChanged(instanceDir, m, fs);
      }

      // write submission file
      File submissionFile = new File(instanceDir, "submission.xml");
      OutputStreamWriter fo = new OutputStreamWriter(new FileOutputStream(submissionFile), "UTF-8");
      fo.write(submissionManifest.submissionXml);
      fo.close();

      // if we get here and it was a legacy server (0.9.x), we don't
      // actually know whether the submission was complete.  Otherwise,
      // if we get here, we know that this is a completed submission
      // (because it was in /view/submissionList) and that we safely
      // copied it into the storage area (because we didn't get any
      // exceptions).
      if (serverInfo.isOpenRosaServer()) {
        formDatabase.assertRecordedInstanceDirectory(uri, instanceDir);
      }
    }
  }
예제 #23
0
  public void tickGeneric(int tickerId, int tickType, double value) {
    Hashtable f = new Hashtable();
    f.put(TickType.getField(tickType), String.valueOf(value));

    EventBus.publish(new MktDataEvent(tickerId, f));
  }
예제 #24
0
  public void tickString(int tickerId, int tickType, String value) {
    Hashtable f = new Hashtable();
    f.put(TickType.getField(tickType), value);

    EventBus.publish(new MktDataEvent(tickerId, f));
  }
  public boolean downloadFormAndSubmissionFiles(List<FormStatus> formsToTransfer) {
    boolean allSuccessful = true;

    // boolean error = false;
    int total = formsToTransfer.size();

    for (int i = 0; i < total; i++) {
      FormStatus fs = formsToTransfer.get(i);

      if (isCancelled()) {
        fs.setStatusString("aborted. Skipping fetch of form and submissions...", true);
        EventBus.publish(new FormStatusEvent(fs));
        return false;
      }

      RemoteFormDefinition fd = (RemoteFormDefinition) fs.getFormDefinition();
      fs.setStatusString("Fetching form definition", true);
      EventBus.publish(new FormStatusEvent(fs));
      try {

        File tmpdl = FileSystemUtils.getTempFormDefinitionFile();
        AggregateUtils.commonDownloadFile(serverInfo, tmpdl, fd.getDownloadUrl());

        fs.setStatusString("resolving against briefcase form definitions", true);
        EventBus.publish(new FormStatusEvent(fs));

        boolean successful = false;
        BriefcaseFormDefinition briefcaseLfd;
        DatabaseUtils formDatabase = null;
        try {
          try {
            briefcaseLfd = BriefcaseFormDefinition.resolveAgainstBriefcaseDefn(tmpdl);
            if (briefcaseLfd.needsMediaUpdate()) {

              if (fd.getManifestUrl() != null) {
                File mediaDir = FileSystemUtils.getMediaDirectory(briefcaseLfd.getFormDirectory());
                String error = downloadManifestAndMediaFiles(mediaDir, fs);
                if (error != null) {
                  allSuccessful = false;
                  fs.setStatusString("Error fetching form definition: " + error, false);
                  EventBus.publish(new FormStatusEvent(fs));
                  continue;
                }
              }
            }
            formDatabase =
                new DatabaseUtils(FileSystemUtils.getFormDatabase(briefcaseLfd.getFormDirectory()));

          } catch (BadFormDefinition e) {
            e.printStackTrace();
            allSuccessful = false;
            fs.setStatusString("Error parsing form definition: " + e.getMessage(), false);
            EventBus.publish(new FormStatusEvent(fs));
            continue;
          }

          fs.setStatusString("preparing to retrieve instance data", true);
          EventBus.publish(new FormStatusEvent(fs));

          File formInstancesDir =
              FileSystemUtils.getFormInstancesDirectory(briefcaseLfd.getFormDirectory());

          // this will publish events
          successful =
              downloadAllSubmissionsForForm(formInstancesDir, formDatabase, briefcaseLfd, fs);
        } catch (FileSystemException e) {
          e.printStackTrace();
          allSuccessful = false;
          fs.setStatusString("unable to open form database: " + e.getMessage(), false);
          EventBus.publish(new FormStatusEvent(fs));
          continue;
        } finally {
          if (formDatabase != null) {
            try {
              formDatabase.close();
            } catch (SQLException e) {
              e.printStackTrace();
              allSuccessful = false;
              fs.setStatusString("unable to close form database: " + e.getMessage(), false);
              EventBus.publish(new FormStatusEvent(fs));
              continue;
            }
          }
        }

        allSuccessful = allSuccessful && successful;

        // on success, we haven't actually set a success event (because we don't know we're done)
        if (successful) {
          fs.setStatusString("SUCCESS!", true);
          EventBus.publish(new FormStatusEvent(fs));
        } else {
          fs.setStatusString("FAILED.", true);
          EventBus.publish(new FormStatusEvent(fs));
        }

      } catch (SocketTimeoutException se) {
        se.printStackTrace();
        allSuccessful = false;
        fs.setStatusString(
            "Communications to the server timed out. Detailed message: "
                + se.getLocalizedMessage()
                + " while accessing: "
                + fd.getDownloadUrl()
                + " A network login screen may be interfering with the transmission to the server.",
            false);
        EventBus.publish(new FormStatusEvent(fs));
        continue;
      } catch (IOException e) {
        e.printStackTrace();
        allSuccessful = false;
        fs.setStatusString(
            "Unexpected error: "
                + e.getLocalizedMessage()
                + " while accessing: "
                + fd.getDownloadUrl()
                + " A network login screen may be interfering with the transmission to the server.",
            false);
        EventBus.publish(new FormStatusEvent(fs));
        continue;
      } catch (FileSystemException e) {
        e.printStackTrace();
        allSuccessful = false;
        fs.setStatusString(
            "Unexpected error: "
                + e.getLocalizedMessage()
                + " while accessing: "
                + fd.getDownloadUrl(),
            false);
        EventBus.publish(new FormStatusEvent(fs));
        continue;
      } catch (URISyntaxException e) {
        e.printStackTrace();
        allSuccessful = false;
        fs.setStatusString(
            "Unexpected error: "
                + e.getLocalizedMessage()
                + " while accessing: "
                + fd.getDownloadUrl(),
            false);
        EventBus.publish(new FormStatusEvent(fs));
        continue;
      } catch (TransmissionException e) {
        e.printStackTrace();
        allSuccessful = false;
        fs.setStatusString(
            "Unexpected error: "
                + e.getLocalizedMessage()
                + " while accessing: "
                + fd.getDownloadUrl(),
            false);
        EventBus.publish(new FormStatusEvent(fs));
        continue;
      }
    }
    return allSuccessful;
  }
예제 #26
0
  public void tickSize(int tickerId, int field, int size) {
    Hashtable f = new Hashtable();
    f.put(TickType.getField(field), String.valueOf(size));

    EventBus.publish(new MktDataEvent(tickerId, f));
  }