Skip to content

Commit 10e34fe

Browse files
committed
[Fix #490] Implement Listen Task
[Fix #490] Delaying registration [Fix #490] Fixing schema generation [Fix #490] Emit executor Signed-off-by: Francisco Javier Tirado Sarti <ftirados@redhat.com>
1 parent dd272e3 commit 10e34fe

32 files changed

+1278
-106
lines changed

api/src/main/resources/schema/workflow.yaml

Lines changed: 61 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,17 @@ $defs:
558558
$ref: '#/$defs/eventConsumptionStrategy'
559559
title: ListenTo
560560
description: Defines the event(s) to listen to.
561+
read:
562+
type: string
563+
enum: [ data, envelope, raw ]
564+
default: data
565+
title: ListenAndReadAs
566+
description: Specifies how events are read during the listen operation.
561567
required: [ to ]
568+
foreach:
569+
$ref: '#/$defs/subscriptionIterator'
570+
title: ListenIterator
571+
description: Configures the iterator, if any, for processing consumed event(s).
562572
raiseTask:
563573
type: object
564574
$ref: '#/$defs/taskBase'
@@ -1315,47 +1325,25 @@ $defs:
13151325
$ref: '#/$defs/eventFilter'
13161326
required: [ all ]
13171327
- title: AnyEventConsumptionStrategy
1318-
oneOf:
1319-
- properties:
1320-
any:
1321-
type: array
1322-
title: AnyEventConsumptionStrategyConfiguration
1323-
description: A list containing any of the events to consume.
1324-
items:
1325-
$ref: '#/$defs/eventFilter'
1326-
minItems: 1
1327-
until:
1328-
oneOf:
1329-
- type: string
1330-
title: AnyEventUntilCondition
1331-
description: A runtime expression condition evaluated after consuming an event and which determines whether or not to continue listening.
1332-
- allOf:
1333-
- $ref: '#/$defs/eventConsumptionStrategy'
1334-
title: AnyEventUntilConsumed
1335-
description: The strategy that defines the event(s) to consume to stop listening.
1336-
- properties:
1337-
until: false
1338-
required: [ any ]
1339-
- properties:
1340-
any:
1341-
type: array
1342-
title: AnyEventConsumptionStrategyConfiguration
1343-
description: A list containing any of the events to consume.
1344-
items:
1345-
$ref: '#/$defs/eventFilter'
1346-
maxItems: 0
1347-
until:
1348-
oneOf:
1349-
- type: string
1350-
title: AnyEventUntilCondition
1351-
description: A runtime expression condition evaluated after consuming an event and which determines whether or not to continue listening.
1352-
- allOf:
1353-
- $ref: '#/$defs/eventConsumptionStrategy'
1354-
title: AnyEventUntilConsumed
1355-
description: The strategy that defines the event(s) to consume to stop listening.
1356-
- properties:
1357-
until: false
1358-
required: [ any, until ]
1328+
properties:
1329+
any:
1330+
type: array
1331+
title: AnyEventConsumptionStrategyConfiguration
1332+
description: A list containing any of the events to consume.
1333+
items:
1334+
$ref: '#/$defs/eventFilter'
1335+
until:
1336+
oneOf:
1337+
- type: string
1338+
title: AnyEventUntilCondition
1339+
description: A runtime expression condition evaluated after consuming an event and which determines whether or not to continue listening.
1340+
- allOf:
1341+
- $ref: '#/$defs/eventConsumptionStrategy'
1342+
description: The strategy that defines the event(s) to consume to stop listening.
1343+
- properties:
1344+
until: false
1345+
title: AnyEventUntilConsumed
1346+
required: [ any ]
13591347
- title: OneEventConsumptionStrategy
13601348
properties:
13611349
one:
@@ -1710,6 +1698,10 @@ $defs:
17101698
$ref: '#/$defs/asyncApiMessageConsumptionPolicy'
17111699
title: AsyncApiMessageConsumptionPolicy
17121700
description: An object used to configure the subscription's message consumption policy.
1701+
foreach:
1702+
$ref: '#/$defs/subscriptionIterator'
1703+
title: AsyncApiSubscriptionIterator
1704+
description: Configures the iterator, if any, for processing consumed messages(s).
17131705
required: [ consume ]
17141706
asyncApiMessageConsumptionPolicy:
17151707
type: object
@@ -1740,3 +1732,31 @@ $defs:
17401732
title: AsyncApiMessageConsumptionPolicyUntil
17411733
description: A runtime expression evaluated before each consumed (filtered) message to decide if message consumption should continue.
17421734
required: [ until ]
1735+
subscriptionIterator:
1736+
type: object
1737+
title: SubscriptionIterator
1738+
description: Configures the iteration over each item (event or message) consumed by a subscription.
1739+
unevaluatedProperties: false
1740+
properties:
1741+
item:
1742+
type: string
1743+
title: SubscriptionIteratorItem
1744+
description: The name of the variable used to store the current item being enumerated.
1745+
default: item
1746+
at:
1747+
type: string
1748+
title: SubscriptionIteratorIndex
1749+
description: The name of the variable used to store the index of the current item being enumerated.
1750+
default: index
1751+
do:
1752+
$ref: '#/$defs/taskList'
1753+
title: SubscriptionIteratorTasks
1754+
description: The tasks to perform for each consumed item.
1755+
output:
1756+
$ref: '#/$defs/output'
1757+
title: SubscriptionIteratorOutput
1758+
description: An object, if any, used to customize the item's output and to document its schema.
1759+
export:
1760+
$ref: '#/$defs/export'
1761+
title: SubscriptionIteratorExport
1762+
description: An object, if any, used to customize the content of the workflow context.

api/src/test/resources/features/emit.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ do:
1010
with:
1111
source: https://fake-source.com
1212
type: com.fake-source.user.greeted.v1
13-
data:
14-
greetings: ${ "Hello \(.user.firstName) \(.user.lastName)!" }
13+
data: [1,2,3,4]
14+

custom-generator/src/main/java/io/serverlessworkflow/generator/AllAnyOneOfSchemaRule.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class AllAnyOneOfSchemaRule extends SchemaRule {
6060
}
6161

6262
private static final String REF = "$ref";
63+
private static final String TITLE = "title";
6364
private static final String PATTERN = "pattern";
6465

6566
private enum Format {
@@ -154,6 +155,16 @@ public JType apply(
154155
&& allOfTypes.isEmpty()
155156
&& refType.isPresent()) {
156157
javaType = refType.get();
158+
} else if (!schemaNode.has("properties")
159+
&& oneOfTypes.isEmpty()
160+
&& allOfTypes.size() == 1
161+
&& refType.isEmpty()) {
162+
javaType = allOfTypes.get(0).getType();
163+
} else if (!schemaNode.has("properties")
164+
&& oneOfTypes.size() == 1
165+
&& allOfTypes.isEmpty()
166+
&& refType.isEmpty()) {
167+
javaType = oneOfTypes.get(0).getType();
157168
} else {
158169
JPackage container = generatableType.getPackage();
159170
javaType = ruleFactory.getTypeRule().apply(nodeName, schemaNode, parent, container, schema);
@@ -469,6 +480,9 @@ private void unionType(
469480
Collection<JTypeWrapper> types) {
470481
if (schemaNode.has(prefix)) {
471482
ArrayNode array = (ArrayNode) schemaNode.get(prefix);
483+
if (schemaNode.has(TITLE)) {
484+
nodeName = schemaNode.get(TITLE).asText();
485+
}
472486
int i = 0;
473487
for (JsonNode oneOf : array) {
474488
if (!ignoreNode(oneOf)) {
@@ -491,6 +505,23 @@ private void unionType(
491505
}
492506

493507
private static boolean ignoreNode(JsonNode node) {
508+
return allRequired(node) || allRemoveProperties(node);
509+
}
510+
511+
private static boolean allRemoveProperties(JsonNode node) {
512+
if (node.size() == 1 && node.has("properties")) {
513+
JsonNode propsNode = node.get("properties");
514+
for (JsonNode propNode : propsNode) {
515+
if (!propNode.isBoolean() || propNode.asBoolean()) {
516+
return false;
517+
}
518+
}
519+
return true;
520+
}
521+
return false;
522+
}
523+
524+
private static boolean allRequired(JsonNode node) {
494525
return node.size() == 1 && node.has("required");
495526
}
496527

@@ -514,7 +545,7 @@ private Optional<JType> refType(
514545
schema.isGenerated()
515546
? schema.getJavaType()
516547
: apply(
517-
nameFromRef(ref, nodeName),
548+
nameFromRef(ref, nodeName, schemaNode),
518549
schema.getContent(),
519550
parent,
520551
generatableType,
@@ -556,7 +587,10 @@ private String pattern(JsonNode node) {
556587
return format != null ? format.pattern() : getFromNode(node, PATTERN);
557588
}
558589

559-
private String nameFromRef(String ref, String nodeName) {
590+
private String nameFromRef(String ref, String nodeName, JsonNode schemaNode) {
591+
if (schemaNode.has(TITLE)) {
592+
return schemaNode.get(TITLE).asText();
593+
}
560594
if ("#".equals(ref)) {
561595
return nodeName;
562596
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.generator;
17+
18+
import com.fasterxml.jackson.databind.JsonNode;
19+
import com.sun.codemodel.JClassAlreadyExistsException;
20+
import com.sun.codemodel.JDefinedClass;
21+
import com.sun.codemodel.JPackage;
22+
import org.jsonschema2pojo.GenerationConfig;
23+
import org.jsonschema2pojo.util.NameHelper;
24+
25+
public class RefNameHelper extends NameHelper {
26+
27+
public RefNameHelper(GenerationConfig generationConfig) {
28+
super(generationConfig);
29+
}
30+
31+
@Override
32+
public String getUniqueClassName(String nodeName, JsonNode node, JPackage _package) {
33+
String className = getClassName(nodeName, node, _package);
34+
try {
35+
JDefinedClass _class = _package._class(className);
36+
_package.remove(_class);
37+
return className;
38+
} catch (JClassAlreadyExistsException ex) {
39+
return super.getUniqueClassName(nodeName, null, _package);
40+
}
41+
}
42+
}

custom-generator/src/main/java/io/serverlessworkflow/generator/UnreferencedFactory.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,25 @@
1818
import com.sun.codemodel.JClassContainer;
1919
import com.sun.codemodel.JDefinedClass;
2020
import com.sun.codemodel.JType;
21+
import org.jsonschema2pojo.GenerationConfig;
2122
import org.jsonschema2pojo.rules.Rule;
2223
import org.jsonschema2pojo.rules.RuleFactory;
24+
import org.jsonschema2pojo.util.NameHelper;
2325

2426
public class UnreferencedFactory extends RuleFactory {
27+
28+
private NameHelper refNameHelper;
29+
30+
public UnreferencedFactory() {
31+
this.refNameHelper = new RefNameHelper(getGenerationConfig());
32+
}
33+
34+
@Override
35+
public void setGenerationConfig(final GenerationConfig generationConfig) {
36+
super.setGenerationConfig(generationConfig);
37+
this.refNameHelper = new RefNameHelper(generationConfig);
38+
}
39+
2540
@Override
2641
public Rule<JClassContainer, JType> getSchemaRule() {
2742
return new AllAnyOneOfSchemaRule(this);
@@ -36,4 +51,9 @@ public Rule<JClassContainer, JType> getTypeRule() {
3651
public Rule<JDefinedClass, JDefinedClass> getAdditionalPropertiesRule() {
3752
return new UnevaluatedPropertiesRule(this);
3853
}
54+
55+
@Override
56+
public NameHelper getNameHelper() {
57+
return refNameHelper;
58+
}
3959
}

impl/core/pom.xml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@
66
<version>7.0.0-SNAPSHOT</version>
77
</parent>
88
<artifactId>serverlessworkflow-impl-core</artifactId>
9-
<properties>
10-
<version.net.thisptr>1.2.0</version.net.thisptr>
11-
<version.com.github.f4b6a3>5.2.3</version.com.github.f4b6a3>
12-
</properties>
139
<dependencies>
1410
<dependency>
1511
<groupId>io.serverlessworkflow</groupId>
1612
<artifactId>serverlessworkflow-api</artifactId>
17-
<version>7.0.0-SNAPSHOT</version>
13+
<version>${project.version}</version>
14+
</dependency>
15+
<dependency>
16+
<groupId>io.cloudevents</groupId>
17+
<artifactId>cloudevents-api</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>io.cloudevents</groupId>
21+
<artifactId>cloudevents-json-jackson</artifactId>
1822
</dependency>
1923
<dependency>
2024
<groupId>com.github.f4b6a3</groupId>
2125
<artifactId>ulid-creator</artifactId>
22-
<version>${version.com.github.f4b6a3}</version>
2326
</dependency>
2427
<dependency>
2528
<groupId>com.networknt</groupId>
@@ -28,7 +31,6 @@
2831
<dependency>
2932
<groupId>net.thisptr</groupId>
3033
<artifactId>jackson-jq</artifactId>
31-
<version>${version.net.thisptr}</version>
3234
</dependency>
3335
<dependency>
3436
<groupId>org.junit.jupiter</groupId>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl;
17+
18+
import java.util.function.BiFunction;
19+
20+
public interface ExpressionHolder<T> extends BiFunction<WorkflowContext, TaskContext, T> {}

impl/core/src/main/java/io/serverlessworkflow/impl/LongFilter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,5 @@
1515
*/
1616
package io.serverlessworkflow.impl;
1717

18-
import java.util.function.BiFunction;
19-
2018
@FunctionalInterface
21-
public interface LongFilter extends BiFunction<WorkflowContext, TaskContext, Long> {}
19+
public interface LongFilter extends ExpressionHolder<Long> {}

impl/core/src/main/java/io/serverlessworkflow/impl/StringFilter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,5 @@
1515
*/
1616
package io.serverlessworkflow.impl;
1717

18-
import java.util.function.BiFunction;
19-
2018
@FunctionalInterface
21-
public interface StringFilter extends BiFunction<WorkflowContext, TaskContext, String> {}
19+
public interface StringFilter extends ExpressionHolder<String> {}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy