| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ShopOrderItem |
|
| 5.0;5 |
| 1 | package org.paneris.bibliomania; | |
| 2 | ||
| 3 | import java.sql.Timestamp; | |
| 4 | import java.util.Enumeration; | |
| 5 | ||
| 6 | import org.melati.poem.AccessPoemException; | |
| 7 | import org.paneris.bibliomania.generated.ShopOrderItemBase; | |
| 8 | ||
| 9 | public class ShopOrderItem extends ShopOrderItemBase { | |
| 10 | 0 | public ShopOrderItem() {} |
| 11 | ||
| 12 | // when we set the line status, we should check to see if the order status | |
| 13 | // required changing | |
| 14 | public void setStatus(OrderStatus cooked) | |
| 15 | throws AccessPoemException { | |
| 16 | 0 | super.setStatus(cooked); |
| 17 | 0 | BibliomaniaDatabase db = (BibliomaniaDatabase)getDatabase(); |
| 18 | ||
| 19 | // set the date | |
| 20 | 0 | if (getFufilleddate_unsafe() == null && |
| 21 | cooked == db.getOrderStatusTable().getFufilled()) { | |
| 22 | 0 | setFufilleddate_unsafe(now()); |
| 23 | } | |
| 24 | ||
| 25 | // set the order status | |
| 26 | 0 | ShopOrder orderL = getOrder(); |
| 27 | 0 | Enumeration e = orderL.getItems(); |
| 28 | 0 | boolean notAuthorised = false; |
| 29 | 0 | boolean authorised = false; |
| 30 | 0 | boolean partFufilled = false; |
| 31 | 0 | boolean fufilled = false; |
| 32 | 0 | while (e.hasMoreElements()) { |
| 33 | 0 | ShopOrderItem item = (ShopOrderItem)e.nextElement(); |
| 34 | // anything not authorised - the entire order is not authorised | |
| 35 | 0 | if (item.getStatus() == db.getOrderStatusTable().getNotAuthorised()) |
| 36 | 0 | notAuthorised = true; |
| 37 | 0 | if (item.getStatus() == db.getOrderStatusTable().getAuthorised()) |
| 38 | 0 | authorised = true; |
| 39 | 0 | if (item.getStatus() == db.getOrderStatusTable().getPartFufilled()) |
| 40 | 0 | partFufilled = true; |
| 41 | 0 | if (item.getStatus() == db.getOrderStatusTable().getFufilled()) |
| 42 | 0 | fufilled = true; |
| 43 | 0 | } |
| 44 | // only found fufilled - entire order is fufilled | |
| 45 | 0 | if (fufilled && !partFufilled && !authorised && !notAuthorised) { |
| 46 | 0 | orderL.setStatus(db.getOrderStatusTable().getFufilled()); |
| 47 | 0 | return; |
| 48 | } | |
| 49 | // anything fufilled or part fufilled - entire order is part fufilled | |
| 50 | 0 | if (fufilled || partFufilled) { |
| 51 | 0 | orderL.setStatus(db.getOrderStatusTable().getPartFufilled()); |
| 52 | 0 | return; |
| 53 | } | |
| 54 | // otherwise anything not authorisaed - entire order is not authorised | |
| 55 | 0 | if (notAuthorised) { |
| 56 | 0 | orderL.setStatus(db.getOrderStatusTable().getNotAuthorised()); |
| 57 | 0 | return; |
| 58 | } | |
| 59 | // this order must therefor be simply authorised | |
| 60 | 0 | orderL.setStatus(db.getOrderStatusTable().getAuthorised()); |
| 61 | 0 | } |
| 62 | ||
| 63 | public void setFufilleddate_unsafe(Timestamp cooked) { | |
| 64 | // avoid nulling it if the flag is set | |
| 65 | 0 | BibliomaniaDatabase db = (BibliomaniaDatabase)getDatabase(); |
| 66 | 0 | if (getStatus() != db.getOrderStatusTable().getFufilled() || cooked != null) { |
| 67 | 0 | super.setFufilleddate_unsafe(cooked); |
| 68 | } | |
| 69 | 0 | } |
| 70 | ||
| 71 | protected void writeLock() { | |
| 72 | 0 | super.writeLock(); |
| 73 | 0 | if (getDate_unsafe() == null) { |
| 74 | 0 | setDate_unsafe(now()); |
| 75 | } | |
| 76 | 0 | } |
| 77 | ||
| 78 | private static java.sql.Timestamp now() { | |
| 79 | 0 | return new java.sql.Timestamp(new java.util.Date().getTime()); |
| 80 | } | |
| 81 | ||
| 82 | } |