ALF-9933: RSOLR 042: Add query support for new CMIS object ids

- Part 1: fix and test the old implementation (non opencmis)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30007 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrew Hind
2011-08-23 20:20:09 +00:00
parent f7f23f6eb7
commit 47b39283e2
3 changed files with 103 additions and 22 deletions

View File

@@ -47,6 +47,7 @@ import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.thumbnail.ThumbnailService;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
@@ -111,6 +112,8 @@ public abstract class BaseCMISTest extends TestCase
protected NamespaceDAOImpl namespaceDao;
protected VersionService versionService;
public void setUp() throws Exception
{
serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
@@ -135,6 +138,8 @@ public abstract class BaseCMISTest extends TestCase
permissionService = (PermissionService) ctx.getBean("permissionService");
versionService = (VersionService) ctx.getBean("versionService");
authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");

View File

@@ -108,7 +108,33 @@ public class ObjectIdProperty extends AbstractVersioningProperty
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
return lqp.getFieldQuery(field, stringValue, AnalysisMode.IDENTIFIER, luceneFunction);
String[] split = stringValue.split(";");
if(split.length == 1)
{
return lqp.getFieldQuery(field, stringValue, AnalysisMode.IDENTIFIER, luceneFunction);
}
else
{
if(split[1].equalsIgnoreCase("PWC"))
{
return new TermQuery(new Term("NO_TOKENS", "__"));
}
BooleanQuery query = new BooleanQuery();
BooleanQuery part1 = new BooleanQuery();
part1.add(lqp.getFieldQuery(field, split[0], AnalysisMode.IDENTIFIER, luceneFunction), Occur.MUST);
part1.add(lqp.getFieldQuery("@"+ContentModel.PROP_VERSION_LABEL.toString(), split[1], AnalysisMode.IDENTIFIER, luceneFunction), Occur.MUST);
query.add(part1, Occur.SHOULD);
if(split[1].equals("1.0"))
{
BooleanQuery part2 = new BooleanQuery();
part2.add(lqp.getFieldQuery(field, split[0], AnalysisMode.IDENTIFIER, luceneFunction), Occur.MUST);
part2.add(lqp.getFieldQuery(AbstractLuceneQueryParser.FIELD_ASPECT, ContentModel.ASPECT_VERSIONABLE.toString(), AnalysisMode.IDENTIFIER, luceneFunction), Occur.MUST_NOT);
query.add(part2, Occur.SHOULD);
}
return query;
}
}
/*
@@ -151,7 +177,6 @@ public class ObjectIdProperty extends AbstractVersioningProperty
*/
public Query buildLuceneIn(AbstractLuceneQueryParser lqp, Collection<Serializable> values, Boolean not, PredicateMode mode) throws ParseException
{
String field = getLuceneFieldName();
// Check type conversion
@@ -175,11 +200,14 @@ public class ObjectIdProperty extends AbstractVersioningProperty
String value = asStrings.iterator().next();
if (not)
{
return lqp.getDoesNotMatchFieldQuery(field, value, AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(new MatchAllDocsQuery(), Occur.MUST);
booleanQuery.add(buildLuceneEquality(lqp, value, mode, LuceneFunction.FIELD), Occur.MUST_NOT);
return booleanQuery;
}
else
{
return lqp.getFieldQuery(field, value, AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
return buildLuceneEquality(lqp, value, mode, LuceneFunction.FIELD);
}
}
else
@@ -191,7 +219,7 @@ public class ObjectIdProperty extends AbstractVersioningProperty
}
for (String value : asStrings)
{
Query any = lqp.getFieldQuery(field, value, AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
Query any = buildLuceneEquality(lqp, value, mode, LuceneFunction.FIELD);
if (not)
{
booleanQuery.add(any, Occur.MUST_NOT);
@@ -211,9 +239,10 @@ public class ObjectIdProperty extends AbstractVersioningProperty
*/
public Query buildLuceneInequality(AbstractLuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
String field = getLuceneFieldName();
String stringValue = getValueAsString(value);
return lqp.getDoesNotMatchFieldQuery(field, stringValue, AnalysisMode.IDENTIFIER, luceneFunction);
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(new MatchAllDocsQuery(), Occur.MUST);
booleanQuery.add(buildLuceneEquality(lqp, value, mode, LuceneFunction.FIELD), Occur.MUST_NOT);
return booleanQuery;
}
/*
@@ -242,20 +271,7 @@ public class ObjectIdProperty extends AbstractVersioningProperty
*/
public Query buildLuceneLike(AbstractLuceneQueryParser lqp, 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, AnalysisMode.IDENTIFIER), Occur.MUST_NOT);
return booleanQuery;
}
else
{
return lqp.getLikeQuery(field, stringValue, AnalysisMode.IDENTIFIER);
}
throw new CMISQueryException("Property " + getName() + " can not be used in a 'like' comparison");
}
/* (non-Javadoc)