Sunday, March 29, 2015

Automatic ADF Popup Opening on Fragment Load

I had a post about opening ADF Popup on page load - Opening ADF PopUp on Page Load. Approach is quite straightforward, developer needs to use showPopupBehavior operation with appropriate trigger type. When it comes to ADF Popup opening on fragment load, implementation is a bit more complex. There is a known method to implement hidden text field and in the getter method call your custom logic - getter will be executed when fragment loads. However, this is not very efficient, you will need to add condition to distinguish between first and subsequent calls to the getter (it will be executed multiple times). I will describe in this post different approach - using ADF poll component and forcing it to execute only once after fragment load.

Here you can download sample application - FragmentPopUpLoadApp.zip. This sample implements two UI tabs. Each of the tabs renders ADF region. First region displays information about all employees - tree map with salary information:


Automatic popup opening is implemented in the second region - Employees By Department tab. As soon as user opens this tab, popup is load to select department. Data in the region is filtered, based on department selected in the popup:


Filtered data after selection was made in automatically opened popup:


Popup in the fragment is loaded on the first load by ADF poll component. Poll component is set with short interval of 10 milliseconds. During its first execution it will call Java listener method and in addition JavaScript client listener will be invoked. Inside JavaScript client listener, we disable ADF poll component by setting its interval to be negative. This is how ADF poll executes only once and then it stops:


Here is Java listener method, invoked by ADF poll component - it loads the popup:


ADF poll is stopped after its first execution. However, we need to ensure it will be started again - if user re-opens the same tab. For this purpose I have implemented conditional ADF region activation - region is de-activated when user navigates away from the tab. Tab disclosure listener updates helper variable to track which tab becomes active:


Disclosure listener updates page flow scope variable - forceActivate:


This variable is used in the region definition - region is active when tab is selected, and inactive otherwise:

Sunday, March 22, 2015

Background REST Service Access with A-Team Mobile Persistence Accelerator

REST service transfers light data, but service execution time could bring significant delay to the enterprise mobile application. I have already introduced you to the A-Team Mobile Persistence Accelerator (AMPA) in previous post - REST Service Access with A-Team Mobile Persistence Accelerator. Based on AMPA author - Steven Davelaar suggestions, I will post today updated application, where REST service call will be handled in background. This will allow mobile user to continue working with the MAF application, while REST call is being processed in background thread.

Here you can download updated sample application - MobileServiceBusApp_v7.zip. Remote read in background is configurable through AMPA persistence mapping, I have changed it to be false - let's see how it works for slow REST service execution:


Data Control method is executing (sequential in this example) remote findAll operation through AMPA, to fetch employees data. Data collection is loaded to the UI, after service execution is completed:


Server side ADF BC VO is set to wait 30 seconds (waiting for 30 seconds after VO was executed), before completing SOAP response. This allows to simulate slow REST service execution and check how MAF mobile application behaves with sequential service call:


Executing search operation over slow REST operation blocks entire MAF mobile application. User can't navigate to other screens and is locked into current screen, until response comes. This is how it looks like, when I changed search criteria - mobile application waits for the response:


Obviously this is inappropriate, because it blocks application and user can't continue his work. Let's test with AMPA configured to execute REST calls in background - remoteReadInBackground = true:


Data Control method responsible to execute REST action is refactored. I'm only starting remote findAll operation - not waiting it to complete. AMPA generated service class EmployeeService is changed to include additional constructor, where I'm passing instance of Data Control class and a flag to prevent auto query. Here is applyFilter method from Data Control class, it call REST service in background, through AMPA:


AMPA generated class is changed with overriden method refreshEntityList. This method is called automatically by AMPA, when background REST call is completed. Here I'm calling Data Control class method, responsible to refresh UI and display data fetched from the background service:


Data Control class method responsible for UI refresh - it updates Data Control collection and invokes synch with UI:


I will describe a test I have completed, with REST service execution in background. Perform search action with a parameter:


ADF BC on server side executes VO with SQL statement, there is a wait time of 30 seconds:


MAF mobile application is not blocked anymore, as it was with sequential REST service execution. User can navigate to other screen and do different actions:


Once ADF BC VO completes execution and SOAP service returns response, Service Bus is transforming SOAP response to REST. Mobile application receives data and UI refresh happens, to present latest changes. User can view the changes, once he is back to the screen:


In the same way, user could run another search:


While search is running, user could view details for present data:


After returning back to the search list, results for the new search query are displayed - data from REST service call executed in background:


User could load details screen and view the data:

Tuesday, March 17, 2015

ADF BC Property Set to Group Attribute Hints

There is one ADF BC component not mentioned often - Property Set. This is a bag of properties/hints, it can be applied for EO/VO attributes. Frequently used hints can be defined in Property Set once, without repeating the same for each attribute. This simplifies maintenance, if there will be a change required in the future - much easier to change it in single place. I will show below a practical example, where Property Set is applied for EO attribute to define a date type.

You can create Property Set with ADF BC wizard:


Property Set creation is really simple - provide a name and package:


It comes with a section to define Custom Properties. I will add two properties required to set date format - FMR_FORMAT and FMT_FORMATTER. I will be using EU format for the date (dd-MM-yyyy). The advantage of Property Set - you can define multiple sets for different date formats and apply them when required:


Select EO/VO attribute and choose Property Set, it will appear in the choice list:


Attribute is assigned with domain, pointing to the Property Set:


This is how it looks on UI - Hire Date field is correctly formatted, based on the format mask defined in Property Set:


Download sample application - PropertySetApp.zip.

Monday, March 16, 2015

REST Service Access with A-Team Mobile Persistence Accelerator

A-Team Mobile Persistence Accelerator (AMPA) works on top of Oracle Mobile Application Framework (MAF) and provides tools to simplify consumption of REST services. It enables transparent persistent layer usage on the device with the option of synchronising offline data with the server side. In this post, I will be testing AMPA in the context of the use case implemented previously - MAF 2.1 Alta Mobile UI and Oracle Mobile Suite. Working MAF application, where REST service calls are coded by hand, will be changed to fetch REST service data through AMPA - reusing existing Data Control. This is unusual approach, most of the tutorials related to AMPA describe end-to-end scenario, where Data Control is generated on top of AMPA service class and UI is generated with AMPA wizard. Mobile UI in most of the cases will be custom made and we rarely generating it. This is why it is important to explain, how to use AMPA with custom UI and Data Control.

You could read more about AMPA and find installation instructions in Steven Davelaar post - Getting Started with the A-Team Mobile Persistence Accelerator.

I will be using my sample application from the MAF 2.1 Alta UI post mentioned above. You can download application updated with AMPA support here (this includes ADF BC SOAP service, OSB transformation to REST and MAF application with AMPA) - MobileServiceBusApp_v6.zip.

As soon as REST connection is defined, AMPA wizard offers you to define REST resources. In my case I have to different resources, though working with the same Employees data schema. Both require to provide parameter:


Wizard is going to ask you to provide sample parameters to retrieve a response from REST resources. This is how AMPA retrieves metadata required to generate service representation in MAF:


Data Objects will be constructed automatically for each resource path. In my case, both resources are based on the same schema Employees. If this is the case for you, make sure to change the names in the wizard to be unique, otherwise AMPA fails to generate proper SQL scripts and service classes.

In this example I don't want to persist any data on the device. My use case requires to retrieve latest data from the server, therefore there is no need to keep a copy on the device - this is why Persistent checkbox is not set:


Next you will get similar wizard as in ADF BC, where all attributes for the service will be listed along with types, etc.:


I don't have any create/update/delete operations in the example, therefore only mapping present if for find operation:


Both REST resources were defined with attributes. We need to set the values later, for this purpose we could define ELExpression value provider for the attribute and type actual expression into Literal Value field. You could use any scope, I'm using applicationScope in this example. Variable defined by EL expression must be initialised before executing REST operation - this will be done later, in the code:


Six easy steps and AMPA persistence layer for MAF is generated. Let's take a quick look, what was actually generated. There is SQLite script with on device DB structure - two different tables will be created, each per REST service defined in the beginning:


In this example, I'm not really using on device DB, tables are not mandatory. Persistence mapping file is generated, this is where on device persistence structure and REST service mapping is defined. This mapping is used as a metadata resource to describe how data retrieved from REST service should be translated into on device persistence layer. I have set the option not to persist data, this will only retrieve it:


AMPA does a remote read in background by default - this means it reads data from REST, populates it into local SQLite DB and doesn't wait until operation is completed. This is good for performance optimisation reasons in some use cases, but is not suitable, when we want to see data immediately in the same request (especially when we are integrating AMPA into our own custom service class). Remote read in background can be turned off through persistence mapping:


Service class is generated, it extends from AMPA service. We could generate Data Control on top of this class and use it from MAF UI. However, I would like to integrate it into existing service class and consume from existing Data Control:


You could generate Data Control through JDEV menu, as displayed below.


In my case, I have Data Control already - generated on top of ServiceHelper class, I will reuse it. Here is the service class - ServiceHelper. In order to use AMPA generated service class and POJO types from existing service class, I have changed types for service class variables. Names and POJO structure remains the same, this means Data Control will continue to work:


Method responsible to search for employees by name is changed to invoke AMPA functionality. Instead of calling REST service and transforming response - I'm initialising EmployeeService generated by AMPA and calling findAllEmployeesRemote method. Remote method works with REST service, this is what we need - always fetch latest available data from the service:


You should notice how REST service variable is initialized - through EL Expression in application scope. This is the same expression as we have defined in resource mapper.

Here you can see how it look on UI. List of employees is filtered and displayed on the mobile device screen. Data from REST service is retrieved through AMPA, UI remains exactly the same as it was implemented in the previous version of the application:


Very important thing to mention - MAF Data Control is able to cache data by itself. Once you fetch data and if you don't require offline support, MAF Data Control is able to keep fetched rows in memory, without requiring them from the service.

For example, we fetch a set of rows with David Austin in the list:


There are two different MAF fragments (List and Edit), attached to the same Data Control. When we navigate to Edit and back to List, there is no REST call executed - MAF is using previously fetched data from Data Control (there is no need to use AMPA to handle such use cases):


Detail data for David Audit is retrieved from MAF Data Control:


You need to ensure - getter in service class implementing Data Control is not triggering a call to the REST service. REST service call must be invoked from Method Call, before MAF fragment is loaded - this will allow to prepare data in advance (see Task Flow diagram above):

Monday, March 9, 2015

Oracle Fusion Middleware Partner Community Award for Outstanding ACM/BPM Contribution 2015

We have received award for Outstanding ACM/BPM Contribution 2015. This award was given to me and my colleague - Danilo Schmiedel, for successful work in joint ACM/BPM and ADF projects, by Oracle Fusion Middleware Partner Community. Thanks and really proud to be a part of the community !


I'm looking forward to share interesting ideas about ADF/ACM/BPM/Mobile through this blog in the future.

Friday, March 6, 2015

Invoking REST Service from Oracle ACM Java Activity

In this post I will show you, how to call REST service from ACM Java activity class method. This could be useful in the situations, when you would like to have programmatic ACM activity integrated with REST service data. We could access ACM payload data from within the method overriden in the class implementing Case Activity Callback.

ACM activity implemented on top of Java class, contains the same properties and configuration as the regular one. You could define input/output data, execution properties, etc.:


Here is the Java code to invoke REST service from the Java class implementing ACM activity. I'm giving an example to parse ACM payload and access Last Name attribute. REST service is invoked through a library packaged with FMW 12c:


One important hint - you must place ACM activity class under SOA/src path (by default it goes into SOA/SCA-INF/src). This will ensure class will be compiled and executable on runtime:


REST Client library is referenced from FMW 12c installation, no need to add any external libraries:


Sample application implements Cancel Hotel Booking activity, the one which is based on Java class. It executes and calls a method:


Here is the output - Last Name printed out from the payload and REST service call result:


Here you can download sample application, this contains both REST service and ACM examples - HotelBookingProcessing_v2.zip. REST service application implementation - ADF BC Range Paging and REST Pagination. ACM application implementation - Adaptive Case Management 12c and ADF Human Tasks.