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

132544 rneamtu: SHA-1867 : Unable to create links in Shared Files / My Files root node from the Search Results page
      - Added method WebScriptUtil.resolveNodeReference() which will resolve nodeRef


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@132675 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2016-11-10 16:59:59 +00:00
parent 12d7f0ff0c
commit 7ffe84308a
5 changed files with 130 additions and 32 deletions

View File

@@ -1847,6 +1847,7 @@
<property name="siteService" ref="SiteService" />
<property name="documentLinkService" ref="DocumentLinkService" />
<property name="activityService" ref="activityService"/>
<property name="serviceRegistry" ref="ServiceRegistry"/>
</bean>
<bean id="webscript.org.alfresco.repository.doclink.doclinks.delete"

View File

@@ -36,6 +36,11 @@ import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import org.alfresco.repo.nodelocator.CompanyHomeNodeLocator;
import org.alfresco.repo.nodelocator.NodeLocatorService;
import org.alfresco.repo.nodelocator.SharedHomeNodeLocator;
import org.alfresco.repo.nodelocator.SitesHomeNodeLocator;
import org.alfresco.repo.nodelocator.UserHomeNodeLocator;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.ISO8601DateFormat;
import org.json.JSONObject;
@@ -151,4 +156,29 @@ public class WebScriptUtil
}
public static NodeRef resolveNodeReference(String reference, NodeLocatorService nodeLocatorService)
{
NodeRef nodeRef = null;
switch (reference)
{
case "alfresco://company/home":
nodeRef = nodeLocatorService.getNode(CompanyHomeNodeLocator.NAME, null, null);
break;
case "alfresco://user/home":
nodeRef = nodeLocatorService.getNode(UserHomeNodeLocator.NAME, null, null);
break;
case "alfresco://company/shared":
nodeRef = nodeLocatorService.getNode(SharedHomeNodeLocator.NAME, null, null);
break;
case "alfresco://sites/home":
nodeRef = nodeLocatorService.getNode(SitesHomeNodeLocator.NAME, null, null);
break;
default:
nodeRef = new NodeRef(reference);
break;
}
return nodeRef;
}
}

View File

@@ -30,9 +30,8 @@ import java.util.Map;
import java.util.StringTokenizer;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.web.scripts.links.AbstractLinksWebScript;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.activities.ActivityService;
import org.alfresco.service.cmr.links.LinkInfo;
import org.alfresco.service.cmr.repository.DocumentLinkService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
@@ -42,12 +41,9 @@ import org.alfresco.util.ParameterCheck;
import org.alfresco.util.PropertyCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONStringer;
import org.json.simple.JSONObject;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.json.JSONWriter;
/**
@@ -71,6 +67,7 @@ public abstract class AbstractDocLink extends DeclarativeWebScript
protected SiteService siteService;
protected DocumentLinkService documentLinkService;
protected ActivityService activityService;
protected ServiceRegistry serviceRegistry;
private static Log logger = LogFactory.getLog(AbstractDocLink.class);
@@ -190,4 +187,10 @@ public abstract class AbstractDocLink extends DeclarativeWebScript
{
this.activityService = activityService;
}
public void setServiceRegistry(ServiceRegistry serviceRegistry)
{
this.serviceRegistry = serviceRegistry;
}
}

View File

@@ -36,6 +36,7 @@ import org.alfresco.model.ContentModel;
import org.alfresco.repo.activities.ActivityType;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.repo.web.scripts.WebScriptUtil;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.ParameterCheck;
import org.json.simple.JSONArray;
@@ -99,7 +100,7 @@ public class DocLinkPost extends AbstractDocLink
/* Parse the destination NodeRef parameter */
String destinationNodeParam = (String) json.get(PARAM_DESTINATION_NODE);
ParameterCheck.mandatoryString("destinationNodeParam", destinationNodeParam);
destinationNodeRef = new NodeRef(destinationNodeParam);
destinationNodeRef = WebScriptUtil.resolveNodeReference(destinationNodeParam, serviceRegistry.getNodeLocatorService());
List<NodeRef> nodeRefs = new ArrayList<NodeRef>();
if (json.containsKey(PARAM_MULTIPLE_FILES))

View File

@@ -34,12 +34,14 @@ import java.util.Map;
import org.alfresco.model.ApplicationModel;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.dictionary.DictionaryModelTypeTest;
import org.alfresco.repo.node.archive.NodeArchiveService;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.site.SiteModel;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
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;
@@ -70,6 +72,10 @@ public class NodeWebScripTest extends BaseWebScriptTest
{
private static Log logger = LogFactory.getLog(NodeWebScripTest.class);
private static String CREATE_LINK_API = "/api/node/doclink/";
private static String DESTINATION_NODE_REF_PARAM = "destinationNodeRef";
private static String MULTIPLE_FILES_PARAM = "multipleFiles";
private String TEST_SITE_NAME = "TestNodeSite";
private SiteInfo TEST_SITE;
@@ -79,6 +85,7 @@ public class NodeWebScripTest extends BaseWebScriptTest
private SiteService siteService;
private NodeService nodeService;
private NodeArchiveService nodeArchiveService;
private CheckOutCheckInService checkOutCheckInService;
private static final String USER_ONE = "UserOneSecondToo";
private static final String USER_TWO = "UserTwoSecondToo";
@@ -97,6 +104,7 @@ public class NodeWebScripTest extends BaseWebScriptTest
this.siteService = (SiteService)ctx.getBean("SiteService");
this.nodeService = (NodeService)ctx.getBean("NodeService");
this.nodeArchiveService = (NodeArchiveService)ctx.getBean("nodeArchiveService");
this.checkOutCheckInService = (CheckOutCheckInService)ctx.getBean("checkOutCheckInService");
// Do the setup as admin
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
@@ -402,7 +410,7 @@ public class NodeWebScripTest extends BaseWebScriptTest
JSONArray jsonLinkNodes = null;
JSONObject jsonLinkNode = null;
//Create files in the folder
//Create files in the testFolder1
NodeRef testFile1 = createNode(testFolder1, "testingLinkCreationFile1", ContentModel.TYPE_CONTENT,
AuthenticationUtil.getAdminUserName());
NodeRef testFile2 = createNode(testFolder1, "testingLinkCreationFile2", ContentModel.TYPE_CONTENT,
@@ -410,21 +418,21 @@ public class NodeWebScripTest extends BaseWebScriptTest
NodeRef testFile3 = createNode(testFolder1, "testingLinkCreationFile3", ContentModel.TYPE_CONTENT,
AuthenticationUtil.getAdminUserName());
//Create another folder in the folder
//Create testFolder2 in the testFolder1
String testFolder2Name = "testingLinkCreationFolder2";
testFolderProps = new HashMap<QName, Serializable>();
testFolderProps.put(ContentModel.PROP_NAME, testFolder2Name);
NodeRef testFolder2 = nodeService.createNode(siteDocLib, ContentModel.ASSOC_CONTAINS,
QName.createQName("testingLinkCreationFolder2"), ContentModel.TYPE_FOLDER, testFolderProps).getChildRef();
// Create link to file1 in same folder
Request req = new Request("POST", "/api/node/doclink/" + testFile1.getStoreRef().getProtocol() + "/"
// Create link to file1 in same folder - testFolder1
Request req = new Request("POST", CREATE_LINK_API + testFile1.getStoreRef().getProtocol() + "/"
+ testFile1.getStoreRef().getIdentifier() + "/" + testFile1.getId());
jsonReq = new JSONObject();
jsonReq.put("destinationNodeRef", testFolder1.toString());
jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
jsonArray.add(testFile1.toString());
jsonReq.put("multipleFiles", jsonArray);
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
@@ -447,13 +455,13 @@ public class NodeWebScripTest extends BaseWebScriptTest
assertEquals(false, nodeService.hasAspect(testFile1, ApplicationModel.ASPECT_LINKED));
//Create link to testFolder2 in same folder (testFolder1)
req = new Request("POST", "/api/node/doclink/" + testFolder2.getStoreRef().getProtocol() + "/"
req = new Request("POST", CREATE_LINK_API + testFolder2.getStoreRef().getProtocol() + "/"
+ testFolder2.getStoreRef().getIdentifier() + "/" + testFolder2.getId());
jsonReq = new JSONObject();
jsonReq.put("destinationNodeRef", testFolder1.toString());
jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
jsonArray = new JSONArray();
jsonArray.add(testFolder2.toString());
jsonReq.put("multipleFiles", jsonArray);
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
@@ -472,13 +480,13 @@ public class NodeWebScripTest extends BaseWebScriptTest
assertEquals(true, nodeService.exists(folder2Link));
// create another link of testFolder2 in siteDocLib
req = new Request("POST", "/api/node/doclink/" + testFolder2.getStoreRef().getProtocol() + "/"
req = new Request("POST", CREATE_LINK_API + testFolder2.getStoreRef().getProtocol() + "/"
+ testFolder2.getStoreRef().getIdentifier() + "/" + testFolder2.getId());
jsonReq = new JSONObject();
jsonReq.put("destinationNodeRef", siteDocLib.toString());
jsonReq.put(DESTINATION_NODE_REF_PARAM, siteDocLib.toString());
jsonArray = new JSONArray();
jsonArray.add(testFolder2.toString());
jsonReq.put("multipleFiles", jsonArray);
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
@@ -502,15 +510,15 @@ public class NodeWebScripTest extends BaseWebScriptTest
assertEquals(false, nodeService.hasAspect(testFolder2, ApplicationModel.ASPECT_LINKED));
// Create link to testFile1, testFile2 and testFile3 in same testFolder1
req = new Request("POST", "/api/node/doclink/" + testFolder1.getStoreRef().getProtocol() + "/"
req = new Request("POST", CREATE_LINK_API + testFolder1.getStoreRef().getProtocol() + "/"
+ testFolder1.getStoreRef().getIdentifier() + "/" + testFolder1.getId());
jsonReq = new JSONObject();
jsonReq.put("destinationNodeRef", testFolder1.toString());
jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
jsonArray = new JSONArray();
jsonArray.add(testFile1.toString());
jsonArray.add(testFile2.toString());
jsonArray.add(testFile3.toString());
jsonReq.put("multipleFiles", jsonArray);
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
@@ -534,13 +542,13 @@ public class NodeWebScripTest extends BaseWebScriptTest
}
//try to create another link in the same location - an exception should be thrown
req = new Request("POST", "/api/node/doclink/" + testFolder1.getStoreRef().getProtocol() + "/"
req = new Request("POST", CREATE_LINK_API + testFolder1.getStoreRef().getProtocol() + "/"
+ testFolder1.getStoreRef().getIdentifier() + "/" + testFolder1.getId());
jsonReq = new JSONObject();
jsonReq.put("destinationNodeRef", testFolder1.toString());
jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
jsonArray = new JSONArray();
jsonArray.add(testFile1.toString());
jsonReq.put("multipleFiles", jsonArray);
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
@@ -555,17 +563,17 @@ public class NodeWebScripTest extends BaseWebScriptTest
assertEquals(false, nodeService.exists(linkNodeRef));
}
//try create a link to a site
//try create a link to a site - shouldn't be possible
SiteInfo site2 = createSite("Site2TestingNodeCreateLink");
NodeRef siteNodeRef = site2.getNodeRef();
req = new Request("POST", "/api/node/doclink/" + testFolder1.getStoreRef().getProtocol() + "/"
req = new Request("POST", CREATE_LINK_API + testFolder1.getStoreRef().getProtocol() + "/"
+ testFolder1.getStoreRef().getIdentifier() + "/" + testFolder1.getId());
jsonReq = new JSONObject();
jsonReq.put("destinationNodeRef", testFolder1.toString());
jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
jsonArray = new JSONArray();
jsonArray.add(siteNodeRef.toString());
jsonReq.put("multipleFiles", jsonArray);
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
@@ -573,6 +581,61 @@ public class NodeWebScripTest extends BaseWebScriptTest
siteService.deleteSite(site2.getShortName());
nodeArchiveService.purgeArchivedNode(nodeArchiveService.getArchivedNode(siteNodeRef));
//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());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, "alfresco://company/shared");
jsonArray = new JSONArray();
jsonArray.add(testFile4.toString());
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_OK));
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");
jsonArray = new JSONArray();
jsonArray.add(testFile4.toString());
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_OK));
//create link in Repository as Admin
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
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");
jsonArray = new JSONArray();
jsonArray.add(testFile4.toString());
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
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.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_OK));
//all links are removed with success marker aspect should be removed too
assertEquals(false, nodeService.hasAspect(testFile4, ApplicationModel.ASPECT_LINKED));
AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
}
private NodeRef createNode(NodeRef parentNode, String nodeCmName, QName nodeType, String ownerUserName)