Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace image with code snippet: Build Microflow Actions with Java #9112

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 81 additions & 3 deletions content/en/docs/howto/extensibility/howto-connector-kit.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,34 @@ The Java implementation still uses strings to specify the name of an entity, whi

Finally, here's the actual Java implementation of the action defined:

{{< figure src="/attachments/howto/extensibility/howto-connector-kit/join_objects_javacode.png" alt="Java implementation join object" class="no-border" >}}
```java
public class JoinObjectsInList extends CustomJavaAction<java.util.List<IMendixObject>>
{
private java.lang.String Entity;
private IMendixObject Object1;
private IMendixObject Object2;

public JoinObjectsInList(IContext context, java.lang.String Entity, IMendixObject Object, IMendixObject Object2)
{
super(context);
this.Entity = Entity;
this.Object1 = Object1;
this.Object2 = Object2;
}

@Override
public java.util.List<IMendixObject> executeAction() throws Exception
{
// BEGIN USER CODE
List<IMendixObject> resultList = new ArrayList<IMendixObject>();
resultList.add(Objcet1);
resultList.add(Objcet2);

return resultList;
// END USER CODE
}
}
```

You now have a reusable action in your toolbox that will join two objects into a list as illustrated by this example:

Expand Down Expand Up @@ -99,7 +126,27 @@ In the Java implementation for this action, you'll see the following details for
* **InitializationMicroflow** – a string containing the name of the initializing microflow
* **ListSize** – a long variable containing the number of objects desired in the list

{{< figure src="/attachments/howto/extensibility/howto-connector-kit/initilialize_list_java_1.png" alt="Initialize list java implementation 1" class="no-border" >}}
```java
private java.lang.String ResultEntity;
private IMendixObject DefaultObject;
private java.lang.String InitializationMicroflow;
private java.lang.Long ListSize;

public CreateObjectList(
IContext context, java.lang.String ResultEntity,
IMendixObject DefaultObject,
java.lang.String InitializationMicroflow,
java.lang.Long ListSize
)
{
super(context);
this.ResultEntity = ResultEntity;
this.DefaultObject = DefaultObject;
this.InitializationMicroflow = InitializationMicroflow;
this,ListSize = ListSize;
}

```

The `executeAction` method is where all the magic happens:

Expand Down Expand Up @@ -184,7 +231,38 @@ Implement the action in Java as follows:
2. Use `Core.integration().importStream()` to import the JSON with the specified mapping.
3. Return the first object imported.

{{< figure src="/attachments/howto/extensibility/howto-connector-kit/import_string_java.png" alt="Import String Java action" class="no-border" >}}
```java
public ImportString(IContext context, java.lang.String InputString, java.lang.String ImportMapping, java.lang.String ResultEntity)
{
super(context);
this.InputString = InputString;
this.ImportMapping = ImportMapping;
this.ResultEntity = ResultEntity;
}

@Override
public IMendixObject executeAction() throws Exception
{
// BEGIN USER CODE
try (
InputStream is = new ByteArrayInputStream(this.InputString.getBytes(StandardCharsets.UTF_8))
){

// import the string by executing the mapping}
List<IMendixObject> Objects = Core.integration()
.importStream(getContext(), is, this.ImportMapping, null,false);

// Return first object created in mapping
return objects.get(0);
}
catch (Exception e) {
logger.error(e);

throw new MendixRuntimeException(String.format("Failed to import json string: %s",e.getMessage()))
}
// END USER CODE
}
```

## Some Development Tips

Expand Down