REPO-164 / REPO-1150: fix minor regress (eg. if recursively locking nodes via includeChildren)

-  MNT-16446, MNT-14945

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@129826 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2016-08-24 12:11:40 +00:00
parent b04cef45d1
commit 51c220c5a5
2 changed files with 158 additions and 90 deletions

View File

@@ -1,28 +1,28 @@
/* /*
* #%L * #%L
* Alfresco Remote API * Alfresco Remote API
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.api.tests; package org.alfresco.rest.api.tests;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@@ -83,8 +83,8 @@ import org.alfresco.rest.api.impl.node.ratings.RatingScheme;
import org.alfresco.rest.api.tests.client.data.Activity; import org.alfresco.rest.api.tests.client.data.Activity;
import org.alfresco.rest.api.tests.client.data.Comment; import org.alfresco.rest.api.tests.client.data.Comment;
import org.alfresco.rest.api.tests.client.data.Company; import org.alfresco.rest.api.tests.client.data.Company;
import org.alfresco.rest.api.tests.client.data.FavouriteDocument; import org.alfresco.rest.api.tests.client.data.FavouriteDocument;
import org.alfresco.rest.api.tests.client.data.FavouriteFolder; import org.alfresco.rest.api.tests.client.data.FavouriteFolder;
import org.alfresco.rest.api.tests.client.data.FavouriteSite; import org.alfresco.rest.api.tests.client.data.FavouriteSite;
import org.alfresco.rest.api.tests.client.data.MemberOfSite; import org.alfresco.rest.api.tests.client.data.MemberOfSite;
import org.alfresco.rest.api.tests.client.data.NetworkImpl; import org.alfresco.rest.api.tests.client.data.NetworkImpl;
@@ -365,14 +365,27 @@ public class RepoService
nodeService.deleteNode(nodeRef); nodeService.deleteNode(nodeRef);
} }
//
// TODO replace with V1 REST API to Lock/Unlock - except calls to includeChildren (which may not be exposed, initially
//
public void lockNode(NodeRef nodeRef) public void lockNode(NodeRef nodeRef)
{ {
lockService.lock(nodeRef, LockType.NODE_LOCK); lockNode(nodeRef, LockType.NODE_LOCK, 0, false);
}
public void lockNode(NodeRef nodeRef, LockType lockType, int timeToExpire, boolean includeChildren)
{
lockService.lock(nodeRef, lockType, timeToExpire, includeChildren);
} }
public void unlockNode(NodeRef nodeRef) public void unlockNode(NodeRef nodeRef)
{ {
lockService.unlock(nodeRef); unlockNode(nodeRef, false);
}
public void unlockNode(NodeRef nodeRef, boolean includeChildren)
{
lockService.unlock(nodeRef, true, false);
} }
public NodeRef addUserDescription(final String personId, final TestNetwork network, final String personDescription) public NodeRef addUserDescription(final String personId, final TestNetwork network, final String personDescription)
@@ -400,13 +413,13 @@ public class RepoService
public TestPerson createUser(final PersonInfo personInfo, final String username, final TestNetwork network) public TestPerson createUser(final PersonInfo personInfo, final String username, final TestNetwork network)
{ {
return getOrCreateUser(personInfo, username, network, true); return getOrCreateUser(personInfo, username, network, true);
} }
public TestPerson getOrCreateUser(final PersonInfo personInfo, final String username, final TestNetwork network) public TestPerson getOrCreateUser(final PersonInfo personInfo, final String username, final TestNetwork network)
{ {
return getOrCreateUser(personInfo, username, network, false); return getOrCreateUser(personInfo, username, network, false);
} }
public final static String DEFAULT_ADMIN = "admin"; public final static String DEFAULT_ADMIN = "admin";
public final static String DEFAULT_ADMIN_PWD = "admin"; public final static String DEFAULT_ADMIN_PWD = "admin";
@@ -423,55 +436,55 @@ public class RepoService
return ((DEFAULT_ADMIN+"@"+network.getId()).equalsIgnoreCase(username)); return ((DEFAULT_ADMIN+"@"+network.getId()).equalsIgnoreCase(username));
} }
} }
// TODO review delete person // TODO review delete person
public TestPerson getOrCreateUser(final PersonInfo personInfo, final String username, final TestNetwork network, final boolean deletePerson) public TestPerson getOrCreateUser(final PersonInfo personInfo, final String username, final TestNetwork network, final boolean deletePerson)
{ {
return AuthenticationUtil.runAsSystem(new RunAsWork<TestPerson>() return AuthenticationUtil.runAsSystem(new RunAsWork<TestPerson>()
{ {
@Override @Override
public TestPerson doWork() throws Exception public TestPerson doWork() throws Exception
{ {
final TestPerson testPerson = new TestPerson(personInfo.getFirstName(), personInfo.getLastName(), username, personInfo.getPassword(), final TestPerson testPerson = new TestPerson(personInfo.getFirstName(), personInfo.getLastName(), username, personInfo.getPassword(),
personInfo.getCompany(), network, personInfo.getSkype(), personInfo.getLocation(), personInfo.getTel(), personInfo.getCompany(), network, personInfo.getSkype(), personInfo.getLocation(), personInfo.getTel(),
personInfo.getMob(), personInfo.getInstantmsg(), personInfo.getGoogle()); personInfo.getMob(), personInfo.getInstantmsg(), personInfo.getGoogle());
final Map<QName, Serializable> props = testPerson.getProperties(); final Map<QName, Serializable> props = testPerson.getProperties();
// short-circuit for default/tenant "admin" // short-circuit for default/tenant "admin"
if (! isDefaultAdmin(username, network)) if (! isDefaultAdmin(username, network))
{ {
NodeRef personNodeRef = personService.getPersonOrNull(username); NodeRef personNodeRef = personService.getPersonOrNull(username);
if ((personNodeRef != null) && deletePerson) if ((personNodeRef != null) && deletePerson)
{ {
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
{ {
@Override @Override
public Void doWork() throws Exception public Void doWork() throws Exception
{ {
personService.deletePerson(testPerson.getId()); personService.deletePerson(testPerson.getId());
return null; return null;
} }
}); });
} }
if (personNodeRef == null) if (personNodeRef == null)
{ {
personNodeRef = personService.createPerson(props); personNodeRef = personService.createPerson(props);
// create authentication to represent user // create authentication to represent user
authenticationService.createAuthentication(username, personInfo.getPassword().toCharArray()); authenticationService.createAuthentication(username, personInfo.getPassword().toCharArray());
if (EnterpriseTestFixture.WITH_AVATAR.equals(personInfo.getInstantmsg())) if (EnterpriseTestFixture.WITH_AVATAR.equals(personInfo.getInstantmsg()))
{ {
InvitationWebScriptTest.makeAvatar(nodeService, personNodeRef); InvitationWebScriptTest.makeAvatar(nodeService, personNodeRef);
log("Made avatar for " + testPerson.getId() + (network != null ? " in network " + network : "")); log("Made avatar for " + testPerson.getId() + (network != null ? " in network " + network : ""));
} }
} }
} }
log("Username " + testPerson.getId() + (network != null ? " in network " + network : "")); log("Username " + testPerson.getId() + (network != null ? " in network " + network : ""));
publicApiContext.addUser(testPerson.getId()); publicApiContext.addUser(testPerson.getId());
addPerson(testPerson); addPerson(testPerson);
@@ -978,20 +991,20 @@ public class RepoService
return wrapProperties; return wrapProperties;
} }
public FavouriteDocument getDocument(String networkId, final NodeRef nodeRef) public FavouriteDocument getDocument(String networkId, final NodeRef nodeRef)
{ {
return TenantUtil.runAsSystemTenant(new TenantRunAsWork<FavouriteDocument>() return TenantUtil.runAsSystemTenant(new TenantRunAsWork<FavouriteDocument>()
{ {
@Override @Override
public FavouriteDocument doWork() throws Exception public FavouriteDocument doWork() throws Exception
{ {
FavouriteDocument document = null; FavouriteDocument document = null;
QName type = nodeService.getType(nodeRef); QName type = nodeService.getType(nodeRef);
if(dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)) if(dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT))
{ {
Properties properties = getProperties(nodeRef); Properties properties = getProperties(nodeRef);
document = FavouriteDocument.getDocument(nodeRef.getId(), nodeRef.getId(), properties); document = FavouriteDocument.getDocument(nodeRef.getId(), nodeRef.getId(), properties);
} }
else else
{ {
@@ -1003,20 +1016,20 @@ public class RepoService
}, networkId); }, networkId);
} }
public FavouriteFolder getFolder(String networkId, final NodeRef nodeRef) public FavouriteFolder getFolder(String networkId, final NodeRef nodeRef)
{ {
return TenantUtil.runAsSystemTenant(new TenantRunAsWork<FavouriteFolder>() return TenantUtil.runAsSystemTenant(new TenantRunAsWork<FavouriteFolder>()
{ {
@Override @Override
public FavouriteFolder doWork() throws Exception public FavouriteFolder doWork() throws Exception
{ {
FavouriteFolder folder = null; FavouriteFolder folder = null;
QName type = nodeService.getType(nodeRef); QName type = nodeService.getType(nodeRef);
if(dictionaryService.isSubClass(type, ContentModel.TYPE_FOLDER)) if(dictionaryService.isSubClass(type, ContentModel.TYPE_FOLDER))
{ {
Properties properties = getProperties(nodeRef); Properties properties = getProperties(nodeRef);
folder = FavouriteFolder.getFolder(nodeRef.getId(), nodeRef.getId(), properties); folder = FavouriteFolder.getFolder(nodeRef.getId(), nodeRef.getId(), properties);
} }
else else
{ {
@@ -1362,11 +1375,11 @@ public class RepoService
public void create() public void create()
{ {
if(!getId().equals(TenantService.DEFAULT_DOMAIN) && !tenantAdminService.existsTenant(getId())) if(!getId().equals(TenantService.DEFAULT_DOMAIN) && !tenantAdminService.existsTenant(getId()))
{ {
tenantAdminService.createTenant(getId(), DEFAULT_ADMIN_PWD.toCharArray()); tenantAdminService.createTenant(getId(), DEFAULT_ADMIN_PWD.toCharArray());
numNetworks++; numNetworks++;
log("Created network " + getId()); log("Created network " + getId());
} }
} }

View File

@@ -57,6 +57,7 @@ import org.alfresco.rest.api.tests.client.data.Activity;
import org.alfresco.rest.api.tests.client.data.Comment; import org.alfresco.rest.api.tests.client.data.Comment;
import org.alfresco.rest.api.tests.client.data.SiteRole; import org.alfresco.rest.api.tests.client.data.SiteRole;
import org.alfresco.rest.api.tests.client.data.Tag; import org.alfresco.rest.api.tests.client.data.Tag;
import org.alfresco.service.cmr.lock.LockType;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.site.SiteVisibility; import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.util.GUID; import org.alfresco.util.GUID;
@@ -91,6 +92,7 @@ public class TestNodeComments extends EnterpriseTestApi
private NodeRef nodeRef4; private NodeRef nodeRef4;
private NodeRef cmObjectNodeRef; private NodeRef cmObjectNodeRef;
private NodeRef customTypeObject; private NodeRef customTypeObject;
private NodeRef nodeRef5;
@Override @Override
@Before @Before
@@ -170,7 +172,8 @@ public class TestNodeComments extends EnterpriseTestApi
{ {
NodeRef nodeRef = repoService.createDocument(site1.getContainerNodeRef("documentLibrary"), "Test Doc", "Test Content"); NodeRef nodeRef = repoService.createDocument(site1.getContainerNodeRef("documentLibrary"), "Test Doc", "Test Content");
nodes.add(nodeRef); nodes.add(nodeRef);
nodeRef = repoService.createFolder(site1.getContainerNodeRef("documentLibrary"), "Test Folder"); NodeRef folderNodeRef = repoService.createFolder(site1.getContainerNodeRef("documentLibrary"), "Test Folder");
nodeRef = folderNodeRef;
nodes.add(nodeRef); nodes.add(nodeRef);
nodeRef = repoService.createDocument(site1.getContainerNodeRef("documentLibrary"), "Test Doc 1", "Test Content 1"); nodeRef = repoService.createDocument(site1.getContainerNodeRef("documentLibrary"), "Test Doc 1", "Test Content 1");
nodes.add(nodeRef); nodes.add(nodeRef);
@@ -182,6 +185,8 @@ public class TestNodeComments extends EnterpriseTestApi
nodes.add(nodeRef); nodes.add(nodeRef);
nodeRef = repoService.createObjectOfCustomType(site1.getContainerNodeRef("documentLibrary"), "Custom type object", "{custom.model}sop"); nodeRef = repoService.createObjectOfCustomType(site1.getContainerNodeRef("documentLibrary"), "Custom type object", "{custom.model}sop");
nodes.add(nodeRef); nodes.add(nodeRef);
nodeRef = repoService.createDocument(folderNodeRef, "Test Doc 4", "Test Content 4 - in Test Folder");
nodes.add(nodeRef);
return null; return null;
} }
@@ -194,6 +199,7 @@ public class TestNodeComments extends EnterpriseTestApi
this.nodeRef4 = nodes.get(4); this.nodeRef4 = nodes.get(4);
this.cmObjectNodeRef = nodes.get(5); this.cmObjectNodeRef = nodes.get(5);
this.customTypeObject = nodes.get(6); this.customTypeObject = nodes.get(6);
this.nodeRef5 = nodes.get(7);
} }
@Test @Test
@@ -771,16 +777,23 @@ public class TestNodeComments extends EnterpriseTestApi
{ {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
} }
}
@Test
public void testNodeCommentsAndLocking() throws Exception
{
Comments commentsProxy = publicApiClient.comments();
// locked node - cannot add/edit/delete comments (MNT-14945, MNT-16446) // locked node - cannot add/edit/delete comments (MNT-14945, MNT-16446)
try try
{ {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId())); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Comment comment = new Comment(); Comment comment = new Comment();
comment.setContent("my comment"); comment.setContent("my comment");
Comment createdComment = commentsProxy.createNodeComment(nodeRef1.getId(), comment); Comment createdComment = commentsProxy.createNodeComment(nodeRef1.getId(), comment);
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
{ {
@Override @Override
@@ -797,7 +810,7 @@ public class TestNodeComments extends EnterpriseTestApi
int skipCount = 0; int skipCount = 0;
int maxItems = Integer.MAX_VALUE; int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedComments.size(), expectedComments.size()); Paging paging = getPaging(skipCount, maxItems);
commentsProxy.getNodeComments(nodeRef1.getId(), createParams(paging, null)); commentsProxy.getNodeComments(nodeRef1.getId(), createParams(paging, null));
// test POST for a locked node // test POST for a locked node
@@ -809,7 +822,7 @@ public class TestNodeComments extends EnterpriseTestApi
fail(""); fail("");
} }
catch(PublicApiException e) catch (PublicApiException e)
{ {
assertEquals(HttpStatus.SC_CONFLICT, e.getHttpResponse().getStatusCode()); assertEquals(HttpStatus.SC_CONFLICT, e.getHttpResponse().getStatusCode());
} }
@@ -820,10 +833,10 @@ public class TestNodeComments extends EnterpriseTestApi
Comment updatedComment = new Comment(); Comment updatedComment = new Comment();
updatedComment.setContent("my comment"); updatedComment.setContent("my comment");
commentsProxy.updateNodeComment(nodeRef1.getId(), createdComment.getId(), updatedComment); commentsProxy.updateNodeComment(nodeRef1.getId(), createdComment.getId(), updatedComment);
fail(""); fail("");
} }
catch(PublicApiException e) catch (PublicApiException e)
{ {
assertEquals(HttpStatus.SC_CONFLICT, e.getHttpResponse().getStatusCode()); assertEquals(HttpStatus.SC_CONFLICT, e.getHttpResponse().getStatusCode());
} }
@@ -835,7 +848,7 @@ public class TestNodeComments extends EnterpriseTestApi
fail(""); fail("");
} }
catch(PublicApiException e) catch (PublicApiException e)
{ {
assertEquals(HttpStatus.SC_CONFLICT, e.getHttpResponse().getStatusCode()); assertEquals(HttpStatus.SC_CONFLICT, e.getHttpResponse().getStatusCode());
} }
@@ -853,7 +866,49 @@ public class TestNodeComments extends EnterpriseTestApi
}, person11.getId(), network1.getId()); }, person11.getId(), network1.getId());
} }
} }
// lock recursively (MNT-14945, MNT-16446, REPO-1150)
@Test
public void testNodeCommentsAndLockingIncludingChildren() throws Exception
{
Comments commentsProxy = publicApiClient.comments();
// TODO push-down to future CommentServiceImplTest (see ACE-5437) - since includeChildren is via LockService api only
try
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Comment comment = new Comment();
comment.setContent("my comment");
Comment createdComment = commentsProxy.createNodeComment(nodeRef5.getId(), comment);
// recursive lock (folderRef1, nodeRef5)
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
repoService.lockNode(folderNodeRef1, LockType.WRITE_LOCK, 0, true);
return null;
}
}, person11.getId(), network1.getId());
}
finally
{
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
repoService.unlockNode(folderNodeRef1, true);
return null;
}
}, network1.getId());
}
}
@Test @Test
public void test_MNT_16446() throws Exception public void test_MNT_16446() throws Exception
{ {