mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Fix for ALF-2376: Expose cmis:baseTypeId as queryable property (or at least include it in the returned query result properties) PART 2: baseTypeId is now queryable
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19821 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -19,13 +19,29 @@
|
||||
package org.alfresco.cmis.mapping;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.alfresco.cmis.CMISDictionaryModel;
|
||||
import org.alfresco.cmis.CMISQueryException;
|
||||
import org.alfresco.cmis.CMISScope;
|
||||
import org.alfresco.cmis.CMISTypeDefinition;
|
||||
import org.alfresco.repo.search.impl.lucene.AnalysisMode;
|
||||
import org.alfresco.repo.search.impl.lucene.LuceneFunction;
|
||||
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
|
||||
import org.alfresco.repo.search.impl.querymodel.PredicateMode;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.queryParser.ParseException;
|
||||
import org.apache.lucene.search.BooleanQuery;
|
||||
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
import org.apache.lucene.search.BooleanClause.Occur;
|
||||
|
||||
/**
|
||||
* Get the CMIS object type id property
|
||||
@@ -64,4 +80,109 @@ public class BaseTypeIdProperty extends AbstractProperty
|
||||
return getServiceRegistry().getCMISDictionaryService().findTypeForClass(type, CMISScope.RELATIONSHIP).getBaseType().getTypeId().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query buildLuceneEquality(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
|
||||
{
|
||||
return lqp.getFieldQuery("TYPE", getBaseType(getValueAsString(value)), AnalysisMode.IDENTIFIER, luceneFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query buildLuceneInequality(LuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
|
||||
{
|
||||
return lqp.getDoesNotMatchFieldQuery("TYPE", getBaseType(getValueAsString(value)), AnalysisMode.IDENTIFIER, luceneFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query buildLuceneIn(LuceneQueryParser lqp, Collection<Serializable> values, Boolean not, PredicateMode mode) throws ParseException
|
||||
{
|
||||
String field = "TYPE";
|
||||
|
||||
// Check type conversion
|
||||
|
||||
|
||||
Collection<String> asStrings = DefaultTypeConverter.INSTANCE.convert(String.class, values);
|
||||
|
||||
if (asStrings.size() == 0)
|
||||
{
|
||||
if (not)
|
||||
{
|
||||
return new MatchAllDocsQuery();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new TermQuery(new Term("NO_TOKENS", "__"));
|
||||
}
|
||||
}
|
||||
else if (asStrings.size() == 1)
|
||||
{
|
||||
String value = asStrings.iterator().next();
|
||||
if (not)
|
||||
{
|
||||
return lqp.getDoesNotMatchFieldQuery(field, getBaseType(value), AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
|
||||
}
|
||||
else
|
||||
{
|
||||
return lqp.getFieldQuery(field, getBaseType(value), AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
BooleanQuery booleanQuery = new BooleanQuery();
|
||||
if (not)
|
||||
{
|
||||
booleanQuery.add(new MatchAllDocsQuery(), Occur.MUST);
|
||||
}
|
||||
for (String value : asStrings)
|
||||
{
|
||||
Query any = lqp.getFieldQuery(field, getBaseType(value), AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
|
||||
if (not)
|
||||
{
|
||||
booleanQuery.add(any, Occur.MUST_NOT);
|
||||
}
|
||||
else
|
||||
{
|
||||
booleanQuery.add(any, Occur.SHOULD);
|
||||
}
|
||||
}
|
||||
return booleanQuery;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query buildLuceneExists(LuceneQueryParser lqp, Boolean not) throws ParseException
|
||||
{
|
||||
if (not)
|
||||
{
|
||||
return new TermQuery(new Term("NO_TOKENS", "__"));
|
||||
}
|
||||
else
|
||||
{
|
||||
return new MatchAllDocsQuery();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getBaseType(String tableName)
|
||||
{
|
||||
CMISTypeDefinition typeDef = getServiceRegistry().getCMISDictionaryService().findTypeByQueryName(tableName);
|
||||
if (typeDef == null)
|
||||
{
|
||||
throw new CMISQueryException("Unknwon base type: " + tableName);
|
||||
}
|
||||
if(!typeDef.getBaseType().equals(typeDef))
|
||||
{
|
||||
throw new CMISQueryException("Not a base type: " + tableName);
|
||||
}
|
||||
if(!typeDef.isQueryable())
|
||||
{
|
||||
throw new CMISQueryException("Base type is not queryable: " + tableName);
|
||||
}
|
||||
return typeDef.getTypeId().getQName().toString();
|
||||
}
|
||||
|
||||
private String getValueAsString(Serializable value)
|
||||
{
|
||||
String asString = DefaultTypeConverter.INSTANCE.convert(String.class, value);
|
||||
return asString;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user