/* * GSASuspendTransactionActionImpl * * 06/11/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; /** * GSASuspendTransactionActionImpl is a class which the POSAutomationProvider * uses to suspend the current transaction in the GSA application. * */ public class GSASuspendTransactionActionImpl extends GSAActionImpl { static String copyright() { return com.ibm.retail.si.Copyright.IBM_COPYRIGHT_SHORT;} /** * 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 GSASuspendTransactionActionImpl(ActionRequest request) throws AEFException { super(request); if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter GSASuspendTransactionActionImpl.GSASuspendTransactionActionImpl()."); log.trace(tempAEFMessage); } try { // Validate the reason code or set it to 0 if none was passed in. reasonCode = (String)(request.getArguments().get("reason")); if (isReasonCodeValid() == false) { throw new AEFException(AEFConst.INVALID_ARGUMENT, AEFConst.REASON_CODE_PROHIBITED, "GSASuspendTransactionActionImpl.constructor(): Suspend reason code " + reasonCode + " is not supported by this application."); } } catch (AEFException e) { tempAEFMessage.setMessage("There was an AEF exception thrown in performAction of GSASuspendTransactionActionImpl."); log.error(tempAEFMessage, e); throw e; } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit GSASuspendTransactionActionImpl.GSASuspendTransactionActionImpl()."); log.trace(tempAEFMessage); } } /** * Perform the suspend transaction action. * * @return Object That is Null. * @exception AEFException * AEFException error codes: * <br>AEFConst.PROCEDURE_NOT_ALLOWED, AEFConst.TRANSACTION_NOT_ACTIVE */ public Object performAction() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter GSASuspendTransactionActionImpl.performAction()."); log.trace(tempAEFMessage); } super.performAction(); // Call super to perform any common processing and clear any errors before we start. try { if (log.isDebugEnabled()) { tempAEFMessage.setMessage("GSASuspendTransactionActionImpl.performAction Started."); log.debug(tempAEFMessage); } if (getBooleanProviderProperty(WorkstationStatusProperties.CATEGORY, WorkstationStatusProperties.SALES_TRANSACTION_IN_PROGRESS)) { sendsuspendSequence(); } else { throw new AEFException(AEFConst.PROCEDURE_NOT_ALLOWED, AEFConst.TRANSACTION_NOT_ACTIVE, "GSASuspendTransactionActionImpl.performAction(): Cannot suspend the transaction because no transaction is in progress."); } } catch (AEFException e) { tempAEFMessage.setMessage("There was an AEF exception thrown in performAction of GSASuspendTransactionActionImpl."); log.error(tempAEFMessage, e); throw e; } catch (RemoteException re) { // We should never get here because we are calling locally. tempAEFMessage.setMessage("There was a remote exception thrown in performAction of GSASuspendTransactionActionImpl."); log.error(tempAEFMessage, re); } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit GSASuspendTransactionActionImpl.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 a good state. * @exception AEFException * AEFException error codes: * <br>AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR */ public int sendsuspendSequence() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter GSASuspendTransactionActionImpl.sendsuspendSequence()."); log.trace(tempAEFMessage); } int retVal = -1; ConditionLock lock = new ConditionLock(); AEFAction keySequenceAction = null; AEFErrorHandler errorHandler = null; // Make Sure that we are in the ENTER_TENDER_AMOUNT state. If not send the total key. String currentState = getCurrentState(); if (currentState.equals(State.getState("ENTER_TENDER_AMOUNT")) == false) { args.clear(); args.put("SEQUENCE_ID", "total"); keySequenceAction = (AEFAction)(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args))); Condition[] goodConditions = { new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_STATE, State.getState("ENTER_TENDER_AMOUNT")) }; retVal = lock.performActionAndWait("wait-for-suspend-transaction-total", keySequenceAction, goodConditions, BadConditionsImpl.getInstance().getBadConditions(), getTimeout()); if (retVal < 0) { errorHandler = new AEFErrorHandler("Send Suspend Sequence (TOTAL) Error"); retVal = errorHandler.handleError(lock, keySequenceAction, goodConditions, BadConditionsImpl.getInstance().getBadConditions(), getTimeout(), retVal); if (retVal < 0) { tempAEFMessage.setMessage("An AEF exception was thrown in GSASuspendTransactionActionImpl.sendsuspendSequence()."); log.error(tempAEFMessage, errorHandler.getAllExceptions()); throw errorHandler.getAllExceptions(); } } } args.clear(); args.put("%0", reasonCode); args.put("SEQUENCE_ID", "suspendTransaction"); keySequenceAction = (AEFAction)(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args))); retVal = lock.performActionAndWait("wait-for-suspend-transaction-complete", keySequenceAction, GSANormalConditionsImpl.getInstance().getConditions(), BadConditionsImpl.getInstance().getBadConditions(), getTimeout()); if (retVal < 0) { errorHandler = new AEFErrorHandler("Send Suspend Sequence Error"); retVal = errorHandler.handleError(lock, keySequenceAction, GSANormalConditionsImpl.getInstance().getConditions(), BadConditionsImpl.getInstance().getBadConditions(), getTimeout(), retVal); if (retVal < 0) { tempAEFMessage.setMessage("An AEF exception was thrown in GSASuspendTransactionActionImpl.sendsuspendSequence()."); log.error(tempAEFMessage, errorHandler.getAllExceptions()); throw errorHandler.getAllExceptions(); } } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit GSASuspendTransactionActionImpl.sendsuspendSequence()."); log.trace(tempAEFMessage); } return retVal; } /** * Validates Reason Code. * * @return True if the reason code is valid. */ private boolean isReasonCodeValid() { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter GSASuspendTransactionActionImpl.isReasonCodeValid()."); log.trace(tempAEFMessage); } boolean retVal = true; if (reasonCode.equals("")) { reasonCode = "0"; } if (reasonCode.length() < 1) { retVal = false; } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit GSASuspendTransactionActionImpl.isReasonCodeValid()."); log.trace(tempAEFMessage); } return(retVal); } /* Instance and Class Variables */ protected String reasonCode = null; private static Log log = LogFactory.getLog(GSASuspendTransactionActionImpl.class); }