More SearchService refactor. Added CMIS SQL to the search service. Tidy ups. FTS supports default namespace and templates via search parameters API. (MOB-568, MOB-569)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14463 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrew Hind
2009-05-28 10:34:51 +00:00
parent d8c87a5abd
commit e46585becf
53 changed files with 1365 additions and 390 deletions

View File

@@ -1049,6 +1049,10 @@ public class CMISQueryParser
qualifer = columnReferenceNode.getChild(1).getText();
}
CMISPropertyDefinition propDef = cmisDictionaryService.findProperty(cmisPropertyName, null);
if(propDef == null)
{
throw new CMISQueryException("Unknown column/property " + cmisPropertyName);
}
return factory.createPropertyArgument(argumentName, propDef.isQueryable(), propDef.isOrderable(), qualifer, propDef.getPropertyId().getName());
}

View File

@@ -38,6 +38,7 @@ import org.alfresco.cmis.CMISServices;
import org.alfresco.repo.search.impl.querymodel.Query;
import org.alfresco.repo.search.impl.querymodel.QueryEngine;
import org.alfresco.repo.search.impl.querymodel.QueryEngineResults;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.ResultSet;
@@ -53,6 +54,8 @@ public class CMISQueryServiceImpl implements CMISQueryService
private QueryEngine queryEngine;
private NodeService nodeService;
private DictionaryService alfrescoDictionaryService;
/**
* @param service
@@ -90,6 +93,17 @@ public class CMISQueryServiceImpl implements CMISQueryService
this.nodeService = nodeService;
}
/**
* @param alfrescoDictionaryService
* the Alfresco Dictionary Service to set
*/
public void setAlfrescoDictionaryService(DictionaryService alfrescoDictionaryService)
{
this.alfrescoDictionaryService = alfrescoDictionaryService;
}
/*
* (non-Javadoc)
*
@@ -121,7 +135,7 @@ public class CMISQueryServiceImpl implements CMISQueryService
wrapped.put(selector, current);
}
}
CMISResultSet cmis = new CMISResultSetImpl(wrapped, options, nodeService, query, cmisDictionaryService);
CMISResultSet cmis = new CMISResultSetImpl(wrapped, options, nodeService, query, cmisDictionaryService, alfrescoDictionaryService);
return cmis;
}

View File

@@ -25,8 +25,10 @@
package org.alfresco.cmis.search;
import org.alfresco.cmis.CMISDataTypeEnum;
import org.alfresco.cmis.CMISDictionaryService;
import org.alfresco.cmis.CMISPropertyDefinition;
import org.alfresco.cmis.CMISResultSetColumn;
import org.alfresco.service.namespace.QName;
/**
* @author andyh
@@ -39,13 +41,19 @@ public class CMISResultSetColumnImpl implements CMISResultSetColumn
private CMISPropertyDefinition propertyDefinition;
private CMISDataTypeEnum propertyType;
private CMISDataTypeEnum dataType;
CMISResultSetColumnImpl(String name, CMISPropertyDefinition propertyDefinition, CMISDataTypeEnum propertyType)
private QName alfrescoPropertyQName;
private QName alfrescoDataTypeQName;
CMISResultSetColumnImpl(String name, CMISPropertyDefinition propertyDefinition, CMISDataTypeEnum dataType, QName alfrescoPropertyQName, QName alfrescoDataTypeQName)
{
this.name = name;
this.propertyDefinition = propertyDefinition;
this.propertyType = propertyType;
this.dataType = dataType;
this.alfrescoPropertyQName = alfrescoPropertyQName;
this.alfrescoDataTypeQName = alfrescoDataTypeQName;
}
@@ -60,7 +68,7 @@ public class CMISResultSetColumnImpl implements CMISResultSetColumn
/* (non-Javadoc)
* @see org.alfresco.cmis.search.CMISResultSetColumn#getPropertyDefinition()
*/
public CMISPropertyDefinition getPropertyDefinition()
public CMISPropertyDefinition getCMISPropertyDefinition()
{
return propertyDefinition;
}
@@ -68,9 +76,21 @@ public class CMISResultSetColumnImpl implements CMISResultSetColumn
/* (non-Javadoc)
* @see org.alfresco.cmis.search.CMISResultSetColumn#getPropertyType()
*/
public CMISDataTypeEnum getPropertyType()
public CMISDataTypeEnum getCMISDataType()
{
return propertyType;
return dataType;
}
public QName getDataType()
{
return alfrescoDataTypeQName;
}
public QName getPropertyType()
{
return alfrescoPropertyQName;
}
}

View File

@@ -25,9 +25,11 @@
package org.alfresco.cmis.search;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -37,10 +39,13 @@ import org.alfresco.cmis.CMISResultSet;
import org.alfresco.cmis.CMISResultSetMetaData;
import org.alfresco.cmis.CMISResultSetRow;
import org.alfresco.repo.search.impl.querymodel.Query;
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.LimitBy;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.ResultSetRow;
/**
* @author andyh
@@ -58,15 +63,18 @@ public class CMISResultSetImpl implements CMISResultSet, Serializable
Query query;
CMISDictionaryService cmisDictionaryService;
DictionaryService alfrescoDictionaryService;
public CMISResultSetImpl(Map<String, ResultSet> wrapped, CMISQueryOptions options, NodeService nodeService, Query query, CMISDictionaryService cmisDictionaryService)
public CMISResultSetImpl(Map<String, ResultSet> wrapped, CMISQueryOptions options, NodeService nodeService, Query query, CMISDictionaryService cmisDictionaryService, DictionaryService alfrescoDictionaryService)
{
this.wrapped = wrapped;
this.options = options;
this.nodeService = nodeService;
this.query = query;
this.cmisDictionaryService = cmisDictionaryService;
this.alfrescoDictionaryService = alfrescoDictionaryService;
}
/*
@@ -95,7 +103,7 @@ public class CMISResultSetImpl implements CMISResultSet, Serializable
*/
public CMISResultSetMetaData getMetaData()
{
return new CMISResultSetMetaDataImpl(options, query, cmisDictionaryService);
return new CMISResultSetMetaDataImpl(options, query, cmisDictionaryService, alfrescoDictionaryService);
}
/*
@@ -197,4 +205,68 @@ public class CMISResultSetImpl implements CMISResultSet, Serializable
return scores;
}
public ChildAssociationRef getChildAssocRef(int n)
{
NodeRef nodeRef = getNodeRef(n);
return nodeService.getPrimaryParent(nodeRef);
}
public List<ChildAssociationRef> getChildAssocRefs()
{
ArrayList<ChildAssociationRef> cars = new ArrayList<ChildAssociationRef>(length());
for (ResultSetRow row : this)
{
cars.add(row.getChildAssocRef());
}
return cars;
}
public NodeRef getNodeRef(int n)
{
Map<String, NodeRef> refs = getNodeRefs(n);
if(refs.size() == 1)
{
return refs.values().iterator().next();
}
else
{
throw new IllegalStateException("Ambiguous selector");
}
}
public List<NodeRef> getNodeRefs()
{
ArrayList<NodeRef> nodeRefs = new ArrayList<NodeRef>(length());
for (ResultSetRow row : this)
{
nodeRefs.add(row.getNodeRef());
}
return nodeRefs;
}
public CMISResultSetMetaData getResultSetMetaData()
{
return getMetaData();
}
public float getScore(int n)
{
Map<String, Float> scores = getScores(n);
if(scores.size() == 1)
{
return scores.values().iterator().next();
}
else
{
throw new IllegalStateException("Ambiguous selector");
}
}
public int length()
{
return getLength();
}
}

View File

@@ -40,6 +40,12 @@ import org.alfresco.repo.search.impl.querymodel.PropertyArgument;
import org.alfresco.repo.search.impl.querymodel.Query;
import org.alfresco.repo.search.impl.querymodel.Selector;
import org.alfresco.repo.search.impl.querymodel.impl.functions.PropertyAccessor;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.search.LimitBy;
import org.alfresco.service.cmr.search.PermissionEvaluationMode;
import org.alfresco.service.cmr.search.ResultSetType;
import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.namespace.QName;
/**
@@ -53,7 +59,7 @@ public class CMISResultSetMetaDataImpl implements CMISResultSetMetaData
private Map<String, CMISResultSetSelector> selectorMetaData;
public CMISResultSetMetaDataImpl(CMISQueryOptions options, Query query, CMISDictionaryService cmisDictionaryService)
public CMISResultSetMetaDataImpl(CMISQueryOptions options, Query query, CMISDictionaryService cmisDictionaryService, DictionaryService alfrescoDictionaryService)
{
this.options = options;
@@ -71,10 +77,22 @@ public class CMISResultSetMetaDataImpl implements CMISResultSetMetaData
{
CMISPropertyDefinition propertyDefinition = null;
CMISDataTypeEnum type = null;
QName alfrescoPropertyQName = null;
QName alfrescoDataTypeQName = null;
if (column.getFunction().getName().equals(PropertyAccessor.NAME))
{
PropertyArgument arg = (PropertyArgument) column.getFunctionArguments().get(PropertyAccessor.ARG_PROPERTY);
String propertyName = arg.getPropertyName();
alfrescoPropertyQName = QName.createQName(propertyName);
PropertyDefinition alfPropDef = alfrescoDictionaryService.getProperty(alfrescoPropertyQName);
if(alfPropDef == null)
{
alfrescoPropertyQName = null;
}
else
{
alfrescoDataTypeQName = alfPropDef.getDataType().getName();
}
propertyDefinition = cmisDictionaryService.findProperty(propertyName, null);
type = propertyDefinition.getDataType();
}
@@ -82,7 +100,11 @@ public class CMISResultSetMetaDataImpl implements CMISResultSetMetaData
{
type = cmisDictionaryService.findDataType(column.getFunction().getReturnType());
}
CMISResultSetColumn cmd = new CMISResultSetColumnImpl(column.getAlias(), propertyDefinition, type);
if(alfrescoDataTypeQName == null)
{
alfrescoDataTypeQName = type.getDefaultDataType();
}
CMISResultSetColumn cmd = new CMISResultSetColumnImpl(column.getAlias(), propertyDefinition, type, alfrescoPropertyQName, alfrescoDataTypeQName);
columnMetaData.put(cmd.getName(), cmd);
}
}
@@ -157,4 +179,24 @@ public class CMISResultSetMetaDataImpl implements CMISResultSetMetaData
return selectorMetaData.values().toArray(new CMISResultSetSelector[0]);
}
public LimitBy getLimitedBy()
{
throw new UnsupportedOperationException();
}
public PermissionEvaluationMode getPermissionEvaluationMode()
{
throw new UnsupportedOperationException();
}
public ResultSetType getResultSetType()
{
return ResultSetType.COLUMN_AND_NODE_REF;
}
public SearchParameters getSearchParameters()
{
throw new UnsupportedOperationException();
}
}

View File

@@ -30,11 +30,16 @@ import java.util.Map;
import org.alfresco.cmis.CMISDictionaryService;
import org.alfresco.cmis.CMISResultSet;
import org.alfresco.cmis.CMISResultSetMetaData;
import org.alfresco.cmis.CMISResultSetRow;
import org.alfresco.repo.search.impl.querymodel.Column;
import org.alfresco.repo.search.impl.querymodel.Query;
import org.alfresco.repo.search.results.ResultSetSPIWrapper;
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.ResultSet;
import org.alfresco.service.namespace.QName;
/**
* @author andyh
@@ -87,9 +92,9 @@ public class CMISResultSetRowImpl implements CMISResultSetRow
*
* @see org.alfresco.cmis.search.CMISResultSetRow#getResultSet()
*/
public CMISResultSet getResultSet()
public ResultSet getResultSet()
{
return resultSet;
return new ResultSetSPIWrapper<CMISResultSetRow, CMISResultSetMetaData>(resultSet);
}
/*
@@ -186,4 +191,37 @@ public class CMISResultSetRowImpl implements CMISResultSetRow
return answer;
}
public CMISResultSet getCMISResultSet()
{
return resultSet;
}
public ChildAssociationRef getChildAssocRef()
{
NodeRef nodeRef = getNodeRef();
return nodeService.getPrimaryParent(nodeRef);
}
public NodeRef getNodeRef()
{
if(getCMISResultSet().getMetaData().getColumns().length == 1)
{
return getNodeRef(getCMISResultSet().getMetaData().getColumns()[0].getName());
}
else
{
throw new UnsupportedOperationException("Ambiguous selector");
}
}
public QName getQName()
{
return getChildAssocRef().getQName();
}
public Serializable getValue(QName qname)
{
throw new UnsupportedOperationException();
}
}

View File

@@ -26,6 +26,7 @@ package org.alfresco.cmis.search;
import org.alfresco.cmis.CMISResultSetSelector;
import org.alfresco.cmis.CMISTypeDefinition;
import org.alfresco.service.namespace.QName;
/**
* @author andyh
@@ -60,4 +61,10 @@ public class CMISResultSetSelectorImpl implements CMISResultSetSelector
return typeDefinition;
}
public QName getType()
{
return typeDefinition.getTypeId().getQName();
}
}