Search in sources :

Example 56 with ActivitiObjectNotFoundException

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

the class DeploymentResourceResource method getDeploymentResource.

@RequestMapping(value = "/repository/deployments/{deploymentId}/resources/**", method = RequestMethod.GET, produces = "application/json")
public DeploymentResourceResponse getDeploymentResource(@PathVariable("deploymentId") String deploymentId, HttpServletRequest request) {
    // Check if deployment exists
    Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
    if (deployment == null) {
        throw new ActivitiObjectNotFoundException("Could not find a deployment with id '" + deploymentId + "'.");
    }
    String pathInfo = request.getPathInfo();
    String resourceName = pathInfo.replace("/repository/deployments/" + deploymentId + "/resources/", "");
    List<String> resourceList = repositoryService.getDeploymentResourceNames(deploymentId);
    if (resourceList.contains(resourceName)) {
        // Build resource representation
        DeploymentResourceResponse response = restResponseFactory.createDeploymentResourceResponse(deploymentId, resourceName, contentTypeResolver.resolveContentType(resourceName));
        return response;
    } else {
        // Resource not found in deployment
        throw new ActivitiObjectNotFoundException("Could not find a resource with id '" + resourceName + "' in deployment '" + deploymentId + "'.");
    }
}
Also used : Deployment(org.activiti.engine.repository.Deployment) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 57 with ActivitiObjectNotFoundException

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

the class AddCommentCmd method execute.

public Comment execute(CommandContext commandContext) {
    // Validate task
    if (taskId != null) {
        TaskEntity task = commandContext.getTaskEntityManager().findTaskById(taskId);
        if (task == null) {
            throw new ActivitiObjectNotFoundException("Cannot find task with id " + taskId, Task.class);
        }
        if (task.isSuspended()) {
            throw new ActivitiException(getSuspendedTaskException());
        }
    }
    if (processInstanceId != null) {
        ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
        if (execution == null) {
            throw new ActivitiObjectNotFoundException("execution " + processInstanceId + " doesn't exist", Execution.class);
        }
        if (execution.isSuspended()) {
            throw new ActivitiException(getSuspendedExceptionMessage());
        }
    }
    String userId = Authentication.getAuthenticatedUserId();
    CommentEntity comment = new CommentEntity();
    comment.setUserId(userId);
    comment.setType((type == null) ? CommentEntity.TYPE_COMMENT : type);
    comment.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());
    comment.setTaskId(taskId);
    comment.setProcessInstanceId(processInstanceId);
    comment.setAction(Event.ACTION_ADD_COMMENT);
    String eventMessage = message.replaceAll("\\s+", " ");
    if (eventMessage.length() > 163) {
        eventMessage = eventMessage.substring(0, 160) + "...";
    }
    comment.setMessage(eventMessage);
    comment.setFullMessage(message);
    commandContext.getCommentEntityManager().insert(comment);
    return comment;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) CommentEntity(org.activiti.engine.impl.persistence.entity.CommentEntity)

Example 58 with ActivitiObjectNotFoundException

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

the class AddIdentityLinkForProcessInstanceCmd method execute.

public Void execute(CommandContext commandContext) {
    ExecutionEntity processInstance = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
    if (processInstance == null) {
        throw new ActivitiObjectNotFoundException("Cannot find process instance with id " + processInstanceId, ExecutionEntity.class);
    }
    processInstance.addIdentityLink(userId, groupId, type);
    commandContext.getHistoryManager().createProcessInstanceIdentityLinkComment(processInstanceId, userId, groupId, type, true);
    return null;
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 59 with ActivitiObjectNotFoundException

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

the class ChangeDeploymentTenantIdCmd method execute.

public Void execute(CommandContext commandContext) {
    if (deploymentId == null) {
        throw new ActivitiIllegalArgumentException("deploymentId is null");
    }
    // Update all entities
    DeploymentEntity deployment = commandContext.getDeploymentEntityManager().findDeploymentById(deploymentId);
    if (deployment == null) {
        throw new ActivitiObjectNotFoundException("Could not find deployment with id " + deploymentId, Deployment.class);
    }
    String oldTenantId = deployment.getTenantId();
    deployment.setTenantId(newTenantId);
    // Doing process instances, executions and tasks with direct SQL updates (otherwise would not be performant) 
    commandContext.getProcessDefinitionEntityManager().updateProcessDefinitionTenantIdForDeployment(deploymentId, newTenantId);
    commandContext.getExecutionEntityManager().updateExecutionTenantIdForDeployment(deploymentId, newTenantId);
    commandContext.getTaskEntityManager().updateTaskTenantIdForDeployment(deploymentId, newTenantId);
    commandContext.getJobEntityManager().updateJobTenantIdForDeployment(deploymentId, newTenantId);
    commandContext.getEventSubscriptionEntityManager().updateEventSubscriptionTenantId(oldTenantId, newTenantId);
    // Doing process definitions in memory, cause we need to clear the process definition cache
    List<ProcessDefinition> processDefinitions = commandContext.getDbSqlSession().createProcessDefinitionQuery().deploymentId(deploymentId).list();
    for (ProcessDefinition processDefinition : processDefinitions) {
        commandContext.getProcessEngineConfiguration().getProcessDefinitionCache().remove(processDefinition.getId());
    }
    // Clear process definition cache
    commandContext.getProcessEngineConfiguration().getProcessDefinitionCache().clear();
    return null;
}
Also used : DeploymentEntity(org.activiti.engine.impl.persistence.entity.DeploymentEntity) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 60 with ActivitiObjectNotFoundException

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

the class DeleteIdentityLinkForProcessDefinitionCmd 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.deleteIdentityLink(userId, groupId);
    return null;
}
Also used : ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

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