001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.shopping.action;
022:
023: import com.liferay.portal.kernel.util.Constants;
024: import com.liferay.portal.kernel.util.ParamUtil;
025: import com.liferay.portal.kernel.util.StringUtil;
026: import com.liferay.portal.model.Layout;
027: import com.liferay.portal.security.auth.PrincipalException;
028: import com.liferay.portal.struts.PortletAction;
029: import com.liferay.portal.util.WebKeys;
030: import com.liferay.portlet.shopping.NoSuchOrderException;
031: import com.liferay.portlet.shopping.service.ShoppingOrderServiceUtil;
032: import com.liferay.portlet.shopping.util.ShoppingUtil;
033: import com.liferay.util.servlet.SessionErrors;
034:
035: import javax.portlet.ActionRequest;
036: import javax.portlet.ActionResponse;
037: import javax.portlet.PortletConfig;
038: import javax.portlet.RenderRequest;
039: import javax.portlet.RenderResponse;
040:
041: import org.apache.struts.action.ActionForm;
042: import org.apache.struts.action.ActionForward;
043: import org.apache.struts.action.ActionMapping;
044:
045: /**
046: * <a href="EditOrderAction.java.html"><b><i>View Source</i></b></a>
047: *
048: * @author Brian Wing Shun Chan
049: *
050: */
051: public class EditOrderAction extends PortletAction {
052:
053: public void processAction(ActionMapping mapping, ActionForm form,
054: PortletConfig config, ActionRequest req, ActionResponse res)
055: throws Exception {
056:
057: String cmd = ParamUtil.getString(req, Constants.CMD);
058:
059: try {
060: if (cmd.equals(Constants.ADD)
061: || cmd.equals(Constants.UPDATE)) {
062: updateOrder(req);
063: } else if (cmd.equals(Constants.DELETE)) {
064: deleteOrders(req);
065: } else if (cmd.equals("sendEmail")) {
066: sendEmail(req);
067: }
068:
069: sendRedirect(req, res);
070: } catch (Exception e) {
071: if (e instanceof NoSuchOrderException
072: || e instanceof PrincipalException) {
073:
074: SessionErrors.add(req, e.getClass().getName());
075:
076: setForward(req, "portlet.shopping.error");
077: } else {
078: throw e;
079: }
080: }
081: }
082:
083: public ActionForward render(ActionMapping mapping, ActionForm form,
084: PortletConfig config, RenderRequest req, RenderResponse res)
085: throws Exception {
086:
087: try {
088: ActionUtil.getOrder(req);
089: } catch (Exception e) {
090: if (e instanceof NoSuchOrderException
091: || e instanceof PrincipalException) {
092:
093: SessionErrors.add(req, e.getClass().getName());
094:
095: return mapping.findForward("portlet.shopping.error");
096: } else {
097: throw e;
098: }
099: }
100:
101: return mapping.findForward(getForward(req,
102: "portlet.shopping.edit_order"));
103: }
104:
105: protected void deleteOrders(ActionRequest req) throws Exception {
106: Layout layout = (Layout) req.getAttribute(WebKeys.LAYOUT);
107:
108: long[] deleteOrderIds = StringUtil.split(ParamUtil.getString(
109: req, "deleteOrderIds"), 0L);
110:
111: for (int i = 0; i < deleteOrderIds.length; i++) {
112: ShoppingOrderServiceUtil.deleteOrder(layout.getPlid(),
113: deleteOrderIds[i]);
114: }
115: }
116:
117: protected void sendEmail(ActionRequest req) throws Exception {
118: Layout layout = (Layout) req.getAttribute(WebKeys.LAYOUT);
119:
120: long orderId = ParamUtil.getLong(req, "orderId");
121:
122: String emailType = ParamUtil.getString(req, "emailType");
123:
124: ShoppingOrderServiceUtil.sendEmail(layout.getPlid(), orderId,
125: emailType);
126: }
127:
128: protected void updateOrder(ActionRequest req) throws Exception {
129: Layout layout = (Layout) req.getAttribute(WebKeys.LAYOUT);
130:
131: String number = ParamUtil.getString(req, "number");
132: String ppTxnId = ParamUtil.getString(req, "ppTxnId");
133: String ppPaymentStatus = ShoppingUtil
134: .getPpPaymentStatus(ParamUtil.getString(req,
135: "ppPaymentStatus"));
136: double ppPaymentGross = ParamUtil.getDouble(req,
137: "ppPaymentGross");
138: String ppReceiverEmail = ParamUtil.getString(req,
139: "ppReceiverEmail");
140: String ppPayerEmail = ParamUtil.getString(req, "ppPayerEmail");
141:
142: ShoppingOrderServiceUtil.completeOrder(layout.getPlid(),
143: number, ppTxnId, ppPaymentStatus, ppPaymentGross,
144: ppReceiverEmail, ppPayerEmail);
145: }
146:
147: }
|