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

View File

@@ -108,7 +108,33 @@ public class ObjectIdProperty extends AbstractVersioningProperty
{ {
String field = getLuceneFieldName(); String field = getLuceneFieldName();
String stringValue = getValueAsString(value); 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 public Query buildLuceneIn(AbstractLuceneQueryParser lqp, Collection<Serializable> values, Boolean not, PredicateMode mode) throws ParseException
{ {
String field = getLuceneFieldName();
// Check type conversion // Check type conversion
@@ -175,11 +200,14 @@ public class ObjectIdProperty extends AbstractVersioningProperty
String value = asStrings.iterator().next(); String value = asStrings.iterator().next();
if (not) 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 else
{ {
return lqp.getFieldQuery(field, value, AnalysisMode.IDENTIFIER, LuceneFunction.FIELD); return buildLuceneEquality(lqp, value, mode, LuceneFunction.FIELD);
} }
} }
else else
@@ -191,7 +219,7 @@ public class ObjectIdProperty extends AbstractVersioningProperty
} }
for (String value : asStrings) for (String value : asStrings)
{ {
Query any = lqp.getFieldQuery(field, value, AnalysisMode.IDENTIFIER, LuceneFunction.FIELD); Query any = buildLuceneEquality(lqp, value, mode, LuceneFunction.FIELD);
if (not) if (not)
{ {
booleanQuery.add(any, Occur.MUST_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 public Query buildLuceneInequality(AbstractLuceneQueryParser lqp, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{ {
String field = getLuceneFieldName(); BooleanQuery booleanQuery = new BooleanQuery();
String stringValue = getValueAsString(value); booleanQuery.add(new MatchAllDocsQuery(), Occur.MUST);
return lqp.getDoesNotMatchFieldQuery(field, stringValue, AnalysisMode.IDENTIFIER, luceneFunction); 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 public Query buildLuceneLike(AbstractLuceneQueryParser lqp, Serializable value, Boolean not) throws ParseException
{ {
String field = getLuceneFieldName(); throw new CMISQueryException("Property " + getName() + " can not be used in a 'like' comparison");
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);
}
} }
/* (non-Javadoc) /* (non-Javadoc)

View File

@@ -501,6 +501,7 @@ public class QueryTest extends BaseCMISTest
T returnValue = null; T returnValue = null;
CMISQueryOptions options = new CMISQueryOptions(query, rootNodeRef.getStoreRef()); CMISQueryOptions options = new CMISQueryOptions(query, rootNodeRef.getStoreRef());
options.setQueryMode(mode); options.setQueryMode(mode);
options.setIncludeInTransactionData(true);
rs = cmisQueryService.query(options); rs = cmisQueryService.query(options);
for (CMISResultSetRow row : rs) for (CMISResultSetRow row : rs)
@@ -2737,6 +2738,65 @@ public class QueryTest extends BaseCMISTest
testQuery("SELECT cmis:objectId FROM cmis:folder WHERE ANY cmis:objectId IN ('" + companyHomeId + "')", 1, false, "cmis:objectId", new String(), true); testQuery("SELECT cmis:objectId FROM cmis:folder WHERE ANY cmis:objectId IN ('" + companyHomeId + "')", 1, false, "cmis:objectId", new String(), true);
testQuery("SELECT cmis:objectId FROM cmis:folder WHERE ANY cmis:objectId NOT IN ('" + companyHomeId + "')", 9, false, "cmis:objectId", new String(), true); testQuery("SELECT cmis:objectId FROM cmis:folder WHERE ANY cmis:objectId NOT IN ('" + companyHomeId + "')", 9, false, "cmis:objectId", new String(), true);
// Folder versions which are ignored ....
testQuery("SELECT cmis:objectId FROM cmis:folder WHERE cmis:objectId = '" + companyHomeId + ";1.0'", 1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:folder WHERE cmis:objectId <> '" + companyHomeId + ";1.0'", 9, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:folder WHERE cmis:objectId IN ('" + companyHomeId + ";1.0')", 1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:folder WHERE cmis:objectId NOT IN ('" + companyHomeId + ";1.0')", 9, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:folder WHERE cmis:objectId IS NOT NULL", 10, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:folder WHERE cmis:objectId IS NULL", 0, false, "cmis:objectId", new String(), false);
// Docs
String docId = testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:name = 'Alfresco Tutorial'", 1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId = '" + docId + "'", 1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId <> '" + docId + "'", doc_count-1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId IN ('" + docId + "')", 1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId NOT IN ('" + docId + "')", doc_count-1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId IS NOT NULL", doc_count, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId IS NULL", 0, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId = '" + docId + ";1.0'", 1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId <> '" + docId + ";1.0'", doc_count-1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId IN ('" + docId + ";1.0')", 1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId NOT IN ('" + docId + ";1.0')", doc_count-1, false, "cmis:objectId", new String(), false);
nodeService.setProperty(c0, ContentModel.PROP_VERSION_LABEL, "1.0");
docId = testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:name = 'Alfresco Tutorial'", 1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId = '" + docId + "'", 1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId <> '" + docId + "'", doc_count-1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId IN ('" + docId + "')", 1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId NOT IN ('" + docId + "')", doc_count-1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId IS NOT NULL", doc_count, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId IS NULL", 0, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId = '" + docId + ";1.0'", 1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId <> '" + docId + ";1.0'", doc_count-1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId IN ('" + docId + ";1.0')", 1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId NOT IN ('" + docId + ";1.0')", doc_count-1, false, "cmis:objectId", new String(), false);
nodeService.setProperty(c0, ContentModel.PROP_VERSION_LABEL, "2.1");
docId = testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:name = 'Alfresco Tutorial'", 1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId = '" + docId + "'", 1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId <> '" + docId + "'", doc_count-1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId IN ('" + docId + "')", 1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId NOT IN ('" + docId + "')", doc_count-1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId IS NOT NULL", doc_count, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId IS NULL", 0, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId = '" + docId + ";2.1'", 1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId <> '" + docId + ";2.1'", doc_count-1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId IN ('" + docId + ";2.1')", 1, false, "cmis:objectId", new String(), false);
testQuery("SELECT cmis:objectId FROM cmis:document WHERE cmis:objectId NOT IN ('" + docId + ";2.1')", doc_count-1, false, "cmis:objectId", new String(), false);
} }
public void testOrderBy() throws Exception public void testOrderBy() throws Exception