Search in sources :

Example 36 with EntityNotFoundException

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

the class ResultMapper method getNode.

/**
 * Builds a node representation based on a ResultSetRow;
 * @param searchRequestContext
 * @param aRow
 * @param params
 * @param mapUserInfo
 * @param isHistory
 * @return Node
 */
public Node getNode(ResultSetRow aRow, Params params, Map<String, UserInfo> mapUserInfo, boolean isHistory) {
    String nodeStore = storeMapper.getStore(aRow.getNodeRef());
    if (isHistory)
        nodeStore = HISTORY;
    Node aNode = null;
    switch(nodeStore) {
        case LIVE_NODES:
            aNode = nodes.getFolderOrDocument(aRow.getNodeRef(), null, null, params.getInclude(), mapUserInfo);
            break;
        case HISTORY:
            aNode = nodes.getFolderOrDocument(aRow.getNodeRef(), null, null, params.getInclude(), mapUserInfo);
            break;
        case VERSIONS:
            Map<QName, Serializable> properties = serviceRegistry.getNodeService().getProperties(aRow.getNodeRef());
            NodeRef frozenNodeRef = ((NodeRef) properties.get(Version2Model.PROP_QNAME_FROZEN_NODE_REF));
            String versionLabelId = (String) properties.get(Version2Model.PROP_QNAME_VERSION_LABEL);
            Version v = null;
            try {
                if (frozenNodeRef != null && versionLabelId != null) {
                    v = nodeVersions.findVersion(frozenNodeRef.getId(), versionLabelId);
                    aNode = nodes.getFolderOrDocument(v.getFrozenStateNodeRef(), null, null, params.getInclude(), mapUserInfo);
                }
            } catch (EntityNotFoundException | InvalidNodeRefException e) {
                // Solr says there is a node but we can't find it
                logger.debug("Failed to find a versioned node with id of " + frozenNodeRef + " this is probably because the original node has been deleted.");
            }
            if (v != null && aNode != null) {
                nodeVersions.mapVersionInfo(v, aNode, aRow.getNodeRef());
                aNode.setNodeId(frozenNodeRef.getId());
                aNode.setVersionLabel(versionLabelId);
            }
            break;
        case DELETED:
            try {
                aNode = deletedNodes.getDeletedNode(aRow.getNodeRef().getId(), params, false, mapUserInfo);
            } catch (EntityNotFoundException enfe) {
                // Solr says there is a deleted node but we can't find it, we want the rest of the search to return so lets ignore it.
                logger.debug("Failed to find a deleted node with id of " + aRow.getNodeRef().getId());
            }
            break;
    }
    if (aNode != null) {
        aNode.setLocation(nodeStore);
    }
    return aNode;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) Version(org.alfresco.service.cmr.version.Version) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.rest.api.model.Node) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 37 with EntityNotFoundException

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

the class CustomModelsImpl method getCustomType.

@Override
public CustomType getCustomType(String modelName, String typeName, Parameters parameters) {
    if (typeName == null) {
        throw new InvalidArgumentException(TYPE_NAME_NULL_ERR);
    }
    final CustomModelDefinition modelDef = getCustomModelImpl(modelName);
    QName typeQname = QName.createQName(modelDef.getName().getNamespaceURI(), typeName);
    TypeDefinition customTypeDef = customModelService.getCustomType(typeQname);
    if (customTypeDef == null) {
        throw new EntityNotFoundException(typeName);
    }
    // Check if inherited properties have been requested
    boolean includeInheritedProps = hasSelectProperty(parameters, SELECT_ALL_PROPS);
    return convertToCustomType(customTypeDef, includeInheritedProps);
}
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) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition)

Example 38 with EntityNotFoundException

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

the class CustomModelsImpl method mergeProperties.

private void mergeProperties(AbstractClassModel existingDetails, AbstractClassModel newDetails, Parameters parameters, boolean isModelActive) {
    validateList(newDetails.getProperties(), "cmm.rest_api.properties_empty_null");
    // Transform existing properties into a map
    Map<String, CustomModelProperty> existingProperties = transformToMap(existingDetails.getProperties(), toNameFunction());
    // Transform new properties into a map
    Map<String, CustomModelProperty> newProperties = transformToMap(newDetails.getProperties(), toNameFunction());
    String propName = parameters.getParameter(PARAM_UPDATE_PROP);
    // (propName == null) => property create request
    if (propName == null) {
        // As this is a create request, check for duplicate properties
        for (String name : newProperties.keySet()) {
            if (existingProperties.containsKey(name)) {
                throw new ConstraintViolatedException(I18NUtil.getMessage("cmm.rest_api.property_create_name_already_in_use", name));
            }
        }
    } else {
        // Update request
        CustomModelProperty existingProp = existingProperties.get(propName);
        if (existingProp == null) {
            throw new EntityNotFoundException(propName);
        }
        CustomModelProperty modifiedProp = newProperties.get(propName);
        if (modifiedProp == null) {
            throw new InvalidArgumentException("cmm.rest_api.property_update_prop_not_found", new Object[] { propName });
        }
        existingProp.setTitle(modifiedProp.getTitle());
        existingProp.setDescription(modifiedProp.getDescription());
        existingProp.setDefaultValue(modifiedProp.getDefaultValue());
        existingProp.setConstraintRefs(modifiedProp.getConstraintRefs());
        existingProp.setConstraints(modifiedProp.getConstraints());
        if (isModelActive) {
            validateActivePropertyUpdate(existingProp, modifiedProp);
        }
        existingProp.setDataType(modifiedProp.getDataType());
        existingProp.setMandatory(modifiedProp.isMandatory());
        existingProp.setMandatoryEnforced(modifiedProp.isMandatoryEnforced());
        existingProp.setMultiValued(modifiedProp.isMultiValued());
    }
    // Override properties
    existingProperties.putAll(newProperties);
    existingDetails.setProperties(new ArrayList<>(existingProperties.values()));
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) CustomModelProperty(org.alfresco.rest.api.model.CustomModelProperty)

Example 39 with EntityNotFoundException

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

the class CustomModelsImpl method deleteCustomType.

@Override
public void deleteCustomType(String modelName, String typeName) {
    // Check the current user is authorised to delete the custom model's type
    validateCurrentUser();
    if (typeName == null) {
        throw new InvalidArgumentException(TYPE_NAME_NULL_ERR);
    }
    ModelDetails existingModelDetails = new ModelDetails(getCustomModelImpl(modelName));
    if (existingModelDetails.isActive()) {
        throw new ConstraintViolatedException("cmm.rest_api.type_cannot_delete");
    }
    Map<String, CustomType> allTypes = transformToMap(existingModelDetails.getTypes(), toNameFunction());
    CustomType typeToBeDeleted = allTypes.get(typeName);
    if (typeToBeDeleted == null) {
        throw new EntityNotFoundException(typeName);
    }
    // Validate type's dependency
    validateTypeAspectDelete(allTypes.values(), typeToBeDeleted.getPrefixedName());
    // Remove the validated type
    allTypes.remove(typeName);
    existingModelDetails.setTypes(new ArrayList<>(allTypes.values()));
    updateModel(existingModelDetails, "cmm.rest_api.type_delete_failure");
}
Also used : CustomType(org.alfresco.rest.api.model.CustomType) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 40 with EntityNotFoundException

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

the class NodesImpl method validateNode.

@Override
public NodeRef validateNode(StoreRef storeRef, String nodeId) {
    String versionLabel = null;
    int idx = nodeId.indexOf(";");
    if (idx != -1) {
        versionLabel = nodeId.substring(idx + 1);
        nodeId = nodeId.substring(0, idx);
        if (versionLabel.equals("pwc")) {
            // TODO correct exception?
            throw new EntityNotFoundException(nodeId);
        }
    }
    NodeRef nodeRef = new NodeRef(storeRef, nodeId);
    return validateNode(nodeRef);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

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