Skip to content

Commit

Permalink
fix(elementTemplate): edit element-template-generation-plugin (#365)
Browse files Browse the repository at this point in the history
* better visibility if a field is a `inputParameter` or `outputParameter`
* it is now only possible to give one `targetPlatform`
* interrupt generation and log error when no `targetPlatform` is given
* set `version` type to `int` and make it optional
* remove `targetPlatform` as output directory
* add configuration for naming the input value
  • Loading branch information
peterhnm authored May 29, 2024
1 parent bfe9320 commit 132afea
Show file tree
Hide file tree
Showing 23 changed files with 567 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
*
* @return the version of the element template
*/
String version() default "0-1";
int version() default -1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
public class Camunda7ElementTemplateGenerator implements ElementTemplateGenerator {

@Override
public ElementTemplateGenerationResult generate(ElementTemplateInfo elementTemplateInfo) {
public ElementTemplateGenerationResult generate(ElementTemplateInfo elementTemplateInfo, InputValueNamingPolicy inputValueNamingPolicy) {
var elementTemplate = new CamundaC7ElementTemplate()
.withName(elementTemplateInfo.getName())
.withId(elementTemplateInfo.getId())
.withAppliesTo(Collections.singletonList(BPMNElementType.BPMN_SERVICE_TASK.getValue()));

if (elementTemplateInfo.getVersion() > 0) {
elementTemplate.setVersion((double) elementTemplateInfo.getVersion());
}

// Add external task property
var implementationProperty = createExternalTaskProperty();
elementTemplate.getProperties().add(implementationProperty);
Expand All @@ -31,38 +35,54 @@ public ElementTemplateGenerationResult generate(ElementTemplateInfo elementTempl

// Add properties for input parameters
for (var inputProperty : elementTemplateInfo.getInputProperties()) {
var property = createPropertyWithValue(inputProperty, false);
var property = createInputParameterProp(inputProperty, inputValueNamingPolicy);
elementTemplate.getProperties().add(property);
}

// Add properties for output parameters
for (var outputProperties : elementTemplateInfo.getOutputProperties()) {
var property = createPropertyWithValue(outputProperties, true);
var property = createOutputParameterProp(outputProperties);
elementTemplate.getProperties().add(property);
}

var json = CamundaC7ElementTemplateConverter.toJsonString(elementTemplate);
return new ElementTemplateGenerationResult(elementTemplateInfo.getId(), elementTemplateInfo.getVersion(), json, TargetPlatform.camunda7);
return new ElementTemplateGenerationResult(elementTemplateInfo.getId(), elementTemplateInfo.getVersion(), json, TargetPlatform.C7);
}

private Property createPropertyWithValue(ElementTemplatePropertyInfo info, boolean output) {
var value = output ? info.getLabel() + "Result" : "";
var bindingType = output ? Binding.Type.CAMUNDA_OUTPUT_PARAMETER : Binding.Type.CAMUNDA_INPUT_PARAMETER;
private Property createInputParameterProp(ElementTemplatePropertyInfo info, InputValueNamingPolicy inputValueNamingPolicy) {
var property = new Property()
.withLabel(info.getLabel())
.withLabel("Input: %s".formatted(info.getLabel()))
.withValue(switch (inputValueNamingPolicy) {
case EMPTY -> "${}";
case ATTRIBUTE_NAME -> "${%s}".formatted(info.getName());
})
.withType(info.getType().getType())
.withChoices(null)
.withBinding(new Binding()
.withType(bindingType))
.withValue(value);
.withType(Binding.Type.CAMUNDA_INPUT_PARAMETER)
.withName(info.getName()));

if (!info.isNotEmpty()) {
property.setConstraints(new Constraints()
.withNotEmpty(info.isNotEmpty()));
}

if (output) {
property.getBinding().setSource("${" + info.getLabel() + "}");
} else {
property.getBinding().setName(info.getName());
if (!info.isEditable()) {
property.setEditable(info.isEditable());
}

// Only set if false, else jackson will display default value in generated json
return property;
}

private Property createOutputParameterProp(ElementTemplatePropertyInfo info) {
var property = new Property()
.withLabel("Output: %s".formatted(info.getLabel()))
.withValue(info.getName())
.withType(info.getType().getType())
.withChoices(null)
.withBinding(new Binding()
.withType(Binding.Type.CAMUNDA_OUTPUT_PARAMETER)
.withSource("${%s}".formatted(info.getName())));

if (!info.isNotEmpty()) {
property.setConstraints(new Constraints()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.miragon.miranum.connect.elementtemplate.c7.Camunda7ElementTemplateGenerator;
import io.miragon.miranum.connect.elementtemplate.core.ElementTemplateInfo;
import io.miragon.miranum.connect.elementtemplate.core.ElementTemplateInfoMapper;
import io.miragon.miranum.connect.elementtemplate.core.InputValueNamingPolicy;
import org.junit.jupiter.api.Test;

import java.io.IOException;
Expand All @@ -25,15 +26,15 @@ void generateCamunda7ElementTemplate_withValidInput_shouldReturnValidOutputWithI
"Test",
"test",
"test",
"0-1",
-1,
"test",
ElementTemplateInfoMapper.mapTypeToElementTemplateInfos(TestInput.class),
ElementTemplateInfoMapper.mapTypeToElementTemplateInfos(TestOutput.class));

var expectedJsonResult = Files.readString(Path.of("./src/test/resources/expected-test-element-template.json"));

// Act
var result = camunda7ElementTemplateGenerator.generate(elementTemplateInfo);
var result = camunda7ElementTemplateGenerator.generate(elementTemplateInfo, InputValueNamingPolicy.EMPTY);

// Assert
assertNotNull(result.getJson());
Expand All @@ -48,15 +49,15 @@ void generateCamunda7ElementTemplate_withNoInputAndOutputTypes_shouldReturnValid
"Test",
"test",
"test",
"0-1",
-1,
"test",
new ArrayList<>(),
new ArrayList<>());

var expectedJsonResult = Files.readString(Path.of("./src/test/resources/expected-test-element-template-no-input-and-output.json"));

// Act
var result = camunda7ElementTemplateGenerator.generate(elementTemplateInfo);
var result = camunda7ElementTemplateGenerator.generate(elementTemplateInfo, InputValueNamingPolicy.EMPTY);

// Assert
assertNotNull(result.getJson());
Expand All @@ -72,15 +73,63 @@ void generateCamunda7ElementTemplate_withAnnotatedInputProperties_shouldReturnVa
"Test",
"test",
"test",
"0-1",
-1,
"test",
ElementTemplateInfoMapper.mapTypeToElementTemplateInfos(TestInputWithElementTemplatePropertyAnnotation.class),
ElementTemplateInfoMapper.mapTypeToElementTemplateInfos(TestOutput.class));

var expectedJsonResult = Files.readString(Path.of("./src/test/resources/expected-test-element-template-with-annotated-input-properties.json"));

// Act
var result = camunda7ElementTemplateGenerator.generate(elementTemplateInfo);
var result = camunda7ElementTemplateGenerator.generate(elementTemplateInfo, InputValueNamingPolicy.EMPTY);

// Assert
assertNotNull(result.getJson());
assertEquals(expectedJsonResult, result.getJson());
}

@Test
void generateCamunda7ElementTemplate_withNoInputAndOutputTypes_shouldReturnValidOutputWithVersion() throws IOException {
// Arrange
Camunda7ElementTemplateGenerator camunda7ElementTemplateGenerator = new Camunda7ElementTemplateGenerator();
var elementTemplateInfo = new ElementTemplateInfo(
"Test",
"test",
"test",
1,
"test",
new ArrayList<>(),
new ArrayList<>()
);

var expectedJsonResult = Files.readString(Path.of("./src/test/resources/expected-test-element-template-with-version.json"));

// Act
var result = camunda7ElementTemplateGenerator.generate(elementTemplateInfo, InputValueNamingPolicy.EMPTY);

// Assert
assertNotNull(result.getJson());
assertEquals(expectedJsonResult, result.getJson());
}

@Test
void generateCamunda7ElementTemplate_withValidInput_shouldReturnValidOutputWithNamedInputValues() throws IOException {
// Arrange
Camunda7ElementTemplateGenerator camunda7ElementTemplateGenerator = new Camunda7ElementTemplateGenerator();
var elementTemplateInfo = new ElementTemplateInfo(
"Test",
"test",
"test",
-1,
"test",
ElementTemplateInfoMapper.mapTypeToElementTemplateInfos(TestInput.class),
new ArrayList<>()
);

var expectedJsonResult = Files.readString(Path.of("./src/test/resources/expected-test-element-template-with-named-input-values.json"));

// Act
var result = camunda7ElementTemplateGenerator.generate(elementTemplateInfo, InputValueNamingPolicy.ATTRIBUTE_NAME);

// Assert
assertNotNull(result.getJson());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
"name" : "camunda:topic"
}
}, {
"value" : "",
"label" : "Property1",
"value" : "${}",
"label" : "Input: Property1",
"type" : "Text",
"binding" : {
"type" : "camunda:inputParameter",
"name" : "name"
}
}, {
"value" : "",
"label" : "Property2",
"value" : "${}",
"label" : "Input: Property2",
"type" : "String",
"binding" : {
"type" : "camunda:inputParameter",
Expand All @@ -41,16 +41,16 @@
"notEmpty" : false
}
}, {
"value" : "nameResult",
"label" : "name",
"value" : "name",
"label" : "Output: name",
"type" : "String",
"binding" : {
"type" : "camunda:outputParameter",
"source" : "${name}"
}
}, {
"value" : "idResult",
"label" : "id",
"value" : "id",
"label" : "Output: id",
"type" : "String",
"binding" : {
"type" : "camunda:outputParameter",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema" : "https://unpkg.com/@camunda/[email protected]/resources/schema.json",
"name" : "Test",
"id" : "test",
"appliesTo" : [ "bpmn:ServiceTask" ],
"properties" : [ {
"value" : "external",
"label" : "Implementation Type",
"type" : "String",
"editable" : false,
"binding" : {
"type" : "property",
"name" : "camunda:type"
}
}, {
"value" : "test",
"label" : "Topic",
"type" : "String",
"editable" : false,
"binding" : {
"type" : "property",
"name" : "camunda:topic"
}
}, {
"value" : "${name}",
"label" : "Input: name",
"type" : "String",
"binding" : {
"type" : "camunda:inputParameter",
"name" : "name"
}
}, {
"value" : "${id}",
"label" : "Input: id",
"type" : "String",
"binding" : {
"type" : "camunda:inputParameter",
"name" : "id"
}
} ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema" : "https://unpkg.com/@camunda/[email protected]/resources/schema.json",
"name" : "Test",
"id" : "test",
"version" : 1.0,
"appliesTo" : [ "bpmn:ServiceTask" ],
"properties" : [ {
"value" : "external",
"label" : "Implementation Type",
"type" : "String",
"editable" : false,
"binding" : {
"type" : "property",
"name" : "camunda:type"
}
}, {
"value" : "test",
"label" : "Topic",
"type" : "String",
"editable" : false,
"binding" : {
"type" : "property",
"name" : "camunda:topic"
}
} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@
"name" : "camunda:topic"
}
}, {
"value" : "",
"label" : "name",
"value" : "${}",
"label" : "Input: name",
"type" : "String",
"binding" : {
"type" : "camunda:inputParameter",
"name" : "name"
}
}, {
"value" : "",
"label" : "id",
"value" : "${}",
"label" : "Input: id",
"type" : "String",
"binding" : {
"type" : "camunda:inputParameter",
"name" : "id"
}
}, {
"value" : "nameResult",
"label" : "name",
"value" : "name",
"label" : "Output: name",
"type" : "String",
"binding" : {
"type" : "camunda:outputParameter",
"source" : "${name}"
}
}, {
"value" : "idResult",
"label" : "id",
"value" : "id",
"label" : "Output: id",
"type" : "String",
"binding" : {
"type" : "camunda:outputParameter",
Expand Down
Loading

0 comments on commit 132afea

Please sign in to comment.