/*
* SAOperatorOverrideActionImpl
*
* 01/07/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;
/**
* SAOperatorOverrideActionImpl is a class which the POSAutomationProvider uses to accomplish
* an operator override in a transaction on the POS application.
*
*/
public class SAOperatorOverrideActionImpl 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.
*
*/
public SAOperatorOverrideActionImpl(ActionRequest request) throws AEFException
{
super(request);
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter SAOperatorOverrideActionImpl.SAOperatorOverrideActionImpl().");
log.trace(tempAEFMessage);
}
overrideState = State.getState("OVERRIDE");
overrideSubState = Substate.getSubstate("EXPECTING_OPERATOR_OVERRIDE");
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit SAOperatorOverrideActionImpl.SAOperatorOverrideActionImpl().");
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 Null object
* @exception AEFException
* AEFException error codes:
*
AEFConst.APPLICATION_NOT_IN_PROPER_STATE, AEFConst.APPLICATION_NOT_IN_PROPER_SUBSTATE
*
AEFConst.APPLICATION_NOT_IN_PROPER_STATE, AEFConst.NONE
*/
public Object performAction() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter SAOperatorOverrideActionImpl.performAction().");
log.trace(tempAEFMessage);
}
// Don't call super (to avoid being cleared out of override state) - just check for proper state and substate
String currentState = getCurrentState();
String currentSubState = null;
if (currentState.equals(overrideState))
{
// Wait for either the manager override substate, or the operator override substate.
String[] states = {Substate.getSubstate("EXPECTING_OPERATOR_OVERRIDE"),
Substate.getSubstate("EXPECTING_MANAGER_OVERRIDE")};
try
{
waitForSubStates(states);
}
catch (AEFException aefe)
{
// Ignore the timeout at this point, because we'll handle an invalid substate
// error below.
}
currentSubState = getCurrentSubstate();
if (currentSubState.equals(overrideSubState))
{
sendOperatorOverrideSequence();
}
else
{
String tempString = "SAManagerOverrideActionImpl.performAction(): POS application not in proper substate to perform override.\n Expected substate " + overrideSubState + ", but application is in state " + currentSubState + ".";
AEFException tempException = new AEFException(AEFConst.APPLICATION_NOT_IN_PROPER_STATE, AEFConst.APPLICATION_NOT_IN_PROPER_SUBSTATE, tempString);
tempAEFMessage.setMessage(tempString);
log.error(tempAEFMessage, tempException);
throw tempException;
}
}
else
{
String tempString = "SAManagerOverrideActionImpl.performAction(): POS application not in proper state to perform override.\n Expected state " + overrideState + ", but 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;
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit SAOperatorOverrideActionImpl.performAction().");
log.trace(tempAEFMessage);
}
return null;
}
/**
* Sends the key sequence which will cause the operator override to be entered.
*
*
* @return int An integer value representing the result of the key sequence.
* @exception AEFException
*/
public int sendOperatorOverrideSequence() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter SAOperatorOverrideActionImpl.sendOperatorOverrideSequence().");
log.trace(tempAEFMessage);
}
int retVal = -1;
args.clear();
args.put("SEQUENCE_ID", "operatorOverride");
theKeySequenceAction = (AEFAction)
(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args)));
Condition[] goodConditions =
{
new PropertyNotEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_SUB_STATE, Substate.getSubstate("EXPECTING_OPERATOR_OVERRIDE")),
// 0 Success, we are no longer in EXPECTING_OPERATOR_OVERRIDE state
};
theLock = new ConditionLock();
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"operatorOverride",
">>>Sending operator override key sequence to application.");
}
retVal = theLock.performActionAndWait("wait-for-operator-override-complete",
theKeySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout());
if (retVal < 0)
{
AEFErrorHandler errorHandler = new AEFErrorHandler("Send Operator Override Sequence Error");
retVal = errorHandler.handleError(theLock,
theKeySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout(),
retVal);
}
if (log.isDebugEnabled())
{
tempAEFMessage.setMessage(" Condition returned was " + retVal);
log.debug(tempAEFMessage);
}
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"operatorOverride",
"<<