Jump to: navigation, search

Scout/Tutorial/3.9/webservices/Integrate StockQuote service into CompanyService

< Scout‎ | Tutorial‎ | 3.9‎ | webservices
Revision as of 13:51, 21 August 2013 by Jbr.bsiag.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Scout
Wiki Home
Website
DownloadGit
Community
ForumsBlogTwitter
Bugzilla
Bugzilla
@Override
public CompanyFormData load(CompanyFormData formData) throws ProcessingException {
  SQL.selectInto("" +
      "SELECT NAME, " +
      "       SYMBOL " +
      "FROM   COMPANY " +
      "WHERE  COMPANY_NR = :companyNr " +
      "INTO   :name, " +
      "       :symbol "
      , formData);
 
  // get stock qutoes from webservice
  StockQuoteServiceSoapWebServiceClient service = SERVICES.getService(StockQuoteServiceSoapWebServiceClient.class);
  // get port type to access webservice
  StockQuoteServiceSoap portType = service.getPortType();
 
  // get quote for the given company
  StockQuote stockQuote = portType.getStockQuote(formData.getSymbol().getValue());
  // load quotes into form data to be transferred to client
  formData.getSymbol().setValue(stockQuote.getStockTickerSymbol());
  formData.getTradeTime().setValue(parseDateTime(stockQuote.getDate(), stockQuote.getTradeTime()));
  formData.getValueLast().setValue(parseDouble(stockQuote.getLastTrade()));
  formData.getValueOpen().setValue(parseDouble(stockQuote.getOpen()));
  formData.getValueLow().setValue(parseDouble(stockQuote.getDayLow()));
  formData.getValueHigh().setValue(parseDouble(stockQuote.getDayHigh()));
  formData.getVolume().setValue(parseLong(stockQuote.getVolume()));
  formData.getChange().setValue(parseDouble(stockQuote.getChangePercentage()));
 
  return formData;
}