diff --git a/source/java/org/alfresco/repo/site/SiteInfoImpl.java b/source/java/org/alfresco/repo/site/SiteInfoImpl.java index 72285e7394..0e2bb85e3d 100644 --- a/source/java/org/alfresco/repo/site/SiteInfoImpl.java +++ b/source/java/org/alfresco/repo/site/SiteInfoImpl.java @@ -19,6 +19,7 @@ package org.alfresco.repo.site; import java.io.Serializable; +import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -52,6 +53,12 @@ public class SiteInfoImpl implements SiteInfo /** Site visibility */ private SiteVisibility visibility; + /** Site created date */ + private Date createdDate; + + /** Site last modified date */ + private Date lastModifiedDate; + /** Set of custom properties that have been defined for site */ private Map customProperties = new HashMap(1); @@ -215,6 +222,38 @@ public class SiteInfoImpl implements SiteInfo return result; } + /** + * @see org.alfresco.service.cmr.site.SiteInfo#getCreatedDate() + */ + public Date getCreatedDate() + { + return this.createdDate; + } + + /** + * @see org.alfresco.service.cmr.site.SiteInfo#setCreatedDate(java.util.Date) + */ + public void setCreatedDate(Date createdDate) + { + this.createdDate = createdDate; + } + + /** + * @see org.alfresco.service.cmr.site.SiteInfo#getLastModifiedDate() + */ + public Date getLastModifiedDate() + { + return this.lastModifiedDate; + } + + /** + * @see org.alfresco.service.cmr.site.SiteInfo#setLastModifiedDate(java.util.Date) + */ + public void setLastModifiedDate(Date lastModifiedDate) + { + this.lastModifiedDate = lastModifiedDate; + } + /** * Override equals for this ref type * diff --git a/source/java/org/alfresco/repo/site/SiteServiceImpl.java b/source/java/org/alfresco/repo/site/SiteServiceImpl.java index 0b17fe1c68..989cf82b22 100644 --- a/source/java/org/alfresco/repo/site/SiteServiceImpl.java +++ b/source/java/org/alfresco/repo/site/SiteServiceImpl.java @@ -22,6 +22,7 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -77,6 +78,7 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; import org.alfresco.service.cmr.search.LimitBy; import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.SearchParameters; @@ -198,10 +200,10 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic public void setPreferenceService(PreferenceService preferenceService) { - this.preferenceService = preferenceService; - } + this.preferenceService = preferenceService; + } - /** + /** * Set node service */ public void setNodeService(NodeService nodeService) @@ -340,7 +342,7 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic public void setSysAdminParams(SysAdminParams sysAdminParams) { - this.sysAdminParams = sysAdminParams; + this.sysAdminParams = sysAdminParams; } public void setBehaviourFilter(BehaviourFilter behaviourFilter) @@ -450,36 +452,36 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic final String description, final SiteVisibility visibility) { - return createSite(sitePreset, passedShortName, title, description, visibility, SiteModel.TYPE_SITE); + return createSite(sitePreset, passedShortName, title, description, visibility, SiteModel.TYPE_SITE); } public SiteInfo createSite(final String sitePreset, - String passedShortName, - final String title, + String passedShortName, + final String title, final String description, final SiteVisibility visibility, final QName siteType) - { - // Check that the provided site type is a subtype of TYPE_SITE - if (SiteModel.TYPE_SITE.equals(siteType) == false && - dictionaryService.isSubClass(siteType, TYPE_SITE) == false) - { - throw new SiteServiceException(MSG_INVALID_SITE_TYPE, new Object[]{siteType}); - } - + { + // Check that the provided site type is a subtype of TYPE_SITE + if (SiteModel.TYPE_SITE.equals(siteType) == false && + dictionaryService.isSubClass(siteType, TYPE_SITE) == false) + { + throw new SiteServiceException(MSG_INVALID_SITE_TYPE, new Object[]{siteType}); + } + // Remove spaces from shortName final String shortName = passedShortName.replaceAll(" ", ""); - // Check to see if we already have a site of this name - NodeRef existingSite = getSiteNodeRef(shortName, false); - if (existingSite != null || authorityService.authorityExists(getSiteGroup(shortName, true))) - { - // Throw an exception since we have a duplicate site name - throw new SiteServiceException(MSG_UNABLE_TO_CREATE, new Object[]{shortName}); - } - - // Check that the site name isn't too long - // Authorities are limited to 100 characters by the PermissionService + // Check to see if we already have a site of this name + NodeRef existingSite = getSiteNodeRef(shortName, false); + if (existingSite != null || authorityService.authorityExists(getSiteGroup(shortName, true))) + { + // Throw an exception since we have a duplicate site name + throw new SiteServiceException(MSG_UNABLE_TO_CREATE, new Object[]{shortName}); + } + + // Check that the site name isn't too long + // Authorities are limited to 100 characters by the PermissionService int longestPermissionLength = 0; for (String permission : permissionService.getSettablePermissions(siteType)) { @@ -488,12 +490,12 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic } int maximumPermisionGroupLength = 99 - longestPermissionLength; - if (getSiteGroup(shortName, true).length() > maximumPermisionGroupLength) - { - throw new SiteServiceException(MSG_SITE_SHORT_NAME_TOO_LONG, new Object[] { - shortName, maximumPermisionGroupLength - getSiteGroup("", true).length() - }); - } + if (getSiteGroup(shortName, true).length() > maximumPermisionGroupLength) + { + throw new SiteServiceException(MSG_SITE_SHORT_NAME_TOO_LONG, new Object[] { + shortName, maximumPermisionGroupLength - getSiteGroup("", true).length() + }); + } // Get the site parent node reference final NodeRef siteParent = getSiteParent(shortName); @@ -1133,7 +1135,10 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic // Create and return the site information Map customProperties = getSiteCustomProperties(properties); + siteInfo = new SiteInfoImpl(sitePreset, shortName, title, description, visibility, customProperties, siteNodeRef); + siteInfo.setCreatedDate(DefaultTypeConverter.INSTANCE.convert(Date.class, properties.get(ContentModel.PROP_CREATED))); + siteInfo.setLastModifiedDate(DefaultTypeConverter.INSTANCE.convert(Date.class, properties.get(ContentModel.PROP_MODIFIED))); return siteInfo; } @@ -1157,13 +1162,13 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic if (visibilityValue == null) { // Examine each permission to see if this is a public site or not - Set permissions; - try { - permissions = this.permissionService.getAllSetPermissions(siteNodeRef); - } catch (AccessDeniedException ae){ - // We might not have permission to examine the permissions - return visibility; - } + Set permissions; + try { + permissions = this.permissionService.getAllSetPermissions(siteNodeRef); + } catch (AccessDeniedException ae){ + // We might not have permission to examine the permissions + return visibility; + } for (AccessPermission permission : permissions) { if (permission.getAuthority().equals(PermissionService.ALL_AUTHORITIES) == true && @@ -1614,7 +1619,7 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic } if(callback.isDone()) { - break; + break; } break; case GROUP: @@ -1647,12 +1652,12 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic else { // No name filter add this group - callback.siteMember(authority, permission); + callback.siteMember(authority, permission); } if(callback.isDone()) { - break; + break; } } break; @@ -1678,21 +1683,21 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic if (addUser) { // Add the collapsed user into the members list if they do not already appear in the list - callback.siteMember(subUser, entry.getValue()); + callback.siteMember(subUser, entry.getValue()); } if(callback.isDone()) { - break; + break; } } } } } - public PagingResults listMembersPaged(String shortName, boolean collapseGroups, List> sortProps, PagingRequest pagingRequest) + public PagingResults listMembersPaged(String shortName, boolean collapseGroups, List> sortProps, PagingRequest pagingRequest) { - SiteMembershipCannedQueryFactory sitesCannedQueryFactory = (SiteMembershipCannedQueryFactory)cannedQueryRegistry.getNamedObject("sitesCannedQueryFactory"); + SiteMembershipCannedQueryFactory sitesCannedQueryFactory = (SiteMembershipCannedQueryFactory)cannedQueryRegistry.getNamedObject("sitesCannedQueryFactory"); CannedQueryPageDetails pageDetails = new CannedQueryPageDetails(pagingRequest.getSkipCount(), pagingRequest.getMaxItems()); @@ -1712,11 +1717,11 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic SiteMembersCannedQueryParams parameterBean = new SiteMembersCannedQueryParams(shortName, collapseGroups); CannedQueryParameters params = new CannedQueryParameters(parameterBean, pageDetails, sortDetails, pagingRequest.getRequestTotalCountMax(), pagingRequest.getQueryExecutionId()); - CannedQuery query = sitesCannedQueryFactory.getCannedQuery(params); + CannedQuery query = sitesCannedQueryFactory.getCannedQuery(params); - CannedQueryResults results = query.execute(); + CannedQueryResults results = query.execute(); - return getPagingResults(pagingRequest, results); + return getPagingResults(pagingRequest, results); } /** @@ -2063,21 +2068,21 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic List roles = getMembersRoles(shortName, authorityName); if (roles.size() != 0) { - if (roles.size() > 1 && roleComparator != null) - { - // Need to sort the roles into the most important first. - SortedSet sortedRoles = new TreeSet(roleComparator); - for (String role : roles) - { - sortedRoles.add(role); - } - result = sortedRoles.first(); - } - else - { - // don't search on precedence or only one result - result = roles.get(0); - } + if (roles.size() > 1 && roleComparator != null) + { + // Need to sort the roles into the most important first. + SortedSet sortedRoles = new TreeSet(roleComparator); + for (String role : roles) + { + sortedRoles.add(role); + } + result = sortedRoles.first(); + } + else + { + // don't search on precedence or only one result + result = roles.get(0); + } } return result; } @@ -2323,8 +2328,8 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic { // TODO if this is the only site manager do not down grade their // permissions - if(canAddMember(shortName, authorityName, role)) - { + if(canAddMember(shortName, authorityName, role)) + { // Check that we are not about to remove the last site manager checkLastManagerRemoval(shortName, authorityName, currentRole); @@ -2529,20 +2534,20 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic } @SuppressWarnings("unchecked") - public PagingResults listContainers(String shortName, PagingRequest pagingRequest) + public PagingResults listContainers(String shortName, PagingRequest pagingRequest) { - SiteContainersCannedQueryFactory sitesContainersCannedQueryFactory = (SiteContainersCannedQueryFactory)cannedQueryRegistry.getNamedObject("siteContainersCannedQueryFactory"); + SiteContainersCannedQueryFactory sitesContainersCannedQueryFactory = (SiteContainersCannedQueryFactory)cannedQueryRegistry.getNamedObject("siteContainersCannedQueryFactory"); CannedQueryPageDetails pageDetails = new CannedQueryPageDetails(pagingRequest.getSkipCount(), pagingRequest.getMaxItems()); - CannedQuerySortDetails sortDetails = new CannedQuerySortDetails(new Pair(SiteContainersCannedQueryParams.SortFields.ContainerName, SortOrder.ASCENDING)); - SiteContainersCannedQueryParams parameterBean = new SiteContainersCannedQueryParams(getSiteNodeRef(shortName)); + CannedQuerySortDetails sortDetails = new CannedQuerySortDetails(new Pair(SiteContainersCannedQueryParams.SortFields.ContainerName, SortOrder.ASCENDING)); + SiteContainersCannedQueryParams parameterBean = new SiteContainersCannedQueryParams(getSiteNodeRef(shortName)); CannedQueryParameters params = new CannedQueryParameters(parameterBean, pageDetails, sortDetails, pagingRequest.getRequestTotalCountMax(), pagingRequest.getQueryExecutionId()); - CannedQuery query = sitesContainersCannedQueryFactory.getCannedQuery(params); - - CannedQueryResults results = query.execute(); + CannedQuery query = sitesContainersCannedQueryFactory.getCannedQuery(params); + + CannedQueryResults results = query.execute(); - return getPagingResults(pagingRequest, results); + return getPagingResults(pagingRequest, results); } /** @@ -2832,11 +2837,11 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic // Check that we are not about to remove the last site manager if (SiteModel.SITE_MANAGER.equals(role) == true) { - int siteAuthorities = countAuthoritiesWithRole(shortName, SiteModel.SITE_MANAGER); + int siteAuthorities = countAuthoritiesWithRole(shortName, SiteModel.SITE_MANAGER); if (siteAuthorities <= 1) { - throw new SiteServiceException(MSG_DO_NOT_CHANGE_MGR, new Object[] {authorityName}); - } + throw new SiteServiceException(MSG_DO_NOT_CHANGE_MGR, new Object[] {authorityName}); + } } } @@ -2860,9 +2865,9 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic return result; } - public PagingResults listSitesPaged(final String userName, List> sortProps, final PagingRequest pagingRequest) - { - SiteMembershipCannedQueryFactory sitesCannedQueryFactory = (SiteMembershipCannedQueryFactory)cannedQueryRegistry.getNamedObject("sitesCannedQueryFactory"); + public PagingResults listSitesPaged(final String userName, List> sortProps, final PagingRequest pagingRequest) + { + SiteMembershipCannedQueryFactory sitesCannedQueryFactory = (SiteMembershipCannedQueryFactory)cannedQueryRegistry.getNamedObject("sitesCannedQueryFactory"); CannedQueryPageDetails pageDetails = new CannedQueryPageDetails(pagingRequest.getSkipCount(), pagingRequest.getMaxItems()); @@ -2882,69 +2887,69 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic SitesCannedQueryParams parameterBean = new SitesCannedQueryParams(userName); CannedQueryParameters params = new CannedQueryParameters(parameterBean, pageDetails, sortDetails, pagingRequest.getRequestTotalCountMax(), pagingRequest.getQueryExecutionId()); - CannedQuery query = sitesCannedQueryFactory.getCannedQuery(params); - - CannedQueryResults results = query.execute(); + CannedQuery query = sitesCannedQueryFactory.getCannedQuery(params); + + CannedQueryResults results = query.execute(); - return getPagingResults(pagingRequest, results); - } + return getPagingResults(pagingRequest, results); + } - private PagingResults getPagingResults(PagingRequest pagingRequest, final CannedQueryResults results) - { - List entities = null; - if (results.getPageCount() > 0) - { - entities = results.getPages().get(0); - } - else - { - entities = Collections.emptyList(); - } - - // set total count - final Pair totalCount; - if (pagingRequest.getRequestTotalCountMax() > 0) - { - totalCount = results.getTotalResultCount(); - } - else - { - totalCount = null; - } - - final List members = new ArrayList(entities.size()); - for (T entity : entities) - { - members.add(entity); - } - - return new PagingResults() - { - @Override - public String getQueryExecutionId() - { - return results.getQueryExecutionId(); - } + private PagingResults getPagingResults(PagingRequest pagingRequest, final CannedQueryResults results) + { + List entities = null; + if (results.getPageCount() > 0) + { + entities = results.getPages().get(0); + } + else + { + entities = Collections.emptyList(); + } + + // set total count + final Pair totalCount; + if (pagingRequest.getRequestTotalCountMax() > 0) + { + totalCount = results.getTotalResultCount(); + } + else + { + totalCount = null; + } + + final List members = new ArrayList(entities.size()); + for (T entity : entities) + { + members.add(entity); + } + + return new PagingResults() + { + @Override + public String getQueryExecutionId() + { + return results.getQueryExecutionId(); + } - @Override - public List getPage() - { - return members; - } - - @Override - public boolean hasMoreItems() - { - return results.hasMoreItems(); - } + @Override + public List getPage() + { + return members; + } + + @Override + public boolean hasMoreItems() + { + return results.hasMoreItems(); + } - @Override - public Pair getTotalResultCount() - { - return totalCount; - } - }; - } + @Override + public Pair getTotalResultCount() + { + return totalCount; + } + }; + } /** * Private sites have separate ACLs on each component and don't inherit from the diff --git a/source/java/org/alfresco/repo/site/script/ScriptSiteService.java b/source/java/org/alfresco/repo/site/script/ScriptSiteService.java index 78908f9ca4..cda93016b2 100644 --- a/source/java/org/alfresco/repo/site/script/ScriptSiteService.java +++ b/source/java/org/alfresco/repo/site/script/ScriptSiteService.java @@ -202,6 +202,39 @@ public class ScriptSiteService extends BaseScopableProcessorExtension } } + /** + * Retrieves the sites available in the repository based on the user's access right. For example, + * Site Administrator can access all the sites (Public, MODERATED and PRIVATE). The returned list can optionally + * be filtered by name and site preset. If no filters are specified then all the available sites are returned. + * + * NOTE: If the filter starts with a * a Lucene based search will be performed, this may discover a wider range + * of results i.e. those sites that contain the search term as opposed to those that start with the search term, + * but newly created sites may not be found until the underlying search indexes are updated. + * + * @param filter inclusion filter for returned sites. Only sites whose cm:name OR cm:title + * OR cm:description start with the filter string will be returned. + * @param sitePresetFilter site preset filter + * @param size max results size crop if >0 + * @return Site[] a list of the site filtered as appropriate + */ + public Site[] getSitesAsSiteAdmin(final String filter, final String sitePresetFilter, final int size) + { + if (siteService.isSiteAdmin(AuthenticationUtil.getFullyAuthenticatedUser())) + { + return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() + { + public Site[] doWork() throws Exception + { + return getSites(filter, sitePresetFilter, size); + } + }, AuthenticationUtil.getSystemUserName()); + } + else + { + return getSites(filter, sitePresetFilter, size); + } + } + /** * List the sites available in the repository. The returned list can optionally be filtered by name and site * preset. @@ -314,13 +347,28 @@ public class ScriptSiteService extends BaseScopableProcessorExtension *

* Returns null if the site does not exist. * - * @param shortName short name of the site - * @return Site the site, null if does not exist + * @param shortName short name of the site + * @return Site the site, null if does not exist */ - public Site getSite(String shortName) + public Site getSite(final String shortName) { + SiteInfo siteInfo = null; Site site = null; - SiteInfo siteInfo = this.siteService.getSite(shortName); + if (siteService.isSiteAdmin(AuthenticationUtil.getFullyAuthenticatedUser())) + { + siteInfo = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() + { + public SiteInfo doWork() throws Exception + { + return siteService.getSite(shortName); + } + }, AuthenticationUtil.getSystemUserName()); + } + else + { + siteInfo = this.siteService.getSite(shortName); + } + if (siteInfo != null) { site = new Site(siteInfo, this.serviceRegistry, this.siteService, getScope()); diff --git a/source/java/org/alfresco/repo/site/script/Site.java b/source/java/org/alfresco/repo/site/script/Site.java index 9313699eb6..9d28e00165 100644 --- a/source/java/org/alfresco/repo/site/script/Site.java +++ b/source/java/org/alfresco/repo/site/script/Site.java @@ -19,6 +19,7 @@ package org.alfresco.repo.site.script; import java.io.Serializable; +import java.util.Date; import java.util.List; import java.util.Map; @@ -272,7 +273,27 @@ public class Site implements Serializable } /** - * Saves any outstanding updates to the site details. + * Get the site created date + * + * @return Date site created date + */ + public Date getCreatedDate() + { + return this.siteInfo.getCreatedDate(); + } + + /** + * Get the site last modified date + * + * @return Date site last modified date + */ + public Date getLastModifiedDate() + { + return this.siteInfo.getLastModifiedDate(); + } + + /** + * Saves any outstanding updates to the site details. *

* If properties of the site are changed and save is not called, those changes will be lost. */ @@ -280,9 +301,23 @@ public class Site implements Serializable { if (this.isDirty == true) { - // Update the site details - this.siteService.updateSite(this.siteInfo); - + if (siteService.isSiteAdmin(AuthenticationUtil.getFullyAuthenticatedUser())) + { + AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() + { + public Void doWork() throws Exception + { + // Update the site details as a site-admin + siteService.updateSite(siteInfo); + return null; + } + }, AuthenticationUtil.getSystemUserName()); + } + else + { + // Update the site details + this.siteService.updateSite(this.siteInfo); + } // Reset the dirty flag this.isDirty = false; } @@ -293,8 +328,23 @@ public class Site implements Serializable */ public void deleteSite() { - // Delete the site - this.siteService.deleteSite(this.siteInfo.getShortName()); + if (siteService.isSiteAdmin(AuthenticationUtil.getFullyAuthenticatedUser())) + { + AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() + { + public Void doWork() throws Exception + { + // Delete the site + siteService.deleteSite(siteInfo.getShortName()); + return null; + } + }, AuthenticationUtil.getSystemUserName()); + } + else + { + // Delete the site + this.siteService.deleteSite(this.siteInfo.getShortName()); + } } /** diff --git a/source/java/org/alfresco/service/cmr/site/SiteInfo.java b/source/java/org/alfresco/service/cmr/site/SiteInfo.java index 76fb6e3b28..40c42268c8 100644 --- a/source/java/org/alfresco/service/cmr/site/SiteInfo.java +++ b/source/java/org/alfresco/service/cmr/site/SiteInfo.java @@ -19,6 +19,7 @@ package org.alfresco.service.cmr.site; import java.io.Serializable; +import java.util.Date; import java.util.Map; import org.alfresco.api.AlfrescoPublicApi; @@ -124,4 +125,32 @@ public interface SiteInfo extends PermissionCheckValue */ public abstract Serializable getCustomProperty(QName name); + /** + * Get the site created date + * + * @return Date site created date + */ + public abstract Date getCreatedDate(); + + /** + * Set the site created date + * + * @param createdDate site created date + */ + public abstract void setCreatedDate(Date createdDate); + + /** + * Get the site last modified date + * + * @return Date site last modified date + */ + public abstract Date getLastModifiedDate(); + + /** + * Set the site last modified date + * + * @param lastModifiedDate site last modified date + */ + public abstract void setLastModifiedDate(Date lastModifiedDate); + }