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

129711 jvonka: REPO-1138 / REPO-983: Add support for the isLocked property
   - can optionally "include" when getting node info, listing children, ...


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@130219 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2016-09-06 14:41:32 +00:00
parent 2a5218afb8
commit 2953ce53de
5 changed files with 86 additions and 4 deletions

View File

@@ -274,6 +274,7 @@ public interface Nodes
String PARAM_INCLUDE_PATH = "path";
String PARAM_INCLUDE_ASPECTNAMES = "aspectNames";
String PARAM_INCLUDE_ISLINK = "isLink";
String PARAM_INCLUDE_ISLOCKED = "isLocked";
String PARAM_INCLUDE_ALLOWABLEOPERATIONS = "allowableOperations";
String PARAM_INCLUDE_ASSOCIATION = "association";

View File

@@ -122,6 +122,7 @@ import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.lock.LockStatus;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
@@ -881,9 +882,11 @@ public class NodesImpl implements Nodes
node.setProperties(mapFromNodeProperties(properties, includeParam, mapUserInfo));
}
Set<QName> aspects = null;
if (includeParam.contains(PARAM_INCLUDE_ASPECTNAMES))
{
node.setAspectNames(mapFromNodeAspects(nodeService.getAspects(nodeRef)));
aspects = nodeService.getAspects(nodeRef);
node.setAspectNames(mapFromNodeAspects(aspects));
}
if (includeParam.contains(PARAM_INCLUDE_ISLINK))
@@ -892,6 +895,12 @@ public class NodesImpl implements Nodes
node.setIsLink(isLink);
}
if (includeParam.contains(PARAM_INCLUDE_ISLOCKED))
{
boolean isLocked = isLocked(nodeRef, aspects);
node.setIsLocked(isLocked);
}
if (includeParam.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS))
{
// note: refactor when requirements change
@@ -1971,6 +1980,22 @@ public class NodesImpl implements Nodes
return false;
}
private boolean isLocked(NodeRef nodeRef, Set<QName> aspects)
{
boolean locked = false;
if (((aspects != null) && aspects.contains(ContentModel.ASPECT_LOCKABLE))
|| nodeService.hasAspect(nodeRef, ContentModel.ASPECT_LOCKABLE))
{
LockStatus status = lockService.getLockStatus(nodeRef);
if (status == LockStatus.LOCKED || status == LockStatus.LOCK_OWNER)
{
locked = true;
}
}
return locked;
}
@Override
public Node updateNode(String nodeId, Node nodeInfo, Parameters parameters)
{

View File

@@ -73,6 +73,7 @@ public class Node implements Comparable<Node>
protected Boolean isFolder;
protected Boolean isFile;
protected Boolean isLink;
protected Boolean isLocked;
protected NodeRef parentNodeRef;
protected PathInfo pathInfo;
@@ -305,6 +306,16 @@ public class Node implements Comparable<Node>
this.isLink = isLink;
}
public Boolean getIsLocked()
{
return isLocked;
}
public void setIsLocked(Boolean isLocked)
{
this.isLocked = isLocked;
}
public List<String> getAllowableOperations()
{
return allowableOperations;

View File

@@ -3593,19 +3593,33 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
Document d1 = createTextFile(folderId, d1Name, "The quick brown fox jumps over the lazy dog 1.");
String d1Id = d1.getId();
HttpResponse response = getSingle(URL_NODES, d1Id, null, null, 200);
Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertNull(node.getProperties().get("cm:lockType"));
assertNull(node.getProperties().get("cm:lockOwner"));
assertNull(node.getIsLocked());
Map<String, String> params = Collections.singletonMap("include", "isLocked");
response = getSingle(URL_NODES, d1Id, params, null, 200);
node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertNull(node.getProperties().get("cm:lockType"));
assertNull(node.getProperties().get("cm:lockOwner"));
assertFalse(node.getIsLocked());
Map<String, String> body = new HashMap<>();
body.put("includeChildren", "true");
body.put("timeToExpire", "60");
body.put("type", "FULL");
body.put("lifetime", "PERSISTENT");
HttpResponse response = post(URL_NODES, d1Id, "lock", toJsonAsStringNonNull(body).getBytes(), null, null, 200);
response = post(URL_NODES, d1Id, "lock", toJsonAsStringNonNull(body).getBytes(), null, null, 200);
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals(d1Name, documentResp.getName());
assertEquals(d1Id, documentResp.getId());
assertEquals("READ_ONLY_LOCK", documentResp.getProperties().get("cm:lockType"));
assertNotNull(documentResp.getProperties().get("cm:lockOwner"));
assertNull(documentResp.getIsLocked());
// Empty lock body, the default values are used
post("nodes/"+folderId+"/lock", "{}", null, 200);
@@ -3627,6 +3641,23 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
Document dA2 = createTextFile(folderId, dA2Name, "A2 content");
String dA2Id = dA2.getId();
params = Collections.singletonMap("include", "isLocked");
response = getSingle(URL_NODES, folderAId, params, null, 200);
node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertNull(node.getProperties());
assertFalse(node.getIsLocked());
params = Collections.singletonMap("include", "aspectNames,properties,isLocked");
response = getAll(getNodeChildrenUrl(folderAId), null, params, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
// Check children nodes are not locked.
for (Node child : nodes)
{
assertNull(child.getProperties().get("cm:lockType"));
assertNull(child.getProperties().get("cm:lockOwner"));
assertFalse(child.getIsLocked());
}
body = new HashMap<>();
body.put("includeChildren", "true");
body.put("timeToExpire", "60");
@@ -3641,15 +3672,17 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
assertEquals(folderAId, documentResp.getId());
assertNotNull(documentResp.getProperties().get("cm:lockType"));
assertNotNull(documentResp.getProperties().get("cm:lockOwner"));
assertNull(documentResp.getIsLocked());
Map<String, String> params = Collections.singletonMap("include", "aspectNames,properties");
params = Collections.singletonMap("include", "aspectNames,properties,isLocked");
response = getAll(getNodeChildrenUrl(folderAId), null, params, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
// Test if children nodes are locked as well.
for (Node child : nodes)
{
assertNotNull(child.getProperties().get("cm:lockType"));
assertNotNull(child.getProperties().get("cm:lockOwner"));
assertTrue(child.getIsLocked());
}
Folder folderB = createFolder(Nodes.PATH_MY, "folderB");

View File

@@ -64,6 +64,7 @@ public class Node
protected Boolean isFolder;
protected Boolean isFile;
protected Boolean isLink;
protected Boolean isLocked;
protected String parentId;
protected PathInfo path;
@@ -196,6 +197,16 @@ public class Node
isLink = link;
}
public Boolean getIsLocked()
{
return isLocked;
}
public void setIsLocked(Boolean locked)
{
isLocked = locked;
}
public String getParentId()
{
return parentId;
@@ -396,6 +407,7 @@ public class Node
AssertUtil.assertEquals("isFolder", isFolder, other.getIsFolder());
AssertUtil.assertEquals("isFile", isFile, other.getIsFile());
AssertUtil.assertEquals("isLink", isLink, other.getIsLink());
AssertUtil.assertEquals("isLocked", isLocked, other.getIsLocked());
if (path != null)
{