use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class ProcessDefinitionResource method executeProcessDefinitionAction.
@RequestMapping(value = "/repository/process-definitions/{processDefinitionId}", method = RequestMethod.PUT, produces = "application/json")
public ProcessDefinitionResponse executeProcessDefinitionAction(@PathVariable String processDefinitionId, @RequestBody ProcessDefinitionActionRequest actionRequest, HttpServletRequest request) {
if (actionRequest == null) {
throw new ActivitiIllegalArgumentException("No action found in request body.");
}
ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
if (actionRequest.getCategory() != null) {
// Update of category required
repositoryService.setProcessDefinitionCategory(processDefinition.getId(), actionRequest.getCategory());
// No need to re-fetch the ProcessDefinition entity, just update category in response
ProcessDefinitionResponse response = restResponseFactory.createProcessDefinitionResponse(processDefinition);
response.setCategory(actionRequest.getCategory());
return response;
} else {
// Actual action
if (actionRequest.getAction() != null) {
if (ProcessDefinitionActionRequest.ACTION_SUSPEND.equals(actionRequest.getAction())) {
return suspendProcessDefinition(processDefinition, actionRequest.isIncludeProcessInstances(), actionRequest.getDate());
} else if (ProcessDefinitionActionRequest.ACTION_ACTIVATE.equals(actionRequest.getAction())) {
return activateProcessDefinition(processDefinition, actionRequest.isIncludeProcessInstances(), actionRequest.getDate());
}
}
throw new ActivitiIllegalArgumentException("Invalid action: '" + actionRequest.getAction() + "'.");
}
}
use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class SimpleWorkflowResource method createWorkflow.
@RequestMapping(value = "/simple-workflow", method = RequestMethod.POST, produces = "application/json")
public SimpleWorkflowSuccessResponse createWorkflow(@RequestBody String json) {
// Convert json to simple workflow definition
SimpleWorkflowJsonConverter jsonConverter = new SimpleWorkflowJsonConverter();
WorkflowDefinition workflowDefinition = jsonConverter.readWorkflowDefinition(json.getBytes());
WorkflowDefinitionConversionFactory conversionFactory = new WorkflowDefinitionConversionFactory();
WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(workflowDefinition);
conversion.convert();
// Deploy process
BpmnModel bpmnModel = conversion.getBpmnModel();
Deployment deployment = repositoryService.createDeployment().addBpmnModel(bpmnModel.getProcesses().get(0).getName() + ".bpmn20.xml", bpmnModel).deploy();
// Fetch process definition id
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
return new SimpleWorkflowSuccessResponse(processDefinition.getId());
}
use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class TerminateEndEventTest method testParseTerminateEndEventDefinitionWithExtensions.
public void testParseTerminateEndEventDefinitionWithExtensions() {
org.activiti.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/bpmn/event/end/TerminateEndEventTest.parseExtensionElements.bpmn20.xml").deploy();
ProcessDefinition processDefinitionQuery = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
ProcessDefinitionEntity processDefinition = this.processEngineConfiguration.getProcessDefinitionCache().get(processDefinitionQuery.getId());
assertThat(processDefinition.getActivities().size(), is(2));
ActivityImpl endEvent = processDefinition.getActivities().get(1);
assertThat(endEvent.getId(), is("terminateEnd"));
assertThat(endEvent.getActivityBehavior(), instanceOf(TerminateEndEventActivityBehavior.class));
TerminateEndEventActivityBehavior terminateEndEventBehavior = (TerminateEndEventActivityBehavior) endEvent.getActivityBehavior();
Map<String, List<ExtensionElement>> extensionElements = terminateEndEventBehavior.getEndEvent().getExtensionElements();
assertThat(extensionElements.size(), is(1));
List<ExtensionElement> strangeProperties = extensionElements.get("strangeProperty");
assertThat(strangeProperties.size(), is(1));
ExtensionElement strangeProperty = strangeProperties.get(0);
assertThat(strangeProperty.getNamespace(), is("http://activiti.org/bpmn"));
assertThat(strangeProperty.getElementText(), is("value"));
assertThat(strangeProperty.getAttributes().size(), is(1));
ExtensionAttribute id = strangeProperty.getAttributes().get("id").get(0);
assertThat(id.getName(), is("id"));
assertThat(id.getValue(), is("strangeId"));
repositoryService.deleteDeployment(deployment.getId());
}
use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class TenancyTest method testGetLatestProcessDefinitionVersionForSameProcessDefinitionKey.
/*
* See https://activiti.atlassian.net/browse/ACT-4034
*/
public void testGetLatestProcessDefinitionVersionForSameProcessDefinitionKey() {
String tenant1 = "tenant1";
String tenant2 = "tenant2";
// Tenant 1 ==> version 4
for (int i = 0; i < 4; i++) {
deployTestProcessWithTestTenant(tenant1);
}
// Tenant 2 ==> version 2
for (int i = 0; i < 2; i++) {
deployTestProcessWithTestTenant(tenant2);
}
// No tenant ==> version 3
for (int i = 0; i < 3; i++) {
deployTestProcessWithTwoTasksNoTenant();
}
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionTenantId(tenant1).latestVersion().singleResult();
assertEquals(4, processDefinition.getVersion());
processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionTenantId(tenant2).latestVersion().singleResult();
assertEquals(2, processDefinition.getVersion());
processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionWithoutTenantId().latestVersion().singleResult();
assertEquals(3, processDefinition.getVersion());
List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().latestVersion().list();
assertEquals(3, processDefinitions.size());
// Verify they have different tenant ids
int tenant1Count = 0, tenant2Count = 0, noTenantCount = 0;
for (ProcessDefinition p : processDefinitions) {
if (p.getTenantId() == null || p.getTenantId().equals(ProcessEngineConfiguration.NO_TENANT_ID)) {
noTenantCount++;
} else if (p.getTenantId().equals(tenant1)) {
tenant1Count++;
} else if (p.getTenantId().equals(tenant2)) {
tenant2Count++;
}
}
assertEquals(1, tenant1Count);
assertEquals(1, tenant2Count);
assertEquals(1, noTenantCount);
}
use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class AdminRunningInstancesPanel method initDefinitionsTable.
protected void initDefinitionsTable() {
if (instanceList == null || instanceList.isEmpty()) {
noMembersTable = new Label(i18nManager.getMessage(Messages.ADMIN_RUNNING_NONE_FOUND));
definitionsLayout.addComponent(noMembersTable);
} else {
runningDefinitions = new HashMap<String, ManagementProcessDefinition>();
for (HistoricProcessInstance instance : instanceList) {
String processDefinitionId = instance.getProcessDefinitionId();
ManagementProcessDefinition managementDefinition = null;
if (runningDefinitions.containsKey(processDefinitionId)) {
managementDefinition = runningDefinitions.get(processDefinitionId);
} else {
ProcessDefinition definition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
if (definition == null) {
// this process has a missing definition - skip
continue;
}
managementDefinition = new ManagementProcessDefinition();
managementDefinition.processDefinition = definition;
managementDefinition.runningInstances = new ArrayList<HistoricProcessInstance>();
runningDefinitions.put(definition.getId(), managementDefinition);
}
managementDefinition.runningInstances.add(instance);
}
definitionsTable = new Table();
definitionsTable.setWidth(100, UNITS_PERCENTAGE);
definitionsTable.setHeight(250, UNITS_PIXELS);
definitionsTable.setEditable(false);
definitionsTable.setImmediate(true);
definitionsTable.setSelectable(true);
definitionsTable.setSortDisabled(false);
definitionsTable.addContainerProperty("id", String.class, null, i18nManager.getMessage(Messages.PROCESS_INSTANCE_ID), null, Table.ALIGN_LEFT);
definitionsTable.addContainerProperty("name", String.class, null, i18nManager.getMessage(Messages.PROCESS_INSTANCE_NAME), null, Table.ALIGN_LEFT);
definitionsTable.addContainerProperty("nr of instances", String.class, null, i18nManager.getMessage(Messages.ADMIN_NR_INSTANCES), null, Table.ALIGN_LEFT);
for (ManagementProcessDefinition managementDefinition : runningDefinitions.values()) {
definitionsTable.addItem(new String[] { managementDefinition.processDefinition.getId(), managementDefinition.processDefinition.getName(), String.valueOf(managementDefinition.runningInstances.size()) }, managementDefinition.processDefinition.getId());
}
definitionsTable.addListener(new Property.ValueChangeListener() {
private static final long serialVersionUID = 1L;
public void valueChange(ValueChangeEvent event) {
// the value of the property is the itemId of the table entry
Item item = definitionsTable.getItem(event.getProperty().getValue());
if (item != null) {
String definitionId = (String) item.getItemProperty("id").getValue();
selectedManagementDefinition = runningDefinitions.get(definitionId);
refreshInstancesTable();
}
}
});
definitionsLayout.addComponent(definitionsTable);
}
}
Aggregations