mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Switch the Links creating webscript to be Java backed using the new service, and enhance unit tests
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30108 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -40,6 +40,8 @@ import org.alfresco.repo.site.SiteServiceImpl;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.links.LinkInfo;
|
||||
import org.alfresco.service.cmr.links.LinksService;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
@@ -79,6 +81,7 @@ public class LinksServiceImpl implements LinksService
|
||||
private NodeService nodeService;
|
||||
private SiteService siteService;
|
||||
private SearchService searchService;
|
||||
private ContentService contentService;
|
||||
private TaggingService taggingService;
|
||||
private NamespaceService namespaceService;
|
||||
private DictionaryService dictionaryService;
|
||||
@@ -105,6 +108,11 @@ public class LinksServiceImpl implements LinksService
|
||||
this.searchService = searchService;
|
||||
}
|
||||
|
||||
public void setContentService(ContentService contentService)
|
||||
{
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
public void setTaggingService(TaggingService taggingService)
|
||||
{
|
||||
this.taggingService = taggingService;
|
||||
@@ -232,6 +240,11 @@ public class LinksServiceImpl implements LinksService
|
||||
props
|
||||
).getChildRef();
|
||||
|
||||
// Duplicate the url into the node as the content property
|
||||
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||
writer.setEncoding("UTF-8");
|
||||
writer.putContent(url);
|
||||
|
||||
// Generate the wrapping object for it
|
||||
// Build it that way, so creator and created date come through
|
||||
return buildLink(nodeRef, container, name);
|
||||
@@ -270,6 +283,11 @@ public class LinksServiceImpl implements LinksService
|
||||
}
|
||||
}
|
||||
|
||||
// Duplicate the url into the node as the content property
|
||||
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||
writer.setEncoding("UTF-8");
|
||||
writer.putContent(link.getURL());
|
||||
|
||||
// Now do the tags
|
||||
taggingService.setTags(nodeRef, link.getTags());
|
||||
|
||||
|
@@ -37,6 +37,7 @@ import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.links.LinkInfo;
|
||||
import org.alfresco.service.cmr.links.LinksService;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||
@@ -78,6 +79,7 @@ public class LinksServiceImplTest
|
||||
private static RetryingTransactionHelper TRANSACTION_HELPER;
|
||||
private static PermissionService PERMISSION_SERVICE;
|
||||
private static SiteService SITE_SERVICE;
|
||||
private static ContentService CONTENT_SERVICE;
|
||||
private static TaggingService TAGGING_SERVICE;
|
||||
|
||||
private static final String TEST_USER = LinksServiceImplTest.class.getSimpleName() + "_testuser";
|
||||
@@ -106,6 +108,7 @@ public class LinksServiceImplTest
|
||||
TRANSACTION_HELPER = (RetryingTransactionHelper)testContext.getBean("retryingTransactionHelper");
|
||||
PERMISSION_SERVICE = (PermissionService)testContext.getBean("permissionService");
|
||||
SITE_SERVICE = (SiteService)testContext.getBean("siteService");
|
||||
CONTENT_SERVICE = (ContentService)testContext.getBean("ContentService");
|
||||
TAGGING_SERVICE = (TaggingService)testContext.getBean("TaggingService");
|
||||
|
||||
// Do the setup as admin
|
||||
@@ -197,6 +200,14 @@ public class LinksServiceImplTest
|
||||
assertEquals(0, link.getTags().size());
|
||||
|
||||
|
||||
// Check the underlying node
|
||||
assertEquals("Title", NODE_SERVICE.getProperty(link.getNodeRef(), LinksModel.PROP_TITLE));
|
||||
assertEquals("Description", NODE_SERVICE.getProperty(link.getNodeRef(), LinksModel.PROP_DESCRIPTION));
|
||||
assertEquals("http://www.alfresco.com/", NODE_SERVICE.getProperty(link.getNodeRef(), LinksModel.PROP_URL));
|
||||
assertEquals("http://www.alfresco.com/", CONTENT_SERVICE.getReader(link.getNodeRef(), ContentModel.PROP_CONTENT).getContentString());
|
||||
assertEquals(false, NODE_SERVICE.hasAspect(link.getNodeRef(), LinksModel.ASPECT_INTERNAL_LINK));
|
||||
|
||||
|
||||
// Change it
|
||||
link.setTitle("New Title");
|
||||
link.setURL("http://share.alfresco.com/");
|
||||
@@ -215,6 +226,14 @@ public class LinksServiceImplTest
|
||||
assertEquals(0, link.getTags().size());
|
||||
|
||||
|
||||
// Check the underlying node now
|
||||
assertEquals("New Title", NODE_SERVICE.getProperty(link.getNodeRef(), LinksModel.PROP_TITLE));
|
||||
assertEquals("Description", NODE_SERVICE.getProperty(link.getNodeRef(), LinksModel.PROP_DESCRIPTION));
|
||||
assertEquals("http://share.alfresco.com/", NODE_SERVICE.getProperty(link.getNodeRef(), LinksModel.PROP_URL));
|
||||
assertEquals("http://share.alfresco.com/", CONTENT_SERVICE.getReader(link.getNodeRef(), ContentModel.PROP_CONTENT).getContentString());
|
||||
assertEquals(true, NODE_SERVICE.hasAspect(link.getNodeRef(), LinksModel.ASPECT_INTERNAL_LINK));
|
||||
|
||||
|
||||
// Delete it
|
||||
LINKS_SERVICE.deleteLink(link);
|
||||
|
||||
|
Reference in New Issue
Block a user