📄 orderchangehelper.java
字号:
/*
* $Id: OrderChangeHelper.java,v 1.10 2003/12/06 23:57:46 ajzeneski Exp $
*
* Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
package org.ofbiz.order.order;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.ofbiz.base.util.*;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.util.EntityUtil;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.ModelService;
import org.ofbiz.service.ServiceUtil;
import org.ofbiz.workflow.WfException;
import org.ofbiz.workflow.client.WorkflowClient;
/**
* Order Helper - Helper Methods For Non-Read Actions
*
* @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
* @version $Revision: 1.10 $
* @since 2.0
*/
public class OrderChangeHelper {
public static final String module = OrderChangeHelper.class.getName();
public static boolean approveOrder(LocalDispatcher dispatcher, GenericValue userLogin, String orderId) {
GenericValue productStore = OrderReadHelper.getProductStoreFromOrder(dispatcher.getDelegator(), orderId);
String HEADER_STATUS = "ORDER_PROCESSING";
String ITEM_STATUS = "ITEM_CREATED";
String DIGITAL_ITEM_STATUS = "ITEM_APPROVED";
if (productStore.get("headerApprovedStatus") != null) {
HEADER_STATUS = productStore.getString("headerApprovedStatus");
}
if (productStore.get("itemApprovedStatus") != null) {
ITEM_STATUS = productStore.getString("itemApprovedStatus");
}
if (productStore.get("digitalItemApprovedStatus") != null) {
DIGITAL_ITEM_STATUS = productStore.getString("digitalItemApprovedStatus");
}
try {
OrderChangeHelper.orderStatusChanges(dispatcher, userLogin, orderId, HEADER_STATUS, "ITEM_CREATED", ITEM_STATUS, DIGITAL_ITEM_STATUS);
OrderChangeHelper.releaseInitialOrderHold(dispatcher, orderId);
// call the service to check/run digial fulfillment
Map checkDigi = dispatcher.runSync("checkDigitalItemFulfillment", UtilMisc.toMap("orderId", orderId, "userLogin", userLogin));
// this service will return a message with success if there were any problems. Get this message and return it to the user
String message = (String) checkDigi.get(ModelService.SUCCESS_MESSAGE);
if (UtilValidate.isNotEmpty(message)) {
throw new GeneralRuntimeException(message);
}
} catch (GenericServiceException e) {
Debug.logError(e, "Service invocation error, status changes were not updated for order #" + orderId, module);
return false;
}
return true;
}
public static boolean rejectOrder(LocalDispatcher dispatcher, GenericValue userLogin, String orderId) {
GenericValue productStore = OrderReadHelper.getProductStoreFromOrder(dispatcher.getDelegator(), orderId);
String HEADER_STATUS = "ORDER_REJECTED";
String ITEM_STATUS = "ITEM_REJECTED";
if (productStore.get("headerDeclinedStatus") != null) {
HEADER_STATUS = productStore.getString("headerDeclinedStatus");
}
if (productStore.get("itemDeclinedStatus") != null) {
ITEM_STATUS = productStore.getString("itemDeclinedStatus");
}
try {
OrderChangeHelper.orderStatusChanges(dispatcher, userLogin, orderId, HEADER_STATUS, null, ITEM_STATUS, null);
OrderChangeHelper.cancelInventoryReservations(dispatcher, userLogin, orderId);
OrderChangeHelper.releasePaymentAuthorizations(dispatcher, userLogin,orderId);
OrderChangeHelper.releaseInitialOrderHold(dispatcher, orderId);
} catch (GenericServiceException e) {
Debug.logError(e, "Service invocation error, status changes were not updated for order #" + orderId, module);
return false;
}
return true;
}
public static boolean cancelOrder(LocalDispatcher dispatcher, GenericValue userLogin, String orderId) {
GenericValue productStore = OrderReadHelper.getProductStoreFromOrder(dispatcher.getDelegator(), orderId);
String HEADER_STATUS = "ORDER_CANCELLED";
String ITEM_STATUS = "ITEM_CANCELLED";
if (productStore.get("headerCancelStatus") != null) {
HEADER_STATUS = productStore.getString("headerCancelStatus");
}
if (productStore.get("itemCancelStatus") != null) {
ITEM_STATUS = productStore.getString("itemCancelStatus");
}
try {
OrderChangeHelper.orderStatusChanges(dispatcher, userLogin, orderId, HEADER_STATUS, null, ITEM_STATUS, null);
OrderChangeHelper.cancelInventoryReservations(dispatcher, userLogin, orderId);
OrderChangeHelper.releasePaymentAuthorizations(dispatcher, userLogin,orderId);
OrderChangeHelper.releaseInitialOrderHold(dispatcher, orderId);
} catch (GenericServiceException e) {
Debug.logError(e, "Service invocation error, status changes were not updated for order #" + orderId, module);
return false;
}
return true;
}
public static void orderStatusChanges(LocalDispatcher dispatcher, GenericValue userLogin, String orderId, String orderStatus, String fromItemStatus, String toItemStatus, String digitalItemStatus) throws GenericServiceException {
// set the status on the order header
Map statusFields = UtilMisc.toMap("orderId", orderId, "statusId", orderStatus, "userLogin", userLogin);
Map statusResult = dispatcher.runSync("changeOrderStatus", statusFields);
if (statusResult.containsKey(ModelService.ERROR_MESSAGE)) {
Debug.logError("Problems adjusting order header status for order #" + orderId, module);
}
// set the status on the order item(s)
Map itemStatusFields = UtilMisc.toMap("orderId", orderId, "statusId", toItemStatus, "userLogin", userLogin);
if (fromItemStatus != null) {
itemStatusFields.put("fromStatusId", fromItemStatus);
}
Map itemStatusResult = dispatcher.runSync("changeOrderItemStatus", itemStatusFields);
if (itemStatusResult.containsKey(ModelService.ERROR_MESSAGE)) {
Debug.logError("Problems adjusting order item status for order #" + orderId, module);
}
// now set the status for digital items
if (digitalItemStatus != null && !digitalItemStatus.equals(toItemStatus)) {
GenericDelegator delegator = dispatcher.getDelegator();
GenericValue orderHeader = null;
try {
orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
} catch (GenericEntityException e) {
Debug.logError(e, "ERROR: Unable to get OrderHeader for OrderID : " + orderId, module);
}
if (orderHeader != null) {
List orderItems = null;
try {
orderItems = orderHeader.getRelated("OrderItem");
} catch (GenericEntityException e) {
Debug.logError(e, "ERROR: Unable to get OrderItem records for OrderHeader : " + orderId, module);
}
if (orderItems != null && orderItems.size() > 0) {
Iterator oii = orderItems.iterator();
while (oii.hasNext()) {
GenericValue orderItem = (GenericValue) oii.next();
String orderItemSeqId = orderItem.getString("orderItemSeqId");
GenericValue product = null;
try {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -