1 19 20 package com.lutris.airsent.business.delivery; 21 22 23 import com.lutris.airsent.spec.AirSentException; 24 25 import com.lutris.airsent.business.*; 26 27 import com.lutris.airsent.business.delivery.*; 28 import com.lutris.airsent.spec.delivery.DeliveryManager; 29 30 import com.lutris.airsent.spec.delivery.*; 31 import com.lutris.airsent.data.delivery.*; 32 import com.lutris.airsent.spec.address.Address; 33 import com.lutris.airsent.spec.messenger.Messenger; 34 import com.lutris.airsent.data.person.MessengerDO; 35 import com.lutris.airsent.spec.customer.Customer; 36 37 import com.lutris.airsent.data.person.CustomerDO; 38 import com.lutris.appserver.server.sql.*; 39 import com.lutris.dods.builder.generator.query.*; 40 import java.sql.Date ; 41 42 45 public class DeliveryManagerImpl implements DeliveryManager { 46 47 private Update update = null; 48 49 52 public DeliveryManagerImpl() { 53 this.update = new UpdateImpl(System.currentTimeMillis()); 54 } 55 56 64 public long getUpdate(long browserState, long wait) 65 throws AirSentBusinessException { 66 try { 67 return update.needUpdate(browserState, wait); 68 } catch (Exception e) { 69 throw new AirSentBusinessException(e); 70 } 71 } 72 73 80 public Delivery create(Customer customer) 81 throws AirSentBusinessException { 82 try { 83 return new DeliveryImpl(update, customer); 84 } catch (Exception e) { 85 throw new AirSentBusinessException(e); 86 } 87 } 88 89 96 public Delivery create(Customer customer, OrderForm orderForm) 97 throws AirSentException, AirSentBusinessException { 98 try { 99 Delivery d; 100 if (orderForm.getOrderId() == null) { 101 d = new DeliveryImpl(update, customer); 102 } else { 103 d = new DeliveryImpl(update, orderForm.getOrderId()); 104 } 105 d.setIsFragile(orderForm.getFragile()); 106 d.setIsUrgent(orderForm.getUrgent()); 107 d.setSize(orderForm.getSize()); 108 d.setDescription(orderForm.getDescription()); 109 110 Address pua = d.getPickUp(); 111 pua.setName(orderForm.getPickUpName()); 112 pua.setStreet1(orderForm.getPickUpAddress1()); 113 pua.setLocalNumber(orderForm.getPickUpPhone()); 114 pua.setDirections(orderForm.getPickUpDirections()); 115 116 Address doa = d.getDropOff(); 117 doa.setName(orderForm.getDropOffName()); 118 doa.setStreet1(orderForm.getDropOffAddress1()); 119 doa.setLocalNumber(orderForm.getDropOffPhone()); 120 doa.setDirections(orderForm.getDropOffDirections()); 121 return d; 122 } catch (AirSentBusinessException be) { 123 throw be; 124 } catch (Exception e) { 125 throw new AirSentException(e); 126 } 127 } 128 129 136 public Delivery findByHandle(String handle) 137 throws AirSentBusinessException { 138 try { 139 DeliveryQuery query = new DeliveryQuery(); 140 query.requireUniqueInstance(); 141 query.setQueryOId(new ObjectId(handle)); 142 DeliveryDO theDeliveryDO = query.getNextDO(); 143 return new DeliveryImpl(update, theDeliveryDO); 144 } catch (Exception e) { 145 throw new AirSentBusinessException(e); 146 } 147 } 148 149 156 public Delivery[] findByCustomer(Customer customer) 157 throws AirSentBusinessException { 158 159 Delivery[] theDeliveryArray = null; 160 try { 161 DeliveryQuery query = new DeliveryQuery(); 162 QueryBuilder qb = query.getQueryBuilder(); 163 qb.addEndClause(" order by oid"); 164 query.setQueryCustomerID(CustomerDO.createExisting(customer.getHandle())); 165 DeliveryDO[] DOarray = query.getDOArray(); 166 theDeliveryArray = new Delivery[DOarray.length]; 167 for (int i = 0; i < DOarray.length; i++) { 168 theDeliveryArray[i] = new DeliveryImpl(update, DOarray[i]); 169 } 170 } catch (Exception e) { 171 throw new AirSentBusinessException(e); 172 } 173 return theDeliveryArray; 174 } 175 176 182 public Delivery[] findAll() 183 throws AirSentBusinessException { 184 Delivery[] theDeliveryArray = null; 185 try { 186 DeliveryQuery query = new DeliveryQuery(); 187 QueryBuilder qb = query.getQueryBuilder(); 188 qb.addEndClause(" order by oid"); 189 DeliveryDO[] DOarray = query.getDOArray(); 190 theDeliveryArray = new Delivery[DOarray.length]; 191 for (int i = 0; i < DOarray.length; i++) { 192 theDeliveryArray[i] = new DeliveryImpl(update, DOarray[i]); 193 } 194 } catch (Exception e) { 195 throw new AirSentBusinessException(e); 196 } 197 return theDeliveryArray; 198 } 199 200 201 208 public Delivery[] findSubset(int subset) 209 throws AirSentBusinessException { 210 Delivery[] theDeliveryArray = null; 211 try { 212 DeliveryQuery query = new DeliveryQuery(); 213 QueryBuilder qb = query.getQueryBuilder(); 214 qb.addEndClause(" order by oid"); 215 DeliveryDO[] DOarray = query.getDOArray(); 216 int count = 0; 217 if(DOarray.length <= subset) { 218 count = DOarray.length; 219 } else { 220 count = subset; 221 } 222 theDeliveryArray = new Delivery[count]; 223 for (int i = 0; i < count; i++) { 224 theDeliveryArray[i] = new DeliveryImpl(update, DOarray[i]); 225 } 226 } catch (Exception e) { 227 throw new AirSentBusinessException(e); 228 } 229 return theDeliveryArray; 230 } 231 232 239 public Delivery[] findByMessenger(Messenger messenger) 240 throws AirSentBusinessException { 241 Delivery[] theDeliveryArray = null; 242 try { 243 DeliveryQuery query = new DeliveryQuery(); 244 query.setQueryMessengerID(MessengerDO.createExisting(messenger.getHandle())); 245 DeliveryDO[] DOarray = query.getDOArray(); 251 int len=0; 252 for (int i = 0; i < DOarray.length; i++) { 253 if ((!DOarray[i].getIsPickedUp()) || (!DOarray[i].getIsDroppedOff())){ 254 len=len+1; 255 } 256 } 257 theDeliveryArray = new Delivery[len]; 258 int j=0; 259 for (int i = 0; i < DOarray.length; i++) { 260 if ((!DOarray[i].getIsPickedUp()) || (!DOarray[i].getIsDroppedOff())){ 261 theDeliveryArray[j] = new DeliveryImpl(update, DOarray[i]); 262 j=j+1; 263 } 264 } 265 } catch (Exception e) { 266 e.printStackTrace(); 267 throw new AirSentBusinessException(e); 268 } 269 return theDeliveryArray; 270 } 271 272 276 282 public Delivery[] findUndelivered() 283 throws AirSentBusinessException { 284 Delivery[] theDeliveryArray = null; 285 try { 286 DeliveryQuery query = new DeliveryQuery(); 287 query.setQueryIsPickedUp(false); 288 query.or(); 289 query.setQueryIsDroppedOff(false); 290 DeliveryDO[] DOarray = query.getDOArray(); 291 theDeliveryArray = new Delivery[DOarray.length]; 292 for (int i = 0; i < DOarray.length; i++) { 293 theDeliveryArray[i] = new DeliveryImpl(update, DOarray[i]); 294 } 295 } catch (Exception e) { 296 throw new AirSentBusinessException(e); 297 } 298 return theDeliveryArray; 299 } 300 301 308 public Delivery findByInvoice(int invoice) 309 throws AirSentBusinessException { 310 Delivery theDelivery = null; 311 try { 312 DeliveryQuery query = new DeliveryQuery(); 313 query.requireUniqueInstance(); 314 query.setQueryInvoice(invoice); 315 DeliveryDO theDeliveryDO = query.getNextDO(); 316 theDelivery = new DeliveryImpl(update, theDeliveryDO); 317 return theDelivery; 318 } catch (Exception e) { 319 throw new AirSentBusinessException(e); 320 } 321 } 322 323 330 public Delivery[] findAllAfter(long date) 331 throws AirSentBusinessException { 332 Delivery[] theDeliveryArray = null; 333 Date searchDate = new Date (date); 334 try { 335 DeliveryQuery query = new DeliveryQuery(); 336 QueryBuilder builder = query.getQueryBuilder(); 337 builder.addWhere(DeliveryDO.PickedUpTime, searchDate, QueryBuilder.GREATER_THAN); 338 builder.addWhereOr(); 339 builder.addWhere(DeliveryDO.DroppedOffTime, searchDate, QueryBuilder.GREATER_THAN); 340 DeliveryDO[] DOarray = query.getDOArray(); 341 theDeliveryArray = new Delivery[DOarray.length]; 342 for (int i = 0; i < DOarray.length; i++) { 343 theDeliveryArray[i] = new DeliveryImpl(update, DOarray[i]); 344 } 345 } catch (Exception e) { 346 throw new AirSentBusinessException(e); 347 } 348 return theDeliveryArray; 349 } 350 } 351 352 | Popular Tags |