KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > airsent > presentation > admin > AdminMain


1 /*
2  * Copyright (c) 1999-2001 Lutris Technologies, Inc. All Rights
3  * Reserved.
4  *
5  * This source code file is distributed by Lutris Technologies, Inc. for
6  * use only by licensed users of product(s) that include this source
7  * file. Use of this source file or the software that uses it is covered
8  * by the terms and conditions of the Lutris Enhydra Development License
9  * Agreement included with this product.
10  *
11  * This Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
12  * ANY KIND, either express or implied. See the License for the specific terms
13  * governing rights and limitations under the License.
14  *
15  */

16
17 package com.lutris.airsent.presentation.admin;
18
19 import org.enhydra.xml.xmlc.XMLObject;
20 import com.lutris.appserver.server.httpPresentation.*;
21 import com.lutris.appserver.server.session.*;
22 import com.lutris.util.*;
23 //import com.lutris.xml.xmlc.*;
24
//import com.lutris.xml.xmlc.html.*;
25
import org.w3c.dom.*;
26 import org.w3c.dom.html.*;
27 import java.util.*;
28 import com.lutris.airsent.presentation.BasePO;
29 import com.lutris.airsent.spec.AirSentException;
30
31 import com.lutris.airsent.presentation.AirSentPresentationException;
32 import com.lutris.airsent.presentation.AirSentConstants;
33 import com.lutris.airsent.spec.delivery.Delivery;
34 import com.lutris.airsent.spec.messenger.Messenger;
35 import com.lutris.airsent.spec.address.*;
36 /**
37  * AdminMain is the main interactive page for the AirSent
38  * administrator. AdminMain shows current(and past) delivies
39  * allows for Detailed viewing of Deliveries and Messengers.
40  *
41  */

42 public class AdminMain extends BasePO {
43
44     /**
45      * Constants
46      */

47     private static final int AUTH_LEVEL = AirSentConstants.ADMINISTRATOR_USER;
48     private static final int TOP_TEN_DELIVERIES = 10;
49     private static final int TOP_TWENTY_DELIVERIES = 20;
50     private static final int ALL_DELIVERIES = 0;
51     private static final long TIME_OUT = 60;
52
53     /**
54      * Superclass method override.
55      * returns the authorization level necessary to access this po.
56      *
57      * @return int required authorization level
58      */

59     public int getRequiredAuthLevel() {
60     return AUTH_LEVEL;
61     }
62
63     /**
64      * Default event. Just show the page.
65      */

66     public XMLObject handleDefault() throws HttpPresentationException {
67     return showPage(null);
68     }
69
70     /**
71      *
72      * @param error messages
73      * @return page.
74      */

75     public XMLObject showPage(String JavaDoc errorMsg)
76         throws AirSentPresentationException {
77       // Build the page, checking for errors first.
78
AdminMainHTML page =
79         (AdminMainHTML) myComms.xmlcFactory.create(AdminMainHTML.class);
80     
81     try {
82        
83       
84         
85         if (null != errorMsg
86         || null
87         != (errorMsg =
88             getSessionData().getAndClearUserMessage())) {
89         page.setTextErrorText(errorMsg);
90         } else {
91         page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText());
92         }
93
94         /**
95          * If the ServerPush tecnique is specified in the
96          * conf file, then server push will be enabled. Essentially
97          * server push is a page that is continously loading, or until
98          * rather, waiting to load until the page has a)changed, or b)
99          * the TCP/IP timeout of 60 seconds has expired.
100          */

101         
102         if(getApplication().useServerPush()) {
103         if (getComms().request.getParameter(AirSentConstants.REFRESH)
104             != null) {
105             
106             //
107
// Do the update or wait
108
//
109
getSessionData().setBrowserState(getApplication().getHomeManager().getDeliveryManager().getUpdate(getSessionData().getBrowserState(),
110                                                               TIME_OUT));
111         } else {
112             getSessionData().setBrowserState(getApplication().getHomeManager().getDeliveryManager().getUpdate(0,
113                                                               TIME_OUT));
114         }
115         } else {
116         
117         //Remove the javascript that reloads the
118
//page as the mechanism fo ServerPush.
119
page.getElementRefreshScript().getParentNode().removeChild(page.getElementRefreshScript());
120         }
121                 
122
123         // Decide how to sort each table by delivery.
124
String JavaDoc pickupSort = null;
125         int currentPickupSort = 0;
126
127         if ((pickupSort = getComms().request.getParameter(AirSentConstants.PICKUP_FILTER))
128             != null) {
129         currentPickupSort = Integer.parseInt(pickupSort);
130         }
131
132         String JavaDoc dropoffSort = null;
133         int currentDropoffSort = 0;
134
135         if ((dropoffSort = getComms().request.getParameter(AirSentConstants.PICKUP_FILTER))
136             != null) {
137         currentDropoffSort = Integer.parseInt(dropoffSort);
138         }
139
140         // Build each table based on the delivery filters.
141
buildPickUpTable(page, currentPickupSort);
142         buildDropOffTable(page, currentDropoffSort);
143 /*
144  * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run AirSent_pres )
145  * We need to allow AirSent_pres to be functional , response
146  * will be default HTML page with message
147  *
148  */

149        }catch(NullPointerException JavaDoc e){
150               page.setTextErrorText("You cannot delete order while runnig AirSent_pres");
151     } catch (Exception JavaDoc e) {
152         throw new AirSentPresentationException("Trouble showing page", e);
153     }
154      return page;
155     }
156
157     /**
158      * Builds the PickUp table
159      *
160      *
161      */

162     protected void buildPickUpTable(AdminMainHTML page, int type)
163         throws AirSentPresentationException {
164     String JavaDoc messenger = null;
165
166     try {
167         HTMLTableRowElement templatePickUpRow =
168         page.getElementPickuprow();
169         Node pickupTable =
170         templatePickUpRow.getParentNode();
171
172         // Get the template elements
173
HTMLElement pickupnameCellTemplate =
174         page.getElementPickupname();
175         HTMLElement pickupaddressCellTemplate =
176         page.getElementPickupaddress();
177         HTMLImageElement pickupisurgentCellTemplate =
178         page.getElementPickupurgent();
179         HTMLElement pickupmessengerCellTemplate =
180         page.getElementPickupmessenger();
181         HTMLAnchorElement pickupeditCellTemplate =
182         page.getElementPickupedit();
183         HTMLAnchorElement deletepickupCellTemplate =
184         page.getElementDeletepickuporder();
185         HTMLAnchorElement messengerURL =
186         page.getElementPickupmessengerURL();
187
188         // Remove ids to prevent duplicates
189
// (browsers don't care, but the DOM does)
190
templatePickUpRow.removeAttribute("id");
191         pickupnameCellTemplate.removeAttribute("id");
192         pickupaddressCellTemplate.removeAttribute("id");
193         pickupisurgentCellTemplate.removeAttribute("id");
194         pickupeditCellTemplate.removeAttribute("id");
195         deletepickupCellTemplate.removeAttribute("id");
196         messengerURL.removeAttribute("id");
197         
198         // Get the array of deliveries.
199
Delivery[] deliveryList = getDeliveries(type);
200
201         // Create a row for each delivery
202
for (int numDeliveries = 0; numDeliveries < deliveryList.length;
203             numDeliveries++) {
204         Delivery currentDelivery = deliveryList[numDeliveries];
205
206         // set text of new cells to values from string array
207
page.setTextPickupname(currentDelivery.getPickUp().getName());
208         page.setTextPickupaddress(currentDelivery.getPickUp().getStreet1());
209
210         messenger = AirSentConstants.NOT_ASSIGNED;
211
212         if (currentDelivery.getMessenger() != null) {
213             messenger = currentDelivery.getMessenger().getFirstName();
214
215            messengerURL.setHref(AirSentConstants.NEW_MESSENGER_PAGE
216                      + "?"
217                      + AirSentConstants.MESSENGER_NAME
218                      + "="
219                      + currentDelivery.getMessenger().getBadge());
220         } else {
221                     messengerURL.setHref(AirSentConstants.ADMINDETAILS_PAGE
222                            + "?deliveryID="
223                            + currentDelivery.getHandle());
224         }
225
226         page.setTextPickupmessenger(messenger);
227         page.setTextPickuptime(currentDelivery.getPickedUpTime());
228         page.setTextPickupordernumber(currentDelivery.getHandle());
229         pickupeditCellTemplate.setHref(AirSentConstants.ADMINDETAILS_PAGE
230                            + "?deliveryID="
231                            + currentDelivery.getHandle());
232         deletepickupCellTemplate.setHref(AirSentConstants.ADMIN_MAIN_PAGE
233                          + "?event=delete"
234                          + "&deliveryID="
235                          + currentDelivery.getHandle());
236
237         if (currentDelivery.isUrgent()) {
238             pickupisurgentCellTemplate.setSrc(AirSentConstants.URGENT_IMAGE);
239         } else {
240             pickupisurgentCellTemplate.setSrc(AirSentConstants.BLANK_IMAGE);
241         }
242
243         HTMLTableRowElement tempPickUpRow =
244             (HTMLTableRowElement) templatePickUpRow.cloneNode(true);
245
246         if (currentDelivery.isPickedUp()) {
247             tempPickUpRow.setBgColor("cccccc");
248         } else {
249             tempPickUpRow.setBgColor("yellow");
250             page.setTextPickuptime("-");
251         }
252
253         // Add a deep clone of the row to the DOM
254
pickupTable.appendChild(tempPickUpRow);
255         }
256
257         // Finally remove the template row and template select option
258
// from the page
259
templatePickUpRow.getParentNode().removeChild(templatePickUpRow);
260     //same thing
261
}catch(NullPointerException JavaDoc e){
262     } catch (Exception JavaDoc e) {
263         throw new AirSentPresentationException("Trouble showing page", e);
264     }
265     }
266
267     /**
268      * Builds the DropOff table
269      *
270      *
271      */

272     protected void buildDropOffTable(AdminMainHTML page, int type)
273         throws AirSentPresentationException {
274     String JavaDoc messenger = AirSentConstants.NOT_ASSIGNED;
275
276     try {
277         HTMLTableRowElement templateDropOffRow =
278         page.getElementDropoffrow();
279         Node dropoffTable =
280         templateDropOffRow.getParentNode();
281
282         // Get the elements
283
HTMLElement dropoffnameCellTemplate =
284         page.getElementDropoffname();
285         HTMLElement dropoffaddressCellTemplate =
286         page.getElementDropoffaddress();
287         HTMLElement dropoffmessengerCellTemplate =
288         page.getElementDropoffmessenger();
289         HTMLImageElement dropoffisurgentCellTemplate =
290         page.getElementDropoffurgent();
291         HTMLAnchorElement dropoffeditCellTemplate =
292         page.getElementDropoffedit();
293         HTMLAnchorElement deletedropoffCellTemplate =
294         page.getElementDeletedropofforder();
295         HTMLAnchorElement messengerURL =
296         page.getElementDropoffmessengerURL();
297
298         // Remove ids to prevent duplicates
299
// (browsers don't care, but the DOM does)
300
templateDropOffRow.removeAttribute("id");
301         dropoffnameCellTemplate.removeAttribute("id");
302         dropoffaddressCellTemplate.removeAttribute("id");
303         dropoffmessengerCellTemplate.removeAttribute("id");
304         dropoffisurgentCellTemplate.removeAttribute("id");
305         dropoffeditCellTemplate.removeAttribute("id");
306
307         // Get the delivery array
308
Delivery[] deliveryList = getDeliveries(type);
309
310         for (int numDeliveries = 0; numDeliveries < deliveryList.length;
311             numDeliveries++) {
312         Delivery currentDelivery = deliveryList[numDeliveries];
313
314         // set text of new cells to values from string array
315
page.setTextDropoffname(currentDelivery.getDropOff().getName());
316         page.setTextDropoffaddress(currentDelivery.getDropOff().getStreet1());
317
318                 messenger = AirSentConstants.NOT_ASSIGNED;
319
320         if (currentDelivery.getMessenger() != null) {
321             messenger = currentDelivery.getMessenger().getFirstName();
322
323             messengerURL.setHref(AirSentConstants.NEW_MESSENGER_PAGE
324                      + "?"
325                      + AirSentConstants.MESSENGER_NAME
326                      + "="
327                      + currentDelivery.getMessenger().getBadge());
328         } else {
329             messengerURL.setHref(AirSentConstants.ADMINDETAILS_PAGE
330                         + "?deliveryID="
331                         + currentDelivery.getHandle());
332
333         }
334
335         page.setTextDropoffmessenger(messenger);
336         page.setTextDropoffordernumber(currentDelivery.getHandle());
337         page.setTextDropofftime(currentDelivery.getDroppedOffTime());
338         dropoffeditCellTemplate.setHref(AirSentConstants.ADMINDETAILS_PAGE
339                         + "?deliveryID="
340                         + currentDelivery.getHandle());
341         deletedropoffCellTemplate.setHref(AirSentConstants.ADMIN_MAIN_PAGE
342                           + "?event=delete"
343                           + "&deliveryID="
344                           + currentDelivery.getHandle());
345
346         if (currentDelivery.isUrgent()) {
347             dropoffisurgentCellTemplate.setSrc(AirSentConstants.URGENT_IMAGE);
348         } else {
349             dropoffisurgentCellTemplate.setSrc(AirSentConstants.BLANK_IMAGE);
350         }
351
352         HTMLTableRowElement tempDropOffRow =
353             (HTMLTableRowElement) templateDropOffRow.cloneNode(true);
354
355         if (currentDelivery.isDroppedOff()) {
356             tempDropOffRow.setBgColor("cccccc");
357         } else {
358             tempDropOffRow.setBgColor("yellow");
359             page.setTextDropofftime("-");
360         }
361
362         // Add a deep clone of the row to the DOM
363
dropoffTable.appendChild(tempDropOffRow);
364         }
365
366         // Finally remove the template row and template select option
367
// from the page
368
templateDropOffRow.getParentNode().removeChild(templateDropOffRow);
369     
370          }catch(NullPointerException JavaDoc e){
371     } catch (Exception JavaDoc e) {
372         throw new AirSentPresentationException("Trouble showing page", e);
373     }
374     }
375
376     /**
377      * Gets a collection of deliveries based on the type.
378      *
379      *
380      */

381     protected Delivery[] getDeliveries(int type)
382         throws AirSentPresentationException {
383     try {
384         switch (type) {
385
386         case TOP_TEN_DELIVERIES:
387         return getApplication().getHomeManager().getDeliveryManager().findSubset(TOP_TEN_DELIVERIES);
388
389         case TOP_TWENTY_DELIVERIES:
390         return getApplication().getHomeManager().getDeliveryManager().findSubset(TOP_TWENTY_DELIVERIES);
391
392         case ALL_DELIVERIES:
393         return getApplication().getHomeManager().getDeliveryManager().findAll();
394
395         default:
396         return getApplication().getHomeManager().getDeliveryManager().findAll();
397         }
398     
399     }catch(NullPointerException JavaDoc e){
400                 throw new NullPointerException JavaDoc();
401     } catch (Exception JavaDoc e) {
402         throw new AirSentPresentationException("Trouble getting deliveries:",
403                            e);
404     }
405     }
406
407     /**
408      *Handles the deletion of an Order.
409      *
410      *
411      */

412     public XMLObject handleDelete() throws AirSentPresentationException {
413     try {
414         String JavaDoc deliveryID =
415         getComms().request.getParameter(AirSentConstants.DELIVERYID);
416         Delivery delivery = null;
417
418         if ((delivery = getApplication().getHomeManager().getDeliveryManager().findByHandle(deliveryID))
419             != null) {
420         delivery.delete();
421         
422         }
423     //We need to allow AirSent_pres to be functional , response will be default HTML page
424
}catch(NullPointerException JavaDoc e){
425         
426          AdminMainHTML defaultPage = (AdminMainHTML) myComms.xmlcFactory.create(AdminMainHTML.class);
427      defaultPage.setTextErrorText("You cannot delete delivery while running AirSent_pres");
428      return defaultPage;
429     } catch (Exception JavaDoc ex) {
430         throw new AirSentPresentationException("Error in confimation",
431                            ex);
432     }
433     throw new ClientPageRedirectException(AirSentConstants.ADMIN_MAIN_PAGE);
434     }
435
436     /**
437      * Update the AdminMain page.
438      *
439      *
440      */

441     public XMLObject handleUpdate() throws AirSentPresentationException {
442     return showPage(null);
443     }
444
445 }
446
447
448
Popular Tags