/* * ACELogoffActionImpl * * 07/17/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.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; /** * ACELogoffActionImpl is a class which the POSAutomationProvider uses * to logoff the ACE application. * */ public class ACELogoffActionImpl extends ACEActionImpl { static String copyright() { return com.ibm.retail.si.Copyright.IBM_COPYRIGHT_SHORT; } private static Log log = LogFactory.getLog(ACELogoffActionImpl.class); private static AEFPerfTrace perfTrace = AEFPerfTrace.getInstance(); /** * Constructor * * @param request The ActionRequest which contains a HashMap of arguments. * * @exception AEFException */ public ACELogoffActionImpl(ActionRequest request) throws AEFException { super(request); if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter/-Exit constructor of ACELogoffActionImpl."); 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 * Among the possible error codes are: * <br>AEFConst.PROCEDURE_NOT_ALLOWED, AEFConst.TRANSACTION_IN_PROGRESS * <br><a href="../commonerrorcodes.html">Common Errors</a> */ public Object performAction() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter ACELogoffActionImpl.performAction()"); log.trace(tempAEFMessage); } // Call super to perform any common processing and clear any errors before we start. super.performAction(); Object retVal = null; // If ACE is in secured state and options are set to automatically do a special // signon, then do a special signon first. checkForSpecialSignon(); int seqResult = -1; // Check that no transaction is in progress and that POS_STATE is // "MAIN" state (10). If not, throw exception. String currentState = "0"; currentState = getCurrentState(); theIdState = State.getState("ID"); theMainState = State.getState("MAIN"); theRepeatSignoffSubstate = Substate.getSubstate("REPEAT_SIGNOFF"); try { Transaction trans = automationProvider.getTransaction(); if (trans != null) { // We have a transaction in progress. The client must void the transaction // before logging off. String tempString = "ACELogoffActionImpl.performAction(): Unable to logoff because a transaction is in progress."; AEFException tempException = new AEFException(AEFConst.PROCEDURE_NOT_ALLOWED, AEFConst.TRANSACTION_IN_PROGRESS, tempString); tempAEFMessage.setMessage(tempString); log.error(tempAEFMessage, tempException); throw tempException; } } catch (RemoteException re) { // We should never get here because we are calling locally. } if (!currentState.equals(theMainState)) { // Can only logoff from the MAIN state. String tempString = "ACELogoffActionImpl.performAction(): POS application not in proper state to perform logoff.\n Expected state " + theMainState + ", but application is in state " + currentState + "."; 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 { // Application is in correct state to start performing the logoff. seqResult = sendLogoffSequence(); if (seqResult==0) { // Successfully got to id state. if (perfTrace.isEnabled(AEFPerfTrace. COARSE)) { perfTrace.reportTimer(AEFPerfTrace. COARSE, sessionID, "logoff", "<<<Detected logoff from application."); } return retVal; } } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit ACELogoffActionImpl.performAction()"); log.trace(tempAEFMessage); } return retVal; } /** * Send the key sequence required for a logoff. * * * @return int An integer representing the result of the key sequence. * @exception AEFException * Among the possible error codes are: * <br>AEFConst.APPLICATION_NOT_IN_PROPER_SUBSTATE */ public int sendLogoffSequence() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter ACELogoffActionImpl.sendLogoffSequence()"); log.trace(tempAEFMessage); } int retVal = -1; theLock = new ConditionLock(); // Send the first part of the logoff sequence and check for errors. args.clear(); args.put("SEQUENCE_ID", "logoff1"); theKeySequenceAction = (AEFAction) (actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args))); Condition[] goodConditions1 = { new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_SUB_STATE, theRepeatSignoffSubstate), new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_STATE, theIdState) }; retVal = theLock.performActionAndWait("wait-for-id-state", theKeySequenceAction, goodConditions1, BadConditionsImpl.getInstance().getBadConditions(), getTimeout()); if (retVal < 0) { AEFErrorHandler errorHandler = new AEFErrorHandler("Send Logoff Sequence Error Part 1"); retVal = errorHandler.handleError(theLock, theKeySequenceAction, goodConditions1, BadConditionsImpl.getInstance().getBadConditions(), getTimeout(), retVal); } if (retVal >= 0) // The last command completed and any errors were handled. { if (getCurrentState().equalsIgnoreCase(theIdState) == false) // We are not in the desired state. { String substateNow = getCurrentSubstate(); if (substateNow.equalsIgnoreCase(theRepeatSignoffSubstate)) // Send the second part of the signoff sequence. { args.clear(); args.put("SEQUENCE_ID", "logoff2"); theKeySequenceAction = (AEFAction)(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args))); Condition[] goodConditions2 = { new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_STATE, theIdState) }; if (perfTrace.isEnabled(AEFPerfTrace. COARSE)) { perfTrace.reportTimer(AEFPerfTrace. COARSE, sessionID, "logoff", ">>>Sending logoff key sequence to application."); } retVal = theLock.performActionAndWait("wait-for-id-state", theKeySequenceAction, goodConditions2, BadConditionsImpl.getInstance().getBadConditions(), getTimeout()); if (retVal < 0) { AEFErrorHandler errorHandler = new AEFErrorHandler("Send Logoff Sequence Error Part 2"); retVal = errorHandler.handleError(theLock, theKeySequenceAction, goodConditions2, BadConditionsImpl.getInstance().getBadConditions(), getTimeout(), retVal); } } else // We are not where we think we should be. { // Not in valid state for applyDelayedCoupons. String tempString = "ACELogoffActionImpl.sendLogoffSequence(): POS application not in proper substate to perform logoff.\n Expected substate " + theRepeatSignoffSubstate + ", but application is in substate " + substateNow + "."; 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; } } } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit ACELogoffActionImpl.sendLogoffSequence()"); log.trace(tempAEFMessage); } return retVal; } /* Instance Variables */ protected AEFAction theKeySequenceAction = null; protected ConditionLock theLock = null; protected String theIdState = null; protected String theMainState = null; protected String theRepeatSignoffSubstate = null; }