⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ordermanagementactions.java

📁 噶额外噶外骨骼感广泛高热感 就 啊啊
💻 JAVA
字号:
/*
 * @author                        : Sujatha
 * @Version                       : 1.0
 *
 * Development Environment        : Oracle9i JDeveloper
 * Name of the File               : OrderManagementActions.java
 * Creation/Modification History  :
 *
 * Sujatha   16-Jan-2003      Created
 *
 */
package oracle.otnsamples.vsm.actions.owner;


//IO and servlet API
import java.io.IOException;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.StringTokenizer;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import oracle.otnsamples.util.MessageCache;
import oracle.otnsamples.util.ServiceLocator;
import oracle.otnsamples.vsm.Constants;
import oracle.otnsamples.vsm.services.OrderException;
import oracle.otnsamples.vsm.services.OrderManagement;
import oracle.otnsamples.vsm.services.OrderManagementHome;
import oracle.otnsamples.vsm.services.ShopOwner;
import oracle.otnsamples.vsm.services.ShopOwnerHome;
import oracle.otnsamples.vsm.services.data.Order;
import oracle.otnsamples.vsm.services.data.OrderDetail;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.actions.DispatchAction;


/**
 * This action class is used by the shop owner to manage the 
 * pending orders for a shop.
 * 
 * @author Sujatha
 * @version 1.0
 */
public class OrderManagementActions extends DispatchAction {
  /**
   * This is the action called from the Struts framework to get the list of
   * pending orders for a given shop
   *
   * @param mapping The ActionMapping used to select this instance.
   * @param form The optional ActionForm bean for this request.
   * @param request The HTTP Request we are processing.
   * @param response The HTTP Response we are processing.
   */
  public ActionForward getPendingOrders(
                                        ActionMapping mapping, ActionForm form,
                                        HttpServletRequest request,
                                        HttpServletResponse response)
                                 throws IOException, 
                                        ServletException {

    OrderManagementHome orderHome = null;
    OrderManagement order         = null;
    ActionForward forward         = mapping.findForward("ordersForm");

    try {
      orderHome =
        (OrderManagementHome) ServiceLocator.getLocator().getService("OrderManagement");
      order = orderHome.create();

      Order[] orders =
        order.getPendingOrdersForShop((String) request.getSession()
                                                      .getAttribute("shopID"));
      request.setAttribute("orders", orders);

      /* Loop through the pending orders and for each order item retrieve the
         item name */
      if(orders != null) {

        HashMap itemInfo = new HashMap();
        String itemID    = null;
        String langID    = request.getLocale().getLanguage();
        List ordersList  = null;

        for(int i = 0; i < orders.length; i++) {
          ordersList = orders [ i ].getOrderDetail();

          for(int j = 0; j < ordersList.size(); j++) {
            itemID = ((OrderDetail) ordersList.get(j)).getItemID();
            itemInfo.put(itemID, order.getItemName(itemID, langID));
          }
        }

        request.setAttribute("itemInfo", itemInfo);
      }
    } catch(OrderException ex) {
      servlet.log("PendingOrdersError", ex);
      ActionErrors errors = new ActionErrors();
      errors.add("ShopError", new ActionError("common.error", ex.getMessage()));
      saveErrors(request, errors);
      forward = mapping.findForward("error");
    } catch(Exception ex) {
      servlet.log("PendingOrdersError", ex);
      ActionErrors errors = new ActionErrors();
      errors.add("ShopError", new ActionError("common.error", ex.getMessage()));
      saveErrors(request, errors);
      forward = mapping.findForward("error");
    } finally {

      try {

        if(order != null) {
          order.remove();
        }
      } catch(Exception ex) {
      }
    }

    return forward;
  }
  /**
   * This is the action called from the Struts framework to update the status
   * of orders selected for shipment by the shop owner
   *
   * @param mapping The ActionMapping used to select this instance.
   * @param form The optional ActionForm bean for this request.
   * @param request The HTTP Request we are processing.
   * @param response The HTTP Response we are processing.
   */
  public ActionForward updateOrders(
                                    ActionMapping mapping, ActionForm form,
                                    HttpServletRequest request,
                                    HttpServletResponse response)
                             throws IOException, 
                                    ServletException {

    ShopOwnerHome shopHome = null;
    ShopOwner shop         = null;
    ActionForward forward  = mapping.findForward("success");

    try {

      List orderDetails = new ArrayList();
      Enumeration names = request.getParameterNames();
      String param      = null;
      String val        = null;

      while(names.hasMoreElements()) {
        param   = (String) names.nextElement();
        val     = request.getParameter(param);

        // For each order selected for shipping, get the order id and order item id
        if(
           Constants.SHIPPED.equals(val) || Constants.IN_PROGRESS.equals(val) ||
             Constants.REJECTED.equals(val)) {

          // Order id and order item id are separated by # in the request object
          // i.e <order_id>#<order_item_id>
          // Get the individual values using String Tokenizer
          StringTokenizer st = new StringTokenizer(param, "#");
          orderDetails.add(new OrderDetail(
                                           st.nextToken(), // orderID
                                           st.nextToken(), // itemID
                                           null,
                                           Integer.parseInt(st.nextToken()), // quantity
                                           0.0, // unitPrice  
                                           val)); // status   
        }
      }
      if( orderDetails.size() > 0 ) {
        shopHome =
          (ShopOwnerHome) ServiceLocator.getLocator().getService("ShopOwner");
        shop = shopHome.create();
        shop.manageOrders(orderDetails);
      }
      ActionMessages messages = new ActionMessages();
      messages.add(
                   "OrderUpdateSuccess",
                   new ActionMessage("message.orderupdate.success"));
      saveMessages(request, messages);
      
    } catch(OrderException ex) {
      servlet.log("UpdateOrdersError", ex);
      ActionErrors errors = new ActionErrors();
      errors.add(
                 "ShopError",
                 new ActionError(
                                 "common.error",
                                 MessageCache.getMessage(
                                                         ex.getMessageCode(),
                                                         getLocale(request))));
      saveErrors(request, errors);
      forward = mapping.findForward("error");
    } catch(Exception ex) {
      servlet.log("UpdateOrdersError", ex);
      ActionErrors errors = new ActionErrors();
      errors.add("ShopError", new ActionError("common.error", ex.getMessage()));
      saveErrors(request, errors);
      forward = mapping.findForward("error");
    } finally {

      try {

        if(shop != null) {
          shop.remove();
        }
      } catch(Exception ex) {
        ex.printStackTrace();
      }
    }

    return forward;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -