adding cc auth process before processing shipment.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk/specialpurpose@558234 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Anil Patel
2007-07-21 03:34:07 +00:00
parent a4bbf1826c
commit 61e0a446c5
3 changed files with 253 additions and 213 deletions
+2 -2
View File
@@ -28,9 +28,9 @@ under the License.
<condition-field field-name="statusId" operator="not-equals" to-field-name="oldStatusId"/>
<action service="oagisProcessShipment" mode="sync"/>
</eca-->
<eca service="oagisPocessShipment" event="commit" run-on-error="false">
<!--eca service="oagisPocessShipment" event="commit" run-on-error="false">
<action service="createOagisMessageInfo" mode="sync"/>
</eca>
</eca-->
<!--<eca service="receiveConfirmBod" event="commit" run-on-error="true">
<action service="createOagisMessageInfo" mode="sync"/>
+5 -5
View File
@@ -45,7 +45,7 @@ under the License.
<attribute name="errorMapList" type="java.util.List" mode="OUT" optional="true"/>
</service>
<service name="createOagisMessageInfo" engine="simple" default-entity-name="OagisMessageInfo"
<service name="createOagisMessageInfo" engine="simple" default-entity-name="OagisMessageInfo"
location="org/ofbiz/oagis/OagisMessageServices.xml" invoke="createOagisMessageInfo" auth="true">
<description>Create MessageInfo</description>
<auto-attributes mode="IN" include="pk" optional="false"/>
@@ -65,7 +65,7 @@ under the License.
<auto-attributes mode="IN" include="pk" optional="false"/>
<auto-attributes mode="IN" include="nonpk" optional="true"/>
<override name="errorSeqId" optional="true"/>
</service>
</service>
<service name="updateOagisMessageErrorInfo" engine="simple" default-entity-name="OagisMessageErrorInfo"
location="org/ofbiz/oagis/OagisMessageServices.xml" invoke="updateOagisMessageErrorInfo" auth="true">
@@ -119,17 +119,17 @@ under the License.
<attribute name="bodyParameters" type="Map" mode="IN" optional="true"/>
<attribute name="body" type="String" mode="OUT" optional="true"/>
</service>
<service name="oagisProcessShipment" max-retry="0" engine="java"
<service name="oagisProcessShipment" max-retry="0" engine="java"
location="org.ofbiz.oagis.OagisShipmentServices" invoke="oagisProcessShipment">
<description>Prepare and Optionally Send OAGIS Process Shipment Message.
Note on usage: you can pass in either sendToUrl, saveToFilename, or outputStream.
If none are passed in the URL in oagis.properties will be used at the target for the message.</description>
<implements service="oagisMessageInfoInterface"/>
<!--implements service="oagisMessageInfoInterface"/-->
<attribute name="sendToUrl" type="String" mode="IN" optional="true"/>
<attribute name="saveToFilename" type="String" mode="IN" optional="true"/>
<attribute name="saveToDirectory" type="String" mode="IN" optional="true"/>
<attribute name="outputStream" type="java.io.OutputStream" mode="IN" optional="true"/>
<override name="orderId" mode="INOUT" type="String" optional="false"/>
<attribute name="orderId" mode="IN" type="String" optional="false"/>
</service>
<service name="sendProcessShipmentMsg" max-retry="0" engine="simple"
location="org/ofbiz/oagis/OagisMessageServices.xml" invoke="sendProcessShipmentMsg">
@@ -36,6 +36,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
@@ -43,6 +44,7 @@ import java.util.TreeSet;
import javax.xml.parsers.ParserConfigurationException;
import javolution.util.FastList;
import javolution.util.FastMap;
import javolution.util.FastSet;
import org.ofbiz.base.util.Debug;
@@ -247,8 +249,10 @@ public class OagisShipmentServices {
String saveToFilename = (String) context.get("saveToFilename");
String saveToDirectory = (String) context.get("saveToDirectory");
OutputStream out = (OutputStream) context.get("outputStream");
Locale locale = (Locale) context.get("locale");
Map result = ServiceUtil.returnSuccess();
Map comiCtx = new HashMap();
MapStack bodyParameters = MapStack.create();
if (userLogin == null) {
try {
@@ -257,215 +261,251 @@ public class OagisShipmentServices {
Debug.logError(e, "Error getting userLogin", module);
}
}
GenericValue orderHeader = null;
GenericValue orderItemShipGroup = null;
try {
orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
GenericValue shipment =null;
if (orderHeader != null) {
String orderStatusId = orderHeader.getString("statusId");
if (orderStatusId.equals("ORDER_APPROVED")) {
try {
Map cospResult= dispatcher.runSync("createOrderShipmentPlan", UtilMisc.toMap("orderId", orderId, "userLogin", userLogin));
shipmentId = (String) cospResult.get("shipmentId");
} catch (GenericServiceException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
// check payment authorization
boolean checkPaymentAuth = false;
if (orderId != null) {
Map serviceContext = FastMap.newInstance();
serviceContext.put("orderId", orderId);
serviceContext.put("userLogin", userLogin);
Map authResult = null;
try {
authResult = dispatcher.runSync("authOrderPayments", serviceContext);
String processResult = (String) authResult.get("processResult");
if (processResult.equals("APPROVED")) {
checkPaymentAuth = true;
Debug.logInfo("payment authorization completed: ", module);
} else {
Debug.logInfo("payment authorization could not completed: ", module);
}
try {
shipment = delegator.findByPrimaryKey("Shipment", UtilMisc.toMap("shipmentId", shipmentId));
bodyParameters.put("shipment", shipment);
OrderReadHelper orderReadHelper = new OrderReadHelper(orderHeader);
if(orderReadHelper.hasShippingAddress()) {
GenericValue address = EntityUtil.getFirst(orderReadHelper.getShippingLocations());
bodyParameters.put("address", address);
}
String emailString = orderReadHelper.getOrderEmailString();
bodyParameters.put("emailString", emailString);
String contactMechId = shipment.getString("destinationTelecomNumberId");
GenericValue telecomNumber = delegator.findByPrimaryKey("TelecomNumber", UtilMisc.toMap("contactMechId", contactMechId));
bodyParameters.put("telecomNumber", telecomNumber);
List shipmentItems = delegator.findByAnd("ShipmentItem", UtilMisc.toMap("shipmentId", shipmentId));
bodyParameters.put("shipmentItems", shipmentItems);
orderItemShipGroup = EntityUtil.getFirst(delegator.findByAnd("OrderItemShipGroup", UtilMisc.toMap("orderId", orderId)));
bodyParameters.put("orderItemShipGroup", orderItemShipGroup);
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
Set correspondingPoIdSet = FastSet.newInstance();
try {
List orderItems = delegator.findByAnd("OrderItem", UtilMisc.toMap("orderId", shipment.getString("primaryOrderId")));
Iterator oiIter = orderItems.iterator();
while (oiIter.hasNext()) {
GenericValue orderItem = (GenericValue) oiIter.next();
String correspondingPoId = orderItem.getString("correspondingPoId");
if (correspondingPoId != null) {
correspondingPoIdSet.add(correspondingPoId);
}
}
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
bodyParameters.put("correspondingPoIdSet", correspondingPoIdSet);
Set externalIdSet = FastSet.newInstance();
try {
GenericValue primaryOrderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", shipment.getString("primaryOrderId")));
externalIdSet.add(primaryOrderHeader.getString("externalId"));
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
bodyParameters.put("externalIdSet", externalIdSet);
// Check if order was a return replacement order (associated with return)
List returnItemResponses = null;
List returnItemRespExprs = UtilMisc.toList(new EntityExpr("replacementOrderId", EntityOperator.NOT_EQUAL, null));
EntityCondition returnItemRespCond = new EntityConditionList(returnItemRespExprs, EntityOperator.AND);
// list of fields to select (initial list)
List fieldsToSelect = FastList.newInstance();
fieldsToSelect.add("replacementOrderId");
try {
returnItemResponses = delegator.findByCondition("ReturnItemResponse", returnItemRespCond, fieldsToSelect, null);
Iterator rirIter = returnItemResponses.iterator();
while (rirIter.hasNext()) {
GenericValue returnItemResponse = (GenericValue) rirIter.next();
String replacementOrderId = returnItemResponse.getString("replacementOrderId");
if (replacementOrderId.equals(shipment.getString("primaryOrderId"))) {
bodyParameters.put("shipnotes", "RETURNLABEL");
// Get the associated return Id (replaceReturnId)
String returnItemResponseId = returnItemResponse.getString("returnItemResponseId");
GenericValue returnItem = EntityUtil.getFirst(delegator.findByAnd("ReturnItem", UtilMisc.toMap("returnItemResponseId", returnItemResponseId)));
bodyParameters.put("replacementReturnId", returnItem.getString("returnId"));
}
}
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
String logicalId = UtilProperties.getPropertyValue("oagis.properties", "CNTROLAREA.SENDER.LOGICALID");
bodyParameters.put("logicalId", logicalId);
result.put("logicalId", logicalId);
String authId = UtilProperties.getPropertyValue("oagis.properties", "CNTROLAREA.SENDER.AUTHID");
bodyParameters.put("authId", authId);
result.put("authId", authId);
String referenceId = delegator.getNextSeqId("OagisMessageInfo");
bodyParameters.put("referenceId", referenceId);
result.put("referenceId", referenceId);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'Z");
Timestamp timestamp = UtilDateTime.nowTimestamp();
String sentDate = dateFormat.format(timestamp);
bodyParameters.put("sentDate", sentDate);
result.put("sentDate", timestamp);
// tracking shipper account
String partyId = shipment.getString("partyIdTo");
List partyCarrierAccounts = new ArrayList();
try {
partyCarrierAccounts = delegator.findByAnd("PartyCarrierAccount", UtilMisc.toMap("partyId", partyId));
partyCarrierAccounts = EntityUtil.filterByDate(partyCarrierAccounts);
if (partyCarrierAccounts != null) {
Iterator pcaIter = partyCarrierAccounts.iterator();
while (pcaIter.hasNext()) {
GenericValue partyCarrierAccount = (GenericValue) pcaIter.next();
String carrierPartyId = partyCarrierAccount.getString("carrierPartyId");
if (carrierPartyId.equals(orderItemShipGroup.getString("carrierPartyId"))) {
String accountNumber = partyCarrierAccount.getString("accountNumber");
bodyParameters.put("shipperId", accountNumber);
}
}
}
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
bodyParameters.put("shipmentId", shipmentId);
bodyParameters.put("orderId", orderId);
bodyParameters.put("userLogin", userLogin);
String bodyScreenUri = UtilProperties.getPropertyValue("oagis.properties", "Oagis.Template.ProcessShipment");
Writer writer = null;
if (out != null) {
writer = new OutputStreamWriter(out);
} else if (UtilValidate.isNotEmpty(saveToFilename)) {
try {
File outdir = new File(saveToDirectory);
if (!outdir.exists()) {
outdir.mkdir();
}
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(outdir, saveToFilename)), "UTF-8")));
} catch (Exception e) {
String errMsg = "Error opening file to save message to [" + saveToFilename + "]: " + e.toString();
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
}
} else if (UtilValidate.isNotEmpty(sendToUrl)) {
writer = new StringWriter();
}
ScreenRenderer screens = new ScreenRenderer(writer, bodyParameters, new HtmlScreenRenderer());
try {
screens.render(bodyScreenUri);
writer.close();
} catch (Exception e) {
String errMsg = "Error rendering message: " + e.toString();
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
}
// TODO: call service with require-new-transaction=true to save the OagisMessageInfo data (to make sure it saves before)
if (UtilValidate.isNotEmpty(sendToUrl)) {
HttpClient http = new HttpClient(sendToUrl);
// test parameters
http.setHostVerificationLevel(SSLUtil.HOSTCERT_NO_CHECK);
http.setAllowUntrusted(true);
http.setDebug(true);
// needed XML post parameters
if (UtilValidate.isNotEmpty(certAlias)) {
http.setClientCertificateAlias(certAlias);
}
if (UtilValidate.isNotEmpty(basicAuthUsername)) {
http.setBasicAuthInfo(basicAuthUsername, basicAuthPassword);
}
http.setContentType("text/xml");
http.setKeepAlive(true);
try {
String resp = http.post(writer.toString());
} catch (Exception e) {
String errMsg = "Error posting message to server with UTL [" + sendToUrl + "]: " + e.toString();
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
}
}
// prepare map to Create Oagis Message Info
result.put("component", "INVENTORY");
result.put("task", "SHIPREQUES"); // Actual value of task is "SHIPREQUEST" which is more than 10 char
result.put("outgoingMessage", "Y");
result.put("confirmation", "1");
result.put("bsrVerb", "PROCESS");
result.put("bsrNoun", "SHIPMENT");
result.put("bsrRevision", "001");
result.put("processingStatusId", orderStatusId);
result.put("orderId", orderId);
result.put("shipmentId", shipmentId);
result.put("userLogin", userLogin);
} catch (GenericServiceException e) {
String errMsg = "Error authorizing payment: " + e.toString();
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
}
}
return result;
if (checkPaymentAuth) {
GenericValue orderHeader = null;
GenericValue orderItemShipGroup = null;
try {
orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
GenericValue shipment =null;
if (orderHeader != null) {
String orderStatusId = orderHeader.getString("statusId");
if (orderStatusId.equals("ORDER_APPROVED")) {
try {
Map cospResult= dispatcher.runSync("createOrderShipmentPlan", UtilMisc.toMap("orderId", orderId, "userLogin", userLogin));
shipmentId = (String) cospResult.get("shipmentId");
} catch (GenericServiceException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
try {
shipment = delegator.findByPrimaryKey("Shipment", UtilMisc.toMap("shipmentId", shipmentId));
bodyParameters.put("shipment", shipment);
OrderReadHelper orderReadHelper = new OrderReadHelper(orderHeader);
if(orderReadHelper.hasShippingAddress()) {
GenericValue address = EntityUtil.getFirst(orderReadHelper.getShippingLocations());
bodyParameters.put("address", address);
}
String emailString = orderReadHelper.getOrderEmailString();
bodyParameters.put("emailString", emailString);
String contactMechId = shipment.getString("destinationTelecomNumberId");
GenericValue telecomNumber = delegator.findByPrimaryKey("TelecomNumber", UtilMisc.toMap("contactMechId", contactMechId));
bodyParameters.put("telecomNumber", telecomNumber);
List shipmentItems = delegator.findByAnd("ShipmentItem", UtilMisc.toMap("shipmentId", shipmentId));
bodyParameters.put("shipmentItems", shipmentItems);
orderItemShipGroup = EntityUtil.getFirst(delegator.findByAnd("OrderItemShipGroup", UtilMisc.toMap("orderId", orderId)));
bodyParameters.put("orderItemShipGroup", orderItemShipGroup);
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
Set correspondingPoIdSet = FastSet.newInstance();
try {
List orderItems = delegator.findByAnd("OrderItem", UtilMisc.toMap("orderId", shipment.getString("primaryOrderId")));
Iterator oiIter = orderItems.iterator();
while (oiIter.hasNext()) {
GenericValue orderItem = (GenericValue) oiIter.next();
String correspondingPoId = orderItem.getString("correspondingPoId");
if (correspondingPoId != null) {
correspondingPoIdSet.add(correspondingPoId);
}
}
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
bodyParameters.put("correspondingPoIdSet", correspondingPoIdSet);
Set externalIdSet = FastSet.newInstance();
try {
GenericValue primaryOrderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", shipment.getString("primaryOrderId")));
String externalId = primaryOrderHeader.getString("externalId");
if (externalId != null) {
externalIdSet.add(externalId);
}
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
bodyParameters.put("externalIdSet", externalIdSet);
// if order was a return replacement order (associated with return)
List returnItemResponses = null;
List returnItemRespExprs = UtilMisc.toList(new EntityExpr("replacementOrderId", EntityOperator.NOT_EQUAL, null));
EntityCondition returnItemRespCond = new EntityConditionList(returnItemRespExprs, EntityOperator.AND);
// list of fields to select (initial list)
List fieldsToSelect = FastList.newInstance();
fieldsToSelect.add("replacementOrderId");
try {
returnItemResponses = delegator.findByCondition("ReturnItemResponse", returnItemRespCond, fieldsToSelect, null);
Iterator rirIter = returnItemResponses.iterator();
while (rirIter.hasNext()) {
GenericValue returnItemResponse = (GenericValue) rirIter.next();
String replacementOrderId = returnItemResponse.getString("replacementOrderId");
if (replacementOrderId.equals(shipment.getString("primaryOrderId"))) {
bodyParameters.put("shipnotes", "RETURNLABEL");
// Get the associated return Id (replaceReturnId)
String returnItemResponseId = returnItemResponse.getString("returnItemResponseId");
GenericValue returnItem = EntityUtil.getFirst(delegator.findByAnd("ReturnItem", UtilMisc.toMap("returnItemResponseId", returnItemResponseId)));
bodyParameters.put("replacementReturnId", returnItem.getString("returnId"));
}
}
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
String logicalId = UtilProperties.getPropertyValue("oagis.properties", "CNTROLAREA.SENDER.LOGICALID");
bodyParameters.put("logicalId", logicalId);
comiCtx.put("logicalId", logicalId);
String authId = UtilProperties.getPropertyValue("oagis.properties", "CNTROLAREA.SENDER.AUTHID");
bodyParameters.put("authId", authId);
comiCtx.put("authId", authId);
String referenceId = delegator.getNextSeqId("OagisMessageInfo");
bodyParameters.put("referenceId", referenceId);
comiCtx.put("referenceId", referenceId);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'Z");
Timestamp timestamp = UtilDateTime.nowTimestamp();
String sentDate = dateFormat.format(timestamp);
bodyParameters.put("sentDate", sentDate);
comiCtx.put("sentDate", timestamp);
// tracking shipper account
String partyId = shipment.getString("partyIdTo");
List partyCarrierAccounts = new ArrayList();
try {
partyCarrierAccounts = delegator.findByAnd("PartyCarrierAccount", UtilMisc.toMap("partyId", partyId));
partyCarrierAccounts = EntityUtil.filterByDate(partyCarrierAccounts);
if (partyCarrierAccounts != null) {
Iterator pcaIter = partyCarrierAccounts.iterator();
while (pcaIter.hasNext()) {
GenericValue partyCarrierAccount = (GenericValue) pcaIter.next();
String carrierPartyId = partyCarrierAccount.getString("carrierPartyId");
if (carrierPartyId.equals(orderItemShipGroup.getString("carrierPartyId"))) {
String accountNumber = partyCarrierAccount.getString("accountNumber");
bodyParameters.put("shipperId", accountNumber);
}
}
}
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
bodyParameters.put("shipmentId", shipmentId);
bodyParameters.put("orderId", orderId);
bodyParameters.put("userLogin", userLogin);
String bodyScreenUri = UtilProperties.getPropertyValue("oagis.properties", "Oagis.Template.ProcessShipment");
Writer writer = null;
if (out != null) {
writer = new OutputStreamWriter(out);
} else if (UtilValidate.isNotEmpty(saveToFilename)) {
try {
File outdir = new File(saveToDirectory);
if (!outdir.exists()) {
outdir.mkdir();
}
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(outdir, saveToFilename)), "UTF-8")));
} catch (Exception e) {
String errMsg = "Error opening file to save message to [" + saveToFilename + "]: " + e.toString();
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
}
} else if (UtilValidate.isNotEmpty(sendToUrl)) {
writer = new StringWriter();
}
ScreenRenderer screens = new ScreenRenderer(writer, bodyParameters, new HtmlScreenRenderer());
try {
screens.render(bodyScreenUri);
writer.close();
} catch (Exception e) {
String errMsg = "Error rendering message: " + e.toString();
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
}
// TODO: call service with require-new-transaction=true to save the OagisMessageInfo data (to make sure it saves before)
// prepare map to Create Oagis Message Info
comiCtx.put("component", "INVENTORY");
comiCtx.put("task", "SHIPREQUES"); // Actual value of task is "SHIPREQUEST" which is more than 10 char
comiCtx.put("outgoingMessage", "Y");
comiCtx.put("confirmation", "1");
comiCtx.put("bsrVerb", "PROCESS");
comiCtx.put("bsrNoun", "SHIPMENT");
comiCtx.put("bsrRevision", "001");
comiCtx.put("processingStatusId", orderStatusId);
comiCtx.put("orderId", orderId);
comiCtx.put("shipmentId", shipmentId);
comiCtx.put("userLogin", userLogin);
try {
Map oagisMsgInfoResult = dispatcher.runSync("createOagisMessageInfo", comiCtx);
} catch (GenericServiceException e){
String errMsg = UtilProperties.getMessage(ServiceUtil.resource, "OagisErrorInCreatingDataForOagisMessageInfoEntity", locale);
Debug.logError(e, errMsg, module);
}
if (UtilValidate.isNotEmpty(sendToUrl)) {
HttpClient http = new HttpClient(sendToUrl);
// test parameters
http.setHostVerificationLevel(SSLUtil.HOSTCERT_NO_CHECK);
http.setAllowUntrusted(true);
http.setDebug(true);
// needed XML post parameters
if (UtilValidate.isNotEmpty(certAlias)) {
http.setClientCertificateAlias(certAlias);
}
if (UtilValidate.isNotEmpty(basicAuthUsername)) {
http.setBasicAuthInfo(basicAuthUsername, basicAuthPassword);
}
http.setContentType("text/xml");
http.setKeepAlive(true);
try {
String resp = http.post(writer.toString());
} catch (Exception e) {
String errMsg = "Error posting message to server with UTL [" + sendToUrl + "]: " + e.toString();
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
}
}
}
}
return result;
} else {
String errMsg = "Service failed:";
return ServiceUtil.returnError(errMsg);
}
}
public static Map oagisReceiveDelivery(DispatchContext dctx, Map context) {