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:
Derek Hulley
2007-09-10 23:44:07 +00:00
parent 807349fab5
commit 0d728ed843
21 changed files with 1579 additions and 1378 deletions

View File

@@ -1,132 +0,0 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.webservice.repository;
import java.util.Set;
import org.alfresco.repo.webservice.types.ResultSetRowNode;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.GUID;
/**
* Abstract implementation of a QuerySession providing support
* for automatic id generation and provides support for
* paging through query results.
*
* @author gavinc
*/
public abstract class AbstractQuerySession implements QuerySession
{
protected int batchSize;
protected int position = 0;
private String id;
/**
* Common constructor that initialises the session's id and batch size
*
* @param batchSize The batch size this session will use
*/
public AbstractQuerySession(int batchSize)
{
this.id = GUID.generate();
this.batchSize = batchSize;
}
/**
* @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, QueryResult queryResult)
{
this.position += this.batchSize;
if (this.position >= totalRowCount)
{
// signify that there are no more results
this.position = -1;
queryResult.setQuerySession(null);
}
}
/**
* Create a result set row node object for the provided node reference
*
* @param nodeRef the node reference
* @param nodeService the node service
* @return the result set row node
*/
protected ResultSetRowNode createResultSetRowNode(NodeRef nodeRef, NodeService nodeService)
{
// Get the type
String type = nodeService.getType(nodeRef).toString();
// Get the aspects applied to the node
Set<QName> aspects = nodeService.getAspects(nodeRef);
String[] aspectNames = new String[aspects.size()];
int index = 0;
for (QName aspect : aspects)
{
aspectNames[index] = aspect.toString();
index ++;
}
// Create and return the result set row node
return new ResultSetRowNode(nodeRef.getId(), type, aspectNames);
}
}

View File

@@ -1,196 +0,0 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.webservice.repository;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.webservice.Utils;
import org.alfresco.repo.webservice.types.NamedValue;
import org.alfresco.repo.webservice.types.Reference;
import org.alfresco.repo.webservice.types.ResultSetRow;
import org.alfresco.repo.webservice.types.ResultSetRowNode;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.AssociationRef;
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.namespace.QNamePattern;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Implementation of a QuerySession that stores the results from a query for
* associations
*
* @author Roy Wetherall
*/
public class AssociatedQuerySession extends AbstractQuerySession
{
private static final long serialVersionUID = 6488008047324436124L;
private transient static Log logger = LogFactory
.getLog(AssociatedQuerySession.class);
private Reference node;
private Association association;
/**
* Constructs a AssociatedQuerySession
*
* @param batchSize
* The batch size to use for this session
* @param node
* The node to retrieve the associations
*/
public AssociatedQuerySession(int batchSize, Reference node, Association association)
{
super(batchSize);
this.node = node;
this.association = association;
}
/**
* @see org.alfresco.repo.webservice.repository.QuerySession#getNextResultsBatch(org.alfresco.service.cmr.search.SearchService,
* org.alfresco.service.cmr.repository.NodeService,
* org.alfresco.service.namespace.NamespaceService)
*/
public QueryResult getNextResultsBatch(SearchService searchService,
NodeService nodeService, NamespaceService namespaceService, DictionaryService dictionaryService)
{
QueryResult queryResult = null;
if (this.position != -1)
{
if (logger.isDebugEnabled())
logger.debug("Before getNextResultsBatch: " + toString());
// create the node ref and get the children from the repository
NodeRef nodeRef = Utils.convertToNodeRef(this.node, nodeService, searchService, namespaceService);
List<AssociationRef> assocs = null;
if (association != null)
{
assocs = nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
}
else
{
QNamePattern name = RegexQNamePattern.MATCH_ALL;
String assocType = association.getAssociationType();
if (assocType != null)
{
name = QName.createQName(assocType);
}
if ("source".equals(association.getDirection()) == true)
{
assocs = nodeService.getSourceAssocs(nodeRef, name);
}
else
{
assocs = nodeService.getTargetAssocs(nodeRef, name);
}
}
int totalRows = assocs.size();
int lastRow = calculateLastRowIndex(totalRows);
int currentBatchSize = lastRow - this.position;
if (logger.isDebugEnabled())
logger.debug("Total rows = " + totalRows
+ ", current batch size = " + currentBatchSize);
org.alfresco.repo.webservice.types.ResultSet batchResults = new org.alfresco.repo.webservice.types.ResultSet();
org.alfresco.repo.webservice.types.ResultSetRow[] rows = new org.alfresco.repo.webservice.types.ResultSetRow[currentBatchSize];
int arrPos = 0;
for (int x = this.position; x < lastRow; x++)
{
AssociationRef assoc = assocs.get(x);
NodeRef childNodeRef = assoc.getTargetRef();
ResultSetRowNode rowNode = createResultSetRowNode(childNodeRef, nodeService);
// create columns for all the properties of the node
// get the data for the row and build up the columns structure
Map<QName, Serializable> props = nodeService
.getProperties(childNodeRef);
NamedValue[] columns = new NamedValue[props.size()+2];
int col = 0;
for (QName propName : props.keySet())
{
columns[col] = Utils.createNamedValue(dictionaryService, propName, props.get(propName));
col++;
}
// Now add the system columns containing the association details
columns[col] = new NamedValue(SYS_COL_ASSOC_TYPE, Boolean.FALSE, assoc.getTypeQName().toString(), null);
// Add one more column for the node's path
col++;
columns[col] = Utils.createNamedValue(dictionaryService, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "path"), nodeService.getPath(childNodeRef).toString());
ResultSetRow row = new ResultSetRow();
row.setRowIndex(x);
row.setNode(rowNode);
row.setColumns(columns);
// add the row to the overall results
rows[arrPos] = row;
arrPos++;
}
// add the rows to the result set and set the total row count
batchResults.setRows(rows);
batchResults.setTotalRowCount(totalRows);
queryResult = new QueryResult(getId(), batchResults);
// move the position on
updatePosition(totalRows, queryResult);
if (logger.isDebugEnabled())
logger.debug("After getNextResultsBatch: " + toString());
}
return queryResult;
}
/**
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
StringBuilder builder = new StringBuilder(super.toString());
builder.append(" (id=").append(getId());
builder.append(" batchSize=").append(this.batchSize);
builder.append(" position=").append(this.position);
builder.append(" node-id=").append(this.node.getUuid()).append(")");
return builder.toString();
}
}

View File

@@ -0,0 +1,168 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.webservice.repository;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.webservice.AbstractQuery;
import org.alfresco.repo.webservice.Utils;
import org.alfresco.repo.webservice.types.NamedValue;
import org.alfresco.repo.webservice.types.Reference;
import org.alfresco.repo.webservice.types.ResultSet;
import org.alfresco.repo.webservice.types.ResultSetRow;
import org.alfresco.repo.webservice.types.ResultSetRowNode;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.AssociationRef;
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.namespace.QNamePattern;
import org.alfresco.service.namespace.RegexQNamePattern;
/**
* A query to retrieve normal node associations.
*
* @author Derek Hulley
* @since 2.1
*/
public class AssociationQuery extends AbstractQuery<ResultSet>
{
private static final long serialVersionUID = -672399618512462040L;
private Reference node;
private Association association;
/**
* @param node
* The node to query against
* @param association
* The association type to query or <tt>null</tt> to query all
*/
public AssociationQuery(Reference node, Association association)
{
this.node = node;
this.association = association;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(128);
sb.append("AssociationQuery")
.append("[ node=").append(node.getUuid())
.append(", association=").append(association)
.append("]");
return sb.toString();
}
/**
* {@inheritDoc}
*/
public ResultSet execute(ServiceRegistry serviceRegistry)
{
SearchService searchService = serviceRegistry.getSearchService();
NodeService nodeService = serviceRegistry.getNodeService();
DictionaryService dictionaryService = serviceRegistry.getDictionaryService();
NamespaceService namespaceService = serviceRegistry.getNamespaceService();
// create the node ref and get the children from the repository
NodeRef nodeRef = Utils.convertToNodeRef(node, nodeService, searchService, namespaceService);
List<AssociationRef> assocRefs = null;
if (association != null)
{
assocRefs = nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
}
else
{
QNamePattern name = RegexQNamePattern.MATCH_ALL;
String assocType = association.getAssociationType();
if (assocType != null)
{
name = QName.createQName(assocType);
}
if ("source".equals(association.getDirection()) == true)
{
assocRefs = nodeService.getSourceAssocs(nodeRef, name);
}
else
{
assocRefs = nodeService.getTargetAssocs(nodeRef, name);
}
}
int totalRows = assocRefs.size();
ResultSet results = new ResultSet();
ResultSetRow[] rows = new ResultSetRow[totalRows];
int index = 0;
for (AssociationRef assocRef : assocRefs)
{
NodeRef childNodeRef = assocRef.getTargetRef();
ResultSetRowNode rowNode = createResultSetRowNode(childNodeRef, nodeService);
// create columns for all the properties of the node
// get the data for the row and build up the columns structure
Map<QName, Serializable> props = nodeService.getProperties(childNodeRef);
NamedValue[] columns = new NamedValue[props.size()+2];
int col = 0;
for (QName propName : props.keySet())
{
columns[col] = Utils.createNamedValue(dictionaryService, propName, props.get(propName));
col++;
}
// Now add the system columns containing the association details
columns[col] = new NamedValue(SYS_COL_ASSOC_TYPE, Boolean.FALSE, assocRef.getTypeQName().toString(), null);
// Add one more column for the node's path
col++;
columns[col] = Utils.createNamedValue(
dictionaryService,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "path"),
nodeService.getPath(childNodeRef).toString());
ResultSetRow row = new ResultSetRow();
row.setRowIndex(index);
row.setNode(rowNode);
row.setColumns(columns);
// add the row to the overall results
rows[index] = row;
index++;
}
// add the rows to the result set and set the total row count
results.setRows(rows);
results.setTotalRowCount(totalRows);
return results;
}
}

View File

@@ -0,0 +1,146 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.webservice.repository;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.webservice.AbstractQuery;
import org.alfresco.repo.webservice.Utils;
import org.alfresco.repo.webservice.types.NamedValue;
import org.alfresco.repo.webservice.types.Reference;
import org.alfresco.repo.webservice.types.ResultSet;
import org.alfresco.repo.webservice.types.ResultSetRow;
import org.alfresco.repo.webservice.types.ResultSetRowNode;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService;
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;
/**
* A query to retrieve all child associations on a node.
*
* @author Derek Hulley
* @since 2.1
*/
public class ChildAssociationQuery extends AbstractQuery<ResultSet>
{
private static final long serialVersionUID = -4965097420552826582L;
private Reference node;
/**
* @param node
* The node to query against
*/
public ChildAssociationQuery(Reference node)
{
this.node = node;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(128);
sb.append("ChildAssociationQuery")
.append("[ node=").append(node.getUuid())
.append("]");
return sb.toString();
}
/**
* {@inheritDoc}
*/
public ResultSet execute(ServiceRegistry serviceRegistry)
{
SearchService searchService = serviceRegistry.getSearchService();
NodeService nodeService = serviceRegistry.getNodeService();
DictionaryService dictionaryService = serviceRegistry.getDictionaryService();
NamespaceService namespaceService = serviceRegistry.getNamespaceService();
// create the node ref and get the children from the repository
NodeRef nodeRef = Utils.convertToNodeRef(node, nodeService, searchService, namespaceService);
List<ChildAssociationRef> assocRefs = nodeService.getChildAssocs(nodeRef);
int totalRows = assocRefs.size();
ResultSet results = new ResultSet();
ResultSetRow[] rows = new ResultSetRow[totalRows];
int index = 0;
for (ChildAssociationRef assocRef : assocRefs)
{
NodeRef childNodeRef = assocRef.getChildRef();
ResultSetRowNode rowNode = createResultSetRowNode(childNodeRef, nodeService);
// create columns for all the properties of the node
// get the data for the row and build up the columns structure
Map<QName, Serializable> props = nodeService.getProperties(childNodeRef);
NamedValue[] columns = new NamedValue[props.size()+5];
int col = 0;
for (QName propName : props.keySet())
{
columns[col] = Utils.createNamedValue(dictionaryService, propName, props.get(propName));
col++;
}
// Now add the system columns containing the association details
columns[col] = new NamedValue(SYS_COL_ASSOC_TYPE, Boolean.FALSE, assocRef.getTypeQName().toString(), null);
col++;
columns[col] = new NamedValue(SYS_COL_ASSOC_NAME, Boolean.FALSE, assocRef.getQName().toString(), null);
col++;
columns[col] = new NamedValue(SYS_COL_IS_PRIMARY, Boolean.FALSE, Boolean.toString(assocRef.isPrimary()), null);
col++;
columns[col] = new NamedValue(SYS_COL_NTH_SIBLING, Boolean.FALSE, Integer.toString(assocRef.getNthSibling()), null);
// Add one more column for the node's path
col++;
columns[col] = Utils.createNamedValue(
dictionaryService,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "path"),
nodeService.getPath(childNodeRef).toString());
ResultSetRow row = new ResultSetRow();
row.setRowIndex(index);
row.setNode(rowNode);
row.setColumns(columns);
// add the row to the overall results
rows[index] = row;
index++;
}
// add the rows to the result set and set the total row count
results.setRows(rows);
results.setTotalRowCount(totalRows);
return results;
}
}

View File

@@ -1,168 +0,0 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.webservice.repository;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.webservice.Utils;
import org.alfresco.repo.webservice.types.NamedValue;
import org.alfresco.repo.webservice.types.Reference;
import org.alfresco.repo.webservice.types.ResultSetRow;
import org.alfresco.repo.webservice.types.ResultSetRowNode;
import org.alfresco.service.cmr.dictionary.DictionaryService;
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.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Implementation of a QuerySession that stores the results from a query for children
*
* @author gavinc
*/
public class ChildrenQuerySession extends AbstractQuerySession
{
private static final long serialVersionUID = -5347036309571057074L;
private transient static Log logger = LogFactory.getLog(ChildrenQuerySession.class);
private Reference node;
/**
* Constructs a ChildrenQuerySession
*
* @param batchSize The batch size to use for this session
* @param node The node to retrieve the parents
*/
public ChildrenQuerySession(int batchSize, Reference node)
{
super(batchSize);
this.node = node;
}
/**
* @see org.alfresco.repo.webservice.repository.QuerySession#getNextResultsBatch(org.alfresco.service.cmr.search.SearchService, org.alfresco.service.cmr.repository.NodeService, org.alfresco.service.namespace.NamespaceService)
*/
public QueryResult getNextResultsBatch(SearchService searchService, NodeService nodeService, NamespaceService namespaceService, DictionaryService dictionaryService)
{
QueryResult queryResult = null;
if (this.position != -1)
{
if (logger.isDebugEnabled())
logger.debug("Before getNextResultsBatch: " + toString());
// create the node ref and get the children from the repository
NodeRef nodeRef = Utils.convertToNodeRef(this.node, nodeService, searchService, namespaceService);
List<ChildAssociationRef> kids = nodeService.getChildAssocs(nodeRef);
int totalRows = kids.size();
int lastRow = calculateLastRowIndex(totalRows);
int currentBatchSize = lastRow - this.position;
if (logger.isDebugEnabled())
logger.debug("Total rows = " + totalRows + ", current batch size = " + currentBatchSize);
org.alfresco.repo.webservice.types.ResultSet batchResults = new org.alfresco.repo.webservice.types.ResultSet();
org.alfresco.repo.webservice.types.ResultSetRow[] rows = new org.alfresco.repo.webservice.types.ResultSetRow[currentBatchSize];
int arrPos = 0;
for (int x = this.position; x < lastRow; x++)
{
ChildAssociationRef assoc = kids.get(x);
NodeRef childNodeRef = assoc.getChildRef();
ResultSetRowNode rowNode = createResultSetRowNode(childNodeRef, nodeService);
// create columns for all the properties of the node
// get the data for the row and build up the columns structure
Map<QName, Serializable> props = nodeService.getProperties(childNodeRef);
NamedValue[] columns = new NamedValue[props.size()+5];
int col = 0;
for (QName propName : props.keySet())
{
columns[col] = Utils.createNamedValue(dictionaryService, propName, props.get(propName));
col++;
}
// Now add the system columns containing the association details
columns[col] = new NamedValue(SYS_COL_ASSOC_TYPE, Boolean.FALSE, assoc.getTypeQName().toString(), null);
col++;
columns[col] = new NamedValue(SYS_COL_ASSOC_NAME, Boolean.FALSE, assoc.getQName().toString(), null);
col++;
columns[col] = new NamedValue(SYS_COL_IS_PRIMARY, Boolean.FALSE, Boolean.toString(assoc.isPrimary()), null);
col++;
columns[col] = new NamedValue(SYS_COL_NTH_SIBLING, Boolean.FALSE, Integer.toString(assoc.getNthSibling()), null);
// Add one more column for the node's path
col++;
columns[col] = Utils.createNamedValue(dictionaryService, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "path"), nodeService.getPath(childNodeRef).toString());
ResultSetRow row = new ResultSetRow();
row.setRowIndex(x);
row.setNode(rowNode);
row.setColumns(columns);
// add the row to the overall results
rows[arrPos] = row;
arrPos++;
}
// add the rows to the result set and set the total row count
batchResults.setRows(rows);
batchResults.setTotalRowCount(totalRows);
queryResult = new QueryResult(getId(), batchResults);
// move the position on
updatePosition(totalRows, queryResult);
if (logger.isDebugEnabled())
logger.debug("After getNextResultsBatch: " + toString());
}
return queryResult;
}
/**
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
StringBuilder builder = new StringBuilder(super.toString());
builder.append(" (id=").append(getId());
builder.append(" batchSize=").append(this.batchSize);
builder.append(" position=").append(this.position);
builder.append(" node-id=").append(this.node.getUuid()).append(")");
return builder.toString();
}
}

View File

@@ -0,0 +1,146 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.webservice.repository;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.webservice.AbstractQuery;
import org.alfresco.repo.webservice.Utils;
import org.alfresco.repo.webservice.types.NamedValue;
import org.alfresco.repo.webservice.types.Reference;
import org.alfresco.repo.webservice.types.ResultSet;
import org.alfresco.repo.webservice.types.ResultSetRow;
import org.alfresco.repo.webservice.types.ResultSetRowNode;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService;
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;
/**
* A query to retrieve all parent associations on a node.
*
* @author Derek Hulley
* @since 2.1
*/
public class ParentAssociationQuery extends AbstractQuery<ResultSet>
{
private static final long serialVersionUID = -4157476722256947274L;
private Reference node;
/**
* @param node
* The node to query against
*/
public ParentAssociationQuery(Reference node)
{
this.node = node;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(128);
sb.append("ParentAssociationQuery")
.append("[ node=").append(node.getUuid())
.append("]");
return sb.toString();
}
/**
* {@inheritDoc}
*/
public ResultSet execute(ServiceRegistry serviceRegistry)
{
SearchService searchService = serviceRegistry.getSearchService();
NodeService nodeService = serviceRegistry.getNodeService();
DictionaryService dictionaryService = serviceRegistry.getDictionaryService();
NamespaceService namespaceService = serviceRegistry.getNamespaceService();
// create the node ref and get the parent from the repository
NodeRef nodeRef = Utils.convertToNodeRef(node, nodeService, searchService, namespaceService);
List<ChildAssociationRef> assocRefs = nodeService.getParentAssocs(nodeRef);
int totalRows = assocRefs.size();
ResultSet results = new ResultSet();
ResultSetRow[] rows = new ResultSetRow[totalRows];
int index = 0;
for (ChildAssociationRef assocRef : assocRefs)
{
NodeRef parentNodeRef = assocRef.getParentRef();
ResultSetRowNode rowNode = createResultSetRowNode(parentNodeRef, nodeService);
// create columns for all the properties of the node
// get the data for the row and build up the columns structure
Map<QName, Serializable> props = nodeService.getProperties(parentNodeRef);
NamedValue[] columns = new NamedValue[props.size()+5];
int col = 0;
for (QName propName : props.keySet())
{
columns[col] = Utils.createNamedValue(dictionaryService, propName, props.get(propName));
col++;
}
// Now add the system columns containing the association details
columns[col] = new NamedValue(SYS_COL_ASSOC_TYPE, Boolean.FALSE, assocRef.getTypeQName().toString(), null);
col++;
columns[col] = new NamedValue(SYS_COL_ASSOC_NAME, Boolean.FALSE, assocRef.getQName().toString(), null);
col++;
columns[col] = new NamedValue(SYS_COL_IS_PRIMARY, Boolean.FALSE, Boolean.toString(assocRef.isPrimary()), null);
col++;
columns[col] = new NamedValue(SYS_COL_NTH_SIBLING, Boolean.FALSE, Integer.toString(assocRef.getNthSibling()), null);
// Add one more column for the node's path
col++;
columns[col] = Utils.createNamedValue(
dictionaryService,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "path"),
nodeService.getPath(parentNodeRef).toString());
ResultSetRow row = new ResultSetRow();
row.setRowIndex(index);
row.setNode(rowNode);
row.setColumns(columns);
// add the row to the overall results
rows[index] = row;
index++;
}
// add the rows to the result set and set the total row count
results.setRows(rows);
results.setTotalRowCount(totalRows);
return results;
}
}

View File

@@ -1,167 +0,0 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.webservice.repository;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.webservice.Utils;
import org.alfresco.repo.webservice.types.NamedValue;
import org.alfresco.repo.webservice.types.Reference;
import org.alfresco.repo.webservice.types.ResultSetRow;
import org.alfresco.repo.webservice.types.ResultSetRowNode;
import org.alfresco.service.cmr.dictionary.DictionaryService;
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.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Implementation of a QuerySession that stores the results from a query for parents
*
* @author gavinc
*/
public class ParentsQuerySession extends AbstractQuerySession
{
private static final long serialVersionUID = 2539375863409175463L;
private transient static Log logger = LogFactory.getLog(ParentsQuerySession.class);
private Reference node;
/**
* Constructs a ParentsQuerySession
*
* @param batchSize The batch size to use for this session
* @param node The node to retrieve the parents
*/
public ParentsQuerySession(int batchSize, Reference node)
{
super(batchSize);
this.node = node;
}
/**
* @see org.alfresco.repo.webservice.repository.QuerySession#getNextResultsBatch(org.alfresco.service.cmr.search.SearchService, org.alfresco.service.cmr.repository.NodeService, org.alfresco.service.namespace.NamespaceService)
*/
public QueryResult getNextResultsBatch(SearchService searchService, NodeService nodeService, NamespaceService namespaceService, DictionaryService dictionaryService)
{
QueryResult queryResult = null;
if (this.position != -1)
{
if (logger.isDebugEnabled())
logger.debug("Before getNextResultsBatch: " + toString());
// create the node ref and get the children from the repository
NodeRef nodeRef = Utils.convertToNodeRef(this.node, nodeService, searchService, namespaceService);
List<ChildAssociationRef> parents = nodeService.getParentAssocs(nodeRef);
int totalRows = parents.size();
int lastRow = calculateLastRowIndex(totalRows);
int currentBatchSize = lastRow - this.position;
if (logger.isDebugEnabled())
logger.debug("Total rows = " + totalRows + ", current batch size = " + currentBatchSize);
org.alfresco.repo.webservice.types.ResultSet batchResults = new org.alfresco.repo.webservice.types.ResultSet();
org.alfresco.repo.webservice.types.ResultSetRow[] rows = new org.alfresco.repo.webservice.types.ResultSetRow[currentBatchSize];
int arrPos = 0;
for (int x = this.position; x < lastRow; x++)
{
ChildAssociationRef assoc = parents.get(x);
NodeRef parentNodeRef = assoc.getParentRef();
ResultSetRowNode rowNode = createResultSetRowNode(parentNodeRef, nodeService);
// create columns for all the properties of the node
// get the data for the row and build up the columns structure
Map<QName, Serializable> props = nodeService.getProperties(parentNodeRef);
NamedValue[] columns = new NamedValue[props.size()+5];
int col = 0;
for (QName propName : props.keySet())
{
columns[col] = Utils.createNamedValue(dictionaryService, propName, props.get(propName));
col++;
}
// Now add the system columns containing the association details
columns[col] = new NamedValue(SYS_COL_ASSOC_TYPE, Boolean.FALSE, assoc.getTypeQName().toString(), null);
col++;
columns[col] = new NamedValue(SYS_COL_ASSOC_NAME, Boolean.FALSE, assoc.getQName().toString(), null);
col++;
columns[col] = new NamedValue(SYS_COL_IS_PRIMARY, Boolean.FALSE, Boolean.toString(assoc.isPrimary()), null);
col++;
columns[col] = new NamedValue(SYS_COL_NTH_SIBLING, Boolean.FALSE, Integer.toString(assoc.getNthSibling()), null);
// Add one more column for the node's path
col++;
columns[col] = Utils.createNamedValue(dictionaryService, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "path"), nodeService.getPath(parentNodeRef).toString());
ResultSetRow row = new ResultSetRow();
row.setRowIndex(x);
row.setNode(rowNode);
row.setColumns(columns);
// add the row to the overall results
rows[arrPos] = row;
arrPos++;
}
// add the rows to the result set and set the total row count
batchResults.setRows(rows);
batchResults.setTotalRowCount(totalRows);
queryResult = new QueryResult(getId(), batchResults);
// move the position on
updatePosition(totalRows, queryResult);
if (logger.isDebugEnabled())
logger.debug("After getNextResultsBatch: " + toString());
}
return queryResult;
}
/**
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
StringBuilder builder = new StringBuilder(super.toString());
builder.append(" (id=").append(getId());
builder.append(" batchSize=").append(this.batchSize);
builder.append(" position=").append(this.position);
builder.append(" node-id=").append(this.node.getUuid()).append(")");
return builder.toString();
}
}

View File

@@ -1,74 +0,0 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.webservice.repository;
import java.io.Serializable;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService;
/**
* Interface definition for a QuerySession.
*
* @author gavinc
*/
public interface QuerySession extends Serializable
{
/** System column namess */
public static String SYS_COL_ASSOC_TYPE = "associationType";
public static String SYS_COL_ASSOC_NAME = "associationName";
public static String SYS_COL_IS_PRIMARY = "isPrimary";
public static String SYS_COL_NTH_SIBLING = "nthSibling";
/**
* Retrieves the id this query session can be identified as
*
* @return Id of this query session
*/
public String getId();
/**
* Returns a QueryResult object representing the next batch of results.
* QueryResult will contain a maximum of items as determined by the
* <code>fetchSize</code> element of the QueryConfiguration SOAP header.
*
* When the last batch of results is being returned the querySession of
* QueryResult will be null.
*
* @see org.alfresco.repo.webservice.repository.QuerySession#getId()
* @param searchService The SearchService to use for gathering the results
* @param nodeService The NodeService to use for gathering the results
* @param namespaceService The NamespaceService to use
* @return QueryResult containing the next batch of results or null if there
* are no more results
*/
public QueryResult getNextResultsBatch(
SearchService searchService,
NodeService nodeService,
NamespaceService namespaceService,
DictionaryService dictionaryService);
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.webservice.repository;
import org.alfresco.repo.webservice.AbstractQuerySession;
import org.alfresco.repo.webservice.ServerQuery;
import org.alfresco.repo.webservice.types.ResultSet;
import org.alfresco.repo.webservice.types.ResultSetRow;
import org.alfresco.service.ServiceRegistry;
/**
* A query session for use with {@linkplain RepositoryWebService node-related queries} against the
* repository.
*
* @author Derek Hulley
* @since 2.1
*/
public class RepositoryQuerySession extends AbstractQuerySession<ResultSet, ResultSetRow>
{
private static final long serialVersionUID = -3621997639261137000L;
public RepositoryQuerySession(long maxResults, long batchSize, ServerQuery<ResultSet> query)
{
super(maxResults, batchSize, query);
}
@Override
protected ResultSetRow[] makeArray(int size)
{
return new ResultSetRow[size];
}
public ResultSet getNextResults(ServiceRegistry serviceRegistry)
{
ResultSet queryResults = getQueryResults(serviceRegistry);
ResultSetRow[] allRows = queryResults.getRows();
ResultSetRow[] batchedRows = getNextResults(allRows);
// Build the resultset for the batched results
ResultSet batchedResults = new ResultSet();
batchedResults.setMetaData(queryResults.getMetaData());
batchedResults.setRows(batchedRows);
batchedResults.setTotalRowCount(batchedRows.length);
// Done
return batchedResults;
}
}

View File

@@ -31,10 +31,10 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.repo.webservice.AbstractWebService;
import org.alfresco.repo.webservice.CMLUtil;
import org.alfresco.repo.webservice.ServerQuery;
import org.alfresco.repo.webservice.Utils;
import org.alfresco.repo.webservice.types.CML;
import org.alfresco.repo.webservice.types.ClassDefinition;
@@ -44,9 +44,9 @@ import org.alfresco.repo.webservice.types.NodeDefinition;
import org.alfresco.repo.webservice.types.Predicate;
import org.alfresco.repo.webservice.types.Query;
import org.alfresco.repo.webservice.types.Reference;
import org.alfresco.repo.webservice.types.ResultSet;
import org.alfresco.repo.webservice.types.Store;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
@@ -67,23 +67,8 @@ public class RepositoryWebService extends AbstractWebService implements
{
private static Log logger = LogFactory.getLog(RepositoryWebService.class);
private DictionaryService dictionaryService;
private CMLUtil cmlUtil;
private SimpleCache<String, QuerySession> querySessionCache;
/**
* Sets the instance of the DictionaryService to be used
*
* @param dictionaryService
* The DictionaryService
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* Sets the CML Util
*
@@ -94,18 +79,6 @@ public class RepositoryWebService extends AbstractWebService implements
this.cmlUtil = cmlUtil;
}
/**
* Sets the instance of the SimpleCache to be used
*
* @param querySessionCache
* The SimpleCache
*/
public void setQuerySessionCache(
SimpleCache<String, QuerySession> querySessionCache)
{
this.querySessionCache = querySessionCache;
}
/**
* {@inheritDoc}
*/
@@ -156,11 +129,58 @@ public class RepositoryWebService extends AbstractWebService implements
}
}
/**
* Executes the given query, caching the results as required.
*/
private QueryResult executeQuery(final MessageContext msgContext, final ServerQuery<ResultSet> query) throws RepositoryFault
{
try
{
RetryingTransactionCallback<QueryResult> callback = new RetryingTransactionCallback<QueryResult>()
{
public QueryResult execute() throws Throwable
{
// Construct a session to handle the iteration
long batchSize = Utils.getBatchSize(msgContext);
RepositoryQuerySession session = new RepositoryQuerySession(Long.MAX_VALUE, batchSize, query);
String sessionId = session.getId();
// Get the first batch of results
ResultSet batchedResults = session.getNextResults(serviceRegistry);
// Construct the result
// TODO: http://issues.alfresco.com/browse/AR-1689
boolean haveMoreResults = session.haveMoreResults();
QueryResult queryResult = new QueryResult(
haveMoreResults ? sessionId : null,
batchedResults);
// Cache the session
if (session.haveMoreResults())
{
querySessionCache.put(sessionId, session);
}
// Done
return queryResult;
}
};
return Utils.getRetryingTransactionHelper(MessageContext.getCurrentContext()).doInTransaction(callback, true);
}
catch (Throwable e)
{
if (logger.isDebugEnabled())
{
logger.error("Unexpected error occurred", e);
}
e.printStackTrace();
throw new RepositoryFault(0, e.toString());
}
}
/**
* {@inheritDoc}
*/
public QueryResult query(final Store store, final Query query, final boolean includeMetaData)
throws RemoteException, RepositoryFault
public QueryResult query(final Store store, final Query query, final boolean includeMetaData) throws RemoteException, RepositoryFault
{
String language = query.getLanguage();
if (language.equals(Utils.QUERY_LANG_LUCENE) == false)
@@ -171,131 +191,52 @@ public class RepositoryWebService extends AbstractWebService implements
}
final MessageContext msgContext = MessageContext.getCurrentContext();
try
{
RetryingTransactionCallback<QueryResult> callback = new RetryingTransactionCallback<QueryResult>()
{
public QueryResult execute() throws Throwable
{
// setup a query session and get the first batch of results
QuerySession querySession = new ResultSetQuerySession(Utils
.getBatchSize(msgContext), store, query, includeMetaData);
QueryResult queryResult = querySession
.getNextResultsBatch(searchService, nodeService, namespaceService, dictionaryService);
// add the session to the cache if there are more results to come
if (queryResult.getQuerySession() != null)
{
// this.querySessionCache.putQuerySession(querySession);
querySessionCache.put(queryResult.getQuerySession(), querySession);
}
return queryResult;
}
};
return Utils.getRetryingTransactionHelper(MessageContext.getCurrentContext()).doInTransaction(callback);
}
catch (Throwable e)
{
if (logger.isDebugEnabled())
{
logger.error("Unexpected error occurred", e);
}
e.printStackTrace();
throw new RepositoryFault(0, e.toString());
}
SearchQuery serverQuery = new SearchQuery(store, query);
QueryResult queryResult = executeQuery(msgContext, serverQuery);
// Done
return queryResult;
}
/**
* {@inheritDoc}
*/
public QueryResult queryChildren(final Reference node) throws RemoteException,
RepositoryFault
public QueryResult queryChildren(final Reference node) throws RemoteException, RepositoryFault
{
try
{
RetryingTransactionCallback<QueryResult> callback = new RetryingTransactionCallback<QueryResult>()
{
public QueryResult execute() throws Throwable
{
// setup a query session and get the first batch of results
QuerySession querySession = new ChildrenQuerySession(Utils
.getBatchSize(MessageContext.getCurrentContext()), node);
QueryResult queryResult = querySession
.getNextResultsBatch(searchService, nodeService, namespaceService, dictionaryService);
// add the session to the cache if there are more results to come
if (queryResult.getQuerySession() != null)
{
querySessionCache.put(queryResult.getQuerySession(), querySession);
}
if (logger.isDebugEnabled())
{
logger.debug("Method end ... queryChildren");
}
return queryResult;
}
};
return Utils.getRetryingTransactionHelper(MessageContext.getCurrentContext()).doInTransaction(callback);
}
catch (Throwable e)
{
if (logger.isDebugEnabled())
{
logger.error("Unexpected error occurred", e);
}
e.printStackTrace();
throw new RepositoryFault(0, e.toString());
}
final MessageContext msgContext = MessageContext.getCurrentContext();
ChildAssociationQuery query = new ChildAssociationQuery(node);
QueryResult queryResult = executeQuery(msgContext, query);
// Done
return queryResult;
}
/**
* {@inheritDoc}
*/
public QueryResult queryParents(final Reference node) throws RemoteException, RepositoryFault
{
try
{
RetryingTransactionCallback<QueryResult> callback = new RetryingTransactionCallback<QueryResult>()
{
public QueryResult execute() throws Throwable
{
// setup a query session and get the first batch of results
QuerySession querySession = new ParentsQuerySession(Utils
.getBatchSize(MessageContext.getCurrentContext()), node);
QueryResult queryResult = querySession.getNextResultsBatch(
searchService, nodeService, namespaceService, dictionaryService);
// add the session to the cache if there are more results to come
if (queryResult.getQuerySession() != null)
{
// this.querySessionCache.putQuerySession(querySession);
querySessionCache.put(queryResult.getQuerySession(), querySession);
}
return queryResult;
}
};
return Utils.getRetryingTransactionHelper(MessageContext.getCurrentContext()).doInTransaction(callback);
}
catch (Throwable e)
{
if (logger.isDebugEnabled())
{
logger.error("Unexpected error occurred", e);
}
throw new RepositoryFault(0, e.toString());
}
final MessageContext msgContext = MessageContext.getCurrentContext();
ParentAssociationQuery query = new ParentAssociationQuery(node);
QueryResult queryResult = executeQuery(msgContext, query);
// Done
return queryResult;
}
/**
* {@inheritDoc}
*/
public QueryResult queryAssociated(final Reference node, final Association association)
throws RemoteException, RepositoryFault
public QueryResult queryAssociated(final Reference node, final Association association) throws RemoteException, RepositoryFault
{
final MessageContext msgContext = MessageContext.getCurrentContext();
AssociationQuery query = new AssociationQuery(node, association);
QueryResult queryResult = executeQuery(msgContext, query);
// Done
return queryResult;
}
/**
* {@inheritDoc}
*/
public QueryResult fetchMore(final String querySessionId) throws RemoteException, RepositoryFault
{
try
{
@@ -303,76 +244,54 @@ public class RepositoryWebService extends AbstractWebService implements
{
public QueryResult execute() throws Throwable
{
// setup a query session and get the first batch of results
QuerySession querySession = new AssociatedQuerySession(Utils.getBatchSize(MessageContext.getCurrentContext()), node, association);
QueryResult queryResult = querySession.getNextResultsBatch(searchService, nodeService, namespaceService, dictionaryService);
// add the session to the cache if there are more results to come
if (queryResult.getQuerySession() != null)
RepositoryQuerySession session = null;
try
{
// this.querySessionCache.putQuerySession(querySession);
querySessionCache.put(queryResult.getQuerySession(), querySession);
// try and get the QuerySession with the given id from the cache
session = (RepositoryQuerySession) querySessionCache.get(querySessionId);
}
catch (ClassCastException e)
{
if (logger.isDebugEnabled())
{
logger.debug("Query session was not generated by the RepositoryWebService: " + querySessionId);
}
throw new RepositoryFault(
4,
"querySession with id '" + querySessionId + "' is invalid");
}
return queryResult;
}
};
return Utils.getRetryingTransactionHelper(MessageContext.getCurrentContext()).doInTransaction(callback);
}
catch (Throwable e)
{
if (logger.isDebugEnabled())
{
logger.error("Unexpected error occurred", e);
}
throw new RepositoryFault(0, e.toString());
}
}
/**
* {@inheritDoc}
*/
public QueryResult fetchMore(final String querySession) throws RemoteException, RepositoryFault
{
try
{
RetryingTransactionCallback<QueryResult> callback = new RetryingTransactionCallback<QueryResult>()
{
public QueryResult execute() throws Throwable
{
// try and get the QuerySession with the given id from the cache
QuerySession session = querySessionCache.get(querySession);
if (session == null)
{
if (logger.isDebugEnabled())
{
logger.debug("Invalid querySession id requested: " + querySession);
logger.debug("Invalid querySession id requested: " + querySessionId);
}
throw new RepositoryFault(
4,
"querySession with id '" + querySession + "' is invalid");
"querySession with id '" + querySessionId + "' is invalid");
}
ResultSet moreResults = session.getNextResults(serviceRegistry);
// Drop the cache results if there are no more results expected
if (!session.haveMoreResults())
{
querySessionCache.remove(querySessionId);
}
// get the next batch of results
QueryResult queryResult = session.getNextResultsBatch(
searchService,
nodeService,
namespaceService,
dictionaryService);
// remove the QuerySession from the cache if there are no more
// results to come
if (queryResult.getQuerySession() == null)
{
querySessionCache.remove(querySession);
}
// TODO: http://issues.alfresco.com/browse/AR-1689
boolean haveMoreResults = session.haveMoreResults();
QueryResult queryResult = new QueryResult(
haveMoreResults ? querySessionId : null,
moreResults);
// Done
return queryResult;
}
};
return Utils.getRetryingTransactionHelper(MessageContext.getCurrentContext()).doInTransaction(callback);
return Utils.getRetryingTransactionHelper(MessageContext.getCurrentContext()).doInTransaction(callback, true);
}
catch (Throwable e)
{

View File

@@ -1,208 +0,0 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.webservice.repository;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.webservice.Utils;
import org.alfresco.repo.webservice.types.NamedValue;
import org.alfresco.repo.webservice.types.Query;
import org.alfresco.repo.webservice.types.ResultSetRowNode;
import org.alfresco.repo.webservice.types.Store;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.Path;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.ResultSetRow;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Implementation of a QuerySession that retrieves results from a repository ResultSet
*
* @author gavinc
*/
public class ResultSetQuerySession extends AbstractQuerySession
{
private static final long serialVersionUID = -9154514445963635138L;
private transient static Log logger = LogFactory.getLog(ResultSetQuerySession.class);
private Store store;
private Query query;
@SuppressWarnings("unused")
private boolean includeMetaData;
/**
* Constructs a ResultSetQuerySession
*
* @param batchSize The batch size to use for this session
* @param store The repository store to query against
* @param query The query to execute
* @param includeMetaData Whether to include metadata in the query results
*/
public ResultSetQuerySession(int batchSize, Store store, Query query, boolean includeMetaData)
{
super(batchSize);
this.store = store;
this.query = query;
this.includeMetaData = includeMetaData;
}
/**
* @see org.alfresco.repo.webservice.repository.QuerySession#getNextResultsBatch(org.alfresco.service.cmr.search.SearchService, org.alfresco.service.cmr.repository.NodeService, org.alfresco.service.namespace.NamespaceService)
*/
public QueryResult getNextResultsBatch(SearchService searchService, NodeService nodeService, NamespaceService namespaceService, DictionaryService dictionaryService)
{
QueryResult queryResult = null;
if (this.position != -1)
{
if (logger.isDebugEnabled())
logger.debug("Before getNextResultsBatch: " + toString());
// handle the special search string of * meaning, get everything
String statement = query.getStatement();
if (statement.equals("*"))
{
statement = "ISNODE:*";
}
ResultSet searchResults = null;
try
{
searchResults = searchService.query(Utils.convertToStoreRef(this.store),
this.query.getLanguage(), statement);
int totalRows = searchResults.length();
int lastRow = calculateLastRowIndex(totalRows);
int currentBatchSize = lastRow - this.position;
if (logger.isDebugEnabled())
logger.debug("Total rows = " + totalRows + ", current batch size = " + currentBatchSize);
org.alfresco.repo.webservice.types.ResultSet batchResults = new org.alfresco.repo.webservice.types.ResultSet();
List<org.alfresco.repo.webservice.types.ResultSetRow> rowList =
new ArrayList<org.alfresco.repo.webservice.types.ResultSetRow>();
for (int x = this.position; x < lastRow; x++)
{
ResultSetRow origRow = searchResults.getRow(x);
NodeRef nodeRef = origRow.getNodeRef();
// search can return nodes that no longer exist, so we need to ignore these
if(nodeService.exists(nodeRef) == false)
{
if(logger.isDebugEnabled())
{
logger.warn("Search returned node that doesn't exist: " + nodeRef);
}
continue;
}
ResultSetRowNode rowNode = createResultSetRowNode(nodeRef, nodeService);
// get the data for the row and build up the columns structure
Map<Path, Serializable> values = origRow.getValues();
NamedValue[] columns = new NamedValue[values.size() + 1];
int col = 0;
for (Path path : values.keySet())
{
// Get the attribute QName from the result path
String attributeName = path.last().toString();
if (attributeName.startsWith("@") == true)
{
attributeName = attributeName.substring(1);
}
columns[col] = Utils.createNamedValue(dictionaryService, QName.createQName(attributeName), values.get(path));
col++;
}
// add one extra column for the node's path
columns[col] = Utils.createNamedValue(dictionaryService, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "path"), nodeService.getPath(nodeRef).toString());
org.alfresco.repo.webservice.types.ResultSetRow row = new org.alfresco.repo.webservice.types.ResultSetRow();
row.setColumns(columns);
row.setScore(origRow.getScore());
row.setRowIndex(x);
row.setNode(rowNode);
// add the row to the overall results list
rowList.add(row);
}
// TODO: build up the meta data data structure if we've been asked to
// add the rows to the result set and set the total row count
org.alfresco.repo.webservice.types.ResultSetRow[] rows =
rowList.toArray(new org.alfresco.repo.webservice.types.ResultSetRow[rowList.size()]);;
batchResults.setRows(rows);
batchResults.setTotalRowCount(totalRows);
queryResult = new QueryResult(getId(), batchResults);
// move the position on
updatePosition(totalRows, queryResult);
if (logger.isDebugEnabled())
logger.debug("After getNextResultsBatch: " + toString());
}
finally
{
if (searchResults != null)
{
searchResults.close();
}
}
}
return queryResult;
}
/**
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
StringBuilder builder = new StringBuilder(super.toString());
builder.append(" (id=").append(getId());
builder.append(" batchSize=").append(this.batchSize);
builder.append(" position=").append(this.position);
builder.append(" store=").append(this.store.getScheme()).append(":").append(this.store.getAddress());
builder.append(" language=").append(this.query.getLanguage());
builder.append(" statement=").append(this.query.getStatement());
builder.append(")");
return builder.toString();
}
}

View File

@@ -0,0 +1,184 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.webservice.repository;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.webservice.AbstractQuery;
import org.alfresco.repo.webservice.Utils;
import org.alfresco.repo.webservice.types.NamedValue;
import org.alfresco.repo.webservice.types.Query;
import org.alfresco.repo.webservice.types.ResultSet;
import org.alfresco.repo.webservice.types.ResultSetRow;
import org.alfresco.repo.webservice.types.ResultSetRowNode;
import org.alfresco.repo.webservice.types.Store;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.Path;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
/**
* A query to using full search.
*
* @author Derek Hulley
* @since 2.1
*/
public class SearchQuery extends AbstractQuery<ResultSet>
{
private static final long serialVersionUID = 5429510102265380433L;
private Store store;
private Query query;
/**
* @param node The node to query against
* @param association The association type to query or <tt>null</tt> to query all
*/
public SearchQuery(Store store, Query query)
{
this.store = store;
this.query = query;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(128);
sb.append("SearchQuery")
.append("[ store=").append(this.store.getScheme()).append(":").append(this.store.getAddress())
.append(" language=").append(this.query.getLanguage())
.append(" statement=").append(this.query.getStatement())
.append("]");
return sb.toString();
}
/**
* {@inheritDoc}
*/
public ResultSet execute(ServiceRegistry serviceRegistry)
{
SearchService searchService = serviceRegistry.getSearchService();
NodeService nodeService = serviceRegistry.getNodeService();
DictionaryService dictionaryService = serviceRegistry.getDictionaryService();
// handle the special search string of * meaning, get everything
String statement = query.getStatement();
if (statement.equals("*"))
{
statement = "ISNODE:*";
}
org.alfresco.service.cmr.search.ResultSet searchResults = null;
try
{
StoreRef storeRef = Utils.convertToStoreRef(store);
searchResults = searchService.query(storeRef, query.getLanguage(), statement);
return convert(
nodeService,
dictionaryService,
searchResults);
}
finally
{
if (searchResults != null)
{
try
{
searchResults.close();
}
catch (Throwable e)
{
}
}
}
}
private ResultSet convert(
NodeService nodeService,
DictionaryService dictionaryService,
org.alfresco.service.cmr.search.ResultSet searchResults)
{
ResultSet results = new ResultSet();
List<ResultSetRow> rowsList = new ArrayList<org.alfresco.repo.webservice.types.ResultSetRow>();
int index = 0;
for (org.alfresco.service.cmr.search.ResultSetRow searchRow : searchResults)
{
NodeRef nodeRef = searchRow.getNodeRef();
// Search can return nodes that no longer exist, so we need to ignore these
if (!nodeService.exists(nodeRef))
{
continue;
}
ResultSetRowNode rowNode = createResultSetRowNode(nodeRef, nodeService);
// get the data for the row and build up the columns structure
Map<Path, Serializable> values = searchRow.getValues();
NamedValue[] columns = new NamedValue[values.size() + 1];
int col = 0;
for (Path path : values.keySet())
{
// Get the attribute QName from the result path
String attributeName = path.last().toString();
if (attributeName.startsWith("@") == true)
{
attributeName = attributeName.substring(1);
}
columns[col] = Utils.createNamedValue(dictionaryService, QName.createQName(attributeName), values.get(path));
col++;
}
// add one extra column for the node's path
columns[col] = Utils.createNamedValue(dictionaryService, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "path"), nodeService.getPath(nodeRef).toString());
ResultSetRow row = new org.alfresco.repo.webservice.types.ResultSetRow();
row.setColumns(columns);
row.setScore(searchRow.getScore());
row.setRowIndex(index);
row.setNode(rowNode);
// add the row to the overall results list
rowsList.add(row);
index++;
}
// Convert list to array
int totalRows = rowsList.size();
ResultSetRow[] rows = rowsList.toArray(new org.alfresco.repo.webservice.types.ResultSetRow[totalRows]);
// add the rows to the result set and set the total row count
results.setRows(rows);
results.setTotalRowCount(totalRows);
return results;
}
}