mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-QA to HEAD (4.2) (including moving test classes into separate folders)
51903 to 54309 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@54310 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
@@ -14,184 +14,184 @@
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.web.bean.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.web.bean.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.alfresco.model.ApplicationModel;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.SessionUser;
|
||||
import org.alfresco.repo.configuration.ConfigurableService;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
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.search.SearchService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
|
||||
import org.alfresco.model.ApplicationModel;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.SessionUser;
|
||||
import org.alfresco.repo.configuration.ConfigurableService;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
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.search.SearchService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
import org.springframework.web.jsf.FacesContextUtils;
|
||||
|
||||
/**
|
||||
* Bean that represents the currently logged in user
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public final class User implements SessionUser
|
||||
{
|
||||
private static final long serialVersionUID = -90577901805847829L;
|
||||
|
||||
private String companyRootId;
|
||||
private String homeSpaceId;
|
||||
private String userName;
|
||||
private String ticket;
|
||||
private NodeRef person;
|
||||
private String fullName = null;
|
||||
private Boolean administrator = null;
|
||||
|
||||
private Preferences preferences = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param userName constructor for the user
|
||||
*/
|
||||
public User(String userName, String ticket, NodeRef person)
|
||||
{
|
||||
if (userName == null || ticket == null || person == null)
|
||||
{
|
||||
throw new IllegalArgumentException("All user details are mandatory!");
|
||||
}
|
||||
|
||||
this.userName = userName;
|
||||
this.ticket = ticket;
|
||||
this.person = person;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces a clear of any cached or calcluated values
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
this.fullName = null;
|
||||
this.administrator = null;
|
||||
this.preferences = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The user name
|
||||
*/
|
||||
public String getUserName()
|
||||
{
|
||||
return this.userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the full name of the Person this User represents
|
||||
*
|
||||
* @param service NodeService to use
|
||||
*
|
||||
* @return The full name
|
||||
*/
|
||||
public String getFullName(NodeService service)
|
||||
{
|
||||
if (this.fullName == null)
|
||||
{
|
||||
String firstName = (String)service.getProperty(this.person, ContentModel.PROP_FIRSTNAME);
|
||||
String lastName = (String)service.getProperty(this.person, ContentModel.PROP_LASTNAME);
|
||||
this.fullName = (firstName != null ? firstName : "") + ' ' + (lastName != null ? lastName : "");
|
||||
}
|
||||
|
||||
return this.fullName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Retrieves the user's home space (this may be the id of the company home space)
|
||||
*/
|
||||
public String getHomeSpaceId()
|
||||
{
|
||||
return this.homeSpaceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param homeSpaceId Sets the id of the users home space
|
||||
*/
|
||||
public void setHomeSpaceId(String homeSpaceId)
|
||||
{
|
||||
this.homeSpaceId = homeSpaceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Retrieves the company home space
|
||||
*/
|
||||
public String getCompanyRootId()
|
||||
{
|
||||
return this.companyRootId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param companyRootId Sets the id of the company home space
|
||||
*/
|
||||
public void setCompanyRootId(String companyRootId)
|
||||
{
|
||||
this.companyRootId = companyRootId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the ticket.
|
||||
*/
|
||||
public String getTicket()
|
||||
{
|
||||
return this.ticket;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the person NodeRef
|
||||
*/
|
||||
public NodeRef getPerson()
|
||||
{
|
||||
return this.person;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return If the current user has Admin Authority
|
||||
*/
|
||||
public boolean isAdmin()
|
||||
{
|
||||
if (administrator == null)
|
||||
{
|
||||
administrator = Repository.getServiceRegistry(FacesContext.getCurrentInstance())
|
||||
.getAuthorityService().hasAdminAuthority();
|
||||
}
|
||||
|
||||
return administrator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The Preferences for the User
|
||||
*/
|
||||
|
||||
/**
|
||||
* Bean that represents the currently logged in user
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public final class User implements SessionUser
|
||||
{
|
||||
private static final long serialVersionUID = -90577901805847829L;
|
||||
|
||||
private String companyRootId;
|
||||
private String homeSpaceId;
|
||||
private String userName;
|
||||
private String ticket;
|
||||
private NodeRef person;
|
||||
private String fullName = null;
|
||||
private Boolean administrator = null;
|
||||
|
||||
private Preferences preferences = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param userName constructor for the user
|
||||
*/
|
||||
public User(String userName, String ticket, NodeRef person)
|
||||
{
|
||||
if (userName == null || ticket == null || person == null)
|
||||
{
|
||||
throw new IllegalArgumentException("All user details are mandatory!");
|
||||
}
|
||||
|
||||
this.userName = userName;
|
||||
this.ticket = ticket;
|
||||
this.person = person;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces a clear of any cached or calcluated values
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
this.fullName = null;
|
||||
this.administrator = null;
|
||||
this.preferences = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The user name
|
||||
*/
|
||||
public String getUserName()
|
||||
{
|
||||
return this.userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the full name of the Person this User represents
|
||||
*
|
||||
* @param service NodeService to use
|
||||
*
|
||||
* @return The full name
|
||||
*/
|
||||
public String getFullName(NodeService service)
|
||||
{
|
||||
if (this.fullName == null)
|
||||
{
|
||||
String firstName = (String)service.getProperty(this.person, ContentModel.PROP_FIRSTNAME);
|
||||
String lastName = (String)service.getProperty(this.person, ContentModel.PROP_LASTNAME);
|
||||
this.fullName = (firstName != null ? firstName : "") + ' ' + (lastName != null ? lastName : "");
|
||||
}
|
||||
|
||||
return this.fullName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Retrieves the user's home space (this may be the id of the company home space)
|
||||
*/
|
||||
public String getHomeSpaceId()
|
||||
{
|
||||
return this.homeSpaceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param homeSpaceId Sets the id of the users home space
|
||||
*/
|
||||
public void setHomeSpaceId(String homeSpaceId)
|
||||
{
|
||||
this.homeSpaceId = homeSpaceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Retrieves the company home space
|
||||
*/
|
||||
public String getCompanyRootId()
|
||||
{
|
||||
return this.companyRootId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param companyRootId Sets the id of the company home space
|
||||
*/
|
||||
public void setCompanyRootId(String companyRootId)
|
||||
{
|
||||
this.companyRootId = companyRootId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the ticket.
|
||||
*/
|
||||
public String getTicket()
|
||||
{
|
||||
return this.ticket;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the person NodeRef
|
||||
*/
|
||||
public NodeRef getPerson()
|
||||
{
|
||||
return this.person;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return If the current user has Admin Authority
|
||||
*/
|
||||
public boolean isAdmin()
|
||||
{
|
||||
if (administrator == null)
|
||||
{
|
||||
administrator = Repository.getServiceRegistry(FacesContext.getCurrentInstance())
|
||||
.getAuthorityService().hasAdminAuthority();
|
||||
}
|
||||
|
||||
return administrator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The Preferences for the User
|
||||
*/
|
||||
Preferences getPreferences(FacesContext fc)
|
||||
{
|
||||
if (this.preferences == null)
|
||||
{
|
||||
{
|
||||
if (this.preferences == null)
|
||||
{
|
||||
this.preferences = new Preferences(getUserPreferencesRef(
|
||||
FacesContextUtils.getRequiredWebApplicationContext(fc)));
|
||||
}
|
||||
return this.preferences;
|
||||
}
|
||||
|
||||
/**
|
||||
}
|
||||
return this.preferences;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The Preferences for the User
|
||||
*/
|
||||
Preferences getPreferences(ServletContext sc)
|
||||
@@ -205,88 +205,87 @@ public final class User implements SessionUser
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or create the node used to store user preferences.
|
||||
* Utilises the 'configurable' aspect on the Person linked to this user.
|
||||
*/
|
||||
* Get or create the node used to store user preferences.
|
||||
* Utilises the 'configurable' aspect on the Person linked to this user.
|
||||
*/
|
||||
synchronized NodeRef getUserPreferencesRef(WebApplicationContext context)
|
||||
{
|
||||
final ServiceRegistry registry = (ServiceRegistry) context.getBean("ServiceRegistry");
|
||||
final NodeService nodeService = registry.getNodeService();
|
||||
final SearchService searchService = registry.getSearchService();
|
||||
final NamespaceService namespaceService = registry.getNamespaceService();
|
||||
final TransactionService txService = registry.getTransactionService();
|
||||
final ConfigurableService configurableService = (ConfigurableService) context.getBean("ConfigurableService");
|
||||
RetryingTransactionHelper txnHelper = registry.getRetryingTransactionHelper();
|
||||
return txnHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
|
||||
{
|
||||
|
||||
public NodeRef execute() throws Throwable
|
||||
{
|
||||
NodeRef prefRef = null;
|
||||
NodeRef person = getPerson();
|
||||
if (nodeService.hasAspect(person, ApplicationModel.ASPECT_CONFIGURABLE) == false)
|
||||
{
|
||||
// if the repository is in read-only mode just return null
|
||||
if (txService.isReadOnly())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
// create the configuration folder for this Person node
|
||||
configurableService.makeConfigurable(person);
|
||||
}
|
||||
}
|
||||
|
||||
// target of the assoc is the configurations folder ref
|
||||
NodeRef configRef = configurableService.getConfigurationFolder(person);
|
||||
if (configRef == null)
|
||||
{
|
||||
throw new IllegalStateException("Unable to find associated 'configurations' folder for node: "
|
||||
+ person);
|
||||
}
|
||||
|
||||
String xpath = NamespaceService.APP_MODEL_PREFIX + ":" + "preferences";
|
||||
List<NodeRef> nodes = searchService.selectNodes(configRef, xpath, null, namespaceService, false);
|
||||
|
||||
if (nodes.size() == 1)
|
||||
{
|
||||
prefRef = nodes.get(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// create the preferences Node for this user (if repo is not read-only)
|
||||
if (txService.isReadOnly() == false)
|
||||
{
|
||||
final ServiceRegistry registry = (ServiceRegistry) context.getBean("ServiceRegistry");
|
||||
final NodeService nodeService = registry.getNodeService();
|
||||
final SearchService searchService = registry.getSearchService();
|
||||
final NamespaceService namespaceService = registry.getNamespaceService();
|
||||
final TransactionService txService = registry.getTransactionService();
|
||||
final ConfigurableService configurableService = (ConfigurableService) context.getBean("ConfigurableService");
|
||||
RetryingTransactionHelper txnHelper = registry.getTransactionService().getRetryingTransactionHelper();
|
||||
return txnHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
|
||||
{
|
||||
public NodeRef execute() throws Throwable
|
||||
{
|
||||
NodeRef prefRef = null;
|
||||
NodeRef person = getPerson();
|
||||
if (nodeService.hasAspect(person, ApplicationModel.ASPECT_CONFIGURABLE) == false)
|
||||
{
|
||||
// if the repository is in read-only mode just return null
|
||||
if (txService.isReadOnly())
|
||||
{
|
||||
ChildAssociationRef childRef = nodeService.createNode(configRef,
|
||||
ContentModel.ASSOC_CONTAINS, QName.createQName(
|
||||
NamespaceService.APP_MODEL_1_0_URI, "preferences"),
|
||||
ContentModel.TYPE_CMOBJECT);
|
||||
|
||||
prefRef = childRef.getChildRef();
|
||||
}
|
||||
}
|
||||
return prefRef;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full name of the user represented by the given NodeRef
|
||||
*
|
||||
* @param nodeService The node service instance
|
||||
* @param user The user to get the full name for
|
||||
* @return The full name
|
||||
*/
|
||||
public static String getFullName(NodeService nodeService, NodeRef user)
|
||||
{
|
||||
Map<QName, Serializable> props = nodeService.getProperties(user);
|
||||
String firstName = (String)props.get(ContentModel.PROP_FIRSTNAME);
|
||||
String lastName = (String)props.get(ContentModel.PROP_LASTNAME);
|
||||
String fullName = firstName + ((lastName != null && lastName.length() > 0) ? " " + lastName : "");
|
||||
|
||||
return fullName;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
// create the configuration folder for this Person node
|
||||
configurableService.makeConfigurable(person);
|
||||
}
|
||||
}
|
||||
|
||||
// target of the assoc is the configurations folder ref
|
||||
NodeRef configRef = configurableService.getConfigurationFolder(person);
|
||||
if (configRef == null)
|
||||
{
|
||||
throw new IllegalStateException("Unable to find associated 'configurations' folder for node: "
|
||||
+ person);
|
||||
}
|
||||
|
||||
String xpath = NamespaceService.APP_MODEL_PREFIX + ":" + "preferences";
|
||||
List<NodeRef> nodes = searchService.selectNodes(configRef, xpath, null, namespaceService, false);
|
||||
|
||||
if (nodes.size() == 1)
|
||||
{
|
||||
prefRef = nodes.get(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// create the preferences Node for this user (if repo is not read-only)
|
||||
if (txService.isReadOnly() == false)
|
||||
{
|
||||
ChildAssociationRef childRef = nodeService.createNode(configRef,
|
||||
ContentModel.ASSOC_CONTAINS, QName.createQName(
|
||||
NamespaceService.APP_MODEL_1_0_URI, "preferences"),
|
||||
ContentModel.TYPE_CMOBJECT);
|
||||
|
||||
prefRef = childRef.getChildRef();
|
||||
}
|
||||
}
|
||||
return prefRef;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full name of the user represented by the given NodeRef
|
||||
*
|
||||
* @param nodeService The node service instance
|
||||
* @param user The user to get the full name for
|
||||
* @return The full name
|
||||
*/
|
||||
public static String getFullName(NodeService nodeService, NodeRef user)
|
||||
{
|
||||
Map<QName, Serializable> props = nodeService.getProperties(user);
|
||||
String firstName = (String)props.get(ContentModel.PROP_FIRSTNAME);
|
||||
String lastName = (String)props.get(ContentModel.PROP_LASTNAME);
|
||||
String fullName = firstName + ((lastName != null && lastName.length() > 0) ? " " + lastName : "");
|
||||
|
||||
return fullName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full name of the user plus their userid in the form [id]
|
||||
@@ -313,4 +312,4 @@ public final class User implements SessionUser
|
||||
|
||||
return nameAndId.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user