*
* @param transportable
* @param window
*/
void initTransportable(Transportable transportable, WindowInterface window) {
PostShipmentManager postShipmentManager = (PostShipmentManager) ModelUtil
.getBean("postShipmentManager");
CustTrManager custTrManager = (CustTrManager) ModelUtil
.getBean("custTrManager");
Set<String> checkers = statusCheckers.keySet();
Map<String, String> statusMap;
String status;
StatusCheckerInterface<Transportable> checker;
boolean orderLoaded = false;
boolean needToSave = false;
transportable.setCustTrs(custTrManager.findByOrderNr(transportable
.getOrder().getOrderNr()));
statusMap = Util.createStatusMap(transportable.getStatus());
for (String checkerName : checkers) {
checker = statusCheckers.get(checkerName);
status = statusMap.get(checker.getArticleName());
if (status == null) {
needToSave = true;
if (!orderLoaded && transportable instanceof Order) {
((OrderManager) overviewManager).lazyLoadOrder(
(Order) transportable, new LazyLoadOrderEnum[] {
LazyLoadOrderEnum.COLLIES,
LazyLoadOrderEnum.ORDER_LINES,
LazyLoadOrderEnum.ORDER_LINE_ORDER_LINES,
LazyLoadOrderEnum.COMMENTS,
LazyLoadOrderEnum.PROCENT_DONE });
orderLoaded = true;
} else if (!orderLoaded
&& transportable instanceof PostShipment) {
postShipmentManager
.lazyLoad(
(PostShipment) transportable,
new LazyLoadPostShipmentEnum[] {
LazyLoadPostShipmentEnum.COLLIES,
LazyLoadPostShipmentEnum.ORDER_LINES,
LazyLoadPostShipmentEnum.ORDER_LINE_ORDER_LINES,
LazyLoadPostShipmentEnum.ORDER_COMMENTS });
orderLoaded = true;
}
status = checker.getArticleStatus(transportable);
}
statusMap.put(checker.getArticleName(), status);
}
transportable.setStatus(Util.statusMapToString(statusMap));
if (transportable.getComment() == null) {
needToSave = true;
cacheComment(transportable, window, !orderLoaded);
orderLoaded = true;
}
if (needToSave) {
if (transportable instanceof Order) {
try {
((OrderManager) overviewManager)
.saveOrder((Order) transportable);
} catch (ProTransException e) {
Util.showErrorDialog(window, "Feil", e.getMessage());
e.printStackTrace();
}
} else {
postShipmentManager
.savePostShipment((PostShipment) transportable);
}
}
if (transportable instanceof Order
&& !Hibernate.isInitialized(((Order) transportable)