Search in sources :

Example 11 with ProcessEngineImpl

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;
}
Also used : ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl)

Example 12 with ProcessEngineImpl

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());
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) Model(org.activiti.engine.repository.Model) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl) RepositoryService(org.activiti.engine.RepositoryService)

Example 13 with ProcessEngineImpl

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());
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) Date(java.util.Date) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl) AcquireTimerJobsCmd(org.activiti.engine.impl.cmd.AcquireTimerJobsCmd) Deployment(org.activiti.engine.test.Deployment)

Example 14 with ProcessEngineImpl

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();
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiWrongDbException(org.activiti.engine.ActivitiWrongDbException) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession) SqlSession(org.apache.ibatis.session.SqlSession) HashMap(java.util.HashMap) ActivitiException(org.activiti.engine.ActivitiException) ActivitiWrongDbException(org.activiti.engine.ActivitiWrongDbException) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession) DbSqlSessionFactory(org.activiti.engine.impl.db.DbSqlSessionFactory) DbSqlSessionFactory(org.activiti.engine.impl.db.DbSqlSessionFactory) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl)

Aggregations

ProcessEngineImpl (org.activiti.engine.impl.ProcessEngineImpl)14 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)4 NoExecutionVariableScope (org.activiti.engine.impl.el.NoExecutionVariableScope)4 ProcessEngineConfiguration (org.activiti.engine.ProcessEngineConfiguration)3 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)3 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)3 ProcessDiagramGenerator (org.activiti.image.ProcessDiagramGenerator)3 Test (org.junit.Test)3 StreamResource (com.vaadin.terminal.StreamResource)2 Embedded (com.vaadin.ui.Embedded)2 HashMap (java.util.HashMap)2 ReplaySimulationRun (org.activiti.crystalball.simulator.ReplaySimulationRun)2 SimulationDebugger (org.activiti.crystalball.simulator.SimulationDebugger)2 DefaultClockFactory (org.activiti.crystalball.simulator.impl.clock.DefaultClockFactory)2 ThreadLocalClock (org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock)2 ActivitiException (org.activiti.engine.ActivitiException)2 RuntimeService (org.activiti.engine.RuntimeService)2 TaskService (org.activiti.engine.TaskService)2 CommandConfig (org.activiti.engine.impl.interceptor.CommandConfig)2 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)2