/*
* ACEActionImpl
*
* 07/01/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.AEF.factory.*;
import com.ibm.retail.AEF.thread.*;
import com.ibm.retail.AEF.data.*;
import com.ibm.retail.AEF.session.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.*;
import java.rmi.*;
/**
* ACEActionImpl is a class which the POSAutomationProvider uses to start a
* sales transaction on the POS application.
*
*/
public class ACEActionImpl extends AEFActionImpl
{
static String copyright()
{ return com.ibm.retail.si.Copyright.IBM_COPYRIGHT_SHORT; }
private static Log log = LogFactory.getLog(ACEActionImpl.class);
private static AEFPerfTrace perfTrace = AEFPerfTrace.getInstance();
/**
* Constructor
*
* @param request The ActionRequest.
* @exception com.ibm.retail.AEF.util.AEFException
* Among the possible AEFException error codes are:
*
AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR
*
Common Errors
*/
public ACEActionImpl(ActionRequest request) throws AEFException
{
super(request);
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter/-Exit constructor of AEFActionImpl.");
log.trace(tempAEFMessage);
}
}
/**
* Perform the action represented by the ActionRequest and return an object.
* It is up to the client to know the return type of the object. For general
* actions, the return type may be assumed to be ActionResult.
*
* This method is overridden to check if we are in a override state prior to performing
* the action. If so, we will attempt to clear the override state.
*
* @return Object The required return value (may be null).
* @exception AEFException
* Because of the nature of this method, just about any error code could be returned.
*/
public Object performAction() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter ACEActionImpl.performAction().");
log.trace(tempAEFMessage);
}
String overrideState = State.getState("OVERRIDE");
if (overrideState.equals(getCurrentState()))
{
// Send the clear and wait until we are no longer in override state.
sendClearSequence(false,false);
waitForStateChange(overrideState);
}
super.performAction();
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit ACEActionImpl.performAction().");
log.trace(tempAEFMessage);
}
return null;
}
/**
* Checks if the application is in special signoff, and attempts to do a special
* signon if the configuration option is set to do so.
*
*
* @exception com.ibm.retail.AEF.util.AEFException
* Among the possible AEFException error codes are:
*
Common Errors
*/
public void checkForSpecialSignon() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter ACEActionImpl.checkForSpecialSignon()");
log.trace(tempAEFMessage);
}
String securedState = State.getState("SECURED");
// If app is in secured state, and options are set to automatically do a special
// signon, then create the logon action to do the special signon first.
String autoSpecialSignon = null;
try
{
autoSpecialSignon = automationProvider.getProperty(ACEAutomationProperties.AUTO_SPECIAL_SIGNON);
}
catch (RemoteException re)
{
// Impossible to get here.
}
if (securedState.equals(getCurrentState()) &&
autoSpecialSignon != null && autoSpecialSignon.equalsIgnoreCase("true"))
{
// App is in special signoff, attempt to do the special signon.
if (log.isTraceEnabled())
{
log.trace(new AEFMessage(sessionID, "Automatically performing special signon."));
}
String id = null;
String password = null;
Operator operator = null;
try
{
operator = automationProvider.getOperator();
if (operator != null)
{
OperatorInfo info = operator.getInfo();
id = info.getID();
password = info.getPassword();
}
if (id != null && id.length() > 0 && password != null && password.length() > 0)
{
automationProvider.logon(id,password);
}
else
{
automationProvider.logon();
}
}
catch (RemoteException re)
{
// Impossible to get here.
}
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit ACEActionImpl.checkForSpecialSignon()");
log.trace(tempAEFMessage);
}
}
/**
* Sends a manager override sequence if the POSAutomationProvider is
* configured for automatic manager override.
*
* @return true if a manager override was performed.
* @exception com.ibm.retail.AEF.util.AEFException
* Among the possible AEFException error codes are:
*
Common Errors
*/
public boolean checkForAutomaticManagerOverride() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter ACEActionImpl.checkForAutomaticManagerOverride()");
log.trace(tempAEFMessage);
}
boolean retVal = false;
try
{
String autoMgrOverride = automationProvider.getProperty(POSAutomationProvider.AUTO_MGR_OVERRIDE);
if (log.isDebugEnabled())
{
log.debug(new AEFMessage(sessionID, "ACEActionImpl.checkForAutomaticManagerOverride(), flag = " + autoMgrOverride));
}
if (autoMgrOverride.equalsIgnoreCase("true"))
{
if (log.isTraceEnabled())
{
log.trace(new AEFMessage(sessionID, "Performing automatic mgr override."));
}
automationProvider.managerOverride();
retVal = true;
}
}
catch (RemoteException re)
{
// We will never get here because the call is local.
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit ACEActionImpl.checkForAutomaticManagerOverride()");
log.trace(tempAEFMessage);
}
return retVal;
}
/**
* Sends an operator override sequence if the POSAutomationProvider is
* configured for automatic operator override.
*
* @return true if an operator override was performed.
* @exception com.ibm.retail.AEF.util.AEFException
* Among the possible AEFException error codes are:
*
AEFConst.WAIT_INTERRUPTED
*
AEFConst.OPERATION_TIMEOUT
*
Common Errors
*/
public boolean checkForAutomaticOperatorOverride() throws AEFException
{
boolean retVal = false;
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter ACEActionImpl.checkForAutomaticOperatorOverride()");
log.trace(tempAEFMessage);
}
try
{
String autoOprOverride = automationProvider.getProperty(POSAutomationProvider.AUTO_OPR_OVERRIDE);
if (log.isDebugEnabled())
{
log.debug(new AEFMessage(sessionID, "ACEActionImpl.checkForAutomaticOperatorOverride(), flag = " + autoOprOverride));
}
if (autoOprOverride.equalsIgnoreCase("true"))
{
if (log.isTraceEnabled())
{
log.trace(new AEFMessage(sessionID, "Performing automatic operator override."));
}
automationProvider.operatorOverride("");
retVal = true;
}
}
catch (RemoteException re)
{
// We will never get here because the call is local.
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit ACEActionImpl.checkForAutomaticOperatorOverride()");
log.trace(tempAEFMessage);
}
return retVal;
}
/**
* Gets the current sub state.
*
*
* @return String The current application sub state.
*/
public String getCurrentSubstate()
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter ACEActionImpl.getCurrentSubstate().");
log.trace(tempAEFMessage);
}
String retVal = null;
try
{
retVal = (String)
(dataProvider.getPropertyValue(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_SUB_STATE));
}
catch (RemoteException re)
{
// Not expected to get here since we are calling locally.
}
if (log.isDebugEnabled())
{
tempAEFMessage.setMessage("getCurrentSubstate returned " + retVal + ".");
log.debug(tempAEFMessage);
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit ACEActionImpl.getCurrentSubstate().");
log.trace(tempAEFMessage);
}
return retVal;
}
/**
* WaitForSubStates for the application to go into specific sub-states.
*
* @param states An array of strings that contains the sub-states that we are interested in.
* @return int The index number of the sub-state (in the subStates array) that satisfied the wait.
* @exception com.ibm.retail.AEF.util.AEFException
* Among the possible AEFException error codes are:
*
AEFConst.WAIT_INTERRUPTED
*
AEFConst.OPERATION_TIMEOUT
*
Common Errors
*/
public int waitForSubStates(String[] subStates) throws AEFException
{
return waitForSubStates(subStates, getTimeout());
}
/**
* WaitForSubStates for the application to go into specific sub-states.
*
* @param states An array of strings that contains the sub-states that we are interested in.
* @param int The number of milliseconds to wait before a timeout exception is thrown. Use zero
* to wait indefinitely.
* @return int The index number of the sub-state (in the subStates array) that satisfied the wait.
* @exception com.ibm.retail.AEF.util.AEFException
* Among the possible AEFException error codes are:
*
AEFConst.WAIT_INTERRUPTED
*
AEFConst.OPERATION_TIMEOUT
*
Common Errors
*/
public int waitForSubStates(String[] subStates, int timeout) throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter ACEActionImpl.waitForSubstates().");
log.trace(tempAEFMessage);
}
int retVal = -1;
ConditionLock lock = null;
AbstractPropertyCondition[] conditions = new AbstractPropertyCondition[subStates.length];
for (int i = 0; i < subStates.length; i++)
{
conditions[i] = new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_SUB_STATE, subStates[i]);
}
lock = new ConditionLock();
if (log.isTraceEnabled())
{
log.trace( new AEFMessage( sessionID, "About to wait on the perform action for 'WaitForSubStates'")) ;
}
retVal = lock.wait("wait-for-states", conditions, timeout, true);
if (log.isDebugEnabled())
{
log.debug( new AEFMessage( sessionID, "WaitForSubStates return was " + retVal + ".")) ;
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit ACEActionImpl.waitForSubstates().");
log.trace(tempAEFMessage);
}
return retVal;
}
/* Instance Variables */
}