001: /*
002: * Copyright (c) 1999-2001 Lutris Technologies, Inc. All Rights
003: * Reserved.
004: *
005: * This source code file is distributed by Lutris Technologies, Inc. for
006: * use only by licensed users of product(s) that include this source
007: * file. Use of this source file or the software that uses it is covered
008: * by the terms and conditions of the Lutris Enhydra Development License
009: * Agreement included with this product.
010: *
011: * This Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
012: * ANY KIND, either express or implied. See the License for the specific terms
013: * governing rights and limitations under the License.
014: *
015: * Contributor(s):
016: *
017: * $Id: OrderPage4.java,v 1.1 2006-09-11 12:29:26 sinisa Exp $
018: */
019:
020: package com.lutris.airsent.presentation.customer;
021:
022: import com.lutris.airsent.spec.AirSentException;
023: import com.lutris.airsent.presentation.*;
024:
025: import com.lutris.airsent.spec.customer.Customer;
026: import com.lutris.airsent.spec.delivery.*;
027: import com.lutris.airsent.spec.*;
028:
029: import com.lutris.appserver.server.httpPresentation.*;
030: import com.lutris.util.*; //import com.lutris.xml.xmlc.*;
031: //import com.lutris.xml.xmlc.html.*;
032: import org.w3c.dom.*;
033: import org.w3c.dom.html.*;
034: import org.enhydra.xml.xmlc.XMLObject;
035: import java.util.*;
036:
037: /**
038: * Presentation object for order page 4
039: */
040: public class OrderPage4 extends BasePO {
041:
042: /**
043: * Constants
044: */
045: private static final int AUTH_LEVEL = AirSentConstants.CUSTOMER_USER;
046:
047: /**
048: * Superclass method override.
049: * returns the authorization level necessary to access this po.
050: *
051: * @return int required authorization level
052: */
053: public int getRequiredAuthLevel() {
054: return AUTH_LEVEL;
055: }
056:
057: /**
058: * displays default page
059: *
060: * @return html page
061: * @exception if an error occurs
062: */
063: public XMLObject handleDefault() throws HttpPresentationException {
064:
065: try {
066: OrderForm orderForm = getSessionData().getOrderForm();
067: if (orderForm == null) {
068: System.err.println("ERROR: no order form");
069: throw new ClientPageRedirectException(
070: AirSentConstants.ORDERSTEP1_PO);
071: }
072: return showPage4(null, orderForm);
073: } catch (Exception e) {
074: throw new AirSentPresentationException(
075: "System error finding user", e);
076: }
077: }
078:
079: /**
080: * creates the html page
081: *
082: * @param errorMsg error message to display
083: * @param orderData data to populate the page with
084: * @exception if an error occurs
085: */
086: private XMLObject showPage4(String errorMsg, OrderForm orderForm)
087: throws AirSentPresentationException {
088:
089: ConfirmationHTML page = (ConfirmationHTML) myComms.xmlcFactory
090: .create(ConfirmationHTML.class);
091: if (null != errorMsg
092: || null != (errorMsg = getSessionData()
093: .getAndClearUserMessage())) {
094: page.setTextErrorText(errorMsg);
095: } else {
096: page.getElementErrorText().getParentNode().removeChild(
097: page.getElementErrorText());
098: }
099:
100: try {
101: page.setTextPickupname(orderForm.getPickUpName());
102: page.setTextPickupaddress(orderForm.getPickUpAddress1());
103: page.setTextPickupphone(orderForm.getPickUpPhone());
104: page.setTextDropoffname(orderForm.getDropOffName());
105: page.setTextDropoffaddress(orderForm.getDropOffAddress1());
106: page.setTextDropoffphone(orderForm.getDropOffPhone());
107:
108: if (orderForm.getUrgent() == true) {
109: page.getElementPickupurgent().setSrc(
110: AirSentConstants.URGENT_IMAGE);
111: page.getElementDropoffurgent().setSrc(
112: AirSentConstants.URGENT_IMAGE);
113: } else {
114: page.getElementPickupurgent().setSrc(
115: AirSentConstants.BLANK_IMAGE);
116: page.getElementDropoffurgent().setSrc(
117: AirSentConstants.BLANK_IMAGE);
118: }
119:
120: if (orderForm.getFragile() == true) {
121: page.getElementPickupfragile().setSrc(
122: AirSentConstants.URGENT_IMAGE);
123: page.getElementDropofffragile().setSrc(
124: AirSentConstants.URGENT_IMAGE);
125: } else {
126: page.getElementPickupfragile().setSrc(
127: AirSentConstants.BLANK_IMAGE);
128: page.getElementDropofffragile().setSrc(
129: AirSentConstants.BLANK_IMAGE);
130: }
131: page.setTextPickupdescription(orderForm.getDescription());
132: page.setTextDropoffdescription(orderForm.getDescription());
133:
134: //We need to allow AirSent_pres to be functional , responsed will be default HTML page
135: } catch (NullPointerException e) {
136:
137: ConfirmationHTML defaultPage = (ConfirmationHTML) myComms.xmlcFactory
138: .create(ConfirmationHTML.class);
139: defaultPage.setTextErrorText("This is a default HTML page");
140: return defaultPage;
141: } catch (Exception ex) {
142: throw new AirSentPresentationException(
143: "Error in confimation", ex);
144: }
145: return page;
146: }
147:
148: /**
149: * process the form submission
150: *
151: * @return html page
152: * @exception if an error occurs
153: */
154: public XMLObject handleOrder4() throws AirSentPresentationException {
155: try {
156: OrderForm orderForm = getSessionData().getOrderForm();
157: if (orderForm == null) {
158: System.err.println("ERROR: no order form");
159: throw new ClientPageRedirectException(
160: AirSentConstants.ORDERSTEP1_PO);
161: }
162: Customer customer = getSessionData().getCustomer();
163: HomeManager hf = getApplication().getHomeManager();
164: DeliveryManager df = hf.getDeliveryManager();
165: Delivery delivery = df.create(customer, orderForm);
166: delivery.save();
167: if (orderForm.getOrderId() == null) {
168: getSessionData().setUserMessage(
169: "Thanks for your order! Your order # is:"
170: + delivery.getHandle());
171: } else {
172: getSessionData().setUserMessage(
173: "Your changes to order #:"
174: + delivery.getHandle()
175: + " have been saved.");
176: }
177: getSessionData().setOrderForm(null);
178: throw new ClientPageRedirectException(
179: AirSentConstants.ORDERSTEP1_PO);
180: //We need to allow AirSent_pres to be functional , responsed will be default HTML page
181: } catch (NullPointerException e) {
182: throw new ClientPageRedirectException(
183: AirSentConstants.ORDERSTEP1_PO);
184:
185: } catch (AirSentException ex) {
186: throw new AirSentPresentationException(
187: "Exception logging in order: ", ex);
188: }
189: }
190:
191: /**
192: * process the cancel event
193: *
194: * @return html page
195: * @exception if an error occurs
196: */
197: public XMLObject handleCancel() {
198: getSessionData().setOrderForm(null);
199: throw new ClientPageRedirectException(
200: AirSentConstants.ORDERSTEP1_PO);
201: }
202: }
|