This is a helper class for some of the other samples. This sample demonstrates how to implement reusable roster-specific methods which can be accessed by other classes or applications.
Note The sample code assumes you created a session and supplied a user name and password with appropriate access privileges.
The following sections describe the public RosterHelper(VWSession, Logger) class methods.
The RosterHelper(VWSession, Logger) constructor sets variables m_vwSession and m_logger to point to the vwSession and logger object arguments, as shown below:
m_vwSession = vwSession;
m_logger = logger;
Displays the process information from the items in the default roster with the following processing steps:
Validate the session pointer:
try {
if (m_vwSession == null){
m_logger.log("Invalid session: <null> (displayProcessInformation)");
return;
}
Use the m_vwSession.getRoster() method to get the roster object for the DefaultRoster:
vwRoster = m_vwSession.getRoster("DefaultRoster");
m_logger.log("Displaying process information for roster: " +
vwRoster.toString());
// Set the maximum number of items to 25, which requires less memory for each fetch than the default setting (50).
vwRoster.setBufferSize(25);
Construct a roster query object and query for all elements. The fetch type is denoted by "VWFetchType.FETCH_TYPE_ROSTER_ELEMENT".
rQuery = vwRoster.createQuery(null, null, null, 0, null, null, VWFetchType.FETCH_TYPE_ROSTER_ELEMENT);
Determine if any there any elements to retrieve with the query object, and get each roster element:
if (rQuery.hasNext()){
do
{
// Get each roster element.
rosterElement = (VWRosterElement)rQuery.next();
m_logger.log("\nVWProcess information for roster element:\n");
Obtain a object process from the roster element's first work object:
workObject = rosterElement.fetchWorkObject(false, false);
if (workObject != null)
process = workObject.fetchProcess();
if (process == null) continue;
Get workflow history & log key information from the process object.
Tip The mapId parameter is currently always -3 (PW version 4.0).
wflHistory = process.fetchWorkflowHistory(-3);
Log the launch date of the workflow.
m_logger.log("\tWorkflow Launch Date: " + wflHistory.getLaunchDate());
Log each of the step history element step IDs. Note the complementary use of the next() and hasNext() methods to control the loop:
m_logger.log("\n\tStep Histories:\n");
if (wflHistory.hasNext()) {
do {
stepHistory = wflHistory.next();
m_logger.log("\t\tStepId: " + stepHistory.getStepId());} while (wflHistory.hasNext());
} else {
m_logger.log("\t\tNo Step Histories exist.");
}
Log the lock state for each remaining work objects in this process.
m_logger.log("\n\tWork Objects:\n");
if (process.hasNext()) {do {
workObject = process.next();
m_logger.log("\t\tWork Object Id: " + workObject.getWorkObjectNumber());
// Get the lock state.
if (workObject.fetchLockedStatus() == 0)
m_logger.log("\t\t\tObject is not locked.");
else
m_logger.log("\t\t\tObject is locked.");} while (process.hasNext());
} else {
m_logger.log("\t\tNo Step Histories exist.");
}} while (rQuery.hasNext());
} else {
m_logger.log("\t No roster elements, therefore can't get VWProcess information.");
}
Handle any exceptions:
}
catch (Exception ex)
{
if (m_logger != null)
m_logger.log(ex);
else
ex.printStackTrace();
}
}
Displays the contents of the "DefaultRoster" with the following steps:
Get the roster object for the DefaultRoster.
vwRoster = m_vwSession.getRoster("DefaultRoster");
Log the roster depth.
m_logger.log("Roster element count: " + vwRoster.fetchCount());
Display the roster elements with a local method, as outlined below.
displayRosterElements(vwRoster);
Display the work objects with a local method.
displayWorkObjects(vwRoster);
Displays the VWRosterElements in the specified VWRoster object with the following processing steps:
Construct a roster query object to query for all elements.
for displayRosterElements()
ElemQuery = vwRoster.createQuery(null, null, null, 0, null, null, VWFetchType.FETCH_TYPE_ROSTER_ELEMENT);
for displayWorkObjects()
ElemQuery = vwRoster.createQuery(null, null, null, 0, null, null, VWFetchType.FETCH_TYPE_WORKOBJECT);
Fetch the first element using the VWRosterQuery object and casting to the appropriate object type.
for displayRosterElements()
Element = (VWRosterElement)ElemQuery.next();
for displayWorkObjects()
Element = (VWWorkObject)ElemQuery.next();
Check to see if there are any elements:
if (Element == null)
m_logger.log("\t Roster elements: none");
else
{
For each element, display the element information appropriately:
for displayWorkObjects()
do
{
// Display the work object information.
m_logger.displayWorkObjectInfo(vwWorkObject);
}
while ((vwWorkObject = (VWWorkObject)Element.next()) != null);
}
Additional code for displayWorkObjects() performs common error handling and cleanup.
for displayRosterElements()
// Initialize variables to hold the field names and each object value.
String[] fieldNames = null;
Object value = null;
// For each roster element, iteratively process fields:
do {
m_logger.log("\t Roster element:");
This step and the remaining steps apply to Roster elements only. Display the system-defined field names and user-defined exposed field names supported by the roster element:
fieldNames = Element.getFieldNames();
if (fieldNames == null)
{
m_logger.log("\t\t no Fields!");
}
else
{
m_logger.log("\t\t Fields:");
// For each field, iteratively display:
for (int i = 0; i < fieldNames.length; i++) {
if (fieldNames[i] != null){
value = Element.getFieldValue(fieldNames[i]);
// Display the field names and their values:
m_logger.log("\t\t\t" + fieldNames[i] + "=" + value);
}
}
}
Log specialized data available through VWRosterElement retrieval ("get") methods.
m_logger.log("\n\t\tOther Information:");
String bvalue = Element.getWorkObjectNumber();
m_logger.log("\t\t\t"+ "WorkObjectNumber" + "="
+ bvalue);
String svalue = Element.getWorkObjectName();
m_logger.log("\t\t\t"+ "WorkObjectName" + "="
+ svalue);
svalue = Element.getTag();
m_logger.log("\t\t\t"+ "Tag" + "=" + svalue);
int ivalue = Element.getServerLocation();
m_logger.log("\t\t\t"+ "CurrentServerLocation" + "="
+ ivalue);
}
while ((rosterElement = (VWRosterElement)rElemQuery.next()) != null);
}
Additional code in this sample performs exception handling and cleanup.