Merged V3.0 to HEAD

12003: ETHREEOH-535: User with Editor role can't edit content
   12016: ETHREEOH-864
   12018: Fixed NullPointerException during NFS mount. JLAN-51.
   12019: Fixed problems in mounting the Alfresco filesystems with NFS. ETHREEOH-913.
   12020: Use a default RPC authenticator if not specified in the xml configuration. JLAN-51.
   12021: Fixed typo in Portmapper server class name that is loader dynamically. JLAN-52.
   12025: MT - fix export/import tenant (ensure tenant admin ops run in tx)
   12026: Site service now returns information about the site managers. First part of fix for ETHREEOH-547
   12027: Fix for ETHREEOH-664 and ETHREEOH-789. RSS feed issues and authentication errors when trying to retrieve user details via feed service endpoint.
   12029: Fix for some wiki page links being highlighted as "missing page" when they're not
   12030: ETHREEOH-916 - Unable to "Publish Internally" a newly created blog post
   12031: Added logging to thumbnail service to help diagnose ETHREEOH-910 should it occur again
   12032: Removed out of date comment on mysql driver
   12034: Suppress freemarker.runtime ERROR log messages. These may correspond to exceptions that get handled by Alfresco's retrying transaction handler (e.g. optimistic locking failures) and are only passed on and logged if the retry threshold is exceeded.
   12037: Fix for ETHREEOH-901: Radio buttons using a enumeration can not be selected in internet explorer and selecting an option in a drop down menu causes a script error in Internet Explorer
   12038: Merged 2.2 to 3.0
      12017: Integrated ETWOTWO-926: Inline callouts should be able to reference a web script maintained in the Data Dictionary
   12042: Build fix
   12043: Fix for ETHREEOH-472 & ETHREEOH-473: File picker restrictions (folder and search) do not work.
   12065: New class Alfresco.service.Preferences that makes it easy to add and remove user preferences.
   12069: Fix for ETHREEOH-926. Fixed bug webscript matching code when url element containing a dot is followed by further url elements.
   12071: Added support to Alfresco.service.Preferences so it can handle hirerchial properties, ie "org.alfresco.share.sites.favourites"
   12074: Fix for ETHREEOH-896: XML Form layout is incorrect on Firefox 3
   12075: Fix for ETHREEOH-917 - help text for Create Site changed as requested.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@12497 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2008-12-18 15:49:55 +00:00
parent 6b3d327f64
commit 9f42bfac4c
9 changed files with 571 additions and 385 deletions

View File

@@ -36,7 +36,7 @@
#db.url=jdbc:derby:/srv/alfresco/alf_data/derby_data/alfresco;create=true #db.url=jdbc:derby:/srv/alfresco/alf_data/derby_data/alfresco;create=true
# #
# MySQL connection (This is default and requires mysql-connector-java-5.0.3-bin.jar, which ships with the Alfresco server) # MySQL connection
# #
#db.driver=org.gjt.mm.mysql.Driver #db.driver=org.gjt.mm.mysql.Driver
#db.url=jdbc:mysql://localhost/alfresco #db.url=jdbc:mysql://localhost/alfresco

View File

@@ -644,7 +644,7 @@
<property name="afterInvocationManager"><ref local="afterInvocationManager"/></property> <property name="afterInvocationManager"><ref local="afterInvocationManager"/></property>
<property name="objectDefinitionSource"> <property name="objectDefinitionSource">
<value> <value>
org.alfresco.service.cmr.coci.CheckOutCheckInService.checkout=ACL_NODE.0.cm:lockable.CheckOut,ACL_NODE.1.sys:base.CreateChildren org.alfresco.service.cmr.coci.CheckOutCheckInService.checkout=ACL_NODE.0.cm:lockable.CheckOut
org.alfresco.service.cmr.coci.CheckOutCheckInService.checkin=ACL_NODE.0.cm:lockable.CheckIn org.alfresco.service.cmr.coci.CheckOutCheckInService.checkin=ACL_NODE.0.cm:lockable.CheckIn
org.alfresco.service.cmr.coci.CheckOutCheckInService.cancelCheckout=ACL_NODE.0.cm:lockable.CancelCheckOut org.alfresco.service.cmr.coci.CheckOutCheckInService.cancelCheckout=ACL_NODE.0.cm:lockable.CancelCheckOut
org.alfresco.service.cmr.coci.CheckOutCheckInService.getWorkingCopy=ACL_NODE.0.sys:base.Read org.alfresco.service.cmr.coci.CheckOutCheckInService.getWorkingCopy=ACL_NODE.0.sys:base.Read

View File

@@ -255,7 +255,7 @@ public class AlfrescoRpcAuthenticator implements RpcAuthenticator {
{ {
// Start a transaction // Start a transaction
UserTransaction tx = m_alfrescoConfig.getTransactionService().getUserTransaction( true); UserTransaction tx = m_alfrescoConfig.getTransactionService().getUserTransaction( false);
try try
{ {

View File

@@ -31,6 +31,7 @@ import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.i18n.I18NUtil; import org.alfresco.i18n.I18NUtil;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.version.VersionableAspect; import org.alfresco.repo.version.VersionableAspect;
import org.alfresco.service.cmr.coci.CheckOutCheckInService; import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.coci.CheckOutCheckInServiceException; import org.alfresco.service.cmr.coci.CheckOutCheckInServiceException;
@@ -194,9 +195,9 @@ public class CheckOutCheckInServiceImpl implements CheckOutCheckInService
* @see org.alfresco.service.cmr.coci.CheckOutCheckInService#checkout(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, org.alfresco.service.namespace.QName) * @see org.alfresco.service.cmr.coci.CheckOutCheckInService#checkout(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, org.alfresco.service.namespace.QName)
*/ */
public NodeRef checkout( public NodeRef checkout(
NodeRef nodeRef, final NodeRef nodeRef,
NodeRef destinationParentNodeRef, final NodeRef destinationParentNodeRef,
QName destinationAssocTypeQName, final QName destinationAssocTypeQName,
QName destinationAssocQName) QName destinationAssocQName)
{ {
LockType lockType = this.lockService.getLockType(nodeRef); LockType lockType = this.lockService.getLockType(nodeRef);
@@ -242,12 +243,19 @@ public class CheckOutCheckInServiceImpl implements CheckOutCheckInService
} }
// Make the working copy // Make the working copy
destinationAssocQName = QName.createQName(destinationAssocQName.getNamespaceURI(), QName.createValidLocalName(copyName)); final QName copyQName = QName.createQName(destinationAssocQName.getNamespaceURI(), QName.createValidLocalName(copyName));
NodeRef workingCopy = this.copyService.copy( NodeRef workingCopy = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<NodeRef>()
{
public NodeRef doWork() throws Exception
{
NodeRef workingCopy = copyService.copy(
nodeRef, nodeRef,
destinationParentNodeRef, destinationParentNodeRef,
destinationAssocTypeQName, destinationAssocTypeQName,
destinationAssocQName); copyQName);
return workingCopy;
}
}, AuthenticationUtil.getSystemUserName());
// Update the working copy name // Update the working copy name
this.nodeService.setProperty(workingCopy, ContentModel.PROP_NAME, copyName); this.nodeService.setProperty(workingCopy, ContentModel.PROP_NAME, copyName);

View File

@@ -74,7 +74,7 @@ public interface SiteService
/** /**
* List the memebers of the site. * List the memebers of the site.
* <p> * <p>
* Name and role filters are optional and if not specified all the memebers of the site are returned. * Name and role filters are optional and if not specified all the members of the site are returned.
* *
* @param shortName site short name * @param shortName site short name
* @param nameFilter name filter * @param nameFilter name filter

View File

@@ -73,7 +73,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
private static Log logger = LogFactory.getLog(SiteServiceImpl.class); private static Log logger = LogFactory.getLog(SiteServiceImpl.class);
/** The DM store where site's are kept */ /** The DM store where site's are kept */
public static final StoreRef SITE_STORE = new StoreRef("workspace://SpacesStore"); public static final StoreRef SITE_STORE = new StoreRef(
"workspace://SpacesStore");
/** Activiti tool */ /** Activiti tool */
private static final String ACTIVITY_TOOL = "siteService"; private static final String ACTIVITY_TOOL = "siteService";
@@ -92,7 +93,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
/** /**
* Set node service * Set node service
* *
* @param nodeService node service * @param nodeService
* node service
*/ */
public void setNodeService(NodeService nodeService) public void setNodeService(NodeService nodeService)
{ {
@@ -102,7 +104,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
/** /**
* Set file folder service * Set file folder service
* *
* @param fileFolderService file folder service * @param fileFolderService
* file folder service
*/ */
public void setFileFolderService(FileFolderService fileFolderService) public void setFileFolderService(FileFolderService fileFolderService)
{ {
@@ -112,7 +115,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
/** /**
* Set search service * Set search service
* *
* @param searchService search service * @param searchService
* search service
*/ */
public void setSearchService(SearchService searchService) public void setSearchService(SearchService searchService)
{ {
@@ -122,7 +126,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
/** /**
* Set permission service * Set permission service
* *
* @param permissionService permission service * @param permissionService
* permission service
*/ */
public void setPermissionService(PermissionService permissionService) public void setPermissionService(PermissionService permissionService)
{ {
@@ -132,7 +137,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
/** /**
* Set activity service * Set activity service
* *
* @param activityService activity service * @param activityService
* activity service
*/ */
public void setActivityService(ActivityService activityService) public void setActivityService(ActivityService activityService)
{ {
@@ -142,7 +148,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
/** /**
* Set person service * Set person service
* *
* @param personService person service * @param personService
* person service
*/ */
public void setPersonService(PersonService personService) public void setPersonService(PersonService personService)
{ {
@@ -152,9 +159,11 @@ public class SiteServiceImpl implements SiteService, SiteModel
/** /**
* Set authentication component * Set authentication component
* *
* @param authenticationComponent authententication component * @param authenticationComponent
* authententication component
*/ */
public void setAuthenticationComponent(AuthenticationComponent authenticationComponent) public void setAuthenticationComponent(
AuthenticationComponent authenticationComponent)
{ {
this.authenticationComponent = authenticationComponent; this.authenticationComponent = authenticationComponent;
} }
@@ -162,7 +171,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
/** /**
* Set the taggin service * Set the taggin service
* *
* @param taggingService tagging service * @param taggingService
* tagging service
*/ */
public void setTaggingService(TaggingService taggingService) public void setTaggingService(TaggingService taggingService)
{ {
@@ -172,7 +182,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
/** /**
* Set the authority service * Set the authority service
* *
* @param authorityService authority service * @param authorityService
* authority service
*/ */
public void setAuthorityService(AuthorityService authorityService) public void setAuthorityService(AuthorityService authorityService)
{ {
@@ -180,9 +191,11 @@ public class SiteServiceImpl implements SiteService, SiteModel
} }
/** /**
* @see org.alfresco.repo.site.SiteService#createSite(java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean) * @see org.alfresco.repo.site.SiteService#createSite(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String, boolean)
*/ */
public SiteInfo createSite(final String sitePreset, String passedShortName, final String title, final String description, final boolean isPublic) public SiteInfo createSite(final String sitePreset, String passedShortName,
final String title, final String description, final boolean isPublic)
{ {
// Remove spaces from shortName // Remove spaces from shortName
final String shortName = passedShortName.replaceAll(" ", ""); final String shortName = passedShortName.replaceAll(" ", "");
@@ -192,7 +205,10 @@ public class SiteServiceImpl implements SiteService, SiteModel
if (existingSite != null) if (existingSite != null)
{ {
// Throw an exception since we have a duplicate site name // Throw an exception since we have a duplicate site name
throw new AlfrescoRuntimeException("Unable to create site because the site short name '" + shortName + "' is already in use. Site short names must be unique."); throw new AlfrescoRuntimeException(
"Unable to create site because the site short name '"
+ shortName
+ "' is already in use. Site short names must be unique.");
} }
// Get the site parent node reference // Get the site parent node reference
@@ -207,9 +223,9 @@ public class SiteServiceImpl implements SiteService, SiteModel
final NodeRef siteNodeRef = this.nodeService.createNode( final NodeRef siteNodeRef = this.nodeService.createNode(
siteParent, siteParent,
ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, shortName), QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
SiteModel.TYPE_SITE, shortName), SiteModel.TYPE_SITE, properties)
properties).getChildRef(); .getChildRef();
// Make the new site a tag scope // Make the new site a tag scope
this.taggingService.addTagScope(siteNodeRef); this.taggingService.addTagScope(siteNodeRef);
@@ -221,33 +237,44 @@ public class SiteServiceImpl implements SiteService, SiteModel
final String currentUser = authenticationComponent.getCurrentUserName(); final String currentUser = authenticationComponent.getCurrentUserName();
// Create the relevant groups and assign permissions // Create the relevant groups and assign permissions
AuthenticationUtil.runAs( AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>()
new AuthenticationUtil.RunAsWork<Object>()
{ {
public String doWork() throws Exception public String doWork() throws Exception
{ {
// Create the site's groups // Create the site's groups
String siteGroup = authorityService.createAuthority(AuthorityType.GROUP, null, getSiteGroup(shortName, false)); String siteGroup = authorityService.createAuthority(
Set<String> permissions = permissionService.getSettablePermissions(SiteModel.TYPE_SITE); AuthorityType.GROUP, null, getSiteGroup(shortName,
false));
Set<String> permissions = permissionService
.getSettablePermissions(SiteModel.TYPE_SITE);
for (String permission : permissions) for (String permission : permissions)
{ {
// Create a group for the permission // Create a group for the permission
String permissionGroup = authorityService.createAuthority(AuthorityType.GROUP, siteGroup, getSiteRoleGroup(shortName, permission, false)); String permissionGroup = authorityService.createAuthority(
AuthorityType.GROUP, siteGroup, getSiteRoleGroup(
shortName, permission, false));
// Assign the group the relevant permission on the site // Assign the group the relevant permission on the site
permissionService.setPermission(siteNodeRef, permissionGroup, permission, true); permissionService.setPermission(siteNodeRef,
permissionGroup, permission, true);
} }
// Set the memberhips details // Set the memberhips details
// - give all authorities read permissions if site is public // - give all authorities read permissions if site is public
// - give all authorities read permission on permissions so memberships can be calculated // - give all authorities read permission on permissions so
// memberships can be calculated
// - add the current user to the site manager group // - add the current user to the site manager group
if (isPublic == true) if (isPublic == true)
{ {
permissionService.setPermission(siteNodeRef, PermissionService.ALL_AUTHORITIES, SITE_CONSUMER, true); permissionService.setPermission(siteNodeRef,
PermissionService.ALL_AUTHORITIES, SITE_CONSUMER,
true);
} }
permissionService.setPermission(siteNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.READ_PERMISSIONS, true); permissionService.setPermission(siteNodeRef,
authorityService.addAuthority(getSiteRoleGroup(shortName, SiteModel.SITE_MANAGER, true), currentUser); PermissionService.ALL_AUTHORITIES,
PermissionService.READ_PERMISSIONS, true);
authorityService.addAuthority(getSiteRoleGroup(shortName,
SiteModel.SITE_MANAGER, true), currentUser);
// Return nothing // Return nothing
return null; return null;
@@ -291,7 +318,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
} }
/** /**
* @see org.alfresco.repo.site.SiteService#getSiteRoleGroup(java.lang.String, java.lang.String) * @see org.alfresco.repo.site.SiteService#getSiteRoleGroup(java.lang.String,
* java.lang.String)
*/ */
public String getSiteRoleGroup(String shortName, String role) public String getSiteRoleGroup(String shortName, String role)
{ {
@@ -301,7 +329,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
/** /**
* Helper method to get the name of the site group * Helper method to get the name of the site group
* *
* @param shortName site short name * @param shortName
* site short name
* @return String site group name * @return String site group name
*/ */
public String getSiteGroup(String shortName, boolean withGroupPrefix) public String getSiteGroup(String shortName, boolean withGroupPrefix)
@@ -319,25 +348,30 @@ public class SiteServiceImpl implements SiteService, SiteModel
/** /**
* Helper method to get the name of the site permission group * Helper method to get the name of the site permission group
* *
* @param shortName site short name * @param shortName
* @param permission permission name * site short name
* @param permission
* permission name
* @return String site permission group name * @return String site permission group name
*/ */
public String getSiteRoleGroup(String shortName, String permission, boolean withGroupPrefix) public String getSiteRoleGroup(String shortName, String permission,
boolean withGroupPrefix)
{ {
return getSiteGroup(shortName, withGroupPrefix) + "_" + permission; return getSiteGroup(shortName, withGroupPrefix) + "_" + permission;
} }
/** /**
* Gets a sites parent folder based on it's short name * Gets a sites parent folder based on it's short name ]
* ] *
* @param shortName site short name * @param shortName
* site short name
* @return NodeRef the site's parent * @return NodeRef the site's parent
*/ */
private NodeRef getSiteParent(String shortName) private NodeRef getSiteParent(String shortName)
{ {
// TODO // TODO
// For now just return the site root, later we may build folder structure based on the shortname to // For now just return the site root, later we may build folder
// structure based on the shortname to
// spread the sites about // spread the sites about
return getSiteRoot(); return getSiteRoot();
} }
@@ -350,34 +384,39 @@ public class SiteServiceImpl implements SiteService, SiteModel
private NodeRef getSiteRoot() private NodeRef getSiteRoot()
{ {
// Get the root 'sites' folder // Get the root 'sites' folder
ResultSet resultSet = this.searchService.query(SITE_STORE, SearchService.LANGUAGE_LUCENE, "TYPE:\"st:sites\""); ResultSet resultSet = this.searchService.query(SITE_STORE,
SearchService.LANGUAGE_LUCENE, "TYPE:\"st:sites\"");
if (resultSet.length() == 0) if (resultSet.length() == 0)
{ {
// No root site folder exists // 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)
{ {
// More than one root site folder exits // 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");
} }
return resultSet.getNodeRef(0); return resultSet.getNodeRef(0);
} }
/** /**
* @see org.alfresco.repo.site.SiteService#listSites(java.lang.String, java.lang.String) * @see org.alfresco.repo.site.SiteService#listSites(java.lang.String,
* java.lang.String)
*/ */
public List<SiteInfo> listSites(String nameFilter, String sitePresetFilter) public List<SiteInfo> listSites(String nameFilter, String sitePresetFilter)
{ {
// TODO // TODO
// - take into consideration the filters set // - take into consideration the filters set
// - take into consideration that the sites may not just be in a flat list under the site root // - take into consideration that the sites may not just be in a flat
// list under the site root
// TODO // TODO
// For now just return the list of sites present under the site root // For now just return the list of sites present under the site root
NodeRef siteRoot = getSiteRoot(); NodeRef siteRoot = getSiteRoot();
List<ChildAssociationRef> assocs = this.nodeService.getChildAssocs(siteRoot, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL); List<ChildAssociationRef> assocs = this.nodeService.getChildAssocs(
siteRoot, ContentModel.ASSOC_CONTAINS,
RegexQNamePattern.MATCH_ALL);
List<SiteInfo> result = new ArrayList<SiteInfo>(assocs.size()); List<SiteInfo> result = new ArrayList<SiteInfo>(assocs.size());
for (ChildAssociationRef assoc : assocs) for (ChildAssociationRef assoc : assocs)
{ {
@@ -407,17 +446,20 @@ public class SiteServiceImpl implements SiteService, SiteModel
/** /**
* Creates a site informatoin object given a site node reference * Creates a site informatoin object given a site node reference
* *
* @param siteNodeRef site node reference * @param siteNodeRef
* site node reference
* @return SiteInfo site information object * @return SiteInfo site information object
*/ */
private SiteInfo createSiteInfo(NodeRef siteNodeRef) private SiteInfo createSiteInfo(NodeRef siteNodeRef)
{ {
// Get the properties // Get the properties
Map<QName, Serializable> properties = this.nodeService.getProperties(siteNodeRef); Map<QName, Serializable> properties = this.nodeService
String shortName = (String)properties.get(ContentModel.PROP_NAME); .getProperties(siteNodeRef);
String sitePreset = (String)properties.get(PROP_SITE_PRESET); String shortName = (String) properties.get(ContentModel.PROP_NAME);
String title = (String)properties.get(ContentModel.PROP_TITLE); String sitePreset = (String) properties.get(PROP_SITE_PRESET);
String description = (String)properties.get(ContentModel.PROP_DESCRIPTION); String title = (String) properties.get(ContentModel.PROP_TITLE);
String description = (String) properties
.get(ContentModel.PROP_DESCRIPTION);
// Determine whether the space is public or not // Determine whether the space is public or not
boolean isPublic = isSitePublic(siteNodeRef); boolean isPublic = isSitePublic(siteNodeRef);
@@ -431,17 +473,20 @@ public class SiteServiceImpl implements SiteService, SiteModel
/** /**
* Indicates whether a site is public or not * Indicates whether a site is public or not
* *
* @param siteNodeRef site node reference * @param siteNodeRef
* site node reference
* @return boolean true if the site is public, false otherwise * @return boolean true if the site is public, false otherwise
*/ */
private boolean isSitePublic(NodeRef siteNodeRef) private boolean isSitePublic(NodeRef siteNodeRef)
{ {
boolean isPublic = false; boolean isPublic = false;
Set<AccessPermission> permissions = this.permissionService.getAllSetPermissions(siteNodeRef); Set<AccessPermission> permissions = this.permissionService
.getAllSetPermissions(siteNodeRef);
for (AccessPermission permission : permissions) for (AccessPermission permission : permissions)
{ {
if (permission.getAuthority().equals(PermissionService.ALL_AUTHORITIES) == true && if (permission.getAuthority().equals(
permission.getPermission().equals(SITE_CONSUMER) == true) PermissionService.ALL_AUTHORITIES) == true
&& permission.getPermission().equals(SITE_CONSUMER) == true)
{ {
isPublic = true; isPublic = true;
break; break;
@@ -472,7 +517,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
/** /**
* Gets the site's node reference based on its short name * Gets the site's node reference based on its short name
* *
* @param shortName short name * @param shortName
* short name
* @return NodeRef node reference * @return NodeRef node reference
*/ */
private NodeRef getSiteNodeRef(String shortName) private NodeRef getSiteNodeRef(String shortName)
@@ -480,9 +526,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
NodeRef result = null; NodeRef result = null;
NodeRef siteRoot = getSiteParent(shortName); NodeRef siteRoot = getSiteParent(shortName);
List<ChildAssociationRef> assoc = this.nodeService.getChildAssocs( List<ChildAssociationRef> assoc = this.nodeService.getChildAssocs(
siteRoot, siteRoot, ContentModel.ASSOC_CONTAINS, QName.createQName(
ContentModel.ASSOC_CONTAINS, NamespaceService.CONTENT_MODEL_1_0_URI, shortName));
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, shortName));
if (assoc.size() == 1) if (assoc.size() == 1)
{ {
result = assoc.get(0).getChildRef(); result = assoc.get(0).getChildRef();
@@ -498,30 +543,35 @@ public class SiteServiceImpl implements SiteService, SiteModel
NodeRef siteNodeRef = getSiteNodeRef(siteInfo.getShortName()); NodeRef siteNodeRef = getSiteNodeRef(siteInfo.getShortName());
if (siteNodeRef == null) if (siteNodeRef == null)
{ {
throw new AlfrescoRuntimeException("Can not update site " + siteInfo.getShortName() + " because it does not exist."); throw new AlfrescoRuntimeException("Can not update site "
+ siteInfo.getShortName() + " because it does not exist.");
} }
// Note: the site preset and short name can not be updated // Note: the site preset and short name can not be updated
// Update the properties of the site // Update the properties of the site
Map<QName, Serializable> properties = this.nodeService.getProperties(siteNodeRef); Map<QName, Serializable> properties = this.nodeService
.getProperties(siteNodeRef);
properties.put(ContentModel.PROP_TITLE, siteInfo.getTitle()); properties.put(ContentModel.PROP_TITLE, siteInfo.getTitle());
properties.put(ContentModel.PROP_DESCRIPTION, siteInfo.getDescription()); properties
.put(ContentModel.PROP_DESCRIPTION, siteInfo.getDescription());
this.nodeService.setProperties(siteNodeRef, properties); this.nodeService.setProperties(siteNodeRef, properties);
// Update the isPublic flag // Update the isPublic flag
boolean isPublic = isSitePublic(siteNodeRef); boolean isPublic = isSitePublic(siteNodeRef);
if (isPublic != siteInfo.getIsPublic()); if (isPublic != siteInfo.getIsPublic())
;
{ {
if (siteInfo.getIsPublic() == true) if (siteInfo.getIsPublic() == true)
{ {
// Add the permission // Add the permission
this.permissionService.setPermission(siteNodeRef, PermissionService.ALL_AUTHORITIES, SITE_CONSUMER, true); this.permissionService.setPermission(siteNodeRef,
} PermissionService.ALL_AUTHORITIES, SITE_CONSUMER, true);
else } else
{ {
// Remove the permission // Remove the permission
this.permissionService.deletePermission(siteNodeRef, PermissionService.ALL_AUTHORITIES, SITE_CONSUMER); this.permissionService.deletePermission(siteNodeRef,
PermissionService.ALL_AUTHORITIES, SITE_CONSUMER);
} }
} }
} }
@@ -534,15 +584,15 @@ public class SiteServiceImpl implements SiteService, SiteModel
NodeRef siteNodeRef = getSiteNodeRef(shortName); NodeRef siteNodeRef = getSiteNodeRef(shortName);
if (siteNodeRef == null) if (siteNodeRef == null)
{ {
throw new AlfrescoRuntimeException("Can not delete site " + shortName + " because it does not exist."); throw new AlfrescoRuntimeException("Can not delete site "
+ shortName + " because it does not exist.");
} }
// Delete the node // Delete the node
this.nodeService.deleteNode(siteNodeRef); this.nodeService.deleteNode(siteNodeRef);
// Delete the associatated group's // Delete the associatated group's
AuthenticationUtil.runAs( AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>()
new AuthenticationUtil.RunAsWork<Object>()
{ {
public Object doWork() throws Exception public Object doWork() throws Exception
{ {
@@ -553,35 +603,51 @@ public class SiteServiceImpl implements SiteService, SiteModel
} }
/** /**
* @see org.alfresco.repo.site.SiteService#listMembers(java.lang.String, java.lang.String, java.lang.String) * @see org.alfresco.repo.site.SiteService#listMembers(java.lang.String,
* java.lang.String, java.lang.String)
*/ */
public Map<String, String> listMembers(String shortName, String nameFilter, String roleFilter) public Map<String, String> listMembers(String shortName, String nameFilter,
String roleFilter)
{ {
NodeRef siteNodeRef = getSiteNodeRef(shortName); NodeRef siteNodeRef = getSiteNodeRef(shortName);
if (siteNodeRef == null) if (siteNodeRef == null)
{ {
throw new AlfrescoRuntimeException("Site " + shortName + " does not exist."); throw new AlfrescoRuntimeException("Site " + shortName
+ " does not exist.");
} }
Map<String, String> members = new HashMap<String, String>(23); Map<String, String> members = new HashMap<String, String>(23);
Set<String> permissions = permissionService.getSettablePermissions(SiteModel.TYPE_SITE); Set<String> permissions = permissionService
.getSettablePermissions(SiteModel.TYPE_SITE);
for (String permission : permissions) for (String permission : permissions)
{
if (roleFilter == null ||
roleFilter.length() == 0 ||
roleFilter.equals(permission) == true)
{ {
String groupName = getSiteRoleGroup(shortName, permission, true); String groupName = getSiteRoleGroup(shortName, permission, true);
Set<String> users = this.authorityService.getContainedAuthorities(AuthorityType.USER, groupName, true); Set<String> users = this.authorityService.getContainedAuthorities(
AuthorityType.USER, groupName, true);
for (String user : users) for (String user : users)
{
if (nameFilter == null ||
nameFilter.length() == 0 ||
nameFilter.equals(user) == true)
{ {
// Add the user and their permission to the returned map // Add the user and their permission to the returned map
members.put(user, permission); members.put(user, permission);
} }
} }
}
}
return members; return members;
} }
/** /**
* @see org.alfresco.repo.site.SiteService#getMembersRole(java.lang.String, java.lang.String) * @see org.alfresco.repo.site.SiteService#getMembersRole(java.lang.String,
* java.lang.String)
*/ */
public String getMembersRole(String shortName, String userName) public String getMembersRole(String shortName, String userName)
{ {
@@ -592,7 +658,7 @@ public class SiteServiceImpl implements SiteService, SiteModel
int index = group.lastIndexOf('_'); int index = group.lastIndexOf('_');
if (index != -1) if (index != -1)
{ {
result = group.substring(index+1); result = group.substring(index + 1);
} }
} }
return result; return result;
@@ -602,17 +668,21 @@ public class SiteServiceImpl implements SiteService, SiteModel
* Helper method to get the permission group for a given user on a site. * Helper method to get the permission group for a given user on a site.
* Returns null if the user does not have a explicit membership to the site. * Returns null if the user does not have a explicit membership to the site.
* *
* @param siteShortName site short name * @param siteShortName
* @param userName user name * site short name
* @param userName
* user name
* @return String permission group, null if no explicit membership set * @return String permission group, null if no explicit membership set
*/ */
private String getPermissionGroup(String siteShortName, String userName) private String getPermissionGroup(String siteShortName, String userName)
{ {
String result = null; String result = null;
Set<String> groups = this.authorityService.getContainingAuthorities(AuthorityType.GROUP, userName, true); Set<String> groups = this.authorityService.getContainingAuthorities(
AuthorityType.GROUP, userName, true);
for (String group : groups) for (String group : groups)
{ {
if (group.startsWith(PermissionService.GROUP_PREFIX + "site_" + siteShortName) == true) if (group.startsWith(PermissionService.GROUP_PREFIX + "site_"
+ siteShortName) == true)
{ {
result = group; result = group;
break; break;
@@ -626,12 +696,14 @@ public class SiteServiceImpl implements SiteService, SiteModel
*/ */
public List<String> getSiteRoles() public List<String> getSiteRoles()
{ {
Set<String> permissions = permissionService.getSettablePermissions(SiteModel.TYPE_SITE); Set<String> permissions = permissionService
.getSettablePermissions(SiteModel.TYPE_SITE);
return new ArrayList<String>(permissions); return new ArrayList<String>(permissions);
} }
/** /**
* @see org.alfresco.repo.site.SiteService#isMember(java.lang.String, java.lang.String) * @see org.alfresco.repo.site.SiteService#isMember(java.lang.String,
* java.lang.String)
*/ */
public boolean isMember(String shortName, String userName) public boolean isMember(String shortName, String userName)
{ {
@@ -639,17 +711,20 @@ public class SiteServiceImpl implements SiteService, SiteModel
} }
/** /**
* @see org.alfresco.repo.site.SiteService#removeMembership(java.lang.String, java.lang.String) * @see org.alfresco.repo.site.SiteService#removeMembership(java.lang.String,
* java.lang.String)
*/ */
public void removeMembership(final String shortName, final String userName) public void removeMembership(final String shortName, final String userName)
{ {
final NodeRef siteNodeRef = getSiteNodeRef(shortName); final NodeRef siteNodeRef = getSiteNodeRef(shortName);
if (siteNodeRef == null) if (siteNodeRef == null)
{ {
throw new AlfrescoRuntimeException("Site " + shortName + " does not exist."); throw new AlfrescoRuntimeException("Site " + shortName
+ " does not exist.");
} }
// TODO what do we do about the user if they are in a group that has rights to the site? // TODO what do we do about the user if they are in a group that has
// rights to the site?
// Determine whether the site is private or not // Determine whether the site is private or not
boolean isPublic = isSitePublic(siteNodeRef); boolean isPublic = isSitePublic(siteNodeRef);
@@ -664,13 +739,17 @@ public class SiteServiceImpl implements SiteService, SiteModel
// Check that we are not about to remove the last site manager // Check that we are not about to remove the last site manager
if (SiteModel.SITE_MANAGER.equals(role) == true) if (SiteModel.SITE_MANAGER.equals(role) == true)
{ {
Set<String> siteMangers = this.authorityService.getContainedAuthorities( Set<String> siteMangers = this.authorityService
.getContainedAuthorities(
AuthorityType.USER, AuthorityType.USER,
getSiteRoleGroup(shortName, SITE_MANAGER, true), getSiteRoleGroup(shortName, SITE_MANAGER, true),
true); true);
if (siteMangers.size() == 1) if (siteMangers.size() == 1)
{ {
throw new AlfrescoRuntimeException("A site requires at least one site manager. You can not remove '" + userName + "' from the site memebership because they are currently the only site manager."); throw new AlfrescoRuntimeException(
"A site requires at least one site manager. You can not remove '"
+ userName
+ "' from the site memebership because they are currently the only site manager.");
} }
} }
@@ -680,20 +759,24 @@ public class SiteServiceImpl implements SiteService, SiteModel
// -- the site is public and // -- the site is public and
// -- the user is ourselves and // -- the user is ourselves and
// -- the users current role is consumer // -- the users current role is consumer
if ((permissionService.hasPermission(siteNodeRef, PermissionService.CHANGE_PERMISSIONS) == AccessStatus.ALLOWED) if ((permissionService.hasPermission(siteNodeRef,
|| PermissionService.CHANGE_PERMISSIONS) == AccessStatus.ALLOWED)
(isPublic == true && || (isPublic == true
currentUserName.equals(userName) == true && && currentUserName.equals(userName) == true && role
role.equals(SiteModel.SITE_CONSUMER) == true)) .equals(SiteModel.SITE_CONSUMER) == true))
{ {
// Run as system user // Run as system user
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>() AuthenticationUtil.runAs(
new AuthenticationUtil.RunAsWork<Object>()
{ {
public Object doWork() throws Exception public Object doWork() throws Exception
{ {
// Remove the user from the current permission group // Remove the user from the current permission
String currentGroup = getSiteRoleGroup(shortName, role, true); // group
authorityService.removeAuthority(currentGroup, userName); String currentGroup = getSiteRoleGroup(
shortName, role, true);
authorityService.removeAuthority(currentGroup,
userName);
return null; return null;
} }
@@ -702,36 +785,44 @@ public class SiteServiceImpl implements SiteService, SiteModel
// Raise events // Raise events
if (AuthorityType.getAuthorityType(userName) == AuthorityType.USER) if (AuthorityType.getAuthorityType(userName) == AuthorityType.USER)
{ {
activityService.postActivity(ActivityType.SITE_USER_REMOVED, shortName, ACTIVITY_TOOL, getActivityData(userName, "")); activityService.postActivity(
} ActivityType.SITE_USER_REMOVED, shortName,
else ACTIVITY_TOOL, getActivityData(userName, ""));
} else
{ {
// TODO - update this, if sites support groups // TODO - update this, if sites support groups
logger.error("setMembership - failed to post activity: unexpected authority type: " + AuthorityType.getAuthorityType(userName)); logger
.error("setMembership - failed to post activity: unexpected authority type: "
+ AuthorityType.getAuthorityType(userName));
} }
} } else
else
{ {
// Throw a permission exception // Throw a permission exception
throw new AlfrescoRuntimeException("Access denied, user does not have permissions to delete membership details of the site '" + shortName + "'"); throw new AlfrescoRuntimeException(
"Access denied, user does not have permissions to delete membership details of the site '"
+ shortName + "'");
} }
} } else
else
{ {
// Throw a permission exception // Throw a permission exception
throw new AlfrescoRuntimeException("Access denied, user does not have permissions to delete membership details of the site '" + shortName + "'"); throw new AlfrescoRuntimeException(
"Access denied, user does not have permissions to delete membership details of the site '"
+ shortName + "'");
} }
} }
/** /**
* @see org.alfresco.repo.site.SiteService#setMembership(java.lang.String, java.lang.String, java.lang.String) * @see org.alfresco.repo.site.SiteService#setMembership(java.lang.String,
* java.lang.String, java.lang.String)
*/ */
public void setMembership(final String shortName, final String userName, final String role) public void setMembership(final String shortName, final String userName,
final String role)
{ {
final NodeRef siteNodeRef = getSiteNodeRef(shortName); final NodeRef siteNodeRef = getSiteNodeRef(shortName);
if (siteNodeRef == null) if (siteNodeRef == null)
{ {
throw new AlfrescoRuntimeException("Site " + shortName + " does not exist."); throw new AlfrescoRuntimeException("Site " + shortName
+ " does not exist.");
} }
// Get the user's current role // Get the user's current role
@@ -743,7 +834,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
// Determine whether the site is private or not // Determine whether the site is private or not
boolean isPublic = isSitePublic(siteNodeRef); boolean isPublic = isSitePublic(siteNodeRef);
// TODO if this is the only site manager do not downgrade their permissions // TODO if this is the only site manager do not downgrade their
// permissions
// If we are ... // If we are ...
// -- the current user has change permissions rights on the site // -- the current user has change permissions rights on the site
@@ -753,42 +845,51 @@ public class SiteServiceImpl implements SiteService, SiteModel
// -- the user being added is ourselves and // -- the user being added is ourselves and
// -- the member does not already have permissions // -- the member does not already have permissions
// ... then we can set the permissions as system user // ... then we can set the permissions as system user
final String currentUserName = AuthenticationUtil.getCurrentUserName(); final String currentUserName = AuthenticationUtil
if ((permissionService.hasPermission(siteNodeRef, PermissionService.CHANGE_PERMISSIONS) == AccessStatus.ALLOWED) .getCurrentUserName();
|| if ((permissionService.hasPermission(siteNodeRef,
(isPublic == true && PermissionService.CHANGE_PERMISSIONS) == AccessStatus.ALLOWED)
role.equals(SiteModel.SITE_CONSUMER) == true && || (isPublic == true
userName.equals(currentUserName) == true && && role.equals(SiteModel.SITE_CONSUMER) == true
currentRole == null)) && userName.equals(currentUserName) == true && currentRole == null))
{ {
// Check that we are not about to remove the last site manager // Check that we are not about to remove the last site manager
if (SiteModel.SITE_MANAGER.equals(currentRole) == true) if (SiteModel.SITE_MANAGER.equals(currentRole) == true)
{ {
Set<String> siteMangers = this.authorityService.getContainedAuthorities( Set<String> siteMangers = this.authorityService
AuthorityType.USER, .getContainedAuthorities(AuthorityType.USER,
getSiteRoleGroup(shortName, SITE_MANAGER, true), getSiteRoleGroup(shortName, SITE_MANAGER,
true); true), true);
if (siteMangers.size() == 1) if (siteMangers.size() == 1)
{ {
throw new AlfrescoRuntimeException("A site requires at least one site manager. You can not change '" + userName + "' role from the site memebership because they are currently the only site manager."); throw new AlfrescoRuntimeException(
"A site requires at least one site manager. You can not change '"
+ userName
+ "' role from the site memebership because they are currently the only site manager.");
} }
} }
// Run as system user // Run as system user
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>() AuthenticationUtil.runAs(
new AuthenticationUtil.RunAsWork<Object>()
{ {
public Object doWork() throws Exception public Object doWork() throws Exception
{ {
if (currentRole != null) if (currentRole != null)
{ {
// Remove the user from the current permission group // Remove the user from the current
String currentGroup = getSiteRoleGroup(shortName, currentRole, true); // permission group
authorityService.removeAuthority(currentGroup, userName); String currentGroup = getSiteRoleGroup(
shortName, currentRole, true);
authorityService.removeAuthority(
currentGroup, userName);
} }
// Add the user to the new permission group // Add the user to the new permission group
String newGroup = getSiteRoleGroup(shortName, role, true); String newGroup = getSiteRoleGroup(shortName,
authorityService.addAuthority(newGroup, userName); role, true);
authorityService.addAuthority(newGroup,
userName);
return null; return null;
} }
@@ -799,42 +900,53 @@ public class SiteServiceImpl implements SiteService, SiteModel
{ {
if (AuthorityType.getAuthorityType(userName) == AuthorityType.USER) if (AuthorityType.getAuthorityType(userName) == AuthorityType.USER)
{ {
activityService.postActivity(ActivityType.SITE_USER_JOINED, shortName, ACTIVITY_TOOL, getActivityData(userName, role)); activityService.postActivity(
} ActivityType.SITE_USER_JOINED, shortName,
else ACTIVITY_TOOL, getActivityData(userName, role));
} else
{ {
// TODO - update this, if sites support groups // TODO - update this, if sites support groups
logger.error("setMembership - failed to post activity: unexpected authority type: " + AuthorityType.getAuthorityType(userName)); logger
.error("setMembership - failed to post activity: unexpected authority type: "
+ AuthorityType
.getAuthorityType(userName));
} }
} } else
else
{ {
if (AuthorityType.getAuthorityType(userName) == AuthorityType.USER) if (AuthorityType.getAuthorityType(userName) == AuthorityType.USER)
{ {
activityService.postActivity(ActivityType.SITE_USER_ROLE_UPDATE, shortName, ACTIVITY_TOOL, getActivityData(userName, role)); activityService.postActivity(
} ActivityType.SITE_USER_ROLE_UPDATE, shortName,
else ACTIVITY_TOOL, getActivityData(userName, role));
} else
{ {
// TODO - update this, if sites support groups // TODO - update this, if sites support groups
logger.error("setMembership - failed to post activity: unexpected authority type: " + AuthorityType.getAuthorityType(userName)); logger
.error("setMembership - failed to post activity: unexpected authority type: "
+ AuthorityType
.getAuthorityType(userName));
} }
} }
} } else
else
{ {
// Raise a permission exception // Raise a permission exception
throw new AlfrescoRuntimeException("Access denied, user does not have permissions to modify membership details of the site '" + shortName + "'"); throw new AlfrescoRuntimeException(
"Access denied, user does not have permissions to modify membership details of the site '"
+ shortName + "'");
} }
} }
} }
/** /**
* @see org.alfresco.repo.site.SiteService#createContainer(java.lang.String, java.lang.String, org.alfresco.service.namespace.QName, java.util.Map) * @see org.alfresco.repo.site.SiteService#createContainer(java.lang.String,
* java.lang.String, org.alfresco.service.namespace.QName,
* java.util.Map)
*/ */
public NodeRef createContainer(String shortName, String componentId, QName containerType, Map<QName, Serializable> containerProperties) public NodeRef createContainer(String shortName, String componentId,
QName containerType, Map<QName, Serializable> containerProperties)
{ {
// Check for the component id // Check for the component id
if (componentId == null || componentId.length() ==0) if (componentId == null || componentId.length() == 0)
{ {
throw new AlfrescoRuntimeException("Component id not provided"); throw new AlfrescoRuntimeException("Component id not provided");
} }
@@ -843,7 +955,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
NodeRef siteNodeRef = getSiteNodeRef(shortName); NodeRef siteNodeRef = getSiteNodeRef(shortName);
if (siteNodeRef == null) if (siteNodeRef == null)
{ {
throw new AlfrescoRuntimeException("Site " + shortName + " does not exist."); throw new AlfrescoRuntimeException("Site " + shortName
+ " does not exist.");
} }
// retrieve component folder within site // retrieve component folder within site
@@ -851,8 +964,7 @@ public class SiteServiceImpl implements SiteService, SiteModel
try try
{ {
containerNodeRef = findContainer(siteNodeRef, componentId); containerNodeRef = findContainer(siteNodeRef, componentId);
} } catch (FileNotFoundException e)
catch(FileNotFoundException e)
{ {
} }
@@ -865,7 +977,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
} }
// create component folder // create component folder
FileInfo fileInfo = fileFolderService.create(siteNodeRef, componentId, containerType); FileInfo fileInfo = fileFolderService.create(siteNodeRef,
componentId, containerType);
// Get the created container // Get the created container
containerNodeRef = fileInfo.getNodeRef(); containerNodeRef = fileInfo.getNodeRef();
@@ -873,15 +986,18 @@ public class SiteServiceImpl implements SiteService, SiteModel
// Set the properties if they have been provided // Set the properties if they have been provided
if (containerProperties != null) if (containerProperties != null)
{ {
Map<QName, Serializable> props = this.nodeService.getProperties(containerNodeRef); Map<QName, Serializable> props = this.nodeService
.getProperties(containerNodeRef);
props.putAll(containerProperties); props.putAll(containerProperties);
this.nodeService.setProperties(containerNodeRef, props); this.nodeService.setProperties(containerNodeRef, props);
} }
// Add the container aspect // Add the container aspect
Map<QName, Serializable> aspectProps = new HashMap<QName, Serializable>(1); Map<QName, Serializable> aspectProps = new HashMap<QName, Serializable>(
1);
aspectProps.put(SiteModel.PROP_COMPONENT_ID, componentId); aspectProps.put(SiteModel.PROP_COMPONENT_ID, componentId);
this.nodeService.addAspect(containerNodeRef, ASPECT_SITE_CONTAINER, aspectProps); this.nodeService.addAspect(containerNodeRef, ASPECT_SITE_CONTAINER,
aspectProps);
// Make the container a tag scope // Make the container a tag scope
this.taggingService.addTagScope(containerNodeRef); this.taggingService.addTagScope(containerNodeRef);
@@ -895,7 +1011,7 @@ public class SiteServiceImpl implements SiteService, SiteModel
*/ */
public NodeRef getContainer(String shortName, String componentId) public NodeRef getContainer(String shortName, String componentId)
{ {
if (componentId == null || componentId.length() ==0) if (componentId == null || componentId.length() == 0)
{ {
throw new AlfrescoRuntimeException("Component id not provided"); throw new AlfrescoRuntimeException("Component id not provided");
} }
@@ -904,7 +1020,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
NodeRef siteNodeRef = getSiteNodeRef(shortName); NodeRef siteNodeRef = getSiteNodeRef(shortName);
if (siteNodeRef == null) if (siteNodeRef == null)
{ {
throw new AlfrescoRuntimeException("Site " + shortName + " does not exist."); throw new AlfrescoRuntimeException("Site " + shortName
+ " does not exist.");
} }
// retrieve component folder within site // retrieve component folder within site
@@ -913,8 +1030,7 @@ public class SiteServiceImpl implements SiteService, SiteModel
try try
{ {
containerNodeRef = findContainer(siteNodeRef, componentId); containerNodeRef = findContainer(siteNodeRef, componentId);
} } catch (FileNotFoundException e)
catch(FileNotFoundException e)
{ {
} }
@@ -926,7 +1042,7 @@ public class SiteServiceImpl implements SiteService, SiteModel
*/ */
public boolean hasContainer(String shortName, String componentId) public boolean hasContainer(String shortName, String componentId)
{ {
if (componentId == null || componentId.length() ==0) if (componentId == null || componentId.length() == 0)
{ {
throw new AlfrescoRuntimeException("Component id not provided"); throw new AlfrescoRuntimeException("Component id not provided");
} }
@@ -935,7 +1051,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
NodeRef siteNodeRef = getSiteNodeRef(shortName); NodeRef siteNodeRef = getSiteNodeRef(shortName);
if (siteNodeRef == null) if (siteNodeRef == null)
{ {
throw new AlfrescoRuntimeException("Site " + shortName + " does not exist."); throw new AlfrescoRuntimeException("Site " + shortName
+ " does not exist.");
} }
// retrieve component folder within site // retrieve component folder within site
@@ -945,8 +1062,7 @@ public class SiteServiceImpl implements SiteService, SiteModel
{ {
findContainer(siteNodeRef, componentId); findContainer(siteNodeRef, componentId);
hasContainer = true; hasContainer = true;
} } catch (FileNotFoundException e)
catch(FileNotFoundException e)
{ {
} }
@@ -956,8 +1072,10 @@ public class SiteServiceImpl implements SiteService, SiteModel
/** /**
* Locate site "container" folder for component * Locate site "container" folder for component
* *
* @param siteNodeRef site * @param siteNodeRef
* @param componentId component id * site
* @param componentId
* component id
* @return "container" node ref, if it exists * @return "container" node ref, if it exists
* @throws FileNotFoundException * @throws FileNotFoundException
*/ */
@@ -966,10 +1084,12 @@ public class SiteServiceImpl implements SiteService, SiteModel
{ {
List<String> paths = new ArrayList<String>(1); List<String> paths = new ArrayList<String>(1);
paths.add(componentId); paths.add(componentId);
FileInfo fileInfo = fileFolderService.resolveNamePath(siteNodeRef, paths); FileInfo fileInfo = fileFolderService.resolveNamePath(siteNodeRef,
paths);
if (!fileInfo.isFolder()) if (!fileInfo.isFolder())
{ {
throw new AlfrescoRuntimeException("Site container " + fileInfo.getName() + " does not refer to a folder "); throw new AlfrescoRuntimeException("Site container "
+ fileInfo.getName() + " does not refer to a folder ");
} }
return fileInfo.getNodeRef(); return fileInfo.getNodeRef();
} }
@@ -981,8 +1101,10 @@ public class SiteServiceImpl implements SiteService, SiteModel
NodeRef person = personService.getPerson(userName); NodeRef person = personService.getPerson(userName);
if (person != null) if (person != null)
{ {
memberFN = (String)nodeService.getProperty(person, ContentModel.PROP_FIRSTNAME); memberFN = (String) nodeService.getProperty(person,
memberLN = (String)nodeService.getProperty(person, ContentModel.PROP_LASTNAME); ContentModel.PROP_FIRSTNAME);
memberLN = (String) nodeService.getProperty(person,
ContentModel.PROP_LASTNAME);
} }
try try
@@ -992,10 +1114,10 @@ public class SiteServiceImpl implements SiteService, SiteModel
activityData.put("memberUserName", userName); activityData.put("memberUserName", userName);
activityData.put("memberFirstName", memberFN); activityData.put("memberFirstName", memberFN);
activityData.put("memberLastName", memberLN); activityData.put("memberLastName", memberLN);
activityData.put("title", (memberFN + " " + memberLN + " (" + userName + ")").trim()); activityData.put("title", (memberFN + " " + memberLN + " ("
+ userName + ")").trim());
return activityData.toString(); return activityData.toString();
} } catch (JSONException je)
catch (JSONException je)
{ {
// log error, subsume exception // log error, subsume exception
logger.error("Failed to get activity data: " + je); logger.error("Failed to get activity data: " + je);

View File

@@ -374,6 +374,20 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest
assertTrue(members.containsKey(USER_THREE)); assertTrue(members.containsKey(USER_THREE));
assertEquals(SiteModel.SITE_COLLABORATOR, members.get(USER_THREE)); assertEquals(SiteModel.SITE_COLLABORATOR, members.get(USER_THREE));
// Get only the site managers
members = this.siteService.listMembers("testMembership", null, SiteModel.SITE_MANAGER);
assertNotNull(members);
assertEquals(1, members.size());
assertTrue(members.containsKey(USER_ONE));
assertEquals(SiteModel.SITE_MANAGER, members.get(USER_ONE));
// Get only user two
members = this.siteService.listMembers("testMembership", USER_TWO, null);
assertNotNull(members);
assertEquals(1, members.size());
assertTrue(members.containsKey(USER_TWO));
assertEquals(SiteModel.SITE_CONSUMER, members.get(USER_TWO));
// Change the membership of user two // Change the membership of user two
this.siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_COLLABORATOR); this.siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_COLLABORATOR);

View File

@@ -84,8 +84,15 @@ public class TenantInterpreter extends BaseInterpreter
try try
{ {
AuthenticationUtil.setSystemUserAsCurrentUser(); AuthenticationUtil.setSystemUserAsCurrentUser();
RetryingTransactionCallback<String> txnWork = new RetryingTransactionCallback<String>()
{
public String execute() throws Exception
{
return executeCommand(line); return executeCommand(line);
} }
};
return transactionService.getRetryingTransactionHelper().doInTransaction(txnWork);
}
finally finally
{ {
AuthenticationUtil.setCurrentUser(currentUserName); AuthenticationUtil.setCurrentUser(currentUserName);
@@ -323,17 +330,10 @@ public class TenantInterpreter extends BaseInterpreter
AuthenticationUtil.runAs(new RunAsWork<Object>() AuthenticationUtil.runAs(new RunAsWork<Object>()
{ {
public Object doWork() throws Exception public Object doWork() throws Exception
{
RetryingTransactionCallback<Object> txnWork = new RetryingTransactionCallback<Object>()
{
public Object execute() throws Exception
{ {
authenticationService.setAuthentication(tenantAdminUsername, newPassword.toCharArray()); authenticationService.setAuthentication(tenantAdminUsername, newPassword.toCharArray());
return null; return null;
} }
};
return transactionService.getRetryingTransactionHelper().doInTransaction(txnWork);
}
}, tenantAdminUsername); }, tenantAdminUsername);
} }

View File

@@ -49,17 +49,21 @@ import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.GUID; import org.alfresco.util.GUID;
import org.alfresco.util.ParameterCheck; import org.alfresco.util.ParameterCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/** /**
* @author Roy Wetherall * @author Roy Wetherall
*/ */
public class ThumbnailServiceImpl implements ThumbnailService public class ThumbnailServiceImpl implements ThumbnailService
{ {
/** Logger */
private static Log logger = LogFactory.getLog(ThumbnailServiceImpl.class);
/** Error messages */ /** Error messages */
private static final String ERR_NO_CREATE = "Thumbnail could not be created as required transformation is not supported from {0} to {1}"; private static final String ERR_NO_CREATE = "Thumbnail could not be created as required transformation is not supported from {0} to {1}";
private static final String ERR_DUPLICATE_NAME = "Thumbnail could not be created because of a duplicate name"; private static final String ERR_DUPLICATE_NAME = "Thumbnail could not be created because of a duplicate name";
private static final String ERR_NO_PARENT = "Thumbnail has no parent so update cannot take place."; private static final String ERR_NO_PARENT = "Thumbnail has no parent so update cannot take place.";
private static final String ERR_TOO_PARENT = "Thumbnail has more than one source content node. This is invalid so update cannot take place.";
/** Node service */ /** Node service */
private NodeService nodeService; private NodeService nodeService;
@@ -140,11 +144,21 @@ public class ThumbnailServiceImpl implements ThumbnailService
ParameterCheck.mandatoryString( "mimetype", mimetype); ParameterCheck.mandatoryString( "mimetype", mimetype);
ParameterCheck.mandatory("transformationOptions", transformationOptions); ParameterCheck.mandatory("transformationOptions", transformationOptions);
if (logger.isDebugEnabled() == true)
{
logger.debug("Creating thumbnail (node=" + node.toString() + "; contentProperty=" + contentProperty.toString() + "; mimetype=" + mimetype);
}
NodeRef thumbnail = null; NodeRef thumbnail = null;
// Check for duplicate names // Check for duplicate names
if (thumbnailName != null && getThumbnailByName(node, contentProperty, thumbnailName) != null) if (thumbnailName != null && getThumbnailByName(node, contentProperty, thumbnailName) != null)
{ {
if (logger.isDebugEnabled() == true)
{
logger.debug("Creating thumbnail: There is already a thumbnail with the name '" + thumbnail + "' (node=" + node.toString() + "; contentProperty=" + contentProperty.toString() + "; mimetype=" + mimetype);
}
// We can't continue because there is already an thumnail with the given name for that content property // We can't continue because there is already an thumnail with the given name for that content property
throw new ThumbnailException(ERR_DUPLICATE_NAME); throw new ThumbnailException(ERR_DUPLICATE_NAME);
} }
@@ -209,6 +223,11 @@ public class ThumbnailServiceImpl implements ThumbnailService
// Catch the failure to create the thumbnail // Catch the failure to create the thumbnail
if (this.contentService.isTransformable(reader, writer, transformationOptions) == false) if (this.contentService.isTransformable(reader, writer, transformationOptions) == false)
{ {
if (logger.isDebugEnabled() == true)
{
logger.debug("Creating thumbnail: There is no transformer to generate the thumbnail required (node=" + node.toString() + "; contentProperty=" + contentProperty.toString() + "; mimetype=" + mimetype + ")");
}
// Throw exception indicating that the thumbnail could not be created // Throw exception indicating that the thumbnail could not be created
throw new ThumbnailException(MessageFormat.format(ERR_NO_CREATE, reader.getMimetype(), writer.getMimetype())); throw new ThumbnailException(MessageFormat.format(ERR_NO_CREATE, reader.getMimetype(), writer.getMimetype()));
} }
@@ -239,6 +258,11 @@ public class ThumbnailServiceImpl implements ThumbnailService
*/ */
public void updateThumbnail(NodeRef thumbnail, TransformationOptions transformationOptions) public void updateThumbnail(NodeRef thumbnail, TransformationOptions transformationOptions)
{ {
if (logger.isDebugEnabled() == true)
{
logger.debug("Updating thumbnail (thumbnail=" + thumbnail.toString() + ")");
}
// First check that we are dealing with a thumbnail // First check that we are dealing with a thumbnail
if (ContentModel.TYPE_THUMBNAIL.equals(this.nodeService.getType(thumbnail)) == true) if (ContentModel.TYPE_THUMBNAIL.equals(this.nodeService.getType(thumbnail)) == true)
{ {
@@ -247,16 +271,13 @@ public class ThumbnailServiceImpl implements ThumbnailService
List<ChildAssociationRef> parents = this.nodeService.getParentAssocs(thumbnail, ContentModel.ASSOC_THUMBNAILS, RegexQNamePattern.MATCH_ALL); List<ChildAssociationRef> parents = this.nodeService.getParentAssocs(thumbnail, ContentModel.ASSOC_THUMBNAILS, RegexQNamePattern.MATCH_ALL);
if (parents.size() == 0) if (parents.size() == 0)
{ {
if (logger.isDebugEnabled() == true)
{
logger.debug("Updating thumbnail: The thumbnails parent cannot be found (thumbnail=" + thumbnail.toString() + ")");
}
throw new ThumbnailException(ERR_NO_PARENT); throw new ThumbnailException(ERR_NO_PARENT);
} }
// TODO
// When a node with thumbnails is checked in the assoc's get doubled up. This means we get more than one parent.
// As a work around simply take the first parent retrieved
//
//else if (parents.size() != 1)
//{
// throw new ThumbnailException(ERR_TOO_PARENT);
//}
else else
{ {
node = parents.get(0).getParentRef(); node = parents.get(0).getParentRef();
@@ -278,6 +299,11 @@ public class ThumbnailServiceImpl implements ThumbnailService
// Catch the failure to create the thumbnail // Catch the failure to create the thumbnail
if (this.contentService.isTransformable(reader, writer, transformationOptions) == false) if (this.contentService.isTransformable(reader, writer, transformationOptions) == false)
{ {
if (logger.isDebugEnabled() == true)
{
logger.debug("Updating thumbnail: there is not transformer to update the thumbnail with (thumbnail=" + thumbnail.toString() + ")");
}
// Throw exception indicating that the thumbnail could not be created // Throw exception indicating that the thumbnail could not be created
throw new ThumbnailException(MessageFormat.format(ERR_NO_CREATE, reader.getMimetype(), writer.getMimetype())); throw new ThumbnailException(MessageFormat.format(ERR_NO_CREATE, reader.getMimetype(), writer.getMimetype()));
} }
@@ -287,7 +313,13 @@ public class ThumbnailServiceImpl implements ThumbnailService
this.contentService.transform(reader, writer, transformationOptions); this.contentService.transform(reader, writer, transformationOptions);
} }
} }
// TODO else should we throw an exception? else
{
if (logger.isDebugEnabled() == true)
{
logger.debug("Updating thumbnail: cannot update a thumbnail node that isn't the correct thumbnail type (thumbnail=" + thumbnail.toString() + ")");
}
}
} }
/** /**
@@ -304,6 +336,11 @@ public class ThumbnailServiceImpl implements ThumbnailService
// If retrieval performance becomes an issue then this code can be replaced // If retrieval performance becomes an issue then this code can be replaced
// //
if (logger.isDebugEnabled() == true)
{
logger.debug("Getting thumbnail by name (nodeRef=" + node.toString() + "; contentProperty=" + contentProperty.toString() + "; thumbnailName=" + thumbnailName + ")");
}
// Check that the node has the thumbnailed aspect applied // Check that the node has the thumbnailed aspect applied
if (nodeService.hasAspect(node, ContentModel.ASPECT_THUMBNAILED) == true) if (nodeService.hasAspect(node, ContentModel.ASPECT_THUMBNAILED) == true)
{ {
@@ -339,6 +376,11 @@ public class ThumbnailServiceImpl implements ThumbnailService
// If retrieval performance becomes an issue then this code can be replaced // If retrieval performance becomes an issue then this code can be replaced
// //
if (logger.isDebugEnabled() == true)
{
logger.debug("Getting thumbnails (nodeRef=" + node.toString() + "; contentProperty=" + contentProperty.toString() + "; mimetype=" + mimetype + ")");
}
// Check that the node has the thumbnailed aspect applied // Check that the node has the thumbnailed aspect applied
if (nodeService.hasAspect(node, ContentModel.ASPECT_THUMBNAILED) == true) if (nodeService.hasAspect(node, ContentModel.ASPECT_THUMBNAILED) == true)
{ {