Search in sources :

Example 1 with DefaultExecutionContextFactory

use of io.takari.bpm.context.DefaultExecutionContextFactory in project concord by walmartlabs.

the class EngineFactory method create.

@SuppressWarnings("deprecation")
public Engine create(ProjectDefinition project, Path baseDir, Collection<String> activeProfiles, Set<String> metaVariables, EventConfiguration eventCfg) {
    Path attachmentsDir = baseDir.resolve(InternalConstants.Files.JOB_ATTACHMENTS_DIR_NAME);
    Path stateDir = attachmentsDir.resolve(InternalConstants.Files.JOB_STATE_DIR_NAME);
    Path eventsDir = stateDir.resolve("events");
    Path instancesDir = stateDir.resolve("instances");
    Path formsDir = stateDir.resolve(InternalConstants.Files.JOB_FORMS_DIR_NAME);
    try {
        Files.createDirectories(eventsDir);
        Files.createDirectories(instancesDir);
        Files.createDirectories(formsDir);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    ExpressionManager expressionManager = new DefaultExpressionManager(new String[] { InternalConstants.Context.CONTEXT_KEY, InternalConstants.Context.EXECUTION_CONTEXT_KEY }, new TaskResolver(taskRegistry), new InjectVariableELResolver()) {

        @Override
        protected ELResolver createResolver(ExecutionContext ctx) {
            CompositeELResolver cr = new CompositeELResolver();
            cr.add(new ExecutionContextVariableResolver(ctx));
            for (ELResolver r : resolvers) {
                cr.add(r);
            }
            return cr;
        }
    };
    FormStorage formStorage = new FileFormStorage(formsDir);
    // here we create a separate ContextFactory to avoid circular references
    // between ConcordFormService and ConcordExecutionContextFactory
    // TODO find a better way
    FormService formService = new ConcordFormService(new DefaultExecutionContextFactory(expressionManager), new NoopResumeHandler(), formStorage);
    ProtectedVarContext protectedVarContext = new ProtectedVarContext(PolicyEngineHolder.INSTANCE.getEngine());
    ConcordExecutionContextFactory contextFactory = new ConcordExecutionContextFactory(expressionManager, protectedVarContext, formService);
    EventStorage eventStorage = new FileEventStorage(eventsDir);
    PersistenceManager persistenceManager = new FilePersistenceManager(instancesDir);
    ProjectDefinitionAdapter adapter = new ProjectDefinitionAdapter(project, activeProfiles, baseDir);
    UserTaskHandler uth = new FormTaskHandler(contextFactory, adapter.forms(), formService);
    Configuration cfg = new Configuration();
    cfg.setInterpolateInputVariables(true);
    cfg.setWrapAllExceptionsAsBpmnErrors(true);
    cfg.setCopyAllCallActivityOutVariables(true);
    ElementEventProcessor eventProcessor;
    if (eventCfg.isRecordEvents()) {
        eventProcessor = new DefaultElementEventProcessor(apiClientFactory, adapter.processes());
    } else {
        eventProcessor = new NopElementEventProcessor();
    }
    ProcessOutVariables outVariables = new ProcessOutVariables(contextFactory);
    List<TaskInterceptor> taskInterceptors = new ArrayList<>();
    taskInterceptors.add(protectedVarContext);
    taskInterceptors.add(new TaskEventInterceptor(eventCfg, eventProcessor));
    taskInterceptors.add(new PolicyPreprocessor(baseDir));
    Engine engine = new EngineBuilder().withContextFactory(contextFactory).withLockManager(new NoopLockManager()).withExpressionManager(expressionManager).withDefinitionProvider(adapter.processes()).withTaskRegistry(taskRegistry).withJavaDelegateHandler(new JavaDelegateHandlerImpl(taskInterceptors)).withEventStorage(eventStorage).withPersistenceManager(persistenceManager).withUserTaskHandler(uth).withConfiguration(cfg).withListener(new ProcessOutVariablesListener(attachmentsDir, outVariables)).withListener(new VariablesSnapshotListener(stateDir)).withResourceResolver(new ResourceResolverImpl(baseDir)).build();
    engine.addInterceptor(new ProcessElementInterceptor(eventProcessor, new ProcessMetadataProcessor(apiClientFactory, metaVariables)));
    return engine;
}
Also used : NoopLockManager(io.takari.bpm.lock.NoopLockManager) Configuration(io.takari.bpm.Configuration) TaskResolver(com.walmartlabs.concord.runner.engine.el.TaskResolver) FormService(io.takari.bpm.form.FormService) ArrayList(java.util.ArrayList) InjectVariableELResolver(com.walmartlabs.concord.runner.engine.el.InjectVariableELResolver) DefaultExecutionContextFactory(io.takari.bpm.context.DefaultExecutionContextFactory) InjectVariableELResolver(com.walmartlabs.concord.runner.engine.el.InjectVariableELResolver) CompositeELResolver(javax.el.CompositeELResolver) ELResolver(javax.el.ELResolver) FormStorage(io.takari.bpm.form.FormStorage) UserTaskHandler(io.takari.bpm.task.UserTaskHandler) EngineBuilder(io.takari.bpm.EngineBuilder) Engine(io.takari.bpm.api.Engine) Path(java.nio.file.Path) DefaultExpressionManager(io.takari.bpm.el.DefaultExpressionManager) ExpressionManager(io.takari.bpm.el.ExpressionManager) FormTaskHandler(io.takari.bpm.form.FormTaskHandler) CompositeELResolver(javax.el.CompositeELResolver) PersistenceManager(io.takari.bpm.persistence.PersistenceManager) ExecutionContextVariableResolver(io.takari.bpm.el.ExecutionContextVariableResolver) IOException(java.io.IOException) VariablesSnapshotListener(com.walmartlabs.concord.runner.VariablesSnapshotListener) ExecutionContext(io.takari.bpm.api.ExecutionContext) DefaultExpressionManager(io.takari.bpm.el.DefaultExpressionManager) NoopResumeHandler(io.takari.bpm.form.DefaultFormService.NoopResumeHandler) EventStorage(io.takari.bpm.event.EventStorage)

Example 2 with DefaultExecutionContextFactory

use of io.takari.bpm.context.DefaultExecutionContextFactory in project concord by walmartlabs.

the class AbstractYamlParserTest method setUp.

@BeforeEach
@SuppressWarnings("unchecked")
public void setUp() {
    taskRegistry = new TestServiceTaskRegistry();
    forms = new HashMap<>();
    FormStorage fs = new TestFormStorage(forms);
    ExpressionManager expressionManager = new DefaultExpressionManager(taskRegistry);
    DefaultExecutionContextFactory contextFactory = new DefaultExecutionContextFactory(expressionManager);
    DefaultFormService.ResumeHandler rs = (form, args) -> getEngine().resume(form.getProcessBusinessKey(), form.getEventName(), args);
    formService = new DefaultFormService(contextFactory, rs, fs) {

        @Override
        public FormField toFormField(Map<String, Object> m) {
            Map.Entry<String, Object> entry = m.entrySet().iterator().next();
            Map<String, Object> opts = (Map<String, Object>) entry.getValue();
            return new FormField.Builder(entry.getKey(), (String) opts.get("type")).build();
        }
    };
    ResourceResolver resourceResolver = ClassLoader::getSystemResourceAsStream;
    Configuration cfg = new Configuration();
    cfg.setInterpolateInputVariables(true);
    cfg.setWrapAllExceptionsAsBpmnErrors(true);
    cfg.setCopyAllCallActivityOutVariables(true);
    engine = new EngineBuilder().withDefinitionProvider(workflowProvider.processes()).withTaskRegistry(taskRegistry).withUserTaskHandler(new FormTaskHandler(contextFactory, workflowProvider.forms(), formService)).withResourceResolver(resourceResolver).withConfiguration(cfg).build();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Configuration(io.takari.bpm.Configuration) ImportManager(com.walmartlabs.concord.imports.ImportManager) ProcessDefinitionProvider(io.takari.bpm.ProcessDefinitionProvider) HashMap(java.util.HashMap) FormField(io.takari.bpm.model.form.FormField) UUID(java.util.UUID) DefaultExpressionManager(io.takari.bpm.el.DefaultExpressionManager) ExecutionException(io.takari.bpm.api.ExecutionException) ExpressionManager(io.takari.bpm.el.ExpressionManager) EngineBuilder(io.takari.bpm.EngineBuilder) ServiceTaskRegistry(io.takari.bpm.task.ServiceTaskRegistry) DefaultExecutionContextFactory(io.takari.bpm.context.DefaultExecutionContextFactory) Engine(io.takari.bpm.api.Engine) ProcessDefinition(io.takari.bpm.model.ProcessDefinition) ProjectDefinition(com.walmartlabs.concord.project.model.ProjectDefinition) Map(java.util.Map) FormDefinition(io.takari.bpm.model.form.FormDefinition) ResourceResolver(io.takari.bpm.resource.ResourceResolver) io.takari.bpm.form(io.takari.bpm.form) ProjectLoader(com.walmartlabs.concord.project.ProjectLoader) InputStream(java.io.InputStream) Mockito.mock(org.mockito.Mockito.mock) DefaultExpressionManager(io.takari.bpm.el.DefaultExpressionManager) ExpressionManager(io.takari.bpm.el.ExpressionManager) Configuration(io.takari.bpm.Configuration) EngineBuilder(io.takari.bpm.EngineBuilder) DefaultExecutionContextFactory(io.takari.bpm.context.DefaultExecutionContextFactory) DefaultExpressionManager(io.takari.bpm.el.DefaultExpressionManager) ResourceResolver(io.takari.bpm.resource.ResourceResolver) FormField(io.takari.bpm.model.form.FormField) HashMap(java.util.HashMap) Map(java.util.Map) EngineBuilder(io.takari.bpm.EngineBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Configuration (io.takari.bpm.Configuration)2 EngineBuilder (io.takari.bpm.EngineBuilder)2 Engine (io.takari.bpm.api.Engine)2 DefaultExecutionContextFactory (io.takari.bpm.context.DefaultExecutionContextFactory)2 DefaultExpressionManager (io.takari.bpm.el.DefaultExpressionManager)2 ExpressionManager (io.takari.bpm.el.ExpressionManager)2 ImportManager (com.walmartlabs.concord.imports.ImportManager)1 ProjectLoader (com.walmartlabs.concord.project.ProjectLoader)1 ProjectDefinition (com.walmartlabs.concord.project.model.ProjectDefinition)1 VariablesSnapshotListener (com.walmartlabs.concord.runner.VariablesSnapshotListener)1 InjectVariableELResolver (com.walmartlabs.concord.runner.engine.el.InjectVariableELResolver)1 TaskResolver (com.walmartlabs.concord.runner.engine.el.TaskResolver)1 ProcessDefinitionProvider (io.takari.bpm.ProcessDefinitionProvider)1 ExecutionContext (io.takari.bpm.api.ExecutionContext)1 ExecutionException (io.takari.bpm.api.ExecutionException)1 ExecutionContextVariableResolver (io.takari.bpm.el.ExecutionContextVariableResolver)1 EventStorage (io.takari.bpm.event.EventStorage)1 io.takari.bpm.form (io.takari.bpm.form)1 NoopResumeHandler (io.takari.bpm.form.DefaultFormService.NoopResumeHandler)1 FormService (io.takari.bpm.form.FormService)1