Search in sources :

Example 56 with EntityNotFoundException

use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.

the class ProcessDefinitionsImpl method getStartFormModel.

@Override
public CollectionWithPagingInfo<FormModelElement> getStartFormModel(String definitionId, Paging paging) {
    // first validate if user is allowed to access the process definition if workflows are deployed per tenant
    if (tenantService.isEnabled() && deployWorkflowsInTenant) {
        ProcessDefinitionQuery query = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionId(definitionId);
        query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
        org.activiti.engine.repository.ProcessDefinition processDefinition = query.singleResult();
        if (processDefinition == null) {
            throw new EntityNotFoundException(definitionId);
        }
    }
    StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(definitionId);
    if (startFormData == null) {
        throw new EntityNotFoundException(definitionId);
    }
    if (qNameConverter == null) {
        qNameConverter = new WorkflowQNameConverter(namespaceService);
    }
    if (workflowFactory == null) {
        workflowFactory = new WorkflowObjectFactory(qNameConverter, tenantService, messageService, dictionaryService, engineId, defaultStartTaskType);
    }
    // Lookup type definition for the startTask
    TypeDefinition startTaskType = workflowFactory.getTaskFullTypeDefinition(startFormData.getFormKey(), true);
    return getFormModelElements(startTaskType, paging);
}
Also used : WorkflowQNameConverter(org.alfresco.repo.workflow.WorkflowQNameConverter) StartFormData(org.activiti.engine.form.StartFormData) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) WorkflowObjectFactory(org.alfresco.repo.workflow.WorkflowObjectFactory) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition)

Example 57 with EntityNotFoundException

use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.

the class ProcessesImpl method getProcessImage.

@Override
public BinaryResource getProcessImage(String processId) {
    validateIfUserAllowedToWorkWithProcess(processId);
    ProcessInstance processInstance = activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processId).singleResult();
    if (processInstance == null) {
        throw new EntityNotFoundException(processId);
    }
    try {
        BpmnModel model = activitiProcessEngine.getRepositoryService().getBpmnModel(processInstance.getProcessDefinitionId());
        if (model != null && model.getLocationMap().size() > 0) {
            List<String> activeActivities = activitiProcessEngine.getRuntimeService().getActiveActivityIds(processId);
            ProcessDiagramGenerator generator = new DefaultProcessDiagramGenerator();
            InputStream generateDiagram = generator.generateDiagram(model, "png", activeActivities);
            File file = TempFileProvider.createTempFile(processId + UUID.randomUUID(), ".png");
            FileOutputStream fos = new FileOutputStream(file);
            IOUtils.copy(generateDiagram, fos);
            fos.close();
            return new FileBinaryResource(file);
        } else {
            throw new EntityNotFoundException(processId + "/image");
        }
    } catch (IOException error) {
        throw new ApiException("Error while getting process image.");
    }
}
Also used : InputStream(java.io.InputStream) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) IOException(java.io.IOException) FileBinaryResource(org.alfresco.rest.framework.resource.content.FileBinaryResource) BpmnModel(org.activiti.bpmn.model.BpmnModel) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) FileOutputStream(java.io.FileOutputStream) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) File(java.io.File) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Example 58 with EntityNotFoundException

use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.

the class ProcessesImpl method updateVariable.

@Override
public Variable updateVariable(String processId, Variable variable) {
    validateIfUserAllowedToWorkWithProcess(processId);
    ProcessInstance processInstance = activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processId).singleResult();
    if (processInstance == null) {
        throw new EntityNotFoundException(processId);
    }
    return updateVariableInProcess(processId, processInstance.getProcessDefinitionId(), variable);
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 59 with EntityNotFoundException

use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.

the class ProcessesImpl method updateVariables.

@Override
public List<Variable> updateVariables(String processId, List<Variable> variables) {
    validateIfUserAllowedToWorkWithProcess(processId);
    ProcessInstance processInstance = activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processId).singleResult();
    if (processInstance == null) {
        throw new EntityNotFoundException(processId);
    }
    List<Variable> updatedVariables = new ArrayList<Variable>();
    if (variables != null) {
        for (Variable variable : variables) {
            updatedVariables.add(updateVariableInProcess(processId, processInstance.getProcessDefinitionId(), variable));
        }
    }
    return updatedVariables;
}
Also used : Variable(org.alfresco.rest.workflow.api.model.Variable) ArrayList(java.util.ArrayList) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 60 with EntityNotFoundException

use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.

the class WorkflowRestImpl method deleteItemFromProcess.

/**
 *  Delete an item from the process package variable
 */
public void deleteItemFromProcess(String itemId, String processId) {
    NodeRef nodeRef = getNodeRef(itemId);
    ActivitiScriptNode packageScriptNode = null;
    try {
        packageScriptNode = (ActivitiScriptNode) activitiProcessEngine.getRuntimeService().getVariable(processId, BPM_PACKAGE);
    } catch (ActivitiObjectNotFoundException e) {
        throw new EntityNotFoundException(processId);
    }
    if (packageScriptNode == null) {
        throw new InvalidArgumentException("process doesn't contain a workflow package variable");
    }
    boolean itemIdFoundInPackage = false;
    List<ChildAssociationRef> documentList = nodeService.getChildAssocs(packageScriptNode.getNodeRef());
    for (ChildAssociationRef childAssociationRef : documentList) {
        if (childAssociationRef.getChildRef().equals(nodeRef)) {
            itemIdFoundInPackage = true;
            break;
        }
    }
    if (itemIdFoundInPackage == false) {
        throw new EntityNotFoundException("Item " + itemId + " not found in the process package variable");
    }
    try {
        nodeService.removeChild(packageScriptNode.getNodeRef(), nodeRef);
        activitiWorkflowEngine.dispatchPackageUpdatedEvent(packageScriptNode, null, null, processId, null);
    } catch (InvalidNodeRefException e) {
        throw new EntityNotFoundException("Item " + itemId + " not found");
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ActivitiScriptNode(org.alfresco.repo.workflow.activiti.ActivitiScriptNode) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Aggregations

EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)66 NodeRef (org.alfresco.service.cmr.repository.NodeRef)28 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)24 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)16 QName (org.alfresco.service.namespace.QName)15 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)12 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)12 HashMap (java.util.HashMap)11 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)11 ArrayList (java.util.ArrayList)9 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)8 InvalidSharedIdException (org.alfresco.service.cmr.quickshare.InvalidSharedIdException)7 Serializable (java.io.Serializable)6 FileInfo (org.alfresco.service.cmr.model.FileInfo)6 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)5 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)5 ActivitiScriptNode (org.alfresco.repo.workflow.activiti.ActivitiScriptNode)5 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)5 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)4 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)4