Author: rineholt
Date: Wed May 3 06:36:14 2006
New Revision: 399297
URL: http://svn.apache.org/viewcvs?rev=399297&view=rev
Log:
Does stock transactions.
Added:
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/accountTransaction.jsp
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/purchaseStock.jsp
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/stockSale.jsp
Modified:
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/account/AccountServiceImpl.java
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataService.java
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataServiceDASImpl.java
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataServiceImpl.java
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdb/AccountDBInit.java
incubator/tuscany/java/samples/bigbank/account/src/main/resources/DasAccountConfiguration.xml
incubator/tuscany/java/samples/bigbank/account/src/main/resources/wsdl/AccountService.wsdl
incubator/tuscany/java/samples/bigbank/webclient/src/main/java/org/apache/tuscany/samples/bigbank/webclient/services/account/AccountServiceComponentImpl.java
incubator/tuscany/java/samples/bigbank/webclient/src/main/java/org/apache/tuscany/samples/bigbank/webclient/ui/FormServlet.java
incubator/tuscany/java/samples/bigbank/webclient/src/main/java/org/apache/tuscany/samples/bigbank/webclient/ui/LoginServlet.java
incubator/tuscany/java/samples/bigbank/webclient/src/main/resources/wsdl/AccountService.wsdl
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/login.html
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/summary.jsp
Modified:
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/account/AccountServiceImpl.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/account/AccountServiceImpl.java?rev=399297&r1=399296&r2=399297&view=diff
==============================================================================
---
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/account/AccountServiceImpl.java
(original)
+++
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/account/AccountServiceImpl.java
Wed May 3 06:36:14 2006
@@ -17,10 +17,14 @@
package org.apache.tuscany.samples.bigbank.account.services.account;
import java.rmi.RemoteException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.TimeZone;
import
org.apache.tuscany.samples.bigbank.account.services.accountdata.AccountDataService;
import
org.apache.tuscany.samples.bigbank.account.services.stockquote.StockQuote;
@@ -44,8 +48,11 @@
public static final String ACCOUNT_TYPE_SAVINGS = "savings";
public static final String ACCOUNT_TYPE_CHECKINGS = "checkings";
- static {
+ public static final DateFormat tsformatXSDDateTime = new
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz");
+
+ static {
SDOUtil.registerStaticTypes(AccountFactory.class);
+
AccountServiceImpl.tsformatXSDDateTime.setTimeZone(TimeZone.getTimeZone("UTC"));
}
private String currency = "USD";
@@ -198,14 +205,39 @@
}
}
- public StockSummary purchaseStock(int param0, String param1, int param2)
throws RemoteException {
- // TODO Auto-generated method stub
- return null;
+ public StockSummary purchaseStock(int id, StockSummary stock) throws
RemoteException {
+ try{
+ String symbol= stock.getSymbol();
+ Map<String, StockQuote> stockInfo =
stockQuoteService.getQuotes(new String[]{symbol});
+
+ StockQuote stockQuote = stockInfo.get(symbol);
+
stock.setPurchasePrice(Float.parseFloat(stockQuote.getStockQuote()));
+ String purchaseDate= tsformatXSDDateTime.format(new Date());
+ if (purchaseDate.endsWith("UTC"))
+ purchaseDate = purchaseDate.substring(0, purchaseDate.length()
- 3) + "Z";
+ stock.setPurchaseDate(purchaseDate);
+
+
+ return accountDataService.purchaseStock(id, stock);
+ } catch (RemoteException e){
+ e.printStackTrace();
+ throw e;
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RemoteException(e.getClass() + " " +e.getMessage(),e);
+ }
}
- public StockSummary sellStock(int param9, int param10) throws
RemoteException {
- // TODO Auto-generated method stub
- return null;
+ public StockSummary sellStock(int purchaseLotNumber, int quantity) throws
RemoteException {
+ try{
+ return accountDataService.sellStock(purchaseLotNumber, quantity);
+ } catch (RemoteException e){
+ e.printStackTrace();
+ throw e;
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RemoteException(e.getClass() + " " +e.getMessage(),e);
+ }
}
public float withdraw(String account, float ammount) throws
RemoteException {
Modified:
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataService.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataService.java?rev=399297&r1=399296&r2=399297&view=diff
==============================================================================
---
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataService.java
(original)
+++
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataService.java
Wed May 3 06:36:14 2006
@@ -25,7 +25,7 @@
* @param param0* @param param1* @param param2
*/
public com.bigbank.account.StockSummary purchaseStock(
- int param0,java.lang.String param1,int param2) throws
java.rmi.RemoteException;
+ int param0,com.bigbank.account.StockSummary parm1) throws
java.rmi.RemoteException;
/**
Modified:
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataServiceDASImpl.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataServiceDASImpl.java?rev=399297&r1=399296&r2=399297&view=diff
==============================================================================
---
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataServiceDASImpl.java
(original)
+++
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataServiceDASImpl.java
Wed May 3 06:36:14 2006
@@ -16,15 +16,19 @@
*/
package org.apache.tuscany.samples.bigbank.account.services.accountdata;
+import java.awt.geom.QuadCurve2D;
import java.io.InputStream;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.SQLException;
+import java.sql.Timestamp;
import java.text.DateFormat;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
+import java.util.List;
import java.util.Properties;
import java.util.TimeZone;
@@ -54,7 +58,13 @@
static {
SDOUtil.registerStaticTypes(AccountFactory.class);
}
-
+ public static final DateFormat tsformatXSDDateTime = new
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz");
+ public static final DateFormat sqlformatDateTime = new
SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSz");
+
+ static {
+ tsformatXSDDateTime.setTimeZone(TimeZone.getTimeZone("UTC"));
+ //sqlformatDateTime.setTimeZone(TimeZone.getTimeZone("UTC"));
+ }
public CustomerProfileData getCustomerProfile(String logonID) throws
RemoteException {
try {
@@ -107,8 +117,8 @@
Collection customers = root.getCustomerProfileData();
CustomerProfileData customerProfileData = (CustomerProfileData)
customers.iterator().next();
-System.out.println(customerProfileData);
-System.out.flush();
+//System.out.println(customerProfileData);
+//System.out.flush();
return customerProfileData;
}
@@ -256,14 +266,68 @@
}
- public StockSummary sellStock(int param13, int param14) throws
RemoteException {
- // TODO Auto-generated method stub
- return null;
+ public StockSummary sellStock(int purchaseLotNumber, int quantity) throws
RemoteException {
+ try {
+ CommandGroup commandGroup =
CommandGroup.FACTORY.createCommandGroup(createConfigStream());
+ commandGroup.setConnection(getConnection());
+
+ Command read = commandGroup.getCommand("stockbylotSelect");
+ TypeHelper helper = TypeHelper.INSTANCE;
+ read.setDataObjectModel(helper.getType(DataGraphRoot.class));
+ read.setParameterValue("PURCHASELOTNUMBER",
purchaseLotNumber);//autoboxing :-)
+ DataGraphRoot root = (DataGraphRoot) read.executeQuery();
+ List stocks= root.getStockSummaries();
+ if(null != stocks && !stocks.isEmpty()){
+ StockSummary stock= (StockSummary) stocks.get(0);
+ int newQuatity = Math.max(stock.getQuantity() - quantity, 0);
+ if( newQuatity <1 ){
+
+ Command delete = Command.FACTORY.createCommand("DELETE
FROM STOCKS WHERE PURCHASELOTNUMBER = ?");
+ delete.setParameterValue(1, purchaseLotNumber);
+ delete.setConnection(getConnection());
+ delete.execute();
+
+ }else{
+
+ Command update = commandGroup.getCommand("stockbylot");
+
+ update.setParameterValue("QUANTITY", newQuatity);
+ update.setParameterValue("PURCHASELOTNUMBER",
purchaseLotNumber);
+ update.execute();
+
+ stock.setQuantity(newQuatity);
+ }
+
+ }
+
+
+ return null;
+ } catch (Exception e) {
+ throw new RemoteException("sellStock",e);
+ }
}
- public StockSummary purchaseStock(int param0, String param1, int param2)
throws RemoteException {
- // TODO Auto-generated method stub
- return null;
+ public StockSummary purchaseStock(int id, StockSummary stock) throws
RemoteException {
+
+ try {
+
+ Command insert = Command.FACTORY.createCommand("insert into stocks
(id, symbol, quantity, purchasePrice, purchaseDate) values (?,?,?,?,?)");
+ insert.setParameterValue(1, new Integer(id));
+ insert.setParameterValue(2, stock.getSymbol());
+ insert.setParameterValue(3, stock.getQuantity());
+ insert.setParameterValue(4, stock.getPurchasePrice());
+ insert.setParameterValue(5,
DateConverter.INSTANCE.getColumnValue(stock.getPurchaseDate()));
+
+ insert.setConnection(getConnection());
+ insert.execute();
+
+
+ return stock;
+ } catch (Exception e) {
+ if (e instanceof RemoteException)
+ throw (RemoteException) e;
+ throw new RemoteException("purchaseStock " +
e.getClass().getName() + "'. " + e.getMessage(), e);
+ }
}
protected Connection getConnection() throws InstantiationException,
IllegalAccessException, ClassNotFoundException, SQLException {
@@ -284,6 +348,7 @@
}
public static class DateConverter implements Converter {
+ public final static DateConverter INSTANCE = new DateConverter();
public DateConverter() {
}
@@ -291,13 +356,10 @@
private static final DateFormat tsformatXSDDate = new
SimpleDateFormat("yyyy-MM-dd");
- private static final DateFormat tsformatXSDDateTime = new
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz");
-
public Object getPropertyValue(Object columnData) {
try {
-
- tsformatXSDDateTime.setTimeZone(TimeZone.getTimeZone("UTC"));
+
String ret = tsformatXSDDateTime.format(columnData);
if (ret.endsWith("UTC"))
ret = ret.substring(0, ret.length() - 3) + "Z";
@@ -312,12 +374,34 @@
}
public Object getColumnValue(Object propertyData) {
-
- if (propertyData instanceof Date) {
- return tsformat.format(propertyData);
+
+ if (propertyData instanceof java.util.Date) {
+ //Need to convert back to local time for DB and remove
timezone notation at the end..
+ String ret= sqlformatDateTime.format(propertyData);
+ char lc= ret.charAt(ret.length()-1);
+ while(!Character.isDigit(lc)){
+ ret= ret.substring(0, ret.length()-1);
+ lc= ret.charAt(ret.length()-1);
+ }
+ return ret;
+ } else if (propertyData instanceof String) {
+
+ try {
+ String time= (String) propertyData;
+ char last= time.charAt(time.length()-1);
+ if(last == 'z' || last =='Z'){
+ time= time.substring(0,time.length()-1);
+ }
+ if(!time.endsWith("UTC")){
+ time= time + "UTC";
+ }
+ return getColumnValue(tsformatXSDDateTime.parse(time));
+ } catch (ParseException e) {
+ throw new IllegalArgumentException("'" +propertyData +"'
does not parse to date.");
+ }
} else
throw new IllegalArgumentException();
-
+
}
}
Modified:
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataServiceImpl.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataServiceImpl.java?rev=399297&r1=399296&r2=399297&view=diff
==============================================================================
---
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataServiceImpl.java
(original)
+++
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataServiceImpl.java
Wed May 3 06:36:14 2006
@@ -18,7 +18,9 @@
import java.rmi.RemoteException;
import java.util.List;
+import java.util.TimeZone;
+import
org.apache.tuscany.samples.bigbank.account.services.account.AccountServiceImpl;
import org.osoa.sca.annotations.Service;
import com.bigbank.account.AccountFactory;
@@ -32,6 +34,7 @@
public class AccountDataServiceImpl implements AccountDataService {
+
public CustomerProfileData getCustomerProfile(String logonID) throws
RemoteException {
// TODO Auto-generated method stub
return null;
@@ -83,7 +86,7 @@
return 0;
}
- public StockSummary purchaseStock(int param0, String param1, int param2)
throws RemoteException {
+ public StockSummary purchaseStock(int param0, StockSummary stock) throws
RemoteException {
// TODO Auto-generated method stub
return null;
}
Modified:
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdb/AccountDBInit.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdb/AccountDBInit.java?rev=399297&r1=399296&r2=399297&view=diff
==============================================================================
---
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdb/AccountDBInit.java
(original)
+++
incubator/tuscany/java/samples/bigbank/account/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdb/AccountDBInit.java
Wed May 3 06:36:14 2006
@@ -34,6 +34,7 @@
import com.bigbank.account.AccountSummary;
import com.bigbank.account.CustomerProfileData;
import com.bigbank.account.DataGraphRoot;
+import com.bigbank.account.StockSummary;
import com.bigbank.account.purchaseStock;
import com.bigbank.account.withdraw;
import commonj.sdo.DataObject;
@@ -279,9 +280,11 @@
// test stock purchase.
purchaseStock sp = AccountFactory.INSTANCE.createpurchaseStock();
- sp.setSymbol("GOOG");
+ StockSummary stock= AccountFactory.INSTANCE.createStockSummary();
+ sp.setStock(stock);
+ stock.setSymbol("GOOG");
sp.setId(1);
- sp.setQuantity(10);
+ stock.setQuantity(10);
accountDBInit.testStrockPurchaseThroughDAS(sp);
accountDBInit.readDBstdout(System.out);
@@ -301,8 +304,8 @@
// Create a new stockPurchase
DataObject stockPurchase = root.createDataObject("STOCKS");
stockPurchase.set("ID", new Integer(sp.getId()));
- stockPurchase.set("SYMBOL", sp.getSymbol());
- stockPurchase.set("QUANTITY", new Integer(sp.getQuantity()));
+ stockPurchase.set("SYMBOL", sp.getStock().getSymbol());
+ stockPurchase.set("QUANTITY", new
Integer(sp.getStock().getQuantity()));
stockPurchase.set("PURCHASEPRICE", new Float(11.00));
stockPurchase.set("PURCHASEDATE", new Date());
Modified:
incubator/tuscany/java/samples/bigbank/account/src/main/resources/DasAccountConfiguration.xml
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/samples/bigbank/account/src/main/resources/DasAccountConfiguration.xml?rev=399297&r1=399296&r2=399297&view=diff
==============================================================================
---
incubator/tuscany/java/samples/bigbank/account/src/main/resources/DasAccountConfiguration.xml
(original)
+++
incubator/tuscany/java/samples/bigbank/account/src/main/resources/DasAccountConfiguration.xml
Wed May 3 06:36:14 2006
@@ -11,17 +11,16 @@
<Column name="PASSWORD"/>
<Column name="ID"/>
</Table>
+
<Table name="ACCOUNTS" propertyName="AccountSummary">
<!-- Column name="firstName" primaryKey="true"/ -->
<Column name="ACCOUNTNUMBER"/>
<Column name="BALANCE"/>
</Table>
-<!--
-"create table stocks(id int NOT NULL, Symbol varchar(8) NOT NULL, quantity int
NOT NULL, purchasePrice real NOT NULL, purchaseDate TIMESTAMP,
purchaseLotNumber int NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY )");
--->
+
+
<Table name="STOCKS" propertyName="StockSummary" >
-
<Column name="ID"/>
<Column name="Symbol"/>
<Column name="quantity"/>
@@ -35,11 +34,17 @@
kind="Update">
<Parameter name=":BALANCE"/>
<Parameter name=":ACCOUNTNUMBER"/>
- </Command>
+ </Command>
<Command name="all stocks" SQL="select * from stocks" kind="Select"/>
- <Command name="all customers" SQL="select * from CUSTOMERS"
kind="Select"/>
-
+ <Command name="all customers" SQL="select from CUSTOMERS" kind="Select"/>
+ <Command name="stockbylotSelect" SQL="select quantity from STOCKS WHERE
purchaseLotNumber = :PURCHASELOTNUMBER" kind="Select" >
+ <Parameter name=":PURCHASELOTNUMBER"/>
+ </Command>
+ <Command name="stockbylot" SQL="update STOCKS set quantity = :QUANTITY
WHERE purchaseLotNumber = :PURCHASELOTNUMBER" kind="Update" >
+ <Parameter name=":QUANTITY"/>
+ <Parameter name=":PURCHASELOTNUMBER"/>
+ </Command>
</Config>
Modified:
incubator/tuscany/java/samples/bigbank/account/src/main/resources/wsdl/AccountService.wsdl
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/samples/bigbank/account/src/main/resources/wsdl/AccountService.wsdl?rev=399297&r1=399296&r2=399297&view=diff
==============================================================================
---
incubator/tuscany/java/samples/bigbank/account/src/main/resources/wsdl/AccountService.wsdl
(original)
+++
incubator/tuscany/java/samples/bigbank/account/src/main/resources/wsdl/AccountService.wsdl
Wed May 3 06:36:14 2006
@@ -153,8 +153,7 @@
<xsd:complexType>
<xsd:sequence>
<xsd:element name="id"
type="xsd:int" />
- <xsd:element name="symbol"
type="xsd:string" />
- <xsd:element name="quantity"
type="xsd:int" />
+ <xsd:element name="stock"
type="account:StockSummary" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Modified:
incubator/tuscany/java/samples/bigbank/webclient/src/main/java/org/apache/tuscany/samples/bigbank/webclient/services/account/AccountServiceComponentImpl.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/samples/bigbank/webclient/src/main/java/org/apache/tuscany/samples/bigbank/webclient/services/account/AccountServiceComponentImpl.java?rev=399297&r1=399296&r2=399297&view=diff
==============================================================================
---
incubator/tuscany/java/samples/bigbank/webclient/src/main/java/org/apache/tuscany/samples/bigbank/webclient/services/account/AccountServiceComponentImpl.java
(original)
+++
incubator/tuscany/java/samples/bigbank/webclient/src/main/java/org/apache/tuscany/samples/bigbank/webclient/services/account/AccountServiceComponentImpl.java
Wed May 3 06:36:14 2006
@@ -37,16 +37,16 @@
@Service(AccountService.class)
public class AccountServiceComponentImpl implements AccountService {
- static {
- SDOUtil.registerStaticTypes(AccountFactory.class);
- TypeHelper th = SDOUtil.createTypeHelper();
- XSDHelper xsdHelper = SDOUtil.createXSDHelper(th);
-
- InputStream xsdInputStream =
AccountServiceComponentImpl.class.getClassLoader().getResourceAsStream("wsdl/AccountService.wsdl");
- xsdHelper.define(xsdInputStream, null);
-
-
- }
+// static {
+// SDOUtil.registerStaticTypes(AccountFactory.class);
+// TypeHelper th = SDOUtil.createTypeHelper();
+// XSDHelper xsdHelper = SDOUtil.createXSDHelper(th);
+//
+// InputStream xsdInputStream =
AccountServiceComponentImpl.class.getClassLoader().getResourceAsStream("wsdl/AccountService.wsdl");
+// xsdHelper.define(xsdInputStream, null);
+//
+//
+// }
private AccountService accountService;
@@ -73,9 +73,9 @@
}
}
- public StockSummary purchaseStock(int customerID) throws RemoteException {
+ public StockSummary purchaseStock(int customerID, StockSummary
stockSummary) throws RemoteException {
try {
- return accountService.purchaseStock(customerID, null, customerID);
+ return accountService.purchaseStock(customerID, stockSummary);
} catch (Exception e) {
throw new ServiceUnavailableException(e);
}
@@ -97,14 +97,13 @@
}
}
- public StockSummary purchaseStock(int param0, String param1, int param2)
throws RemoteException {
- // TODO Auto-generated method stub
- return null;
- }
- public StockSummary sellStock(int param9, int param10) throws
RemoteException {
- // TODO Auto-generated method stub
- return null;
+ public StockSummary sellStock(int purchaseLotNumber, int quantity) throws
RemoteException {
+ try {
+ return accountService.sellStock(purchaseLotNumber, quantity);
+ } catch (Exception e) {
+ throw new ServiceUnavailableException(e);
+ }
}
public float withdraw(String account, float amount) throws RemoteException
{
Modified:
incubator/tuscany/java/samples/bigbank/webclient/src/main/java/org/apache/tuscany/samples/bigbank/webclient/ui/FormServlet.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/samples/bigbank/webclient/src/main/java/org/apache/tuscany/samples/bigbank/webclient/ui/FormServlet.java?rev=399297&r1=399296&r2=399297&view=diff
==============================================================================
---
incubator/tuscany/java/samples/bigbank/webclient/src/main/java/org/apache/tuscany/samples/bigbank/webclient/ui/FormServlet.java
(original)
+++
incubator/tuscany/java/samples/bigbank/webclient/src/main/java/org/apache/tuscany/samples/bigbank/webclient/ui/FormServlet.java
Wed May 3 06:36:14 2006
@@ -17,58 +17,61 @@
package org.apache.tuscany.samples.bigbank.webclient.ui;
import java.io.IOException;
-import java.io.InputStream;
-import java.rmi.RemoteException;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import
org.apache.tuscany.samples.bigbank.webclient.services.account.AccountServiceComponentImpl;
-import org.apache.tuscany.sdo.util.SDOUtil;
+import
org.apache.tuscany.samples.bigbank.webclient.services.profile.ProfileService;
import org.osoa.sca.CurrentModuleContext;
import org.osoa.sca.ModuleContext;
import com.bigbank.account.AccountFactory;
import com.bigbank.account.AccountService;
import com.bigbank.account.CustomerProfileData;
-import commonj.sdo.helper.TypeHelper;
-import commonj.sdo.helper.XSDHelper;
+import com.bigbank.account.StockSummary;
public class FormServlet extends HttpServlet {
- static {
- SDOUtil.registerStaticTypes(AccountFactory.class);
- TypeHelper th = SDOUtil.createTypeHelper();
- XSDHelper xsdHelper = SDOUtil.createXSDHelper(th);
-
- InputStream xsdInputStream =
AccountServiceComponentImpl.class.getClassLoader().getResourceAsStream("wsdl/AccountService.wsdl");
- xsdHelper.define(xsdInputStream, null);
- }
- private ServletContext mContext;
- public void init(ServletConfig pCfg) throws ServletException {
- mContext = pCfg.getServletContext();
- }
+// private ServletContext mContext;
+// public void init(ServletConfig pCfg) throws ServletException {
+// mContext = pCfg.getServletContext();
+// }
public void doPost(HttpServletRequest pReq, HttpServletResponse pResp)
throws ServletException {
try {
+ final String action = pReq.getParameter("action");
ModuleContext moduleContext = CurrentModuleContext.getContext();
AccountService accountServices = (AccountService)
moduleContext.locateService("AccountServiceComponent");
if (accountServices == null) {
throw new ServletException("AccountServiceComponent");
}
- final String action = pReq.getParameter("action");
+ ProfileService profileServices = null;
+ if (!"createAccount".equals(action)) {
+ profileServices = (ProfileService)
moduleContext.locateService("ProfileServiceComponent");
+ if (profileServices == null) {
+ throw new ServletException("ProfileServiceComponent not
found.");
+ }
+ if(!profileServices.isLoggedIn()){
+ throw new ServletException("User id '"+
profileServices.getId() +"' not logged on.");
+ }
+ }
+
if ("createAccount".equals(action)) {
createAccount(pReq, pResp, accountServices);
} else if ("account".equals(action)) {
accountTransaction(pReq, pResp, accountServices);
+ }else if ("stockPurchase".equals(action)) {
+ stockPurchase(pReq, pResp, profileServices, accountServices);
+ }else if ("stockSale".equals(action)){
+ stockSale(pReq, pResp, profileServices, accountServices);
+ }else{
+ throw new IllegalArgumentException("Unknown action in Form
servlet '" +action+"'.");
}
// mContext.getRequestDispatcher("summary.jsp").forward(pReq,
pResp);
pResp.sendRedirect("summary.jsp");
@@ -77,23 +80,61 @@
throw e;
} catch(Exception e){
- e.printStackTrace();
+
throw new ServletException(e);
}
-
-
}
- private void accountTransaction(HttpServletRequest req,
HttpServletResponse resp, AccountService accountServices) throws
NumberFormatException, RemoteException {
- String account = req.getParameter("account");
- String amount = req.getParameter("Amount");
-
- if("deposit".equals(req.getParameter("actionType")))
- accountServices.deposit(account, Float.parseFloat(amount));
- else
- accountServices.withdraw(account, Float.parseFloat(amount));
-
+ private void stockSale(HttpServletRequest req, HttpServletResponse resp,
ProfileService profileServices, AccountService accountServices)
+ throws ServletException {
+ try {
+ if (!"cancel".equals(req.getParameter("cancel"))) {
+
+ int quantity = Integer.parseInt(req.getParameter("quantity"));
+ int purchaseLotNumber =
Integer.parseInt(req.getParameter("purchaseLotNumber"));
+ accountServices.sellStock(purchaseLotNumber, quantity);
+ }
+
+ } catch (Exception e) {
+
+ throw new ServletException("stockSale " + e.getMessage(), e);
+ }
+
+ }
+
+
+ private void stockPurchase(HttpServletRequest req, HttpServletResponse
resp, ProfileService profileServices, AccountService accountServices) throws
ServletException {
+ try {
+ if (!"cancel".equals(req.getParameter("cancel"))) {
+
+ String symbol =
req.getParameter("symbol").trim().toUpperCase();
+ int quantity = Integer.parseInt(req.getParameter("quantity"));
+ StockSummary stockSummry =
AccountFactory.eINSTANCE.createStockSummary();
+ stockSummry.setSymbol(symbol);
+ stockSummry.setQuantity(quantity);
+ accountServices.purchaseStock(profileServices.getId(),
stockSummry);
+ }
+ } catch (Exception e) {
+ throw new ServletException("stockPurchase " + e.getMessage(), e);
+ }
+ }
+
+
+ private void accountTransaction(HttpServletRequest req,
HttpServletResponse resp, AccountService accountServices) throws
ServletException {
+ try {
+ if (!"cancel".equals(req.getParameter("cancel"))) {
+ String account = req.getParameter("account");
+ String amount = req.getParameter("Amount");
+ if ("deposit".equals(req.getParameter("actionType")))
+ accountServices.deposit(account, Float.parseFloat(amount));
+ else
+ accountServices.withdraw(account,
Float.parseFloat(amount));
+ }
+ } catch (Exception e) {
+ throw new ServletException("accountTransaction " + e.getMessage(),
e);
+ }
+
}
private void createAccount(HttpServletRequest pReq, HttpServletResponse
pResp, AccountService accountServices) throws ServletException {
Modified:
incubator/tuscany/java/samples/bigbank/webclient/src/main/java/org/apache/tuscany/samples/bigbank/webclient/ui/LoginServlet.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/samples/bigbank/webclient/src/main/java/org/apache/tuscany/samples/bigbank/webclient/ui/LoginServlet.java?rev=399297&r1=399296&r2=399297&view=diff
==============================================================================
---
incubator/tuscany/java/samples/bigbank/webclient/src/main/java/org/apache/tuscany/samples/bigbank/webclient/ui/LoginServlet.java
(original)
+++
incubator/tuscany/java/samples/bigbank/webclient/src/main/java/org/apache/tuscany/samples/bigbank/webclient/ui/LoginServlet.java
Wed May 3 06:36:14 2006
@@ -57,20 +57,10 @@
}else{
-// ModuleContext moduleContext = CurrentModuleContext.getContext();
-// LoginService loginMgr = (LoginService)
-// moduleContext.locateService("LoginServiceComponent");
-//
-// if (loginMgr == null) {
-// throw new ServletException("LoginManager not found");
-// }
String login = pReq.getParameter("login");
String password = pReq.getParameter("password");
try {
-// if (login == null || password == null) {
-// pResp.sendRedirect("/summary.jsp");
-// }
int resp = login(login, password);
if (resp == LoginService.SUCCESS) {
// mContext.getRequestDispatcher("/summary.jsp").forward(pReq,
pResp);
@@ -95,9 +85,6 @@
throw new ServletException("LoginManager not found");
}
-// if (login == null || password == null) {
-// pResp.sendRedirect("/summary.jsp");
-// }
try {
return loginMgr.login(login, password);
} catch (RemoteException e) {
Modified:
incubator/tuscany/java/samples/bigbank/webclient/src/main/resources/wsdl/AccountService.wsdl
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/samples/bigbank/webclient/src/main/resources/wsdl/AccountService.wsdl?rev=399297&r1=399296&r2=399297&view=diff
==============================================================================
---
incubator/tuscany/java/samples/bigbank/webclient/src/main/resources/wsdl/AccountService.wsdl
(original)
+++
incubator/tuscany/java/samples/bigbank/webclient/src/main/resources/wsdl/AccountService.wsdl
Wed May 3 06:36:14 2006
@@ -153,8 +153,7 @@
<xsd:complexType>
<xsd:sequence>
<xsd:element name="id"
type="xsd:int" />
- <xsd:element name="symbol"
type="xsd:string" />
- <xsd:element name="quantity"
type="xsd:int" />
+ <xsd:element name="stock"
type="account:StockSummary" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Added:
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/accountTransaction.jsp
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/accountTransaction.jsp?rev=399297&view=auto
==============================================================================
---
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/accountTransaction.jsp
(added)
+++
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/accountTransaction.jsp
Wed May 3 06:36:14 2006
@@ -0,0 +1,32 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+
+<HTML>
+<HEAD>
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+ pageEncoding="ISO-8859-1"%>
+<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<META name="GENERATOR" content="IBM Software Development Platform">
+<META http-equiv="Content-Style-Type" content="text/css">
+<LINK href="theme/Master.css" rel="stylesheet" type="text/css">
+<TITLE>BigBank - <%=request.getParameter("account") %> </TITLE>
+</HEAD>
+<BODY>
+<P>Account <%= request.getParameter("account") %><BR>
+<BR>
+<BR>
+</P>
+<FORM method="post" action="FormServlet">
+<input type="hidden" name="action" value='account' />
+<input type="hidden" name="account" value='<%=
request.getParameter("account") %>' />
+<input type="hidden" name="actionType"
value='<%=request.getParameter("transaction")%>' />
+Amount to <%=request.getParameter("transaction")%> <INPUT type="text"
name="Amount" size="10"
+ maxlength="10"><BR>
+<BR>
+<BR>
+<BR>
+<INPUT type="submit" name="Submit"
+ value="Submit"> <INPUT type="submit"
+ name="cancel" value="cancel">
+</FORM>
+</BODY>
+</HTML>
Modified:
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/login.html
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/login.html?rev=399297&r1=399296&r2=399297&view=diff
==============================================================================
--- incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/login.html
(original)
+++ incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/login.html
Wed May 3 06:36:14 2006
@@ -12,18 +12,23 @@
<table>
<tr>
<td>Login</td>
- <td><input type="text" name="login"/> <I><FONT
+ <td><input type="text" name="login"/></td>
+ <td><I><FONT
size="-1" color="red">(test)</FONT></I></td>
</tr>
<tr>
<td>Password</td>
- <td><input type="password"
name="password"/> <I><FONT
- size="-1" color="red">(password)</FONT></I></td>
+ <td><input type="password" name="password"/></td>
+ <td><I><FONT size="-1" color="red">(password)</FONT></I></td>
+ </tr>
+ <tr> <td></td>
+ <td align="right"><input type="submit" name='login'
value="login"/></td>
+ <tr> <td></td>
</tr>
- <tr><td></td><td align="right"><input type="submit"/></td></tr>
</table>
</form>
<P><BR></P>
+<HR/>
<FORM action="CustomerProfile.jsp" method="get">
<BR>New to Big Bank? Please open a new account with us.
<BR/>
Added:
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/purchaseStock.jsp
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/purchaseStock.jsp?rev=399297&view=auto
==============================================================================
---
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/purchaseStock.jsp
(added)
+++
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/purchaseStock.jsp
Wed May 3 06:36:14 2006
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<%--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as
applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ --%>
+
+<HTML>
+<HEAD>
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+ pageEncoding="ISO-8859-1"%>
+<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<META http-equiv="Content-Style-Type" content="text/css">
+<TITLE>BigBank- Stock purchase</TITLE>
+</HEAD>
+<BODY><P><FONT size="+1">Stock purchase</FONT><BR>
+<BR>
+</P>
+<FORM method="post" action="FormServlet">
+<input type="hidden" name="action" value='stockPurchase' />
+<TABLE border="0">
+ <TBODY>
+ <TR>
+ <TD>Symbol </TD>
+ <TD width="10%"></TD>
+ <TD><INPUT type="text" name="symbol" size="6"></TD>
+ </TR>
+ <TR>
+ <TD>Quantity</TD>
+ <TD></TD>
+ <TD><INPUT type="text" name="quantity" size="6"></TD>
+ </TR>
+ <TR>
+ <TD></TD>
+ <TD></TD>
+ <TD></TD>
+ </TR>
+ </TBODY>
+</TABLE>
+<BR>
+<INPUT type="submit" name="purchase" value="purchase">
+<INPUT type="submit" name="cancel" value="cancel"></FORM>
+<P><BR>
+</P>
+</BODY>
+</HTML>
Added:
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/stockSale.jsp
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/stockSale.jsp?rev=399297&view=auto
==============================================================================
---
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/stockSale.jsp
(added)
+++
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/stockSale.jsp
Wed May 3 06:36:14 2006
@@ -0,0 +1,59 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<%--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as
applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ --%>
+
+<HTML>
+<HEAD>
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+ pageEncoding="ISO-8859-1"%>
+<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<META http-equiv="Content-Style-Type" content="text/css">
+<TITLE>BigBank- Stock sale</TITLE>
+</HEAD>
+<BODY><P><FONT size="+1">Stock sale</FONT><BR>
+<BR>
+</P>
+<FORM method="post" action="FormServlet">
+<input type="hidden" name="action" value='stockSale' />
+<input type="hidden" name="purchaseLotNumber"
value='<%=request.getParameter("purchaseLotNumber")%>' />
+<TABLE border="0">
+ <TBODY>
+<%--
+ <TR>
+ <TD>Symbol </TD>
+ <TD width="10%"></TD>
+ <TD><INPUT type="text" name="symbol" size="6"></TD>
+ </TR>
+--%>
+ <TR>
+ <TD>Quantity</TD>
+ <TD></TD>
+ <TD><INPUT type="text" name="quantity" size="6"></TD>
+ </TR>
+ <TR>
+ <TD></TD>
+ <TD></TD>
+ <TD></TD>
+ </TR>
+ </TBODY>
+</TABLE>
+<BR>
+<INPUT type="submit" name="stockSale" value="sell">
+<INPUT type="submit" name="cancel" value="cancel"></FORM>
+<P><BR>
+</P>
+</BODY>
+</HTML>
Modified:
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/summary.jsp
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/summary.jsp?rev=399297&r1=399296&r2=399297&view=diff
==============================================================================
---
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/summary.jsp
(original)
+++
incubator/tuscany/java/samples/bigbank/webclient/src/main/webapp/summary.jsp
Wed May 3 06:36:14 2006
@@ -14,7 +14,8 @@
limitations under the License.
--%>
- <%@ page import="com.bigbank.account.AccountSummary" %>
+ <%@ page import="com.bigbank.account.AccountSummary" %>
+ <%@ page import="com.bigbank.account.StockSummary" %>
<%@ page session="true" %>
<%@ page autoFlush="true" %>
<%@ taglib uri="/WEB-INF/bigbank-tags.tld" prefix="sca" %>
@@ -30,7 +31,7 @@
<FORM method="post" action='loginAction'>
<jsp:getProperty name='profile' property='firstName'/>
<jsp:getProperty name='profile' property='lastName'/>
- <INPUT type="submit" name='logout' value="logout">
+ <INPUT type="submit" name='logout' value="logout">
<br>
</FORM>
@@ -69,19 +70,27 @@
<hr/>
- Stocks:<br/>
+ <FORM method="post" action='purchaseStock.jsp'>
+ Stocks: <INPUT type="submit" name='Purchase'
value="Purchase"><br/>
+ </FORM>
+
<table>
+
<tr>
<td><strong>Symbol</strong></td>
<td><strong>Quantity</strong></td>
<td><strong>Purchase Date</strong></td>
+ <td> </td> <%-- spacer --%>
<td><strong>Purchase Price</strong></td>
<td><strong>Current Price</strong></td>
<td><strong>Company Name</strong></td>
<td><strong>Today High</strong></td>
<td><strong>Today Low</strong></td>
+ <td> </td> <%-- spacer --%>
+ <td> <%-- sell button --%></td>
</tr>
<sca:stockStatus id="stocksummary">
+ <FORM method="post" action='stockSale.jsp' >
<tr>
<td>
<jsp:getProperty name="stocksummary" property="symbol"/>
@@ -92,6 +101,7 @@
<td>
<jsp:getProperty name="stocksummary" property="purchaseDate"/>
</td>
+ <td> </td> <%-- spacer --%>
<td>
<jsp:getProperty name="stocksummary" property="purchasePrice"/>
</td>
@@ -109,9 +119,16 @@
<td>
<jsp:getProperty name="stocksummary" property="lowPrice"/>
</td>
+ <td> </td> <%-- spacer --%>
+ <td>
+ <INPUT type="submit" name='stocksale' value="sell"><br/>
+ <input type="hidden" name="purchaseLotNumber"
value='<%=((StockSummary)pageContext.getAttribute("stocksummary")).getPurchaseLotNumber()%>'
/>
+ </td>
</tr>
+ </FORM>
</sca:stockStatus>
</table>
+
</body>
</html>