iKnowBase Process Services for Activiti

The iKnowBase Process Services for Activiti is a set of tools and techniques that enables the building of process-centric applications using the combined power of iKnowBase® and Activiti®. The iKnowBase Process Services for Activiti comprises the following items:

Preparations

In order to use the iKnowBase Process Services for Activiti, the following must be done:

Developing process applications

Developing process applications typically comprises the following steps:

The iKnowBase applications may also be implemented in Java.

The integration mechanisms between the two technologies (iKnowBase and Activiti) are kept intentionally simple:

Your process data will be available in iKnowBase Process Studio.

Accessing Activiti data from a Template Viewer

This groovy script shows the fundamentals of accessing and presenting data from an iKnowBase component:

// Prepare some utitlity variables 
def engine = bpmClient.activitiEngine

// Create a query using Activiti apis, and load data
def query = engine.historyService.createHistoricProcessInstanceQuery().startedBy("orcladmin").orderByProcessInstanceId().desc()
def rowcount = query.count()
def instances = query.listPage(1, 20)

// Render data using the groovy MarkupBuilder which is automatically supplied
html.div {
    h1 ("Process instances started by orcladmin, ordered by processInstanceId (rows 1-20)")
    table {
        tr {
            th ("Process Definition Id")
            th ("Process Instance Id")
            th ("Start time")
        }
        instances.each { instance ->
            tr {
                th (instance.processDefinitionId)
                th (instance.id)
                th (instance.startTime)
            }
        }
    }
}

Accessing iKnowBase data from a ScriptTask

This groovy script shows the fundamentals of accessing and working with iKnowBase data from an Activiti ScriptTask:

import com.iknowbase.api.contentservices.v2.model.*

// Init
def userref = new UserReference().withUsername(initiator)
def docref = new DocumentReference().withId(ikbDocumentId)

def document = iknowbase.documentService.getDocument(
    userref,
    docref,
    GetOperationEnumeration.MIN,
    GetOperationEnumeration.NONE,
    GetOperationEnumeration.NONE
)

document.setDescription(document.getDescription() + "<p>Activiti process: Document approved</p>")

iknowbase.documentService.saveDocument(
  userref,
  document,
  SaveOperationEnumeration.MERGE,
  SaveOperationEnumeration.NONE,
  SaveOperationEnumeration.NONE,
  null, null, null, false
)

Using a form to start processes and complete UserTasks

First, define an Activiti StartEvent or UserTask with the relevant form properties. The XML below is an extract from the Activiti BPMN definition:

<userTask id="registerissue" name="Register issue" activiti:assignee="${initiator}"
          activiti:formKey="urn:iknowbase:form:guid:C26AD8CA297355DCE040000A180062E2">
    <extensionElements>
        <activiti:formProperty id="hdTitle" name="Title" type="string" required="true"></activiti:formProperty>
        <activiti:formProperty id="hdDescription" name="Description" type="string"></activiti:formProperty>
        <activiti:formProperty id="hdPriority" name="Priority" type="long"></activiti:formProperty>
        <activiti:formProperty id="hdCategory" name="Category" type="long"></activiti:formProperty>
    </extensionElements>
</userTask>

Then, in iKnowBase, define a page with an Activity Task Form component based on a FreeMarker template such as this one:

[#macro showForm]
<h2>Comments</h2>
[@form.form]
    <table>
	<tr>
		<td>[@form.label bind="task.hdTitle" /]</td>
		<td>[@form.input name="task.hdTitle" /]</td>
	</tr>
	<tr>
		<td>[@form.label bind="task.hdDescription" /]</td>
		<td>[@form.input name="task.hdDescription" type="textarea" /]</td>
	</tr>
	<tr>
		<td>[@form.label bind="task.hdPriority" /]</td>
		<td>[@form.input name="task.hdPriority" type="select" attribute="IKB_PRIORITY" /]</td>
	</tr>
	<tr>
		<td>[@form.label bind="task.hdCategory" /]</td>
		<td>[@form.input name="task.hdCategory" type="select" attribute="IKB_SUBJECT"  /]</td>
	</tr>
    </table>
    [@form.button name="submit"      action="submit" attributes='accesskey="x"'      ]Complete task[/@form.button]
[/@form.form]
[/#macro]

[#macro thankyou]
<h1>Thank you!</h1>
<p>Your comment has been submitted. Click to view
<a href="/dev/activiti/processdefinitions/processinstance?processInstanceId=${form.data["task"].processInstanceId}">process details</a>.</p>
[/#macro]

[#if form.currentCommand.action! == 'submit']
    [@thankyou /]
[#else]
    [@showForm /]
[/#if]


A couple of items of interest:

See the chapter Activiti Form Viewer in iKnowBase API Reference for further details.

Associating an Activiti Process with an iKnowBase Document

For associating an Activiti process instance with an iKnowBase document, we recommend that you use a process instance variable named “documentId” of type “long”. iKnowBase Process Studio provides filtering mechanisms for this variable.