Create an ADF ViewObject based on BPEL’s HumanWorkflow Tasklist
A few posts ago I blogged about how you can access BPEL HumanWOrkflow with a standalone Java program. In this post I will go one step further and show you how you can create a viewobject based on the HumanWorkFlowReader. You can use this viewobject for example in your JHeadstart Application Definition file so you can generate a JSF page to browse through the HumanWorkflow tasks.
The base for this post is this one, to create a standalone HumanWorkflowReader. If you have this in place (or something similar) then it is time to create the view object (I have based this viewobject on an example of Steve Muench. It is based on the class ‘SRStaticDataViewObjectImpl’, which is supplied with this example of Steve).
The most important thing is that the viewobject is not based on a query, but is programmaticaly supplied with rows, as shown in the next figure:

As an example I have created 3 attributes for this viewobject:



After the viewobject is created, open the Java class of the ViewObject, in this example called TaskListViewObjImpl.java. The following methods must be implemented:
protected void executeQueryForCollection(Object rowset, Object[] params, int UserParams)
protected void create()
protected ViewRowImpl createRowFromResultSet(Object rowset, ResultSet rs)
public long getQueryHitCount(ViewRowSetImpl viewRowSet)
I have the code for the complete class here (with several helper methods):
-
package com.test.model.dataaccess;
-
-
import base.util.DateUtils;
-
import java.sql.ResultSet;
-
import java.util.List;
-
import net.pascalalma.bpel.HumanWorkflowServices;
-
import oracle.bpel.services.workflow.task.model.Task;
-
import oracle.bpel.services.workflow.verification.IWorkflowContext;
-
import oracle.jbo.server.ViewRowImpl;
-
import oracle.jbo.server.ViewRowSetImpl;
-
-
// ———————————————————————
-
// — File generated by Oracle ADF Business Components Design Time.
-
// — Custom code may be added to this class.
-
// — Warning: Do not modify method signatures of generated methods.
-
// ———————————————————————
-
public class TaskListViewObjImpl extends ViewObjectImpl
-
{
-
private int _rows = -1;
-
/**This is the default constructor (do not remove)
-
*/
-
public TaskListViewObjImpl()
-
{
-
}
-
-
/**
-
* Overridden framework method
-
*
-
* This is the framework "pinch point" for all query execution.
-
* The fact that we have nulled out all traces of a query
-
* in the create() method will mean that the framework doesn’t actually
-
* perform any query during this setup.
-
*
-
* @param rowset the query collection about to execute the query.
-
* @param params the bind parameters that will be applied to the query.
-
* @param noUserParams the number of user bind parameters supplied
-
* through the setWhereClauseParam calls.
-
*/
-
{
-
// Initialize our fetch position for the query collection
-
initializeData();
-
// Set indicator if rows are available
-
_rows = (_list != null) ? _list.size() : 0;
-
// Set the curRec position
-
setFetchPos(rowset, 0);
-
-
super.executeQueryForCollection(rowset, params, noUserParams);
-
}
-
-
/**
-
* Overridden framework method
-
*
-
* The framework calls this method to support the hasNext() method on
-
* the rowset iterator for a rowset created from this view object.
-
* We return true if our fetchPosition is still less than the _rows in
-
* our in-memory data arrays
-
*
-
* @param rowset The current query collection based on this view object
-
* @return true if there are more _rows still to fetch.
-
*/
-
{
-
return getFetchPos(rowset) <_rows;
-
}
-
-
/**
-
* Overridden framework method.
-
*
-
* Populates the "fetched" data for one row when the framework asks us to.
-
* We get the data from the list with ‘BpelTasks’ and create a TakenlijstViewRowImpl
-
* for it. We ignore the resultSet passed in which will be null
-
* since there is no real query going on here to get the data.
-
*
-
* @param rowset The current query collection based on this view object
-
* @param rs The JDBC result set being used to fetch data from
-
* @return Next view row fetched from this rowset
-
*/
-
{
-
// Create and populate a new row
-
ViewRowImpl r = createNewRowForCollection(rowset);
-
int pos = getFetchPos(rowset);
-
// Get the task for the current row
-
Task currentTask = (Task)_list.get(pos);
-
// Now copy the fields from the task to the viewobject row.
-
populateAttributeForRow(r, TaskListViewObjRowImpl.ID, currentTask.getSystemAttributes().getTaskId());
-
populateAttributeForRow(r, TaskListViewObjRowImpl.TASKNUMBER ,Integer.toString(currentTask.getSystemAttributes().getTaskNumber()));
-
populateAttributeForRow(r, TaskListViewObjRowImpl.CREATIONDATE, DateUtils.getOraDate(currentTask.getSystemAttributes().getCreatedDate()) ) ;
-
-
setFetchPos(rowset, pos + 1);
-
return r;
-
}
-
-
/**
-
* Overridden framework method.
-
*
-
* When this VO component is created, we load the data from properties file.
-
*
-
* This method is called once when the VO is first instantiated.
-
*/
-
protected void create()
-
{
-
super.create();
-
// Setup string arrays of codes and values from VO custom properties
-
// Wipe out all traces of a query for this VO
-
getViewDef().setQuery(null);
-
getViewDef().setSelectClause(null);
-
setQuery(null);
-
}
-
-
/**
-
* Overridden framework method.
-
*
-
* If anyone asks for a getEstimatedRowCount() on this VO, we’ll return
-
* the number of _rows we read from the property file.
-
*
-
* @param viewRowSet The current set of view _rows
-
* @return Count of _rows read from the properties file
-
*/
-
public long getQueryHitCount(ViewRowSetImpl viewRowSet)
-
{
-
return _rows;
-
}
-
-
/**
-
* Override to initialize the static data for this view object.
-
*/
-
protected void initializeData()
-
{
-
IWorkflowContext ctx = HumanWorkflowServices.authenticate(“oc4jadmin”,“ias_admin1″,“jazn.com”, null);
-
_list = HumanWorkflowServices.getTaskList( ctx );
-
}
-
-
/**
-
* Set the current fetch position for the query collection
-
*
-
* Since one view object can be used to create multiple rowsets, we
-
* need to keep track our current position in the rowset in the
-
* per-rowset "user data" that the framework allows us to store as
-
* context information.
-
*/
-
{
-
if (pos == _rows)
-
{
-
setFetchCompleteForCollection(rowset, true);
-
}
-
}
-
-
/**
-
* Get the current fetch position for the query collection
-
*
-
* This returns the fetch position for the current rowset in question
-
* by retrieve the user data we stored in the context.
-
*/
-
{
-
}
-
}
Although this will work there are a few improvements possible and maybe necessary.
The first one is the call to the authenticate method to obtain a context. It would be better if we cache the obtained context in the session scope so next time the query is performed the context is taken from the cache. This will improve the performance and reduce the network traffic.
The second one is the addition of a bind parameter with which we can determine whose tasks are shown in the viewobject. Now we will see all tasks belonging to oc4jadmin, but in real life you probably just want to show the task belonging to the logged-in web user (or his group).
For now I stop at this point. Next time I will show you how you can implement the two improvements.
Tags: Oracle BPEL, Oracle JHeadstart









