You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mendix provides the tools to enable Java developers to easily add powerful and robust new microflow actions to their Mendix toolbox. These microflow actions can be shared in the Mendix Marketplace, so anyone can benefit from them without having to know Java. This is particularly useful when building connectors to services.
11
+
Mendix offers tools that enable Java developers to seamlessly add powerful, and robust new microflow actions to their Mendix toolbox. You can share these microflow actions in the Mendix Marketplace allowing anyone to benefit from them without needing Java knowledge. This is especially useful when building connectors to services.
12
12
13
-
The diagram below illustrates the power of Mendix's integration with Java. It shows a Mendix Slack bot that enables users to determine things and people in pictures taken with a mobile Slack app:
13
+
The diagram below highlights the power of Mendix's integration with Java. It shows a Mendix Slack bot that enables users to identify objects and people in images taken with the mobile Slack app.
The Mendix application consists of a small number of microflows that use Mendix microflow actions to offer a conversational user interface using[Slack](https://slack.com/) and different Amazon services: [S3](https://aws.amazon.com/s3/), [Rekognition](https://aws.amazon.com/rekognition/), and [Lex](https://aws.amazon.com/lex/).
17
+
The Mendix application consists of a few microflows that use Mendix microflow actions to provide a conversational user interface through[Slack](https://slack.com/) and various Amazon services: [S3](https://aws.amazon.com/s3/), [Rekognition](https://aws.amazon.com/rekognition/), and [Lex](https://aws.amazon.com/lex/).
18
18
19
-
This image shows what the microflow toolbox looks like after including all the modules that provide connectors to the services used:
19
+
This image below illustrates the microflow toolbox after including all the modules that provide connectors to the services used:
For the basics of building toolbox actions, see the blog post [Introducing the Mendix Connector Kit](https://www.mendix.com/blog/introducing-mendix-connector-kit/).
24
24
25
-
This how-to teaches you how to do the following:
25
+
This document shows you how to do the following:
26
26
27
27
* Use advanced features when creating your own microflow actions
28
28
* Create the **Create object list** action
@@ -31,7 +31,7 @@ This how-to teaches you how to do the following:
31
31
32
32
## Creating Generic Actions Using Type Parameters
33
33
34
-
Let's start with type parameters. In the **Type parameters** tab in the Java action definition dialog box, you can use a type parameter if you want to ensure that certain parameters of your action share the same entity but you do not know the name of this entity when defining the actions.
34
+
In the **Type parameters** tab of the Java Action definition dialog box, you can use a type parameter to ensure that certain parameters of your action share the same entity, even if you do not yet know the name of that entity when defining the action.
35
35
36
36
For example, suppose you want to create an action that takes two objects of the same entity and returns a list containing both objects. You can use a type parameter to guarantee that both the input parameters for specifying the objects and the resulting list all use the same entity.
37
37
@@ -59,11 +59,42 @@ To create a generic action using type parameters, follow these steps:
59
59
60
60
The Java implementation still uses strings to specify the name of an entity, which means that you can upgrade your existing Java actions to use these new parameter types without having to refactor your existing code.
61
61
62
-
Finally, here's the actual Java implementation of the action defined:
62
+
Finally, here is the actual Java implementation of the action defined:
Here's an alternative to the microflow above that uses a custom Java action to replace the loop, instantiation, and initialization of the objects with a Java action:
109
+
Here is an alternative to the above microflow that uses a custom Java action to replace the loop, instantiation, and initialization of the objects with a Java action:
79
110
80
111
{{< figure src="/attachments/howto/extensibility/howto-connector-kit/init-list-use.png" alt="Init list loop with action" class="no-border" >}}
81
112
@@ -92,24 +123,44 @@ As you can see below, this action uses a new parameter type (**Microflow**) to i
92
123
93
124
{{< figure src="/attachments/howto/extensibility/howto-connector-kit/initialize_list_mf_pars.png" alt="Initialize list using microflow action parameters" class="no-border" >}}
94
125
95
-
In the Java implementation for this action, you'll see the following details for the parameters:
126
+
In the Java implementation for this action, see the following details for the parameters:
96
127
97
128
***ResultEntity** – a string with the entity name used for the default object and the result list
98
-
***DefaultObject** – an IMendixObject instance containing the default object
129
+
***DefaultObject** – an `IMendixObject` instance containing the default object
99
130
***InitializationMicroflow** – a string containing the name of the initializing microflow
100
131
***ListSize** – a long variable containing the number of objects desired in the list
101
132
102
-
{{< figure src="/attachments/howto/extensibility/howto-connector-kit/initilialize_list_java_1.png" alt="Initialize list java implementation 1" class="no-border" >}}
The `executeAction` method is where all the magic happens:
155
+
The `executeAction` method handles the main functionality:
105
156
106
-
1. It initializes an ArrayList for the result.
107
-
2.It has a for-loop to create the desired number of objects.
108
-
3.The objects are created using `Core.instantiate()`. The entity name specified in the action is used as the input to specify what entity to instantiate.
109
-
4.The system determines if a default object was specified. If so, it copies all the attribute values to the new object.
110
-
5. The system executes the initialization microflow using `Core.microflowCall()`.
157
+
1. It initializes an `ArrayList` to store the results.
158
+
2.A `for`loop runs to create the desired number of objects.
159
+
3.Each object is created using `Core.instantiate()` with the entity name specified in the action used as the input to specify which entity to instantiate.
160
+
4.If a default object is defined, its attribute values are copied to the new object.
161
+
5. The system then executes the initialization microflow using `Core.microflowCall()`.
111
162
6. The newly instantiated and initialized object is added to the result list.
112
-
7.The list of new objects is returned.
163
+
7.Finally, the method returns the list of newly created objects.
113
164
114
165
```java
115
166
@Override
@@ -161,13 +212,13 @@ Microflow parameters are especially useful for handling events. For example, the
161
212
162
213
## Using Import and Export Mappings
163
214
164
-
Now we will discuss an example of how you can use mappings in your Java actions. In this example, you'll create an action to import a string using an import mapping. This is not particularly useful, seeing there is a default action in your toolbox already that provides this functionality called **Import with mapping**. However, as an example, it illustrates how to use mappings.
215
+
In this section, you can see how to use mappings in your Java actions. In this example, you will create an action to import a string using an import mapping. This is not particularly useful, seeing there is a default action in your toolbox already that provides this functionality called **Import with mapping**. However, as an example, it illustrates how to use mappings.
165
216
166
-
This is an image of what we are building: an action to import JSON strings:
217
+
This is an image of what we are building: an action to import JSON strings.
The action requires the user to provide a string with the JSON to import, select an import mapping, and define the entity of the result. Finally, a name needs to be provided for the result of the import mapping.
221
+
The action requires the user to provide a string with the JSON to import, select an import mapping, and define the entity of the result. Finally, provide a name for the result of the import mapping.
171
222
172
223
The action is defined as follows:
173
224
@@ -180,22 +231,54 @@ The action is defined as follows:
180
231
181
232
Implement the action in Java as follows:
182
233
183
-
1. Create an InputStream from the JSON input so it can be read by the import mapping.
234
+
1. Create an `InputStream` from the JSON input so it can be read by the import mapping.
184
235
2. Use `Core.integration().importStream()` to import the JSON with the specified mapping.
try (InputStream is =newByteArrayInputStream(this.InputString.getBytes(StandardCharsets.UTF_8))) {
257
+
258
+
// Import the string by executing the mapping
259
+
List<IMendixObject> objects =Core.integration().importStream(getContext(), is, this.ImportMapping, null, false);
260
+
261
+
// Return first object created in mapping
262
+
return objects.get(0);
263
+
264
+
} catch (Exception e) {
265
+
logger.error(e);
266
+
thrownewMendixRuntimeException(String.format("Failed to import JSON string: ", e.getMessage()));
267
+
}
268
+
// END USER CODE
269
+
}
270
+
```
188
271
189
-
## Some Development Tips
272
+
## Development Tips
190
273
191
274
### Unit Testing
192
275
193
-
When developing connector modules, you can use the unit test module to test the actions you are implementing.
276
+
When developing connector modules, you can use the [Unit Testing](https://marketplace.mendix.com/link/component/390) module to test the actions you are implementing.
194
277
195
278
If you want to publish your module with custom microflow actions to the Mendix Marketplace for easy reuse, it's best to have a module containing only the reusable parts. Add another module to your app with all the test microflows and anything else you need
196
279
while developing your application.
197
280
198
-
In the screenshot below, observe two important points. First, the **ConnectorKitDemo** module only contains the actions you want to publish to the Marketplace. To do this, right-click the module and select **Export module package...**. Second, the **ConnectorKitDemoTests** module contains all the functionality you need while developing the reusable module: a small domain model with some sample data and some test pages. It also contains the unit test microflow **Test_InitProduct**, which will be called by the unit test module.
281
+
In the screenshot below, observe two important points. First, the **ConnectorKitDemo** module only contains the actions you want to publish to the Marketplace. To do this, right-click the module and select **Export module package...**. Second, the **ConnectorKitDemoTests** module contains all the functionality you need while developing the reusable module: a small domain model with some sample data and some test pages. It also contains the unit test microflow **Test_InitProduct**, which will be called by the [Unit Testing](/appstore/modules/unit-testing/) module.
0 commit comments