1 19 20 package com.lutris.airsent.presentation.customer; 21 22 import com.lutris.airsent.presentation.BasePO; 23 import com.lutris.appserver.server.httpPresentation.*; 24 import com.lutris.appserver.server.session.*; 25 import com.lutris.util.*; 26 import org.w3c.dom.*; 29 import org.w3c.dom.html.*; 30 import org.enhydra.xml.xmlc.XMLObject; 31 32 33 import com.lutris.airsent.spec.AirSentException; 34 35 import com.lutris.airsent.presentation.AirSentPresentationException; 36 import com.lutris.airsent.presentation.AirSentConstants; 37 import java.util.*; 38 import com.lutris.airsent.spec.address.*; 39 import com.lutris.airsent.spec.customer.*; 40 import com.lutris.airsent.spec.*; 41 42 43 import com.lutris.airsent.spec.delivery.*; 44 47 public class OrderPage1 48 extends BasePO { 49 50 53 private static final int AUTH_LEVEL = AirSentConstants.CUSTOMER_USER; 54 55 56 62 public int getRequiredAuthLevel() { 63 return AUTH_LEVEL; 64 } 65 66 72 public XMLObject handleDefault() 73 throws HttpPresentationException { 74 try { 75 String id = getComms().request.getParameter(AirSentConstants.DELIVERYID); 76 OrderForm d = getOrder(id); 77 getSessionData().setOrderForm(d); 78 return showPage1(null, d); 79 } catch (Exception e) { 80 throw new AirSentPresentationException("System error finding user", e); 81 } 82 } 83 84 90 public XMLObject handleOrder1() 91 throws AirSentPresentationException { 92 try { 93 String p; 94 OrderForm orderForm = getOrder(null); 95 96 p = getComms().request.getParameter(AirSentConstants.PICKUP_NAME); 97 if (checkField(p, Address.MAX_NAME) == false) { 98 return showPage1("Please provide a pickupname", orderForm); 99 } 100 orderForm.setPickUpName(p); 101 102 p = getComms().request.getParameter(AirSentConstants.PICKUP_ADDRESS); 103 if (checkField(p, Address.MAX_ADDRESS) == false) { 104 return showPage1("Please provide a pickupaddress", orderForm); 105 } 106 orderForm.setPickUpAddress1(p); 107 108 p = getComms().request.getParameter(AirSentConstants.PICKUP_PHONE); 109 if (checkField(p, Address.MAX_PHONE) == false) { 110 return showPage1("Please provide a pickupphone", orderForm); 111 } 112 orderForm.setPickUpPhone(p); 113 114 p = getComms().request.getParameter(AirSentConstants.PICKUP_DIRECTIONS); 115 if (checkField(p, Address.MAX_DIRECTIONS) == false) { 116 return showPage1("Please provide a pickupdirections", orderForm); 117 } 118 orderForm.setPickUpDirections(p); 119 120 getSessionData().setOrderForm(orderForm); 121 throw new ClientPageRedirectException(AirSentConstants.ORDERSTEP2_PO); 122 123 }catch(NullPointerException e){ 125 OrderStep2HTML defaultPage = (OrderStep2HTML) myComms.xmlcFactory.create(OrderStep2HTML.class); 126 defaultPage.setTextErrorText("This is a default HTML page"); 127 return defaultPage; 128 } catch (Exception e) { 129 throw new AirSentPresentationException("System error processing OrderStep1.", e); 130 } 131 } 132 133 140 private XMLObject showPage1(String errorMsg, OrderForm orderForm) 141 throws AirSentPresentationException { 142 143 OrderStep1HTML page = (OrderStep1HTML) myComms.xmlcFactory.create(OrderStep1HTML.class); 144 try { 145 if (null != errorMsg || null != (errorMsg = getSessionData().getAndClearUserMessage())) { 146 page.setTextErrorText(errorMsg); 147 } else { 148 page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText()); 149 } 150 if(orderForm.getOrderId() == null) { 151 Node n = page.getElementNavDestination().getParentNode(); 152 n.removeChild(page.getElementNavDestination()); 153 n.removeChild(page.getElementNavDetails()); 154 } 155 populatePage1(page, orderForm); 156 }catch(NullPointerException e){ 158 159 OrderStep1HTML defaultPage = (OrderStep1HTML) myComms.xmlcFactory.create(OrderStep1HTML.class); 160 defaultPage.setTextErrorText("This is a default HTML page"); 161 return defaultPage; 162 } catch (Exception e) { 163 throw new AirSentPresentationException("System error showing page 1", e); 164 } 165 return page; 166 } 167 168 175 private void populatePage1(OrderStep1HTML page, OrderForm orderForm) 176 throws AirSentPresentationException { 177 178 try { 179 if(orderForm.getOrderId() != null) { 180 page.setTextOrderHeader("Order"); 181 page.setTextOrdernumber(orderForm.getOrderId()); 182 page.getElementPickupname().setValue(orderForm.getPickUpName()); 183 page.getElementPickupaddress().setValue(orderForm.getPickUpAddress1()); 184 page.getElementPickupphone().setValue(orderForm.getPickUpPhone()); 185 } else { 186 page.setTextOrdernumber(""); 187 } 188 192 if (orderForm.getPickUpDirections() != null) { 193 Text commentText = (page.getDocument()).createTextNode(orderForm.getPickUpDirections()); 194 page.getElementPickupdirections().appendChild(commentText); 195 } 196 } catch (Exception e) { 197 throw new AirSentPresentationException("System error populating page1", e); 198 } 199 } 200 201 204 private OrderForm getOrder(String id) 205 throws AirSentPresentationException { 206 try { 207 OrderForm orderForm = getSessionData().getOrderForm(); 208 if ((orderForm == null) && (id == null)) { 209 212 orderForm = OrderFormFactory.getOrderForm("com.lutris.airsent.business.delivery.OrderFormImpl"); 213 214 215 216 } else if (id != null) { 217 HomeManager homeManager = getApplication().getHomeManager(); 220 Delivery d = homeManager.getDeliveryManager().findByHandle(id); 221 222 orderForm = OrderFormFactory.getOrderForm("com.lutris.airsent.business.delivery.OrderFormImpl",d); 223 } 224 return orderForm; 225 226 227 } catch (Exception e) { 228 throw new AirSentPresentationException("System error getting order", e); 229 } 230 } 231 } 232 233 234 | Popular Tags |