mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Implementation of site getContainer(), hasContainer()
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9267 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
<bean id="siteService" class="org.alfresco.repo.site.SiteServiceImpl">
|
<bean id="siteService" class="org.alfresco.repo.site.SiteServiceImpl">
|
||||||
<property name="nodeService" ref="NodeService"/>
|
<property name="nodeService" ref="NodeService"/>
|
||||||
|
<property name="fileFolderService" ref="FileFolderService"/>
|
||||||
<property name="searchService" ref="SearchService"/>
|
<property name="searchService" ref="SearchService"/>
|
||||||
<property name="permissionService" ref="PermissionService" />
|
<property name="permissionService" ref="PermissionService" />
|
||||||
<property name="authenticationComponent" ref="authenticationComponent"/>
|
<property name="authenticationComponent" ref="authenticationComponent"/>
|
||||||
@@ -30,6 +31,7 @@
|
|||||||
<property name="extensionName">
|
<property name="extensionName">
|
||||||
<value>siteService</value>
|
<value>siteService</value>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="serviceRegistry" ref="ServiceRegistry"/>
|
||||||
<property name="siteService" ref="siteService"/>
|
<property name="siteService" ref="siteService"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
@@ -3,6 +3,8 @@ package org.alfresco.repo.site;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Site service fundamental API.
|
* Site service fundamental API.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -105,6 +107,23 @@ public interface SiteService
|
|||||||
void removeMembership(String shortName, String userName);
|
void removeMembership(String shortName, String userName);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets (or creates, if it doesn't exist) the "container" folder for the specified
|
||||||
|
* component.
|
||||||
|
*
|
||||||
|
* @param shortName short name of site
|
||||||
|
* @param componentId component id
|
||||||
|
* @return noderef of folder container
|
||||||
|
*/
|
||||||
|
NodeRef getContainer(String shortName, String componentId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if a "container" folder for the specified component exists.
|
||||||
|
*
|
||||||
|
* @param shortName short name of site
|
||||||
|
* @param componentId component id
|
||||||
|
* @return true => "container" folder exists for component
|
||||||
|
*/
|
||||||
|
boolean hasContainer(String shortName, String componentId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -37,6 +37,9 @@ import org.alfresco.repo.activities.ActivityType;
|
|||||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||||
import org.alfresco.service.cmr.activities.ActivityService;
|
import org.alfresco.service.cmr.activities.ActivityService;
|
||||||
|
import org.alfresco.service.cmr.model.FileFolderService;
|
||||||
|
import org.alfresco.service.cmr.model.FileInfo;
|
||||||
|
import org.alfresco.service.cmr.model.FileNotFoundException;
|
||||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
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.NodeService;
|
||||||
@@ -74,6 +77,7 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
|
|||||||
private static final String ACTIVITY_TOOL = "siteService";
|
private static final String ACTIVITY_TOOL = "siteService";
|
||||||
|
|
||||||
private NodeService nodeService;
|
private NodeService nodeService;
|
||||||
|
private FileFolderService fileFolderService;
|
||||||
private SearchService searchService;
|
private SearchService searchService;
|
||||||
private PermissionService permissionService;
|
private PermissionService permissionService;
|
||||||
private ActivityService activityService;
|
private ActivityService activityService;
|
||||||
@@ -86,6 +90,11 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
|
|||||||
this.nodeService = nodeService;
|
this.nodeService = nodeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFileFolderService(FileFolderService fileFolderService)
|
||||||
|
{
|
||||||
|
this.fileFolderService = fileFolderService;
|
||||||
|
}
|
||||||
|
|
||||||
public void setSearchService(SearchService searchService)
|
public void setSearchService(SearchService searchService)
|
||||||
{
|
{
|
||||||
this.searchService = searchService;
|
this.searchService = searchService;
|
||||||
@@ -453,6 +462,93 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.alfresco.repo.site.SiteService#getContainer(java.lang.String)
|
||||||
|
*/
|
||||||
|
public NodeRef getContainer(String shortName, String componentId)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
// NOTE: component id is used for folder name
|
||||||
|
NodeRef containerNodeRef = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
containerNodeRef = findContainer(siteNodeRef, componentId);
|
||||||
|
}
|
||||||
|
catch(FileNotFoundException e)
|
||||||
|
{
|
||||||
|
// create component folder
|
||||||
|
FileInfo fileInfo = fileFolderService.create(siteNodeRef, componentId, ContentModel.TYPE_FOLDER);
|
||||||
|
containerNodeRef = fileInfo.getNodeRef();
|
||||||
|
}
|
||||||
|
|
||||||
|
return containerNodeRef;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.alfresco.repo.site.SiteService#hasContainer(java.lang.String)
|
||||||
|
*/
|
||||||
|
public boolean hasContainer(String shortName, String componentId)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
// NOTE: component id is used for folder name
|
||||||
|
boolean hasContainer = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
findContainer(siteNodeRef, componentId);
|
||||||
|
hasContainer = true;
|
||||||
|
}
|
||||||
|
catch(FileNotFoundException e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locate site "container" folder for component
|
||||||
|
*
|
||||||
|
* @param siteNodeRef site
|
||||||
|
* @param componentId component id
|
||||||
|
* @return "container" node ref, if it exists
|
||||||
|
* @throws FileNotFoundException
|
||||||
|
*/
|
||||||
|
private NodeRef findContainer(NodeRef siteNodeRef, String componentId)
|
||||||
|
throws FileNotFoundException
|
||||||
|
{
|
||||||
|
List<String> paths = new ArrayList<String>(1);
|
||||||
|
paths.add(componentId);
|
||||||
|
FileInfo fileInfo = fileFolderService.resolveNamePath(siteNodeRef, paths);
|
||||||
|
if (!fileInfo.isFolder())
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Site container " + fileInfo.getName() + " does not refer to a folder ");
|
||||||
|
}
|
||||||
|
return fileInfo.getNodeRef();
|
||||||
|
}
|
||||||
|
|
||||||
private String getActivityData(String userName, String role)
|
private String getActivityData(String userName, String role)
|
||||||
{
|
{
|
||||||
String memberFN = "";
|
String memberFN = "";
|
||||||
|
@@ -31,6 +31,7 @@ import java.util.Map;
|
|||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
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.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;
|
||||||
@@ -334,6 +335,30 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
// TODO .. try and remove the only site manager and should get a failure
|
// TODO .. try and remove the only site manager and should get a failure
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testContainer()
|
||||||
|
{
|
||||||
|
// Create a couple of sites as user one
|
||||||
|
SiteInfo siteInfo = this.siteService.createSite(TEST_SITE_PRESET, "testContainer", TEST_TITLE, TEST_DESCRIPTION, true);
|
||||||
|
|
||||||
|
boolean hasContainer = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component");
|
||||||
|
assertFalse(hasContainer);
|
||||||
|
NodeRef container1 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component");
|
||||||
|
assertNotNull(container1);
|
||||||
|
NodeRef container2 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component");
|
||||||
|
assertNotNull(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");
|
||||||
|
assertNotNull(container3);
|
||||||
|
assertFalse(container1.equals(container3));
|
||||||
|
boolean hasContainer4 = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component2");
|
||||||
|
assertTrue(hasContainer4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// == Test the JavaScript API ==
|
// == Test the JavaScript API ==
|
||||||
|
|
||||||
public void testJSAPI() throws Exception
|
public void testJSAPI() throws Exception
|
||||||
|
@@ -28,9 +28,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
|
import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
|
||||||
import org.alfresco.repo.jscript.ScriptableHashMap;
|
|
||||||
import org.alfresco.repo.site.SiteInfo;
|
import org.alfresco.repo.site.SiteInfo;
|
||||||
import org.alfresco.repo.site.SiteService;
|
import org.alfresco.repo.site.SiteService;
|
||||||
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,9 +40,22 @@ import org.alfresco.repo.site.SiteService;
|
|||||||
*/
|
*/
|
||||||
public class ScriptSiteService extends BaseScopableProcessorExtension
|
public class ScriptSiteService extends BaseScopableProcessorExtension
|
||||||
{
|
{
|
||||||
|
/** Service Registry */
|
||||||
|
private ServiceRegistry serviceRegistry;
|
||||||
|
|
||||||
/** The site service */
|
/** The site service */
|
||||||
private SiteService siteService;
|
private SiteService siteService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Service Registry
|
||||||
|
*
|
||||||
|
* @param serviceRegistry
|
||||||
|
*/
|
||||||
|
public void setServiceRegistry(ServiceRegistry serviceRegistry)
|
||||||
|
{
|
||||||
|
this.serviceRegistry = serviceRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the site service
|
* Set the site service
|
||||||
*
|
*
|
||||||
@@ -61,14 +74,14 @@ public class ScriptSiteService extends BaseScopableProcessorExtension
|
|||||||
* @param sitePreset site preset
|
* @param sitePreset site preset
|
||||||
* @param shortName site short name
|
* @param shortName site short name
|
||||||
* @param title site title
|
* @param title site title
|
||||||
* @param descripion site description
|
* @param description site description
|
||||||
* @param isPublic whether the site is public or not
|
* @param isPublic whether the site is public or not
|
||||||
* @return Site the created site
|
* @return Site the created site
|
||||||
*/
|
*/
|
||||||
public Site createSite(String sitePreset, String shortName, String title, String descripion, boolean isPublic)
|
public Site createSite(String sitePreset, String shortName, String title, String description, boolean isPublic)
|
||||||
{
|
{
|
||||||
SiteInfo siteInfo = this.siteService.createSite(sitePreset, shortName, title, descripion, isPublic);
|
SiteInfo siteInfo = this.siteService.createSite(sitePreset, shortName, title, description, isPublic);
|
||||||
return new Site(this.siteService, siteInfo);
|
return new Site(siteInfo, this.serviceRegistry, this.siteService, getScope());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,7 +100,7 @@ public class ScriptSiteService extends BaseScopableProcessorExtension
|
|||||||
List<Site> sites = new ArrayList<Site>(siteInfos.size());
|
List<Site> sites = new ArrayList<Site>(siteInfos.size());
|
||||||
for (SiteInfo siteInfo : siteInfos)
|
for (SiteInfo siteInfo : siteInfos)
|
||||||
{
|
{
|
||||||
sites.add(new Site(this.siteService, siteInfo));
|
sites.add(new Site(siteInfo, this.serviceRegistry, this.siteService, getScope()));
|
||||||
}
|
}
|
||||||
return (Site[])sites.toArray(new Site[sites.size()]);
|
return (Site[])sites.toArray(new Site[sites.size()]);
|
||||||
}
|
}
|
||||||
@@ -106,7 +119,7 @@ public class ScriptSiteService extends BaseScopableProcessorExtension
|
|||||||
SiteInfo siteInfo = this.siteService.getSite(shortName);
|
SiteInfo siteInfo = this.siteService.getSite(shortName);
|
||||||
if (siteInfo != null)
|
if (siteInfo != null)
|
||||||
{
|
{
|
||||||
site = new Site(this.siteService, siteInfo);
|
site = new Site(siteInfo, this.serviceRegistry, this.siteService, getScope());
|
||||||
}
|
}
|
||||||
return site;
|
return site;
|
||||||
}
|
}
|
||||||
|
@@ -27,9 +27,14 @@ package org.alfresco.repo.site.script;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
|
import org.alfresco.repo.jscript.ScriptNode;
|
||||||
import org.alfresco.repo.jscript.ScriptableHashMap;
|
import org.alfresco.repo.jscript.ScriptableHashMap;
|
||||||
import org.alfresco.repo.site.SiteInfo;
|
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.cmr.repository.NodeRef;
|
||||||
|
import org.mozilla.javascript.Scriptable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Site JavaScript object
|
* Site JavaScript object
|
||||||
@@ -38,15 +43,23 @@ import org.alfresco.repo.site.SiteService;
|
|||||||
*/
|
*/
|
||||||
public class Site implements Serializable
|
public class Site implements Serializable
|
||||||
{
|
{
|
||||||
|
// TODO: DC - Should Site derive from ScriptNode?
|
||||||
|
|
||||||
/** Serializable serial verion UID */
|
/** Serializable serial verion UID */
|
||||||
private static final long serialVersionUID = 8013569574120957923L;
|
private static final long serialVersionUID = 8013569574120957923L;
|
||||||
|
|
||||||
/** Site information */
|
/** Site information */
|
||||||
private SiteInfo siteInfo;
|
private SiteInfo siteInfo;
|
||||||
|
|
||||||
|
/** Services Registry */
|
||||||
|
private ServiceRegistry serviceRegistry;
|
||||||
|
|
||||||
/** Site service */
|
/** Site service */
|
||||||
private SiteService siteService;
|
private SiteService siteService;
|
||||||
|
|
||||||
|
/** Scriptable */
|
||||||
|
private Scriptable scope;
|
||||||
|
|
||||||
/** Indicates whether there are any outstanding changes that need to be saved */
|
/** Indicates whether there are any outstanding changes that need to be saved */
|
||||||
private boolean isDirty = false;
|
private boolean isDirty = false;
|
||||||
|
|
||||||
@@ -55,10 +68,12 @@ public class Site implements Serializable
|
|||||||
*
|
*
|
||||||
* @param siteInfo site information
|
* @param siteInfo site information
|
||||||
*/
|
*/
|
||||||
/*package*/ Site(SiteService siteService, SiteInfo siteInfo)
|
/*package*/ Site(SiteInfo siteInfo, ServiceRegistry serviceRegistry, SiteService siteService, Scriptable scope)
|
||||||
{
|
{
|
||||||
|
this.serviceRegistry = serviceRegistry;
|
||||||
this.siteService = siteService;
|
this.siteService = siteService;
|
||||||
this.siteInfo = siteInfo;
|
this.siteInfo = siteInfo;
|
||||||
|
this.scope = scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -242,4 +257,48 @@ public class Site implements Serializable
|
|||||||
{
|
{
|
||||||
this.siteService.removeMembership(getShortName(), userName);
|
this.siteService.removeMembership(getShortName(), userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets (or creates) the "container" folder for the specified component id
|
||||||
|
*
|
||||||
|
* @param componentId
|
||||||
|
* @return node representing the "container" folder
|
||||||
|
*/
|
||||||
|
public ScriptNode getContainer(String componentId)
|
||||||
|
{
|
||||||
|
ScriptNode container = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
NodeRef containerNodeRef = this.siteService.getContainer(getShortName(), componentId);
|
||||||
|
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
|
||||||
|
*
|
||||||
|
* @param componentId
|
||||||
|
* @return true => "container" folder exists
|
||||||
|
*/
|
||||||
|
public boolean hasContainer(String componentId)
|
||||||
|
{
|
||||||
|
boolean hasContainer = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
hasContainer = this.siteService.hasContainer(getShortName(), componentId);
|
||||||
|
}
|
||||||
|
catch(AlfrescoRuntimeException e)
|
||||||
|
{
|
||||||
|
// NOTE: not good practice to catch all, but in general we're not throwing exceptions
|
||||||
|
// into the script layer
|
||||||
|
}
|
||||||
|
return hasContainer;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -78,7 +78,26 @@ function testMembership()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testContainer()
|
||||||
|
{
|
||||||
|
var site = siteService.getSite("siteShortName");
|
||||||
|
test.assertNotNull(site);
|
||||||
|
|
||||||
|
var hasContainer = site.hasContainer("folder.component");
|
||||||
|
test.assertFalse(hasContainer);
|
||||||
|
|
||||||
|
var container = site.getContainer("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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Execute test's
|
// Execute test's
|
||||||
testCRUD();
|
testCRUD();
|
||||||
testListSites();
|
testListSites();
|
||||||
testMembership();
|
testMembership();
|
||||||
|
testContainer();
|
Reference in New Issue
Block a user