/* * ACEManagerOverrideActionImpl * * 08/21/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; /** * ACEManagerOverrideActionImpl is used to perform an automatic manager override on ACE. * */ public class ACEManagerOverrideActionImpl 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: * <br>AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR * <br>AEFConst.CONFIG_ERROR, AEFConst.NO_DEFAULT_MANAGER_OVERRIDE_PASSWORD */ public ACEManagerOverrideActionImpl(ActionRequest request) throws AEFException { super(request); if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter ACEManagerOverrideActionImpl.ACEManagerOverrideActionImpl()."); log.trace(tempAEFMessage); } thePassword = (String)(request.getArguments().get("password")); if (thePassword == null || thePassword.length() == 0) { try { thePassword = automationProvider.getProperty(POSAutomationProvider.MGR_OVERRIDE_NUMBER); } catch (RemoteException re) { // Not expected to get here since we are calling locally. } if (thePassword == null || thePassword.length() == 0) { // Error, unable to lookup default password for manager override. String tempString = "ACEManagerOverrideActionImpl: 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 states and substates. theOverrideState = State.getState("OVERRIDE"); theClearState = State.getState("CLEAR"); theEnterState = State.getState("ENTER"); theOverrideSubState = Substate.getSubstate("EXPECTING_MANAGER_OVERRIDE"); if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit ACEManagerOverrideActionImpl.ACEManagerOverrideActionImpl()."); 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: * <br>AEFConst.APPLICATION_NOT_IN_PROPER_STATE, AEFConst.NONE * <br>AEFConst.APPLICATION_NOT_IN_PROPER_STATE, AEFConst.APPLICATION_NOT_IN_PROPER_SUBSTATE */ public Object performAction() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter ACEManagerOverrideActionImpl.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(theOverrideState)) { // 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(theOverrideSubState)) { sendOverrideSequence(); } else { String tempString = "ACEManagerOverrideActionImpl.performAction(): POS application not in proper substate to perform override.\n Expected substate " + theOverrideSubState + ", 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 = "ACEManagerOverrideActionImpl.performAction(): POS application not in proper state to perform override.\n Expected state " + theOverrideState + ", 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 ACEManagerOverrideActionImpl.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: * <br>AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR */ public int sendOverrideSequence() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter ACEManagerOverrideActionImpl.sendOverrideSequence()."); log.trace(tempAEFMessage); } int retVal = -1; AEFAction keySequenceAction = null; AEFErrorHandler errorHandler = null; args.clear(); args.put("%0", thePassword); args.put("SEQUENCE_ID", "managerOverride"); keySequenceAction = (AEFAction)(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args))); Condition conditions1[] = { new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_STATE, theClearState), 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")), }; Condition conditions2[] = { new PropertyNotEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_STATE, theClearState), new PropertyNotEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_STATE, theOverrideState), new PropertyNotEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_STATE, theEnterState) }; 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 ACEManagerOverrideActionImpl.sendOverrideSequence()"); retVal = errorHandler.handleError(lock, keySequenceAction, goodConditions, BadConditionsImpl.getInstance().getExtendedBadConditions(), getTimeout(), retVal); if (retVal < 0) { throw errorHandler.getAllExceptions(); } } if (perfTrace.isEnabled(AEFPerfTrace. COARSE)) { perfTrace.reportTimer(AEFPerfTrace. COARSE, sessionID, "managerOverride", "<<<Manager override key sequence processed by application."); } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit ACEManagerOverrideActionImpl.sendOverrideSequence()."); log.trace(tempAEFMessage); } return retVal; } /* Instance Variables */ protected String thePassword = null; protected String theOverrideState = null; protected String theClearState = null; protected String theEnterState = null; protected String theOverrideSubState = null; private static Log log = LogFactory.getLog(ACEManagerOverrideActionImpl.class); }