/*
* SAManagerOverrideActionImpl
*
* 12/11/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.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;
/**
* SAManagerOverrideActionImpl is a class which the POSAutomationProvider
* uses to accomplish a manager's override onto the SA application.
*
*/
public class SAManagerOverrideActionImpl 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 codes:
*
AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR
*
AEFConst.CONFIG_ERROR, AEFConst.NO_DEFAULT_MANAGER_OVERRIDE_PASSWORD
*/
public SAManagerOverrideActionImpl(ActionRequest request) throws AEFException
{
super(request);
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter SAManagerOverrideActionImpl.SAManagerOverrideActionImpl().");
log.trace(tempAEFMessage);
}
password = (String)(request.getArguments().get("password"));
if (password == null || password.length() == 0)
{
try
{
password = automationProvider.getProperty(POSAutomationProvider.MGR_OVERRIDE_NUMBER);
}
catch (RemoteException re)
{
// Not expected to get here since we are calling locally.
tempAEFMessage.setMessage("There was a remote exception thrown in SAManagerOverrideActionImpl.SAManagerOverrideActionImpl().");
log.error(tempAEFMessage, re);
}
if (password == null || password.length() == 0)
{
// Error, unable to lookup default password for manager override.
String tempString = "SAManagerOverrideActionImpl: Default manager override password not configured.\n Unable to perform the Manager Override function.";
AEFException tempException = new AEFException(AEFConst.CONFIG_ERROR, AEFConst.NO_DEFAULT_MANAGER_OVERRIDE_PASSWORD, tempString);
tempAEFMessage.setMessage(tempString);
log.error(tempAEFMessage, tempException);
throw tempException;
}
}
// Get the values for the Override and Clear states.
overrideState = State.getState("OVERRIDE");
clearState = State.getState("CLEAR");
enterState = State.getState("ENTER");
overrideSubState = Substate.getSubstate("EXPECTING_MANAGER_OVERRIDE");
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit SAManagerOverrideActionImpl.SAManagerOverrideActionImpl().");
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 That is Null.
* @exception AEFException
* AEFException error codes:
*
AEFConst.APPLICATION_NOT_IN_PROPER_STATE, AEFConst.NONE
*
AEFConst.APPLICATION_NOT_IN_PROPER_STATE, AEFConst.APPLICATION_NOT_IN_PROPER_SUBSTATE
*/
public Object performAction() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter SAManagerOverrideActionImpl.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))
{
sendOverrideSequence();
}
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 SAManagerOverrideActionImpl.performAction().");
log.trace(tempAEFMessage);
}
return null;
}
/**
* Send the override sequence to the terminal and wait to get out of the
* override state without any errors.
*
* @return int 0 means that we are not in the Override state, Enter state or Clear state.
* Any negative number means that there was an error.
* @exception AEFException
* AEFException error codes:
*
AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR
*/
public int sendOverrideSequence() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter SAManagerOverrideActionImpl.sendOverrideSequence().");
log.trace(tempAEFMessage);
}
int retVal = -1;
AEFAction keySequenceAction = null;
AEFErrorHandler errorHandler = null;
args.clear();
args.put("%0", password);
args.put("SEQUENCE_ID", "managerOverride");
keySequenceAction = (AEFAction)(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args)));
Condition conditions1[] =
{
new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_STATE, clearState),
new PropertyNotEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_SUB_STATE, Substate.getSubstate("INVALID_KEY_SEQUENCE")),
new PropertyNotEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_SUB_STATE, Substate.getSubstate("KEYED_DATA_OUT_OF_RANGE")),
new PropertyNotEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_SUB_STATE, Substate.getSubstate("CHECK_OVERRIDE_NUMBER")), // B059
};
Condition conditions2[] =
{
new PropertyNotEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_STATE, clearState),
new PropertyNotEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_STATE, overrideState),
new PropertyNotEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_STATE, enterState)
};
// Condition1 or Condition2 may be true to have a successful manager override.
Condition goodConditions[] =
{
new AndCondition(conditions1),
new AndCondition(conditions2),
};
ConditionLock lock = new ConditionLock();
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"managerOverride",
">>>Sending manager override key sequence to application.");
}
retVal = lock.performActionAndWait("wait-for-manager_override-complete",
keySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getExtendedBadConditions(),
getTimeout());
if (retVal < 0)
{
errorHandler = new AEFErrorHandler("There was an error in SAManagerOverrideActionImpl.sendOverrideSequence()");
retVal = errorHandler.handleError(lock,
keySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getExtendedBadConditions(),
getTimeout(),
retVal);
if (retVal < 0)
{
tempAEFMessage.setMessage("There was an error in SAManagerOverrideActionImpl.sendOverrideSequence()");
log.error(tempAEFMessage, errorHandler.getAllExceptions());
throw errorHandler.getAllExceptions();
}
}
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"managerOverride",
"<<