示例#1
0
    @Override
    public Boolean call() throws Exception {
      boolean result = false;

      final Engine e = EngineFactory.getEngine(EngineFactory.DEFAULT);

      if (e != null && securityNode.getQuoteSource() != QuoteSource.NONE) {
        final SecurityParser parser = securityNode.getQuoteSource().getParser();

        if (parser != null
            && !Thread.currentThread().isInterrupted()) { // check for thread interruption
          if (parser.parse(securityNode)) {

            final SecurityHistoryNode node =
                new SecurityHistoryNode(
                    parser.getDate(),
                    parser.getPrice(),
                    parser.getVolume(),
                    parser.getHigh(),
                    parser.getLow());

            if (!Thread.currentThread().isInterrupted()) { // check for thread interruption
              result = e.addSecurityHistory(securityNode, node);

              if (result) {
                logger.info(
                    ResourceUtils.getString("Message.UpdatedPrice", securityNode.getSymbol()));
              }
            }
          }
        }
      }

      return result;
    }
示例#2
0
    @Override
    public Boolean call() throws Exception {
      boolean result = true;

      try {
        final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
        Objects.requireNonNull(engine);

        final List<SecurityHistoryNode> newSecurityNodes =
            downloadHistory(securityNode, startDate, endDate);

        for (final SecurityHistoryNode historyNode : newSecurityNodes) {
          engine.addSecurityHistory(securityNode, historyNode);
        }
      } catch (NullPointerException | NumberFormatException ex) {
        logger.log(Level.SEVERE, null, ex);
        result = false;
      }

      return result;
    }
示例#3
0
  private void parseSecurityNode(final XMLStreamReader reader) {
    Map<String, String> elementMap = new HashMap<>();
    List<SecurityHistoryNode> history = null;

    try {
      /* still at start of the element.  Need to know when end is reached */
      QName parsingElement = reader.getName();

      while (reader.hasNext()) {
        int event = reader.next();

        switch (event) {
          case XMLStreamConstants.START_ELEMENT:
            if (reader.getLocalName().equals("history")) {
              logger.finest("parse history");
              history = parseHistoryNodes(reader);
            } else {
              String element = reader.getLocalName();
              elementMap.put(element, reader.getElementText());
            }
            break;
          case XMLStreamConstants.END_ELEMENT:
            if (reader.getName().equals(parsingElement)) {
              logger.finest("Found the end of a SecurityNode");

              Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);

              if (engine.getSecurity(elementMap.get("symbol")) == null) {

                SecurityNode node = new SecurityNode(engine.getDefaultCurrency());

                node.setSymbol(elementMap.get("symbol"));
                node.setDescription(elementMap.get("description"));
                node.setPrefix(elementMap.get("prefix"));
                node.setSuffix(elementMap.get("suffix"));
                node.setScale(Byte.parseByte(elementMap.get("scale")));
                node.setQuoteSource(QuoteSource.YAHOO);

                if (elementMap.get("reportedCurrency") != null) {
                  SecurityThread thread =
                      new SecurityThread(node, elementMap.get("reportedCurrency"));
                  workQueue.add(thread);
                }

                engine.addSecurity(node);
              }

              if (history != null) {
                SecurityNode node = engine.getSecurity(elementMap.get("symbol"));
                if (node != null) {
                  for (SecurityHistoryNode hNode : history) {
                    if (!engine.addSecurityHistory(node, hNode)) {
                      logger.warning("Failed to add security history");
                    }
                  }
                }
              }
              return;
            }
            break;

          default:
            break;
        }
      }
    } catch (XMLStreamException e) {
      logger.log(Level.SEVERE, "Exception at element: {0}", reader.getName().toString());
      logger.log(Level.SEVERE, e.toString(), e);
    }
  }