In this article:
Overview - Basic overview of the Java Invocation Custom Activity
Creating a new Java Invocation activity - How to create a new Java Invocation custom activity
Using the Custom Java Invocation Activity - Adding the activity to a workflow and using it
Overview
The workflow designer supports the creation of custom activities. One such custom activity is the Java Invocation custom activity. This facilitates the execution of Java methods during the workflow execution. Any Java method that exists in any of the referenced class libraries that ship as part of the Adaptiva product set can be referenced, including Adaptiva's own classes.
Creating a new Java Invocation activity
In this very simple example, we are going to use a java lang class called Math (java.lang.Math) to round up a decimal number to the nearest whole number.
Setting the Activity Details
To create a new Java Invocation activity, first ensure the Workflow Designer Palette tab is selected.
Note: If the Workflow Designer Palette tab is not shown in the workflow designer, it must have been closed. On the top toolbar, select Perspective > Reset Perspective.
Next, right-click on any palette folder (including the Workflow Activities root folder) and select New > Java Invocation activity.
A new Window will appear requesting either a java class by name or the path to a java class file.
If Choose java class is specified then a file browser dialogue will open requesting that an applicable java .class file be selected.
For this example, we will select Specify java class and in the textbox we will enter java.lang.Math.
Please note that java is case sensitive so java.lang.Math and java.lang.math are not the same.
If the class could not be found or an invalid java class was entered, an exception dialogue box will appear saying that the class could not be loaded:
If a valid class was found then a new Java Activity window will open which will list all of the available methods contained in that class.
Provide the following details:
Activity Name: The name of the activity as it will appear in the workflow designer palette activity list. Example: RoundNumber
Activity Description: A description of what the activity will do. This text will appear when the activity is hovered over with the mouse cursor in the activity list. Example: Rounds up the specified decimal number to the nearest whole number
Node Name Prefix: The name that will appear when the activity is dragged onto the designer canvas. The name is always proceeded with a number. Example: A node name prefix of "RoundUp" will show on the canvas as RoundUp1, RoundUp2 etc.
Adding the Method(s)
It is now time to select one or multiple methods contained in this class. These will appear as different operations in the workflow designer properties that can be selected at design time.
For this example, we want to perform the round function so we scroll down until we see round in the list.
Here we can see that there are two methods called round. There is round and round2. Any method that has a number on the end indicates that there are multiple overloads for the same method. Both round and round2 are the same function, but they take different input properties. In the third column we see the input properties that are required. We see that round takes a float datatype input property and round2 takes a double datatype input property.
In our example we want to round a decimal number so we select round2 from the list.
When we select round2, a Method parameters box appears requesting that we enter a name for the parameter. This is the input property for the number that we want to perform the round operation on. We just need to enter something descriptive for this, to act as a prompt at design time for what to enter in this field.
We will give this the descriptive name NumberToRound.
After clicking OK on the method parameters window and the Java Activity window, a new activity gets added to our workflow designer palette called RoundNumber. We are then in a position to add this to a workflow.
Using the Custom Java Invocation Activity
Once the Java Invocation activity has been created it will appear within the Workflow Designer Palette.
To use the activity, simply drag and drop it into a new or existing workflow. The activity can be used as many times as desired either within multiple workflows or the same workflow.
The java invocation activity is added to the workflow and the built-in properties are listed on the right-hand side in the Workflow Designer properties window. This shows the ClassName for the class that was added and initially has a single input - the Operation.
Selecting the drop-down for Operation will reveal all of the methods that were previously selected. In the case of the example, there is just one method round2. Selecting this will reveal two new properties:
NumberToRound - the input property that we specified earlier. This should be a fractional number to round up.
Result - the output property containing the rounded number. Note that this rounded number data type is now a WHOLE NUMBER rather than a FRACTIONAL NUMBER as it has now been rounded.
We are going to enter the number 3.141 in the NumberToRound Initial value box.
In this example, a logger activity will be placed just after the RoundUp1 activity so that we can capture the results of the round up.
The logger activity uses the following runtime expression:
"Before Round: 3.141
After Round: " + RoundUp1.Result
The workflow is then given a name and then Saved and Deployed (with logging enabled)
The workflow is then executed. The workflow log file shows the output.
Note: The workflow logs can be found in the workflowlogs folder on either client or server (for business/server workflows the workflowlogs folder will be in the Server logs folder [default: C:\Program Files\Adaptiva\AdaptivaServer\logs\workflowlogs]. For client workflows, the workflowlogs folder will be in the Client logs folder [default: C:\Program Files (x86)\Adaptiva\AdaptivaClient\logs\workflowlogs]).
The workflow log name will match the name given to the workflow
We can see from the output that the number 3.141 has been successfully rounded to the nearest whole number 3.
The workflow and Java Invocation activity examples used in this article can be downloaded from the link below. Import the obex file using the Object Export-Import perspective in the Adaptiva Workbench.
Comments
0 comments
Please sign in to leave a comment.