/*
 * @author  : Elangovan
 * @version : 1.0
 *
 * Development Environment : Oracle9i JDeveloper
 * Name of the File        : SampleData.java
 *
 * Creation / Modification History
 *    Elangovan           28-Aug-2003        Created
 *
 */
package oracle.otnsamples.ibfbs.admin.helper;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.ArrayList;

import oracle.toplink.tools.schemaframework.SequenceDefinition;
import oracle.toplink.tools.schemaframework.TableDefinition;
import oracle.toplink.tools.schemaframework.OracleSequenceDefinition;

import oracle.otnsamples.ibfbs.toplink.Stockrate;
import oracle.otnsamples.ibfbs.toplink.Symbol;
import oracle.otnsamples.ibfbs.toplink.News;
import oracle.otnsamples.ibfbs.toplink.Exchange;

/**
 * This class holds the data ( tables, sequences and sample data) that is required
 * by FBS application. 
 * 
 * @see DataPopulator.java
 */
public class SampleData {
  
  public static SimpleDateFormat dtFormat = new SimpleDateFormat("dd-MMM-yyyy");
 
  /**
   * Returns Stock Exchange table definition.
   *   Table Name: Exchange
   *     ExchangeID   (Primary Key)
   *     ExchangeName 
   *     Location     
   * 
   * @return  Exchange table definition.
   */
  public static TableDefinition getExchangeTableDefn() {
  
    TableDefinition exchgTable = new TableDefinition();
    exchgTable.setName("EXCHANGE");
    exchgTable.addPrimaryKeyField("EXCHANGEID",Integer.class,10);
    exchgTable.addField("EXCHANGENAME",String.class,20);
    exchgTable.addField("LOCATION",String.class,200);
    return exchgTable;
  }


  /**
   * Returns Symbol table definition.
   * 
   * Table Name : Symbol
   *    Symbol (Primary Key)
   *    CompanyName
   *    CompanyProfile
   *    Traded
   *    ExchangeID References Exchange(ExchangeID)
   * 
   * @return  Symbol table definition
   */
  public static TableDefinition getSymbolTableDefn() {
  
    TableDefinition symbolTable = new TableDefinition();
    symbolTable.setName("SYMBOL");
    symbolTable.addPrimaryKeyField("SYMBOL",String.class,10);
    symbolTable.addField("COMPANYNAME",String.class,100);
    symbolTable.addField("COMPANYPROFILE",String.class,2000);
    symbolTable.addField("TRADED",String.class,1);
    symbolTable.addField("EXCHANGEID",Integer.class,10);
    symbolTable.addForeignKeyConstraint("exchange_symbol_fk","EXCHANGEID","EXCHANGEID","EXCHANGE");
    return symbolTable;
  }

  /**
   * Returns Stockrate table definition.
   * 
   * Table Name : StockRate
   *   Symbol References Symbol(Symbol)  Primary Key
   *   StockDate                         Primary Key
   *   LowPrice
   *   HighPrice
   * 
   * @return Stockrate table definition. 
   */
  public static TableDefinition getStockrateTableDefn() {
  
    TableDefinition srTable = new TableDefinition();
    srTable.setName("STOCKRATE");
    srTable.addPrimaryKeyField("SYMBOL",String.class,10);
    srTable.addPrimaryKeyField("STOCKDATE",Timestamp.class);
    srTable.addField("LOWPRICE",Double.class,15,2);
    srTable.addField("HIGHPRICE",Double.class,15,2);
    srTable.addForeignKeyConstraint("symbol_stockrate_fk","SYMBOL","SYMBOL","SYMBOL");
    return srTable;
  }
  
  /**
   * Returns News table definition.
   * 
   *  Table Name : News
   *     NewsID   PrimaryKey
   *     NewsDate
   *     Symbol   References Symbol(Symbol)
   *     NewsTitle
   *     NewsURL
   * 
   * @return News table definition. 
   */
  public static TableDefinition getNewsTableDefn() {
    TableDefinition newsTable = new TableDefinition();
    newsTable.setName("NEWS");
    newsTable.addPrimaryKeyField("NEWSID",BigDecimal.class,10);
    newsTable.addField("NEWSDATE",java.sql.Date.class);
    newsTable.addField("SYMBOL",String.class,10);
    newsTable.addField("NEWSTITLE",String.class,1000);
    newsTable.addField("NEWSURL",String.class,1000);
    newsTable.addForeignKeyConstraint("news_symbol_fk","SYMBOL","SYMBOL","SYMBOL");
    return newsTable;
  }
 
  /**
   * Returns Oracle sequence definition with the specified name, increment and
   * starts with 'startwith'.
   * 
   * @param seqName Sequence name
   * @param incr increment 
   * @param startwith starts with
   * @return  sequence definition
   */
  public static SequenceDefinition getOracleSequenceDefn(String seqName, int incr,
                                                         int startwith) {
                                                         
    OracleSequenceDefinition seq = new OracleSequenceDefinition(seqName);
    // Increment By
    seq.setIncrement(incr);
    // Start With
    seq.setStart(startwith);
    return seq;
  }
  
  /**
   * Constructs a new Symbol instance with the specified details.
   * 
   * @param sname Symbol name
   * @param cname Company name
   * @param cprofile company profile
   * @param traded wheather traded by this FBS
   * @param exchgId Exchange ID
   * @return Symbol instance
   */
  public static Symbol getSymbol(String sname,String cname, String cprofile, 
                                 String traded, int exchgId) {
    Symbol symbol = new Symbol();
    symbol.setSymbol(sname);
    symbol.setCompanyname(cname);
    symbol.setCompanyprofile(cprofile);
    symbol.setTraded(traded);
    symbol.setExchangeid(new Integer(exchgId));
    return symbol;
  }
  
  /**
   * Contructs a new instance of Stockrate with the specified details.
   * 
   * @param sname Stock Symbol name
   * @param sdate Stock rate on this date
   * @param lprice low price of the day
   * @param hprice high price of the day
   * @return  Stockrate instance
   */
  public static Stockrate getStockrate(String sname, java.util.Date sdate, 
                                           double lprice, double hprice) {
  
    Stockrate sr = new Stockrate();
    
    sr.setSymbol(sname);
    sr.setStockdate(new Timestamp(sdate.getTime()));
    sr.setLowprice(new Double(lprice));
    sr.setHighprice(new Double(hprice));
    
    return sr;
  }
  
  /**
   * Constructs a new News instance with the specified details.
   * 
   * @param newsdate News on this date.
   * @param sym Stock symbol
   * @param title News title
   * @param url HTTP url for the news item
   * @return  News instance
   */
  public static News getNews(java.util.Date newsdate, String sym, String title, String url) {
    News news = new News();
    
    news.setNewsdate(new Timestamp(newsdate.getTime()));
    news.setNewstitle(title);
    news.setSymbol(sym);
    news.setNewsurl(url);
    
    return news;
  }

  /**
   * Construct a collection containing the Stock Exchanges to be populated.
   * 
   * @return  Collection of Exchanges to be populated
   */
  public static Collection populateExchange() {

    Collection xchgs = new ArrayList();
    
    Exchange nyExchange  =  new Exchange();
    nyExchange.setExchangeid(new Integer(1));
    nyExchange.setExchangename("NYSE");
    nyExchange.setLocation("New York Stock Exchange, USA");
    
    xchgs.add(nyExchange);
    return xchgs;
  }

  /**
   * Constructs the Symbols to be populated and returns them in a Collection.
   * 
   * @return  Collection of Symbols to be populated.
   */
  public static Collection populateSymbol() {
    Collection symbols = new ArrayList();
    
    symbols.add(SampleData.getSymbol("ORCL", "Oracle",
         "Oracle Corporation is a supplier of software for information management. The Company develops, manufactures, markets and distributes computer software thathelps corporations manage and grow their businesses. The Companys software productscan be categorized into two broad areas: systems software and business applicationssoftware.", 
         "Y", 1));
    symbols.add(SampleData.getSymbol("AOL", "AOL",
         "AOL Time Warner Inc. is a fully integrated, Internet-powered media and communications company. The Company was formed in connection with the merger of America Online, Inc.(America Online) and Time Warner Inc. (Time Warner), which was consummated on January 11, 2001. America Online and Time Warner are wholly owned subsidiaries of AOL Time Warner.",
         "Y", 1));
    symbols.add(SampleData.getSymbol("BEAS", "Bea Systems", 
         "BEA Systems, Inc. is a e-business infrastructure software company. Customers use BEA products as a deployment platform for Internet-based applications including custom-built and packaged applications, and as a means for robust enterprise application integration among mainframe, client/server and Internet-basedapplications.", 
         "Y", 1));
    symbols.add(SampleData.getSymbol("CSCO", "CISCO Systems", 
         "Cisco Systems Inc. is engaged in networking for the Internet. Cisco Internet Protocol(IP)-based networking solutions are installed at corporations, public institutions and telecommunication companies, and are found in a growing number of medium-sized commercial enterprises.",
         "Y", 1));
    symbols.add(SampleData.getSymbol("IBM", "IBM", 
         "International Business Machines Corporation (IBM) manufactures and sells computer services, hardware and software. The Company also provides financing services in support of its computer business. The Companys major operations comprise a Global Services segment, three hardware product segments (Enterprise Systems, Personal and Printing Systems, and Technology), a Software segment, a Global Financing segmentand an Enterprise Investments segment.",
         "Y", 1));
    symbols.add(SampleData.getSymbol("HPQ", "HEWLETT-PACKARD", 
         "Hewlett-Packard Company is a global provider of products, technologies, solutions and services. The Companys offerings span information technology (IT) infrastructure,personal computing and access devices, global services and imaging and printing. In May 2002, the Company merged with Compaq Computer Corporation.", 
         "Y", 1));
    symbols.add(SampleData.getSymbol("MSFT", "Microsoft", 
         "Microsoft Corporation develops, manufactures, licenses and supports a wide range ofsoftware products for a multitude of computing devices. Microsoft software includes scalable operating systems for servers, personal computers (PCs) and intelligent devices, server applications for client/server environments; knowledge worker productivity applications; and software development tools. ", 
         "Y", 1));
    symbols.add(SampleData.getSymbol("PSFT", "Peoplesoft", 
         "PeopleSoft, Inc. designs, develops, markets and supports a family of enterprise application software products for use throughout large and medium-sized organizations.The Company provides enterprise application software for customer relationship management (CRM), human resources management, financial management and supply chain management (SCM), along with a range of industry-specific products.",
         "Y", 1));
    symbols.add(SampleData.getSymbol("SUNW", "Sun Microsystems",
         "Sun Microsystems, Inc. (Sun) is a worldwide provider of products, services and support solutions for building and maintaining network computing environments. Sun sells scalable computer and storage systems, high-speed microprocessors, and a comprehensive line of high-performance software for operating network computingequipment. ",
         "Y", 1));
    return symbols;
  }

  /**
   * Constructs the Stock rates to be populated and returns them in a Collection.
   * 
   * @return  Collection of StockRates to be populated
   */
  public static Collection populateStockRate() {
  
    Collection stockrates = new ArrayList();
    
    try {
    stockrates.add(SampleData.getStockrate("PSFT", dtFormat.parse("28-AUG-2003"), 
      16.79, 17.29));
    stockrates.add(SampleData.getStockrate("HPQ", dtFormat.parse("28-AUG-2003"),
      19.52, 20.02));
    stockrates.add(SampleData.getStockrate("SUNW", dtFormat.parse("28-AUG-2003"),
      3.81, 4.31));
    stockrates.add(SampleData.getStockrate("CSCO", dtFormat.parse("28-AUG-2003"),
      19.01, 19.51));
    stockrates.add(SampleData.getStockrate("IBM", dtFormat.parse("28-AUG-2003"),
      82, 82.5));
    stockrates.add(SampleData.getStockrate("BEAS", dtFormat.parse("28-AUG-2003"),
      12.63, 13.13));
    stockrates.add(SampleData.getStockrate("AOL", dtFormat.parse("28-AUG-2003"),
      15.85, 16.35));
    stockrates.add(SampleData.getStockrate("ORCL", dtFormat.parse("28-AUG-2003"),
      12.45, 12.95));
    stockrates.add(SampleData.getStockrate("MSFT", dtFormat.parse("28-AUG-2003"),
      26.42, 26.92));
    }catch(ParseException parseEx) {
      System.out.println("Error loading stock rates :"+parseEx);
    }
    return stockrates;
  }  

  /**
   * Constructs the News to be populated and returns them in a Collection.
   * 
   * @return  Collection of News items.
   */
  public static Collection populateStockNews() {
  
    Collection stocknews = new ArrayList();
    try {
    
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "HPQ", "Yahoo! Finance - Before the Bell- Network Appliance, Hewlett- ... ", "http%3A%2F%2Fuk.biz.yahoo.com%2F030820%2F80%2Fe6jia.html"));

      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "CSCO", "TheStreet.com: Cisco, Lucent and Nortel: Prime Lenders for the ... ", "http%3A%2F%2Fwww.thestreet.com%2Ftech%2Ftelecom%2F1163145.html"));
      
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "CSCO", "Cisco: Stock Options Fuel IT Industry Growth", "http%3A%2F%2Fwww.internetnews.com%2Ffina-news%2Farticle.php%2F10795_2233641"));
      
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "SUNW", "Before the Bell-Sun drops, GlaxoSmithKline rises", "http%3A%2F%2Fuk.biz.yahoo.com%2F030723%2F80%2Fe4s50.html"));
           
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "AOL", "US stocks to open higher, eyes on AOL, Kodak", "http%3A%2F%2Fuk.biz.yahoo.com%2F030723%2F80%2Fe4s0e.html"));
            
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "SUNW", "Before the Bell-Cyberonics up, Sun Microsystems ... ", "http%3A%2F%2Fuk.biz.yahoo.com%2F030723%2F80%2Fe4s6o.html"));
            
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "PSFT", "PeopleSoft Beats Estimates, Announces Stock ... ", "http%3A%2F%2Fwww.thestreet.com%2Fbrknews%2Fsoftware%2F1129762.html"));
           
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "HPQ", "Hewlett-Packard, Intel fall",
       "http%3A%2F%2Fuk.biz.yahoo.com%2F030820%2F80%2Fe6jgn.html"));
        
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "ORCL", "US tech stocks rise on Oracle. other shares dip", "http%3A%2F%2Fuk.biz.yahoo.com%2F030811%2F80%2Fe5zuo.html"));
           
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "IBM", "US stocks fall as IBM, Nokia earnings disappoint", "http%3A%2F%2Fuk.biz.yahoo.com%2F030717%2F80%2Fe4gw7.html"));
            
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "AOL", "AOL yahoo news", "http%3A%2F%2Ffinance.yahoo.com%2Fq%3Fs%3Daol"));     
      
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "MSFT", " US stocks fly on Microsoft, McDonald's, budget ... ", "http%3A%2F%2Fuk.biz.yahoo.com%2F030718%2F80%2Fe4j8w.html"));      
      
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "BEAS", "BEA Systems' Profit Up, but Stock Slips", "http%3A%2F%2Fbiz.yahoo.com%2Frb%2F030814%2Ftech_beasystems_earns_1.html"));
            
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "BEAS", "BEA Systems Posts Good Numbers, but Own Stock ... ", "http%3A%2F%2Fwww.thestreet.com%2Ftech%2Fsoftware%2F1173760.html"));      
      
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "IBM", "US stocks slide on disappointment over IBM, ... ", "http%3A%2F%2Fuk.biz.yahoo.com%2F030717%2F80%2Fe4gsx.html"));
            
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "PSFT", "Before the Bell- ImClone, PeopleSoft, Oracle ... ", "http%3A%2F%2Fuk.biz.yahoo.com%2F030606%2F80%2Fe1pz8.html"));
            
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "PSFT", "PeopleSoft Stock Price", "http%3A%2F%2Fwww.businessweek.com%2Fmagazine%2Fcontent%2F02_15%2Fc3778062.htm"));
            
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "BEAS", "AMAT, BEA Systems Rise After Hours", "http%3A%2F%2Fstocks.internetnews.com%2Fclose%2Farticle%2F0%2C%2C1701_866091%2C00.html"));
            
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "MSFT", "Microsoft cuts stock options (archived)", "http%3A%2F%2Ffinance.news.com.au%2Fcommon%2Fstory_page%2F0%2C4057%2C6725129%25255E14305%2C00.html"));
            
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "AOL", "Yahoo! Finance - AOL", "http%3A%2F%2Ffinance.yahoo.com%2Fq%3Fs%3DAOL"));
            
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "HPQ", "Before the Bell-Network Appliance up, Hewlett- ... ", "http%3A%2F%2Fuk.biz.yahoo.com%2F030820%2F80%2Fe6jro.html"));
            
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "ORCL", "Oracle scales back Ellison's stock ...", "http%3A%2F%2Fuk.biz.yahoo.com%2F030716%2F94%2Fe4a9q.html"));
            
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "MSFT", "Microsoft to beef up finance function", "http%3A%2F%2Fwww.msnbc.com%2Fnews%2F942907.asp"));
            
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "ORCL", "US tech issues boosted by Oracle; Dow flat", "http%3A%2F%2Fuk.biz.yahoo.com%2F030811%2F80%2Fe6035.html"));
            
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "CSCO", "Cisco: Stock Options Fuel IT Industry Growth", "http%3A%2F%2Fwww.internetnews.com%2Ffina-news%2Farticle.php%2F2233641"));
    
      stocknews.add(SampleData.getNews(dtFormat.parse("28-AUG-2003"),
      "IBM", "US stocks slide on disappointment over IBM, ... ", "http%3A%2F%2Fuk.biz.yahoo.com%2F030717%2F80%2Fe4gsw.html"));

    } catch(ParseException parseEx) {
      System.err.println("Error parsing date to construct stock news :"+parseEx);
    }
    return stocknews;
  }      
}