Skip to content

Commit 084fd7e

Browse files
committed
Add fluent DSL equivalents for core task types and expand coverage
Signed-off-by: Matheus André <matheusandr2@gmail.com>
1 parent 554aee6 commit 084fd7e

3 files changed

Lines changed: 646 additions & 1 deletion

File tree

fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/UseBuilder.java

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@
1515
*/
1616
package io.serverlessworkflow.fluent.spec;
1717

18+
import io.serverlessworkflow.api.types.Error;
19+
import io.serverlessworkflow.api.types.ErrorDetails;
20+
import io.serverlessworkflow.api.types.ErrorTitle;
21+
import io.serverlessworkflow.api.types.ErrorType;
22+
import io.serverlessworkflow.api.types.UriTemplate;
1823
import io.serverlessworkflow.api.types.Use;
1924
import io.serverlessworkflow.api.types.UseAuthentications;
25+
import io.serverlessworkflow.api.types.UseErrors;
26+
import java.net.URI;
27+
import java.net.URISyntaxException;
2028
import java.util.List;
2129
import java.util.function.Consumer;
2230

@@ -47,9 +55,77 @@ public UseBuilder authentications(Consumer<UseAuthenticationsBuilder> authentica
4755
return this;
4856
}
4957

50-
// TODO: implement the remaining `use` attributes
58+
public UseBuilder errors(Consumer<UseErrorsBuilder> errorsConsumer) {
59+
final UseErrorsBuilder builder = new UseErrorsBuilder();
60+
errorsConsumer.accept(builder);
61+
this.use.setErrors(builder.build());
62+
return this;
63+
}
5164

5265
public Use build() {
5366
return use;
5467
}
68+
69+
public static final class UseErrorsBuilder {
70+
private final UseErrors useErrors;
71+
72+
UseErrorsBuilder() {
73+
this.useErrors = new UseErrors();
74+
}
75+
76+
public UseErrorsBuilder error(String name, Consumer<UseErrorBuilder> errorConsumer) {
77+
final UseErrorBuilder errorBuilder = new UseErrorBuilder();
78+
errorConsumer.accept(errorBuilder);
79+
this.useErrors.withAdditionalProperty(name, errorBuilder.build());
80+
return this;
81+
}
82+
83+
public UseErrors build() {
84+
return useErrors;
85+
}
86+
}
87+
88+
public static final class UseErrorBuilder {
89+
private final Error error;
90+
91+
UseErrorBuilder() {
92+
this.error = new Error();
93+
}
94+
95+
public UseErrorBuilder type(String expression) {
96+
ErrorType errorType = new ErrorType();
97+
try {
98+
errorType.withLiteralErrorType(new UriTemplate().withLiteralUri(new URI(expression)));
99+
} catch (URISyntaxException ex) {
100+
errorType.withExpressionErrorType(expression);
101+
}
102+
this.error.setType(errorType);
103+
return this;
104+
}
105+
106+
public UseErrorBuilder type(URI errorType) {
107+
this.error.setType(
108+
new ErrorType().withLiteralErrorType(new UriTemplate().withLiteralUri(errorType)));
109+
return this;
110+
}
111+
112+
public UseErrorBuilder status(int status) {
113+
this.error.setStatus(status);
114+
return this;
115+
}
116+
117+
public UseErrorBuilder title(String expression) {
118+
this.error.setTitle(new ErrorTitle().withExpressionErrorTitle(expression));
119+
return this;
120+
}
121+
122+
public UseErrorBuilder detail(String expression) {
123+
this.error.setDetail(new ErrorDetails().withExpressionErrorDetails(expression));
124+
return this;
125+
}
126+
127+
public Error build() {
128+
return error;
129+
}
130+
}
55131
}

fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/dsl/UseSpec.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.serverlessworkflow.fluent.spec.configurers.UseConfigurer;
2121
import java.util.LinkedList;
2222
import java.util.List;
23+
import java.util.function.Consumer;
2324

2425
public class UseSpec implements UseConfigurer {
2526

@@ -40,6 +41,11 @@ public UseSpec auth(String name, AuthenticationConfigurer auth) {
4041
return this;
4142
}
4243

44+
public UseSpec errors(Consumer<UseBuilder.UseErrorsBuilder> errorsConsumer) {
45+
steps.add(u -> u.errors(errorsConsumer));
46+
return this;
47+
}
48+
4349
@Override
4450
public void accept(UseBuilder useBuilder) {
4551
steps.forEach(step -> step.accept(useBuilder));

0 commit comments

Comments
 (0)