Skip to content

Fix #368 - Introduce Standard Fluent DSL #645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions fluent/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-parent</artifactId>
<version>8.0.0-SNAPSHOT</version>
</parent>
<name>Serverless Workflow :: Fluent</name>
<artifactId>serverlessworkflow-fluent</artifactId>
<packaging>pom</packaging>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-types</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

<modules>
<module>standard</module>
</modules>

</project>
32 changes: 32 additions & 0 deletions fluent/standard/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-fluent</artifactId>
<version>8.0.0-SNAPSHOT</version>
</parent>
<name>Serverless Workflow :: Fluent :: Standard</name>
<artifactId>serverlessworkflow-fluent-standard</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-types</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.fluent.standard;

import io.serverlessworkflow.api.types.AuthenticationPolicyUnion;
import java.util.function.Consumer;

public class AuthenticationPolicyUnionBuilder {
final AuthenticationPolicyUnion authenticationPolicy;

AuthenticationPolicyUnionBuilder() {
this.authenticationPolicy = new AuthenticationPolicyUnion();
}

public AuthenticationPolicyUnionBuilder basic(
Consumer<BasicAuthenticationPolicyBuilder> basicConsumer) {
final BasicAuthenticationPolicyBuilder basicAuthenticationPolicyBuilder =
new BasicAuthenticationPolicyBuilder();
basicConsumer.accept(basicAuthenticationPolicyBuilder);
this.authenticationPolicy.setBasicAuthenticationPolicy(
basicAuthenticationPolicyBuilder.build());
return this;
}

public AuthenticationPolicyUnionBuilder bearer(
Consumer<BearerAuthenticationPolicyBuilder> bearerConsumer) {
final BearerAuthenticationPolicyBuilder bearerAuthenticationPolicyBuilder =
new BearerAuthenticationPolicyBuilder();
bearerConsumer.accept(bearerAuthenticationPolicyBuilder);
this.authenticationPolicy.setBearerAuthenticationPolicy(
bearerAuthenticationPolicyBuilder.build());
return this;
}

public AuthenticationPolicyUnionBuilder digest(
Consumer<DigestAuthenticationPolicyBuilder> digestConsumer) {
final DigestAuthenticationPolicyBuilder digestAuthenticationPolicyBuilder =
new DigestAuthenticationPolicyBuilder();
digestConsumer.accept(digestAuthenticationPolicyBuilder);
this.authenticationPolicy.setDigestAuthenticationPolicy(
digestAuthenticationPolicyBuilder.build());
return this;
}

public AuthenticationPolicyUnionBuilder oauth2(
Consumer<OAuth2AuthenticationPolicyBuilder> oauth2Consumer) {
final OAuth2AuthenticationPolicyBuilder oauth2AuthenticationPolicyBuilder =
new OAuth2AuthenticationPolicyBuilder();
oauth2Consumer.accept(oauth2AuthenticationPolicyBuilder);
this.authenticationPolicy.setOAuth2AuthenticationPolicy(
oauth2AuthenticationPolicyBuilder.build());
return this;
}

public AuthenticationPolicyUnionBuilder openIDConnect(
Consumer<OpenIdConnectAuthenticationPolicyBuilder> openIdConnectConsumer) {
final OpenIdConnectAuthenticationPolicyBuilder builder =
new OpenIdConnectAuthenticationPolicyBuilder();
openIdConnectConsumer.accept(builder);
this.authenticationPolicy.setOpenIdConnectAuthenticationPolicy(builder.build());
return this;
}

public AuthenticationPolicyUnion build() {
return authenticationPolicy;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.fluent.standard;

import io.serverlessworkflow.api.types.BasicAuthenticationPolicy;
import io.serverlessworkflow.api.types.BasicAuthenticationPolicyConfiguration;
import io.serverlessworkflow.api.types.BasicAuthenticationProperties;

public final class BasicAuthenticationPolicyBuilder {

private final BasicAuthenticationProperties basicAuthenticationProperties;

BasicAuthenticationPolicyBuilder() {
this.basicAuthenticationProperties = new BasicAuthenticationProperties();
}

public BasicAuthenticationPolicyBuilder username(String username) {
this.basicAuthenticationProperties.setUsername(username);
return this;
}

public BasicAuthenticationPolicyBuilder password(String password) {
this.basicAuthenticationProperties.setPassword(password);
return this;
}

public BasicAuthenticationPolicy build() {
final BasicAuthenticationPolicyConfiguration configuration =
new BasicAuthenticationPolicyConfiguration();
configuration.setBasicAuthenticationProperties(basicAuthenticationProperties);
return new BasicAuthenticationPolicy(configuration);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.fluent.standard;

import io.serverlessworkflow.api.types.BearerAuthenticationPolicy;
import io.serverlessworkflow.api.types.BearerAuthenticationPolicyConfiguration;
import io.serverlessworkflow.api.types.BearerAuthenticationProperties;

public final class BearerAuthenticationPolicyBuilder {
private final BearerAuthenticationProperties bearerAuthenticationProperties;

BearerAuthenticationPolicyBuilder() {
this.bearerAuthenticationProperties = new BearerAuthenticationProperties();
}

public BearerAuthenticationPolicyBuilder token(final String token) {
this.bearerAuthenticationProperties.setToken(token);
return this;
}

public BearerAuthenticationPolicy build() {
final BearerAuthenticationPolicyConfiguration configuration =
new BearerAuthenticationPolicyConfiguration();
configuration.setBearerAuthenticationProperties(bearerAuthenticationProperties);
return new BearerAuthenticationPolicy(configuration);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.fluent.standard;

import io.serverlessworkflow.api.types.CallHTTP;
import io.serverlessworkflow.api.types.Endpoint;
import io.serverlessworkflow.api.types.HTTPArguments;
import io.serverlessworkflow.api.types.HTTPHeaders;
import io.serverlessworkflow.api.types.HTTPQuery;
import io.serverlessworkflow.api.types.Headers;
import io.serverlessworkflow.api.types.Query;
import io.serverlessworkflow.api.types.UriTemplate;
import java.net.URI;
import java.util.Map;
import java.util.function.Consumer;

public class CallHTTPTaskBuilder extends TaskBaseBuilder<CallHTTPTaskBuilder> {

private final CallHTTP callHTTP;

CallHTTPTaskBuilder() {
callHTTP = new CallHTTP();
callHTTP.setWith(new HTTPArguments());
callHTTP.getWith().setOutput(HTTPArguments.HTTPOutput.CONTENT);
super.setTask(this.callHTTP);
}

@Override
protected CallHTTPTaskBuilder self() {
return this;
}

public CallHTTPTaskBuilder method(String method) {
this.callHTTP.getWith().setMethod(method);
return this;
}

public CallHTTPTaskBuilder endpoint(URI endpoint) {
this.callHTTP
.getWith()
.setEndpoint(new Endpoint().withUriTemplate(new UriTemplate().withLiteralUri(endpoint)));
return this;
}

public CallHTTPTaskBuilder endpoint(String expr) {
this.callHTTP.getWith().setEndpoint(new Endpoint().withRuntimeExpression(expr));
return this;
}

// TODO: add endpoint configuration to support authentication

public CallHTTPTaskBuilder headers(String expr) {
this.callHTTP.getWith().setHeaders(new Headers().withRuntimeExpression(expr));
return this;
}

public CallHTTPTaskBuilder headers(Consumer<HTTPHeadersBuilder> consumer) {
HTTPHeadersBuilder hb = new HTTPHeadersBuilder();
consumer.accept(hb);
callHTTP.getWith().setHeaders(hb.build());
return this;
}

public CallHTTPTaskBuilder headers(Map<String, String> headers) {
HTTPHeadersBuilder hb = new HTTPHeadersBuilder();
hb.headers(headers);
callHTTP.getWith().setHeaders(hb.build());
return this;
}

public CallHTTPTaskBuilder body(Object body) {
this.callHTTP.getWith().setBody(body);
return this;
}

public CallHTTPTaskBuilder query(String expr) {
this.callHTTP.getWith().setQuery(new Query().withRuntimeExpression(expr));
return this;
}

public CallHTTPTaskBuilder query(Consumer<HTTPQueryBuilder> consumer) {
HTTPQueryBuilder queryBuilder = new HTTPQueryBuilder();
consumer.accept(queryBuilder);
callHTTP.getWith().setQuery(queryBuilder.build());
return this;
}

public CallHTTPTaskBuilder query(Map<String, String> query) {
HTTPQueryBuilder httpQueryBuilder = new HTTPQueryBuilder();
httpQueryBuilder.queries(query);
callHTTP.getWith().setQuery(httpQueryBuilder.build());
return this;
}

public CallHTTPTaskBuilder redirect(boolean redirect) {
callHTTP.getWith().setRedirect(redirect);
return this;
}

public CallHTTPTaskBuilder output(HTTPArguments.HTTPOutput output) {
callHTTP.getWith().setOutput(output);
return this;
}

public CallHTTP build() {
return callHTTP;
}

public static class HTTPQueryBuilder {
private final HTTPQuery httpQuery = new HTTPQuery();

public HTTPQueryBuilder query(String name, String value) {
httpQuery.setAdditionalProperty(name, value);
return this;
}

public HTTPQueryBuilder queries(Map<String, String> headers) {
headers.forEach(httpQuery::setAdditionalProperty);
return this;
}

public Query build() {
return new Query().withHTTPQuery(httpQuery);
}
}

public static class HTTPHeadersBuilder {
private final HTTPHeaders httpHeaders = new HTTPHeaders();

public HTTPHeadersBuilder header(String name, String value) {
httpHeaders.setAdditionalProperty(name, value);
return this;
}

public HTTPHeadersBuilder headers(Map<String, String> headers) {
headers.forEach(httpHeaders::setAdditionalProperty);
return this;
}

public Headers build() {
return new Headers().withHTTPHeaders(httpHeaders);
}
}
}
Loading