Support for sub-types of folder in site.getContainer() - to allow for specialised types of component folder and backwards compatibility with existing models such as forum.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9306 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana 2008-05-29 11:37:42 +00:00
parent e09ae51c1d
commit 14660ea397
5 changed files with 56 additions and 10 deletions

View File

@ -4,6 +4,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
/** /**
* Site service fundamental API. * Site service fundamental API.
@ -113,9 +114,10 @@ public interface SiteService
* *
* @param shortName short name of site * @param shortName short name of site
* @param componentId component id * @param componentId component id
* @return noderef of folder container * @param folderType type of folder to create (if null, creates standard folder)
* @return noderef of container
*/ */
NodeRef getContainer(String shortName, String componentId); NodeRef getContainer(String shortName, String componentId, QName folderType);
/** /**
* Determines if a "container" folder for the specified component exists. * Determines if a "container" folder for the specified component exists.

View File

@ -465,7 +465,7 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.repo.site.SiteService#getContainer(java.lang.String) * @see org.alfresco.repo.site.SiteService#getContainer(java.lang.String)
*/ */
public NodeRef getContainer(String shortName, String componentId) public NodeRef getContainer(String shortName, String componentId, QName folderType)
{ {
if (componentId == null || componentId.length() ==0) if (componentId == null || componentId.length() ==0)
{ {
@ -489,7 +489,7 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
catch(FileNotFoundException e) catch(FileNotFoundException e)
{ {
// create component folder // create component folder
FileInfo fileInfo = fileFolderService.create(siteNodeRef, componentId, ContentModel.TYPE_FOLDER); FileInfo fileInfo = fileFolderService.create(siteNodeRef, componentId, folderType == null ? ContentModel.TYPE_FOLDER : folderType);
containerNodeRef = fileInfo.getNodeRef(); containerNodeRef = fileInfo.getNodeRef();
} }

View File

@ -29,9 +29,12 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ApplicationModel;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.jscript.ClasspathScriptLocation; import org.alfresco.repo.jscript.ClasspathScriptLocation;
import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.service.cmr.repository.NodeRef; 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.ScriptLocation;
import org.alfresco.service.cmr.repository.ScriptService; import org.alfresco.service.cmr.repository.ScriptService;
import org.alfresco.util.BaseAlfrescoSpringTest; import org.alfresco.util.BaseAlfrescoSpringTest;
@ -55,6 +58,7 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest
private SiteService siteService; private SiteService siteService;
private ScriptService scriptService; private ScriptService scriptService;
private NodeService nodeService;
private AuthenticationComponent authenticationComponent; private AuthenticationComponent authenticationComponent;
/** /**
@ -67,6 +71,7 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest
// Get the required services // Get the required services
this.siteService = (SiteService)this.applicationContext.getBean("siteService"); this.siteService = (SiteService)this.applicationContext.getBean("siteService");
this.scriptService = (ScriptService)this.applicationContext.getBean("ScriptService"); this.scriptService = (ScriptService)this.applicationContext.getBean("ScriptService");
this.nodeService = (NodeService)this.applicationContext.getBean("NodeService");
this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent"); this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
// Do the test's as userOne // Do the test's as userOne
@ -342,20 +347,35 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest
boolean hasContainer = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component"); boolean hasContainer = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component");
assertFalse(hasContainer); assertFalse(hasContainer);
NodeRef container1 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component"); NodeRef container1 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component", null);
assertNotNull(container1); assertNotNull(container1);
NodeRef container2 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component"); NodeRef container2 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component", null);
assertNotNull(container2); assertNotNull(container2);
assertTrue(container1.equals(container2)); assertTrue(container1.equals(container2));
boolean hasContainer2 = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component"); boolean hasContainer2 = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component");
assertTrue(hasContainer2); assertTrue(hasContainer2);
boolean hasContainer3 = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component2"); boolean hasContainer3 = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component2");
assertFalse(hasContainer3); assertFalse(hasContainer3);
NodeRef container3 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component2"); NodeRef container3 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component2", null);
assertNotNull(container3); assertNotNull(container3);
assertFalse(container1.equals(container3)); assertFalse(container1.equals(container3));
boolean hasContainer4 = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component2"); boolean hasContainer4 = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component2");
assertTrue(hasContainer4); 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);
assertNotNull(container5);
NodeRef container6 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component3", null);
assertNotNull(container6);
assertTrue(container5.equals(container6));
assertEquals(ContentModel.TYPE_FOLDER, nodeService.getType(container6));
NodeRef container7 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component3", ApplicationModel.TYPE_PROJECTSPACE);
assertNotNull(container7);
assertTrue(container5.equals(container7));
assertEquals(ContentModel.TYPE_FOLDER, nodeService.getType(container7));
NodeRef container8 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component4", ApplicationModel.TYPE_PROJECTSPACE);
assertNotNull(container8);
assertEquals(ApplicationModel.TYPE_PROJECTSPACE, nodeService.getType(container8));
} }

View File

@ -34,6 +34,7 @@ import org.alfresco.repo.site.SiteInfo;
import org.alfresco.repo.site.SiteService; import org.alfresco.repo.site.SiteService;
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.Scriptable;
/** /**
@ -261,15 +262,31 @@ public class Site implements Serializable
/** /**
* Gets (or creates) the "container" folder for the specified component id * Gets (or creates) the "container" folder for the specified component id
* *
* NOTE: The container is of type cm:folder.
*
* @param componentId * @param componentId
* @return node representing the "container" folder * @return node representing the "container" folder
*/ */
public ScriptNode getContainer(String componentId) 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)
{ {
ScriptNode container = null; ScriptNode container = null;
try try
{ {
NodeRef containerNodeRef = this.siteService.getContainer(getShortName(), componentId); 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); container = new ScriptNode(containerNodeRef, this.serviceRegistry, this.scope);
} }
catch(AlfrescoRuntimeException e) catch(AlfrescoRuntimeException e)

View File

@ -93,6 +93,13 @@ function testContainer()
var container2 = site.getContainer("folder.component"); var container2 = site.getContainer("folder.component");
test.assertNotNull(container2); test.assertNotNull(container2);
test.assertEquals(container, container2); test.assertEquals(container, container2);
var container3 = site.getContainer("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", "app:projectfolder");
test.assertNotNull(container4);
test.assertEquals("{http://www.alfresco.org/model/application/1.0}projectfolder", container4.type);
} }