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

132612 rneamtu: SHA-1892 : Error appears when Consumer or Contributor is trying to create a link on a document
      - After creating the link for a node, add the marker aspect (LINKED) to the original node as System user. 
      - Added test for case 
      - Added a new test for DocumentLinkServiceImplTest for updated fucntionality


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@132692 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2016-11-10 21:53:10 +00:00
parent effcb6bf22
commit 44d77c4475

View File

@@ -45,7 +45,9 @@ import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService;
@@ -86,6 +88,7 @@ public class NodeWebScripTest extends BaseWebScriptTest
private NodeService nodeService;
private NodeArchiveService nodeArchiveService;
private CheckOutCheckInService checkOutCheckInService;
private PermissionService permissionService;
private static final String USER_ONE = "UserOneSecondToo";
private static final String USER_TWO = "UserTwoSecondToo";
@@ -105,6 +108,7 @@ public class NodeWebScripTest extends BaseWebScriptTest
this.nodeService = (NodeService)ctx.getBean("NodeService");
this.nodeArchiveService = (NodeArchiveService)ctx.getBean("nodeArchiveService");
this.checkOutCheckInService = (CheckOutCheckInService)ctx.getBean("checkOutCheckInService");
this.permissionService = (PermissionService)ctx.getBean("permissionService");
// Do the setup as admin
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
@@ -585,8 +589,8 @@ public class NodeWebScripTest extends BaseWebScriptTest
// Links can be created in Shared Files, My Files and Repository
NodeRef testFile4 = createNode(testFolder1, "testingLinkCreationFile4", ContentModel.TYPE_CONTENT,
AuthenticationUtil.getAdminUserName());
req = new Request("POST", CREATE_LINK_API + testFile4.getStoreRef().getProtocol() + "/"
+ testFile4.getStoreRef().getIdentifier() + "/" + testFile4.getId());
req = new Request("POST", CREATE_LINK_API + testFile4.getStoreRef().getProtocol() + "/" + testFile4.getStoreRef().getIdentifier()
+ "/" + testFile4.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, "alfresco://company/shared");
@@ -598,8 +602,8 @@ public class NodeWebScripTest extends BaseWebScriptTest
json = asJSON(sendRequest(req, Status.STATUS_OK));
req = new Request("POST", CREATE_LINK_API + testFile4.getStoreRef().getProtocol() + "/"
+ testFile4.getStoreRef().getIdentifier() + "/" + testFile4.getId());
req = new Request("POST", CREATE_LINK_API + testFile4.getStoreRef().getProtocol() + "/" + testFile4.getStoreRef().getIdentifier()
+ "/" + testFile4.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, "alfresco://user/home");
@@ -613,8 +617,8 @@ public class NodeWebScripTest extends BaseWebScriptTest
// create link in Repository as Admin
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
req = new Request("POST", CREATE_LINK_API + testFile4.getStoreRef().getProtocol() + "/"
+ testFile4.getStoreRef().getIdentifier() + "/" + testFile4.getId());
req = new Request("POST", CREATE_LINK_API + testFile4.getStoreRef().getProtocol() + "/" + testFile4.getStoreRef().getIdentifier()
+ "/" + testFile4.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, "alfresco://company/home");
@@ -627,8 +631,8 @@ public class NodeWebScripTest extends BaseWebScriptTest
json = asJSON(sendRequest(req, Status.STATUS_OK));
// all 3 links are created with success, delete all links
req = new Request("DELETE", CREATE_LINK_API + testFile4.getStoreRef().getProtocol() + "/"
+ testFile4.getStoreRef().getIdentifier() + "/" + testFile4.getId() + "/delete");
req = new Request("DELETE", CREATE_LINK_API + testFile4.getStoreRef().getProtocol() + "/" + testFile4.getStoreRef().getIdentifier()
+ "/" + testFile4.getId() + "/delete");
req.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_OK));
@@ -641,8 +645,8 @@ public class NodeWebScripTest extends BaseWebScriptTest
final NodeRef testFile5 = createNode(testFolder1, "testingLinkCreationFileWithLock", ContentModel.TYPE_CONTENT,
AuthenticationUtil.getAdminUserName());
req = new Request("POST", CREATE_LINK_API + testFile5.getStoreRef().getProtocol() + "/"
+ testFile5.getStoreRef().getIdentifier() + "/" + testFile5.getId());
req = new Request("POST", CREATE_LINK_API + testFile5.getStoreRef().getProtocol() + "/" + testFile5.getStoreRef().getIdentifier()
+ "/" + testFile5.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
@@ -707,6 +711,41 @@ public class NodeWebScripTest extends BaseWebScriptTest
});
assertEquals(false, nodeService.hasAspect(testFile5, ContentModel.ASPECT_LOCKABLE));
// test that Consumers can create and delete links if they have only read permission
NodeRef testFile6 = createNode(testFolder1, "testingLinkCreationFile6", ContentModel.TYPE_CONTENT,
AuthenticationUtil.getAdminUserName());
AuthenticationUtil.setFullyAuthenticatedUser(USER_TWO);
assertTrue(permissionService.hasPermission(testFile6, PermissionService.READ) == AccessStatus.ALLOWED);
assertTrue(permissionService.hasPermission(testFile6, PermissionService.WRITE) == AccessStatus.DENIED);
// create another link of testFile1 in MyFiles
req = new Request("POST", CREATE_LINK_API + testFile6.getStoreRef().getProtocol() + "/"
+ testFile6.getStoreRef().getIdentifier() + "/" + testFile6.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, "alfresco://user/home");
jsonArray = new JSONArray();
jsonArray.add(testFile6.toString());
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_OK));
jsonLinkNodes = (JSONArray) json.get("linkNodes");
assertNotNull(jsonLinkNodes);
assertEquals(1, jsonLinkNodes.size());
assertEquals("true", json.get("overallSuccess"));
assertEquals("1", json.get("successCount"));
assertEquals("0", json.get("failureCount"));
jsonLinkNode = (JSONObject) jsonLinkNodes.get(0);
nodeRef = (String) jsonLinkNode.get("nodeRef");
NodeRef testFileSite3Link = new NodeRef(nodeRef);
nodeService.exists(testFileSite3Link);
assertEquals(true, nodeService.hasAspect(testFile6, ApplicationModel.ASPECT_LINKED));
nodeService.deleteNode(testFileSite3Link);
}
private NodeRef createNode(NodeRef parentNode, String nodeCmName, QName nodeType, String ownerUserName)