1 19 20 package com.lutris.airsent.presentation.admin; 21 22 import com.lutris.airsent.presentation.BasePO; 23 import org.enhydra.xml.xmlc.*; 24 import com.lutris.appserver.server.httpPresentation.*; 25 import com.lutris.appserver.server.session.*; 26 27 import org.w3c.dom.*; 28 import org.w3c.dom.html.*; 29 30 31 import com.lutris.airsent.spec.AirSentException; 32 33 import com.lutris.airsent.presentation.AirSentPresentationException; 34 import com.lutris.airsent.presentation.AirSentConstants; 35 import java.util.*; 36 37 import com.lutris.airsent.spec.delivery.Delivery; 38 import com.lutris.airsent.spec.messenger.Messenger; 39 import com.lutris.airsent.spec.*; 40 45 public class AdminDetails extends BasePO { 46 47 50 private static final int AUTH_LEVEL = AirSentConstants.ADMINISTRATOR_USER; 51 52 58 public int getRequiredAuthLevel() { 59 return AUTH_LEVEL; 60 } 61 62 65 public XMLObject handleDefault() throws HttpPresentationException { 66 return showPage(null); 67 } 68 69 74 public XMLObject showPage(String errorMsg) 75 throws HttpPresentationException { 76 AdminDetailsHTML page = (AdminDetailsHTML) myComms.xmlcFactory.create(AdminDetailsHTML.class); 77 HTMLInputElement deliveryField = page.getElementDelivery(); 78 79 try { 80 String deliveryID = getComms().request.getParameter(AirSentConstants.DELIVERYID); 81 82 HomeManager hf = getApplication().getHomeManager(); 83 Delivery delivery = hf.getDeliveryManager().findByHandle(deliveryID); 84 85 deliveryField.setValue(deliveryID); 86 if (null != errorMsg || null != (errorMsg = getSessionData().getAndClearUserMessage())) { 87 page.setTextErrorText(errorMsg); 88 } else { 89 page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText()); 90 } 91 92 93 94 page.setTextPickupname(delivery.getPickUp().getName()); 95 page.setTextPickupaddress(delivery.getPickUp().getStreet1()); 96 page.setTextDropoffname(delivery.getDropOff().getName()); 97 page.setTextDropoffaddress(delivery.getDropOff().getStreet1()); 98 99 Messenger messenger = delivery.getMessenger(); 100 String messengerName = AirSentConstants.NOT_ASSIGNED; 101 102 HTMLSelectElement messengerSelect = page.getElementMessengerSelect(); 103 HTMLOptionElement messengerOption = page.getElementMessengerOption(); 104 messengerOption.removeAttribute("id"); 105 messengerOption.removeChild(messengerOption.getFirstChild()); 106 107 Messenger[] messengerList = hf.getMessengerManager().findAll(); 108 int selected = 0; 109 for (int i = 0; i < messengerList.length; i++) { 110 HTMLOptionElement clonedOption = (HTMLOptionElement) messengerOption.cloneNode(true); 111 String badge = messengerList[i].getBadge(); 112 String name = messengerList[i].getFirstName(); 113 if (messenger != null) { 114 if (badge.equals(messenger.getBadge()) == true) { 115 messengerName = name; 116 selected = i + 1; 117 } 118 } 119 clonedOption.setValue(badge); 120 Node optionTextNode = clonedOption.getOwnerDocument().createTextNode(name); 121 clonedOption.appendChild(optionTextNode); 122 messengerSelect.appendChild(clonedOption); 123 } 124 if (messenger == null) { 125 HTMLOptionElement clonedOption = (HTMLOptionElement) messengerOption.cloneNode(true); 126 clonedOption.setValue("none"); 127 Node optionTextNode = clonedOption.getOwnerDocument().createTextNode(AirSentConstants.NOT_ASSIGNED); 128 clonedOption.appendChild(optionTextNode); 129 messengerSelect.appendChild(clonedOption); 130 selected = messengerList.length + 1; 131 } 132 messengerSelect.setSelectedIndex(selected); 133 messengerOption.getParentNode().removeChild(messengerOption); 134 page.setTextDropoffmessenger(messengerName); 135 141 142 }catch(NullPointerException e){ 143 page.setTextErrorText("You cannot assign or change the messenger assigned to a given order while running AirSent_pres"); 144 } catch (Exception ex) { 145 throw new AirSentPresentationException("Error adding messenger", ex); 146 } 147 return page; 148 149 } 150 151 156 public XMLObject handleEdit() throws HttpPresentationException { 157 String messengerID = getComms().request.getParameter(AirSentConstants.MESSENGER_NAME); 158 String deliveryID = getComms().request.getParameter(AirSentConstants.DELIVERYID); 159 Messenger messenger = null; 160 Delivery delivery = null; 161 162 if ((messengerID != null) && (messengerID.equals("none") == true)) { 163 return showPage("Select a messenger"); 164 } 165 166 try { 167 if ((delivery = getApplication().getHomeManager().getDeliveryManager().findByHandle(deliveryID)) != null) { 168 if ((messenger = getApplication().getHomeManager().getMessengerManager().findByBadge(messengerID)) != null) { 169 sendMessage(delivery, messenger); 170 delivery.setMessenger(messenger); 171 delivery.save(); 172 173 throw new ClientPageRedirectException(AirSentConstants.ADMIN_MAIN_PAGE); 174 } 175 } 176 }catch(NullPointerException e){return showPage("You cannot assign or change the messenger assigned to a given order , while running AirSent_pres"); 177 } catch (Exception ex) { 178 throw new AirSentPresentationException("Error adding messenger", 179 ex); 180 } 181 182 return showPage("Error occured updating delivery."); 183 } 184 185 186 187 193 private void sendMessage(Delivery delivery, Messenger messenger) 194 throws AirSentPresentationException { 195 196 Messenger previousMessenger = null; 197 String changeMessage = "You have been un-assigned delivery: "; 198 String newMessage = "You have been assigned delivery: "; 199 200 try { 201 202 if((previousMessenger = delivery.getMessenger()) != null) { 203 getApplication().getHomeManager().getSMSManager().send(changeMessage + delivery.getHandle(), 204 previousMessenger.getAddress().getLocalNumber()); 205 getApplication().getHomeManager().getSMSManager().send(newMessage + delivery.getHandle(), 206 messenger.getAddress().getLocalNumber()); 207 } else { 208 getApplication().getHomeManager().getSMSManager().send(newMessage + delivery.getHandle(), messenger.getAddress().getLocalNumber()); 209 } 210 211 } catch (Exception ex) { 212 throw new AirSentPresentationException("Error adding messenger", 213 ex); 214 } 215 } 216 217 218 226 public static void setText(Element e, String text) { 227 if (null == text) { 228 text = ""; 229 } 230 231 org.w3c.dom.Text t = null; 232 try { 233 t = XMLCUtil.getFirstText(e); 234 } catch (Throwable th) { 235 } 236 if (t != null) 237 t.setData(text); 238 else { 239 t = e.getOwnerDocument().createTextNode(text); 240 e.insertBefore(t, null); 241 } 242 } 243 244 245 } 246 247 248 249 250 251 252 | Popular Tags |