PI (Programming Interface) Activity

image0 The Program Interface Activity element is located in the Activity drawer of the process editor palette.

Element Details

The Program Interface Activity integrates custom-made software, legacy systems, proprietary applications or any other external system through a Java interface into the process workflow.

Scope

If you just need to call some Java code within your workflow, it’s normally preferrable to do this via the Script Step.

If not only Java code must be called, but process logic, too, you are better off with calling a re-usable Callable SubProcesses that wraps your complex logic.

Furthermore, Callable SubProcess Start elements contain an expressive input/output parameter descriptor. This infrastructure often makes the need for a hand-crafted configuration Editor obsolete. In addition, these starts can be enriched with an illustrative logo and will appear prominently as connectors in the palette if tagged as such.

Still, there might be edge cases where you prefer the programmable element infrastructure. For instance as you like the style, and already built up knowledge on it while implementing a Program Start or a Wait Program Intermediate Event bean.

Inscription

Start Tab

On this tab you define the Java class to be executed.

Start tab

Start tab

Java Class

Fully qualified name of the Java class that implements the IUserProcessExtension interface. Use the New Bean Class Wizard image2 to create a new Java source file with an example implementation of the bean class.

Program

Defines the Error Start element which can handle execution errors.

Timeout

Defines a timeout for the return call to the Java PI class. A timout error can be handled by a catching Error Start.

Editor Tab

The custom editor UI provided by the implementation of IUserProcessExtension allows to configure its execution.

Editor Tab

A custom editor example

Implementation

To initiate a custom bean implementation for your third party system, you start most conveniently by using the New Class image2 button on the Start Tab. The wizard will create a minimal sample implementation that works already. You can then adjust it to your needs.

API reference

The Program Interface consumes a Java class that implements the IUserProcessExtension interface. This implementation is responsible for defining the element execution behavior in the method perform of IUserProcessExtension. The common way to implement a Program Interface Bean is to extend from AbstractUserProcessExtension.

Custom configuration

Very likely, your Program Interface Activity implementation will accept configuration parameters defining the local environment. For instance, a system specific file to send to a legacy system.

We help you with these configurations by providing an accessor for static element configurations via getConfigurationProperty().

Custom editor

To define your custom configuration on the process inscription mask, you must supply an inner Editor class implementation. We recommend to extend your implementation from UiEditorExtension.

This editor class is responsible for two things: Firstly, to create UI widgets, which display configuration values. And secondly, to map configuration data onto these widgets:

1. The initUiFields method supports you in creating widgets for the editor. Currently labels, scriptEditors and textEditors are supported.

2. The ConfigurableExtensionEditor provides methods to read and write configurations, in order to bind them to previously created ui widgets.

Example implementation

 1package com.axonivy.wf.custom;
 2
 3import com.axonivy.erp.ErpFileService;
 4
 5import ch.ivyteam.ivy.process.engine.IRequestId;
 6import ch.ivyteam.ivy.process.extension.impl.AbstractUserProcessExtension;
 7import ch.ivyteam.ivy.process.extension.ui.ExtensionUiBuilder;
 8import ch.ivyteam.ivy.process.extension.ui.IUiFieldEditor;
 9import ch.ivyteam.ivy.process.extension.ui.UiEditorExtension;
10import ch.ivyteam.ivy.scripting.language.IIvyScriptContext;
11import ch.ivyteam.ivy.scripting.objects.CompositeObject;
12import ch.ivyteam.ivy.scripting.objects.File;
13
14public class ErpLoader extends AbstractUserProcessExtension {
15
16  @Override
17  public CompositeObject perform(IRequestId requestId, CompositeObject in, IIvyScriptContext context) throws Exception {
18    String pathScript = getConfigurationProperty(Config.PATH);
19    File statistics = (File) executeIvyScript(context, pathScript);
20    if (statistics.exists()) {
21      ErpFileService.instance().reportStats(statistics);
22    } else {
23      getLog(context).warn("Failed to resolve statistics file from "+pathScript);
24    }
25    return in;
26  }
27
28  public static class Editor extends UiEditorExtension {
29
30    private IUiFieldEditor filePath;
31
32    @Override
33    public void initUiFields(ExtensionUiBuilder ui) {
34      ui.label("The CSV statistic to report to Acme.ERP:").create();
35      filePath = ui.scriptField().requireType(File.class).create();
36    }
37
38    @Override
39    protected void loadUiDataFromConfiguration() {
40      filePath.setText(getBeanConfigurationProperty(Config.PATH));
41    }
42
43    @Override
44    protected boolean saveUiDataToConfiguration() {
45      clearBeanConfiguration();
46      setBeanConfigurationProperty(Config.PATH, filePath.getText());
47      return true;
48    }
49  }
50
51  private static interface Config {
52    String PATH = "path";
53  }
54
55}