Merged HEAD (5.2) to 5.2.N (5.2.1)

126349 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)
      118692 jvonka: Merge from DEV/SABRE_JANV1 (part 2) - RA-613 / RA-655
      - File Folder API (PoC - experimental WIP)
      - TODO add tests +review backwards compat' (eg. favs)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126694 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ancuta Morarasu
2016-05-11 10:44:49 +00:00
parent 3a5a22da8d
commit d3b503759b
12 changed files with 917 additions and 452 deletions

View File

@@ -0,0 +1,50 @@
package org.alfresco.rest.api.model;
/**
* Representation of content info
*
* @author janv
*
*/
public class ContentInfo
{
private String mimeType;
private String mimeTypeName;
private long sizeInBytes;
private String encoding;
public ContentInfo()
{
}
public ContentInfo( String mimeType, String mimeTypeName, long sizeInBytes, String encoding)
{
this.mimeType = mimeType;
this.mimeTypeName = mimeTypeName;
this.sizeInBytes = sizeInBytes;
this.encoding = encoding;
}
public String getMimeType() {
return mimeType;
}
public String getMimeTypeName() {
return mimeTypeName;
}
public long getSizeInBytes() {
return sizeInBytes;
}
public String getEncoding() {
return encoding;
}
@Override
public String toString()
{
return "ContentInfo [mimeType=" + mimeType + ", mimeTypeName=" + mimeTypeName
+ ", encoding=" + encoding + ", sizeInBytes=" + sizeInBytes + "]";
}
}

View File

@@ -29,12 +29,11 @@ import java.io.Serializable;
import java.math.BigInteger;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.data.Properties;
import org.apache.chemistry.opencmis.commons.data.PropertyData;
/**
* Representation of a document node.
@@ -45,32 +44,33 @@ import org.apache.chemistry.opencmis.commons.data.PropertyData;
*/
public class Document extends Node
{
// TODO backward compat' - favourites etc
private String mimeType;
private BigInteger sizeInBytes;
private String versionLabel;
private String versionLabel;
public Document()
{
super();
}
private ContentInfo contentInfo;
/*
public Document(NodeRef nodeRef, Properties properties)
{
super(nodeRef, properties);
public Document() {
super();
}
Map<String, PropertyData<?>> props = properties.getProperties();
this.mimeType = (String)getValue(props, PropertyIds.CONTENT_STREAM_MIME_TYPE);
this.sizeInBytes = (BigInteger)getValue(props, PropertyIds.CONTENT_STREAM_LENGTH);
this.versionLabel = (String)getValue(props, PropertyIds.VERSION_LABEL);
}
*/
public Document(NodeRef nodeRef, NodeRef parentNodeRef, Map<QName, Serializable> nodeProps, ServiceRegistry sr)
{
super(nodeRef, parentNodeRef, nodeProps, sr);
public Document(NodeRef nodeRef, Map<QName, Serializable> nodeProps, NamespaceService namespaceService)
{
super(nodeRef, nodeProps, namespaceService);
}
Serializable val = nodeProps.get(ContentModel.PROP_CONTENT);
if ((val != null) && (val instanceof ContentData)) {
ContentData cd = (ContentData)val;
String mimeType = cd.getMimetype();
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;
@@ -91,13 +91,16 @@ public class Document extends Node
return false;
}
public ContentInfo getContent()
{
return contentInfo;
}
@Override
public String toString()
{
return "Document [mimeType=" + mimeType + ", sizeInBytes="
+ sizeInBytes + ", versionLabel=" + versionLabel + ", nodeRef="
+ nodeRef + ", name=" + name + ", title=" + title
+ ", description=" + description + ", createdAt=" + createdAt
return "Document [contentInfo=" + contentInfo.toString() + ", nodeRef="
+ nodeRef + ", name=" + name + ", createdAt=" + createdAt
+ ", modifiedAt=" + modifiedAt + ", createdBy=" + createdBy
+ ", modifiedBy=" + modifiedBy + "]";
}

View File

@@ -28,10 +28,9 @@ package org.alfresco.rest.api.model;
import java.io.Serializable;
import java.util.Map;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.data.Properties;
/**
* Representation of a folder node.
@@ -47,17 +46,10 @@ public class Folder extends Node
super();
}
/*
public Folder(NodeRef nodeRef, Properties properties)
{
super(nodeRef, properties);
}
*/
public Folder(NodeRef nodeRef, Map<QName, Serializable> nodeProps, NamespaceService namespaceService)
{
super(nodeRef, nodeProps, namespaceService);
}
public Folder(NodeRef nodeRef, NodeRef parentNodeRef, Map<QName, Serializable> nodeProps, ServiceRegistry sr)
{
super(nodeRef, parentNodeRef, nodeProps, sr);
}
public Boolean getIsFolder()
{

View File

@@ -26,167 +26,139 @@
package org.alfresco.rest.api.model;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.rest.framework.resource.UniqueId;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.EqualsHelper;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.data.Properties;
import org.apache.chemistry.opencmis.commons.data.PropertyData;
/**
* Concrete class carrying general information for <b>alf_node</b> data
*
*
* @author steveglover
* @author Gethin James
* @author janv
*/
public class Node implements Comparable<Node>
{
protected NodeRef nodeRef;
protected String name;
protected String title;
protected NodeRef guid; // TODO review - do we need for favorites (backwards compat') ?
protected String description;
protected Date createdAt;
protected Date modifiedAt;
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 String primaryPath;
protected Date createdAt;
protected Date modifiedAt;
protected UserInfo createdByUser;
protected UserInfo modifiedByUser;
protected NodeRef parentNodeRef;
protected PathInfo pathInfo;
protected String prefixTypeQName;
protected List<String> aspectNames;
protected Map<String, Serializable> props;
private static final List<QName> EXCLUDED_PROPS = Arrays.asList(
ContentModel.PROP_NAME,
ContentModel.PROP_TITLE,
ContentModel.PROP_DESCRIPTION,
ContentModel.PROP_MODIFIER,
ContentModel.PROP_MODIFIED,
ContentModel.PROP_CREATOR,
ContentModel.PROP_CREATED,
ContentModel.PROP_CONTENT,
ContentModel.PROP_LOCALE,
ContentModel.PROP_NODE_UUID,
ContentModel.PROP_STORE_IDENTIFIER,
ContentModel.PROP_STORE_PROTOCOL,
ContentModel.PROP_NODE_DBID,
ContentModel.PROP_INITIAL_VERSION,
ContentModel.PROP_AUTO_VERSION_PROPS,
ContentModel.PROP_AUTO_VERSION);
// TODO fixme !
public Node(NodeRef nodeRef, Map<QName, Serializable> nodeProps, NamespaceService namespaceService)
// also need to optionally pass in user map - eg. when listing children (to avoid multiple lookups for same user)
public Node(NodeRef nodeRef, NodeRef parentNodeRef, Map<QName, Serializable> nodeProps, ServiceRegistry sr)
{
if(nodeRef == null)
{
throw new IllegalArgumentException();
}
if(nodeRef == null)
{
throw new IllegalArgumentException();
}
this.nodeRef = nodeRef;
mapProperties(nodeProps, namespaceService);
this.nodeRef = nodeRef;
this.parentNodeRef = parentNodeRef;
mapBasicInfo(nodeProps, sr);
}
protected Object getValue(Map<String, PropertyData<?>> props, String name)
{
PropertyData<?> prop = props.get(name);
Object value = (prop != null ? prop.getFirstValue() : null);
return value;
}
/*
public Node(NodeRef nodeRef, Properties properties)
{
this.nodeRef = nodeRef;
Map<String, PropertyData<?>> props = properties.getProperties();
this.guid = nodeRef;
this.name = (String)getValue(props, PropertyIds.NAME);
this.title = (String)getValue(props, ContentModel.PROP_TITLE.toString());
this.description = (String)getValue(props, PropertyIds.DESCRIPTION);
GregorianCalendar cal = (GregorianCalendar)getValue(props, PropertyIds.CREATION_DATE);
this.createdAt = cal.getTime();
cal = (GregorianCalendar)getValue(props, PropertyIds.LAST_MODIFICATION_DATE);
this.modifiedAt = cal.getTime();
this.createdBy = (String)getValue(props, PropertyIds.CREATED_BY);
this.modifiedBy = (String)getValue(props, PropertyIds.LAST_MODIFIED_BY);
}
*/
protected Object getValue(Map<String, PropertyData<?>> props, String name)
{
PropertyData<?> prop = props.get(name);
Object value = (prop != null ? prop.getFirstValue() : null);
return value;
}
public Node()
{
}
protected void mapProperties(Map<QName, Serializable> nodeProps, NamespaceService namespaceService)
protected void mapBasicInfo(Map<QName, Serializable> nodeProps, ServiceRegistry sr)
{
PersonService personService = sr.getPersonService();
// TODO review backwards compat' for favorites & others (eg. set guid explicitly where still needed)
//this.guid = nodeRef;
//this.title = (String)nodeProps.get(ContentModel.PROP_TITLE);
//this.description = (String)nodeProps.get(ContentModel.PROP_DESCRIPTION);
//this.createdBy = (String)nodeProps.get(ContentModel.PROP_CREATOR);
//this.modifiedBy = (String)nodeProps.get(ContentModel.PROP_MODIFIER);
this.name = (String)nodeProps.get(ContentModel.PROP_NAME);
this.title = (String)nodeProps.get(ContentModel.PROP_TITLE);
this.description = (String)nodeProps.get(ContentModel.PROP_DESCRIPTION);
this.name = (String)nodeProps.get(ContentModel.PROP_NAME);
this.createdAt = (Date)nodeProps.get(ContentModel.PROP_CREATED);
this.createdBy = (String)nodeProps.get(ContentModel.PROP_CREATOR);
this.modifiedAt = (Date)nodeProps.get(ContentModel.PROP_MODIFIED);
this.modifiedBy = (String)nodeProps.get(ContentModel.PROP_MODIFIER);
this.createdAt = (Date)nodeProps.get(ContentModel.PROP_CREATED);
this.createdByUser = lookupUserInfo((String)nodeProps.get(ContentModel.PROP_CREATOR), personService);
this.props = new HashMap<>(nodeProps.size());
this.modifiedAt = (Date)nodeProps.get(ContentModel.PROP_MODIFIED);
this.modifiedByUser = lookupUserInfo((String)nodeProps.get(ContentModel.PROP_MODIFIER), personService);
}
for (Map.Entry<QName, Serializable> entry : nodeProps.entrySet()) {
QName propQName = entry.getKey();
if (! EXCLUDED_PROPS.contains(propQName)) {
props.put(entry.getKey().toPrefixString(namespaceService), entry.getValue());
}
// TODO refactor & optimise to avoid multiple person lookups
private UserInfo lookupUserInfo(final String userName, final PersonService personService) {
String sysUserName = AuthenticationUtil.getSystemUserName();
if (userName.equals(sysUserName) || (AuthenticationUtil.isMtEnabled() && userName.startsWith(sysUserName+"@")))
{
return new UserInfo(userName, userName, "");
}
else
{
PersonService.PersonInfo pInfo = personService.getPerson(personService.getPerson(userName));
return new UserInfo(userName, pInfo.getFirstName(), pInfo.getLastName());
}
}
public void setGuid(NodeRef guid)
{
this.guid = guid;
}
{
this.guid = guid;
}
public NodeRef getGuid()
{
return guid;
}
public NodeRef getGuid() {
return guid;
}
public String getTitle()
{
return title;
}
public String getTitle()
{
return title;
}
@UniqueId
@UniqueId
public NodeRef getNodeRef()
{
return nodeRef;
}
return nodeRef;
}
public void setNodeRef(NodeRef nodeRef)
{
// if(nodeRef == null)
// {
// throw new IllegalArgumentException();
// }
this.nodeRef = nodeRef;
}
public Date getCreatedAt()
public void setNodeRef(NodeRef nodeRef)
{
this.nodeRef = nodeRef;
}
public Date getCreatedAt()
{
return this.createdAt;
}
@@ -196,20 +168,28 @@ public class Node implements Comparable<Node>
this.createdAt = createdAt;
}
public Date getModifiedAt()
{
return modifiedAt;
}
public Date getModifiedAt()
{
return modifiedAt;
}
public String getModifiedBy()
{
return modifiedBy;
}
public String getModifiedBy()
{
return modifiedBy;
}
public UserInfo getModifiedByUser() {
return modifiedByUser;
}
public UserInfo getCreatedByUser() {
return createdByUser;
}
public String getDescription()
{
return description;
}
{
return description;
}
public String getName()
{
@@ -230,59 +210,76 @@ public class Node implements Comparable<Node>
{
this.createdBy = createdBy;
}
public String getPrimaryPath()
{
return primaryPath;
}
public void setPrimaryPath(String primaryPath)
{
this.primaryPath = primaryPath;
}
public String getType()
{
return prefixTypeQName;
}
public void setType(String prefixType)
{
this.prefixTypeQName = prefixType;
public PathInfo getPath()
{
return pathInfo;
}
public Map getProperties() {
public void setPath(PathInfo pathInfo)
{
this.pathInfo = pathInfo;
}
public String getNodeType()
{
return prefixTypeQName;
}
public void setNodeType(String prefixType)
{
this.prefixTypeQName = prefixType;
}
public Map getProperties() {
return this.props;
}
public boolean equals(Object other)
{
if(this == other)
{
return true;
}
if(!(other instanceof Node))
{
return false;
}
Node node = (Node)other;
return EqualsHelper.nullSafeEquals(getNodeRef(), node.getNodeRef());
}
public void setProperties(Map props) {
this.props = props;
}
@Override
public int compareTo(Node node)
{
return getNodeRef().toString().compareTo(node.getNodeRef().toString());
}
public List<String> getAspectNames() {
return aspectNames;
}
@Override
public String toString()
{
return "Node [nodeRef=" + nodeRef + ", type=" + prefixTypeQName + ", name=" + name + ", title="
+ title + ", description=" + description + ", createdAt="
+ createdAt + ", modifiedAt=" + modifiedAt + ", createdBy=" + createdBy + ", modifiedBy="
+ modifiedBy + ", primaryPath =" + primaryPath +"]";
}
}
public void setAspectNames(List<String> aspectNames) {
this.aspectNames = aspectNames;
}
public NodeRef getParentId()
{
return parentNodeRef;
}
public boolean equals(Object other)
{
if(this == other)
{
return true;
}
if(!(other instanceof Node))
{
return false;
}
Node node = (Node)other;
return EqualsHelper.nullSafeEquals(getNodeRef(), node.getNodeRef());
}
@Override
public int compareTo(Node node)
{
return getNodeRef().toString().compareTo(node.getNodeRef().toString());
}
@Override
public String toString()
{
return "Node [nodeRef=" + nodeRef + ", type=" + prefixTypeQName + ", name=" + name + ", title="
+ title + ", description=" + description + ", createdAt="
+ createdAt + ", modifiedAt=" + modifiedAt + ", createdByUser=" + createdByUser + ", modifiedBy="
+ modifiedByUser + ", pathInfo =" + pathInfo +"]";
}
}

View File

@@ -0,0 +1,64 @@
package org.alfresco.rest.api.model;
import java.util.List;
/**
* Representation of a path info
*
* @author janv
*
*/
public class PathInfo
{
private String name;
private Boolean isComplete;
private List<ElementInfo> elements;
public PathInfo()
{
}
public PathInfo(String name, Boolean isComplete, List<ElementInfo> elements)
{
this.name = name;
this.isComplete = isComplete;
this.elements = elements;
}
public String getName() {
return name;
}
public Boolean getIsComplete() {
return isComplete;
}
public List<ElementInfo> getElements() {
return elements;
}
public class ElementInfo {
private String id;
private String name;
public ElementInfo()
{
}
public ElementInfo(String id, String name)
{
this.id = id;
this.name = name;
}
public String getName() {
return name;
}
public String getId() {
return id;
}
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (C) 2005-2015 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.rest.api.model;
/**
* Representation of a user info
*
* @author janv
*
*/
public class UserInfo
{
private String userName;
private String displayName;
public UserInfo()
{
}
public UserInfo(String userName, String firstName, String lastName)
{
this.userName = userName;
this.displayName = ((firstName != null ? firstName + " " : "") + (lastName != null ? lastName : "")).replaceAll("^\\s+|\\s+$", "");
}
public String getDisplayName() {
return displayName;
}
public String getUserName() {
return userName;
}
@Override
public String toString()
{
return "User [userName=" + userName + ", displayName=" + displayName + "]";
}
}