-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Francisco Javier Tirado Sarti <ftirados@redhat.com>
- Loading branch information
Showing
23 changed files
with
719 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
impl/src/main/java/io/serverlessworkflow/impl/WorkflowFactories.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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.impl; | ||
|
||
import io.serverlessworkflow.impl.executors.TaskExecutorFactory; | ||
import io.serverlessworkflow.impl.expressions.ExpressionFactory; | ||
import io.serverlessworkflow.impl.jsonschema.SchemaValidatorFactory; | ||
import io.serverlessworkflow.resources.ResourceLoader; | ||
|
||
public class WorkflowFactories { | ||
|
||
private final TaskExecutorFactory taskFactory; | ||
private final ResourceLoader resourceLoader; | ||
private final ExpressionFactory expressionFactory; | ||
private final SchemaValidatorFactory validatorFactory; | ||
|
||
public WorkflowFactories( | ||
TaskExecutorFactory taskFactory, | ||
ResourceLoader loaderFactory, | ||
ExpressionFactory expressionFactory, | ||
SchemaValidatorFactory validatorFactory) { | ||
this.taskFactory = taskFactory; | ||
this.resourceLoader = loaderFactory; | ||
this.expressionFactory = expressionFactory; | ||
this.validatorFactory = validatorFactory; | ||
} | ||
|
||
public TaskExecutorFactory getTaskFactory() { | ||
return taskFactory; | ||
} | ||
|
||
public ResourceLoader getResourceLoader() { | ||
return resourceLoader; | ||
} | ||
|
||
public ExpressionFactory getExpressionFactory() { | ||
return expressionFactory; | ||
} | ||
|
||
public SchemaValidatorFactory getValidatorFactory() { | ||
return validatorFactory; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
impl/src/main/java/io/serverlessworkflow/impl/WorkflowFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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.impl; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import java.util.Optional; | ||
|
||
@FunctionalInterface | ||
public interface WorkflowFilter { | ||
JsonNode apply(WorkflowContext workflow, Optional<TaskContext<?>> task, JsonNode node); | ||
} |
99 changes: 99 additions & 0 deletions
99
impl/src/main/java/io/serverlessworkflow/impl/WorkflowUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* 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.impl; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.serverlessworkflow.api.types.ExportAs; | ||
import io.serverlessworkflow.api.types.InputFrom; | ||
import io.serverlessworkflow.api.types.OutputAs; | ||
import io.serverlessworkflow.api.types.SchemaExternal; | ||
import io.serverlessworkflow.api.types.SchemaInline; | ||
import io.serverlessworkflow.api.types.SchemaUnion; | ||
import io.serverlessworkflow.impl.expressions.Expression; | ||
import io.serverlessworkflow.impl.expressions.ExpressionFactory; | ||
import io.serverlessworkflow.impl.expressions.ExpressionUtils; | ||
import io.serverlessworkflow.impl.json.JsonUtils; | ||
import io.serverlessworkflow.impl.jsonschema.SchemaValidator; | ||
import io.serverlessworkflow.impl.jsonschema.SchemaValidatorFactory; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.UncheckedIOException; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class WorkflowUtils { | ||
|
||
private WorkflowUtils() {} | ||
|
||
public static Optional<SchemaValidator> getSchemaValidator( | ||
SchemaValidatorFactory validatorFactory, Optional<JsonNode> node) { | ||
return node.map(n -> validatorFactory.getValidator(n)); | ||
} | ||
|
||
public static Optional<JsonNode> schemaToNode(WorkflowFactories factories, SchemaUnion schema) { | ||
if (schema != null) { | ||
if (schema.getSchemaInline() != null) { | ||
SchemaInline inline = schema.getSchemaInline(); | ||
return Optional.of(JsonUtils.mapper().convertValue(inline.getDocument(), JsonNode.class)); | ||
} else if (schema.getSchemaExternal() != null) { | ||
SchemaExternal external = schema.getSchemaExternal(); | ||
try (InputStream in = | ||
factories.getResourceLoader().loadStatic(external.getResource()).open()) { | ||
return Optional.of(JsonUtils.mapper().readTree(in)); | ||
} catch (IOException io) { | ||
throw new UncheckedIOException(io); | ||
} | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
public static Optional<WorkflowFilter> buildWorkflowFilter( | ||
ExpressionFactory exprFactory, InputFrom from) { | ||
return from != null | ||
? Optional.of(buildWorkflowFilter(exprFactory, from.getString(), from.getObject())) | ||
: Optional.empty(); | ||
} | ||
|
||
public static Optional<WorkflowFilter> buildWorkflowFilter( | ||
ExpressionFactory exprFactory, OutputAs as) { | ||
return as != null | ||
? Optional.of(buildWorkflowFilter(exprFactory, as.getString(), as.getObject())) | ||
: Optional.empty(); | ||
} | ||
|
||
public static Optional<WorkflowFilter> buildWorkflowFilter( | ||
ExpressionFactory exprFactory, ExportAs as) { | ||
return as != null | ||
? Optional.of(buildWorkflowFilter(exprFactory, as.getString(), as.getObject())) | ||
: Optional.empty(); | ||
} | ||
|
||
private static WorkflowFilter buildWorkflowFilter( | ||
ExpressionFactory exprFactory, String str, Object object) { | ||
if (str != null) { | ||
Expression expression = exprFactory.getExpression(str); | ||
return expression::eval; | ||
} else { | ||
Object exprObj = ExpressionUtils.buildExpressionObject(object, exprFactory); | ||
return exprObj instanceof Map | ||
? (w, t, n) -> | ||
JsonUtils.fromValue( | ||
ExpressionUtils.evaluateExpressionMap((Map<String, Object>) exprObj, w, t, n)) | ||
: (w, t, n) -> JsonUtils.fromValue(object); | ||
} | ||
} | ||
} |
Oops, something went wrong.