/* * GSARetrieveTransactionActionImpl * * 06/25/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; /** * GSARetrieveTransactionActionImpl is a class which the POSAutomationProvider * uses to retrieve a transaction in the GSA application. * */ public class GSARetrieveTransactionActionImpl extends GSAActionImpl { /** * Constructor * * @param request The ActionRequest which contains a HashMap of arguments. * @exception AEFException * AEFException error codes: * <br>AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR * <brAEFConst.PROCEDURE_NOT_ALLOWED, AEFConst.NO_SUCH_SUSPENDED_TRANSACTION */ public GSARetrieveTransactionActionImpl(ActionRequest request) throws AEFException { super(request); if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter GSARetrieveTransactionActionImpl.GSARetrieveTransactionActionImpl()."); log.trace(tempAEFMessage); } String temp = null; try { terminal = (String)(request.getArguments().get("terminal")); transaction = (String)(request.getArguments().get("transaction")); if (terminal == null || terminal.length() == 0 || transaction == null || transaction.length() == 0) { throw new AEFException(AEFConst.PROCEDURE_NOT_ALLOWED, AEFConst.NO_SUCH_SUSPENDED_TRANSACTION, "GSARetrieveTransactionActionImpl.constructor(): Transaction " + transaction + " for terminal " + terminal + " is not valid."); } } catch (AEFException e) { tempAEFMessage.setMessage("There was an AEF exception thrown in the constructor of GSARetrieveTransactionActionImpl."); log.error(tempAEFMessage, e); throw e; } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit GSARetrieveTransactionActionImpl.GSARetrieveTransactionActionImpl()."); log.trace(tempAEFMessage); } } /** * Perform the retrieve 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_ALREADY_IN_PROGRESS */ public Object performAction() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter GSARetrieveTransactionActionImpl.performAction()."); log.trace(tempAEFMessage); } super.performAction(); // Call super to perform any common processing and clear any errors before we start. String currentState = null; try { if (getBooleanProviderProperty(WorkstationStatusProperties.CATEGORY, WorkstationStatusProperties.SALES_TRANSACTION_IN_PROGRESS) == false) { currentState = getCurrentState(); if (currentState.equalsIgnoreCase(State.getState("TRANSACTION_SELECT"))) { sendRetriveSequence(); } else { throw new AEFException(AEFConst.APPLICATION_NOT_IN_PROPER_STATE, 0, "GSARetrieveTransactionActionImpl.performAction(): POS application not in proper state to retrieve a transaction.\n Application is in state " + currentState + " and should be in state " + State.getState("TRANSACTION_SELECT") + "."); } } else { throw new AEFException(AEFConst.PROCEDURE_NOT_ALLOWED, AEFConst.TRANSACTION_ALREADY_IN_PROGRESS, "GSARetrieveTransactionActionImpl.performAction(): Cannot retrieve the transaction because another transaction is in progress."); } } catch (AEFException e) { tempAEFMessage.setMessage("There was an AEF exception thrown in performAction of GSARetrieveTransactionActionImpl."); log.error(tempAEFMessage, e); throw e; } catch (RemoteException re) { // Should never get here! tempAEFMessage.setMessage("There was a remote exception thrown in performAction of GSARetrieveTransactionActionImpl."); log.error(tempAEFMessage, re); } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit GSARetrieveTransactionActionImpl.performAction()."); log.trace(tempAEFMessage); } return null; } /** * Send the retrieve sequence to the terminal. * * @return int >= 0 means that we are in a good state. * @exception AEFException * AEFException error codes: * <br>AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR */ public int sendRetriveSequence() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter GSARetrieveTransactionActionImpl.sendRetriveSequence()."); log.trace(tempAEFMessage); } int retVal = -1; ConditionLock lock = null; AEFAction keySequenceAction = null; AEFErrorHandler errorHandler = null; args.clear(); args.put("%0", transaction); args.put("%1", terminal); args.put("SEQUENCE_ID", "retrieveTransaction"); keySequenceAction = (AEFAction)(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args))); Condition[] goodConditions = { new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_STATE, State.getState("ITEMENTRY")) }; lock = new ConditionLock(); retVal = lock.performActionAndWait("wait-for-retrieve-transaction-complete",keySequenceAction, goodConditions, BadConditionsImpl.getInstance().getBadConditions(), getTimeout()); if (retVal < 0) { errorHandler = new AEFErrorHandler("Send Retrieve Sequence Error"); retVal = errorHandler.handleError(lock, keySequenceAction, goodConditions, BadConditionsImpl.getInstance().getBadConditions(), getTimeout(), retVal); if (retVal < 0) { tempAEFMessage.setMessage("An AEF exception was thrown in GSARetrieveTransactionActionImpl.sendRetriveSequence()."); log.error(tempAEFMessage, errorHandler.getAllExceptions()); throw errorHandler.getAllExceptions(); } } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit GSARetrieveTransactionActionImpl.sendRetriveSequence()."); log.trace(tempAEFMessage); } return retVal; } /* Instance and Class Variables */ protected String terminal = null; protected String transaction = null; private static Log log = LogFactory.getLog(GSARetrieveTransactionActionImpl.class); }