diff --git a/source/java/org/alfresco/rest/api/Nodes.java b/source/java/org/alfresco/rest/api/Nodes.java index 62c8b19185..34f24a26ca 100644 --- a/source/java/org/alfresco/rest/api/Nodes.java +++ b/source/java/org/alfresco/rest/api/Nodes.java @@ -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"; diff --git a/source/java/org/alfresco/rest/api/impl/NodesImpl.java b/source/java/org/alfresco/rest/api/impl/NodesImpl.java index ebfef14fc4..0a5cbed504 100644 --- a/source/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -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 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 @@ -1970,7 +1979,23 @@ public class NodesImpl implements Nodes return false; } + + private boolean isLocked(NodeRef nodeRef, Set 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) { diff --git a/source/java/org/alfresco/rest/api/model/Node.java b/source/java/org/alfresco/rest/api/model/Node.java index a9c15652fb..519eed92ba 100644 --- a/source/java/org/alfresco/rest/api/model/Node.java +++ b/source/java/org/alfresco/rest/api/model/Node.java @@ -73,6 +73,7 @@ public class Node implements Comparable 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 this.isLink = isLink; } + public Boolean getIsLocked() + { + return isLocked; + } + + public void setIsLocked(Boolean isLocked) + { + this.isLocked = isLocked; + } + public List getAllowableOperations() { return allowableOperations; diff --git a/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java b/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java index 2112ef5c25..35eac7e231 100644 --- a/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java @@ -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 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 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 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 params = Collections.singletonMap("include", "aspectNames,properties"); + params = Collections.singletonMap("include", "aspectNames,properties,isLocked"); response = getAll(getNodeChildrenUrl(folderAId), null, params, 200); - List 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"); diff --git a/source/test-java/org/alfresco/rest/api/tests/client/data/Node.java b/source/test-java/org/alfresco/rest/api/tests/client/data/Node.java index 41e1d48de6..faf0e3d911 100644 --- a/source/test-java/org/alfresco/rest/api/tests/client/data/Node.java +++ b/source/test-java/org/alfresco/rest/api/tests/client/data/Node.java @@ -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) {