Site Service: sites created in sites folder within the SpacesStore

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9719 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2008-07-10 12:43:09 +00:00
parent 8f1c38fcf7
commit be9beda3b8
3 changed files with 63 additions and 96 deletions

View File

@@ -43,7 +43,9 @@
<aspect>cm:titled</aspect> <aspect>cm:titled</aspect>
</mandatory-aspects> </mandatory-aspects>
</type> </type>
<!-- Site Root Folder: -->
<!-- - all sites are stored beneth the site root folder -->
<type name="st:sites"> <type name="st:sites">
<title>Sites</title> <title>Sites</title>
<parent>cm:folder</parent> <parent>cm:folder</parent>

View File

@@ -21,8 +21,7 @@
<property name="fileFolderService" ref="FileFolderService"/> <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"/>
<property name="retryingTransactionHelper" ref="retryingTransactionHelper"/>
<property name="personService" ref="PersonService"/> <property name="personService" ref="PersonService"/>
<property name="activityService" ref="activityService"/> <property name="activityService" ref="activityService"/>
</bean> </bean>

View File

@@ -53,29 +53,30 @@ import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.AbstractLifecycleBean;
import org.alfresco.util.ISO9075; import org.alfresco.util.ISO9075;
import org.alfresco.util.PropertyMap; import org.alfresco.util.PropertyMap;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.context.ApplicationEvent;
/** /**
* Site Service Implementation. Also bootstraps the site AVM and DM stores. * Site Service Implementation. Also bootstraps the site AVM and DM stores.
* *
* @author Roy Wetherall * @author Roy Wetherall
*/ */
public class SiteServiceImpl extends AbstractLifecycleBean implements SiteService, SiteModel public class SiteServiceImpl implements SiteService, SiteModel
{ {
/** Logger */
private static Log logger = LogFactory.getLog(SiteServiceImpl.class); private static Log logger = LogFactory.getLog(SiteServiceImpl.class);
public static final String SITE_AVM_STORE = "SiteStore"; /** The DM store where site's are kept */
public static final StoreRef SITE_DM_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SiteStore"); public static final StoreRef SITE_STORE = new StoreRef("workspace://SpacesStore");
/** Activiti tool */
private static final String ACTIVITY_TOOL = "siteService"; private static final String ACTIVITY_TOOL = "siteService";
/** Services */
private NodeService nodeService; private NodeService nodeService;
private FileFolderService fileFolderService; private FileFolderService fileFolderService;
private SearchService searchService; private SearchService searchService;
@@ -83,48 +84,80 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
private ActivityService activityService; private ActivityService activityService;
private PersonService personService; private PersonService personService;
private AuthenticationComponent authenticationComponent; private AuthenticationComponent authenticationComponent;
private RetryingTransactionHelper retryingTransactionHelper;
/**
* Set node service
*
* @param nodeService node service
*/
public void setNodeService(NodeService nodeService) public void setNodeService(NodeService nodeService)
{ {
this.nodeService = nodeService; this.nodeService = nodeService;
} }
/**
* Set file folder service
*
* @param fileFolderService file folder service
*/
public void setFileFolderService(FileFolderService fileFolderService) public void setFileFolderService(FileFolderService fileFolderService)
{ {
this.fileFolderService = fileFolderService; this.fileFolderService = fileFolderService;
} }
/**
* Set search service
*
* @param searchService search service
*/
public void setSearchService(SearchService searchService) public void setSearchService(SearchService searchService)
{ {
this.searchService = searchService; this.searchService = searchService;
} }
/**
* Set permission service
*
* @param permissionService permission service
*/
public void setPermissionService(PermissionService permissionService) public void setPermissionService(PermissionService permissionService)
{ {
this.permissionService = permissionService; this.permissionService = permissionService;
} }
/**
* Set activity service
*
* @param activityService activity service
*/
public void setActivityService(ActivityService activityService) public void setActivityService(ActivityService activityService)
{ {
this.activityService = activityService; this.activityService = activityService;
} }
/**
* Set person service
*
* @param personService person service
*/
public void setPersonService(PersonService personService) public void setPersonService(PersonService personService)
{ {
this.personService = personService; this.personService = personService;
} }
/**
* Set authentication component
*
* @param authenticationComponent authententication component
*/
public void setAuthenticationComponent(AuthenticationComponent authenticationComponent) public void setAuthenticationComponent(AuthenticationComponent authenticationComponent)
{ {
this.authenticationComponent = authenticationComponent; this.authenticationComponent = authenticationComponent;
} }
public void setRetryingTransactionHelper(RetryingTransactionHelper retryingTransactionHelper) /**
{ * @see org.alfresco.repo.site.SiteService#createSite(java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean)
this.retryingTransactionHelper = retryingTransactionHelper; */
}
public SiteInfo createSite(String sitePreset, String shortName, String title, String description, boolean isPublic) public SiteInfo createSite(String sitePreset, String shortName, String title, String description, boolean isPublic)
{ {
/// TODO check for shortname duplicates /// TODO check for shortname duplicates
@@ -162,6 +195,12 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
return siteInfo; return siteInfo;
} }
/**
* Gets a sites parent folder based on it's short name
* ]
* @param shortName site short name
* @return NodeRef the site's parent
*/
private NodeRef getSiteParent(String shortName) private NodeRef getSiteParent(String shortName)
{ {
// TODO // TODO
@@ -173,23 +212,19 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
private NodeRef getSiteRoot() private NodeRef getSiteRoot()
{ {
// Get the root 'sites' folder // Get the root 'sites' folder
ResultSet resultSet = this.searchService.query(SITE_DM_STORE, SearchService.LANGUAGE_LUCENE, "PATH:\"cm:sites\""); ResultSet resultSet = this.searchService.query(SITE_STORE, SearchService.LANGUAGE_LUCENE, "TYPE:\"st:sites\"");
if (resultSet.length() == 0) if (resultSet.length() == 0)
{ {
// TODO // No root site folder exists
throw new AlfrescoRuntimeException("No root sites folder exists"); throw new AlfrescoRuntimeException("No root sites folder exists");
} }
else if (resultSet.length() != 1) else if (resultSet.length() != 1)
{ {
// TODO // More than one root site folder exits
throw new AlfrescoRuntimeException("More than one root sites folder exists"); throw new AlfrescoRuntimeException("More than one root sites folder exists");
} }
NodeRef sitesRoot = resultSet.getNodeRef(0);
return resultSet.getNodeRef(0);
// TODO
// In time we will use some sort of algorithm to spread the creation of sites across an arbitary structure
return sitesRoot;
} }
public List<SiteInfo> listSites(String nameFilter, String sitePresetFilter) public List<SiteInfo> listSites(String nameFilter, String sitePresetFilter)
@@ -266,7 +301,10 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
private NodeRef getSiteNodeRef(String shortName) private NodeRef getSiteNodeRef(String shortName)
{ {
NodeRef result = null; NodeRef result = null;
ResultSet resultSet = this.searchService.query(SITE_DM_STORE, SearchService.LANGUAGE_LUCENE, "PATH:\"cm:sites/cm:" + ISO9075.encode(shortName) + "\"");
//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) if (resultSet.length() == 1)
{ {
result = resultSet.getNodeRef(0); result = resultSet.getNodeRef(0);
@@ -575,76 +613,4 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
return ""; return "";
} }
} }
/**
* @see org.alfresco.util.AbstractLifecycleBean#onBootstrap(org.springframework.context.ApplicationEvent)
*/
@Override
protected void onBootstrap(ApplicationEvent event)
{
// Ensure execution occures in a transaction
this.retryingTransactionHelper.doInTransaction(
new RetryingTransactionHelper.RetryingTransactionCallback<Object>()
{
public Object execute() throws Throwable
{
String currentUserName = SiteServiceImpl.this.authenticationComponent.getCurrentUserName();
SiteServiceImpl.this.authenticationComponent.setSystemUserAsCurrentUser();
try
{
// Bootstrap the site stores
bootstrapSiteStore(SITE_DM_STORE);
}
finally
{
if (currentUserName != null)
{
SiteServiceImpl.this.authenticationComponent.setCurrentUser(currentUserName);
}
else
{
SiteServiceImpl.this.authenticationComponent.clearCurrentSecurityContext();
}
}
return null;
}
});
}
/**
* @see org.alfresco.util.AbstractLifecycleBean#onShutdown(org.springframework.context.ApplicationEvent)
*/
@Override
protected void onShutdown(ApplicationEvent event)
{
// Do nothing
}
/**
* Bootstrap the DM site store
*
* @param storeRef the store reference
*/
private void bootstrapSiteStore(StoreRef storeRef)
{
// Check to see if the sotre exists
if (this.nodeService.exists(storeRef) == false)
{
// Create the store
this.nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier());
NodeRef rootNode = this.nodeService.getRootNode(storeRef);
// Create the root folder where sites will be stored
NodeRef rootStoreNode = this.nodeService.createNode(rootNode,
ContentModel.ASSOC_CHILDREN,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "sites"),
ContentModel.TYPE_FOLDER).getChildRef();
// Set the permissions for the root store node
this.permissionService.setInheritParentPermissions(rootStoreNode, false);
this.permissionService.setPermission(rootStoreNode, PermissionService.ALL_AUTHORITIES, PermissionService.READ, true);
this.permissionService.setPermission(rootStoreNode, PermissionService.ALL_AUTHORITIES, PermissionService.CREATE_CHILDREN, true);
}
}
} }