Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)

123316 jvonka: Nodes (FileFolder) API - add optional include allowableOperations 
   RA-770


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126538 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-05-10 11:23:44 +00:00
parent 335245acbc
commit e040658433
7 changed files with 205 additions and 18 deletions

View File

@@ -186,6 +186,10 @@ public interface Nodes
String PATH_MY = "-my-";
String PATH_SHARED = "-shared-";
String OP_CREATE = "create";
String OP_DELETE= "delete";
String OP_UPDATE = "update";
String PARAM_RELATIVE_PATH = "relativePath";
String PARAM_AUTO_RENAME = "autoRename";
String PARAM_PERMANENT = "permanent";
@@ -194,6 +198,7 @@ public interface Nodes
String PARAM_INCLUDE_PATH = "path";
String PARAM_INCLUDE_ASPECTNAMES = "aspectNames";
String PARAM_INCLUDE_ISLINK = "isLink";
String PARAM_INCLUDE_ALLOWABLEOPERATIONS = "allowableOperations";
String PARAM_ISFOLDER = "isFolder";
String PARAM_ISFILE = "isFile";

View File

@@ -103,5 +103,5 @@ public interface QuickShareLinks
*/
String PARAM_SHAREDBY = "sharedByUser";
String PARAM_SELECT_ISLINK = "allowableOperations";
String PARAM_INCLUDE_ALLOWABLEOPERATIONS = Nodes.PARAM_INCLUDE_ALLOWABLEOPERATIONS;
}

View File

@@ -721,7 +721,7 @@ public class NodesImpl implements Nodes
return getFolderOrDocument(nodeRef, parentNodeRef, nodeTypeQName, includeParam, null);
}
private Node getFolderOrDocument(final NodeRef nodeRef, NodeRef parentNodeRef, QName nodeTypeQName, List<String> selectParam, Map<String,UserInfo> mapUserInfo)
private Node getFolderOrDocument(final NodeRef nodeRef, NodeRef parentNodeRef, QName nodeTypeQName, List<String> includeParam, Map<String,UserInfo> mapUserInfo)
{
if (mapUserInfo == null)
{
@@ -729,7 +729,7 @@ public class NodesImpl implements Nodes
}
PathInfo pathInfo = null;
if (selectParam.contains(PARAM_INCLUDE_PATH))
if (includeParam.contains(PARAM_INCLUDE_PATH))
{
pathInfo = lookupPathInfo(nodeRef);
}
@@ -770,21 +770,48 @@ public class NodesImpl implements Nodes
throw new RuntimeException("Unexpected - should not reach here: "+type);
}
if (selectParam.size() > 0)
if (includeParam.size() > 0)
{
node.setProperties(mapFromNodeProperties(properties, selectParam, mapUserInfo));
node.setProperties(mapFromNodeProperties(properties, includeParam, mapUserInfo));
}
if (selectParam.contains(PARAM_INCLUDE_ASPECTNAMES))
if (includeParam.contains(PARAM_INCLUDE_ASPECTNAMES))
{
node.setAspectNames(mapFromNodeAspects(nodeService.getAspects(nodeRef)));
}
if (selectParam.contains(PARAM_INCLUDE_ISLINK))
if (includeParam.contains(PARAM_INCLUDE_ISLINK))
{
boolean isLink = isSubClass(nodeTypeQName, ContentModel.TYPE_LINK);
node.setIsLink(isLink);
}
if (includeParam.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS))
{
// note: refactor when requirements change
Map<String, String> mapPermsToOps = new HashMap<>(3);
mapPermsToOps.put(PermissionService.DELETE, OP_DELETE);
mapPermsToOps.put(PermissionService.ADD_CHILDREN, OP_CREATE);
mapPermsToOps.put(PermissionService.WRITE, OP_UPDATE);
List<String> allowableOperations = new ArrayList<>(3);
for (Entry<String, String> kv : mapPermsToOps.entrySet())
{
String perm = kv.getKey();
String op = kv.getValue();
// special case: do not return "create" for file
if (! (perm.equals(PermissionService.ADD_CHILDREN) && type.equals(Type.DOCUMENT)))
{
if (permissionService.hasPermission(nodeRef, perm) == AccessStatus.ALLOWED)
{
allowableOperations.add(op);
}
}
}
node.setAllowableOperations((allowableOperations.size() > 0 )? allowableOperations : null);
}
node.setNodeType(nodeTypeQName.toPrefixString(namespaceService));
node.setPath(pathInfo);

View File

@@ -455,23 +455,23 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean
return CollectionWithPagingInfo.asPaged(paging, qsLinks, results.hasMore(), new Long(results.getNumberFound()).intValue());
}
private QuickShareLink getQuickShareInfo(String sharedId, boolean noAuth, List<String> selectParam)
private QuickShareLink getQuickShareInfo(String sharedId, boolean noAuth, List<String> includeParam)
{
checkValidShareId(sharedId);
Map<String, Object> map = (Map<String, Object>) quickShareService.getMetaData(sharedId).get("item");
NodeRef nodeRef = new NodeRef((String) map.get("nodeRef"));
return getQuickShareInfo(nodeRef, map, noAuth, selectParam);
return getQuickShareInfo(nodeRef, map, noAuth, includeParam);
}
private QuickShareLink getQuickShareInfo(NodeRef nodeRef, boolean noAuth, List<String> selectParam)
private QuickShareLink getQuickShareInfo(NodeRef nodeRef, boolean noAuth, List<String> includeParam)
{
Map<String, Object> map = (Map<String, Object>) quickShareService.getMetaData(nodeRef).get("item");
return getQuickShareInfo(nodeRef, map , noAuth, selectParam);
return getQuickShareInfo(nodeRef, map , noAuth, includeParam);
}
private QuickShareLink getQuickShareInfo(NodeRef nodeRef, Map<String, Object> map, boolean noAuth, List<String> selectParam)
private QuickShareLink getQuickShareInfo(NodeRef nodeRef, Map<String, Object> map, boolean noAuth, List<String> includeParam)
{
String sharedId = (String)map.get("sharedId");
@@ -502,11 +502,11 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean
qs.setModifiedByUser(modifiedByUser);
qs.setSharedByUser(sharedByUser);
if ((! noAuth) && selectParam.contains(PARAM_SELECT_ISLINK))
if ((! noAuth) && includeParam.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS))
{
if (canDeleteSharedLink(nodeRef, sharedByUserId))
{
qs.setAllowableOperations(Collections.singletonList("delete"));
qs.setAllowableOperations(Collections.singletonList(Nodes.OP_DELETE));
}
}

View File

@@ -67,6 +67,8 @@ public class Node implements Comparable<Node>
protected List<String> aspectNames;
protected Map<String, Object> properties;
protected List<String> allowableOperations;
public Node(NodeRef nodeRef, NodeRef parentNodeRef, Map<QName, Serializable> nodeProps, Map<String, UserInfo> mapUserInfo, ServiceRegistry sr)
{
if(nodeRef == null)
@@ -278,6 +280,16 @@ public class Node implements Comparable<Node>
this.isLink = isLink;
}
public List<String> getAllowableOperations()
{
return allowableOperations;
}
public void setAllowableOperations(List<String> allowableOperations)
{
this.allowableOperations = allowableOperations;
}
public boolean equals(Object other)
{
if(this == other)
@@ -303,10 +315,25 @@ public class Node implements Comparable<Node>
@Override
public String toString()
{
return "Node [nodeRef=" + nodeRef + ", type=" + prefixTypeQName + ", name=" + name + ", title="
+ title + ", description=" + description + ", createdAt="
+ createdAt + ", modifiedAt=" + modifiedAt + ", createdByUser=" + createdByUser + ", modifiedBy="
+ modifiedByUser + ", isFolder =" + isFolder + ", isFile =" + isFile + ", pathInfo =" + pathInfo +"]";
StringBuilder sb = new StringBuilder();
sb.append("Node [id=").append(getNodeRef().getId());
sb.append(", parentId=").append(getParentId());
sb.append(", type=").append(getNodeType());
sb.append(", name=").append(getName());
sb.append(", isFolder=").append(getIsFolder());
sb.append(", isFile=").append(getIsFile());
sb.append(", isLink=").append(getIsLink()); // note: symbolic link (not shared link)
sb.append(", modifiedAt=").append(getModifiedAt());
sb.append(", modifiedByUser=").append(getModifiedByUser());
sb.append(", createdAt=").append(getCreatedAt());
sb.append(", createdByUser=").append(getCreatedByUser());
sb.append(", path=").append(getPath());
sb.append(", content=").append(getContent());
sb.append(", aspectNames=").append(getAspectNames());
//sb.append(", properties=").append(getProperties());
sb.append(", allowableOperations=").append(getAllowableOperations());
sb.append("]");
return sb.toString();
}
// here to allow POST /nodes/{id}/children when creating empty file with specified content.mimeType