/* * ACECancelPreviousEntryActionImpl * * 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 java.rmi.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * ACECancelPreviousEntryActionImpl is a class which the POSAutomationProvider uses to * cancel the previous entry added to a transaction on the ACE application. * */ public class ACECancelPreviousEntryActionImpl extends ACEActionImpl { 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 */ public ACECancelPreviousEntryActionImpl(ActionRequest request) throws AEFException { super(request); if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter constructor of ACECancelPreviousEntryActionImpl."); log.trace(tempAEFMessage); } // theValidSubstates contains a list of all the substates for which // a previous entry may be canceled. This is a class static, so it is only // initialized once. if (theValidSubstates == null) { theValidSubstates = new Vector(); theValidSubstates.addElement(Substate.getSubstate("EXPECTING_ITEM")); } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit constructor of ACECancelPreviousEntryActionImpl."); 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 Item instance. * @exception AEFException * Among the possible error codes are: * <br>AEFConst.APPLICATION_NOT_IN_PROPER_STATE, AEFConst.APPLICATION_NOT_IN_PROPER_SUBSTATE */ public Object performAction() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter ACECancelPreviousEntryActionImpl.performAction()"); log.trace(tempAEFMessage); } super.performAction(); // Call super to perform any common processing and clear any errors before we start. Object retVal = null; int seqResult = -1; // Check that ACE is in one of the substates which is valid for // cancel previous entry. If not, then throw an exception. String currentSubstate = getCurrentSubstate(); if (theValidSubstates.contains(currentSubstate)) { // Application is in correct substate to cancel the previous entry. seqResult = sendCancelPreviousEntrySequence(); if (seqResult==0) { // We get a voided item(s) from this command. retVal = waitForItem(); } } // end of if (theValidSubstates.contains(currentSubstate)) else { // Not in valid state for cancel previous. String tempString = "ACECancelPreviousEntryActionImpl.performAction(): POS application not in proper substate to perform cancel previous entry.\n Application substate is " + currentSubstate + "."; 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 ACECancelPreviousEntryActionImpl.performAction()"); log.trace(tempAEFMessage); } return retVal; } /** * Sends the key sequence which will cancel the previous entry. * * * @return int An integer value representing the result of the key sequence. * @exception AEFException */ public int sendCancelPreviousEntrySequence() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter ACECancelPreviousEntryActionImpl.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_SUB_STATE, Substate.getSubstate("EXPECTING_ITEM")), // 0 = Success }; theLock = new ConditionLock(); theDetector = ((DetectorAccess)(SessionContext.getSession())).getLineItemDetector(); // Save any current line item instance number so we are sure to only get a line item // created after this key sequence is sent. theInstanceNumber = theDetector.getInstanceNumber(); retVal = theLock.performActionAndWait("wait-for-expecting-item-substate", theKeySequenceAction, goodConditions, BadConditionsImpl.getInstance().getBadConditions(), getTimeout()); if (retVal < 0) { AEFErrorHandler errorHandler = new AEFErrorHandler("Send Cancel Previous Entry Sequence Error"); retVal = errorHandler.handleError(theLock, theKeySequenceAction, goodConditions, BadConditionsImpl.getInstance().getBadConditions(), getTimeout(), retVal); } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit ACECancelPreviousEntryActionImpl.sendCancelPreviousEntrySequence()"); log.trace(tempAEFMessage); } return retVal; } /** * Sends the key sequence which will cause the previous entry to be canceled. * * * @return ArrayList An array of LineItems created by the action. * @exception AEFException */ public ArrayList waitForItem() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter ACECancelPreviousEntryActionImpl.waitForItem()"); log.trace(tempAEFMessage); } ArrayList retVal = null; // Successfully got to item entry. Wait for the array of LineItems to be created. ObjectDetectorLock objLock = new ObjectDetectorLock(); retVal = (ArrayList)(objLock.waitForNewObject("wait-for-item-array", theDetector, theInstanceNumber, getTimeout())); if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit ACECancelPreviousEntryActionImpl.waitForItem()"); log.trace(tempAEFMessage); } return retVal; } /* Instance Variables */ protected AEFAction theKeySequenceAction; protected ConditionLock theLock; protected ObjectDetector theDetector; protected int theInstanceNumber; protected static Vector theValidSubstates; private static Log log = LogFactory.getLog(ACECancelPreviousEntryActionImpl.class); }