Rev 3449 | Blame | Last modification | View Log | RSS feed
package in.shop2020.support.controllers;import in.shop2020.purchase.POStatus;import in.shop2020.purchase.Purchase;import in.shop2020.purchase.PurchaseOrder;import in.shop2020.purchase.PurchaseServiceException;import in.shop2020.thrift.clients.PurchaseClient;import java.util.List;import javax.servlet.ServletContext;import org.apache.struts2.util.ServletContextAware;import org.apache.thrift.TException;import org.apache.thrift.transport.TTransportException;import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class PurchaseOrderController implements ServletContextAware{private static Logger logger = LoggerFactory.getLogger(PurchaseOrderController.class);private ServletContext context;private String id;private List<PurchaseOrder> purchaseOrders;private PurchaseOrder purchaseOrder;private List<Purchase> purchases;public String index(){//Get a list of all the open purchase orderstry {PurchaseClient purchaseClient = new PurchaseClient();in.shop2020.purchase.PurchaseService.Client client = purchaseClient.getClient();purchaseOrders = client.getAllPurchaseOrders(POStatus.READY);purchaseOrders.addAll(client.getAllPurchaseOrders(POStatus.PARTIALLY_FULFILLED));} catch (TTransportException e) {logger.error("Unable to get the list of all purchase orders.", e);} catch (TException e) {logger.error("Error while communicating to the warehouse server.", e);} catch (PurchaseServiceException e) {logger.error("Error while getting the list of all purchase orders.", e);}return "index";}public String show(){//Get a list of all the open purchase orderstry {PurchaseClient warehouseClient = new PurchaseClient();in.shop2020.purchase.PurchaseService.Client client = warehouseClient.getClient();purchaseOrder = client.getPurchaseOrder(Long.parseLong(id));purchases = client.getAllPurchases(purchaseOrder.getId(), true);} catch (TTransportException e) {logger.error("Unable to get the list of all purchases.", e);} catch (TException e) {logger.error("Error while communicating to the warehouse server.", e);} catch (NumberFormatException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (PurchaseServiceException e) {logger.error("Error while getting the list of all purchases.", e);}return "show";}public void setId(String id){this.id = id;}public List<PurchaseOrder> getPurchaseOrders(){return purchaseOrders;}public PurchaseOrder getPurchaseOrder(){return purchaseOrder;}public List<Purchase> getPurchases(){return purchases;}@Overridepublic void setServletContext(ServletContext context) {this.context = context;}public String getServletContextPath() {return context.getContextPath();}}