mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged V2.1 to HEAD
6515: Fix for AWC-1362 (system error page when clicking on space that doesn't exist in navigator) 6516: Fix for AR-1688 - Vista 6518: Fix for AWC-1479, AWC-1199 and AWC-426 (javascript insertion into forum posts security related fixes) limit to subset of safe tags for posting 6519: Fix AR-1690 Web Scripts url.args is missing even though it's documented in WIKI 6520: Fix for AWC-1271 (component generator config ignored for associations) 6521: Fix AWC-1492 Some included javascript files in template/webscripts use the wrong app context path i.e. /alfresco when the app is called /alfzip 6522: Build fix 6523: - Fix rendering of tasks with no description in office portlets 6524: Added thread pool for index merging (AR-1633, AR-1579) 6525: One more fix for rendering of tasks with no description in office portlets 6527: Renamed axis jar to reflect version number. 6528: WebServices query cache refactoring git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6741 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -36,19 +36,19 @@ import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.cache.SimpleCache;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.repo.webservice.AbstractWebService;
|
||||
import org.alfresco.repo.webservice.Utils;
|
||||
import org.alfresco.repo.webservice.action.ActionFault;
|
||||
import org.alfresco.repo.webservice.repository.RepositoryFault;
|
||||
import org.alfresco.repo.webservice.types.NamedValue;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.apache.axis.MessageContext;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -74,9 +74,6 @@ public class AdministrationWebService extends AbstractWebService implements
|
||||
/** A set of ignored properties */
|
||||
private static Set<QName> ignoredProperties = new HashSet<QName>(3);
|
||||
|
||||
/** Simple cache used to store user query sessions */
|
||||
private SimpleCache<String, UserQuerySession> querySessionCache;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@@ -118,18 +115,6 @@ public class AdministrationWebService extends AbstractWebService implements
|
||||
this.authenticationService = authenticationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the instance of the SimpleCache to be used
|
||||
*
|
||||
* @param querySessionCache
|
||||
* The SimpleCache
|
||||
*/
|
||||
public void setQuerySessionCache(
|
||||
SimpleCache<String, UserQuerySession> querySessionCache)
|
||||
{
|
||||
this.querySessionCache = querySessionCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.webservice.administration.AdministrationServiceSoapPort#queryUsers(org.alfresco.repo.webservice.administration.UserFilter)
|
||||
*/
|
||||
@@ -168,18 +153,33 @@ public class AdministrationWebService extends AbstractWebService implements
|
||||
{
|
||||
MessageContext msgContext = MessageContext.getCurrentContext();
|
||||
|
||||
// Create the query
|
||||
UserQuery query = new UserQuery(filter);
|
||||
|
||||
// Create a user query session
|
||||
UserQuerySession userQuerySession = new UserQuerySession(Utils.getBatchSize(msgContext), filter);
|
||||
UserQueryResults userQueryResults = userQuerySession.getNextBatch();
|
||||
UserQuerySession userQuerySession = new UserQuerySession(Long.MAX_VALUE, Utils.getBatchSize(msgContext), query);
|
||||
|
||||
// Get the next batch of results
|
||||
UserQueryResults userQueryResults = userQuerySession.getNextResults(serviceRegistry);
|
||||
|
||||
String querySessionId = userQuerySession.getId();
|
||||
// add the session to the cache if there are more results to come
|
||||
if (userQueryResults.getQuerySession() != null)
|
||||
boolean haveMoreResults = userQuerySession.haveMoreResults();
|
||||
if (haveMoreResults)
|
||||
{
|
||||
// this.querySessionCache.putQuerySession(querySession);
|
||||
this.querySessionCache.put(userQueryResults.getQuerySession(), userQuerySession);
|
||||
querySessionCache.put(querySessionId, userQuerySession);
|
||||
}
|
||||
|
||||
return userQueryResults;
|
||||
// Construct the return value
|
||||
// TODO: http://issues.alfresco.com/browse/AR-1689
|
||||
// This looks odd, but I've chosen to be specific about when the ID is set on the return
|
||||
// results and when it isn't.
|
||||
UserQueryResults result = new UserQueryResults(
|
||||
haveMoreResults ? querySessionId : null,
|
||||
userQueryResults.getUserDetails());
|
||||
|
||||
// Done
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,20 +212,34 @@ public class AdministrationWebService extends AbstractWebService implements
|
||||
|
||||
/**
|
||||
*
|
||||
* @param querySession
|
||||
* @param querySessionId
|
||||
* @return
|
||||
*/
|
||||
private UserQueryResults fetchMoreUsersImpl(String querySession)
|
||||
private UserQueryResults fetchMoreUsersImpl(String querySessionId) throws RepositoryFault
|
||||
{
|
||||
UserQueryResults queryResult = null;
|
||||
UserQuerySession session = this.querySessionCache.get(querySession);
|
||||
UserQuerySession session = null;
|
||||
try
|
||||
{
|
||||
session = (UserQuerySession) querySessionCache.get(querySessionId);
|
||||
}
|
||||
catch (ClassCastException e)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Query session was not generated by the AdministrationWebService: " + querySessionId);
|
||||
}
|
||||
throw new RepositoryFault(
|
||||
4,
|
||||
"querySession with id '" + querySessionId + "' is invalid");
|
||||
}
|
||||
|
||||
UserQueryResults queryResult = null;
|
||||
if (session != null)
|
||||
{
|
||||
queryResult = session.getNextBatch();
|
||||
if (queryResult.getQuerySession() == null)
|
||||
queryResult = session.getNextResults(serviceRegistry);
|
||||
if (!session.haveMoreResults())
|
||||
{
|
||||
this.querySessionCache.remove(querySession);
|
||||
this.querySessionCache.remove(querySessionId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,12 +283,13 @@ public class AdministrationWebService extends AbstractWebService implements
|
||||
*/
|
||||
private UserDetails getUserImpl(String userName)
|
||||
{
|
||||
NodeService nodeService = serviceRegistry.getNodeService();
|
||||
UserDetails userDetails = null;
|
||||
|
||||
if (this.personService.personExists(userName) == true)
|
||||
{
|
||||
NodeRef nodeRef = this.personService.getPerson(userName);
|
||||
userDetails = createUserDetails(userName, nodeRef);
|
||||
userDetails = createUserDetails(nodeService, userName, nodeRef);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -291,7 +306,7 @@ public class AdministrationWebService extends AbstractWebService implements
|
||||
* @param nodeRef the node reference
|
||||
* @return the user details object populated with the appropriate property values
|
||||
*/
|
||||
private UserDetails createUserDetails(String userName, NodeRef nodeRef)
|
||||
/* package */ static UserDetails createUserDetails(NodeService nodeService, String userName, NodeRef nodeRef)
|
||||
{
|
||||
// Create the user details object
|
||||
UserDetails userDetails = new UserDetails();
|
||||
@@ -300,7 +315,7 @@ public class AdministrationWebService extends AbstractWebService implements
|
||||
userDetails.setUserName(userName);
|
||||
|
||||
// Set the various property values
|
||||
Map<QName, Serializable> properties = this.nodeService.getProperties(nodeRef);
|
||||
Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
|
||||
List<NamedValue> namedValues = new ArrayList<NamedValue>(properties.size());
|
||||
for (Map.Entry<QName, Serializable> entry : properties.entrySet())
|
||||
{
|
||||
@@ -364,6 +379,7 @@ public class AdministrationWebService extends AbstractWebService implements
|
||||
*/
|
||||
private UserDetails[] createUsersImpl(NewUserDetails[] newUsers)
|
||||
{
|
||||
NodeService nodeService = serviceRegistry.getNodeService();
|
||||
UserDetails[] userDetails = new UserDetails[newUsers.length];
|
||||
|
||||
int index = 0;
|
||||
@@ -382,7 +398,7 @@ public class AdministrationWebService extends AbstractWebService implements
|
||||
NodeRef personNodeRef = this.personService.createPerson(properties);
|
||||
|
||||
// Add the details to the result
|
||||
userDetails[index] = createUserDetails(newUser.getUserName(), personNodeRef);
|
||||
userDetails[index] = createUserDetails(nodeService, newUser.getUserName(), personNodeRef);
|
||||
index++;
|
||||
}
|
||||
|
||||
@@ -424,6 +440,7 @@ public class AdministrationWebService extends AbstractWebService implements
|
||||
*/
|
||||
private UserDetails[] updateUsersImpl(UserDetails[] users)
|
||||
{
|
||||
NodeService nodeService = serviceRegistry.getNodeService();
|
||||
UserDetails[] userDetails = new UserDetails[users.length];
|
||||
|
||||
int index = 0;
|
||||
@@ -442,7 +459,7 @@ public class AdministrationWebService extends AbstractWebService implements
|
||||
|
||||
// Add the details to the result
|
||||
NodeRef nodeRef = this.personService.getPerson(user.getUserName());
|
||||
userDetails[index] = createUserDetails(user.getUserName(), nodeRef);
|
||||
userDetails[index] = createUserDetails(nodeService, user.getUserName(), nodeRef);
|
||||
index++;
|
||||
}
|
||||
|
||||
@@ -539,163 +556,4 @@ public class AdministrationWebService extends AbstractWebService implements
|
||||
this.personService.deletePerson(userName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* User query session used to support batched user query
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
private class UserQuerySession implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -2960711874297744356L;
|
||||
|
||||
private int batchSize = -1;
|
||||
private UserFilter filter;
|
||||
protected int position = 0;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param batchSize
|
||||
* @param filter
|
||||
*/
|
||||
public UserQuerySession(int batchSize, UserFilter filter)
|
||||
{
|
||||
this.batchSize = batchSize;
|
||||
this.filter = filter;
|
||||
this.id = GUID.generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.webservice.repository.QuerySession#getId()
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the index of the last row to retrieve.
|
||||
*
|
||||
* @param totalRowCount The total number of rows in the results
|
||||
* @return The index of the last row to return
|
||||
*/
|
||||
protected int calculateLastRowIndex(int totalRowCount)
|
||||
{
|
||||
int lastRowIndex = totalRowCount;
|
||||
|
||||
// set the last row index if there are more results available
|
||||
// than the batch size
|
||||
if ((this.batchSize != -1) && ((this.position + this.batchSize) < totalRowCount))
|
||||
{
|
||||
lastRowIndex = this.position + this.batchSize;
|
||||
}
|
||||
|
||||
return lastRowIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the value of the next position.
|
||||
* If the end of the result set is reached the position is set to -1
|
||||
*
|
||||
* @param totalRowCount The total number of rows in the results
|
||||
* @param queryResult The QueryResult object being returned to the client,
|
||||
* if there are no more results the id is removed from the QueryResult instance
|
||||
*/
|
||||
protected void updatePosition(int totalRowCount, UserQueryResults queryResult)
|
||||
{
|
||||
if (this.batchSize == -1)
|
||||
{
|
||||
this.position = -1;
|
||||
queryResult.setQuerySession(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.position += this.batchSize;
|
||||
if (this.position >= totalRowCount)
|
||||
{
|
||||
// signify that there are no more results
|
||||
this.position = -1;
|
||||
queryResult.setQuerySession(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next batch of user details
|
||||
*
|
||||
* @return user query results
|
||||
*/
|
||||
public UserQueryResults getNextBatch()
|
||||
{
|
||||
UserQueryResults queryResult = null;
|
||||
|
||||
if (this.position != -1)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Before getNextBatch: " + toString());
|
||||
|
||||
Set<NodeRef> nodeRefs = AdministrationWebService.this.personService.getAllPeople();
|
||||
|
||||
// Filter the results
|
||||
List<NodeRef> filteredNodeRefs = null;
|
||||
if (filter != null && filter.getUserName() != null && filter.getUserName().length() != 0)
|
||||
{
|
||||
String userNameFilter = filter.getUserName();
|
||||
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug("Applying user query filter (" + userNameFilter + ")");
|
||||
}
|
||||
|
||||
filteredNodeRefs = new ArrayList<NodeRef>(nodeRefs.size());
|
||||
for (NodeRef nodeRef : nodeRefs)
|
||||
{
|
||||
String userName = (String)AdministrationWebService.this.nodeService.getProperty(nodeRef, ContentModel.PROP_USERNAME);
|
||||
if (userName.matches(userNameFilter) == true)
|
||||
{
|
||||
filteredNodeRefs.add(nodeRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug("No user filter specified");
|
||||
}
|
||||
|
||||
filteredNodeRefs = new ArrayList<NodeRef>(nodeRefs);
|
||||
}
|
||||
|
||||
int totalRows = filteredNodeRefs.size();
|
||||
int lastRow = calculateLastRowIndex(totalRows);
|
||||
int currentBatchSize = lastRow - this.position;
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Total rows = " + totalRows + ", current batch size = " + currentBatchSize);
|
||||
|
||||
List<UserDetails> userDetailsList = new ArrayList<UserDetails>(currentBatchSize);
|
||||
|
||||
for (int x = this.position; x < lastRow; x++)
|
||||
{
|
||||
NodeRef nodeRef = (NodeRef)filteredNodeRefs.get(x);
|
||||
String userName = (String)AdministrationWebService.this.nodeService.getProperty(nodeRef, ContentModel.PROP_USERNAME);
|
||||
UserDetails userDetails = AdministrationWebService.this.createUserDetails(userName, nodeRef);
|
||||
userDetailsList.add(userDetails);
|
||||
}
|
||||
|
||||
queryResult = new UserQueryResults(getId(), (UserDetails[])userDetailsList.toArray(new UserDetails[userDetailsList.size()]));
|
||||
|
||||
// move the position on
|
||||
updatePosition(totalRows, queryResult);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("After getNextBatch: " + toString());
|
||||
}
|
||||
|
||||
return queryResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user