How to Build and Run your first Command
1. What You Will Learn
After finishing this tutorial you will be able to write your own commands up to command groups, build them and integrate them into the PAK editor.
3. What is a Command?
A concrete implementation of a task. Commands are elements that are later displayed in the Construction Kit as part of the Palette in the editor.
4. Implementation
For the demonstration of the single steps in this tutorial the IDE IntelliJ is used. |
First open your selected IDE and create a new Gradle project with the following configuration:
By adding a sample code you will automatically get the desired folder structure |
Then replace the build.gradle file with the following code fragment:
plugins { id 'java-library' id 'maven-publish' } ext { version = '1.0.0' pakVersion = '1.5.14' } allprojects { project.description = 'Example Commands for PAK' project.group = 'org.example' project.version = rootProject.ext.version repositories { mavenCentral() maven { name = 'pak-explorer-maven' url 'https://pak.asap.de/nexus/repository/pak-explorer-maven/' } } } subprojects { apply plugin: 'java-library' apply plugin: 'maven-publish' compileJava.options.encoding = 'UTF-8' sourceCompatibility = 11 targetCompatibility = 11 javadoc { source = sourceSets.main.allJava } } dependencies{ // Dependencies provided by PAK annotationProcessor "de.asap.pak.jlcint:jlcint-processor:${pakVersion}" implementation "de.asap.pak.jlcint:jlcint-commandapi:${pakVersion}" implementation "de.asap.pak.core:pak-common:${pakVersion}" // Extern dependencies implementation 'org.slf4j:slf4j-api:1.7.25' } compileJava { options.compilerArgs.add("-Aversion=$project.version") options.compilerArgs.add("-Agroup=$project.group") options.compilerArgs.add("-Aname=$project.name") } javadoc { source = sourceSets.main.allJava options.tags = [ 'workflowDocu:cm:Workflow Developer Documentation:' ] } task metaJar(type: Jar) { archiveClassifier = 'pakmeta' from sourceSets.main.output include 'meta/**' include 'entities/**' from sourceSets.main.java include 'icon/**' } publishing () { publications { local(MavenPublication) { artifactId = project.name from components.java } } }
You can verify the successful loading of build.gradle using the Gradle toolbar on the right side. This should look like this:
Now we come to the coding of the HelloWorld command. For that you just have to replace the main class with the following class:
package org.example;
import de.asap.pak.jlcint.commandapi.CommandGroup;
import de.asap.pak.jlcint.commandapi.FieldScope;
import de.asap.pak.jlcint.commandapi.JavaCommand;
import de.asap.pak.jlcint.commandapi.Persistent;
import de.asap.pak.jlcint.commandapi.Run;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Sample implementation for a example command that input name and returns a simple output.
*
* The @JavaCommand annotation is necessary for the annotation processor to recognize this class as a command.
* If this is not set, no meta file will be generated!
*
* The @CommandGroup annotation is the described name that will be shown as group/cluster in the workflow editor.
*
* The @workflowDocu annotation describes what the element of the command is for. For classes it describes their
* whole purpose and for fields what are possible inputs and why you can do them.
*
*/
/**
* @workflowDocu Greets an entered name
*/
@JavaCommand
@CommandGroup("Example-Commands")
public class HelloWorld {
/**
* The LoggerFactory is a utility class producing Loggers for various logging APIs
*/
private static final Logger LOG = LoggerFactory.getLogger(HelloWorld.class);
/**
* The @Persistent annotation means that the value is read or saved from the data store. By default, any
* persistent variable is mandatory.
* This annotation provides many options, which are described in the JavaDoc.
*
*/
/**
* @workflowDocu Enter the name you want to greet
*/
@Persistent
private String input;
/**
*
* @workflowDocu The greeting
*/
@Persistent(scope = FieldScope.WRITE_ONLY)
private String output;
/**
* Methods that are annotated with @Run are executed when the task is called.
*
*/
@Run
public void run() {
this.output = "Hello " + input;
LOG.info(this.output);
}
}
Explanations about the individual annotations that can be used for command development can be found in the comments and in the PAK Command Developer Guide |
That’s all, our first command is implemented!
In order to use our new developed command we need to create jar out of it and publish it. (In our example we publish it to maven local)
5. Build a Bpmn Workflow
In order to use our new command in our workflow we need to setup the Commands Repositories for the PAK Editor app.
5.1. Setting Up the Commands
To do so open the menu Preferences
→ Repositories
Select the Folder Button
Select the .m2 folder of your users home and press the Add Button
Save the changes with the Save Changes Button
You can select any folder or directly the created jar-File. We are choosing this option just because we did so above. |
After adding the jar file you should be able to refresh the commands at the bottom left and see the following:
6. Next Steps
This guide covered the building and using a command in the PAK-editor. Now we are ready to run this workflow in our Application