/* * GSACancelPreviousEntryActionImpl * * 07/22/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 org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * GSACancelPreviousEntryActionImpl is a class which the POSAutomationProvider uses to * cancel the previous entry added to a transaction on the POS application. * */ public class GSACancelPreviousEntryActionImpl 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 com.ibm.retail.AEF.util.AEFException * Among the possible AEFException error codes are: * <br>AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR * <br><a href="../commonerrorcodes.html">Common Errors</a> */ public GSACancelPreviousEntryActionImpl(ActionRequest request) throws AEFException { super(request); if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter and -Exit GSACancelPreviousEntryActionImpl.GSACancelPreviousEntryActionImpl()."); log.trace(tempAEFMessage); } } /** * Perform the action represented by the ActionRequest and return an ActionResult. * * @return Object The Item instance. * @exception com.ibm.retail.AEF.util.AEFException * Among the possible AEFException error codes are: * <br>AEFConst.APPLICATION_NOT_IN_PROPER_STATE * <br>AEFConst.OPERATION_TIMEOUT * <br>AEFConst.TRANSACTION_CANNOT_BE_VOIDED * <br>AEFConst.WAIT_INTERRUPTED * <br><a href="../commonerrorcodes.html">Common Errors</a> */ public Object performAction() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter GSACancelPreviousEntryActionImpl.performAction()."); log.trace(tempAEFMessage); } super.performAction(); // Call super to perform any common processing and clear any errors before we start. Object retVal = null; try { //Check to make sure that GSA is in a state that is valid for canceling the last item entry. String currentState = getCurrentState(); if (currentState.equals(State.getState("ITEMENTRY")) || currentState.equals(State.getState("ENTER_TENDER_AMOUNT"))) { sendCancelPreviousEntrySequence(); retVal = waitForItem(); } else { // Not in valid state to cancel the last item entry. throw new AEFException(AEFConst.APPLICATION_NOT_IN_PROPER_STATE, 0, "GSACancelPreviousEntryActionImpl.performAction(): POS application not in the proper state to cancel the last item entry.\n Application is in state " + currentState + "."); } } catch (AEFException e) { tempAEFMessage.setMessage("There was an AEF exception thrown in performAction of GSACancelPrevoiusEntryActionImpl."); log.error(tempAEFMessage, e); throw e; } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit GSACancelPreviousEntryActionImpl.performAction()."); log.trace(tempAEFMessage); } return retVal; } /** * Sends the key sequence which will cancel the previous entry. * * * @exception com.ibm.retail.AEF.util.AEFException * Among the possible AEFException error codes are: * <br>AEFConst.APPLICATION_NOT_IN_PROPER_STATE * <br>AEFConst.OPERATION_TIMEOUT * <br>AEFConst.WAIT_INTERRUPTED</li> * <br><a href="../commonerrorcodes.html">Common Errors</a> */ public void sendCancelPreviousEntrySequence() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter GSACancelPreviousEntryActionImpl.sendCancelPreviousEntrySequence()."); log.trace(tempAEFMessage); } int retVal = -1; args.clear(); args.put("SEQUENCE_ID", "cancelPrevious"); theKeySequenceAction = (AEFAction)(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args))); Condition[] goodConditions = { new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_STATE, State.getState("ITEMENTRY")) }; // Save any current item instance number so we are sure to only get an item created after this key sequence is sent. detector = ((DetectorAccess)(SessionContext.getSession())).getLineItemDetector(); instanceNumber = detector.getInstanceNumber(); // Send the key sequence to GSA. lock = new ConditionLock(); retVal = lock.performActionAndWait("wait-after-cancel-previous-send", theKeySequenceAction, goodConditions, BadConditionsImpl.getInstance().getBadConditions(), getTimeout()); if (retVal < 0) { AEFErrorHandler errorHandler = new AEFErrorHandler("Send Cancel Previous Sequence Error"); retVal = errorHandler.handleError(lock, theKeySequenceAction, goodConditions, BadConditionsImpl.getInstance().getBadConditions(), getTimeout(), retVal); } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit GSACancelPreviousEntryActionImpl.sendCancelPreviousEntrySequence()."); log.trace(tempAEFMessage); } } /** * Waits for the item object after the item is sold. * * @return ArrayList An array of LineItems created by the action. * @exception com.ibm.retail.AEF.util.AEFException * Among the possible AEFException error codes are: * <br>AEFConst.APPLICATION_NOT_RESPONDING * <br>AEFConst.APPLICATION_NOT_IN_PROPER_STATE * <br>AEFConst.OPERATION_TIMEOUT * <br>AEFConst.TRANSACTION_CANNOT_BE_VOIDED * <br>AEFConst.WAIT_INTERRUPTED * <br><a href="../commonerrorcodes.html">Common Errors</a> */ public ArrayList waitForItem() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Enter GSACancelPreviousEntryActionImpl.waitForItem()."); log.trace(tempAEFMessage); } ArrayList retVal = null; // Successfully got to item entry. Wait for the array of LineItems to be created. // TODO: Need to use a new type of ObjectDetectorLock that checks for error conditions. This code does not handle the void of an item not in the order correctly A003. ObjectDetectorLock objLock = new ObjectDetectorLock(); retVal = (ArrayList)(objLock.waitForNewObject("wait-for-item-array",detector, instanceNumber, getTimeout())); if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit GSACancelPreviousEntryActionImpl.waitForItem()."); log.trace(tempAEFMessage); } return retVal; } // Instance Variables and Class Variables protected AEFAction theKeySequenceAction; protected ConditionLock lock; protected ObjectDetector detector; protected int instanceNumber; private static Log log = LogFactory.getLog(GSACancelPreviousEntryActionImpl.class); }