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;
}
Aggregations