From 09eac586f678dd689962dba5e06ce5a463990811 Mon Sep 17 00:00:00 2001 From: Jamal Kaabi-Mofrad Date: Tue, 10 May 2016 10:26:50 +0000 Subject: [PATCH] Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 118728 jvonka: RA-613 / RA-655 - fix for TestFavourites failure (+ related backwards compat' for Favorites API response format) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126350 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/rest/api/impl/NodesImpl.java | 34 +++-- .../org/alfresco/rest/api/model/Document.java | 76 +++++++--- .../org/alfresco/rest/api/model/Node.java | 132 ++++++++++++------ 3 files changed, 169 insertions(+), 73 deletions(-) diff --git a/source/java/org/alfresco/rest/api/impl/NodesImpl.java b/source/java/org/alfresco/rest/api/impl/NodesImpl.java index 491a86d924..b14427c9d7 100644 --- a/source/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -46,6 +46,7 @@ import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.model.FileInfo; import org.alfresco.service.cmr.model.FileNotFoundException; +import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.InvalidNodeRefException; import org.alfresco.service.cmr.repository.NodeRef; @@ -59,6 +60,7 @@ import org.alfresco.util.Pair; import java.io.InputStream; import java.io.Serializable; +import java.math.BigInteger; import java.util.AbstractList; import java.util.ArrayList; import java.util.Arrays; @@ -271,18 +273,26 @@ public class NodesImpl implements Nodes } /** - * Returns the public api representation of a document. - * - * @deprecated review usage (backward compat') + * @deprecated note: currently required for backwards compat' (Favourites API) */ public Document getDocument(NodeRef nodeRef) { Type type = getType(nodeRef); if (type.equals(Type.DOCUMENT)) - { + { Map properties = nodeService.getProperties(nodeRef); - Document doc = new Document(nodeRef, getParentNodeRef(nodeRef), properties, sr); + Document doc = new Document(nodeRef, getParentNodeRef(nodeRef), properties, sr); + + doc.setVersionLabel((String)properties.get(ContentModel.PROP_VERSION_LABEL)); + ContentData cd = (ContentData) properties.get(ContentModel.PROP_CONTENT); + if (cd != null) + { + doc.setSizeInBytes(BigInteger.valueOf(cd.getSize())); + doc.setMimeType((cd.getMimetype())); + } + + setCommonProps(doc, nodeRef, properties); return doc; } else @@ -290,11 +300,18 @@ public class NodesImpl implements Nodes throw new InvalidArgumentException("Node is not a file"); } } + + private void setCommonProps(Node node, NodeRef nodeRef, Map properties) + { + node.setGuid(nodeRef); + node.setTitle((String)properties.get(ContentModel.PROP_TITLE)); + node.setDescription((String)properties.get(ContentModel.PROP_TITLE)); + node.setModifiedBy((String)properties.get(ContentModel.PROP_MODIFIER)); + node.setCreatedBy((String)properties.get(ContentModel.PROP_CREATOR)); + } /** - * Returns the public api representation of a folder. - * - * @deprecated review usage (backward compat') + * @deprecated note: currently required for backwards compat' (Favourites API) */ public Folder getFolder(NodeRef nodeRef) { @@ -304,6 +321,7 @@ public class NodesImpl implements Nodes Map properties = nodeService.getProperties(nodeRef); Folder folder = new Folder(nodeRef, getParentNodeRef(nodeRef), properties, sr); + setCommonProps(folder, nodeRef, properties); return folder; } else diff --git a/source/java/org/alfresco/rest/api/model/Document.java b/source/java/org/alfresco/rest/api/model/Document.java index cb679c26d8..d0136b5cb5 100644 --- a/source/java/org/alfresco/rest/api/model/Document.java +++ b/source/java/org/alfresco/rest/api/model/Document.java @@ -37,11 +37,6 @@ import org.alfresco.service.namespace.QName; */ public class Document extends Node { - // TODO backward compat' - favourites etc - private String mimeType; - private BigInteger sizeInBytes; - private String versionLabel; - private ContentInfo contentInfo; public Document() { @@ -60,25 +55,8 @@ public class Document extends Node String mimeTypeName = sr.getMimetypeService().getDisplaysByMimetype().get(mimeType); this.contentInfo = new ContentInfo(mimeType, mimeTypeName, cd.getSize(), cd.getEncoding()); } - - //this.versionLabel = (String)nodeProps.get(ContentModel.PROP_VERSION_LABEL); } - public String getMimeType() - { - return mimeType; - } - - public BigInteger getSizeInBytes() - { - return sizeInBytes; - } - - public String getVersionLabel() - { - return versionLabel; - } - public Boolean getIsFolder() { return false; @@ -97,4 +75,58 @@ public class Document extends Node + ", modifiedAt=" + modifiedAt + ", createdBy=" + createdBy + ", modifiedBy=" + modifiedBy + "]"; } + + // TODO for backwards compat' - set explicitly when needed (ie. favourites) + private String mimeType; + private BigInteger sizeInBytes; + private String versionLabel; + + /** + * @deprecated + */ + public String getMimeType() + { + return mimeType; + } + + /** + * @deprecated + */ + public BigInteger getSizeInBytes() + { + return sizeInBytes; + } + + /** + * @deprecated + */ + public String getVersionLabel() + { + return versionLabel; + } + + /** + * @deprecated + */ + public void setMimeType(String mimeType) + { + this.mimeType = mimeType; + } + + /** + * @deprecated + */ + public void setSizeInBytes(BigInteger sizeInBytes) + { + this.sizeInBytes = sizeInBytes; + } + + /** + * @deprecated + */ + public void setVersionLabel(String versionLabel) + { + this.versionLabel = versionLabel; + } + } diff --git a/source/java/org/alfresco/rest/api/model/Node.java b/source/java/org/alfresco/rest/api/model/Node.java index 09cb41e194..7f6eb6065c 100644 --- a/source/java/org/alfresco/rest/api/model/Node.java +++ b/source/java/org/alfresco/rest/api/model/Node.java @@ -45,13 +45,6 @@ public class Node implements Comparable protected NodeRef nodeRef; protected String name; - // TODO needed for favourties - backwards compat' - we could also choose to split of NodeInfo / Node impl's etc - protected String title; - protected NodeRef guid; - protected String description; - protected String createdBy; - protected String modifiedBy; - protected Date createdAt; protected Date modifiedAt; protected UserInfo createdByUser; @@ -77,7 +70,7 @@ public class Node implements Comparable this.nodeRef = nodeRef; this.parentNodeRef = parentNodeRef; - mapBasicInfo(nodeProps, sr); + mapMinimalInfo(nodeProps, sr); } protected Object getValue(Map> props, String name) @@ -91,7 +84,7 @@ public class Node implements Comparable { } - protected void mapBasicInfo(Map nodeProps, ServiceRegistry sr) + protected void mapMinimalInfo(Map nodeProps, ServiceRegistry sr) { PersonService personService = sr.getPersonService(); @@ -126,20 +119,6 @@ public class Node implements Comparable } } - public void setGuid(NodeRef guid) - { - this.guid = guid; - } - - public NodeRef getGuid() { - return guid; - } - - public String getTitle() - { - return title; - } - @UniqueId public NodeRef getNodeRef() { @@ -166,11 +145,6 @@ public class Node implements Comparable return modifiedAt; } - public String getModifiedBy() - { - return modifiedBy; - } - public UserInfo getModifiedByUser() { return modifiedByUser; } @@ -179,11 +153,6 @@ public class Node implements Comparable return createdByUser; } - public String getDescription() - { - return description; - } - public String getName() { return this.name; @@ -194,16 +163,6 @@ public class Node implements Comparable this.name = name; } - public String getCreatedBy() - { - return this.createdBy; - } - - public void setCreatedBy(String createdBy) - { - this.createdBy = createdBy; - } - public PathInfo getPath() { return pathInfo; @@ -275,4 +234,91 @@ public class Node implements Comparable + createdAt + ", modifiedAt=" + modifiedAt + ", createdByUser=" + createdByUser + ", modifiedBy=" + modifiedByUser + ", pathInfo =" + pathInfo +"]"; } + + // TODO for backwards compat' - set explicitly when needed (ie. favourites) (note: we could choose to have separate old Node/NodeImpl etc) + + protected String title; + protected NodeRef guid; + protected String description; + protected String createdBy; + protected String modifiedBy; + + /** + * @deprecated + */ + public NodeRef getGuid() { + return guid; + } + + /** + * @deprecated + */ + public void setGuid(NodeRef guid) + { + this.guid = guid; + } + + /** + * @deprecated + */ + public String getTitle() + { + return title; + } + + /** + * @deprecated + */ + public void setTitle(String title) + { + this.title = title; + } + + /** + * @deprecated + */ + public String getDescription() + { + return description; + } + + /** + * @deprecated + */ + public void setDescription(String description) + { + this.description = description; + } + + /** + * @deprecated + */ + public String getCreatedBy() + { + return this.createdBy; + } + + /** + * @deprecated + */ + public void setCreatedBy(String createdBy) + { + this.createdBy = createdBy; + } + + /** + * @deprecated + */ + public String getModifiedBy() + { + return modifiedBy; + } + + /** + * @deprecated + */ + public void setModifiedBy(String modifiedBy) + { + this.modifiedBy = modifiedBy; + } } \ No newline at end of file