use of org.activiti.engine.impl.ProcessEngineImpl in project Activiti by Activiti.
the class ReplayRunTest method initProcessEngine.
private ProcessEngineImpl initProcessEngine() {
ProcessEngineConfigurationImpl configuration = getProcessEngineConfiguration();
ProcessEngineImpl processEngine = (ProcessEngineImpl) configuration.buildProcessEngine();
processEngine.getRepositoryService().createDeployment().addClasspathResource(THE_USERTASK_PROCESS).deploy();
return processEngine;
}
use of org.activiti.engine.impl.ProcessEngineImpl in project Activiti by Activiti.
the class SimpleTableEditor method save.
protected void save() {
WorkflowDefinition workflowDefinition = createWorkflow();
final ProcessEngineImpl defaultProcessEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();
ProcessEngineConfiguration processEngineConfiguration = defaultProcessEngine.getProcessEngineConfiguration();
ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
Model model = null;
if (modelId == null) {
// new process
model = repositoryService.newModel();
} else {
// update existing process
model = repositoryService.getModel(modelId);
}
model.setName(workflowDefinition.getName());
model.setCategory(SimpleTableEditorConstants.TABLE_EDITOR_CATEGORY);
repositoryService.saveModel(model);
// Store model entity
WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
conversion.convert();
try {
// Write JSON to byte-array and set as editor-source
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ExplorerApp.get().getSimpleWorkflowJsonConverter().writeWorkflowDefinition(workflowDefinition, new OutputStreamWriter(baos));
repositoryService.addModelEditorSource(model.getId(), baos.toByteArray());
// Store process image
// TODO: we should really allow the service to take an inputstream as input. Now we load it into memory ...
repositoryService.addModelEditorSourceExtra(model.getId(), IOUtils.toByteArray(diagramGenerator.generateDiagram(conversion.getBpmnModel(), "png", processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader())));
} catch (IOException e) {
logger.warn("Could not generate process image. Image is not stored and will not be shown.", e);
}
ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(model.getId());
}
use of org.activiti.engine.impl.ProcessEngineImpl in project Activiti by Activiti.
the class ManagementServiceTest method testDeleteJobThatWasAlreadyAcquired.
@Deployment(resources = { "org/activiti/engine/test/api/mgmt/timerOnTask.bpmn20.xml" })
public void testDeleteJobThatWasAlreadyAcquired() {
processEngineConfiguration.getClock().setCurrentTime(new Date());
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerOnTask");
Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
// We need to move time at least one hour to make the timer executable
processEngineConfiguration.getClock().setCurrentTime(new Date(processEngineConfiguration.getClock().getCurrentTime().getTime() + 7200000L));
// Acquire job by running the acquire command manually
ProcessEngineImpl processEngineImpl = (ProcessEngineImpl) processEngine;
AcquireTimerJobsCmd acquireJobsCmd = new AcquireTimerJobsCmd("testLockOwner", 60000, 5);
CommandExecutor commandExecutor = processEngineImpl.getProcessEngineConfiguration().getCommandExecutor();
commandExecutor.execute(acquireJobsCmd);
// Try to delete the job. This should fail.
try {
managementService.deleteJob(timerJob.getId());
fail();
} catch (ActivitiException e) {
// Exception is expected
}
// Clean up
managementService.executeJob(timerJob.getId());
}
use of org.activiti.engine.impl.ProcessEngineImpl in project Activiti by Activiti.
the class ProcessEngineInitializationTest method testVersionMismatch.
public void testVersionMismatch() {
// first create the schema
ProcessEngineImpl processEngine = (ProcessEngineImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("org/activiti/standalone/initialization/notables.activiti.cfg.xml").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_CREATE_DROP).buildProcessEngine();
// then update the version to something that is different to the library
// version
DbSqlSessionFactory dbSqlSessionFactory = (DbSqlSessionFactory) processEngine.getProcessEngineConfiguration().getSessionFactories().get(DbSqlSession.class);
SqlSessionFactory sqlSessionFactory = dbSqlSessionFactory.getSqlSessionFactory();
SqlSession sqlSession = sqlSessionFactory.openSession();
boolean success = false;
try {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("name", "schema.version");
parameters.put("value", "25.7");
parameters.put("revision", 1);
parameters.put("newRevision", 2);
sqlSession.update("updateProperty", parameters);
success = true;
} catch (Exception e) {
throw new ActivitiException("couldn't update db schema version", e);
} finally {
if (success) {
sqlSession.commit();
} else {
sqlSession.rollback();
}
sqlSession.close();
}
try {
// now we can see what happens if when a process engine is being
// build with a version mismatch between library and db tables
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("org/activiti/standalone/initialization/notables.activiti.cfg.xml").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).buildProcessEngine();
fail("expected exception");
} catch (ActivitiWrongDbException e) {
assertTextPresent("version mismatch", e.getMessage());
assertEquals("25.7", e.getDbVersion());
assertEquals(ProcessEngine.VERSION, e.getLibraryVersion());
}
// closing the original process engine to drop the db tables
processEngine.close();
}
Aggregations