Site service copes with site root missing

- List sites methods return emtpty list when site root is missing
- Create site throws excpetion with root site is missing



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19158 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2010-03-09 15:31:37 +00:00
parent 91ba631a3b
commit a3db9d0db7

View File

@@ -33,7 +33,6 @@ import java.util.concurrent.ConcurrentHashMap;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.activities.ActivityType; import org.alfresco.repo.activities.ActivityType;
import org.alfresco.repo.model.Repository;
import org.alfresco.repo.search.QueryParameterDefImpl; import org.alfresco.repo.search.QueryParameterDefImpl;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser; import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.security.authentication.AuthenticationContext; import org.alfresco.repo.security.authentication.AuthenticationContext;
@@ -71,13 +70,13 @@ import org.alfresco.service.cmr.tagging.TaggingService;
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.springframework.extensions.surf.util.ParameterCheck;
import org.springframework.extensions.surf.util.PropertyCheck;
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.extensions.surf.util.ParameterCheck;
import org.springframework.extensions.surf.util.PropertyCheck;
/** /**
* Site Service Implementation. Also bootstraps the site AVM and DM stores. * Site Service Implementation. Also bootstraps the site AVM and DM stores.
@@ -113,7 +112,6 @@ public class SiteServiceImpl implements SiteService, SiteModel
private static final String MSG_CAN_NOT_UPDATE = "site_service.can_not_update"; private static final String MSG_CAN_NOT_UPDATE = "site_service.can_not_update";
private static final String MSG_CAN_NOT_DELETE = "site_service.can_not_delete"; private static final String MSG_CAN_NOT_DELETE = "site_service.can_not_delete";
private static final String MSG_SITE_NO_EXIST = "site_service.site_no_exist"; private static final String MSG_SITE_NO_EXIST = "site_service.site_no_exist";
private static final String MSG_DO_NOT_REMOVE_MGR = "site_service.do_not_remove_manager";
private static final String MSG_CAN_NOT_REMOVE_MSHIP = "site_service.can_not_reomve_memebership"; private static final String MSG_CAN_NOT_REMOVE_MSHIP = "site_service.can_not_reomve_memebership";
private static final String MSG_DO_NOT_CHANGE_MGR = "site_service.do_not_change_manager"; private static final String MSG_DO_NOT_CHANGE_MGR = "site_service.do_not_change_manager";
private static final String MSG_CAN_NOT_CHANGE_MSHIP="site_service.can_not_change_memebership"; private static final String MSG_CAN_NOT_CHANGE_MSHIP="site_service.can_not_change_memebership";
@@ -339,6 +337,10 @@ public class SiteServiceImpl implements SiteService, SiteModel
// Get the site parent node reference // Get the site parent node reference
NodeRef siteParent = getSiteParent(shortName); NodeRef siteParent = getSiteParent(shortName);
if (siteParent == null)
{
throw new SiteServiceException("No root sites folder exists");
}
// Create the site node // Create the site node
PropertyMap properties = new PropertyMap(4); PropertyMap properties = new PropertyMap(4);
@@ -542,6 +544,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
{ {
public NodeRef execute() throws Exception public NodeRef execute() throws Exception
{ {
NodeRef result = null;
// Get the root 'sites' folder // Get the root 'sites' folder
NodeRef rootNodeRef = nodeService.getRootNode(SITE_STORE); NodeRef rootNodeRef = nodeService.getRootNode(SITE_STORE);
List<NodeRef> results = searchService.selectNodes( List<NodeRef> results = searchService.selectNodes(
@@ -551,18 +555,12 @@ public class SiteServiceImpl implements SiteService, SiteModel
namespaceService, namespaceService,
false, false,
SearchService.LANGUAGE_XPATH); SearchService.LANGUAGE_XPATH);
if (results.size() == 0) if (results.size() != 0)
{ {
// No root site folder exists result = results.get(0);
throw new SiteServiceException("No root sites folder exists");
}
else if (results.size() != 1)
{
// More than one root site folder exits
logger.warn("More than one root sites folder exists: \n" + results);
} }
return results.get(0); return result;
} }
}, true); }, true);
} }
@@ -591,6 +589,12 @@ public class SiteServiceImpl implements SiteService, SiteModel
// TODO: take into consideration the sitePresetFilter // TODO: take into consideration the sitePresetFilter
NodeRef siteRoot = getSiteRoot(); NodeRef siteRoot = getSiteRoot();
if (siteRoot == null)
{
result = new ArrayList<SiteInfo>(0);
}
else
{
if (nameFilter != null && nameFilter.length() != 0) if (nameFilter != null && nameFilter.length() != 0)
{ {
String escNameFilter = LuceneQueryParser.escape(nameFilter.replace('"', ' ')); String escNameFilter = LuceneQueryParser.escape(nameFilter.replace('"', ' '));
@@ -668,6 +672,7 @@ public class SiteServiceImpl implements SiteService, SiteModel
} }
} }
} }
}
return result; return result;
} }
@@ -677,6 +682,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
*/ */
public List<SiteInfo> listSites(String userName) public List<SiteInfo> listSites(String userName)
{ {
List<SiteInfo> result = null;
// get the Groups this user is contained within (at any level) // get the Groups this user is contained within (at any level)
Set<String> groups = this.authorityService.getContainingAuthorities(null, userName, false); Set<String> groups = this.authorityService.getContainingAuthorities(null, userName, false);
Set<String> siteNames = new HashSet<String>(groups.size()); Set<String> siteNames = new HashSet<String>(groups.size());
@@ -702,6 +709,12 @@ public class SiteServiceImpl implements SiteService, SiteModel
// retrieve the site nodes based on the list from the containing site groups // retrieve the site nodes based on the list from the containing site groups
NodeRef siteRoot = getSiteRoot(); NodeRef siteRoot = getSiteRoot();
if (siteRoot == null)
{
result = new ArrayList<SiteInfo>(0);
}
else
{
List<String> siteList = new ArrayList<String>(siteNames); List<String> siteList = new ArrayList<String>(siteNames);
// ensure we do not trip over the getChildrenByName() 1000 item API limit! // ensure we do not trip over the getChildrenByName() 1000 item API limit!
if (siteList.size() > 1000) if (siteList.size() > 1000)
@@ -712,7 +725,7 @@ public class SiteServiceImpl implements SiteService, SiteModel
siteRoot, siteRoot,
ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CONTAINS,
siteList); siteList);
List<SiteInfo> result = new ArrayList<SiteInfo>(assocs.size()); result = new ArrayList<SiteInfo>(assocs.size());
for (ChildAssociationRef assoc : assocs) for (ChildAssociationRef assoc : assocs)
{ {
// Ignore any node that is not a "site" type // Ignore any node that is not a "site" type
@@ -723,6 +736,7 @@ public class SiteServiceImpl implements SiteService, SiteModel
result.add(createSiteInfo(site)); result.add(createSiteInfo(site));
} }
} }
}
return result; return result;
} }