Skip to content

Commit f08c840

Browse files
Fix #368 - Introduce Standard Fluent DSL (#645)
* Fix #368 - Introduce Standard Fluent DSL Signed-off-by: Ricardo Zanini <[email protected]> * Add input/output to workflow/tasks Signed-off-by: Ricardo Zanini <[email protected]> * Add callHttp task Signed-off-by: Ricardo Zanini <[email protected]> --------- Signed-off-by: Ricardo Zanini <[email protected]>
1 parent 470897d commit f08c840

32 files changed

+3032
-0
lines changed

fluent/pom.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>io.serverlessworkflow</groupId>
8+
<artifactId>serverlessworkflow-parent</artifactId>
9+
<version>8.0.0-SNAPSHOT</version>
10+
</parent>
11+
<name>Serverless Workflow :: Fluent</name>
12+
<artifactId>serverlessworkflow-fluent</artifactId>
13+
<packaging>pom</packaging>
14+
15+
<properties>
16+
<maven.compiler.source>17</maven.compiler.source>
17+
<maven.compiler.target>17</maven.compiler.target>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
</properties>
20+
21+
<dependencyManagement>
22+
<dependencies>
23+
<dependency>
24+
<groupId>io.serverlessworkflow</groupId>
25+
<artifactId>serverlessworkflow-types</artifactId>
26+
<version>${project.version}</version>
27+
</dependency>
28+
</dependencies>
29+
</dependencyManagement>
30+
31+
<modules>
32+
<module>standard</module>
33+
</modules>
34+
35+
</project>

fluent/standard/pom.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>io.serverlessworkflow</groupId>
8+
<artifactId>serverlessworkflow-fluent</artifactId>
9+
<version>8.0.0-SNAPSHOT</version>
10+
</parent>
11+
<name>Serverless Workflow :: Fluent :: Standard</name>
12+
<artifactId>serverlessworkflow-fluent-standard</artifactId>
13+
14+
<properties>
15+
<maven.compiler.source>17</maven.compiler.source>
16+
<maven.compiler.target>17</maven.compiler.target>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>io.serverlessworkflow</groupId>
23+
<artifactId>serverlessworkflow-types</artifactId>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.junit.jupiter</groupId>
27+
<artifactId>junit-jupiter-api</artifactId>
28+
<scope>test</scope>
29+
</dependency>
30+
</dependencies>
31+
32+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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.fluent.standard;
17+
18+
import io.serverlessworkflow.api.types.AuthenticationPolicyUnion;
19+
import java.util.function.Consumer;
20+
21+
public class AuthenticationPolicyUnionBuilder {
22+
final AuthenticationPolicyUnion authenticationPolicy;
23+
24+
AuthenticationPolicyUnionBuilder() {
25+
this.authenticationPolicy = new AuthenticationPolicyUnion();
26+
}
27+
28+
public AuthenticationPolicyUnionBuilder basic(
29+
Consumer<BasicAuthenticationPolicyBuilder> basicConsumer) {
30+
final BasicAuthenticationPolicyBuilder basicAuthenticationPolicyBuilder =
31+
new BasicAuthenticationPolicyBuilder();
32+
basicConsumer.accept(basicAuthenticationPolicyBuilder);
33+
this.authenticationPolicy.setBasicAuthenticationPolicy(
34+
basicAuthenticationPolicyBuilder.build());
35+
return this;
36+
}
37+
38+
public AuthenticationPolicyUnionBuilder bearer(
39+
Consumer<BearerAuthenticationPolicyBuilder> bearerConsumer) {
40+
final BearerAuthenticationPolicyBuilder bearerAuthenticationPolicyBuilder =
41+
new BearerAuthenticationPolicyBuilder();
42+
bearerConsumer.accept(bearerAuthenticationPolicyBuilder);
43+
this.authenticationPolicy.setBearerAuthenticationPolicy(
44+
bearerAuthenticationPolicyBuilder.build());
45+
return this;
46+
}
47+
48+
public AuthenticationPolicyUnionBuilder digest(
49+
Consumer<DigestAuthenticationPolicyBuilder> digestConsumer) {
50+
final DigestAuthenticationPolicyBuilder digestAuthenticationPolicyBuilder =
51+
new DigestAuthenticationPolicyBuilder();
52+
digestConsumer.accept(digestAuthenticationPolicyBuilder);
53+
this.authenticationPolicy.setDigestAuthenticationPolicy(
54+
digestAuthenticationPolicyBuilder.build());
55+
return this;
56+
}
57+
58+
public AuthenticationPolicyUnionBuilder oauth2(
59+
Consumer<OAuth2AuthenticationPolicyBuilder> oauth2Consumer) {
60+
final OAuth2AuthenticationPolicyBuilder oauth2AuthenticationPolicyBuilder =
61+
new OAuth2AuthenticationPolicyBuilder();
62+
oauth2Consumer.accept(oauth2AuthenticationPolicyBuilder);
63+
this.authenticationPolicy.setOAuth2AuthenticationPolicy(
64+
oauth2AuthenticationPolicyBuilder.build());
65+
return this;
66+
}
67+
68+
public AuthenticationPolicyUnionBuilder openIDConnect(
69+
Consumer<OpenIdConnectAuthenticationPolicyBuilder> openIdConnectConsumer) {
70+
final OpenIdConnectAuthenticationPolicyBuilder builder =
71+
new OpenIdConnectAuthenticationPolicyBuilder();
72+
openIdConnectConsumer.accept(builder);
73+
this.authenticationPolicy.setOpenIdConnectAuthenticationPolicy(builder.build());
74+
return this;
75+
}
76+
77+
public AuthenticationPolicyUnion build() {
78+
return authenticationPolicy;
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.fluent.standard;
17+
18+
import io.serverlessworkflow.api.types.BasicAuthenticationPolicy;
19+
import io.serverlessworkflow.api.types.BasicAuthenticationPolicyConfiguration;
20+
import io.serverlessworkflow.api.types.BasicAuthenticationProperties;
21+
22+
public final class BasicAuthenticationPolicyBuilder {
23+
24+
private final BasicAuthenticationProperties basicAuthenticationProperties;
25+
26+
BasicAuthenticationPolicyBuilder() {
27+
this.basicAuthenticationProperties = new BasicAuthenticationProperties();
28+
}
29+
30+
public BasicAuthenticationPolicyBuilder username(String username) {
31+
this.basicAuthenticationProperties.setUsername(username);
32+
return this;
33+
}
34+
35+
public BasicAuthenticationPolicyBuilder password(String password) {
36+
this.basicAuthenticationProperties.setPassword(password);
37+
return this;
38+
}
39+
40+
public BasicAuthenticationPolicy build() {
41+
final BasicAuthenticationPolicyConfiguration configuration =
42+
new BasicAuthenticationPolicyConfiguration();
43+
configuration.setBasicAuthenticationProperties(basicAuthenticationProperties);
44+
return new BasicAuthenticationPolicy(configuration);
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.fluent.standard;
17+
18+
import io.serverlessworkflow.api.types.BearerAuthenticationPolicy;
19+
import io.serverlessworkflow.api.types.BearerAuthenticationPolicyConfiguration;
20+
import io.serverlessworkflow.api.types.BearerAuthenticationProperties;
21+
22+
public final class BearerAuthenticationPolicyBuilder {
23+
private final BearerAuthenticationProperties bearerAuthenticationProperties;
24+
25+
BearerAuthenticationPolicyBuilder() {
26+
this.bearerAuthenticationProperties = new BearerAuthenticationProperties();
27+
}
28+
29+
public BearerAuthenticationPolicyBuilder token(final String token) {
30+
this.bearerAuthenticationProperties.setToken(token);
31+
return this;
32+
}
33+
34+
public BearerAuthenticationPolicy build() {
35+
final BearerAuthenticationPolicyConfiguration configuration =
36+
new BearerAuthenticationPolicyConfiguration();
37+
configuration.setBearerAuthenticationProperties(bearerAuthenticationProperties);
38+
return new BearerAuthenticationPolicy(configuration);
39+
}
40+
}
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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.fluent.standard;
17+
18+
import io.serverlessworkflow.api.types.CallHTTP;
19+
import io.serverlessworkflow.api.types.Endpoint;
20+
import io.serverlessworkflow.api.types.HTTPArguments;
21+
import io.serverlessworkflow.api.types.HTTPHeaders;
22+
import io.serverlessworkflow.api.types.HTTPQuery;
23+
import io.serverlessworkflow.api.types.Headers;
24+
import io.serverlessworkflow.api.types.Query;
25+
import io.serverlessworkflow.api.types.UriTemplate;
26+
import java.net.URI;
27+
import java.util.Map;
28+
import java.util.function.Consumer;
29+
30+
public class CallHTTPTaskBuilder extends TaskBaseBuilder<CallHTTPTaskBuilder> {
31+
32+
private final CallHTTP callHTTP;
33+
34+
CallHTTPTaskBuilder() {
35+
callHTTP = new CallHTTP();
36+
callHTTP.setWith(new HTTPArguments());
37+
callHTTP.getWith().setOutput(HTTPArguments.HTTPOutput.CONTENT);
38+
super.setTask(this.callHTTP);
39+
}
40+
41+
@Override
42+
protected CallHTTPTaskBuilder self() {
43+
return this;
44+
}
45+
46+
public CallHTTPTaskBuilder method(String method) {
47+
this.callHTTP.getWith().setMethod(method);
48+
return this;
49+
}
50+
51+
public CallHTTPTaskBuilder endpoint(URI endpoint) {
52+
this.callHTTP
53+
.getWith()
54+
.setEndpoint(new Endpoint().withUriTemplate(new UriTemplate().withLiteralUri(endpoint)));
55+
return this;
56+
}
57+
58+
public CallHTTPTaskBuilder endpoint(String expr) {
59+
this.callHTTP.getWith().setEndpoint(new Endpoint().withRuntimeExpression(expr));
60+
return this;
61+
}
62+
63+
// TODO: add endpoint configuration to support authentication
64+
65+
public CallHTTPTaskBuilder headers(String expr) {
66+
this.callHTTP.getWith().setHeaders(new Headers().withRuntimeExpression(expr));
67+
return this;
68+
}
69+
70+
public CallHTTPTaskBuilder headers(Consumer<HTTPHeadersBuilder> consumer) {
71+
HTTPHeadersBuilder hb = new HTTPHeadersBuilder();
72+
consumer.accept(hb);
73+
callHTTP.getWith().setHeaders(hb.build());
74+
return this;
75+
}
76+
77+
public CallHTTPTaskBuilder headers(Map<String, String> headers) {
78+
HTTPHeadersBuilder hb = new HTTPHeadersBuilder();
79+
hb.headers(headers);
80+
callHTTP.getWith().setHeaders(hb.build());
81+
return this;
82+
}
83+
84+
public CallHTTPTaskBuilder body(Object body) {
85+
this.callHTTP.getWith().setBody(body);
86+
return this;
87+
}
88+
89+
public CallHTTPTaskBuilder query(String expr) {
90+
this.callHTTP.getWith().setQuery(new Query().withRuntimeExpression(expr));
91+
return this;
92+
}
93+
94+
public CallHTTPTaskBuilder query(Consumer<HTTPQueryBuilder> consumer) {
95+
HTTPQueryBuilder queryBuilder = new HTTPQueryBuilder();
96+
consumer.accept(queryBuilder);
97+
callHTTP.getWith().setQuery(queryBuilder.build());
98+
return this;
99+
}
100+
101+
public CallHTTPTaskBuilder query(Map<String, String> query) {
102+
HTTPQueryBuilder httpQueryBuilder = new HTTPQueryBuilder();
103+
httpQueryBuilder.queries(query);
104+
callHTTP.getWith().setQuery(httpQueryBuilder.build());
105+
return this;
106+
}
107+
108+
public CallHTTPTaskBuilder redirect(boolean redirect) {
109+
callHTTP.getWith().setRedirect(redirect);
110+
return this;
111+
}
112+
113+
public CallHTTPTaskBuilder output(HTTPArguments.HTTPOutput output) {
114+
callHTTP.getWith().setOutput(output);
115+
return this;
116+
}
117+
118+
public CallHTTP build() {
119+
return callHTTP;
120+
}
121+
122+
public static class HTTPQueryBuilder {
123+
private final HTTPQuery httpQuery = new HTTPQuery();
124+
125+
public HTTPQueryBuilder query(String name, String value) {
126+
httpQuery.setAdditionalProperty(name, value);
127+
return this;
128+
}
129+
130+
public HTTPQueryBuilder queries(Map<String, String> headers) {
131+
headers.forEach(httpQuery::setAdditionalProperty);
132+
return this;
133+
}
134+
135+
public Query build() {
136+
return new Query().withHTTPQuery(httpQuery);
137+
}
138+
}
139+
140+
public static class HTTPHeadersBuilder {
141+
private final HTTPHeaders httpHeaders = new HTTPHeaders();
142+
143+
public HTTPHeadersBuilder header(String name, String value) {
144+
httpHeaders.setAdditionalProperty(name, value);
145+
return this;
146+
}
147+
148+
public HTTPHeadersBuilder headers(Map<String, String> headers) {
149+
headers.forEach(httpHeaders::setAdditionalProperty);
150+
return this;
151+
}
152+
153+
public Headers build() {
154+
return new Headers().withHTTPHeaders(httpHeaders);
155+
}
156+
}
157+
}

0 commit comments

Comments
 (0)