/*
* ACECustomerEntryActionImpl
*
* 07/17/2003
*
* Copyright:
* Licensed Materials - Property of IBM
* "Restricted Materials of IBM"
* 5724-AEF
* (C) Copyright IBM Corp. 2003.
*
* ace/com/ibm/retail/AEF/action/ACECustomerEntryActionImpl.java, aef.ace, aef.bravo 04/07/12
*/
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;
/**
* ACECustomerEntryActionImpl is a class which the POSAutomationProvider uses to
* add a customer entry to a transaction on the ACE application.
*
*/
public class ACECustomerEntryActionImpl extends ACEActionImpl
{
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.
*
* @exception AEFException
*/
public ACECustomerEntryActionImpl(ActionRequest request) throws AEFException
{
super(request);
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter constructor of ACECustomerEntryActionImpl.");
log.trace(tempAEFMessage);
}
// theValidSubstates contains a list of all the substates for which
// a customer may be entered. This is a class static, so it is only
// initialized once.
if (theValidSubstates == null)
{
theValidSubstates = new Vector();
theValidSubstates.addElement(Substate.getSubstate("SELECT_PROCEDURE"));
theValidSubstates.addElement(Substate.getSubstate("EXPECTING_ITEM"));
theValidSubstates.addElement(Substate.getSubstate("EXPECTING_TENDER"));
theValidSubstates.addElement(Substate.getSubstate("TRAINING_MODE"));
theValidSubstates.addElement(Substate.getSubstate("ENTER_ITEM"));
}
LoyaltyIdentifier loyaltyId = (LoyaltyIdentifier)(request.getArguments());
theCustomerId = loyaltyId.getID();
theIDType = loyaltyId.getType();
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit constructor of ACECustomerEntryActionImpl.");
log.trace(tempAEFMessage);
}
}
/**
* Perform the action represented by the ActionRequest and return an ActionResult.
*
* @return Object The Customer instance.
* @exception AEFException
* Among the possible error codes are:
*
AEFConst.APPLICATION_NOT_IN_PROPER_STATE
*/
public Object performAction() throws AEFException
{
super.performAction();
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter ACECustomerEntryActionImpl.performAction()");
log.trace(tempAEFMessage);
}
// Call super to perform any common processing and clear any errors before we start.
Object retVal = null;
if (log.isDebugEnabled())
{
log.debug( new AEFMessage(sessionID, "ACECustomerEntryActionImpl.performAction Started.") );
}
// If ACE 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;
// Check that ACE is in one of the substates which is valid for customer entry.
// If not, then throw an exception.
String currentSubstate = getCurrentSubstate();
AEFSession session = SessionContext.getSession();
theDetector = ((DetectorAccess) (session)).getCustomerEntryDetector();
if (theValidSubstates.contains(currentSubstate))
{
// We don't want to send TOTAL unless a customer number had previously been added. TOTAL will play
// the targeted and delayed coupons which may not be what is wanted at this point. We have to
// be very careful when automatically sending a TOTAL.
// In a valid state for customer number entry
seqResult = sendCustomerEntrySequence();
if (log.isDebugEnabled())
{
log.debug( new AEFMessage(sessionID, "ACECustomerEntryActionImpl.performAction seqResult = " + seqResult ) );
}
if (seqResult >= 0)
{
// Successfully entered customer number.
retVal = waitForCustomer();
}
}
else
{
// Not in valid state for customer number entry
String tempString = "ACECustomerEntryActionImpl.performAction(): POS application not in proper state to perform customer entry.\n Application substate is " + currentSubstate + ".";
AEFException tempException = new AEFException(AEFConst.APPLICATION_NOT_IN_PROPER_STATE, 0, tempString);
tempAEFMessage.setMessage(tempString);
log.error(tempAEFMessage, tempException);
throw tempException;
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit ACECustomerEntryActionImpl.performAction()");
log.trace(tempAEFMessage);
}
return retVal;
}
/**
* Sends the key sequence which will enter the customer number.
*
* @return int An integer value representing the result of the key sequence.
* @exception AEFException
* Among the possible error codes are:
*
AEFConst.INVALID_ARGUMENT, AEFConst.INVALID_LOYALTY_NUMBER
*/
public int sendCustomerEntrySequence() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter ACECustomerEntryActionImpl.sendCustomerEntrySequence()");
log.trace(tempAEFMessage);
}
int retVal = -1;
// if all zeroes then an invalid argument.
boolean nonZeroString = false;
for (int i= 0; i < theCustomerId.length(); i++)
{
if (theCustomerId.charAt(i) != '0')
{
nonZeroString = true;
}
}
if (! nonZeroString)
{
String tempString = "ACECustomerEntryActionImpl.sendCustomerEntrySequence(): Invalid argument " + theCustomerId + ".";
AEFException tempException = new AEFException(AEFConst.INVALID_ARGUMENT,
AEFConst.INVALID_LOYALTY_NUMBER,
tempString);
tempAEFMessage.setMessage(tempString);
log.error(tempAEFMessage, tempException);
throw tempException;
}
args.clear();
args.put("%0", theCustomerId);
if (theIDType != null && theIDType.equals(LoyaltyIdentifier.ALTERNATE_TYPE))
{
args.put("SEQUENCE_ID", "alternateCustomer");
}
else
{
args.put("SEQUENCE_ID", "customer");
}
theKeySequenceAction = (AEFAction)
(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args)));
Condition[] goodConditions =
{
new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_SUB_STATE,
Substate.getSubstate("EXPECTING_ITEM")),
new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_SUB_STATE,
Substate.getSubstate("SELECT_PROCEDURE")),
new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_SUB_STATE,
Substate.getSubstate("EXPECTING_TENDER"))
};
theLock = new ConditionLock();
// Save any current customer instance number so we are sure to only get the customer
// created after this key sequence is sent.
theInstanceNumber = theDetector.getInstanceNumber();
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"addCustomer",
">>>Sending customer id key sequence to application.");
}
retVal = theLock.performActionAndWait("wait-for-expecting-item-substate",
theKeySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout());
if (retVal < 0)
{
AEFErrorHandler errorHandler = new AEFErrorHandler("Send Customer Entry Sequence Error");
retVal = errorHandler.handleError(theLock,
theKeySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout(),
retVal);
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit ACECustomerEntryActionImpl.sendCustomerEntrySequence()");
log.trace(tempAEFMessage);
}
return retVal;
}
/**
* Waits for customer to be entered
*
* @return Customer The customer created by the action.
* @exception AEFException
*/
public Customer waitForCustomer() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter ACECustomerEntryActionImpl.waitForCustomer()");
log.trace(tempAEFMessage);
}
Customer retVal = null;
// Successfully entered customer. Wait for the operator object to be created.
ObjectDetectorLock objLock = new ObjectDetectorLock();
retVal = (Customer) (objLock.waitForNewObject("wait-for-customer-entry", theDetector,
theInstanceNumber, getTimeout()));
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"addCustomer",
"<<