Developer

AbstractDynamicMenu class

Abstract implementation of the dynamic menu state.

Package

com.sybase365.mobiliser.brand.plugins.smapp.state
Syntax
Syntax
public abstract class AbstractDynamicMenu extends SmappStatePlugin

Base class

Members

All members of AbstractDynamicMenu, including inherited members.

Variables
Modifier and Type Variable Description
protected static final SelectionBoxAttribute inShowExitMenu Selection for whether to show the exit menu item. Default Id = "SHOW_EXIT"Default description = "Show Exit menu"Default entries are: [0, No], [1,Yes]The subclass may modify the key and description as needed.
protected static final OutputAttribute outKey Selected key. When a menu item is selected, the selected key will be stored in this session OutputAttribute.Default Id = "SELECTED_KEY"Default description = "Variable name of the selected key"The subclass may modify the key and description as needed.
protected static final OutputAttribute outValue Selected value. When a menu item is selected, the selected value will be stored in this session OutputAttribute.Default Id = "SELECTED_VALUE"Default description = "Variable name of the selected value"The subclass may modify the key and description as needed.
Methods
Modifier and Type Method Description
protected abstract List< KeyValuePair< String, String > > constructMenuList() Return a list of menu item that will be used to construct the SMS menu message.
protected SmappState continueWhenSingleEntry(SmappState) When the menu contains a single item, the state will automatically proceed to the continueDyn(1) transition by default.
protected Page createPage(boolean) Provide subclasses the option to extend or override the default Page functionality.
protected String getLineBreak() Line break characters are used in the SMS menu message.
protected int getMaxMenuItems() Maximum number of menu items to display or send as SMS menu message including the pagination "9: More" and "0: Exit" items.
protected final< T > List< T > getMenuListFromSession(BeanConverterInterface< T >) Get the menu list.
protected MwizMessageOptions getMessageOptions(Page) Provide subclasses the option to set some default message options based on the current page before sending the message.
protected String getPaginationExit() String showing: Menu index and description, for exit from the menu.
protected String getPaginationNext() String showing: Menu index and description, for paging the menu, or pagination to the next page.
protected int getPaginationNextIndex() Index recognized by the algorithm for pagination to the next page.
protected abstract Attribute[] getStateAttributeList() Return an array of Attribute specified in the subclass.
protected final Attribute[] getStateAttributes() Returns the complete set of Attribute as specificed by this class and the subclass.
public String getStateNotes() Notes on the default behaviour of the dynamic menu.
protected abstract SmappState init(SmappStateProcessingAction) Allow the subclass to perform all the necessary initialization including constructing the menu list.
protected final SmappState processMessageLogic(SmappStateProcessingContext) Process incoming message.
protected final SmappState processStateLogic(SmappStateProcessingContext, SmappStateProcessingAction) Contains the actual processing logic for constructing the menu list.
protected abstract SmappState saveSessionVariables(String, String) This method is called after a selection is made from the menu, allowing the subclass to prepare the OutputAttributes (if needed) before transition to the follow-up state.
protected final< T extends BeanConverterInterface< T > > void setMenuListToSession(List< T >) Set a new menu list and save it into the session attribute.
public final boolean supportsFailTransition() Support fail transition.
public boolean supportsOkTransition() Support OK transition.
public boolean supportsSendSmsMessage() Support Send SMS message textbox toggle.
Inherited members from SmappStatePlugin
Modifier and Type Member Description
protected SmappState continueDyn(String) Helper method in state development.
protected SmappState continueDyn(Integer) Helper method in state development.
protected SmappState continueDyn(Long) Helper method in state development.
protected SmappState continueFail() Helper method in state development.
protected SmappState continueFail(String) Helper method in state development.
protected SmappState continueOk() Helper method in state development.
protected SmappState determineFollowingSmappStateFromPattern(SmappStateProcessingContext) Determine the follow-up transition that match the message in the state processing context.
protected SmappState determineFollowingSmappStateFromPattern(SmappStateProcessingContext, MwizMessage) Determine the follow-up transition that match the message from the input parameter.
protected SmappState determineFollowingSmappStateFromTransitionType(EnumSmappTransitionType, SmappState, SmappStateProcessingContext) Determine the follow-up transition that match the type provided in the input parameter.
public Customer getCurrentCustomer() Current customer Customer of this session.
public List< IAttribute > getInputAttributes() Return the input attributes specified by the state.
public List< IAttribute > getOutputAttributes() Return the output attributes specified by the state.
protected SessionAttribute getSessionAttributeForKey(String) Get the value of session attribute (SessionAttribute) based on the specified key.
protected List< SessionAttribute > getSessionAttributes() Get session attributes for the current state in the current session.
protected Long getSessionId() Session ID that the application is running.
protected SmsTextI18n getSmsText18nReplaced() Process the SMS message by replacing all the session variables with the actual session variable value.
protected void handleFatal(SmappStateProcessingContext, SmappStateProcessingAction) Helper method in state development.
protected boolean isCurrentStateEncrypted() Indicate whether the current state is encrypted.
public boolean isSelectable() To indicate whether the state can be used as the follow-up state.
public void loadStateAttributes(SmappStateEditorContext) Default implementation is empty.
public SmappState processMessage(SmappStateProcessingContext) This method is called by the processing engine when the state is activated from external source, for example, incoming SMS message.
public void processState(SmappStateProcessingContext, SmappStateProcessingAction) This method is always called by the processing engine when the state is activated by the follow-up transition.
protected void saveOutputAttributes() Saving attributes that has holdValue (see OutputAttribute#getHoldValue()) in bulk for better performance.
protected void saveSessionAttribute(String, String) Save the input parameters to the session attribute (SessionAttribute).
protected void saveSessionAttribute(String, String, boolean) Save the input parameters to the session attribute (SessionAttribute).
protected void saveSessionAttributes(Map< String, String >) Save the session attributes in the Map of the current state in the current session to database.
protected void sendSmappSms(MwizMessage, Language) Send SMS from the current session.
protected void sendSmappSms(MwizMessage, Language, MwizMessageOptions) Send SMS from the current session.
public void setAckMessage(boolean) Set the SMPP acknowledgement request flag for the current session.
public void shutdown() No default implementation.
public void startup(HashMap< String, String >) No default implementation.
public boolean supportEncryption() Indicate whether this state support encryption.
public boolean supportsDynTransition() Indicates if the state supports dynamic (Dyn) transition.
public boolean supportsGoToApplication() Indicate if the state supports transfer flow to another application.
Inherited members from Plugin
Modifier and Type Member Description
public String getInstanceName() Get the instance name.
public void setInstanceName(String) Set the instance name.
Inherited members from PluginInterface
Modifier and Type Member Description
public String getRevisionString()  
public void shutdown() Stop this plugin instance.
public void startup(HashMap< String, String >) Initiate the startup process for this plugin instance.
Inherited members from StatePlugin
Modifier and Type Member Description
public long getStateId() The state unique ID.
public String getStateName() The state name is used for display on the state editor.
Inherited members from PluginInterface
Modifier and Type Member Description
public String getInstanceName()  
public String getRevisionString()  
public void setInstanceName(String) A plugin may be instantiated multiple times with different set of attributes, the instanceName may be set externally to uniquely identify a particular instance.
public void shutdown() Stop this plugin instance.
public void startup(HashMap< String, String >) Initiate the startup process for this plugin instance.

Usage

Typically extended by the states that needs to return a list of items. The list is sent to the mobile handset as Send SMS, and in the form of a menu, as shown on the following example.

   Transactions:
   1. 26 Jan 2012 09:16 - USD 10.00 Pay cab
   2. 26 Jan 2012 10:10 - USD 3.45  Starbucks
   3. 26 Jan 2012 12:25 - USD 20.00 Lunch
   4. 26 Jan 2012 13:30 - USD 3.00 Starbucks
   9: More
   0: Exit

The menu item can be selected by sending reply with the menu item number. Example, 1, 2, 3, or 4, to select the item; 9 will be shown when they are more items and selecting 9 will show them, 0 is for exiting from the menu and proceed to the alternative flow. Typically, when the menu item is selected, a more detailed information of the selected item will be sent as SMS.

If there are more items then those displayed, the paging menu item will be displayed. For the above example, it is "9: More". When 9 is sent back as the reply, the menu will refreshed showing the next page of the menu, and so on. The menu index is always starting from 1. When the menu reaches the end, and the 9 is sent back as a reply again, the menu will rotate back to the first page.

The state can be configured to show the exit menu item. In the above case, it's the "0: Exit". When 0 is sent back as a reply, nothing is selected so the state will continue the transition that is associated with the dynamic "EXIT" value. In some application flows, when a selection is required, the exit menu item can be suppressed by setting "No" to the "Show Exit menu" drop down box in the state editor.

Three Attribute are automatically registered by this class, including:
  • SelectionBoxAttribute - to specify whether to Show Exit menu item
  • OutputAttribute - to specify the variable name to store the selected menu KEY
  • OutputAttribute - to specify the variable name to store the selected menu VALUE

The life cycle of AbstractDynamicMenu is based on the life cycle of the SmappStatePlugin and StatePlugin with the following customizations to meet the menu functionalities.

AbstractDynamicMenu is just an abstract implementation of a state that can Send SMS in the form menu. The subclass provides implementation of getting the list for the menu. The processMessageLogic(SmappStateProcessingContext) and processStateLogic(SmappStateProcessingContext, SmappStateProcessingAction) methods have been final because they have the implementation for the menu functionalities. The subclass need to implement the following abstract methods instead: init(SmappStateProcessingAction), constructMenuList(), getStateAttributeList(), and saveSessionVariables(String, String).

  • init(SmappStateProcessingAction) method will be called by the processStateLogic(SmappStateProcessingContext, SmappStateProcessingAction).Please refer to the method description for details.
  • constructMenuList() and saveSessionVariables(String, String) methods will be called by both the processMessageLogic(SmappStateProcessingContext) and processStateLogic(SmappStateProcessingContext, SmappStateProcessingAction) methods.Please refer to the method description for details.
  • getStateAttributeList() is called from the getStateAttributes() that will aggregate the attributes returned by the getStateAttributeList() with some attributes defined in this abstract class for the menu, such as the input attribute for specifying whether to show the exit menu item, the output attributes for the key and value of the selected menu item.
  • The AbstractDynamicMenu state will initially be activated by the follow-up transition from a previous state, so the processing engine will call the processStateLogic(SmappStateProcessingContext, SmappStateProcessingAction) method. The init and constructMenuList method will be called sequentially to initialize and construct the menu. Eventually the menu will be sent out as SMS message, and the processing engine will be set to action.waitForMessage() waiting for the reply message. In this case, the user selects a menu item.
  • In the special case when the constructMenuList returns a single item only, the state will immediately call the saveSessionVariables(String, String) method proceed with the the default continueDyn(1) follow-up transition. The state can customized the default behavior by overriding the continueWhenSingleEntry(SmappState) method.
  • When the reply message arrives, the processing engine will trigger the AbstractDynamicMenu state using the external activation, hence calling the processMessageLogic(SmappStateProcessingContext) method.The constructMenuList method will be called again to assemble the menu that will be used to interpret the user selected menu index. If the selection is one of the valid menu item, saveSessionVariables(String, String) method will be called allowing the state to prepare all the select item details for output, and proceed with the follow-up transition as returned by the saveSessionVariables method. If null is null, the default OK follow-up transition will be used.