Documentation : Java References

Prelude

This document will provide you with detailed documentation about creating Mobeelizer client application on Java platform.

In this document we assumes that you are familiar with:

  • JAVA language
  • Key concepts of Mobeelizer platform (see)

Prepare your application

To work with Mobeelizer cloud first you have to add Mobeelizer SDK to your application.

If you have use Maven to build your application simply add new dependency:

<dependencies>    
    <dependency>        
        <groupId>com.mobeelizer</groupId>        
        <artifactId>java-sdk</artifactId>        
        <version>1.5.0</version>    
    </dependency>
</dependencies>
<repositories>    
    <repository>        
        <id>qcadoo-releases-repository</id>        
        <url>http://nexus.qcadoo.org/content/repositories/releases</url>
    </repository>
</repositories>

Otherwise download Mobeelizer SDK and its dependencies (commons-logging.commons-logging 1.1.1, org.apache.httpcomponents.httpcore 4.2.1, org.apache.httpcomponents.httpclient 4.2.1, org.apache.httpcomponents.httpmime 4.2.1, org.json.json 20090211, org.slf4j.slf4j-api 1.6.4) and include them into your application classpath.

Next, download XML file of your application created in App Designer and put it in your application directory.

Create model classes

Please see create model classes for more information.

Initialize Mobeelizer

To initialize Mobeelizer SDK you have to have the instance of MobeelizerConfiguration class. This configuration is pass to the Mobeelizer object.

MobeelizerConfiguration configuration = new MobeelizerConfiguration(); 
configuration.setDefinition(definition);  
configuration.setDevice("device");  
configuration.setDeviceIdentifier("deviceIdentifier");
configuration.setPackageName("packageName");  
configuration.setMode(MobeelizerMode.PRODUCTION);  
configuration.setInstance("instance");  
configuration.setUser("user");  
configuration.setPassword("password");  
Mobeelizer mobeelizer = new Mobeelizer(configuration)

Configuration fields are:

NameRequiredDescription

definition

true

Stream with the application definition.

device

true

Name of the device category. See this document for more explanation.

deviceIdentifier

true

Unique identifier of your application's deployment.

packageName

true

Package of your model classes.

mode

false

There are two possible development modes:

  • TEST - application will connect to test environment.

  • PRODUCTION - application will connect to production environment.

By default TEST is set.

instance

false

Name of the instance to connect to. By default it is named base on mode, accordingly "test" and "production".

user

true

Login of the administration user.

password

true

Password of the administration user.

User managements

User management API lets to manage your instance's users. There are methods for CRUD operations on users, listing groups, listing users and authenticate users.

List<string> groups = mobeelizer.getGroups();
List<mobeelizeruser> users = mobeelizer.getUsers();
MobeelizerUser user = mobeelizer.getUser("login");

MobeelizerUser newUser = new MobeelizerUser(); 
newUser.setLogin("newLogin"); 
newUser.setPassword("password"); 
newUser.setGroup("group"); 
mobeelizer.createUser(newUser);

mobeelizer.deleteUser("newLogin"); 
String userRole = mobeelizer.authenticate("login", "password");

Synchronization

There are two methods to sync your application data with Mobeelizer Cloud - syncAll(MobeelizerSyncCallback callback) and sync(Iterable entities, Iterable files, MobeelizerSyncCallback callback). The first one is used to overwrite your application data with data from cloud. It has to be also used as initial synchronization. The second one is differential synchronization.

The 'entities' param is the list of model objects (instances of model classes) that with will be sent to the cloud. It contains entities that have been added, updated and deleted. To delete entity its "deleted" field  must be set to true.

The 'files' param is the list of MobeelizerFile object represented files that will be sent to the cloud.

The 'callback' is the object that will receive notification when the synchronization has finished. It will receive new entities and files from the cloud.

The example sync implementation is presented below:

List<Object> newEntities = // get new entities to sync
List<MobeelizerFile> newFiles = // get new files to sync

MobeelizerSyncCallback callback = new MobeelizerSyncCallback() {

	public void onSyncFinishedWithSuccess(final Iterable<object> entities, final Iterable<mobeelizerfile> files,
			final Iterable<string> deletedFiles, final MobeelizerConfirmSyncCallback confirmCallback) {

		// add new entities from 'entities'
		// add new files from 'files'
		// remove files from 'deletedFiles'
		confirmCallback.confirm();     
	}

	public void onSyncFinishedWithError(final MobeelizerOperationError error) {
		// sync error
	}

	public void onSyncFinishedWithError(final MobeelizerErrors errors) {
		// sync error
	}
}
 
mobeelizer.sync(newEntities, newFiles, callback);

Get Conflict History

There is dedicated method in Mobeelizer to get entity conflict history - getConflictHistory(model, guid, callback). 

The model parameter is String type and it is name of the conflicted entity model. Second parameter - guid - is unique guid value of the entity. The 'callback' is the object that will receive notification when getting history finished. It will receive list of entity versions.

The example is presented below:

MobeelizerGetConflictHistoryCallback callback = new MobeelizerGetConflictHistoryCallback() {
 
    @Override
	public void onFinishedWithSuccess(Iterable<MobeelizerEntityVersion> versions) {
        // let your user to select correct version
    }
 
    @Override
	public void onFinishedWithError(MobeelizerOperationError error) {
		// handle error
	}
}
 
mobeelizer.getConflictHistory("model", "guid", callback);

Push notifications

To learn about Push notification see Push notifications key concept page.

Registering to receive push notifications

If you want client application to be able to receive push notifications you must create web service and register the URL that will be exposed it.

The URL should be registered in MobeelizerConfiguration object.

MobeelizerConfiguration configuration = new MobeelizerConfiguration(); 
// configure application 
configuration.setPushNotificationUrl("http://your.application.com/push/notification/service/");  
Mobeelizer mobeelizer = new Mobeelizer(configuration)

Sending push notifications

To send Push notification call one of methods on Mobeelizer object: