/*
* GSAVoidTransactionActionImpl
*
* 06/26/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;
/**
* GSAVoidTransactionActionImpl is a class which the POSAutomationProvider uses to accomplish
* voiding the current transaction.
*
*/
public class GSAVoidTransactionActionImpl extends GSAActionImpl
{
static String copyright()
{ return com.ibm.retail.si.Copyright.IBM_COPYRIGHT_SHORT; }
/**
* Constructor
*
* @param request The ActionRequest which contains a HashMap of arguments.
* @exception AEFException
* AEFException error codes:
*
AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR
*/
public GSAVoidTransactionActionImpl(ActionRequest request) throws AEFException
{
super(request);
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter GSAVoidTransactionActionImpl.GSAVoidTransactionActionImpl().");
log.trace(tempAEFMessage);
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit GSAVoidTransactionActionImpl.GSAVoidTransactionActionImpl().");
log.trace(tempAEFMessage);
}
}
/**
* Tries to void the current transaction and return the application to the SELECT_PROCEDURE state
* or Default transaction type as defined in the configuration files.
*
* @return Object N/A (null).
* @exception AEFException
* AEFException error codes:
*
AEFConst.PROCEDURE_NOT_ALLOWED, AEFConst.TRANSACTION_NOT_ACTIVE
*/
public Object performAction() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter GSAVoidTransactionActionImpl.performAction().");
log.trace(tempAEFMessage);
}
super.performAction(); // Call super to perform any common processing and clear any errors before we start.
boolean salesTranInProgress = false;
boolean nonSalesTranInProgress = false;
Transaction trans = null;
ObjectDetector detector = null;
try
{
// Check for a "partial" transaction which was started, but no items have been sold.
trans = automationProvider.getTransaction();
if (trans != null)
{
if (trans.getTransactionInfo().getTransactionID() == null)
{
// Clear the partial transaction object.
trans.setIsActive(false);
detector = ((DetectorAccess)(SessionContext.getSession())).getTransactionDetector();
detector.reset();
automationProvider.setTransaction(null);
return null;
}
}
// Check the precondition that we are in the middle of a transaction.
salesTranInProgress = getBooleanProviderProperty(WorkstationStatusProperties.CATEGORY, WorkstationStatusProperties.SALES_TRANSACTION_IN_PROGRESS);
nonSalesTranInProgress = getBooleanProviderProperty(WorkstationStatusProperties.CATEGORY, WorkstationStatusProperties.NONSALES_TRANSACTION_IN_PROGRESS);
if (!salesTranInProgress && !nonSalesTranInProgress)
{
// Not in the middle of the transaction.
throw new AEFException(AEFConst.PROCEDURE_NOT_ALLOWED,
AEFConst.TRANSACTION_NOT_ACTIVE,
"GSAVoidTransactionActionImpl.performAction(): Cannot void a transaction because no transaction is in progress.");
}
// Send the Void sequence.
sendVoidSequence();
}
catch (AEFException e)
{
tempAEFMessage.setMessage("There was an AEF exception thrown in performAction of GSAVoidTransactionActionImpl.");
log.error(tempAEFMessage, e);
throw e;
}
catch (RemoteException re)
{
// Not expected to get here since we are calling locally.
tempAEFMessage.setMessage("There was a remote exception thrown in performAction of GSAVoidTransactionActionImpl.");
log.error(tempAEFMessage, re);
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit GSAVoidTransactionActionImpl.performAction().");
log.trace(tempAEFMessage);
}
return null;
}
/**
* Sends the key sequence required to void the transaction when in ITEMENTRY state.
*
*
* @return int An integer index representing the result of the key sequence.
* @exception AEFException
* AEFException error codes:
*
AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR
*/
public int sendVoidSequence() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter GSAVoidTransactionActionImpl.sendVoidSequence().");
log.trace(tempAEFMessage);
}
int retVal = -1;
AEFErrorHandler errorHandler = null;
args.clear();
args.put("SEQUENCE_ID", "voidTransaction");
keySequenceAction = (AEFAction)(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args)));
lock = new ConditionLock();
retVal = lock.performActionAndWait("wait-for-void-transaction", keySequenceAction, GSANormalConditionsImpl.getInstance().getConditions(), BadConditionsImpl.getInstance().getBadConditions(), getTimeout());
if (log.isDebugEnabled())
{
tempAEFMessage.setMessage("GSAVoidTransactionActionImp.sendVoidSequence: Return Value = " + retVal + " State = " + getCurrentState() + ".");
log.debug(tempAEFMessage);
}
if (retVal < 0)
{
errorHandler = new AEFErrorHandler("Send Void Sequence Error");
retVal = errorHandler.handleError(lock, keySequenceAction, GSANormalConditionsImpl.getInstance().getConditions(), BadConditionsImpl.getInstance().getBadConditions(), getTimeout(), retVal);
if (retVal < 0)
{
tempAEFMessage.setMessage("An AEF exception was thrown in GSAVoidTransactionActionImpl.sendVoidSequence().");
log.error(tempAEFMessage, errorHandler.getAllExceptions());
throw errorHandler.getAllExceptions();
}
}
// Check to make sure that AEF knows that the transaction has been voided.
Condition[] tmpGoodConditions =
{
new PropertyNotEqualsCondition(WorkstationStatusProperties.CATEGORY, WorkstationStatusProperties.SALES_TRANSACTION_IN_PROGRESS, "true"),
new PropertyNotEqualsCondition(WorkstationStatusProperties.CATEGORY, WorkstationStatusProperties.NONSALES_TRANSACTION_IN_PROGRESS, "true")
};
Condition conditions[] =
{
new AndCondition(tmpGoodConditions)
};
lock.wait("wait-for-states", conditions, getTimeout(), true);
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit GSAVoidTransactionActionImpl.sendVoidSequence().");
log.trace(tempAEFMessage);
}
return retVal;
}
// Instance and Class Variables
protected AEFAction keySequenceAction = null;
protected ConditionLock lock = null;
private static Log log = LogFactory.getLog(GSAVoidTransactionActionImpl.class);
}