/*
* ACEItemReturnActionImpl
*
* 07/23/2003
*
* Copyright:
* Licensed Materials - Property of IBM
* "Restricted Materials of IBM"
* 5724-AEF
* (C) Copyright IBM Corp. 2003.
*
* %W% %E%
*/
package com.ibm.retail.AEF.action;
import com.ibm.retail.AEF.automation.*;
import com.ibm.retail.AEF.util.*;
import com.ibm.retail.si.util.*;
import com.ibm.retail.si.Copyright;
import com.ibm.retail.AEF.factory.*;
import com.ibm.retail.AEF.thread.*;
import com.ibm.retail.AEF.data.*;
import com.ibm.retail.AEF.session.*;
import java.util.*;
import java.rmi.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* ACEItemReturnActionImpl is a class which the POSAutomationProvider uses to return
* an item in a transaction on the ACE application.
*
*/
public class ACEItemReturnActionImpl extends ACEActionImpl
{
static String copyright()
{ return com.ibm.retail.si.Copyright.IBM_COPYRIGHT_SHORT; }
private static AEFPerfTrace perfTrace = AEFPerfTrace.getInstance();
/**
* Constructor
*
* @param request The ActionRequest which contains a HashMap of arguments.
* @exception AEFException
*/
public ACEItemReturnActionImpl(ActionRequest request) throws AEFException
{
super(request);
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter constructor of ACEItemReturnActionImpl.");
log.trace(tempAEFMessage);
}
// validSubstates contains a list of all the substates for which
// an item may be returned. This is a class static, so it is only
// initialized once.
if (theValidSubstates == null)
{
theValidSubstates = new Vector();
theValidSubstates.addElement(Substate.getSubstate("SELECT_PROCEDURE"));
theValidSubstates.addElement(Substate.getSubstate("EXPECTING_ITEM"));
theValidSubstates.addElement(Substate.getSubstate("EXPECTING_TENDER"));
theValidSubstates.addElement(Substate.getSubstate("CHANGE_OR_BAL_DUE"));
theValidSubstates.addElement(Substate.getSubstate("TRAINING_MODE"));
}
theItemID = (ItemIdentifier)(request.getArguments().get("id"));
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit constructor of ACEItemReturnActionImpl.");
log.trace(tempAEFMessage);
}
}
/**
* Perform the action represented by the ActionRequest and return an ActionResult.
*
*
* @param request The ActionRequest which contains the classname and arguments.
* @return Object The Item instance.
* @exception AEFException
* Among the possible AEFException error codes are:
*
AEFConst.INVALID_ARGUMENT, AEFConst.WEIGHT_AND_QUANTITY_MUTUALLY_EXCLUSIVE
*
Common Errors
*/
public Object performAction() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter ACEItemReturnActionImpl.performAction()");
log.trace(tempAEFMessage);
}
Object retVal = null;
// If ACE is in secured state, and options are set to automatically do a special
// signon, then do a special signon first.
checkForSpecialSignon();
int seqResult = -1;
theDetector = ((DetectorAccess)(SessionContext.getSession())).getLineItemDetector();
//Check that ACE is in one of the substates which is valid for item return.
//If not, throw exception.
String currentSubstate = getCurrentSubstate();
if (theValidSubstates.contains(currentSubstate))
{
// Application is in correct substate to RETURN the item.
// Validate input, cannot have qty and weight in same sequence
String aQty = theItemID.getQuantity();
String aWeight = theItemID.getWeight();
if (aWeight != null && aWeight.length() != 0)
{
if (aQty != null && aQty.length() != 0)
{
// input bad, only password provided
String tempString = "ACEItemReturnActionImpl.performAction(): Cannot have both a keyed weight and a keyed quantity.\n";
AEFException tempException = new AEFException(AEFConst.INVALID_ARGUMENT,
AEFConst.WEIGHT_AND_QUANTITY_MUTUALLY_EXCLUSIVE,
tempString);
tempAEFMessage.setMessage(tempString);
log.error(tempAEFMessage, tempException);
throw tempException;
}
}
seqResult = sendItemReturnSequence();
if (seqResult>=0)
{
retVal = waitForItem();
}
}
else
{
// Not in valid state for item return.
String tempString = "ACEItemReturnActionImpl.performAction(): POS application not in proper substate to perform item return.\n Application substate is " + currentSubstate + ".";
AEFException tempException = new AEFException(AEFConst.APPLICATION_NOT_IN_PROPER_STATE,
0,
tempString);
tempAEFMessage.setMessage(tempString);
log.error(tempAEFMessage, tempException);
throw tempException;
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit ACEItemReturnActionImpl.performAction()");
log.trace(tempAEFMessage);
}
return retVal;
}
/**
* Sends the key sequence which will cause the item to be returned.
*
*
* @return int An integer value representing the result of the key sequence.
* @exception AEFException
*/
public int sendItemReturnSequence() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter ACEItemReturnActionImpl.sendItemReturnSequence()");
log.trace(tempAEFMessage);
}
String itemCodeType = theItemID.getItemCodeType();
int retVal = -1;
args.clear();
// Select key sequence:
// Example: (overridePrice) PRICE (quantity) QUANTITY (item) ENTER
// (overridePrice) PRICE (weight) WEIGHT (item) ENTER
String aPrice = theItemID.getPrice();
String aQty = theItemID.getQuantity();
String aWeight = theItemID.getWeight();
args.put("%0", theItemID.getItemCode());
if (aPrice != null && aPrice.length() != 0)
{
args.put("%1", aPrice);
if (aWeight != null && aWeight.length() != 0)
{
args.put("%2", aWeight);
args.put("SEQUENCE_ID", "itemReturnPriceWeight");
}
else if (aQty != null && aQty.length() != 0)
{
args.put("%2", aQty);
args.put("SEQUENCE_ID", "itemReturnPriceQty");
}
else
{
args.put("SEQUENCE_ID", "itemReturnPrice");
}
}
else if (aQty != null && aQty.length() != 0)
{
args.put("%1", aQty);
args.put("SEQUENCE_ID", "itemReturnQty");
}
else if (aWeight != null && aWeight.length() != 0)
{
args.put("%1", aWeight);
args.put("SEQUENCE_ID", "itemReturnWeight");
}
else
{
args.put("SEQUENCE_ID", "itemReturn");
}
theKeySequenceAction = (AEFAction)
(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args)));
Condition[] goodConditions =
{
new PropertyEqualsCondition(POSDeviceProperties.CATEGORY,
POSDeviceProperties.POS_SUB_STATE,
Substate.getSubstate("EXPECTING_ITEM")), // 0 = Success
};
theLock = new ConditionLock();
// Save any current item instance number so we are sure to only get an item
// created after this key sequence is sent.
theInstanceNumber = theDetector.getInstanceNumber();
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"returnItem",
">>>Sending item return key sequence to application.");
}
retVal = theLock.performActionAndWait("wait-for-expecting-item-substate",
theKeySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout());
if (retVal < 0)
{
AEFErrorHandler errorHandler = new AEFErrorHandler("Send Item Return Sequence Error");
retVal = errorHandler.handleError(theLock,
theKeySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout(),
retVal);
}
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"returnItem",
"<<