/* * ACESuspendTransactionActionImpl * * 07/23/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; /** * ACESuspendTransactionActionImpl is a class which the POSAutomationProvider * uses to suspend the current transaction on the ACE application. * */ public class ACESuspendTransactionActionImpl 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.INVALID_ARGUMENT, AEFConst.REASON_CODE_PROHIBITED */ public ACESuspendTransactionActionImpl(ActionRequest request) throws AEFException { super(request); if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter constructor of ACESuspendTransactionActionImpl."); log.trace(tempAEFMessage); } theReasonCode = (String)(request.getArguments().get("reason")); if (theReasonCode.equals("") == false) { String tempString = "ACESuspendTransactionActionImpl.constructor(): Suspend reason codes are not supported by this application."; AEFException tempException = new AEFException(AEFConst.INVALID_ARGUMENT, AEFConst.REASON_CODE_PROHIBITED, tempString); tempAEFMessage.setMessage(tempString); log.error(tempAEFMessage, tempException); throw tempException; } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit constructor of ACESuspendTransactionActionImpl."); log.trace(tempAEFMessage); } } /** * Perform the suspend transaction action. * * @return Object That is Null. * @exception AEFException * AEFException error codes: * <br>AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR * <br>AEFConst.APPLICATION_NOT_IN_PROPER_STATE, AEFConst.NONE * <br>AEFConst.PROCEDURE_NOT_ALLOWED, AEFConst.TRANSACTION_NOT_ACTIVE */ public Object performAction() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter ACESuspendTransactionActionImpl.performAction()"); log.trace(tempAEFMessage); } super.performAction(); // Call super to perform any common processing and clear any errors before we start. String currentState = null; String currentSubState = null; String displayLine1 = null; String displayLine2 = null; String autoMgrOverride = null; try { if (getBooleanProviderProperty(WorkstationStatusProperties.CATEGORY, WorkstationStatusProperties.SALES_TRANSACTION_IN_PROGRESS)) { initializeStates(); initializeSubStates(); currentState = getCurrentState(); if (currentState.equalsIgnoreCase(theMainState)) { sendsuspendSequence(); } else { String tempString = "ACESuspendTransactionActionImpl.performAction(): POS application not in proper state to suspend a transaction.\n 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; } } else { String tempString = "ACESuspendTransactionActionImpl.performAction(): Cannot suspend the transaction because no transaction is in progress."; AEFException tempException = new AEFException(AEFConst.PROCEDURE_NOT_ALLOWED, AEFConst.TRANSACTION_NOT_ACTIVE, tempString); tempAEFMessage.setMessage(tempString); log.error(tempAEFMessage, tempException); throw tempException; } } catch (RemoteException e) { // Should never get here! } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit ACESuspendTransactionActionImpl.performAction()"); log.trace(tempAEFMessage); } return null; } /** * Send the suspend sequence to the terminal. * * @return int A negative number means there was an error. * 0 means that we are in sub-state 1008. * @exception AEFException * AEFException error codes: * <br>AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR */ public int sendsuspendSequence() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter ACESuspendTransactionActionImpl.sendsuspendSequence()"); log.trace(tempAEFMessage); } int retVal = -1; ConditionLock lock = null; AEFAction keySequenceAction = null; AEFErrorHandler errorHandler = null; args.clear(); args.put("SEQUENCE_ID", "suspendTransaction"); keySequenceAction = (AEFAction)(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args))); AbstractPropertyCondition[] goodConditions = { new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_SUB_STATE, theMainSubState), new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_SUB_STATE, Substate.getSubstate("SELECT_PROCEDURE")) }; lock = new ConditionLock(); if (perfTrace.isEnabled(AEFPerfTrace. COARSE)) { perfTrace.reportTimer(AEFPerfTrace. COARSE, sessionID, "suspendTransaction", ">>>Sending suspend key sequence to application."); } retVal = lock.performActionAndWait("wait-for-suspend-transaction-complete", keySequenceAction, goodConditions, BadConditionsImpl.getInstance().getBadConditions(), getTimeout()); if (retVal < 0) { errorHandler = new AEFErrorHandler("Send Suspend Sequence 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, "suspendTransaction", "<<<Suspend key sequence processed by application."); } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit ACESuspendTransactionActionImpl.sendsuspendSequence()"); log.trace(tempAEFMessage); } return retVal; } /** * Initialize the sub-state variables for ACE. * * @result void */ private void initializeSubStates() { theMainSubState = Substate.getSubstate("EXPECTING_PROCEDURE"); } /** * Initialize the state variables for ACE. * * @result void */ private void initializeStates() { theMainState = State.getState("MAIN"); } /* Instance Variables */ protected String theReasonCode = null; protected String theMainState = null; protected String theMainSubState = null; private static Log log = LogFactory.getLog(ACESuspendTransactionActionImpl.class); }