Developer

Sample USSD Menu Code

The code for a sample implementation of the Send USSD Menu state produces a menu with four options: Option 1, Option 2, Option 3, and Option 4.

The SmappStateSendUssdMenu class implements the sample USSD menu. The fully qualified class name is:
com.sybase365.mobiliser.brand.plugins.ussd.impl.SmappStateSendUssdMenu
SmappStateSendUssdMenu is a subclass of the AbstractDynamicUssdMenu abstract class.
package com.sybase365.mobiliser.brand.plugins.ussd.impl;       

import com.sybase365.mobiliser.brand.dao.DBException;   
import com.sybase365.mobiliser.brand.jpa.SmappState;   
import com.sybase365.mobiliser.brand.plugins.api.smapp.SmappStateProcessingAction;   
import com.sybase365.mobiliser.brand.plugins.smapp.controls.Attribute;   
import com.sybase365.mobiliser.brand.plugins.useful.KeyValuePair;   
import java.util.ArrayList;   
import java.util.Arrays;   
import java.util.List;   
import org.slf4j.Logger;   
import org.slf4j.LoggerFactory;        

/**    
* Loads all available languages and puts them into a menu    
*     
*/   
public class SmappStateSendUssdMenu extends AbstractDynamicUssdMenu   
{     
  protected static final Logger LOG =         
      LoggerFactory.getLogger(SmappStateSendUssdMenu.class);         
  
  private static final String[] OPTIONS =          
         { "Option 1", "Option 2", "Option 3", "Option 4" };         
  
  private  List<String> listOfOptions = Arrays.asList(OPTIONS);         

  private static Attribute[] stateAttr;         

  static {       
     stateAttr = new Attribute[]{};     
  }         

  @Override     
  protected Attribute[] getStateAttributeList() {       
     return stateAttr.clone();     
  }         

  @Override     
  public long getStateId() {       
     return 485002;     
  }         

  @Override     
  public String getStateName() {       
     return "Send USSD Menu";     
   }         

  @Override     
  public String getStateNotes() {       
     return "This state generates a sample USSD Menu.\n" + 
            "Use these follow-up states:\n" + 
            "- OK: If user selected a menu item.\n" + 
            "- FAIL: If an error occurs.";     
  }         

  @Override     
  public boolean supportsOkTransition() {       
     return true;     
  }         

  @Override     
  public String getRevisionString() {           
     return "$Revision:28128 $";     
  }         

  @Override     
  protected SmappState init(SmappStateProcessingAction action)        
     throws DBException {
     
     if (listOfOptions == null) {        
        return continueFail();       
     }           

     return null;     
  }         

  @Override     
  protected int getMaxMenuItems() {           
     return this.listOfOptions.size();     
  }         

  @Override     
  protected List<KeyValuePair<String, String>> constructMenuList()       
      throws DBException {

     List<KeyValuePair<String, String>> list =            
             new ArrayList<KeyValuePair<String, String>>();           

     int optionNumber = 1;           

     for (String option : listOfOptions) {        
        KeyValuePair<String, String> keyVal = new KeyValuePair<String, String>();       
        keyVal.setKey(Integer.toString(optionNumber));        
        keyVal.setValue(option);        
        list.add(keyVal);        
        optionNumber++;       
     }           
     
     return list;     
  }         

  @Override     
  protected SmappState saveSessionVariables(SmappStateProcessingContext context, 
                                            String key, String value)        
      throws MwizProcessingException, DBException, RequiredParameterMissingException {
     return null;     
  }   
}