Merge from SEAMIST3

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10733 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2008-09-04 11:22:17 +00:00
parent 41b5618d1d
commit a6625b1c61
63 changed files with 5450 additions and 962 deletions

View File

@@ -25,19 +25,24 @@
package org.alfresco.cmis.property;
import java.io.Serializable;
import java.util.Collection;
import org.alfresco.cmis.dictionary.CMISMapping;
import org.alfresco.cmis.dictionary.CMISScope;
import org.alfresco.cmis.search.CMISQueryException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.search.impl.lucene.ParseException;
import org.alfresco.repo.search.impl.querymodel.PredicateMode;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.apache.lucene.index.Term;
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 id property.
@@ -80,20 +85,30 @@ public class ObjectIdPropertyAccessor extends AbstractNamedPropertyAccessor
return CMISScope.OBJECT;
}
private String getLuceneFieldName()
{
return "ID";
}
private String getValueAsString(Serializable value)
{
Object converted = DefaultTypeConverter.INSTANCE.convert(getServiceRegistry().getDictionaryService().getDataType(DataTypeDefinition.NODE_REF), value);
String asString = DefaultTypeConverter.INSTANCE.convert(String.class, converted);
return asString;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.property.NamedPropertyAccessor#buildLuceneEquality(org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.lang.String, java.io.Serializable)
* java.lang.String, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneEquality(LuceneQueryParser lqp, String propertyName, Serializable value) throws ParseException
public Query buildLuceneEquality(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException
{
// TODO: version label form
Object converted = DefaultTypeConverter.INSTANCE.convert(getServiceRegistry().getDictionaryService().getDataType(DataTypeDefinition.NODE_REF), value);
String asString = DefaultTypeConverter.INSTANCE.convert(String.class, converted);
return lqp.getFieldQuery("ID", asString);
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
return lqp.getFieldQuery(field, stringValue);
}
/*
@@ -111,7 +126,159 @@ public class ObjectIdPropertyAccessor extends AbstractNamedPropertyAccessor
else
{
return new MatchAllDocsQuery();
}
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.property.NamedPropertyAccessor#buildLuceneGreaterThan(org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.lang.String, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneGreaterThan(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException
{
throw new CMISQueryException("Property "+getPropertyName() +" can not be used in a 'greater than' comparison");
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.property.NamedPropertyAccessor#buildLuceneGreaterThanOrEquals(org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.lang.String, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneGreaterThanOrEquals(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException
{
throw new CMISQueryException("Property "+getPropertyName() +" can not be used in a 'greater than or equals' comparison");
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.property.NamedPropertyAccessor#buildLuceneIn(org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.lang.String, java.util.Collection, java.lang.Boolean,
* org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneIn(LuceneQueryParser lqp, String propertyName, Collection<Serializable> values, Boolean not, PredicateMode mode) throws ParseException
{
String field = getLuceneFieldName();
// Check type conversion
@SuppressWarnings("unused")
Object converted = DefaultTypeConverter.INSTANCE.convert(getServiceRegistry().getDictionaryService().getDataType(DataTypeDefinition.NODE_REF), values);
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, value);
}
else
{
return lqp.getFieldQuery(field, value);
}
}
else
{
BooleanQuery booleanQuery = new BooleanQuery();
if (not)
{
booleanQuery.add(new MatchAllDocsQuery(), Occur.MUST);
}
for (String value : asStrings)
{
Query any = lqp.getFieldQuery(field, value);
if (not)
{
booleanQuery.add(any, Occur.MUST_NOT);
}
else
{
booleanQuery.add(any, Occur.SHOULD);
}
}
return booleanQuery;
}
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.property.NamedPropertyAccessor#buildLuceneInequality(org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.lang.String, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneInequality(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
return lqp.getDoesNotMatchFieldQuery(field, stringValue);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.property.NamedPropertyAccessor#buildLuceneLessThan(org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.lang.String, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneLessThan(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException
{
throw new CMISQueryException("Property "+getPropertyName() +" can not be used in a 'less than' comparison");
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.property.NamedPropertyAccessor#buildLuceneLessThanOrEquals(org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.lang.String, java.io.Serializable, org.alfresco.repo.search.impl.querymodel.PredicateMode)
*/
public Query buildLuceneLessThanOrEquals(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException
{
throw new CMISQueryException("Property "+getPropertyName() +" can not be used in a 'less than or equals' comparison");
}
/*
* (non-Javadoc)
*
* @see org.alfresco.cmis.property.NamedPropertyAccessor#buildLuceneLike(org.alfresco.repo.search.impl.lucene.LuceneQueryParser,
* java.lang.String, java.io.Serializable, java.lang.Boolean)
*/
public Query buildLuceneLike(LuceneQueryParser lqp, String propertyName, Serializable value, Boolean not) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
if (not)
{
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(new MatchAllDocsQuery(), Occur.MUST);
booleanQuery.add(lqp.getLikeQuery(field, stringValue), Occur.MUST_NOT);
return booleanQuery;
}
else
{
return lqp.getLikeQuery(field, stringValue);
}
}
/* (non-Javadoc)
* @see org.alfresco.cmis.property.NamedPropertyAccessor#getLuceneSortField(java.lang.String)
*/
public String getLuceneSortField(String propertyName)
{
return getLuceneFieldName();
}
}