introducing the universaal utility api
DESCRIPTION
Introducing the universAAL Utility API. Madrid, Spain 08/01/2013 Alvaro Fides (UPVLC). How universAAL works. Let´s assume by now you know (more or less) how universAAL works. How universAAL works. In a nutshell, in universAAL you can do 6 things:. Send and Receive Context Events. - PowerPoint PPT PresentationTRANSCRIPT
Introducing the universAAL Utility API
Madrid, Spain 08/01/2013
Alvaro Fides (UPVLC)
How universAAL works
2 universAAL Training – Utility API
Let´s assume by now you know (more or less) how universAAL works
How universAAL works
3 universAAL Training – Utility API
In a nutshell, in universAAL you can do 6 things:
Send and Receive Context Events
Call and Provide Services
Give Output to the user and Get Input in response
How universAAL works
4 universAAL Training – Utility API
Why not do just that?
The Utility API
The Utility API lets you interact with universAAL in this simplified way (it can do many other things but this is the most flashy)
It is just a library layered on top of universAAL native middleware, so it is seamlessly compatible
universAAL Training – Utility API5
The Utility API
Source: http://forge.universaal.org/svn/support/trunk/utilities/uAAL.utils/
Binary: http://depot.universaal.org/nexus/index.html#view-repositories;snapshots
Maven ID: org.universAAL.support/uAAL.utils/2.0.1-SNAPSHOT
Wiki: http://forge.universaal.org/wiki/support:Utility_API
Javadoc: http://depot.universaal.org/hudson/job/support/site/support.pom/apidocs/index.html
universAAL Training – Utility API6
Using the Utility API
Let´s make a uAAL App with the Utility API that:• Sends a Context Event about a user´s position• Receives that same Context Event• Provides Services to edit a user• Calls one of those Services• Outputs a User Interface with a button
With the native uAAL MW you would need several classes and quite a bit of code
With the Utility API we´ll do this within the Activator in about 100 lines
universAAL Training – Utility API7
Using the Utility API
1. Create an empty uAAL project
2. Setup the POM to use the API:• In addition to the basic uAAL dependencies we will add:
universAAL Training – Utility API8
<dependencies>...<dependency>
<groupId>org.universAAL.ontology</groupId><artifactId>ont.phWorld</artifactId><version>2.0.0</version>
</dependency><dependency>
<groupId>org.universAAL.ontology</groupId><artifactId>ont.profile</artifactId><version>2.0.0</version>
</dependency><dependency>
<groupId>org.universAAL.support</groupId><artifactId>uAAL.utils</artifactId><version>2.0.1-SNAPSHOT</version>
</dependency></dependencies>
To use “Things”
To use “Users”
To use the Utility API
Using the Utility API
3. Modify the Activator to:• Initialize
9
public class Activator implements BundleActivator {
public static BundleContext osgiContext = null;public static ModuleContext context = null;
private static String NAMESPACE = "http://ontology.itaca.upv.es/Test.owl#";
private UAAL u;
public void start(BundleContext bcontext) throws Exception {
Activator.osgiContext = bcontext;Activator.context = uAALBundleContainer.THE_CONTAINER
.registerModule(new Object[] { bcontext });
u = new UAAL(context);...
The OSGi Context and the uAAL Context
The Namespace of this App
The uAAL Helper class
Initialize Context
Initialize uAAL Helper class
universAAL Training – Utility API
Using the Utility API
3. Modify the Activator to:• Subscribe for Context Events:
10
public class Activator implements BundleActivator {...public void start(BundleContext bcontext) throws Exception {
...Pattern cep = new Pattern(User.MY_URI, User.PROP_PHYSICAL_LOCATION, null);u.subscribeC(new ContextEventPattern[] { cep }, new ICListener() {
public void handleContextEvent(ContextEvent event) {System.out.println(">>> Received Event: " + event.toString());
}});...
Describe the event pattern as usual or
with Utility APIInstead of using a Context Subscriber,
create a simple Listener
This is what we do when we receive a
matching event
universAAL Training – Utility API
Using the Utility API
3. Modify the Activator to:• Send a Context Event:
11
public class Activator implements BundleActivator {...public void start(BundleContext bcontext) throws Exception {
...User user1 = new User(Constants.uAAL_MIDDLEWARE_LOCAL_ID_PREFIX + "saied")user1.setLocation(new Location(NAMESPACE + "loc1"));ContextEvent e = new ContextEvent(user1, User.PROP_PHYSICAL_LOCATION);u.sendC(e);
...
Create an event as usual
... and send it
universAAL Training – Utility API
Using the Utility API
3. Modify the Activator to:• Provide a Service:
12
public class Activator implements BundleActivator {...public void start(BundleContext bcontext) throws Exception {
...ServiceProfile[] sp=UtilEditor.getServiceProfiles(NAMESPACE,
ProfilingService.MY_URI,Path.at(ProfilingService.PROP_CONTROLS).path, User.MY_URI);
u.provideS(sp,new ISListener() {public ServiceResponse handleCall(ServiceCall s) {
System.out.println(">>> Received Service Call: "+ s.toString());return new ServiceResponse(CallStatus.succeeded);
}});
...
Declare service profiles as usual or
with Utility API
Instead of using a Service Callee, create
a simple Listener
This gives you the typical get/set/change/remove service
profiles
This is what we do when we receive a matching call. Notice you must return the
response.
universAAL Training – Utility API
Using the Utility API
3. Modify the Activator to:• Call a Service:
13
public class Activator implements BundleActivator {...public void start(BundleContext bcontext) throws Exception {
...ServiceRequest sr=UtilEditor.requestRemove(
ProfilingService.MY_URI,Path.at(ProfilingService.PROP_CONTROLS).path, user1);
ServiceResponse r = u.callS(sr); System.out.println(">>> Received Service Response: “+ r.getCallStatus()); ...
Declare service request as usual or
with Utility API... and call the service
This gives you the typical “remove” service request
... and do something with the response
universAAL Training – Utility API
Using the Utility API
3. Modify the Activator to:• Manage the User Interface:
14
public class Activator implements BundleActivator {...public void start(BundleContext bcontext) throws Exception {
... Dialog d = new Dialog(user1,"UI example");d.add(Forms.out("Result:", "Successfully reached UI test"));d.addSubmit(Forms.submit(NAMESPACE + "button1", "OK"));u.requestUI(d, new IUIListener() {
public void handleUIResponse(UIResponse r) {System.out.println(">>> Received UI Response: “+ r.getSubmissionID());
}});
}
Create a dialog as usual or with Utility
APIInstead of using a UICaller, create a
simple Listener
In Utility API you can create forms like this
This is what we do when we receive the user input
universAAL Training – Utility API
Using the Utility API
3. Modify the Activator to:• … don´t forget to close properly:
15
public class Activator implements BundleActivator {...public void stop(BundleContext arg0) throws Exception {
u.terminate();}
}
universAAL Training – Utility API
Using the Utility API
16 universAAL Training – Utility API
That´s pretty much it. Build, run, try...
public class Activator implements BundleActivator { public static BundleContext osgiContext = null; public static ModuleContext context = null; private static String NAMESPACE = "http://ontology.itaca.upv.es/Test.owl#"; private UAAL u; public void start(BundleContext bcontext) throws Exception {
Activator.osgiContext = bcontext;Activator.context = uAALBundleContainer.THE_CONTAINER
.registerModule(new Object[] { bcontext });u = new UAAL(context);
Pattern cep = new Pattern(User.MY_URI, User.PROP_PHYSICAL_LOCATION, null);u.subscribeC(new ContextEventPattern[] { cep }, new ICListener() { public void handleContextEvent(ContextEvent event) {
System.out.println(">>> Received Event: " + event.toString()); }});
User user1 = new User(Constants.uAAL_MIDDLEWARE_LOCAL_ID_PREFIX + "saied")user1.setLocation(new Location(NAMESPACE + "loc1"));ContextEvent e = new ContextEvent(user1, User.PROP_PHYSICAL_LOCATION);u.sendC(e);
u.provideS(UtilEditor.getServiceProfiles(NAMESPACE,ProfilingService.MY_URI,Path.at(ProfilingService.PROP_CONTROLS).path, User.MY_URI),new ISListener() { public ServiceResponse handleCall(ServiceCall s) {
System.out.println(">>> Received Service Call: " + s.toString());return new ServiceResponse(CallStatus.succeeded);
}});
ServiceResponse r = u.callS(UtilEditor.requestRemove(
ProfilingService.MY_URI,Path.at(ProfilingService.PROP_CONTROLS).path, user1));
System.out.println(">>> Received Service Response: "+ r.getCallStatus());
Dialog d = new Dialog(user1,"UI example");d.add(Forms.out("Result:", "Successfully reached UI test"));d.addSubmit(Forms.submit(NAMESPACE + "button1", "OK"));u.requestUI(d, new IUIListener() { public void handleUIResponse(UIResponse r) {
System.out.println(">>> Received UI Response: " + r.getSubmissionID()); }});
} public void stop(BundleContext arg0) throws Exception {
u.terminate(); }}
There is more…
There are other layers beneath this simplification and uAAL Helper Class which can help you make:• Event Patterns, Publisher Info, Publishers• Service Profiles, Requests, Property Paths,
Process Parameters, Typical Callees and Profiles• UI Dialogs, UI Form Elements, Typical UICallers• More…
universAAL Training – Utility API17