Skip to content
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
5 changes: 5 additions & 0 deletions fluent/spec/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,22 @@ public SELF one(Consumer<F> c) {

protected abstract void setOne(OneEventConsumptionStrategy strategy);

public SELF all(Consumer<F> c) {
@SafeVarargs
public final SELF all(Consumer<F>... consumers) {
ensureNoneSet();
allSet = true;
F fb = this.newEventFilterBuilder();
c.accept(fb);

List<EventFilter> built = new ArrayList<>(consumers.length);

for (Consumer<? super F> c : consumers) {
Objects.requireNonNull(c, "consumer");
F fb = this.newEventFilterBuilder();
c.accept(fb);
built.add(fb.build());
}

AllEventConsumptionStrategy strat = new AllEventConsumptionStrategy();
strat.setAll(List.of(fb.build()));
strat.setAll(built);
this.setAll(strat);
return this.self();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

import io.serverlessworkflow.api.types.CallHTTP;
import io.serverlessworkflow.api.types.Endpoint;
import io.serverlessworkflow.api.types.EndpointConfiguration;
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.ReferenceableAuthenticationPolicy;
import io.serverlessworkflow.api.types.UriTemplate;
import java.net.URI;
import java.util.Map;
Expand Down Expand Up @@ -55,12 +57,44 @@ public CallHTTPTaskBuilder endpoint(URI endpoint) {
return this;
}

public CallHTTPTaskBuilder endpoint(
URI endpoint, Consumer<AuthenticationPolicyUnionBuilder> auth) {
final AuthenticationPolicyUnionBuilder policy = new AuthenticationPolicyUnionBuilder();
auth.accept(policy);
this.callHTTP
.getWith()
.setEndpoint(
new Endpoint()
.withEndpointConfiguration(
new EndpointConfiguration()
.withAuthentication(
new ReferenceableAuthenticationPolicy()
.withAuthenticationPolicy(policy.build())))
.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 endpoint(
String expr, Consumer<AuthenticationPolicyUnionBuilder> auth) {
final AuthenticationPolicyUnionBuilder policy = new AuthenticationPolicyUnionBuilder();
auth.accept(policy);
this.callHTTP
.getWith()
.setEndpoint(
new Endpoint()
.withEndpointConfiguration(
new EndpointConfiguration()
.withAuthentication(
new ReferenceableAuthenticationPolicy()
.withAuthenticationPolicy(policy.build())))
.withRuntimeExpression(expr));
return this;
}

public CallHTTPTaskBuilder headers(String expr) {
this.callHTTP.getWith().setHeaders(new Headers().withRuntimeExpression(expr));
Expand All @@ -70,7 +104,18 @@ public CallHTTPTaskBuilder headers(String expr) {
public CallHTTPTaskBuilder headers(Consumer<HTTPHeadersBuilder> consumer) {
HTTPHeadersBuilder hb = new HTTPHeadersBuilder();
consumer.accept(hb);
callHTTP.getWith().setHeaders(hb.build());
if (callHTTP.getWith().getHeaders() != null
&& callHTTP.getWith().getHeaders().getHTTPHeaders() != null) {
Headers h = callHTTP.getWith().getHeaders();
Headers built = hb.build();
built
.getHTTPHeaders()
.getAdditionalProperties()
.forEach((k, v) -> h.getHTTPHeaders().setAdditionalProperty(k, v));
} else {
callHTTP.getWith().setHeaders(hb.build());
}

return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public SetTaskBuilder expr(String expression) {
return this;
}

public SetTaskBuilder put(String key, String value) {
public SetTaskBuilder put(String key, Object value) {
setTaskConfiguration.withAdditionalProperty(key, value);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public TryTaskBuilder<T> tryHandler(Consumer<T> consumer) {
return this;
}

public TryTaskBuilder<T> catchHandler(Consumer<TryTaskCatchBuilder> consumer) {
final TryTaskCatchBuilder catchBuilder = new TryTaskCatchBuilder();
public TryTaskBuilder<T> catchHandler(Consumer<TryTaskCatchBuilder<T>> consumer) {
final TryTaskCatchBuilder<T> catchBuilder =
new TryTaskCatchBuilder<>(this.doTaskBuilderFactory);
consumer.accept(catchBuilder);
this.tryTask.setCatch(catchBuilder.build());
return this;
Expand All @@ -68,42 +69,51 @@ public TryTask build() {
return tryTask;
}

public static final class TryTaskCatchBuilder {
public static final class TryTaskCatchBuilder<T extends BaseTaskItemListBuilder<T>> {
private final TryTaskCatch tryTaskCatch;
private final T doTaskBuilderFactory;

TryTaskCatchBuilder() {
TryTaskCatchBuilder(T doTaskBuilderFactory) {
this.doTaskBuilderFactory = doTaskBuilderFactory;
this.tryTaskCatch = new TryTaskCatch();
}

public TryTaskCatchBuilder as(final String as) {
public TryTaskCatchBuilder<T> as(final String as) {
this.tryTaskCatch.setAs(as);
return this;
}

public TryTaskCatchBuilder when(final String when) {
public TryTaskCatchBuilder<T> when(final String when) {
this.tryTaskCatch.setWhen(when);
return this;
}

public TryTaskCatchBuilder exceptWhen(final String exceptWhen) {
public TryTaskCatchBuilder<T> exceptWhen(final String exceptWhen) {
this.tryTaskCatch.setExceptWhen(exceptWhen);
return this;
}

public TryTaskCatchBuilder retry(Consumer<RetryPolicyBuilder> consumer) {
public TryTaskCatchBuilder<T> retry(Consumer<RetryPolicyBuilder> consumer) {
final RetryPolicyBuilder retryPolicyBuilder = new RetryPolicyBuilder();
consumer.accept(retryPolicyBuilder);
this.tryTaskCatch.setRetry(new Retry().withRetryPolicyDefinition(retryPolicyBuilder.build()));
return this;
}

public TryTaskCatchBuilder errorsWith(Consumer<CatchErrorsBuilder> consumer) {
public TryTaskCatchBuilder<T> errorsWith(Consumer<CatchErrorsBuilder> consumer) {
final CatchErrorsBuilder catchErrorsBuilder = new CatchErrorsBuilder();
consumer.accept(catchErrorsBuilder);
this.tryTaskCatch.setErrors(catchErrorsBuilder.build());
return this;
}

public TryTaskCatchBuilder<T> doTasks(Consumer<T> consumer) {
final T taskItemListBuilder = this.doTaskBuilderFactory.newItemListBuilder();
consumer.accept(taskItemListBuilder);
this.tryTaskCatch.setDo(taskItemListBuilder.build());
return this;
}

public TryTaskCatch build() {
return tryTaskCatch;
}
Expand Down Expand Up @@ -153,30 +163,30 @@ public static final class RetryPolicyJitterBuilder {
this.retryPolicyJitter = new RetryPolicyJitter();
}

public RetryPolicyJitter to(Consumer<DurationInlineBuilder> consumer) {
public RetryPolicyJitterBuilder to(Consumer<DurationInlineBuilder> consumer) {
final DurationInlineBuilder durationInlineBuilder = new DurationInlineBuilder();
consumer.accept(durationInlineBuilder);
this.retryPolicyJitter.setTo(
new TimeoutAfter().withDurationInline(durationInlineBuilder.build()));
return retryPolicyJitter;
return this;
}

public RetryPolicyJitter to(String expression) {
public RetryPolicyJitterBuilder to(String expression) {
this.retryPolicyJitter.setTo(new TimeoutAfter().withDurationExpression(expression));
return retryPolicyJitter;
return this;
}

public RetryPolicyJitter from(Consumer<DurationInlineBuilder> consumer) {
public RetryPolicyJitterBuilder from(Consumer<DurationInlineBuilder> consumer) {
final DurationInlineBuilder durationInlineBuilder = new DurationInlineBuilder();
consumer.accept(durationInlineBuilder);
this.retryPolicyJitter.setFrom(
new TimeoutAfter().withDurationInline(durationInlineBuilder.build()));
return retryPolicyJitter;
return this;
}

public RetryPolicyJitter from(String expression) {
public RetryPolicyJitterBuilder from(String expression) {
this.retryPolicyJitter.setFrom(new TimeoutAfter().withDurationExpression(expression));
return retryPolicyJitter;
return this;
}

public RetryPolicyJitter build() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.spec.configurers;

import io.serverlessworkflow.fluent.spec.AuthenticationPolicyUnionBuilder;
import java.util.function.Consumer;

@FunctionalInterface
public interface AuthenticationConfigurer extends Consumer<AuthenticationPolicyUnionBuilder> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.spec.configurers;

import io.serverlessworkflow.fluent.spec.CallHTTPTaskBuilder;
import java.util.function.Consumer;

@FunctionalInterface
public interface CallHTTPConfigurer extends Consumer<CallHTTPTaskBuilder> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.spec.configurers;

import io.serverlessworkflow.fluent.spec.EmitTaskBuilder;
import java.util.function.Consumer;

@FunctionalInterface
public interface EmitConfigurer extends Consumer<EmitTaskBuilder> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.spec.configurers;

import io.serverlessworkflow.fluent.spec.EventPropertiesBuilder;
import java.util.function.Consumer;

@FunctionalInterface
public interface EventConfigurer extends Consumer<EventPropertiesBuilder> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.spec.configurers;

import io.serverlessworkflow.fluent.spec.ForEachTaskBuilder;
import io.serverlessworkflow.fluent.spec.TaskItemListBuilder;
import java.util.function.Consumer;

@FunctionalInterface
public interface ForEachConfigurer extends Consumer<ForEachTaskBuilder<TaskItemListBuilder>> {}
Loading