Merged SWIFT to HEAD

25250: SWIFT branch moved to 4.0.0 schema 5000
   25435: Initial checkin for ALF-7069
   25450: ALF-7069:
          - add maxResults to SOLR DAO
          - refactoring
   25480: ALF-7069: further enhancements + unit tests
          - include/exclude aspects, store protocol + identifier

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@27999 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2011-05-24 01:02:38 +00:00
parent 7117ff4722
commit 4490431ba9
9 changed files with 1331 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
<webscript>
<shortname>Get the nodes in the given transactions</shortname>
<description>Get the nodes updated/deleted in the given transactions.</description>
<url>/api/solr/nodes?txnIds={txnIds}&amp;{fromNodeId?}&amp;{toNodeId?}&amp;{count?}</url>
<format default="json">argument</format>
<authentication>admin</authentication>
<transaction allow="readonly">required</transaction>
</webscript>

View File

@@ -0,0 +1,11 @@
<#import "solr.lib.ftl" as solrLib/>
{
"nodes" :
[
<#list nodes as node>
<@solrLib.nodeJSON node=node/>
<#if node_has_next>,</#if>
</#list>
],
"count": ${count}
}

View File

@@ -0,0 +1,8 @@
<webscript>
<shortname>Get transactions</shortname>
<description>Get the transactions from the given commit time.</description>
<url>/api/solr/transactions?fromCommitTime={fromCommitTime}</url>
<format default="json">argument</format>
<authentication>admin</authentication>
<transaction allow="readonly">required</transaction>
</webscript>

View File

@@ -0,0 +1,10 @@
<#import "solr.lib.ftl" as solrLib/>
{
"transactions" :
[
<#list transactions as txn>
<@solrLib.transactionJSON txn=txn/>
<#if txn_has_next>,</#if>
</#list>
]
}

View File

@@ -0,0 +1,16 @@
<#macro transactionJSON txn>
{
"id": "${txn.id?c}",
"commitTimeMs": "${txn.commitTimeMs?c}",
"updates": "${txn.updates?c}",
"deletes": "${txn.deletes?c}"
}
</#macro>
<#macro nodeJSON node>
{
"nodeID": "${node.id?c}",
"txnID": "${node.transaction.id?c}",
"deleted": "${node.deleted?string}"
}
</#macro>

View File

@@ -1176,4 +1176,21 @@
</bean>
<!-- -->
<!-- SOLR -->
<!-- -->
<!-- -->
<bean id="webscript.org.alfresco.repository.solr.getTransactions.get"
class="org.alfresco.repo.web.scripts.solr.GetTransactions"
parent="webscript">
<property name="solrDAO" ref="solrDAO"/>
</bean>
<bean id="webscript.org.alfresco.repository.solr.getNodes.get"
class="org.alfresco.repo.web.scripts.solr.GetNodes"
parent="webscript">
<property name="solrDAO" ref="solrDAO"/>
</bean>
</beans>

View File

@@ -0,0 +1,155 @@
package org.alfresco.repo.web.scripts.solr;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.domain.node.Node;
import org.alfresco.repo.domain.solr.NodeParameters;
import org.alfresco.repo.domain.solr.SOLRDAO;
import org.alfresco.repo.domain.solr.SOLRDAO.NodeQueryCallback;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Support for SOLR. Get a list of nodes in the given transactions.
*
* Supports fromNodeId, toNodeId, count (all optional) to control the number of nodes returned
* e.g. (null, null, 1000) will return at most 1000 nodes starting from the first node in the first transaction.
* e.g. (1234, null, 1000) will return at most 1000 nodes starting from the node id 1234.
*
* @since 4.0
*/
public class GetNodes extends DeclarativeWebScript
{
protected static final Log logger = LogFactory.getLog(GetNodes.class);
private SOLRDAO solrDAO;
/**
* @param solrDAO the solrDAO to set
*/
public void setSolrDAO(SOLRDAO solrDAO)
{
this.solrDAO = solrDAO;
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)
{
String txnIdsString = req.getParameter("txnIds");
if(txnIdsString == null)
{
throw new WebScriptException("txnIds parameter is required for GetNodes");
}
String param = req.getParameter("fromNodeId");
Long fromNodeId = (param == null ? null : Long.valueOf(param));
param = req.getParameter("toNodeId");
Long toNodeId = (param == null ? null : Long.valueOf(param));
param = req.getParameter("excludeAspects");
Set<QName> excludeAspects = null;
if(param != null)
{
String[] excludeAspectsStrings = param.split(",");
excludeAspects = new HashSet<QName>(excludeAspectsStrings.length);
for(String excludeAspect : excludeAspectsStrings)
{
excludeAspects.add(QName.createQName(excludeAspect.trim()));
}
}
param = req.getParameter("includeAspects");
Set<QName> includeAspects = null;
if(param != null)
{
String[] includeAspectsStrings = param.split(",");
includeAspects = new HashSet<QName>(includeAspectsStrings.length);
for(String includeAspect : includeAspectsStrings)
{
includeAspects.add(QName.createQName(includeAspect.trim()));
}
}
param = req.getParameter("maxResults");
int maxResults = (param == null ? 0 : Integer.valueOf(param));
param = req.getParameter("storeProtocol");
String storeProtocol = param;
param = req.getParameter("storeIdentifier");
String storeIdentifier = param;
String[] txnIdStrings = txnIdsString.split(",");
List<Long> txnIds = new ArrayList<Long>(txnIdStrings.length);
for(String txnIdString : txnIdStrings)
{
txnIds.add(Long.valueOf(txnIdString.trim()));
}
WebNodeQueryCallback nodeQueryCallback = new WebNodeQueryCallback(maxResults);
NodeParameters nodeParameters = new NodeParameters();
nodeParameters.setTransactionIds(txnIds);
nodeParameters.setFromNodeId(fromNodeId);
nodeParameters.setToNodeId(toNodeId);
nodeParameters.setExcludeAspects(excludeAspects);
nodeParameters.setIncludeAspects(includeAspects);
nodeParameters.setStoreProtocol(storeProtocol);
nodeParameters.setStoreIdentifier(storeIdentifier);
solrDAO.getNodes(nodeParameters, maxResults, nodeQueryCallback);
Map<String, Object> model = new HashMap<String, Object>(2, 1.0f);
List<Node> nodes = nodeQueryCallback.getNodes();
model.put("nodes", nodes);
model.put("count", nodes.size());
if (logger.isDebugEnabled())
{
logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model);
}
return model;
}
/**
*
*
*/
private static class WebNodeQueryCallback implements NodeQueryCallback
{
private ArrayList<Node> nodes;
public WebNodeQueryCallback(int count) {
super();
nodes = new ArrayList<Node>(count == 0 || count == Integer.MAX_VALUE ? 100 : count);
}
@Override
public boolean handleNode(Node node) {
nodes.add(node);
// continue - get next node
return true;
}
public List<Node> getNodes()
{
return nodes;
}
}
}

View File

@@ -0,0 +1,63 @@
package org.alfresco.repo.web.scripts.solr;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.domain.solr.SOLRDAO;
import org.alfresco.repo.domain.solr.Transaction;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Support for SOLR. Get a list of transactions with a commit time greater than or equal to the given parameter.
*
* @since 4.0
*/
public class GetTransactions extends DeclarativeWebScript
{
protected static final Log logger = LogFactory.getLog(GetTransactions.class);
private SOLRDAO solrDAO;
/**
* @param solrDAO the SOLDAO to set
*/
public void setSolrDAO(SOLRDAO solrDAO)
{
this.solrDAO = solrDAO;
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)
{
String minTxnIdParam = req.getParameter("minTxnId");
String fromCommitTimeParam = req.getParameter("fromCommitTime");
String maxResultsParam = req.getParameter("maxResults");
Long minTxnId = (minTxnIdParam == null ? null : Long.valueOf(minTxnIdParam));
Long fromCommitTime = (fromCommitTimeParam == null ? null : Long.valueOf(fromCommitTimeParam));
int maxResults = (maxResultsParam == null ? 0 : Integer.valueOf(maxResultsParam));
List<Transaction> transactions = solrDAO.getTransactions(minTxnId, fromCommitTime, maxResults);
Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
model.put("transactions", transactions);
if (logger.isDebugEnabled())
{
logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model);
}
return model;
}
}

File diff suppressed because it is too large Load Diff