-
Notifications
You must be signed in to change notification settings - Fork 3
Java references
- Prelude
- Prepare your application
- Create model classes
- Initialize Mobeelizer
- User managements
- Synchronization
- Push notifications
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)
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.1.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.1.3
- org.apache.httpcomponents.httpclient 4.1.3
- org.apache.httpcomponents.httpmime 4.1.3
- 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.
Please see create model classes for more information.
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:
Name | Required | Description |
---|---|---|
definition | true | Stream with the application definition. |
device | true | Name of the device. 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 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");
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 = // todo - get new entities to sync
List<MobeelizerFile> newFiles = // todo - 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) {
// todo - add new entities from 'entities'
// todo - add new files from 'files'
// todo - remove files from 'deletedFiles'
confirmCallback.confirm();
}
public void onSyncFinishedWithError(final Exception exception) {
// failure, todo
}
public void onSyncFinishedWithError(final MobeelizerErrors errors) {
// failure, todo
}
}
mobeelizer.sync(newEntities, newFiles, callback);
To learn about Push notification see Push notifications key concept page.
To send Push notification call one of methods on Mobeelizer object:
- sendRemoteNotification(Map notification)
- sendRemoteNotificationToDevice(Map notification, String device)
- sendRemoteNotificationToUsers(Map notification, List users)
- sendRemoteNotificationToUsersOnDevice(Map notification, List users, String device)
- sendRemoteNotificationToGroup(Map notification, String group)
- sendRemoteNotificationToGroupOnDevice(Map notification, String group, String device)