|
| 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.func; |
| 17 | + |
| 18 | +import io.serverlessworkflow.api.types.ErrorDetails; |
| 19 | +import io.serverlessworkflow.api.types.ErrorTitle; |
| 20 | +import io.serverlessworkflow.api.types.ErrorType; |
| 21 | +import io.serverlessworkflow.api.types.RaiseTask; |
| 22 | +import io.serverlessworkflow.api.types.RaiseTaskConfiguration; |
| 23 | +import io.serverlessworkflow.api.types.RaiseTaskError; |
| 24 | +import io.serverlessworkflow.api.types.UriTemplate; |
| 25 | +import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder; |
| 26 | +import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations; |
| 27 | +import io.serverlessworkflow.fluent.spec.TaskBaseBuilder; |
| 28 | +import java.net.URI; |
| 29 | +import java.util.function.Consumer; |
| 30 | + |
| 31 | +public class FuncRaiseTaskBuilder extends TaskBaseBuilder<FuncRaiseTaskBuilder> |
| 32 | + implements FuncTaskTransformations<FuncRaiseTaskBuilder>, |
| 33 | + ConditionalTaskBuilder<FuncRaiseTaskBuilder> { |
| 34 | + |
| 35 | + private final RaiseTask raiseTask; |
| 36 | + |
| 37 | + FuncRaiseTaskBuilder() { |
| 38 | + this.raiseTask = new RaiseTask(); |
| 39 | + setTask(this.raiseTask); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + protected FuncRaiseTaskBuilder self() { |
| 44 | + return this; |
| 45 | + } |
| 46 | + |
| 47 | + public FuncRaiseTaskBuilder error(Consumer<RaiseTaskErrorBuilder> consumer) { |
| 48 | + final RaiseTaskErrorBuilder raiseTaskErrorBuilder = new RaiseTaskErrorBuilder(); |
| 49 | + consumer.accept(raiseTaskErrorBuilder); |
| 50 | + this.raiseTask.setRaise(new RaiseTaskConfiguration().withError(raiseTaskErrorBuilder.build())); |
| 51 | + return this; |
| 52 | + } |
| 53 | + |
| 54 | + public FuncRaiseTaskBuilder error(String errorReference) { |
| 55 | + this.raiseTask.setRaise( |
| 56 | + new RaiseTaskConfiguration() |
| 57 | + .withError(new RaiseTaskError().withRaiseErrorReference(errorReference))); |
| 58 | + return this; |
| 59 | + } |
| 60 | + |
| 61 | + public RaiseTask build() { |
| 62 | + return this.raiseTask; |
| 63 | + } |
| 64 | + |
| 65 | + public static final class RaiseTaskErrorBuilder { |
| 66 | + private final io.serverlessworkflow.api.types.Error error; |
| 67 | + |
| 68 | + private RaiseTaskErrorBuilder() { |
| 69 | + this.error = new io.serverlessworkflow.api.types.Error(); |
| 70 | + } |
| 71 | + |
| 72 | + public RaiseTaskErrorBuilder type(String expression) { |
| 73 | + this.error.setType(new ErrorType().withExpressionErrorType(expression)); |
| 74 | + return this; |
| 75 | + } |
| 76 | + |
| 77 | + public RaiseTaskErrorBuilder type(URI errorType) { |
| 78 | + this.error.setType( |
| 79 | + new ErrorType().withLiteralErrorType(new UriTemplate().withLiteralUri(errorType))); |
| 80 | + return this; |
| 81 | + } |
| 82 | + |
| 83 | + public RaiseTaskErrorBuilder status(int status) { |
| 84 | + this.error.setStatus(status); |
| 85 | + return this; |
| 86 | + } |
| 87 | + |
| 88 | + public RaiseTaskErrorBuilder title(String expression) { |
| 89 | + this.error.setTitle(new ErrorTitle().withExpressionErrorTitle(expression)); |
| 90 | + return this; |
| 91 | + } |
| 92 | + |
| 93 | + public RaiseTaskErrorBuilder detail(String expression) { |
| 94 | + this.error.setDetail(new ErrorDetails().withExpressionErrorDetails(expression)); |
| 95 | + return this; |
| 96 | + } |
| 97 | + |
| 98 | + public RaiseTaskError build() { |
| 99 | + return new RaiseTaskError().withRaiseErrorDefinition(this.error); |
| 100 | + } |
| 101 | + } |
| 102 | +} |
0 commit comments