use of org.activiti.engine.RepositoryService in project Activiti by Activiti.
the class ProcessDefinitionCacheTest method testDeployRevisedProcessAfterDeleteOnOtherProcessEngine.
public void testDeployRevisedProcessAfterDeleteOnOtherProcessEngine() {
// Setup both process engines
ProcessEngine processEngine1 = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test-schema").setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000").setJobExecutorActivate(false).buildProcessEngine();
RepositoryService repositoryService1 = processEngine1.getRepositoryService();
ProcessEngine processEngine2 = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test").setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000").setJobExecutorActivate(false).buildProcessEngine();
RepositoryService repositoryService2 = processEngine2.getRepositoryService();
RuntimeService runtimeService2 = processEngine2.getRuntimeService();
TaskService taskService2 = processEngine2.getTaskService();
// Deploy first version of process: start->originalTask->end on first process engine
String deploymentId = repositoryService1.createDeployment().addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml").deploy().getId();
// Start process instance on second engine
String processDefinitionId = repositoryService2.createProcessDefinitionQuery().singleResult().getId();
runtimeService2.startProcessInstanceById(processDefinitionId);
Task task = taskService2.createTaskQuery().singleResult();
assertEquals("original task", task.getName());
// Delete the deployment on second process engine
repositoryService2.deleteDeployment(deploymentId, true);
assertEquals(0, repositoryService2.createDeploymentQuery().count());
assertEquals(0, runtimeService2.createProcessInstanceQuery().count());
// deploy a revised version of the process: start->revisedTask->end on first process engine
//
// Before the bugfix, this would set the cache on the first process engine,
// but the second process engine still has the original process definition in his cache.
// Since there is a deployment delete in between, the new generated process definition id is the same
// as in the original deployment, making the second process engine using the old cached process definition.
deploymentId = repositoryService1.createDeployment().addClasspathResource("org/activiti/engine/test/cache/revisedProcess.bpmn20.xml").deploy().getId();
// Start process instance on second process engine -> must use revised process definition
repositoryService2.createProcessDefinitionQuery().singleResult().getId();
runtimeService2.startProcessInstanceByKey("oneTaskProcess");
task = taskService2.createTaskQuery().singleResult();
assertEquals("revised task", task.getName());
// cleanup
repositoryService1.deleteDeployment(deploymentId, true);
processEngine1.close();
processEngine2.close();
}
use of org.activiti.engine.RepositoryService in project Activiti by Activiti.
the class DeploymentsJMXClientTest method testDeploymentsJmxClient.
@SuppressWarnings("unchecked")
@Test
public void testDeploymentsJmxClient() throws IOException, InterruptedException, MalformedObjectNameException, AttributeNotFoundException, MBeanException, ReflectionException, InstanceNotFoundException, IntrospectionException {
String hostName = Utils.getHostName();
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + hostName + ":10111/jndi/rmi://" + hostName + ":1099/jmxrmi/activiti");
ProcessEngineConfiguration processEngineConfig = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
ProcessEngine processEngine = processEngineConfig.buildProcessEngine();
// wait for jmx server to come up
Thread.sleep(500);
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
ObjectName deploymentsBeanName = new ObjectName("org.activiti.jmx.Mbeans:type=Deployments");
Thread.sleep(500);
// no process deployed yet
List<List<String>> deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
assertEquals(0, deployments.size());
// deploy process remotely
URL fileName = Thread.currentThread().getContextClassLoader().getResource("org/activiti/management/jmx/trivialProcess.bpmn");
mbsc.invoke(deploymentsBeanName, "deployProcessDefinition", new String[] { "trivialProcess.bpmn", fileName.getFile() }, new String[] { String.class.getName(), String.class.getName() });
// one process is there now, test remote deployments
deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
assertNotNull(deployments);
assertEquals(1, deployments.size());
assertEquals(3, deployments.get(0).size());
String firstDeploymentId = deployments.get(0).get(0);
// test remote process definition
List<List<String>> pdList = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "ProcessDefinitions");
assertNotNull(pdList);
assertEquals(1, pdList.size());
assertEquals(5, pdList.get(0).size());
assertNotNull(pdList.get(0).get(0));
assertEquals("My process", pdList.get(0).get(1));
// version
assertEquals("1", pdList.get(0).get(2));
// not suspended
assertEquals("false", pdList.get(0).get(3));
assertEquals("This process to test JMX", pdList.get(0).get(4));
// redeploy the same process
mbsc.invoke(deploymentsBeanName, "deployProcessDefinition", new String[] { "trivialProcess.bpmn", fileName.getFile() }, new String[] { String.class.getName(), String.class.getName() });
// now there should be two deployments
deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
assertNotNull(deployments);
assertEquals(2, deployments.size());
assertEquals(3, deployments.get(0).size());
assertEquals(3, deployments.get(1).size());
// there should be two process definitions, one with version equals to two
pdList = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "ProcessDefinitions");
assertNotNull(pdList);
assertEquals(2, pdList.size());
assertEquals(5, pdList.get(0).size());
assertEquals(5, pdList.get(1).size());
// check there is one with version= = 1 and another one with version == 2, other attributed are the same
String pidV2 = null;
String pidV1 = null;
if (pdList.get(0).get(2).equals("1") && pdList.get(1).get(2).equals("2")) {
pidV2 = pdList.get(1).get(0);
pidV1 = pdList.get(0).get(0);
} else if (pdList.get(1).get(2).equals("1") && pdList.get(0).get(2).equals("2")) {
pidV2 = pdList.get(0).get(0);
pidV1 = pdList.get(1).get(0);
} else
fail("there should one process definition with version == 1 and another one with version == 2. It is not the case");
assertNotNull(pdList.get(0).get(0));
assertNotNull(pdList.get(1).get(0));
assertEquals("My process", pdList.get(0).get(1));
assertEquals("My process", pdList.get(1).get(1));
// not suspended
assertEquals("false", pdList.get(0).get(3));
// not suspended
assertEquals("false", pdList.get(1).get(3));
assertEquals("This process to test JMX", pdList.get(0).get(4));
assertEquals("This process to test JMX", pdList.get(1).get(4));
//suspend the one with version == 2
mbsc.invoke(deploymentsBeanName, "suspendProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
RepositoryService repositoryService = processEngine.getRepositoryService();
// test if it is realy suspended and not the other one
assertTrue(repositoryService.getProcessDefinition(pidV2).isSuspended());
assertFalse(repositoryService.getProcessDefinition(pidV1).isSuspended());
// test if it is reported as suspended and not the other one
List<String> pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
assertNotNull(pd);
assertEquals(5, pd.size());
assertEquals("true", pd.get(3));
pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV1 }, new String[] { String.class.getName() });
assertNotNull(pd);
assertEquals(5, pd.size());
assertEquals("false", pd.get(3));
// now reactivate the same suspended process
mbsc.invoke(deploymentsBeanName, "activatedProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
// test if both processes are active again
assertFalse(repositoryService.getProcessDefinition(pidV2).isSuspended());
assertFalse(repositoryService.getProcessDefinition(pidV1).isSuspended());
// test if they are properly reported as activated
pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
assertNotNull(pd);
assertEquals(5, pd.size());
assertEquals("false", pd.get(3));
pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV1 }, new String[] { String.class.getName() });
assertNotNull(pd);
assertEquals(5, pd.size());
assertEquals("false", pd.get(3));
// now undeploy the one with version == 1
mbsc.invoke(deploymentsBeanName, "deleteDeployment", new String[] { firstDeploymentId }, new String[] { String.class.getName() });
// now there should be only one deployment and only one process definition with version 2, first check it with API
assertEquals(1, repositoryService.createDeploymentQuery().count());
assertTrue(!repositoryService.createDeploymentQuery().singleResult().getId().equals(firstDeploymentId));
// check if it is also affected in returned results.
deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
assertNotNull(deployments);
assertEquals(1, deployments.size());
assertEquals(3, deployments.get(0).size());
assertTrue(!deployments.get(0).get(0).equals(firstDeploymentId));
}
use of org.activiti.engine.RepositoryService in project Activiti by Activiti.
the class ChangeProcessSuspensionStatePopupWindow method addOkButton.
protected void addOkButton(final boolean suspend) {
verticalLayout.addComponent(new Label(" ", Label.CONTENT_XHTML));
verticalLayout.addComponent(new Label(" ", Label.CONTENT_XHTML));
Button okButton = new Button(i18nManager.getMessage(Messages.BUTTON_OK));
verticalLayout.addComponent(okButton);
verticalLayout.setComponentAlignment(okButton, Alignment.BOTTOM_CENTER);
okButton.addListener(new ClickListener() {
private static final long serialVersionUID = 1L;
public void buttonClick(ClickEvent event) {
RepositoryService repositoryService = ProcessEngines.getDefaultProcessEngine().getRepositoryService();
boolean includeProcessInstances = (Boolean) includeProcessInstancesCheckBox.getValue();
if (suspend) {
repositoryService.suspendProcessDefinitionById(processDefinitionId, includeProcessInstances, (Date) dateField.getValue());
} else {
repositoryService.activateProcessDefinitionById(processDefinitionId, includeProcessInstances, (Date) dateField.getValue());
}
close();
// select next item in list on the left
parentPage.refreshSelectNext();
}
});
}
use of org.activiti.engine.RepositoryService in project Activiti by Activiti.
the class ReportingUtil method generateTaskDurationReport.
// WARNING!!! DemoWare!!!
public static void generateTaskDurationReport(String processDefinitionId) {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
// Fetch process definition
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
// Report descriptin
String reportDescription = "Average task duration report for process definition " + processDefinition.getName() + " ( version " + processDefinition.getVersion() + ")";
// Script (just plain String for the moment)
String script = "importPackage(java.sql);" + "importPackage(java.lang);" + "importPackage(org.activiti.explorer.reporting);" + "" + "var processDefinitionId = '" + processDefinitionId + "';" + "" + "var result = ReportingUtil.executeSelectSqlQuery(\"select NAME_, avg(DURATION_) from ACT_HI_TASKINST where PROC_DEF_ID_ = '" + processDefinitionId + "' and END_TIME_ is not null group by NAME_\");" + "" + "var reportData = new ReportData();" + "var dataset = reportData.newDataset();" + "dataset.type = 'pieChart';" + "dataset.description = '" + reportDescription + "';" + "" + "while (result.next()) { " + " var name = result.getString(1);" + " var val = result.getLong(2) / 1000;" + " dataset.add(name, val);" + "}" + "" + "execution.setVariable('reportData', reportData.toBytes());";
// Generate bpmn model
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name(processDefinition.getName() + " task duration report").description(reportDescription).addScriptStep(script);
// Convert to BPMN 2.0 XML
WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
conversion.convert();
conversion.getBpmnModel().setTargetNamespace("activiti-report");
// Generate DI
BpmnAutoLayout bpmnAutoLayout = new BpmnAutoLayout(conversion.getBpmnModel());
bpmnAutoLayout.execute();
// Deploy
repositoryService.createDeployment().name(processDefinition.getName() + " - task duration report").addString(conversion.getProcess().getId() + ".bpmn20.xml", conversion.getBpmn20Xml()).deploy();
}
use of org.activiti.engine.RepositoryService in project Activiti by Activiti.
the class IntegrationAutoConfigurationTest method testLaunchingGatewayProcessDefinition.
@Test
public void testLaunchingGatewayProcessDefinition() throws Exception {
AnnotationConfigApplicationContext applicationContext = this.context(InboundGatewayConfiguration.class);
RepositoryService repositoryService = applicationContext.getBean(RepositoryService.class);
RuntimeService runtimeService = applicationContext.getBean(RuntimeService.class);
ProcessEngine processEngine = applicationContext.getBean(ProcessEngine.class);
Assert.assertNotNull("the process engine should not be null", processEngine);
Assert.assertNotNull("we should have a default repositoryService included", repositoryService);
String integrationGatewayProcess = "integrationGatewayProcess";
List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery().processDefinitionKey(integrationGatewayProcess).list();
ProcessDefinition processDefinition = processDefinitionList.iterator().next();
Assert.assertEquals(processDefinition.getKey(), integrationGatewayProcess);
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("customerId", 232);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(integrationGatewayProcess, vars);
Assert.assertNotNull("the processInstance should not be null", processInstance);
org.junit.Assert.assertTrue(applicationContext.getBean(InboundGatewayConfiguration.AnalysingService.class).getStringAtomicReference().get().equals(projectId));
}
Aggregations