HttpServletResponse response) throws Throwable {
ShipMaintActionForm form = (ShipMaintActionForm) actionForm;
AdminBean adminBean = getAdminBean(request);
User user = adminBean.getUser();
EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
OrderHeader orderHeader = (OrderHeader) em.find(OrderHeader.class, Format.getLong(form.getOrderHeaderId()));
getMissingFormInformation(form, adminBean.getSiteId());
String shipHeaderId = form.getShipHeaderId();
ShipHeader shipHeader = null;
if (!Format.isNullOrEmpty(shipHeaderId)) {
shipHeader = (ShipHeader) em.find(ShipHeader.class, Format.getLong(form.getShipHeaderId()));
}
ShipEngine shipEngine = null;
if (shipHeader == null) {
shipEngine = new ShipEngine(orderHeader, user);
}
else {
shipEngine = new ShipEngine(shipHeader, user);
}
shipEngine.setUpdateInventory(form.isUpdateInventory());
initOrder(form, orderHeader, null, null, shipHeader, request);
boolean isValid = validateInput(form, request);
ShipDetailDisplayForm shipDisplays[] = form.getShipDetails();
for (int i = 0; i < shipDisplays.length; i++) {
ShipDetailDisplayForm shipDisplay = shipDisplays[i];
if (!Format.isNullOrEmpty(shipDisplay.getInputShipQtyError())) {
continue;
}
shipEngine.setQty(shipDisplay.getItemSkuCd(), Format.getInt(shipDisplay.getInputShipQty()));
}
shipEngine.calculateHeader();
initOrder(form, orderHeader, null, null, null, request);
if (!isValid) {
Long id = null;
if (!Format.isNullOrEmpty(shipHeaderId)) {
id = Format.getLong(shipHeaderId);
}
calcTotal(form, id, shipEngine);
form.setEditable(true);
form.setNewShip(true);
if (!Format.isNullOrEmpty(shipHeaderId)) {
form.setNewShip(false);
}
em.getTransaction().rollback();
ActionForward actionForward = actionMapping.findForward("error");
return actionForward;
}
saveInput(form, shipEngine);
try {
shipEngine.shipOrder(request);
shipEngine.saveOrder();
OrderEngine orderEngine = new OrderEngine(orderHeader, user);
orderHeader.setOrderStatus(orderEngine.calcStatus(orderHeader));
}
catch (OrderStateException e) {
initOrder(form, orderHeader, null, null, shipHeader, request);
calcTotal(form, shipHeader.getShipHeaderId(), shipEngine);
ActionMessages errors = new ActionMessages();