/*
* SASuspendTransactionActionImpl
*
* 01/02/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.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;
/**
* SASuspendTransactionActionImpl is a class which the POSAutomationProvider
* uses to suspend the current transaction in the SA application.
*
*/
public class SASuspendTransactionActionImpl extends SAActionImpl
{
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 code:
*
AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR
*
AEFConst.INVALID_ARGUMENT, AEFConst.REASON_CODE_PROHIBITED
*/
public SASuspendTransactionActionImpl(ActionRequest request) throws AEFException
{
super(request);
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter SASuspendTransactionActionImpl.SASuspendTransactionActionImpl().");
log.trace(tempAEFMessage);
}
reasonCode = (String)(request.getArguments().get("reason"));
if (reasonCode.equals("") == false)
{
String tempString = "SASuspendTransactionActionImpl.constructor(): Suspend reason codes are not supported by this application.";
AEFException tempException = new AEFException(AEFConst.INVALID_ARGUMENT, AEFConst.REASON_CODE_PROHIBITED, tempString);
tempAEFMessage.setMessage(tempString);
log.error(tempAEFMessage, tempException);
throw tempException;
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit SASuspendTransactionActionImpl.SASuspendTransactionActionImpl().");
log.trace(tempAEFMessage);
}
}
/**
* Perform the suspend transaction action.
*
* @return Object That is Null.
* @exception AEFException
* AEFException error codes:
*
AEFConst.APPLICATION_NOT_IN_PROPER_STATE, AEFConst.NONE
*
AEFConst.PROCEDURE_NOT_ALLOWED, AEFConst.TRANSACTION_NOT_ACTIVE
*/
public Object performAction() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter SASuspendTransactionActionImpl.performAction().");
log.trace(tempAEFMessage);
}
super.performAction(); // Call super to perform any common processing and clear any errors before we start.
String currentState = null;
String currentSubState = null;
String displayLine1 = null;
String displayLine2 = null;
String autoMgrOverride = null;
try
{
if (getBooleanProviderProperty(WorkstationStatusProperties.CATEGORY, WorkstationStatusProperties.SALES_TRANSACTION_IN_PROGRESS))
{
initializeStates();
initializeSubStates();
currentState = getCurrentState();
if (currentState.equalsIgnoreCase(mainState))
{
sendsuspendSequence();
}
else
{
String tempString = "SASuspendTransactionActionImpl.performAction(): POS application not in proper state to suspend 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 = "SASuspendTransactionActionImpl.performAction(): Cannot suspend the transaction because no transaction is in progress.";
AEFException tempException = new AEFException(AEFConst.PROCEDURE_NOT_ALLOWED, AEFConst.TRANSACTION_NOT_ACTIVE, tempString);
tempAEFMessage.setMessage(tempString);
log.error(tempAEFMessage, tempException);
throw tempException;
}
}
catch (RemoteException e)
{
// Should never get here!
tempAEFMessage.setMessage("There was a remote exception thrown in SASuspendTransactionActionImpl.performAction().");
log.error(tempAEFMessage, e);
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit SASuspendTransactionActionImpl.performAction().");
log.trace(tempAEFMessage);
}
return null;
}
/**
* Send the suspend sequence to the terminal.
*
* @return int A negative number means there was an error.
* 0 means that we are in sub-state 1008.
* @exception AEFException
*/
public int sendsuspendSequence() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter SASuspendTransactionActionImpl.sendsuspendSequence().");
log.trace(tempAEFMessage);
}
int retVal = -1;
ConditionLock lock = null;
AEFAction keySequenceAction = null;
AEFErrorHandler errorHandler = null;
args.clear();
args.put("SEQUENCE_ID", "suspendTransaction");
keySequenceAction = (AEFAction)(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args)));
AbstractPropertyCondition[] goodConditions =
{
new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_SUB_STATE, mainSubState)
};
lock = new ConditionLock();
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"suspendTransaction",
">>>Sending suspend key sequence to application.");
}
retVal = lock.performActionAndWait("wait-for-suspend-transaction-complete",
keySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout());
if (retVal < 0)
{
errorHandler = new AEFErrorHandler("Send Suspend Sequence Error");
retVal = errorHandler.handleError(lock,
keySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout(),
retVal);
if (retVal < 0)
{
tempAEFMessage.setMessage("Send Suspend Sequence Error");
log.error(tempAEFMessage, errorHandler.getAllExceptions());
throw errorHandler.getAllExceptions();
}
}
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"suspendTransaction",
"<<