/*
* ACESetTrainingModeOnActionImpl
*
* 09/02/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.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;
/**
* ACESetTrainingModeOnActionImpl is a class which the POSAutomationProvider
* uses to start a training mode transaction and put the terminal into training mode.
*
*/
public class ACESetTrainingModeOnActionImpl extends ACEActionImpl
{
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
*/
public ACESetTrainingModeOnActionImpl(ActionRequest request) throws AEFException
{
super(request);
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter constructor of ACESetTrainingModeOnActionImpl.");
log.trace(tempAEFMessage);
}
theMainState = State.getState("MAIN");
theMainSubState = Substate.getSubstate("EXPECTING_PROCEDURE");
theSelectProcedureSubState = Substate.getSubstate("SELECT_PROCEDURE");
theTrainingSubState = Substate.getSubstate("ITEM_TRAINING");
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit constructor of ACESetTrainingModeOnActionImpl.");
log.trace(tempAEFMessage);
}
}
/**
* Puts the terminal into training mode.
*
* @return Object That is Null.
* @exception AEFException
* AEFException error codes:
*
AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR
*
AEFConst.APPLICATION_NOT_IN_PROPER_STATE
*/
public Object performAction() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter ACESetTrainingModeOnActionImpl.performAction()");
log.trace(tempAEFMessage);
}
// Call super to perform any common processing and clear any errors before we start.
super.performAction();
// Make sure that we are not in the Terminal Secured state.
checkForSpecialSignon();
// Continue with the training mode action.
String currentState = getCurrentState();
String currentSubState = getCurrentSubstate();
if (currentState.equalsIgnoreCase(theMainState) &&
(currentSubState.equalsIgnoreCase(theMainSubState) ||
currentSubState.equalsIgnoreCase(theSelectProcedureSubState)) )
{
sendTrainingOnSequence();
}
else
{
String tempString = "ACESetTrainingModeOnActionImpl.performAction(): POS application not in proper state to go into training mode.\n Application is in state " + currentState + " substate " + currentSubState + ". It should be in state " + theMainState + " substate " + theMainSubState + ".";
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 ACESetTrainingModeOnActionImpl.performAction()");
log.trace(tempAEFMessage);
}
return null;
}
/**
* Send the training mode on sequence to the terminal.
*
* @return int A negative number means there was an error.
* 0 means that we are in sub-state 11045.
* @exception AEFException
* AEFException error codes:
*
AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR
*/
public int sendTrainingOnSequence() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter ACESetTrainingModeOnActionImpl.sendTrainingOnSequence()");
log.trace(tempAEFMessage);
}
int retVal = -1;
ConditionLock lock = null;
AEFAction keySequenceAction = null;
AEFErrorHandler errorHandler = null;
args.clear();
args.put("SEQUENCE_ID", "trainingModeOn");
keySequenceAction = (AEFAction)(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args)));
AbstractPropertyCondition[] goodConditions =
{
new PropertyEqualsCondition(POSDeviceProperties.CATEGORY,
POSDeviceProperties.POS_SUB_STATE,
theTrainingSubState)
};
lock = new ConditionLock();
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"setTrainingMode",
">>>Sending training mode key sequence to application.");
}
retVal = lock.performActionAndWait("wait-for-training-mode",
keySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout());
if (retVal < 0)
{
errorHandler = new AEFErrorHandler("Set Training Mode On Error");
retVal = errorHandler.handleError(lock,
keySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout(),
retVal);
if (retVal < 0)
{
throw errorHandler.getAllExceptions();
}
}
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"setTrainingMode",
"<<