mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +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:
@@ -28,9 +28,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
|
||||
import org.alfresco.repo.jscript.ScriptableHashMap;
|
||||
import org.alfresco.repo.site.SiteInfo;
|
||||
import org.alfresco.repo.site.SiteService;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
|
||||
|
||||
/**
|
||||
@@ -40,8 +40,21 @@ import org.alfresco.repo.site.SiteService;
|
||||
*/
|
||||
public class ScriptSiteService extends BaseScopableProcessorExtension
|
||||
{
|
||||
/** Service Registry */
|
||||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
/** The site service */
|
||||
private SiteService siteService;
|
||||
|
||||
/**
|
||||
* Sets the Service Registry
|
||||
*
|
||||
* @param serviceRegistry
|
||||
*/
|
||||
public void setServiceRegistry(ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the site service
|
||||
@@ -61,14 +74,14 @@ public class ScriptSiteService extends BaseScopableProcessorExtension
|
||||
* @param sitePreset site preset
|
||||
* @param shortName site short name
|
||||
* @param title site title
|
||||
* @param descripion site description
|
||||
* @param description site description
|
||||
* @param isPublic whether the site is public or not
|
||||
* @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);
|
||||
return new Site(this.siteService, siteInfo);
|
||||
SiteInfo siteInfo = this.siteService.createSite(sitePreset, shortName, title, description, isPublic);
|
||||
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());
|
||||
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()]);
|
||||
}
|
||||
@@ -106,7 +119,7 @@ public class ScriptSiteService extends BaseScopableProcessorExtension
|
||||
SiteInfo siteInfo = this.siteService.getSite(shortName);
|
||||
if (siteInfo != null)
|
||||
{
|
||||
site = new Site(this.siteService, siteInfo);
|
||||
site = new Site(siteInfo, this.serviceRegistry, this.siteService, getScope());
|
||||
}
|
||||
return site;
|
||||
}
|
||||
|
@@ -27,9 +27,14 @@ package org.alfresco.repo.site.script;
|
||||
import java.io.Serializable;
|
||||
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.site.SiteInfo;
|
||||
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
|
||||
@@ -38,14 +43,22 @@ import org.alfresco.repo.site.SiteService;
|
||||
*/
|
||||
public class Site implements Serializable
|
||||
{
|
||||
// TODO: DC - Should Site derive from ScriptNode?
|
||||
|
||||
/** Serializable serial verion UID */
|
||||
private static final long serialVersionUID = 8013569574120957923L;
|
||||
|
||||
/** Site information */
|
||||
private SiteInfo siteInfo;
|
||||
|
||||
/** Services Registry */
|
||||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
/** Site service */
|
||||
private SiteService siteService;
|
||||
|
||||
/** Scriptable */
|
||||
private Scriptable scope;
|
||||
|
||||
/** Indicates whether there are any outstanding changes that need to be saved */
|
||||
private boolean isDirty = false;
|
||||
@@ -55,10 +68,12 @@ public class Site implements Serializable
|
||||
*
|
||||
* @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.siteInfo = siteInfo;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,4 +257,48 @@ public class Site implements Serializable
|
||||
{
|
||||
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
|
||||
testCRUD();
|
||||
testListSites();
|
||||
testMembership();
|
||||
testMembership();
|
||||
testContainer();
|
Reference in New Issue
Block a user