mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
- Added batchable user queries to admin web service API
- Added big P person service - web service clinet jar is now build by build process - Added distribute-web-service-client target which will create web service lcient distribution zip file containing jar and dependant resources - Added web service client property file so destination repository can be easily specified git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2233 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -126,7 +126,7 @@ public class UserQueryResults implements java.io.Serializable {
|
|||||||
elemField.setFieldName("querySession");
|
elemField.setFieldName("querySession");
|
||||||
elemField.setXmlName(new javax.xml.namespace.QName("http://www.alfresco.org/ws/service/administration/1.0", "querySession"));
|
elemField.setXmlName(new javax.xml.namespace.QName("http://www.alfresco.org/ws/service/administration/1.0", "querySession"));
|
||||||
elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
|
elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
|
||||||
elemField.setNillable(false);
|
elemField.setNillable(true);
|
||||||
typeDesc.addFieldDesc(elemField);
|
typeDesc.addFieldDesc(elemField);
|
||||||
elemField = new org.apache.axis.description.ElementDesc();
|
elemField = new org.apache.axis.description.ElementDesc();
|
||||||
elemField.setFieldName("userDetails");
|
elemField.setFieldName("userDetails");
|
||||||
|
@@ -27,17 +27,22 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.repo.cache.SimpleCache;
|
||||||
import org.alfresco.repo.transaction.TransactionComponent;
|
import org.alfresco.repo.transaction.TransactionComponent;
|
||||||
import org.alfresco.repo.transaction.TransactionUtil;
|
import org.alfresco.repo.transaction.TransactionUtil;
|
||||||
import org.alfresco.repo.transaction.TransactionUtil.TransactionWork;
|
import org.alfresco.repo.transaction.TransactionUtil.TransactionWork;
|
||||||
import org.alfresco.repo.webservice.AbstractWebService;
|
import org.alfresco.repo.webservice.AbstractWebService;
|
||||||
|
import org.alfresco.repo.webservice.Utils;
|
||||||
import org.alfresco.repo.webservice.action.ActionFault;
|
import org.alfresco.repo.webservice.action.ActionFault;
|
||||||
|
import org.alfresco.repo.webservice.repository.QuerySession;
|
||||||
import org.alfresco.repo.webservice.types.NamedValue;
|
import org.alfresco.repo.webservice.types.NamedValue;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||||
import org.alfresco.service.cmr.security.PersonService;
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.alfresco.util.GUID;
|
||||||
|
import org.apache.axis.MessageContext;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
@@ -62,6 +67,9 @@ public class AdministrationWebService extends AbstractWebService implements
|
|||||||
/** A set of ignored properties */
|
/** A set of ignored properties */
|
||||||
private static Set<QName> ignoredProperties = new HashSet<QName>(3);
|
private static Set<QName> ignoredProperties = new HashSet<QName>(3);
|
||||||
|
|
||||||
|
/** Simple cache used to store user query sessions */
|
||||||
|
private SimpleCache<String, UserQuerySession> querySessionCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
@@ -103,24 +111,116 @@ public class AdministrationWebService extends AbstractWebService implements
|
|||||||
this.authenticationService = authenticationService;
|
this.authenticationService = authenticationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/**
|
||||||
* @see org.alfresco.repo.webservice.administration.AdministrationServiceSoapPort#queryUsers(org.alfresco.repo.webservice.administration.UserFilter)
|
* Sets the instance of the SimpleCache to be used
|
||||||
|
*
|
||||||
|
* @param querySessionCache
|
||||||
|
* The SimpleCache
|
||||||
*/
|
*/
|
||||||
public UserQueryResults queryUsers(UserFilter filter)
|
public void setQuerySessionCache(
|
||||||
throws RemoteException, AdministrationFault
|
SimpleCache<String, UserQuerySession> querySessionCache)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
this.querySessionCache = querySessionCache;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/**
|
||||||
* @see org.alfresco.repo.webservice.administration.AdministrationServiceSoapPort#fetchMoreUsers(java.lang.String)
|
* @see org.alfresco.repo.webservice.administration.AdministrationServiceSoapPort#queryUsers(org.alfresco.repo.webservice.administration.UserFilter)
|
||||||
*/
|
*/
|
||||||
public UserQueryResults fetchMoreUsers(String querySession)
|
public UserQueryResults queryUsers(final UserFilter filter)
|
||||||
throws RemoteException, AdministrationFault
|
throws RemoteException, AdministrationFault
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
try
|
||||||
return null;
|
{
|
||||||
|
return TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionWork<UserQueryResults>()
|
||||||
|
{
|
||||||
|
public UserQueryResults doWork() throws Exception
|
||||||
|
{
|
||||||
|
return queryUsersImpl(filter);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Throwable exception)
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.error("Unexpected error occurred", exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ActionFault(0, exception.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query users, batch by set size
|
||||||
|
*
|
||||||
|
* @param filter used to filter results
|
||||||
|
* @return user query results, optionally batched
|
||||||
|
*/
|
||||||
|
private UserQueryResults queryUsersImpl(UserFilter filter)
|
||||||
|
{
|
||||||
|
MessageContext msgContext = MessageContext.getCurrentContext();
|
||||||
|
|
||||||
|
// Create a user query session
|
||||||
|
UserQuerySession userQuerySession = new UserQuerySession(Utils.getBatchSize(msgContext), filter);
|
||||||
|
UserQueryResults userQueryResults = userQuerySession.getNextBatch();
|
||||||
|
|
||||||
|
// add the session to the cache if there are more results to come
|
||||||
|
if (userQueryResults.getQuerySession() != null)
|
||||||
|
{
|
||||||
|
// this.querySessionCache.putQuerySession(querySession);
|
||||||
|
this.querySessionCache.put(userQueryResults.getQuerySession(), userQuerySession);
|
||||||
|
}
|
||||||
|
|
||||||
|
return userQueryResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.alfresco.repo.webservice.administration.AdministrationServiceSoapPort#fetchMoreUsers(java.lang.String)
|
||||||
|
*/
|
||||||
|
public UserQueryResults fetchMoreUsers(final String querySession)
|
||||||
|
throws RemoteException, AdministrationFault
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionWork<UserQueryResults>()
|
||||||
|
{
|
||||||
|
public UserQueryResults doWork() throws Exception
|
||||||
|
{
|
||||||
|
return fetchMoreUsersImpl(querySession);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Throwable exception)
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.error("Unexpected error occurred", exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ActionFault(0, exception.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param querySession
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private UserQueryResults fetchMoreUsersImpl(String querySession)
|
||||||
|
{
|
||||||
|
UserQueryResults queryResult = null;
|
||||||
|
UserQuerySession session = this.querySessionCache.get(querySession);
|
||||||
|
|
||||||
|
if (session != null)
|
||||||
|
{
|
||||||
|
queryResult = session.getNextBatch();
|
||||||
|
if (queryResult.getQuerySession() == null)
|
||||||
|
{
|
||||||
|
this.querySessionCache.remove(querySession);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return queryResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -413,4 +513,135 @@ public class AdministrationWebService extends AbstractWebService implements
|
|||||||
this.personService.deletePerson(userName);
|
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();
|
||||||
|
|
||||||
|
// TODO do the filter of the resulting list here ....
|
||||||
|
List<NodeRef> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,17 @@
|
|||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<!-- Cache to used to store UserQueryResults instances -->
|
||||||
|
<bean id="userQuerySessionCache" class="org.alfresco.repo.cache.EhCacheAdapter">
|
||||||
|
<property name="cache">
|
||||||
|
<bean class="org.springframework.cache.ehcache.EhCacheFactoryBean" >
|
||||||
|
<property name="cacheName">
|
||||||
|
<value>webservice.UserQuerySessionCache</value>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
<!-- CLM Util bean -->
|
<!-- CLM Util bean -->
|
||||||
<bean id="CMLUtil" class="org.alfresco.repo.webservice.CMLUtil">
|
<bean id="CMLUtil" class="org.alfresco.repo.webservice.CMLUtil">
|
||||||
<property name="nodeService">
|
<property name="nodeService">
|
||||||
@@ -200,7 +211,10 @@
|
|||||||
<ref bean="AuthenticationService"/>
|
<ref bean="AuthenticationService"/>
|
||||||
</property>
|
</property>
|
||||||
<property name="personService">
|
<property name="personService">
|
||||||
<ref bean="personService"/>
|
<ref bean="PersonService"/>
|
||||||
|
</property>
|
||||||
|
<property name="querySessionCache">
|
||||||
|
<ref bean="userQuerySessionCache"/>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
@@ -2704,6 +2704,7 @@
|
|||||||
<requestFlow>
|
<requestFlow>
|
||||||
<handler type="CreateSpringTicketCallback"/>
|
<handler type="CreateSpringTicketCallback"/>
|
||||||
<handler type="WSSecurity"/>
|
<handler type="WSSecurity"/>
|
||||||
|
<handler type="QueryConfigHandler"/>
|
||||||
</requestFlow>
|
</requestFlow>
|
||||||
<!-- generated below here -->
|
<!-- generated below here -->
|
||||||
<parameter name="wsdlTargetNamespace" value="http://www.alfresco.org/ws/service/administration/1.0"/>
|
<parameter name="wsdlTargetNamespace" value="http://www.alfresco.org/ws/service/administration/1.0"/>
|
||||||
|
@@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
<complexType name="UserQueryResults">
|
<complexType name="UserQueryResults">
|
||||||
<sequence>
|
<sequence>
|
||||||
<element name="querySession" type="xsd:string"/>
|
<element name="querySession" type="xsd:string" nillable="true"/>
|
||||||
<element name="userDetails" type="admin:UserDetails" maxOccurs="unbounded" minOccurs="0"/>
|
<element name="userDetails" type="admin:UserDetails" maxOccurs="unbounded" minOccurs="0"/>
|
||||||
</sequence>
|
</sequence>
|
||||||
</complexType>
|
</complexType>
|
||||||
|
Reference in New Issue
Block a user