Search in sources :

Example 71 with ProcessDefinition

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() + "'.");
    }
}
Also used : ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 72 with ProcessDefinition

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());
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) WorkflowDefinitionConversionFactory(org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Deployment(org.activiti.engine.repository.Deployment) SimpleWorkflowJsonConverter(org.activiti.workflow.simple.converter.json.SimpleWorkflowJsonConverter) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) BpmnModel(org.activiti.bpmn.model.BpmnModel) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 73 with ProcessDefinition

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());
}
Also used : ExtensionElement(org.activiti.bpmn.model.ExtensionElement) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ExtensionAttribute(org.activiti.bpmn.model.ExtensionAttribute) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) List(java.util.List) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) TerminateEndEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.TerminateEndEventActivityBehavior)

Example 74 with ProcessDefinition

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);
}
Also used : ProcessDefinition(org.activiti.engine.repository.ProcessDefinition)

Example 75 with ProcessDefinition

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);
    }
}
Also used : Table(com.vaadin.ui.Table) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) Label(com.vaadin.ui.Label) PrettyTimeLabel(org.activiti.explorer.ui.custom.PrettyTimeLabel) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Item(com.vaadin.data.Item) ValueChangeEvent(com.vaadin.data.Property.ValueChangeEvent) Property(com.vaadin.data.Property)

Aggregations

ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)211 Deployment (org.activiti.engine.test.Deployment)82 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)42 ArrayList (java.util.ArrayList)29 ActivitiException (org.activiti.engine.ActivitiException)25 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)23 RepositoryService (org.activiti.engine.RepositoryService)20 ProcessDefinitionQuery (org.activiti.engine.repository.ProcessDefinitionQuery)19 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)19 Task (org.activiti.engine.task.Task)16 Date (java.util.Date)14 Test (org.junit.Test)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 HashMap (java.util.HashMap)12 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)11 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)11 InputStream (java.io.InputStream)10 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)10 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)9