/* * SAItemEntryActionImpl * * 11/04/2002 * * 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; /** * SAItemEntryActionImpl is a class which the POSAutomationProvider uses to add * an item entry to a transaction on the POS application. * */ public class SAItemEntryActionImpl extends SAActionImpl { 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. * */ public SAItemEntryActionImpl(ActionRequest request) throws AEFException { super(request); if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter SAItemEntryActionImpl.SAItemEntryActionImpl()."); log.trace(tempAEFMessage); } // validSubstates contains a list of all the substates for which // an item may be entered. This is a class static, so it is only // initialized once. if (validSubstates == null) { validSubstates = new Vector(); validSubstates.addElement(Substate.getSubstate("SELECT_PROCEDURE")); validSubstates.addElement(Substate.getSubstate("EXPECTING_ITEM")); validSubstates.addElement(Substate.getSubstate("TRANS_TOTALLED")); validSubstates.addElement(Substate.getSubstate("CHANGE_OR_BAL_DUE")); validSubstates.addElement(Substate.getSubstate("TRAINING_MODE")); } itemID = (ItemIdentifier)(request.getArguments()); qty = itemID.getQuantity(); price = itemID.getPrice(); weight = itemID.getWeight(); dealPrice = itemID.getDealPrice(); dealQuantity = itemID.getDealQuantity(); if (price != null) { // Remove any non-digits from the price. price = price.replaceAll("\\D",""); } if (weight != null) { // Remove any non-digits from the weight. weight = weight.replaceAll("\\D",""); } if (dealPrice != null) { // Remove any non-digits from the deal price. dealPrice = dealPrice.replaceAll("\\D",""); } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit SAItemEntryActionImpl.SAItemEntryActionImpl()."); 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 AEFException error codes are: * <br><a href="../commonerrorcodes.html">Common Errors</a> */ public Object performAction() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+EnterSAItemEntryActionImpl.performAction()."); log.trace(tempAEFMessage); } super.performAction(); // Call super to perform any common processing and clear any errors before we start. Object retVal = null; if (log.isDebugEnabled()) { tempAEFMessage.setMessage("SAItemEntryActionImpl.performAction() qty = " + qty + " price =" + price + " weight =" + weight + " dealPrice = " + dealPrice + " dealQuantity = " + dealQuantity); log.debug(tempAEFMessage); } // If app is in secured state, and options are set to automatically do a special // signon, then create the logon action to do the special signon first. checkForSpecialSignon(); int seqResult = -1; detector = ((DetectorAccess)(SessionContext.getSession())).getLineItemDetector(); //Check precondition that app is in one of the substates which is valid for item entry. //If not, throw exception. String currentSubstate = getCurrentSubstate(); if (validSubstates.contains(currentSubstate)) { // Application is in correct substate to add the item. seqResult = sendItemEntrySequence(); if (seqResult==0) { retVal = waitForItem(); } } else { // Not in valid state for item entry. String tempString = "SAItemEntryActionImpl.performAction(): POS application not in proper substate to perform item entry.\n Application substate is " + currentSubstate + "."; AEFException tempException = new AEFException(AEFConst.APPLICATION_NOT_IN_PROPER_STATE, 0, tempString); tempAEFMessage.setMessage(tempString); log.trace(tempAEFMessage, tempException); throw tempException; } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit SAItemEntryActionImpl.performAction()."); log.trace(tempAEFMessage); } return retVal; } /** * Sends the key sequence which will cause the item to be sold. * * * @return int An integer value representing the result of the key sequence. * @exception AEFException */ public int sendItemEntrySequence() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter SAItemEntryActionImpl.sendItemEntrySequence()."); log.trace(tempAEFMessage); } String itemCodeType = itemID.getItemCodeType(); int retVal = -1; args.clear(); StringBuffer sequenceIdBuf = new StringBuffer(); if (price != null) { sequenceIdBuf.append("itemPrice+"); args.put("%itemPrice.0", price); } else if (dealPrice != null) { sequenceIdBuf.append("itemDealPrice+"); args.put("%itemDealPrice.0", dealQuantity); args.put("%itemDealPrice.1", dealPrice); } if (qty != null) { sequenceIdBuf.append("itemQty+"); args.put("%itemQty.0", qty); } else if (weight != null) { sequenceIdBuf.append("itemWeight+"); args.put("%itemWeight.0", weight); } if (log.isDebugEnabled()) { tempAEFMessage.setMessage("SAItemEntryActionImpl.sendItemEntrySequence itemCode = ." + itemID.getItemCode() + "."); log.debug(tempAEFMessage); } if (itemCodeType != null && (itemCodeType.equals(AEFConst.SCAN_LABEL) || itemCodeType.equals(AEFConst.KEYED_LABEL))) { sequenceIdBuf.append("itemScanned"); args.put("%itemScanned.0", itemID.getItemCode()); args.put("SEQUENCE_ID", new String(sequenceIdBuf)); if (log.isDebugEnabled()) { tempAEFMessage.setMessage("SAItemEntryActionImpl.sendItemEntrySequence - keyed or scanned barcode "); log.debug(tempAEFMessage); } } else { sequenceIdBuf.append("item"); args.put("%item.0", itemID.getItemCode()); args.put("SEQUENCE_ID", new String(sequenceIdBuf)); } theKeySequenceAction = (AEFAction) (actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args))); Condition[] goodConditions = { new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_SUB_STATE, Substate.getSubstate("EXPECTING_ITEM")), // 0 = Success }; lock = new ConditionLock(); // Save any current item instance number so we are sure to only get an item // created after this key sequence is sent. instanceNumber = detector.getInstanceNumber(); if (perfTrace.isEnabled(AEFPerfTrace. COARSE)) { perfTrace.reportTimer(AEFPerfTrace. COARSE, sessionID, "addItem", ">>>Sending addItem key sequence to application."); } retVal = lock.performActionAndWait("wait-for-expecting-item-substate", theKeySequenceAction, goodConditions, BadConditionsImpl.getInstance().getBadConditions(), getTimeout()); if (retVal < 0) { AEFErrorHandler errorHandler = new AEFErrorHandler("Send Item Entry Sequence Error"); retVal = errorHandler.handleError(lock, theKeySequenceAction, goodConditions, BadConditionsImpl.getInstance().getBadConditions(), getTimeout(), retVal); } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit SAItemEntryActionImpl.sendItemEntrySequence()."); log.trace(tempAEFMessage); } return retVal; } /** * Sends the key sequence which will cause the item to be sold. * * * @return ArrayList An array of LineItems created by the action. * @exception AEFException */ public ArrayList waitForItem() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter SAItemEntryActionImpl.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",detector, instanceNumber, getTimeout())); if (perfTrace.isEnabled(AEFPerfTrace. COARSE)) { perfTrace.reportTimer(AEFPerfTrace. COARSE, sessionID, "addItem", "<<<Detected item from application."); } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit SAItemEntryActionImpl.waitForItem()."); log.trace(tempAEFMessage); } return retVal; } /* Instance Variables */ protected AEFAction theKeySequenceAction; protected ItemIdentifier itemID; protected String qty = null; protected String price = null; protected String weight = null; protected String dealPrice = null; protected String dealQuantity = null; protected ConditionLock lock; protected ObjectDetector detector; protected int instanceNumber; protected String expectingItemSubstate; protected static Vector validSubstates; private static Log log = LogFactory.getLog(SAItemEntryActionImpl.class); }