From 3c2e33ec2079731ad108e0fefe4251785c604693 Mon Sep 17 00:00:00 2001 From: Jamal Kaabi-Mofrad Date: Tue, 10 May 2016 10:34:27 +0000 Subject: [PATCH] Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 119857 jvonka: FileFolder API - optimise check when getting 'type' of node (whether folder or file, or a link to thereof) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126374 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/rest/api/impl/NodesImpl.java | 65 +++++++++++++------ 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/source/java/org/alfresco/rest/api/impl/NodesImpl.java b/source/java/org/alfresco/rest/api/impl/NodesImpl.java index c5b38a7914..0f5f0e8a18 100644 --- a/source/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -338,9 +338,20 @@ public class NodesImpl implements Nodes private Type getType(QName typeQName, NodeRef nodeRef) { + // quick check for common types + if (typeQName.equals(ContentModel.TYPE_FOLDER) || typeQName.equals(ApplicationModel.TYPE_FOLDERLINK)) + { + return Type.FOLDER; + } + else if (typeQName.equals(ContentModel.TYPE_CONTENT) || typeQName.equals(ApplicationModel.TYPE_FILELINK)) + { + return Type.DOCUMENT; + } + + // further checks + if (dictionaryService.isSubClass(typeQName, ContentModel.TYPE_LINK)) { - // handle file/folder link type (we do not explicitly validate that the destination type matches) if (dictionaryService.isSubClass(typeQName, ApplicationModel.TYPE_FOLDERLINK)) { return Type.FOLDER; @@ -349,27 +360,37 @@ public class NodesImpl implements Nodes { return Type.DOCUMENT; } - else + + NodeRef linkNodeRef = (NodeRef)nodeService.getProperty(nodeRef, ContentModel.PROP_LINK_DESTINATION); + if (linkNodeRef != null) { - // cm:link (or other subclass) - NodeRef linkNodeRef = (NodeRef)nodeService.getProperty(nodeRef, ContentModel.PROP_LINK_DESTINATION); - if (linkNodeRef != null) + try { - try - { - typeQName = nodeService.getType(linkNodeRef); - } - catch (InvalidNodeRefException inre) - { - // ignore - } + typeQName = nodeService.getType(linkNodeRef); + // drop-through to check type of destination + // note: edge-case - if link points to another link then we will return null + } + catch (InvalidNodeRefException inre) + { + // ignore } } } - boolean isContainer = (dictionaryService.isSubClass(typeQName, ContentModel.TYPE_FOLDER) && - (! dictionaryService.isSubClass(typeQName, ContentModel.TYPE_SYSTEM_FOLDER))); - return isContainer ? Type.FOLDER : Type.DOCUMENT; + if (dictionaryService.isSubClass(typeQName, ContentModel.TYPE_FOLDER)) + { + if (! dictionaryService.isSubClass(typeQName, ContentModel.TYPE_SYSTEM_FOLDER)) + { + return Type.FOLDER; + } + return null; // unknown + } + else if (dictionaryService.isSubClass(typeQName, ContentModel.TYPE_CONTENT)) + { + return Type.DOCUMENT; + } + + return null; // unknown } /** @@ -378,7 +399,7 @@ public class NodesImpl implements Nodes public Document getDocument(NodeRef nodeRef) { Type type = getType(nodeRef); - if (type.equals(Type.DOCUMENT)) + if ((type != null) && type.equals(Type.DOCUMENT)) { Map properties = nodeService.getProperties(nodeRef); @@ -416,7 +437,7 @@ public class NodesImpl implements Nodes public Folder getFolder(NodeRef nodeRef) { Type type = getType(nodeRef); - if (type.equals(Type.FOLDER)) + if ((type != null) && type.equals(Type.FOLDER)) { Map properties = nodeService.getProperties(nodeRef); @@ -565,6 +586,12 @@ public class NodesImpl implements Nodes Node node; Map properties = nodeService.getProperties(nodeRef); + if (type == null) + { + // unknown type + node = new Document(nodeRef, parentNodeRef, properties, mapUserInfo, sr); + node.setIsFolder(null); + } if (type.equals(Type.DOCUMENT)) { node = new Document(nodeRef, parentNodeRef, properties, mapUserInfo, sr); @@ -576,7 +603,7 @@ public class NodesImpl implements Nodes } else { - throw new InvalidArgumentException("Node is not a folder or file"); + throw new RuntimeException("Unexpected - should not reach here"); } if (selectParam.size() > 0)