/*
* SACancelOverrideActionImpl
*
* 07/29/2002
*
* 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;
/**
* SACancelOverrideActionImpl is a class which the POSAutomationProvider uses to cancel
* an override.
*
*/
public class SACancelOverrideActionImpl 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 SACancelOverrideActionImpl(ActionRequest request) throws AEFException
{
super(request);
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter and -Exit SACancelOverrideActionImpl.SACancelOverrideActionImpl().");
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 Operator instance.
* @exception AEFException
*/
public Object performAction() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter SACancelOverrideActionImpl.performAction().");
log.trace(tempAEFMessage);
}
super.performAction(); // Call super to perform any common processing and clear any errors before we start.
int seqResult = -1;
dataProvider = null;
try
{
if (dataProvider == null)
{
dataProvider = SessionContext.getSession().getPOSDataProvider();
}
}
catch (RemoteException re)
{
// Not expected to get here since we are calling locally.
tempAEFMessage.setMessage("There was a remote exception thrown in performAction of SACancelOverrideActionImpl.");
log.error(tempAEFMessage, re);
}
// Check the precondition that we are in the override state.
overrideState = State.getState("OVERRIDE");
clearState = State.getState("CLEAR");
// Check if the application is currently in the override state.
try
{
currentState =
((Integer)(dataProvider.getPropertyValue("POS_DEVICE", "POS_STATE"))).toString();
}
catch (RemoteException re)
{
// Not expected to get here since we are calling locally.
tempAEFMessage.setMessage("There was a remote exception thrown in performAction of SACancelOverrideActionImpl.");
log.error(tempAEFMessage, re);
}
// If so, clear the error.
if (currentState.equals(State.getState("CLEAR")))
{
sendClearSequence(true);
currentState = getCurrentState();
}
// Check if we are in a override state.
if (!currentState.equals(overrideState))
{
// Not in valid state for signon.
String tempString = "SALogonActionImpl.performAction(): POS application not in proper state to cancel manager's 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;
}
else
{
seqResult = sendCancelOverrideSequence();
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit SACancelOverrideActionImpl.performAction().");
log.trace(tempAEFMessage);
}
return null;
}
/**
* Sends the key sequence required to clear an override state (cancels the override).
*
* @return int Integer value representing the result of the key sequence.
* @exception AEFException
*/
public int sendCancelOverrideSequence() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter SACancelOverrideActionImpl.sendCancelOverrideSequence().");
log.trace(tempAEFMessage);
}
int retVal = -1;
args.clear();
args.put("SEQUENCE_ID", "cancelOverride");
keySequenceAction = (AEFAction)
(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args)));
Condition[] andConditions =
{
new PropertyNotEqualsCondition(POSDeviceProperties.CATEGORY,
POSDeviceProperties.POS_STATE,
overrideState),
new PropertyNotEqualsCondition(POSDeviceProperties.CATEGORY,
POSDeviceProperties.POS_STATE,
clearState),
};
Condition[] goodConditions =
{
new AndCondition(andConditions)
};
lock = new ConditionLock();
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"cancelOverride",
">>>Sending cancel override key sequence to application.");
}
retVal = lock.performActionAndWait("wait-for-mgr-override-cancel",
keySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout());
if (retVal < 0)
{
AEFErrorHandler errorHandler = new AEFErrorHandler("Send Cancel Override Sequence Error");
retVal = errorHandler.handleError(lock,
keySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout(),
retVal);
}
if (log.isDebugEnabled())
{
tempAEFMessage.setMessage("SACancelOverrideActionImpl.sendCancelOverrideSequence() - returning " + retVal);
log.debug(tempAEFMessage);
}
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"cancelOverride",
"<<