/*
* ACERetrieveTransactionActionImpl
*
* 09/02/2003
*
* Copyright:
* Licensed Materials - Property of IBM
* "Restricted Materials of IBM"
* 5724-AEF
* (C) Copyright IBM Corp. 2003.
*
* ace/com/ibm/retail/AEF/action/ACERetrieveTransactionActionImpl.java, aef.ace, aef.bravo 04/07/02
*/
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.thread.*;
import com.ibm.retail.AEF.data.*;
import java.util.*;
import java.rmi.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* ACERetrieveTransactionActionImpl is a class which the POSAutomationProvider
* uses to retrieve a transaction in ACE.
*
*/
public class ACERetrieveTransactionActionImpl 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
* AEFException error codes:
*
AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR
* AEFConst.PROCEDURE_NOT_ALLOWED, AEFConst.NO_SUCH_SUSPENDED_TRANSACTION
*
*/
public ACERetrieveTransactionActionImpl(ActionRequest request) throws AEFException
{
super(request);
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter constructor of ACERetrieveTransactionActionImpl.");
log.trace(tempAEFMessage);
}
String temp = null;
theTerminalNum = (String)(request.getArguments().get("terminal"));
theTransactionNum = (String)(request.getArguments().get("transaction"));
if (theTerminalNum == null ||
theTerminalNum.length() == 0 ||
theTransactionNum == null ||
theTransactionNum.length() == 0)
{
String tempString = "ACERetrieveTransactionActionImpl.constructor(): Transaction " + theTransactionNum + " for terminal " + theTerminalNum + " is not valid.";
AEFException tempException = new AEFException(AEFConst.PROCEDURE_NOT_ALLOWED,
AEFConst.NO_SUCH_SUSPENDED_TRANSACTION,
tempString);
tempAEFMessage.setMessage(tempString);
log.error(tempAEFMessage, tempException);
throw tempException;
}
// Initialize the state and sub-state variables.
initializeStates();
initializeSubStates();
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit constructor of ACERetrieveTransactionActionImpl.");
log.trace(tempAEFMessage);
}
}
/**
* Perform the retrieve transaction action.
*
* @return Object That is Null.
* @exception AEFException
* AEFException error codes:
*
AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR
*
AEFConst.APPLICATION_NOT_IN_PROPER_STATE, AEFConst.NONE
*
AEFConst.PROCEDURE_NOT_ALLOWED, AEFConst.TRANSACTION_ALREADY_IN_PROGRESS
*/
public Object performAction() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter ACERetrieveTransactionActionImpl.performAction()");
log.trace(tempAEFMessage);
}
super.performAction();
String currentState = null;
String currentSubState = null;
try
{
if (getBooleanProviderProperty(WorkstationStatusProperties.CATEGORY,
WorkstationStatusProperties.SALES_TRANSACTION_IN_PROGRESS) ==
false)
{
currentState = getCurrentState();
if (currentState.equalsIgnoreCase(theMainState))
{
sendRetriveSequence();
}
else
{
String tempString = "ACERetrieveTransactionActionImpl.performAction(): POS application not in proper state to retrieve a transaction.\n Application is in state " + currentState + ".";
AEFException tempException = new AEFException(AEFConst.APPLICATION_NOT_IN_PROPER_STATE,
0,
tempString);
tempAEFMessage.setMessage(tempString);
log.error(tempAEFMessage, tempException);
throw tempException;
}
}
else
{
String tempString = "ACERetrieveTransactionActionImpl.performAction(): Cannot retrieve the transaction because another transaction is in progress.";
AEFException tempException = new AEFException(AEFConst.PROCEDURE_NOT_ALLOWED,
AEFConst.TRANSACTION_ALREADY_IN_PROGRESS,
tempString);
tempAEFMessage.setMessage(tempString);
log.error(tempAEFMessage, tempException);
throw tempException;
}
}
catch (RemoteException e)
{
// Should never get here!
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit ACERetrieveTransactionActionImpl.performAction()");
log.trace(tempAEFMessage);
}
return null;
}
/**
* Send the retrieve sequence to the terminal.
*
* @return int 0 means that we are in sub-state 1002.
* @exception AEFException
* AEFException error codes:
*
AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR
*/
public int sendRetriveSequence() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter ACERetrieveTransactionActionImpl.sendRetriveSequence()");
log.trace(tempAEFMessage);
}
int retVal = -1;
ConditionLock lock = null;
AEFAction keySequenceAction = null;
AEFErrorHandler errorHandler = null;
args.clear();
args.put("%0", theTerminalNum);
args.put("%1", theTransactionNum);
args.put("SEQUENCE_ID", "retrieveTransaction");
keySequenceAction = (AEFAction)(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args)));
AbstractPropertyCondition[] goodConditions =
{
new PropertyEqualsCondition(POSDeviceProperties.CATEGORY,
POSDeviceProperties.POS_SUB_STATE,
theExpectingTenderSubState),
};
lock = new ConditionLock();
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"retrieveTransaction",
">>>Sending retrieve key sequence to application.");
}
retVal = lock.performActionAndWait("wait-for-retrieve-transaction-complete",
keySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout());
if (retVal < 0)
{
errorHandler = new AEFErrorHandler("Send Retrieve Sequence Error");
retVal = errorHandler.handleError(lock,
keySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout(),
retVal);
if (retVal < 0)
{
throw errorHandler.getAllExceptions();
}
}
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"retrieveTransaction",
"<<