Search in sources :

Example 11 with ActivitiObjectNotFoundException

use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.

the class AddIdentityLinkForProcessDefinitionCmd method execute.

public Void execute(CommandContext commandContext) {
    ProcessDefinitionEntity processDefinition = commandContext.getProcessDefinitionEntityManager().findProcessDefinitionById(processDefinitionId);
    if (processDefinition == null) {
        throw new ActivitiObjectNotFoundException("Cannot find process definition with id " + processDefinitionId, ProcessDefinition.class);
    }
    processDefinition.addIdentityLink(userId, groupId);
    return null;
}
Also used : ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 12 with ActivitiObjectNotFoundException

use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.

the class SetProcessDefinitionCategoryCmd method execute.

public Void execute(CommandContext commandContext) {
    if (processDefinitionId == null) {
        throw new ActivitiIllegalArgumentException("Process definition id is null");
    }
    ProcessDefinitionEntity processDefinition = commandContext.getProcessDefinitionEntityManager().findProcessDefinitionById(processDefinitionId);
    if (processDefinition == null) {
        throw new ActivitiObjectNotFoundException("No process definition found for id = '" + processDefinitionId + "'", ProcessDefinition.class);
    }
    // Update category
    processDefinition.setCategory(category);
    // Remove process definition from cache, it will be refetched later
    DeploymentCache<ProcessDefinitionEntity> processDefinitionCache = commandContext.getProcessEngineConfiguration().getProcessDefinitionCache();
    if (processDefinitionCache != null) {
        processDefinitionCache.remove(processDefinitionId);
    }
    if (commandContext.getEventDispatcher().isEnabled()) {
        commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, processDefinition));
    }
    return null;
}
Also used : ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 13 with ActivitiObjectNotFoundException

use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.

the class SetProcessInstanceNameCmd method execute.

@Override
public Void execute(CommandContext commandContext) {
    if (processInstanceId == null) {
        throw new ActivitiIllegalArgumentException("processInstanceId is null");
    }
    ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
    if (execution == null) {
        throw new ActivitiObjectNotFoundException("process instance " + processInstanceId + " doesn't exist", ProcessInstance.class);
    }
    if (!execution.isProcessInstanceType()) {
        throw new ActivitiObjectNotFoundException("process instance " + processInstanceId + " doesn't exist, the given ID references an execution, though", ProcessInstance.class);
    }
    if (execution.isSuspended()) {
        throw new ActivitiException("process instance " + processInstanceId + " is suspended, cannot set name");
    }
    // Actually set the name
    execution.setName(name);
    // Record the change in history
    commandContext.getHistoryManager().recordProcessInstanceNameChange(processInstanceId, name);
    return null;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 14 with ActivitiObjectNotFoundException

use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.

the class RuntimeServiceTest method testSetProcessInstanceName.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testSetProcessInstanceName() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    assertNotNull(processInstance);
    assertNull(processInstance.getName());
    // Set the name
    runtimeService.setProcessInstanceName(processInstance.getId(), "New name");
    processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(processInstance);
    assertEquals("New name", processInstance.getName());
    // Set the name to null
    runtimeService.setProcessInstanceName(processInstance.getId(), null);
    processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(processInstance);
    assertNull(processInstance.getName());
    // Set name for unexisting process instance, should fail
    try {
        runtimeService.setProcessInstanceName("unexisting", null);
        fail("Exception excpected");
    } catch (ActivitiObjectNotFoundException aonfe) {
        assertEquals(ProcessInstance.class, aonfe.getObjectClass());
    }
    processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(processInstance);
    assertNull(processInstance.getName());
    // Set name for suspended process instance, should fail
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    try {
        runtimeService.setProcessInstanceName(processInstance.getId(), null);
        fail("Exception excpected");
    } catch (ActivitiException ae) {
        assertEquals("process instance " + processInstance.getId() + " is suspended, cannot set name", ae.getMessage());
    }
    processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(processInstance);
    assertNull(processInstance.getName());
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) Deployment(org.activiti.engine.test.Deployment)

Example 15 with ActivitiObjectNotFoundException

use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.

the class DeploymentManager method getBpmnModelById.

public BpmnModel getBpmnModelById(String processDefinitionId) {
    if (processDefinitionId == null) {
        throw new ActivitiIllegalArgumentException("Invalid process definition id : null");
    }
    // first try the cache
    BpmnModel bpmnModel = bpmnModelCache.get(processDefinitionId);
    if (bpmnModel == null) {
        ProcessDefinitionEntity processDefinition = findDeployedProcessDefinitionById(processDefinitionId);
        if (processDefinition == null) {
            throw new ActivitiObjectNotFoundException("no deployed process definition found with id '" + processDefinitionId + "'", ProcessDefinition.class);
        }
        // Fetch the resource
        String resourceName = processDefinition.getResourceName();
        ResourceEntity resource = Context.getCommandContext().getResourceEntityManager().findResourceByDeploymentIdAndResourceName(processDefinition.getDeploymentId(), resourceName);
        if (resource == null) {
            if (Context.getCommandContext().getDeploymentEntityManager().findDeploymentById(processDefinition.getDeploymentId()) == null) {
                throw new ActivitiObjectNotFoundException("deployment for process definition does not exist: " + processDefinition.getDeploymentId(), Deployment.class);
            } else {
                throw new ActivitiObjectNotFoundException("no resource found with name '" + resourceName + "' in deployment '" + processDefinition.getDeploymentId() + "'", InputStream.class);
            }
        }
        // Convert the bpmn 2.0 xml to a bpmn model
        BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
        bpmnModel = bpmnXMLConverter.convertToBpmnModel(new BytesStreamSource(resource.getBytes()), false, false);
        bpmnModelCache.add(processDefinition.getId(), bpmnModel);
    }
    return bpmnModel;
}
Also used : BytesStreamSource(org.activiti.engine.impl.util.io.BytesStreamSource) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ResourceEntity(org.activiti.engine.impl.persistence.entity.ResourceEntity) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter)

Aggregations

ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)87 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)27 ActivitiException (org.activiti.engine.ActivitiException)25 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)25 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)16 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)15 Task (org.activiti.engine.task.Task)12 User (org.activiti.engine.identity.User)8 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)8 RestVariable (org.activiti.rest.service.api.engine.variable.RestVariable)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 IOException (java.io.IOException)7 ObjectOutputStream (java.io.ObjectOutputStream)7 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)7 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)7 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)6 RestVariableScope (org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 Comment (org.activiti.engine.task.Comment)5 DeploymentEntity (org.activiti.engine.impl.persistence.entity.DeploymentEntity)4