View source | Discuss this page | Page history | Printable version   
Toolbox
Main Page
Upload file
What links here
Recent changes
Help

PDF Books
Add page
Show collection (0 pages)
Collections help

Search

Mobile server side query components

Contents

Introduction

Openbravo Mobile Core provides some classes to interact retrieving data or to execute processes in the server side. These classes can be invoked from the client side.

This is the hierarchy of abstract classes that are used for this purpose:

Mobile-process-hierarchy.png

SecuredJSONProcess

This class is not intended to be directly extended. It provides the security layer for the ProcessHQLQuery and JSONProcessSimple classes.

Refer to Security Model documentation to understand the security model proposed for mobile applications.

Classes extending SecuredJSONProcess can be securitized overriding the following methods:

These two classes has been overwritten by Openbravo Web Pos Module, so you can extend directly from them without overriding getFormId method

org.openbravo.retail.posterminal.ProcessHQLQuery;

org.openbravo.retail.posterminal.JSONProcessSimple;

Mobile Service implementation

Since RR16Q2 it is possible to have multiple classes implementing the same Mobile Service. To identify the service that it is implementing it is needed to add an Annotation using the MobileServiceQualifier qualifier and declare the service name:

@MobileServiceQualifier(serviceName = "org.openbravo.retail.posterminal.master.BusinessPartner")

It is also possible to determine the order in which the different classes are executed overriding the getPriority() method. Openbravo provided implementations have a default priority of 100.

  /**
   * Returns the execution priority within the classes implementing a Mobile Service.
   * 
   * @return an int with the priority value. The lower int the higher priority.
   */
  protected int getPriority() {
    return 100;
  }

Finally it is possible to determine if the next class has to be executed when the current implementation finish successfully or when it throws an exception. By default Openbravo won't call any other class with lower priority. There are 2 methods available that can be override to configure this behavior:

  /**
   * Mobile Service processes should override this method to determine if the next priority mobile
   * service class should be executed or not.
   * 
   * @return true to execute the next service class.
   */
  protected boolean executeNextServiceClass() {
    return false;
  }
  
  /**
   * Mobile Service processes should override this method to determine if the next priority mobile
   * service class should be executed or not when this service has thrown an exception.
   * 
   * @return true to execute the next service class.
   */
  protected boolean executeNextServiceClassOnFailure() {
    return false;
  }

ProcessHQLQuery class

The aim of this class is to return a JSON object based on a (set of) HQL query. Classes extending this class, return a HQL that will be used to generate the object.

To learn more about HQL queries, see The Hibernate Query Language.

This class implements two methods:

Server side example

package org.openbravo.retail.posterminal.example;
 
import java.util.Arrays;
import java.util.List;
 
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.openbravo.mobile.core.process.ProcessHQLQuery;
 
@MobileServiceQualifier(serviceName = "org.openbravo.retail.posterminal.example.MyExample")
public class MyExample extends ProcessHQLQuery {
 
  @Override
  protected boolean isAdminMode() {
    return true;
  }
 
  @Override
  protected List<String> getQuery(JSONObject jsonsent) throws JSONException {
    return Arrays
        .asList(new String[] {"from Currency where id =:currency and $readableCriteria"});
  }
}

Client side call example

The query is called from the client-side using the OB.DS.Request object. It has two parameters: the JSON object sent and the callback handler:

new OB.DS.Request('org.openbravo.retail.posterminal.example.MyExample').exec(
  {
    currency: this.get('terminal').currency
  }, function(data) {
    if (data[0]) {
      console.log('This is the returned object');
      console.log(data[0]);
    }
  }
);
 

JSONProcessSimple class

The purpose of the classes extending it should be executing a process in the backend, returning as result a JSON object.

It implements one method

Server side example

package org.openbravo.retail.posterminal.example;
 
import javax.servlet.ServletException;
 
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.openbravo.mobile.core.process.JSONProcessSimple;
 
@MobileServiceQualifier(serviceName = "org.openbravo.retail.posterminal.example.MyExample")
public class MyExample extends JSONProcessSimple {
 
  public JSONObject exec(JSONObject jsonsent) throws JSONException, ServletException {
 
    JSONObject result = new JSONObject();
 
    // Here do whatever you need and finally return a JSONObject object
 
    // It is needed to put an object called 'data' if you want to return some variables inside the result JSONObject
    // It is needed to put a variable 'message' if you want to return a string inside the result JSONObject
    // You can return a 'status' variable with '0' in case everything went OK or '1' if there was an exception inside the result JSONObject
 
    return result;
  }
}

Client side call example

new OB.DS.Process('org.openbravo.retail.posterminal.example.MyExample').exec({
  currency: this.get('terminal').currency
}, function(data) {
  if (data && data.exception) {
    // Error handler
  } else {
    console.log('This is the returned object');
    console.log(data);
  }
});

Retrieved from "http://wiki.openbravo.com/wiki/Mobile_server_side_query_components"

This page has been accessed 3,986 times. This page was last modified on 22 February 2016, at 16:48. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.