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

129892 amorarasu: REPO-1155 / REPO-160 / REPO-340: Remove "includeChildren" option for Lock / Unlock in the rest api (REPO-1163)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@130237 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2016-09-06 14:44:30 +00:00
parent 26a1e7b69f
commit a98859b185
7 changed files with 31 additions and 261 deletions

View File

@@ -36,7 +36,6 @@ import org.alfresco.rest.api.model.Document;
import org.alfresco.rest.api.model.Folder;
import org.alfresco.rest.api.model.LockInfo;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.api.model.UnlockInfo;
import org.alfresco.rest.api.model.UserInfo;
import org.alfresco.rest.framework.resource.content.BasicContentInfo;
import org.alfresco.rest.framework.resource.content.BinaryResource;
@@ -259,11 +258,10 @@ public interface Nodes
/**
* Unlock a node
* @param nodeId
* @param unlockInfo
* @param parameters
* @return
*/
Node unlock(String nodeId, UnlockInfo unlockInfo, Parameters parameters);
Node unlock(String nodeId, Parameters parameters);
/**
* API Constants - query parameters, etc

View File

@@ -87,7 +87,6 @@ import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.api.model.PathInfo;
import org.alfresco.rest.api.model.PathInfo.ElementInfo;
import org.alfresco.rest.api.model.QuickShareLink;
import org.alfresco.rest.api.model.UnlockInfo;
import org.alfresco.rest.api.model.UserInfo;
import org.alfresco.rest.api.nodes.NodeAssocService;
import org.alfresco.rest.framework.core.exceptions.ApiException;
@@ -123,7 +122,6 @@ 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.lock.NodeLockedException;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.model.FileFolderService;
@@ -2958,7 +2956,7 @@ public class NodesImpl implements Nodes
}
lockInfo = validateLockInformation(lockInfo);
lockService.lock(nodeRef, lockInfo.getMappedType(), lockInfo.getTimeToExpire(), lockInfo.getLifetime(), lockInfo.getIncludeChildren());
lockService.lock(nodeRef, lockInfo.getMappedType(), lockInfo.getTimeToExpire(), lockInfo.getLifetime());
return getFolderOrDocument(nodeId, parameters);
}
@@ -2974,10 +2972,6 @@ public class NodesImpl implements Nodes
{
lockInfo.setLifetime(Lifetime.PERSISTENT.name());
}
if (lockInfo.getIncludeChildren() == null)
{
lockInfo.setIncludeChildren(false);
}
if (lockInfo.getTimeToExpire() == null)
{
lockInfo.setTimeToExpire(0);
@@ -2986,7 +2980,7 @@ public class NodesImpl implements Nodes
}
@Override
public Node unlock(String nodeId, UnlockInfo unlockInfo, Parameters parameters)
public Node unlock(String nodeId, Parameters parameters)
{
NodeRef nodeRef = validateOrLookupNode(nodeId, null);
@@ -2994,12 +2988,8 @@ public class NodesImpl implements Nodes
{
throw new PermissionDeniedException("Current user doesn't have permission to unlock node " + nodeId);
}
if (unlockInfo.getIncludeChildren() == null)
{
unlockInfo.setIncludeChildren(false);
}
lockService.unlock(nodeRef, unlockInfo.getIncludeChildren());
lockService.unlock(nodeRef);
return getFolderOrDocument(nodeId, parameters);
}

View File

@@ -38,7 +38,6 @@ import org.codehaus.jackson.annotate.JsonIgnoreProperties;
public class LockInfo
{
private Integer timeToExpire;
private Boolean includeChildren;
private LockType2 type;
private Lifetime lifetime;
@@ -77,16 +76,6 @@ public class LockInfo
return timeToExpire;
}
public void setIncludeChildren(Boolean includeChildren)
{
this.includeChildren = includeChildren;
}
public Boolean getIncludeChildren()
{
return includeChildren;
}
public LockType getMappedType()
{
return type != null ? type.getType() : null;
@@ -116,7 +105,6 @@ public class LockInfo
public String toString()
{
final StringBuilder sb = new StringBuilder("LockInfo{");
sb.append("includeChildren='").append(includeChildren).append('\'');
sb.append(", timeToExpire='").append(timeToExpire).append('\'');
sb.append(", type='").append(type).append('\'');
sb.append(", lifetime='").append(lifetime).append('\'');

View File

@@ -1,60 +0,0 @@
/*
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* 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/>.
* #L%
*/
package org.alfresco.rest.api.model;
/**
* Representation of a unlock info
*
* @author Ancuta Morarasu
*/
public class UnlockInfo
{
private Boolean includeChildren;
// private Boolean allowCheckedOut;
public UnlockInfo() {}
public Boolean getIncludeChildren()
{
return includeChildren;
}
public void setIncludeChildren(Boolean includeChildren)
{
this.includeChildren = includeChildren;
}
//
// public Boolean getAllowCheckedOut()
// {
// return allowCheckedOut;
// }
//
// public void setAllowCheckedOut(Boolean allowCheckedOut)
// {
// this.allowCheckedOut = allowCheckedOut;
// }
}

View File

@@ -33,7 +33,6 @@ import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.model.LockInfo;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.api.model.NodeTarget;
import org.alfresco.rest.api.model.UnlockInfo;
import org.alfresco.rest.framework.BinaryProperties;
import org.alfresco.rest.framework.Operation;
import org.alfresco.rest.framework.WebApiDescription;
@@ -185,9 +184,9 @@ public class NodesEntityResource implements
@WebApiDescription(title = "Unlock Node",
description="Removes a lock on a node.",
successStatus = HttpServletResponse.SC_OK)
public Node unlock(String nodeId, UnlockInfo unlockInfo, Parameters parameters, WithResponse withResponse)
public Node unlock(String nodeId, Void ignore, Parameters parameters, WithResponse withResponse)
{
return nodes.unlock(nodeId, unlockInfo, parameters);
return nodes.unlock(nodeId, parameters);
}
}

View File

@@ -806,9 +806,9 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
}
protected Document unlock(String nodeId, String body) throws Exception
protected Document unlock(String nodeId) throws Exception
{
HttpResponse response = post(getNodeOperationUrl(nodeId, "unlock"), body, null, 200);
HttpResponse response = post(getNodeOperationUrl(nodeId, "unlock"), null, null, 200);
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
}

View File

@@ -60,7 +60,6 @@ import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.model.LockInfo;
import org.alfresco.rest.api.model.NodeTarget;
import org.alfresco.rest.api.model.Site;
import org.alfresco.rest.api.model.UnlockInfo;
import org.alfresco.rest.api.nodes.NodesEntityResource;
import org.alfresco.rest.api.tests.client.HttpResponse;
import org.alfresco.rest.api.tests.client.PublicApiClient;
@@ -3610,7 +3609,6 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
assertFalse(node.getIsLocked());
LockInfo lockInfo = new LockInfo();
lockInfo.setIncludeChildren(true);
lockInfo.setTimeToExpire(60);
lockInfo.setType("FULL");
lockInfo.setLifetime("PERSISTENT");
@@ -3635,40 +3633,32 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
// Content update on a locked node
updateTextFile(d1Id, "Updated text", null, 409);
unlock(d1Id);
// Test lock children
// Test lock file
// create folder
String folderAName = "folder" + RUNID + "_A";
Folder folderA = createFolder(Nodes.PATH_MY, folderAName);
String folderAId = folderA.getId();
// create 2 files in the folderA
createTextFile(folderAId, "content" + RUNID + "_A1", "A1 content");
createTextFile(folderAId, "content" + RUNID + "_A2", "A2 content");
// create a file in the folderA
Document dA1 = createTextFile(folderAId, "content" + RUNID + "_A1", "A1 content");
String dA1Id = dA1.getId();
lockInfo = new LockInfo();
lockInfo.setIncludeChildren(true);
lockInfo.setTimeToExpire(60);
lockInfo.setType("ALLOW_OWNER_CHANGES");
lockInfo.setLifetime("EPHEMERAL");
// lock the folder
response = post(getNodeOperationUrl(folderAId, "lock"), toJsonAsStringNonNull(lockInfo), null, 200);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
// lock the file
post(getNodeOperationUrl(dA1Id, "lock"), toJsonAsStringNonNull(lockInfo), null, 200);
params = Collections.singletonMap("include", "aspectNames,properties,isLocked");
response = getAll(getNodeChildrenUrl(folderAId), null, params, 200);
List<Node> 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());
// note: these can be updated by the owner since the lock type is "ALLOW_OWNER_CHANGES"
updateTextFile(child.getId(), "Updated text", null, 200);
}
response = getSingle(URL_NODES, dA1Id, params, null, 200);
node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertTrue(node.getIsLocked());
// note: this can be updated by the owner since the lock type is "ALLOW_OWNER_CHANGES"
updateTextFile(node.getId(), "Updated text", null, 200);
// Lock body properties - boundary values
Folder folderB = createFolder(Nodes.PATH_MY, "folder" + RUNID + "_B");
@@ -3689,7 +3679,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
// use admin for now (might be better to use a user with given WRITE permission)
setRequestContext(networkAdmin);
post(getNodeOperationUrl(f1d1Id, "lock"), EMPTY_BODY, null, 200);
unlock(f1d1Id, EMPTY_BODY);
unlock(f1d1Id);
// -ve tests
// Missing target node
@@ -3727,10 +3717,6 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
Folder folderC = createFolder(Nodes.PATH_MY, "folder" + RUNID + "_C");
String folderCId = folderC.getId();
Map<String, String> body = new HashMap<>();
body.put("includeChildren", "true123");
post(getNodeOperationUrl(folderCId, "lock"), toJsonAsStringNonNull(body), null, 400);
body = new HashMap<>();
body.put("type", "FULL123");
post(getNodeOperationUrl(folderCId, "lock"), toJsonAsStringNonNull(body), null, 400);
@@ -3748,13 +3734,10 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
//cleanup
setRequestContext(user1); // all locks were made by user1
UnlockInfo unlockInfo = new UnlockInfo();
unlockInfo.setIncludeChildren(true);
unlock(folderId, toJsonAsStringNonNull(unlockInfo));
unlock(folderId);
deleteNode(folderId);
unlock(folderAId, toJsonAsStringNonNull(unlockInfo));
deleteNode(folderAId);
unlock(folderBId, EMPTY_BODY);
unlock(folderBId);
deleteNode(folderBId);
deleteNode(folderCId);
deleteNode(folder1Id);
@@ -3783,10 +3766,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
lock(d1Id, EMPTY_BODY);
UnlockInfo unlockInfo = new UnlockInfo();
unlockInfo.setIncludeChildren(true);
HttpResponse response = post(getNodeOperationUrl(d1Id, "unlock"), toJsonAsStringNonNull(unlockInfo), null, 200);
HttpResponse response = post(getNodeOperationUrl(d1Id, "unlock"), null, null, 200);
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals(d1Name, documentResp.getName());
@@ -3797,153 +3777,28 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
lock(d1Id, EMPTY_BODY);
// Users with admin rights can unlock nodes locked by other users.
setRequestContext(networkAdmin);
post(getNodeOperationUrl(d1Id, "unlock"), EMPTY_BODY, null, 200);
post(getNodeOperationUrl(d1Id, "unlock"), null, null, 200);
// -ve
// Missing target node
post(getNodeOperationUrl("fakeId", "unlock"), EMPTY_BODY, null, 404);
post(getNodeOperationUrl("fakeId", "unlock"), null, null, 404);
// Unlock by a user without permission
lock(d1Id, EMPTY_BODY);
setRequestContext(user2);
post(getNodeOperationUrl(d1Id, "unlock"), EMPTY_BODY, null, 403);
post(getNodeOperationUrl(d1Id, "unlock"), null, null, 403);
setRequestContext(user1);
//Unlock on a not locked node
post(getNodeOperationUrl(folderId, "unlock"), EMPTY_BODY, null, 403);
post(getNodeOperationUrl(folderId, "unlock"), null, null, 403);
// Invalid lock body values
setRequestContext(user1);
Folder folderC = createFolder(Nodes.PATH_MY, "folder" + RUNID + "_C");
String folderCId = folderC.getId();
lock(folderCId, EMPTY_BODY);
Map<String, String> body = new HashMap<>();
body.put("includeChildren", "true123");
post(getNodeOperationUrl(folderCId, "unlock"), toJsonAsStringNonNull(body), null, 400);
body = new HashMap<>();
body.put("allowCheckedOut", "false123");
post(getNodeOperationUrl(folderCId, "unlock"), toJsonAsStringNonNull(body), null, 400);
body = new HashMap<>();
body.put("invalid_property", "true");
post(getNodeOperationUrl(folderCId, "unlock"), toJsonAsStringNonNull(body), null, 400);
// clean up
setRequestContext(user1); // all locks were made by user1
unlockInfo = new UnlockInfo();
unlockInfo.setIncludeChildren(true);
unlock(d1Id, toJsonAsStringNonNull(unlockInfo));
unlock(d1Id);
deleteNode(folderId);
unlock(folderCId, EMPTY_BODY);
deleteNode(folderCId);
}
/**
* Tests lock and unlock with children
* <p>POST:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/lock}</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/unlock}
*/
@Test
public void testLockUnlockWithChildren() throws Exception
{
setRequestContext(user1);
// Test unlock children
// create folder
Folder folderA = createFolder(Nodes.PATH_MY, "folder" + RUNID + "_A");
String folderAId = folderA.getId();
// create 2 files in the folderA
String dA1Name = "content" + RUNID + "_A1";
Document dA1 = createTextFile(folderAId, dA1Name, "A1 content");
String dA1Id = dA1.getId();
String dA2Name = "content" + RUNID + "_A2";
Document dA2 = createTextFile(folderAId, dA2Name, "A2 content");
String dA2Id = dA2.getId();
Map<String, String> params = Collections.singletonMap("include", "isLocked");
HttpResponse response = getSingle(URL_NODES, folderAId, params, null, 200);
Node 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());
}
// Lock the folder and children
LockInfo lockInfo = new LockInfo();
lockInfo.setIncludeChildren(true);
response = post(getNodeOperationUrl(folderAId, "lock"), toJsonAsStringNonNull(lockInfo), null, 200);
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals(folderAId, documentResp.getId());
assertNotNull(documentResp.getProperties().get("cm:lockType"));
assertNotNull(documentResp.getProperties().get("cm:lockOwner"));
assertNull(documentResp.getIsLocked());
params = Collections.singletonMap("include", "aspectNames,properties,isLocked");
response = getAll(getNodeChildrenUrl(folderAId), null, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
// Check 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());
}
// Unlock folder and children
UnlockInfo unlockInfo = new UnlockInfo();
unlockInfo.setIncludeChildren(true);
post(getNodeOperationUrl(folderAId, "unlock"), toJsonAsStringNonNull(unlockInfo), null, 200);
params = Collections.singletonMap("include", "aspectNames,properties,isLocked");
response = getAll(getNodeChildrenUrl(folderAId), null, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
// Check if children nodes are unlocked as well.
for (Node child : nodes)
{
assertNull(child.getProperties().get("cm:lockType"));
assertNull(child.getProperties().get("cm:lockOwner"));
assertFalse(child.getIsLocked());
}
// One of the children is not locked
// FolderA locked
// - dA1 locked
// - dA2 unlocked
lock(folderAId, EMPTY_BODY);
lock(dA1Id, EMPTY_BODY);
post(getNodeOperationUrl(folderAId, "unlock"), toJsonAsStringNonNull(unlockInfo), null, 200);
// Parent unlocked, children locked
// FolderA unlocked
// - dA1 locked
// - dA2 locked
lock(dA2Id, EMPTY_BODY);
lock(dA1Id, EMPTY_BODY);
// Unlock on not locked parent
post(getNodeOperationUrl(folderAId, "unlock"), toJsonAsStringNonNull(unlockInfo), null, 403);
// Clean up
unlock(dA1Id, EMPTY_BODY);
unlock(dA2Id, EMPTY_BODY);
deleteNode(folderAId);
}
@Override
public String getScope()
{