Search in sources :

Example 1 with FormStorage

use of io.takari.bpm.form.FormStorage 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)

Aggregations

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 Configuration (io.takari.bpm.Configuration)1 EngineBuilder (io.takari.bpm.EngineBuilder)1 Engine (io.takari.bpm.api.Engine)1 ExecutionContext (io.takari.bpm.api.ExecutionContext)1 DefaultExecutionContextFactory (io.takari.bpm.context.DefaultExecutionContextFactory)1 DefaultExpressionManager (io.takari.bpm.el.DefaultExpressionManager)1 ExecutionContextVariableResolver (io.takari.bpm.el.ExecutionContextVariableResolver)1 ExpressionManager (io.takari.bpm.el.ExpressionManager)1 EventStorage (io.takari.bpm.event.EventStorage)1 NoopResumeHandler (io.takari.bpm.form.DefaultFormService.NoopResumeHandler)1 FormService (io.takari.bpm.form.FormService)1 FormStorage (io.takari.bpm.form.FormStorage)1 FormTaskHandler (io.takari.bpm.form.FormTaskHandler)1 NoopLockManager (io.takari.bpm.lock.NoopLockManager)1 PersistenceManager (io.takari.bpm.persistence.PersistenceManager)1 UserTaskHandler (io.takari.bpm.task.UserTaskHandler)1 IOException (java.io.IOException)1