Search in sources :

Example 46 with ActivitiObjectNotFoundException

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

the class TaskServiceTest method testSetAssigneeUnexistingTask.

public void testSetAssigneeUnexistingTask() {
    User user = identityService.newUser("user");
    identityService.saveUser(user);
    try {
        taskService.setAssignee("unexistingTaskId", user.getId());
        fail("ActivitiException expected");
    } catch (ActivitiObjectNotFoundException ae) {
        assertTextPresent("Cannot find task with id unexistingTaskId", ae.getMessage());
        assertEquals(Task.class, ae.getObjectClass());
    }
    identityService.deleteUser(user.getId());
}
Also used : Task(org.activiti.engine.task.Task) User(org.activiti.engine.identity.User) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 47 with ActivitiObjectNotFoundException

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

the class HistoricTaskInstanceVariableDataResource method getVariableData.

@RequestMapping(value = "/history/historic-task-instances/{taskId}/variables/{variableName}/data", method = RequestMethod.GET)
@ResponseBody
public byte[] getVariableData(@PathVariable("taskId") String taskId, @PathVariable("variableName") String variableName, @RequestParam(value = "scope", required = false) String scope, HttpServletRequest request, HttpServletResponse response) {
    try {
        byte[] result = null;
        RestVariable variable = getVariableFromRequest(true, taskId, variableName, scope, request);
        if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variable.getType())) {
            result = (byte[]) variable.getValue();
            response.setContentType("application/octet-stream");
        } else if (RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variable.getType())) {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutputStream outputStream = new ObjectOutputStream(buffer);
            outputStream.writeObject(variable.getValue());
            outputStream.close();
            result = buffer.toByteArray();
            response.setContentType("application/x-java-serialized-object");
        } else {
            throw new ActivitiObjectNotFoundException("The variable does not have a binary data stream.", null);
        }
        return result;
    } catch (IOException ioe) {
        // Re-throw IOException
        throw new ActivitiException("Unexpected exception getting variable data", ioe);
    }
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable) ActivitiException(org.activiti.engine.ActivitiException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 48 with ActivitiObjectNotFoundException

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

the class HistoricTaskInstanceVariableDataResource method getVariableFromRequest.

public RestVariable getVariableFromRequest(boolean includeBinary, String taskId, String variableName, String scope, HttpServletRequest request) {
    RestVariableScope variableScope = RestVariable.getScopeFromString(scope);
    HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery().taskId(taskId);
    if (variableScope != null) {
        if (variableScope == RestVariableScope.GLOBAL) {
            taskQuery.includeProcessVariables();
        } else {
            taskQuery.includeTaskLocalVariables();
        }
    } else {
        taskQuery.includeTaskLocalVariables().includeProcessVariables();
    }
    HistoricTaskInstance taskObject = taskQuery.singleResult();
    if (taskObject == null) {
        throw new ActivitiObjectNotFoundException("Historic task instance '" + taskId + "' couldn't be found.", HistoricTaskInstanceEntity.class);
    }
    Object value = null;
    if (variableScope != null) {
        if (variableScope == RestVariableScope.GLOBAL) {
            value = taskObject.getProcessVariables().get(variableName);
        } else {
            value = taskObject.getTaskLocalVariables().get(variableName);
        }
    } else {
        // look for local task variables first
        if (taskObject.getTaskLocalVariables().containsKey(variableName)) {
            value = taskObject.getTaskLocalVariables().get(variableName);
        } else {
            value = taskObject.getProcessVariables().get(variableName);
        }
    }
    if (value == null) {
        throw new ActivitiObjectNotFoundException("Historic task instance '" + taskId + "' variable value for " + variableName + " couldn't be found.", VariableInstanceEntity.class);
    } else {
        return restResponseFactory.createRestVariable(variableName, value, null, taskId, RestResponseFactory.VARIABLE_HISTORY_TASK, includeBinary);
    }
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) RestVariableScope(org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope) HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 49 with ActivitiObjectNotFoundException

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

the class HistoricVariableInstanceDataResource method getVariableData.

@RequestMapping(value = "/history/historic-variable-instances/{varInstanceId}/data", method = RequestMethod.GET)
@ResponseBody
public byte[] getVariableData(@PathVariable("varInstanceId") String varInstanceId, HttpServletRequest request, HttpServletResponse response) {
    try {
        byte[] result = null;
        RestVariable variable = getVariableFromRequest(true, varInstanceId, request);
        if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variable.getType())) {
            result = (byte[]) variable.getValue();
            response.setContentType("application/octet-stream");
        } else if (RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variable.getType())) {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutputStream outputStream = new ObjectOutputStream(buffer);
            outputStream.writeObject(variable.getValue());
            outputStream.close();
            result = buffer.toByteArray();
            response.setContentType("application/x-java-serialized-object");
        } else {
            throw new ActivitiObjectNotFoundException("The variable does not have a binary data stream.", null);
        }
        return result;
    } catch (IOException ioe) {
        // Re-throw IOException
        throw new ActivitiException("Unexpected exception getting variable data", ioe);
    }
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable) ActivitiException(org.activiti.engine.ActivitiException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 50 with ActivitiObjectNotFoundException

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

the class GroupMembershipResource method deleteMembership.

@RequestMapping(value = "/identity/groups/{groupId}/members/{userId}", method = RequestMethod.DELETE)
public void deleteMembership(@PathVariable("groupId") String groupId, @PathVariable("userId") String userId, HttpServletRequest request, HttpServletResponse response) {
    Group group = getGroupFromRequest(groupId);
    // Check if user is not a member of group since API doesn't return typed exception
    if (identityService.createUserQuery().memberOfGroup(group.getId()).userId(userId).count() != 1) {
        throw new ActivitiObjectNotFoundException("User '" + userId + "' is not part of group '" + group.getId() + "'.", null);
    }
    identityService.deleteMembership(userId, group.getId());
    response.setStatus(HttpStatus.NO_CONTENT.value());
}
Also used : Group(org.activiti.engine.identity.Group) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)88 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)27 ActivitiException (org.activiti.engine.ActivitiException)26 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)26 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)17 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)15 Task (org.activiti.engine.task.Task)12 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)8 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 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