listMembers(String shortName, String nameFilter, String roleFilter);
/**
+ * Gets the role of the specified user
*
- * @param shortName
- * @param userName
- * @return
+ * @param shortName site short name
+ * @param userName user name
+ * @return String site role, null if none
*/
String getMembersRole(String shortName, String userName);
/**
+ * Inidiactes whether a user is a member of a site or not
*
- * @param shortName
- * @param userName
- * @return
+ * @param shortName site short name
+ * @param userName user name
+ * @return boolean true if the user is a member of the site, false otherwise
*/
boolean isMember(String shortName, String userName);
/**
+ * Sets the role of a user withint a site
*
- * @param shortName
- * @param userName
- * @param role
+ * @param shortName site short name
+ * @param userName user name
+ * @param role site role
*/
void setMembership(String shortName, String userName, String role);
/**
+ * Clears a users role within a site
*
- * @param shortName
- * @param userName
+ * @param shortName site short name
+ * @param userName user name
*/
void removeMembership(String shortName, String userName);
+ /**
+ * Creates a container for a component is a site of the given container type (must be a sub-type of st:siteContainer)
+ *
+ * If no container type is specified then a node of type st:siteContainer is created.
+ *
+ * The map of container properties are set on the created container node. Null can be provided when no properties
+ * need to be set.
+ *
+ * @param shortName site short name
+ * @param componentId component id
+ * @param containerType container type to create (can be null)
+ * @param containerProperties container property values (can be null)
+ * @return
+ */
+ NodeRef createContainer(String shortName, String componentId, QName containerType, Map containerProperties);
/**
- * Gets (or creates, if it doesn't exist) the "container" folder for the specified
+ * Gets the "container" folder for the specified
* component.
*
* @param shortName short name of site
@@ -116,7 +135,7 @@ public interface SiteService
* @param folderType type of folder to create (if null, creates standard folder)
* @return noderef of container
*/
- NodeRef getContainer(String shortName, String componentId, QName folderType);
+ NodeRef getContainer(String shortName, String componentId);
/**
* Determines if a "container" folder for the specified component exists.
diff --git a/source/java/org/alfresco/repo/site/SiteServiceImpl.java b/source/java/org/alfresco/repo/site/SiteServiceImpl.java
index b676894829..97f511b6f6 100644
--- a/source/java/org/alfresco/repo/site/SiteServiceImpl.java
+++ b/source/java/org/alfresco/repo/site/SiteServiceImpl.java
@@ -35,7 +35,6 @@ import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.activities.ActivityType;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
-import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.cmr.activities.ActivityService;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
@@ -50,10 +49,10 @@ import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
+import org.alfresco.service.cmr.tagging.TaggingService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
-import org.alfresco.util.ISO9075;
import org.alfresco.util.PropertyMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -84,6 +83,7 @@ public class SiteServiceImpl implements SiteService, SiteModel
private ActivityService activityService;
private PersonService personService;
private AuthenticationComponent authenticationComponent;
+ private TaggingService taggingService;
/**
* Set node service
@@ -155,6 +155,16 @@ public class SiteServiceImpl implements SiteService, SiteModel
this.authenticationComponent = authenticationComponent;
}
+ /**
+ * Set the taggin service
+ *
+ * @param taggingService tagging service
+ */
+ public void setTaggingService(TaggingService taggingService)
+ {
+ this.taggingService = taggingService;
+ }
+
/**
* @see org.alfresco.repo.site.SiteService#createSite(java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean)
*/
@@ -178,6 +188,9 @@ public class SiteServiceImpl implements SiteService, SiteModel
SiteModel.TYPE_SITE,
properties).getChildRef();
+ // Make the new site a tag scope
+ this.taggingService.addTagScope(siteNodeRef);
+
// Set the memberhips details
// - give all authorities read permissions if site is public
// - give all authorities read permission on permissions so memberships can be calculated
@@ -191,7 +204,7 @@ public class SiteServiceImpl implements SiteService, SiteModel
this.permissionService.setPermission(siteNodeRef, authenticationComponent.getCurrentUserName(), SiteModel.SITE_MANAGER, true);
// Return created site information
- SiteInfo siteInfo = new SiteInfo(sitePreset, shortName, title, description, isPublic);
+ SiteInfo siteInfo = new SiteInfo(sitePreset, shortName, title, description, isPublic, siteNodeRef);
return siteInfo;
}
@@ -259,7 +272,7 @@ public class SiteServiceImpl implements SiteService, SiteModel
boolean isPublic = isSitePublic(siteNodeRef);
// Create and return the site information
- SiteInfo siteInfo = new SiteInfo(sitePreset, shortName, title, description, isPublic);
+ SiteInfo siteInfo = new SiteInfo(sitePreset, shortName, title, description, isPublic, siteNodeRef);
return siteInfo;
}
@@ -298,11 +311,16 @@ public class SiteServiceImpl implements SiteService, SiteModel
return result;
}
+ /**
+ * Gets the site's node reference based on its short name
+ *
+ * @param shortName short name
+ * @return NodeRef node reference
+ */
private NodeRef getSiteNodeRef(String shortName)
{
NodeRef result = null;
-
- //String query = "PATH:\"cm:sites/cm:" + ISO9075.encode(shortName) + "\"";
+
String query = "+TYPE:\"st:site\" +@cm\\:name:\"" + shortName + "\"";
ResultSet resultSet = this.searchService.query(SITE_STORE, SearchService.LANGUAGE_LUCENE, query);
if (resultSet.length() == 1)
@@ -312,6 +330,9 @@ public class SiteServiceImpl implements SiteService, SiteModel
return result;
}
+ /**
+ * @see org.alfresco.repo.site.SiteService#updateSite(org.alfresco.repo.site.SiteInfo)
+ */
public void updateSite(SiteInfo siteInfo)
{
NodeRef siteNodeRef = getSiteNodeRef(siteInfo.getShortName());
@@ -500,10 +521,72 @@ public class SiteServiceImpl implements SiteService, SiteModel
}
}
- /* (non-Javadoc)
+ /**
+ * @see org.alfresco.repo.site.SiteService#createContainer(java.lang.String, java.lang.String, org.alfresco.service.namespace.QName, java.util.Map)
+ */
+ public NodeRef createContainer(String shortName, String componentId, QName containerType, Map containerProperties)
+ {
+ // Check for the component id
+ if (componentId == null || componentId.length() ==0)
+ {
+ throw new AlfrescoRuntimeException("Component id not provided");
+ }
+
+ // retrieve site
+ NodeRef siteNodeRef = getSiteNodeRef(shortName);
+ if (siteNodeRef == null)
+ {
+ throw new AlfrescoRuntimeException("Site " + shortName + " does not exist.");
+ }
+
+ // retrieve component folder within site
+ NodeRef containerNodeRef = null;
+ try
+ {
+ containerNodeRef = findContainer(siteNodeRef, componentId);
+ }
+ catch(FileNotFoundException e)
+ {
+ }
+
+ // create the container node reference
+ if (containerNodeRef == null)
+ {
+ if (containerType == null)
+ {
+ containerType = ContentModel.TYPE_FOLDER;
+ }
+
+ // create component folder
+ FileInfo fileInfo = fileFolderService.create(siteNodeRef, componentId, containerType);
+
+ // Get the created container
+ containerNodeRef = fileInfo.getNodeRef();
+
+ // Set the properties if they have been provided
+ if (containerProperties != null)
+ {
+ Map props = this.nodeService.getProperties(containerNodeRef);
+ props.putAll(containerProperties);
+ this.nodeService.setProperties(containerNodeRef, props);
+ }
+
+ // Add the container aspect
+ Map aspectProps = new HashMap(1);
+ aspectProps.put(SiteModel.PROP_COMPONENT_ID, componentId);
+ this.nodeService.addAspect(containerNodeRef, ASPECT_SITE_CONTAINER, aspectProps);
+
+ // Make the container a tag scope
+ this.taggingService.addTagScope(containerNodeRef);
+ }
+
+ return containerNodeRef;
+ }
+
+ /**
* @see org.alfresco.repo.site.SiteService#getContainer(java.lang.String)
*/
- public NodeRef getContainer(String shortName, String componentId, QName folderType)
+ public NodeRef getContainer(String shortName, String componentId)
{
if (componentId == null || componentId.length() ==0)
{
@@ -525,16 +608,13 @@ public class SiteServiceImpl implements SiteService, SiteModel
containerNodeRef = findContainer(siteNodeRef, componentId);
}
catch(FileNotFoundException e)
- {
- // create component folder
- FileInfo fileInfo = fileFolderService.create(siteNodeRef, componentId, folderType == null ? ContentModel.TYPE_FOLDER : folderType);
- containerNodeRef = fileInfo.getNodeRef();
+ {
}
return containerNodeRef;
}
- /* (non-Javadoc)
+ /**
* @see org.alfresco.repo.site.SiteService#hasContainer(java.lang.String)
*/
public boolean hasContainer(String shortName, String componentId)
diff --git a/source/java/org/alfresco/repo/site/SiteServiceImplTest.java b/source/java/org/alfresco/repo/site/SiteServiceImplTest.java
index fc7c64591f..1d60940a52 100644
--- a/source/java/org/alfresco/repo/site/SiteServiceImplTest.java
+++ b/source/java/org/alfresco/repo/site/SiteServiceImplTest.java
@@ -29,14 +29,15 @@ import java.util.List;
import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.model.ForumModel;
import org.alfresco.model.ContentModel;
+import org.alfresco.model.ForumModel;
import org.alfresco.repo.jscript.ClasspathScriptLocation;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.ScriptLocation;
import org.alfresco.service.cmr.repository.ScriptService;
+import org.alfresco.service.cmr.tagging.TaggingService;
import org.alfresco.util.BaseAlfrescoSpringTest;
import org.alfresco.util.TestWithUserUtils;
@@ -60,6 +61,7 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest
private ScriptService scriptService;
private NodeService nodeService;
private AuthenticationComponent authenticationComponent;
+ private TaggingService taggingService;
/**
* Called during the transaction setup
@@ -73,6 +75,7 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest
this.scriptService = (ScriptService)this.applicationContext.getBean("ScriptService");
this.nodeService = (NodeService)this.applicationContext.getBean("NodeService");
this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
+ this.taggingService = (TaggingService)this.applicationContext.getBean("TaggingService");
// Do the test's as userOne
TestWithUserUtils.authenticateUser(USER_ONE, "PWD", this.authenticationService, this.authenticationComponent);
@@ -96,6 +99,10 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest
assertEquals(expectedTitle, siteInfo.getTitle());
assertEquals(expectedDescription, siteInfo.getDescription());
assertEquals(expectedIsPublic, siteInfo.getIsPublic());
+ assertNotNull(siteInfo.getNodeRef());
+
+ // Check that the site is a tag scope
+ assertTrue(this.taggingService.isTagScope(siteInfo.getNodeRef()));
}
public void testListSites() throws Exception
@@ -347,33 +354,50 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest
boolean hasContainer = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component");
assertFalse(hasContainer);
- NodeRef container1 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component", null);
- assertNotNull(container1);
- NodeRef container2 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component", null);
+ NodeRef container1 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component");
+ assertNull(container1);
+ container1 = this.siteService.createContainer(siteInfo.getShortName(), "folder.component", null, null);
+ assertTrue(this.taggingService.isTagScope(container1));
+ NodeRef container2 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component");
assertNotNull(container2);
+ assertTrue(this.taggingService.isTagScope(container2));
assertTrue(container1.equals(container2));
boolean hasContainer2 = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component");
assertTrue(hasContainer2);
boolean hasContainer3 = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component2");
assertFalse(hasContainer3);
- NodeRef container3 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component2", null);
+
+ NodeRef container3 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component2");
+ assertNull(container3);
+ container3 = this.siteService.createContainer(siteInfo.getShortName(), "folder.component2", null, null);
assertNotNull(container3);
+ assertTrue(this.taggingService.isTagScope(container3));
assertFalse(container1.equals(container3));
+
boolean hasContainer4 = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component2");
assertTrue(hasContainer4);
boolean hasContainer5 = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component3");
assertFalse(hasContainer5);
- NodeRef container5 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component3", ContentModel.TYPE_FOLDER);
+ NodeRef container5 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component3");
+ assertNull(container5);
+ container5 = this.siteService.createContainer(siteInfo.getShortName(), "folder.component3", ContentModel.TYPE_FOLDER, null);
assertNotNull(container5);
- NodeRef container6 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component3", null);
+
+ NodeRef container6 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component3");
+ assertNotNull(container6);
+ container6 = this.siteService.createContainer(siteInfo.getShortName(), "folder.component3", null, null);
assertNotNull(container6);
assertTrue(container5.equals(container6));
assertEquals(ContentModel.TYPE_FOLDER, nodeService.getType(container6));
- NodeRef container7 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component3", ForumModel.TYPE_FORUM);
+ NodeRef container7 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component3");
+ assertNotNull(container7);
+ container7 = this.siteService.createContainer(siteInfo.getShortName(), "folder.component3", ForumModel.TYPE_FORUM, null);
assertNotNull(container7);
assertTrue(container5.equals(container7));
assertEquals(ContentModel.TYPE_FOLDER, nodeService.getType(container7));
- NodeRef container8 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component4", ForumModel.TYPE_FORUM);
+ NodeRef container8 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component4");
+ assertNull(container8);
+ container8 = this.siteService.createContainer(siteInfo.getShortName(), "folder.component4", ForumModel.TYPE_FORUM, null);
assertNotNull(container8);
assertEquals(ForumModel.TYPE_FORUM, nodeService.getType(container8));
}
diff --git a/source/java/org/alfresco/repo/site/script/Site.java b/source/java/org/alfresco/repo/site/script/Site.java
index a61f890679..1fa789107f 100644
--- a/source/java/org/alfresco/repo/site/script/Site.java
+++ b/source/java/org/alfresco/repo/site/script/Site.java
@@ -43,9 +43,7 @@ import org.mozilla.javascript.Scriptable;
* @author Roy Wetherall
*/
public class Site implements Serializable
-{
- // TODO: DC - Should Site derive from ScriptNode?
-
+{
/** Serializable serial verion UID */
private static final long serialVersionUID = 8013569574120957923L;
@@ -160,6 +158,22 @@ public class Site implements Serializable
this.siteInfo.setIsPublic(isPublic);
}
+ /**
+ * Get the site node, null if none
+ *
+ * @return ScriptNode site node
+ */
+ public ScriptNode getNode()
+ {
+ ScriptNode node = null;
+ if (this.siteInfo.getNodeRef() != null)
+ {
+ node = new ScriptNode(this.siteInfo.getNodeRef(), this.serviceRegistry, this.scope);
+ }
+
+ return node;
+ }
+
/**
* Saves any outstanding updates to the site details.
*
@@ -262,32 +276,20 @@ public class Site implements Serializable
/**
* Gets (or creates) the "container" folder for the specified component id
*
- * NOTE: The container is of type cm:folder.
- *
* @param componentId
- * @return node representing the "container" folder
- */
- public ScriptNode getContainer(String componentId)
- {
- return getContainer(componentId, null);
- }
-
- /**
- * Gets (or creates) the "container" folder for the specified component id
- *
- * @param componentId
- * @param folderType type of folder to create (if null, creates a standard folder)
* @return node representing the "container" folder (or null, if for some reason
* the container can not be created)
*/
- public ScriptNode getContainer(String componentId, String folderType)
+ public ScriptNode getContainer(String componentId)
{
ScriptNode container = null;
try
{
- QName folderQName = (folderType == null) ? null : QName.createQName(folderType, serviceRegistry.getNamespaceService());
- NodeRef containerNodeRef = this.siteService.getContainer(getShortName(), componentId, folderQName);
- container = new ScriptNode(containerNodeRef, this.serviceRegistry, this.scope);
+ NodeRef containerNodeRef = this.siteService.getContainer(getShortName(), componentId);
+ if (containerNodeRef != null)
+ {
+ container = new ScriptNode(containerNodeRef, this.serviceRegistry, this.scope);
+ }
}
catch(AlfrescoRuntimeException e)
{
@@ -296,7 +298,42 @@ public class Site implements Serializable
}
return container;
}
+
+ /**
+ * Creates a new site container
+ *
+ * @param componentId component id
+ * @return ScriptNode the created container
+ */
+ public ScriptNode createContainer(String componentId)
+ {
+ return createContainer(componentId, null);
+ }
+ /**
+ * Creates a new site container
+ *
+ * @param componentId component id
+ * @param folderType folder type to create
+ * @return ScriptNode the created container
+ */
+ public ScriptNode createContainer(String componentId, String folderType)
+ {
+ ScriptNode container = null;
+ try
+ {
+ QName folderQName = (folderType == null) ? null : QName.createQName(folderType, serviceRegistry.getNamespaceService());
+ NodeRef containerNodeRef = this.siteService.createContainer(getShortName(), componentId, folderQName, null);
+ container = new ScriptNode(containerNodeRef, this.serviceRegistry, this.scope);
+ }
+ catch(AlfrescoRuntimeException e)
+ {
+ // NOTE: not good practice to catch all, but in general we're not throwing exceptions
+ // into the script layer
+ }
+ return container;
+ }
+
/**
* Determine if the "container" folder for the specified component exists
*
diff --git a/source/java/org/alfresco/repo/site/script/test_siteService.js b/source/java/org/alfresco/repo/site/script/test_siteService.js
index 22fc483fc5..64fa4d9127 100644
--- a/source/java/org/alfresco/repo/site/script/test_siteService.js
+++ b/source/java/org/alfresco/repo/site/script/test_siteService.js
@@ -6,6 +6,8 @@ function checkSite(site, sitePreset, shortName, title, description, isPublic)
test.assertEquals(title, site.title);
test.assertEquals(description, site.description);
test.assertEquals(isPublic, site.isPublic);
+ test.assertNotNull(site.node);
+ test.assertTrue(site.node.isTagScope);
}
function testCRUD()
@@ -87,17 +89,25 @@ function testContainer()
test.assertFalse(hasContainer);
var container = site.getContainer("folder.component");
+ test.assertNull(container);
+ container = site.createContainer("folder.component");
test.assertNotNull(container);
+
var hasContainer2 = site.hasContainer("folder.component");
test.assertTrue(hasContainer2);
+
var container2 = site.getContainer("folder.component");
test.assertNotNull(container2);
test.assertEquals(container, container2);
- var container3 = site.getContainer("folder.component2", "cm:folder");
- test.assertNotNull(container3);
+ var container3 = site.getContainer("folder.component2");
+ test.assertNull(container3);
+ container3 = site.createContainer("folder.component2", "cm:folder");
+ test.assertNotNull(container3)
test.assertEquals("{http://www.alfresco.org/model/content/1.0}folder", container3.type);
- var container4 = site.getContainer("folder.component3", "fm:forum");
+ var container4 = site.getContainer("folder.component3");
+ test.assertNull(container4);
+ container4 = site.createContainer("folder.component3", "fm:forum");
test.assertNotNull(container4);
test.assertEquals("{http://www.alfresco.org/model/forum/1.0}forum", container4.type);
}
diff --git a/source/java/org/alfresco/repo/tagging/TagScopeImpl.java b/source/java/org/alfresco/repo/tagging/TagScopeImpl.java
index dc0c7d716d..e5c32b7128 100644
--- a/source/java/org/alfresco/repo/tagging/TagScopeImpl.java
+++ b/source/java/org/alfresco/repo/tagging/TagScopeImpl.java
@@ -79,6 +79,10 @@ public class TagScopeImpl implements TagScope
*/
public List getTags(int topN)
{
+ if (this.tagDetails.size() < topN)
+ {
+ topN = this.tagDetails.size();
+ }
return this.tagDetails.subList(0, topN);
}