Search in sources :

Example 11 with EntityNotFoundException

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

the class ProcessesImpl method getVariables.

@Override
public CollectionWithPagingInfo<Variable> getVariables(String processId, Paging paging) {
    CollectionWithPagingInfo<Variable> result = null;
    // Check if user is allowed to get variables
    List<HistoricVariableInstance> variableInstances = validateIfUserAllowedToWorkWithProcess(processId);
    Map<String, Object> variables = new HashMap<String, Object>();
    for (HistoricVariableInstance variable : variableInstances) {
        variables.put(variable.getVariableName(), variable.getValue());
    }
    ProcessInstance processInstance = activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processId).singleResult();
    String processDefinitionId = null;
    if (processInstance != null) {
        processDefinitionId = processInstance.getProcessDefinitionId();
    } else {
        // Completed process instance
        HistoricProcessInstance historicInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(processId).singleResult();
        if (historicInstance == null) {
            throw new EntityNotFoundException(processId);
        }
        processDefinitionId = historicInstance.getProcessDefinitionId();
    }
    // Get start-task definition for explicit typing of variables submitted at the start
    String formKey = null;
    StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(processDefinitionId);
    if (startFormData != null) {
        formKey = startFormData.getFormKey();
    }
    TypeDefinition startTaskTypeDefinition = getWorkflowFactory().getTaskFullTypeDefinition(formKey, true);
    // Convert raw variables to Variable objects
    List<Variable> resultingVariables = restVariableHelper.getVariables(variables, startTaskTypeDefinition);
    result = CollectionWithPagingInfo.asPaged(paging, resultingVariables);
    return result;
}
Also used : Variable(org.alfresco.rest.workflow.api.model.Variable) HashMap(java.util.HashMap) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) StartFormData(org.activiti.engine.form.StartFormData) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Example 12 with EntityNotFoundException

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

the class CustomModelsImpl method getCustomModelConstraint.

@Override
public CustomModelConstraint getCustomModelConstraint(String modelName, String constraintName, Parameters parameters) {
    if (constraintName == null) {
        throw new InvalidArgumentException(CONSTRAINT_NAME_NULL_ERR);
    }
    final CustomModelDefinition modelDef = getCustomModelImpl(modelName);
    QName constraintQname = QName.createQName(modelDef.getName().getNamespaceURI(), constraintName);
    ConstraintDefinition constraintDef = customModelService.getCustomConstraint(constraintQname);
    if (constraintDef == null) {
        throw new EntityNotFoundException(constraintName);
    }
    return new CustomModelConstraint(constraintDef, dictionaryService);
}
Also used : CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition)

Example 13 with EntityNotFoundException

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

the class CustomModelsImpl method deleteCustomAspect.

@Override
public void deleteCustomAspect(String modelName, String aspectName) {
    // Check the current user is authorised to delete the custom model's aspect
    validateCurrentUser();
    if (aspectName == null) {
        throw new InvalidArgumentException(ASPECT_NAME_NULL_ERR);
    }
    ModelDetails existingModelDetails = new ModelDetails(getCustomModelImpl(modelName));
    if (existingModelDetails.isActive()) {
        throw new ConstraintViolatedException("cmm.rest_api.aspect_cannot_delete");
    }
    Map<String, CustomAspect> allAspects = transformToMap(existingModelDetails.getAspects(), toNameFunction());
    CustomAspect aspectToBeDeleted = allAspects.get(aspectName);
    if (aspectToBeDeleted == null) {
        throw new EntityNotFoundException(aspectName);
    }
    // Validate aspect's dependency
    validateTypeAspectDelete(allAspects.values(), aspectToBeDeleted.getPrefixedName());
    // Remove the validated aspect
    allAspects.remove(aspectName);
    existingModelDetails.setAspects(new ArrayList<>(allAspects.values()));
    updateModel(existingModelDetails, "cmm.rest_api.aspect_delete_failure");
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) CustomAspect(org.alfresco.rest.api.model.CustomAspect) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 14 with EntityNotFoundException

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

the class CustomModelsImpl method getCustomAspect.

@Override
public CustomAspect getCustomAspect(String modelName, String aspectName, Parameters parameters) {
    if (aspectName == null) {
        throw new InvalidArgumentException(ASPECT_NAME_NULL_ERR);
    }
    final CustomModelDefinition modelDef = getCustomModelImpl(modelName);
    QName aspectQname = QName.createQName(modelDef.getName().getNamespaceURI(), aspectName);
    AspectDefinition customAspectDef = customModelService.getCustomAspect(aspectQname);
    if (customAspectDef == null) {
        throw new EntityNotFoundException(aspectName);
    }
    // Check if inherited properties have been requested
    boolean includeInheritedProps = hasSelectProperty(parameters, SELECT_ALL_PROPS);
    return convertToCustomAspect(customAspectDef, includeInheritedProps);
}
Also used : CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 15 with EntityNotFoundException

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

the class DeletedNodesImpl method restoreArchivedNode.

@Override
public Node restoreArchivedNode(String archivedId, NodeTargetAssoc nodeTargetAssoc) {
    // First check the node is valid and has been archived.
    NodeRef validatedNodeRef = nodes.validateNode(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, archivedId);
    RestoreNodeReport restored = null;
    if (nodeTargetAssoc != null) {
        NodeRef targetNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeTargetAssoc.getTargetParentId());
        QName assocType = nodes.getAssocType(nodeTargetAssoc.getAssocType());
        restored = nodeArchiveService.restoreArchivedNode(validatedNodeRef, targetNodeRef, assocType, null);
    } else {
        restored = nodeArchiveService.restoreArchivedNode(validatedNodeRef);
    }
    switch(restored.getStatus()) {
        case SUCCESS:
            return nodes.getFolderOrDocumentFullInfo(restored.getRestoredNodeRef(), null, null, null, null);
        case FAILURE_PERMISSION:
            throw new PermissionDeniedException();
        case FAILURE_INTEGRITY:
            throw new IntegrityException("Restore failed due to an integrity error", null);
        case FAILURE_DUPLICATE_CHILD_NODE_NAME:
            throw new ConstraintViolatedException("Name already exists in target");
        case FAILURE_INVALID_ARCHIVE_NODE:
            throw new EntityNotFoundException(archivedId);
        case FAILURE_INVALID_PARENT:
            throw new NotFoundException("Invalid parent id " + restored.getTargetParentNodeRef());
        default:
            throw new ApiException("Unable to restore node " + archivedId);
    }
}
Also used : RestoreNodeReport(org.alfresco.repo.node.archive.RestoreNodeReport) NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

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