use of io.automatiko.engine.workflow.base.core.context.variable.VariableScope in project automatiko-engine by automatiko-io.
the class LightProcessRuntime method createProcessInstance.
private io.automatiko.engine.workflow.base.instance.ProcessInstance createProcessInstance(Process process, CorrelationKey correlationKey, Map<String, Object> parameters) {
io.automatiko.engine.workflow.base.instance.ProcessInstance pi = runtimeContext.createProcessInstance(process, correlationKey);
pi.setProcessRuntime(this);
runtimeContext.setupParameters(pi, parameters, variableInitializer);
Map<String, Object> temp = new HashMap<>();
if (parameters != null) {
temp.putAll(parameters);
}
temp.putAll(pi.getVariables());
String uuid;
if (correlationKey != null) {
uuid = UUID.nameUUIDFromBytes(correlationKey.toExternalForm().getBytes(StandardCharsets.UTF_8)).toString();
((WorkflowProcessInstanceImpl) pi).setCorrelationKey(correlationKey.toExternalForm());
} else {
VariableScope variableScope = (VariableScope) ((ContextContainer) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
Optional<Object> businessKeyVar = variableScope.getVariables().stream().filter(var -> var.hasTag(Variable.BUSINESS_KEY_TAG)).map(v -> temp.get(v.getName())).filter(var -> var != null).findAny();
if (businessKeyVar.isPresent()) {
Object businessKey = businessKeyVar.get();
uuid = UUID.nameUUIDFromBytes(businessKey.toString().getBytes(StandardCharsets.UTF_8)).toString();
((WorkflowProcessInstanceImpl) pi).setCorrelationKey(businessKey.toString());
} else {
uuid = UUID.randomUUID().toString();
}
}
pi.setId(uuid);
VariableScope variableScope = (VariableScope) ((ContextContainer) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) pi.getContextInstance(VariableScope.VARIABLE_SCOPE);
// set input parameters
if (parameters != null) {
if (variableScope != null) {
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
variableScope.validateVariable(process.getName(), entry.getKey(), entry.getValue());
variableScopeInstance.setVariable(entry.getKey(), entry.getValue());
}
} else {
throw new IllegalArgumentException("This process does not support parameters!");
}
}
variableScopeInstance.enforceRequiredVariables();
return pi;
}
use of io.automatiko.engine.workflow.base.core.context.variable.VariableScope in project automatiko-engine by automatiko-io.
the class ProcessInstanceManagementResource method importInstance.
@APIResponses(value = { @APIResponse(responseCode = "404", description = "In case of instance with given process id was not found", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "200", description = "Exported process instance", content = @Content(mediaType = "application/json")) })
@Operation(summary = "Imports exported process instance and returns its details after the import")
@POST
@Path("/{processId}/instances")
@Produces(MediaType.APPLICATION_JSON)
public ProcessInstanceDetailsDTO importInstance(@Context UriInfo uriInfo, @Parameter(description = "Unique identifier of the process", required = true) @PathParam("processId") String processId, @Parameter(description = "User identifier as alternative autroization info", required = false, hidden = true) @QueryParam("user") final String user, @Parameter(description = "Groups as alternative autroization info", required = false, hidden = true) @QueryParam("group") final List<String> groups, @Parameter(description = "The input model for orders instance", schema = @Schema(type = SchemaType.OBJECT, implementation = Map.class)) JsonExportedProcessInstance instance) {
identitySupplier.buildIdentityProvider(user, groups);
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
ProcessInstance<?> pi = exporter.importInstance(instance);
ProcessInstanceDetailsDTO details = new ProcessInstanceDetailsDTO();
details.setId(pi.id());
details.setProcessId(processId);
details.setBusinessKey(pi.businessKey());
details.setDescription(pi.description());
details.setFailed(pi.errors().isPresent());
if (pi.errors().isPresent()) {
details.setErrors(pi.errors().get().errors().stream().map(e -> new ErrorInfoDTO(e.failedNodeId(), e.errorId(), e.errorMessage(), e.errorDetails())).collect(Collectors.toList()));
}
details.setImage(uriInfo.getBaseUri().toString() + "management/processes/" + processId + "/instances/" + pi.id() + "/image");
details.setTags(pi.tags().values());
details.setVariables(pi.variables());
VariableScope variableScope = (VariableScope) ((ContextContainer) ((AbstractProcess<?>) pi.process()).process()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
details.setVersionedVariables(variableScope.getVariables().stream().filter(v -> v.hasTag(Variable.VERSIONED_TAG)).map(v -> v.getName()).collect(Collectors.toList()));
return details;
});
}
use of io.automatiko.engine.workflow.base.core.context.variable.VariableScope in project automatiko-engine by automatiko-io.
the class CompositeContextNodeFactory method variable.
public CompositeContextNodeFactory variable(String name, DataType type, Object value, String metaDataName, Object metaDataValue) {
Variable variable = new Variable();
variable.setName(name);
variable.setType(type);
variable.setValue(value);
if (metaDataName != null && metaDataValue != null) {
variable.setMetaData(metaDataName, metaDataValue);
}
VariableScope variableScope = (VariableScope) getCompositeNode().getDefaultContext(VariableScope.VARIABLE_SCOPE);
if (variableScope == null) {
variableScope = new VariableScope();
getCompositeNode().addContext(variableScope);
getCompositeNode().setDefaultContext(variableScope);
}
variableScope.getVariables().add(variable);
return this;
}
use of io.automatiko.engine.workflow.base.core.context.variable.VariableScope in project automatiko-engine by automatiko-io.
the class ForEachNode method setVariable.
public void setVariable(String variableName, DataType type) {
this.variableName = variableName;
VariableScope variableScope = (VariableScope) getCompositeNode().getDefaultContext(VariableScope.VARIABLE_SCOPE);
List<Variable> variables = variableScope.getVariables();
if (variables == null) {
variables = new ArrayList<Variable>();
variableScope.setVariables(variables);
}
Variable variable = new Variable();
variable.setId((String) getMetaData().getOrDefault("MIInput", variableName));
variable.setName(variableName);
variable.setType(type);
variables.add(variable);
}
use of io.automatiko.engine.workflow.base.core.context.variable.VariableScope in project automatiko-engine by automatiko-io.
the class ForEachNode method setOutputVariable.
public void setOutputVariable(String variableName, DataType type) {
this.outputVariableName = variableName;
VariableScope variableScope = (VariableScope) getCompositeNode().getDefaultContext(VariableScope.VARIABLE_SCOPE);
List<Variable> variables = variableScope.getVariables();
if (variables == null) {
variables = new ArrayList<Variable>();
variableScope.setVariables(variables);
}
Variable variable = new Variable();
variable.setId((String) getMetaData().getOrDefault("MIOutput", variableName));
variable.setName(variableName);
variable.setType(type);
variables.add(variable);
Variable tmpvariable = new Variable();
tmpvariable.setId("foreach_output");
tmpvariable.setName("foreach_output");
tmpvariable.setType(type);
variables.add(tmpvariable);
}
Aggregations