Monday, September 23, 2013

My GSoC project - A generic Android viewer for Apache ISIS

Project sources can be found from here 

Overview

Apache Isis software is a framework for rapidly developing domain-driven apps in Java. 
Write your business logic in entities, domain services and repositories, and the framework dynamically generates a representation of that domain model as a webapp or a RESTful API. 



Specially this can be used for rapid prototyping or production. Isis works by building a metamodel from the domain object models, from which a generic user interface is generated dynamically at runtime. 
There are several implementations of the generic UI, one based on Wicket, one based on Servlet/JSPs, and one based on jax-rs and serving up a Restful API over http and json. 

This API is fully documented in the Restful Objects spec there is also a (non-Apache) open source implementation on .NET.

This GSOC suggestion is to develop a native Android app that will consume the RESTful API provided by Isis to provide a generic (naked objects) viewer for use either from a smartphone or tablet. 
Optionally this generic viewer could be extensible to allow mashups (as is supported by Isis' own Wicket-based viewer).

Architecture of the application

Basic task of ISIS Android viewer is to use the Restful Object viewer of Apache ISIS and generate useful information that can be easily readable by Android users.

Application should be able to read the services, domain entities and other details given by framework as JSON objects. Then it should be able to decode it and understand what should be done with this data to create the user interface in application. 

Architectural Goals and Constraints

  • First and major constrain as name of the project implies, this should be a generic view. It should support to all versions of Android OS starting from quite old 2.2 version to current stable latest version  4.2. This is a great challenge to create a such an application maintaining performance and adaptability in single piece.
  • Because this is a application that runs on a mobile device, amount of processing power which is available is limited in compared to a typical computer. So it is needed to manage processor time effectively
  • Android phones are in different sizes. So applications UI should be adjusted according to the size of hosting device and amount of details that is shown on the window should be filtered.  

Layers


Application is basically built upon three layers


1 User Interface Layer


This Layer consists of the elements that are needed to render user interfaces of the application.

a. Activities:
This application is basically an Android application. So the user interfaces are drawn using the Activity classes. One of the major deviation of these activity classes in compared to general activity class in an Android application is, these classes never used pre defined XML to generate UI elements. That means there is no any single UI element, which is rendered in static way. All the UIs are rendered dynamically at the run time.

b. UIModel
This class stores most visited interfaces’ details. It acts like a proxy for the UI. This increases the responsiveness of the application.

2 Applib Layer


This layer contains basically logical stuff. It is responsible to fetch data from server and filter data out of it and pass useful information to UI layer 

a. Constants
Application runs between two significantly different platforms : Apache ISIS data layer and Android layer. The data types and its meanings are different to each other. So it is required to convert Android data types to ISIS data types and vise versa. “Constant” classes do that functionality using one to one mapping of java data types to Android view elements. Simply these classes are working as Adapter classes. 

b. Communicator 
These classes are responsible for encapsulating communication complexities of the server and application to higher layers. It provides interfaces to upper layers in a way that upper layer never feels the underlying stuff happening between application and server.

3 Representation Layer

This layer contains classes that are used to “bean binding”. They are responsible to read plain JSON strings coming from the server and map them to actual objects (Beans). Then upper layers receives the data as a sequence of objects so that data can be retrieved using getters and setters.

Setting up development environment



Isis Android client is compatible with Android 2.2 to 4.2. So basically it can be run on any any android phone or tablet available in market.

To set up the development environment you need eclipse IDE installed with an Android sdk.

http://www.eclipse.org/downloads/
http://developer.android.com/sdk/index.html

Clone the project sources from github

https://github.com/DImuthuUpe/ISIS_Android_Viewer

There are two projects

  • Android_Viewer
  •  Android_Viewer_Test
And one library project

  • JakeWharton-ActionBarSherlock

Android_Viewer is the main project that contains the actual application and for testing purposes "Android_Viewer_Test" project is used

To open these projects

  • Import the supporting library project

file -> import -> Android -> Existing Android Code Into Workspace
project folder->JakeWharton-ActionBarSherlock->library
Go to properties and in the Android tab make sure the check box with the title "Library" is ticked

  • Import other two projects

file -> import -> Android -> Existing Android Code Into Workspace
Select project root
Do this to both projects
Finish

  •  Set up an android emulator emulator to run the project.
  •  To run the application, right click on the Android_Viewer project -> run as -> Android Application.
  • Select the  target emulator to run

Maven build and Configuration

To build the project using maven build tool

  1. From command line go to Android_Viewer folder
  2. Type "mvn clean install" to create apk for the project. Those binaries are generated under "target" folder.

Configurations of pom.xml

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
    <!-- Specify the android version-->
            <version>4.1.1.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
      <groupId>com.actionbarsherlock</groupId>
      <artifactId>actionbarsherlock</artifactId>
      <version>4.4.0</version>
       <type>apklib</type>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.11</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.11</version>
</dependency>
    </dependencies>
    <build>
        <finalName>${project.artifactId}</finalName>
        <sourceDirectory>src</sourceDirectory>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <version>3.6.1</version>
                    <extensions>true</extensions>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <configuration>
                    <sdk>
                        <!-- platform or api level (api level 18 = platform 4.3)-->
                        <platform>18</platform>
                        <!-- provide the path to the android sdk -->
                     <path>/Users/dimuthuupeksha/Downloads/adt-bundle-mac-x86_64-20130729/sdk</path>
                    </sdk>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Demos





Screen Captures