use of io.takari.bpm.Configuration 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;
}
use of io.takari.bpm.Configuration 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();
}
Aggregations