From 98028807a9c63b8539197ce486d4e6e555478a2a Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 3 Aug 2011 14:44:19 +0000 Subject: [PATCH] ALF-9155 related refactoring git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29525 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/blog/cannedqueries/BlogEntity.java | 23 +--- .../alfresco/repo/site/SiteServiceImpl.java | 115 ++++++++++++++++++ .../service/cmr/calendar/CalendarService.java | 2 - 3 files changed, 116 insertions(+), 24 deletions(-) diff --git a/source/java/org/alfresco/repo/blog/cannedqueries/BlogEntity.java b/source/java/org/alfresco/repo/blog/cannedqueries/BlogEntity.java index 3c6f8c51c5..922d9c6de5 100644 --- a/source/java/org/alfresco/repo/blog/cannedqueries/BlogEntity.java +++ b/source/java/org/alfresco/repo/blog/cannedqueries/BlogEntity.java @@ -32,10 +32,7 @@ public class BlogEntity extends NodeBackedEntity private String postedDate; // Supplemental query-related parameters - private Long parentNodeId; - private Long nameQNameId; private Long publishedQNameId; - private Long contentTypeQNameId; private Long blogIntAspectQNameId; private Long blogIntPostedQNameId; @@ -50,11 +47,8 @@ public class BlogEntity extends NodeBackedEntity public BlogEntity(Long parentNodeId, Long nameQNameId, Long publishedQNameId, Long contentTypeQNameId, Long blogIntAspectQNameId, Long blogIntPostedQNameId) { - super(); - this.parentNodeId = parentNodeId; - this.nameQNameId = nameQNameId; + super(parentNodeId, nameQNameId, contentTypeQNameId); this.publishedQNameId = publishedQNameId; - this.contentTypeQNameId = contentTypeQNameId; this.blogIntAspectQNameId = blogIntAspectQNameId; this.blogIntPostedQNameId = blogIntPostedQNameId; @@ -84,26 +78,11 @@ public class BlogEntity extends NodeBackedEntity // Supplemental query-related parameters - public Long getParentNodeId() - { - return parentNodeId; - } - - public Long getNameQNameId() - { - return nameQNameId; - } - public Long getPublishedQNameId() { return publishedQNameId; } - public Long getContentTypeQNameId() - { - return contentTypeQNameId; - } - public Long getBlogIntAspectQNameId() { return blogIntAspectQNameId; diff --git a/source/java/org/alfresco/repo/site/SiteServiceImpl.java b/source/java/org/alfresco/repo/site/SiteServiceImpl.java index ab9911f4bf..b220d91e68 100644 --- a/source/java/org/alfresco/repo/site/SiteServiceImpl.java +++ b/source/java/org/alfresco/repo/site/SiteServiceImpl.java @@ -32,6 +32,7 @@ import java.util.StringTokenizer; import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; +import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; import org.alfresco.query.CannedQuery; import org.alfresco.query.CannedQueryFactory; @@ -77,10 +78,12 @@ import org.alfresco.service.cmr.security.NoSuchPersonException; 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; import org.alfresco.service.cmr.site.SiteVisibility; import org.alfresco.service.cmr.tagging.TaggingService; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; +import org.alfresco.service.transaction.TransactionService; import org.alfresco.util.Pair; import org.alfresco.util.PropertyCheck; import org.alfresco.util.PropertyMap; @@ -2134,6 +2137,118 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic } return fileInfo.getNodeRef(); } + + /** + * Helper method to create a container if missing, and mark it as a + * tag scope if it isn't already one + */ + public static NodeRef getSiteContainer(final String siteShortName, + final String componentName, final boolean create, + final SiteService siteService, final TransactionService transactionService, + final TaggingService taggingService) + { + // Does the site exist? + if(siteService.getSite(siteShortName) == null) { + // Either the site doesn't exist, or you're not allowed to see it + if(! create) + { + // Just say there's no container + return null; + } + else + { + // We can't create on a non-existant site + throw new AlfrescoRuntimeException( + "Unable to create the " + componentName + " container from a hidden or non-existant site" + ); + } + } + + // Check about the container + if(! siteService.hasContainer(siteShortName, componentName)) + { + if(create) + { + if(transactionService.isReadOnly()) + { + throw new AlfrescoRuntimeException( + "Unable to create the " + componentName + " container from a read only transaction" + ); + } + + // Have the site container created + if(logger.isDebugEnabled()) + { + logger.debug("Creating " + componentName + " container in site " + siteShortName); + } + + NodeRef container = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() + { + public NodeRef doWork() throws Exception + { + // Create the site container + NodeRef container = siteService.createContainer( + siteShortName, componentName, null, null + ); + + // Done + return container; + } + }, AuthenticationUtil.getSystemUserName() + ); + + if(logger.isDebugEnabled()) + { + logger.debug("Created " + componentName + " as " + container + " for " + siteShortName); + } + + // Container is setup and ready to use + return container; + } + else + { + // No container for this site, and not allowed to create + // Have the site container created + if(logger.isDebugEnabled()) + { + logger.debug("No " + componentName + " component in " + siteShortName + " and not creating"); + } + return null; + } + } + else + { + // Container is already there + final NodeRef container = siteService.getContainer(siteShortName, componentName); + + // Ensure the calendar container has the tag scope aspect applied to it + if(! taggingService.isTagScope(container)) + { + if(logger.isDebugEnabled()) + { + logger.debug("Attaching tag scope to " + componentName + " " + container.toString() + " for " + siteShortName); + } + AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() { + public Void doWork() throws Exception + { + transactionService.getRetryingTransactionHelper().doInTransaction( + new RetryingTransactionCallback() { + public Void execute() throws Throwable { + // Add the tag scope aspect + taggingService.addTagScope(container); + return null; + } + }, false, true + ); + return null; + } + }, AuthenticationUtil.getSystemUserName()); + } + + // Container is appropriately setup and configured + return container; + } + } /** * Helper method to get the activity data for a user diff --git a/source/java/org/alfresco/service/cmr/calendar/CalendarService.java b/source/java/org/alfresco/service/cmr/calendar/CalendarService.java index 4e77c5ef73..1501c540a7 100644 --- a/source/java/org/alfresco/service/cmr/calendar/CalendarService.java +++ b/source/java/org/alfresco/service/cmr/calendar/CalendarService.java @@ -27,8 +27,6 @@ import org.alfresco.service.NotAuditable; /** * The Calendar service. * - * TODO Lucene free querying - * * @author Nick Burch * @since 4.0 */