CMIS Dictionary Refactor

- follows pattern of Alfresco Dictionary
- simplified and much reduced DictionaryService interface
- model now compiled and cached (no more lots of small continuous object creations)
- walk model via simple getters
- validated (no dangling references)
- fix up property inheritance
- fix up sub-types for all types
- implements strict mode only for now (i.e. doesn't go outside of CMIS doc, folder, rel and policy)
- abstract helper for building other CMIS dictionaries (e.g. mapping all types in Alfresco)

Alfresco Dictionary:
- add event for initialized or re-initialized

Fix up usage in CMIS REST, Web Services and query. Tests pass.

REST support for custom sub-types and properties now reliable as constrained by validated CMIS model.

TODO:
- hook property value accessors into CMIS Dictionary

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13768 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2009-03-27 23:13:29 +00:00
parent df3e143e1c
commit 8fcebdc7cf
51 changed files with 2937 additions and 2095 deletions

View File

@@ -24,7 +24,7 @@
*/
package org.alfresco.cmis.search;
import org.alfresco.cmis.CMISPropertyTypeEnum;
import org.alfresco.cmis.CMISDataTypeEnum;
import org.alfresco.cmis.dictionary.CMISPropertyDefinition;
/**
@@ -51,5 +51,5 @@ public interface CMISResultSetColumn
* The type of the column
* @return - the CMIS type for the column
*/
public CMISPropertyTypeEnum getPropertyType();
public CMISDataTypeEnum getPropertyType();
}

View File

@@ -24,7 +24,7 @@
*/
package org.alfresco.cmis.search;
import org.alfresco.cmis.CMISPropertyTypeEnum;
import org.alfresco.cmis.CMISDataTypeEnum;
import org.alfresco.cmis.dictionary.CMISPropertyDefinition;
/**
@@ -38,9 +38,9 @@ public class CMISResultSetColumnImpl implements CMISResultSetColumn
private CMISPropertyDefinition propertyDefinition;
private CMISPropertyTypeEnum propertyType;
private CMISDataTypeEnum propertyType;
CMISResultSetColumnImpl(String name, CMISPropertyDefinition propertyDefinition, CMISPropertyTypeEnum propertyType)
CMISResultSetColumnImpl(String name, CMISPropertyDefinition propertyDefinition, CMISDataTypeEnum propertyType)
{
this.name = name;
this.propertyDefinition = propertyDefinition;
@@ -67,7 +67,7 @@ public class CMISResultSetColumnImpl implements CMISResultSetColumn
/* (non-Javadoc)
* @see org.alfresco.cmis.search.CMISResultSetColumn#getPropertyType()
*/
public CMISPropertyTypeEnum getPropertyType()
public CMISDataTypeEnum getPropertyType()
{
return propertyType;
}

View File

@@ -28,10 +28,12 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.cmis.CMISPropertyTypeEnum;
import org.alfresco.cmis.CMISDataTypeEnum;
import org.alfresco.cmis.dictionary.CMISDictionaryService;
import org.alfresco.cmis.dictionary.CMISPropertyDefinition;
import org.alfresco.cmis.dictionary.CMISPropertyId;
import org.alfresco.cmis.dictionary.CMISTypeDefinition;
import org.alfresco.cmis.dictionary.CMISTypeId;
import org.alfresco.repo.search.impl.querymodel.Column;
import org.alfresco.repo.search.impl.querymodel.PropertyArgument;
import org.alfresco.repo.search.impl.querymodel.Query;
@@ -63,7 +65,8 @@ public class CMISResultSetMetaDataImpl implements CMISResultSetMetaData
selectorMetaData = new LinkedHashMap<String, CMISResultSetSelector>();
for(Selector selector : selectors.values())
{
CMISTypeDefinition type = new CMISTypeDefinition(cmisDictionaryService, cmisDictionaryService.getCMISMapping().getCmisTypeId(selector.getType()));
CMISTypeId typeId = cmisDictionaryService.getTypeId(selector.getType(), null);
CMISTypeDefinition type = cmisDictionaryService.getType(typeId);
CMISResultSetSelector smd = new CMISResultSetSelectorImpl(selector.getAlias(), type);
selectorMetaData.put(smd.getName(), smd);
}
@@ -75,18 +78,18 @@ public class CMISResultSetMetaDataImpl implements CMISResultSetMetaData
for (Column column : query.getColumns())
{
CMISPropertyDefinition propertyDefinition = null;
CMISPropertyTypeEnum type = null;
CMISDataTypeEnum type = null;
if (column.getFunction().getName().equals(PropertyAccessor.NAME))
{
PropertyArgument arg = (PropertyArgument) column.getFunctionArguments().get(PropertyAccessor.ARG_PROPERTY);
QName propertyQName = arg.getPropertyName();
QName typeQname = selectors.get(arg.getSelector()).getType();
propertyDefinition = new CMISPropertyDefinition(cmisDictionaryService, propertyQName, typeQname);
type = propertyDefinition.getPropertyType();
CMISPropertyId propertyId = cmisDictionaryService.getPropertyId(propertyQName);
propertyDefinition = cmisDictionaryService.getProperty(propertyId);
type = propertyDefinition.getDataType();
}
if (type == null)
{
type = cmisDictionaryService.getCMISMapping().getPropertyType(column.getFunction().getReturnType());
type = cmisDictionaryService.getDataType(column.getFunction().getReturnType());
}
CMISResultSetColumn cmd = new CMISResultSetColumnImpl(column.getAlias(), propertyDefinition, type);
columnMetaData.put(cmd.getName(), cmd);

View File

@@ -29,6 +29,7 @@ import java.util.Collection;
import java.util.Map;
import org.alfresco.cmis.dictionary.CMISDictionaryService;
import org.alfresco.cmis.dictionary.CMISPropertyId;
import org.alfresco.cmis.property.CMISPropertyService;
import org.alfresco.cmis.property.CMISPropertyServiceImpl;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
@@ -130,8 +131,8 @@ public class CmisFunctionEvaluationContext implements FunctionEvaluationContext
*/
public Serializable getProperty(NodeRef nodeRef, QName propertyQName)
{
String propertyName = cmisDictionaryService.getCMISMapping().getCmisPropertyName(propertyQName);
return cmisPropertyService.getProperty(nodeRef, propertyName);
CMISPropertyId propertyId = cmisDictionaryService.getPropertyId(propertyQName);
return cmisPropertyService.getProperty(nodeRef, propertyId.getName());
}
/*
@@ -165,9 +166,9 @@ public class CmisFunctionEvaluationContext implements FunctionEvaluationContext
{
if (cmisPropertyService instanceof CMISPropertyServiceImpl)
{
String propertyName = cmisDictionaryService.getCMISMapping().getCmisPropertyName(propertyQName);
CMISPropertyId propertyId = cmisDictionaryService.getPropertyId(propertyQName);
CMISPropertyServiceImpl impl = (CMISPropertyServiceImpl) cmisPropertyService;
return impl.buildLuceneEquality(lqp, propertyName, value, mode);
return impl.buildLuceneEquality(lqp, propertyId.getName(), value, mode);
}
else
{
@@ -185,9 +186,9 @@ public class CmisFunctionEvaluationContext implements FunctionEvaluationContext
{
if (cmisPropertyService instanceof CMISPropertyServiceImpl)
{
String propertyName = cmisDictionaryService.getCMISMapping().getCmisPropertyName(propertyQName);
CMISPropertyId propertyId = cmisDictionaryService.getPropertyId(propertyQName);
CMISPropertyServiceImpl impl = (CMISPropertyServiceImpl) cmisPropertyService;
return impl.buildLuceneExists(lqp, propertyName, not);
return impl.buildLuceneExists(lqp, propertyId.getName(), not);
}
else
{
@@ -206,9 +207,9 @@ public class CmisFunctionEvaluationContext implements FunctionEvaluationContext
{
if (cmisPropertyService instanceof CMISPropertyServiceImpl)
{
String propertyName = cmisDictionaryService.getCMISMapping().getCmisPropertyName(propertyQName);
CMISPropertyId propertyId = cmisDictionaryService.getPropertyId(propertyQName);
CMISPropertyServiceImpl impl = (CMISPropertyServiceImpl) cmisPropertyService;
return impl.buildLuceneGreaterThan(lqp, propertyName, value, mode);
return impl.buildLuceneGreaterThan(lqp, propertyId.getName(), value, mode);
}
else
{
@@ -227,9 +228,9 @@ public class CmisFunctionEvaluationContext implements FunctionEvaluationContext
{
if (cmisPropertyService instanceof CMISPropertyServiceImpl)
{
String propertyName = cmisDictionaryService.getCMISMapping().getCmisPropertyName(propertyQName);
CMISPropertyId propertyId = cmisDictionaryService.getPropertyId(propertyQName);
CMISPropertyServiceImpl impl = (CMISPropertyServiceImpl) cmisPropertyService;
return impl.buildLuceneGreaterThanOrEquals(lqp, propertyName, value, mode);
return impl.buildLuceneGreaterThanOrEquals(lqp, propertyId.getName(), value, mode);
}
else
{
@@ -248,9 +249,9 @@ public class CmisFunctionEvaluationContext implements FunctionEvaluationContext
{
if (cmisPropertyService instanceof CMISPropertyServiceImpl)
{
String propertyName = cmisDictionaryService.getCMISMapping().getCmisPropertyName(propertyQName);
CMISPropertyId propertyId = cmisDictionaryService.getPropertyId(propertyQName);
CMISPropertyServiceImpl impl = (CMISPropertyServiceImpl) cmisPropertyService;
return impl.buildLuceneIn(lqp, propertyName, values, not, mode);
return impl.buildLuceneIn(lqp, propertyId.getName(), values, not, mode);
}
else
{
@@ -269,9 +270,9 @@ public class CmisFunctionEvaluationContext implements FunctionEvaluationContext
{
if (cmisPropertyService instanceof CMISPropertyServiceImpl)
{
String propertyName = cmisDictionaryService.getCMISMapping().getCmisPropertyName(propertyQName);
CMISPropertyId propertyId = cmisDictionaryService.getPropertyId(propertyQName);
CMISPropertyServiceImpl impl = (CMISPropertyServiceImpl) cmisPropertyService;
return impl.buildLuceneInequality(lqp, propertyName, value, mode);
return impl.buildLuceneInequality(lqp, propertyId.getName(), value, mode);
}
else
{
@@ -290,9 +291,9 @@ public class CmisFunctionEvaluationContext implements FunctionEvaluationContext
{
if (cmisPropertyService instanceof CMISPropertyServiceImpl)
{
String propertyName = cmisDictionaryService.getCMISMapping().getCmisPropertyName(propertyQName);
CMISPropertyId propertyId = cmisDictionaryService.getPropertyId(propertyQName);
CMISPropertyServiceImpl impl = (CMISPropertyServiceImpl) cmisPropertyService;
return impl.buildLuceneLessThan(lqp, propertyName, value, mode);
return impl.buildLuceneLessThan(lqp, propertyId.getName(), value, mode);
}
else
{
@@ -311,9 +312,9 @@ public class CmisFunctionEvaluationContext implements FunctionEvaluationContext
{
if (cmisPropertyService instanceof CMISPropertyServiceImpl)
{
String propertyName = cmisDictionaryService.getCMISMapping().getCmisPropertyName(propertyQName);
CMISPropertyId propertyId = cmisDictionaryService.getPropertyId(propertyQName);
CMISPropertyServiceImpl impl = (CMISPropertyServiceImpl) cmisPropertyService;
return impl.buildLuceneLessThanOrEquals(lqp, propertyName, value, mode);
return impl.buildLuceneLessThanOrEquals(lqp, propertyId.getName(), value, mode);
}
else
{
@@ -331,9 +332,9 @@ public class CmisFunctionEvaluationContext implements FunctionEvaluationContext
{
if (cmisPropertyService instanceof CMISPropertyServiceImpl)
{
String propertyName = cmisDictionaryService.getCMISMapping().getCmisPropertyName(propertyQName);
CMISPropertyId propertyId = cmisDictionaryService.getPropertyId(propertyQName);
CMISPropertyServiceImpl impl = (CMISPropertyServiceImpl) cmisPropertyService;
return impl.buildLuceneLike(lqp, propertyName, value, not);
return impl.buildLuceneLike(lqp, propertyId.getName(), value, not);
}
else
{
@@ -348,9 +349,9 @@ public class CmisFunctionEvaluationContext implements FunctionEvaluationContext
{
if (cmisPropertyService instanceof CMISPropertyServiceImpl)
{
String propertyName = cmisDictionaryService.getCMISMapping().getCmisPropertyName(propertyQName);
CMISPropertyId propertyId = cmisDictionaryService.getPropertyId(propertyQName);
CMISPropertyServiceImpl impl = (CMISPropertyServiceImpl) cmisPropertyService;
return impl.getLuceneSortField(propertyName);
return impl.getLuceneSortField(propertyId.getName());
}
else
{

View File

@@ -35,7 +35,8 @@ import java.util.Locale;
import java.util.Map;
import org.alfresco.cmis.dictionary.BaseCMISTest;
import org.alfresco.cmis.dictionary.CMISMapping;
import org.alfresco.cmis.dictionary.CMISDictionaryModel;
import org.alfresco.cmis.dictionary.CMISTypeDefinition;
import org.alfresco.cmis.search.CMISQueryOptions.CMISQueryMode;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.search.impl.parsers.CMISLexer;
@@ -916,31 +917,31 @@ public class QueryTest extends BaseCMISTest
public void test_CHANGE_TOKEN()
{
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken = 'test'", 0, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken <> 'test'", 10, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken < 'test'", 0, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken <= 'test'", 0, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken > 'test'", 0, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken >= 'test'", 0, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken = 'test'", 0, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken <> 'test'", 10, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken < 'test'", 0, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken <= 'test'", 0, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken > 'test'", 0, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken >= 'test'", 0, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken IN ('test')", 0, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken NOT IN ('test')", 10, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken IN ('test')", 0, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken NOT IN ('test')", 10, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken LIKE 'test'", 0, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken NOT LIKE 'test'", 0, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken LIKE 'test'", 0, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken NOT LIKE 'test'", 0, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken IS NOT NULL", 0, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken IS NULL", 10, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken IS NOT NULL", 0, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE ChangeToken IS NULL", 10, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE 'test' = ANY ChangeToken", 0, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE 'test' <> ANY ChangeToken", 10, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE 'test' < ANY ChangeToken", 0, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE 'test' <= ANY ChangeToken", 0, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE 'test' > ANY ChangeToken", 0, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE 'test' >= ANY ChangeToken", 0, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE 'test' = ANY ChangeToken", 0, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE 'test' <> ANY ChangeToken", 10, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE 'test' < ANY ChangeToken", 0, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE 'test' <= ANY ChangeToken", 0, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE 'test' > ANY ChangeToken", 0, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE 'test' >= ANY ChangeToken", 0, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE ANY ChangeToken IN ('test')", 0, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE ANY ChangeToken NOT IN ('test')", 10, false, "ObjectId", new String(), false);
testQuery("SELECT ChangeToken FROM Folder WHERE ANY ChangeToken IN ('test')", 0, false, "ObjectId", new String(), true);
testQuery("SELECT ChangeToken FROM Folder WHERE ANY ChangeToken NOT IN ('test')", 10, false, "ObjectId", new String(), true);
}
public void test_LAST_MODIFICATION_DATE()
@@ -1314,38 +1315,38 @@ public class QueryTest extends BaseCMISTest
public void test_URI()
{
testQuery("SELECT Uri FROM Folder WHERE Uri = 'test'", 0, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE Uri <> 'test'", 10, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE Uri < 'test'", 0, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE Uri <= 'test'", 0, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE Uri > 'test'", 0, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE Uri >= 'test'", 0, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE Uri = 'test'", 0, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE Uri <> 'test'", 10, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE Uri < 'test'", 0, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE Uri <= 'test'", 0, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE Uri > 'test'", 0, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE Uri >= 'test'", 0, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE Uri IN ('test')", 0, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE Uri NOT IN ('test')", 10, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE Uri IN ('test')", 0, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE Uri NOT IN ('test')", 10, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE Uri LIKE 'test'", 0, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE Uri NOT LIKE 'test'", 0, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE Uri LIKE 'test'", 0, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE Uri NOT LIKE 'test'", 0, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE Uri IS NOT NULL", 0, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE Uri IS NULL", 10, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE Uri IS NOT NULL", 0, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE Uri IS NULL", 10, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE 'test' = ANY Uri", 0, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE 'test' <> ANY Uri", 10, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE 'test' < ANY Uri", 0, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE 'test' <= ANY Uri", 0, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE 'test' > ANY Uri", 0, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE 'test' >= ANY Uri", 0, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE 'test' = ANY Uri", 0, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE 'test' <> ANY Uri", 10, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE 'test' < ANY Uri", 0, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE 'test' <= ANY Uri", 0, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE 'test' > ANY Uri", 0, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE 'test' >= ANY Uri", 0, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE ANY Uri IN ('test')", 0, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE ANY Uri NOT IN ('test')", 10, false, "ObjectId", new String(), false);
testQuery("SELECT Uri FROM Folder WHERE ANY Uri IN ('test')", 0, false, "ObjectId", new String(), true);
testQuery("SELECT Uri FROM Folder WHERE ANY Uri NOT IN ('test')", 10, false, "ObjectId", new String(), true);
}
public void test_ObjectId()
{
String companyHomeId = testQuery("SELECT ObjectId FROM Folder WHERE Name = '\"Folder 0\"'", 1, false, "ObjectId", new String(), false);
Serializable ser = cmisPropertyService.getProperty(f0, CMISMapping.PROP_OBJECT_ID);
Serializable ser = cmisPropertyService.getProperty(f0, CMISDictionaryModel.PROP_OBJECT_ID);
String id = DefaultTypeConverter.INSTANCE.convert(String.class, ser);
assertEquals(companyHomeId, id);
@@ -1473,8 +1474,8 @@ public class QueryTest extends BaseCMISTest
{
testQuery("SELECT * FROM Folder WHERE Name IS NOT NULL", 10, false, "ObjectId", new String(), false);
testQuery("SELECT * FROM Folder WHERE Name IS NULL", 0, false, "ObjectId", new String(), false);
testQuery("SELECT * FROM Document WHERE Uri IS NOT NULL", 0, false, "ObjectId", new String(), false);
testQuery("SELECT * FROM Document WHERE Uri IS NULL", 10, false, "ObjectId", new String(), false);
testQuery("SELECT * FROM Document WHERE Name IS NOT NULL", 10, false, "ObjectId", new String(), false);
testQuery("SELECT * FROM Document WHERE Name IS NULL", 0, false, "ObjectId", new String(), false);
}
public void testObjectEquals()
@@ -1489,7 +1490,7 @@ public class QueryTest extends BaseCMISTest
public void testFolderEquals()
{
Serializable ser = cmisPropertyService.getProperty(f0, CMISMapping.PROP_NAME);
Serializable ser = cmisPropertyService.getProperty(f0, CMISDictionaryModel.PROP_NAME);
String Name = DefaultTypeConverter.INSTANCE.convert(String.class, ser);
testQuery("SELECT * FROM Folder WHERE Name = '" + Name + "'", 1, false, "ObjectId", new String(), false);
@@ -1500,7 +1501,7 @@ public class QueryTest extends BaseCMISTest
public void test_IN_TREE()
{
Serializable ser = cmisPropertyService.getProperty(f0, CMISMapping.PROP_OBJECT_ID);
Serializable ser = cmisPropertyService.getProperty(f0, CMISDictionaryModel.PROP_OBJECT_ID);
String id = DefaultTypeConverter.INSTANCE.convert(String.class, ser);
testQuery("SELECT * FROM Folder WHERE IN_TREE('" + id + "')", 6, false, "ObjectId", new String(), false);
@@ -1508,7 +1509,7 @@ public class QueryTest extends BaseCMISTest
public void test_IN_FOLDER()
{
Serializable ser = cmisPropertyService.getProperty(f0, CMISMapping.PROP_OBJECT_ID);
Serializable ser = cmisPropertyService.getProperty(f0, CMISDictionaryModel.PROP_OBJECT_ID);
String id = DefaultTypeConverter.INSTANCE.convert(String.class, ser);
testQuery("SELECT * FROM Folder WHERE IN_FOLDER('" + id + "')", 2, false, "ObjectId", new String(), false);
@@ -1538,8 +1539,9 @@ public class QueryTest extends BaseCMISTest
CMISResultSet rs = cmisQueryService.query(options);
CMISResultSetMetaData md = rs.getMetaData();
assertNotNull(md.getQueryOptions());
assertEquals(cmisDictionaryService.getPropertyDefinitions(CMISMapping.DOCUMENT_TYPE_ID).size(), md.getColumnNames().length);
assertNotNull(md.getColumn(CMISMapping.PROP_OBJECT_ID));
CMISTypeDefinition typeDef = cmisDictionaryService.getType(CMISDictionaryModel.DOCUMENT_TYPE_ID);
assertEquals(typeDef.getPropertyDefinitions().size(), md.getColumnNames().length);
assertNotNull(md.getColumn(CMISDictionaryModel.PROP_OBJECT_ID));
assertEquals(1, md.getSelectors().length);
assertNotNull(md.getSelector(""));
rs.close();

View File

@@ -35,14 +35,13 @@ import java.util.StringTokenizer;
import org.alfresco.cmis.CMISCardinalityEnum;
import org.alfresco.cmis.CMISJoinEnum;
import org.alfresco.cmis.dictionary.CMISDictionaryService;
import org.alfresco.cmis.dictionary.CMISMapping;
import org.alfresco.cmis.dictionary.CMISPropertyDefinition;
import org.alfresco.cmis.dictionary.CMISPropertyId;
import org.alfresco.cmis.dictionary.CMISScope;
import org.alfresco.cmis.dictionary.CMISTypeDefinition;
import org.alfresco.cmis.dictionary.CMISTypeId;
import org.alfresco.cmis.search.CMISQueryException;
import org.alfresco.cmis.search.CMISQueryOptions;
import org.alfresco.cmis.search.CMISQueryOptions.CMISQueryMode;
import org.alfresco.repo.search.impl.parsers.CMISLexer;
import org.alfresco.repo.search.impl.parsers.CMISParser;
import org.alfresco.repo.search.impl.parsers.FTSLexer;
@@ -101,15 +100,12 @@ public class CMISQueryParser
private CMISDictionaryService cmisDictionaryService;
private CMISMapping cmisMapping;
private CMISJoinEnum joinSupport;
public CMISQueryParser(CMISQueryOptions options, CMISDictionaryService cmisDictionaryService, CMISMapping cmisMapping, CMISJoinEnum joinSupport)
public CMISQueryParser(CMISQueryOptions options, CMISDictionaryService cmisDictionaryService, CMISJoinEnum joinSupport)
{
this.options = options;
this.cmisDictionaryService = cmisDictionaryService;
this.cmisMapping = cmisMapping;
this.joinSupport = joinSupport;
}
@@ -600,35 +596,32 @@ public class CMISQueryParser
{
throw new CMISQueryException("No selector for " + qualifier);
}
QName cmisType = cmisMapping.getCmisType(selector.getType());
CMISTypeId typeId = null;
if (cmisMapping.isValidCmisDocument(cmisType))
{
typeId = cmisMapping.getCmisTypeId(CMISScope.DOCUMENT, cmisType);
}
else if (cmisMapping.isValidCmisFolder(cmisType))
{
typeId = cmisMapping.getCmisTypeId(CMISScope.FOLDER, cmisType);
}
else
CMISTypeId typeId = cmisDictionaryService.getTypeId(selector.getType(), null);
if (typeId == null || (typeId.getScope() != CMISScope.DOCUMENT && typeId.getScope() != CMISScope.FOLDER))
{
throw new CMISQueryException("Type unsupported in CMIS queries: " + selector.getAlias());
}
CMISPropertyDefinition definition = cmisDictionaryService.getPropertyDefinition(typeId, columnName);
if (definition == null)
CMISTypeDefinition typeDef = cmisDictionaryService.getType(typeId);
CMISPropertyDefinition propDef = null;
CMISPropertyId propId = cmisDictionaryService.getPropertyId(columnName);
if (propId != null)
{
throw new CMISQueryException("Invalid column for " + cmisMapping.getQueryName(typeId.getQName()) + "." + columnName);
propDef = typeDef.getPropertyDefinitions().get(propId);
}
if (propDef == null)
{
throw new CMISQueryException("Invalid column for " + typeDef.getQueryName() + "." + columnName);
}
Function function = factory.getFunction(PropertyAccessor.NAME);
QName propertyQName = cmisMapping.getPropertyQName(definition.getPropertyName());
Argument arg = factory.createPropertyArgument(PropertyAccessor.ARG_PROPERTY, definition.isQueryable(), definition.isOrderable(), selector.getAlias(),
propertyQName);
Argument arg = factory.createPropertyArgument(PropertyAccessor.ARG_PROPERTY, propDef.isQueryable(), propDef.isOrderable(), selector.getAlias(),
propDef.getPropertyId().getQName());
Map<String, Argument> functionArguments = new LinkedHashMap<String, Argument>();
functionArguments.put(arg.getName(), arg);
String alias = (selector.getAlias().length() > 0) ? selector.getAlias() + "." + definition.getPropertyName() : definition.getPropertyName();
String alias = (selector.getAlias().length() > 0) ? selector.getAlias() + "." + propDef.getPropertyId().getName() : propDef.getPropertyId().getName();
match = factory.createColumn(function, functionArguments, alias);
}
@@ -642,36 +635,32 @@ public class CMISQueryParser
{
throw new CMISQueryException("No selector for " + qualifier);
}
QName cmisType = cmisMapping.getCmisType(selector.getType());
CMISTypeId typeId = null;
if (cmisMapping.isValidCmisDocument(cmisType))
{
typeId = cmisMapping.getCmisTypeId(CMISScope.DOCUMENT, cmisType);
}
else if (cmisMapping.isValidCmisFolder(cmisType))
{
typeId = cmisMapping.getCmisTypeId(CMISScope.FOLDER, cmisType);
}
else
CMISTypeId typeId = cmisDictionaryService.getTypeId(selector.getType(), null);
if (typeId == null || (typeId.getScope() != CMISScope.DOCUMENT && typeId.getScope() != CMISScope.FOLDER))
{
throw new CMISQueryException("Type unsupported in CMIS queries: " + selector.getAlias());
}
CMISPropertyDefinition definition = cmisDictionaryService.getPropertyDefinition(typeId, columnName);
if (definition == null)
CMISTypeDefinition typeDef = cmisDictionaryService.getType(typeId);
CMISPropertyDefinition propDef = null;
CMISPropertyId propId = cmisDictionaryService.getPropertyId(columnName);
if (propId != null)
{
throw new CMISQueryException("Invalid column for "
+ cmisMapping.getQueryName(typeId.getQName()) + "." + columnName + " selector alias " + selector.getAlias());
propDef = typeDef.getPropertyDefinitions().get(propId);
}
if (propDef == null)
{
throw new CMISQueryException("Invalid column for " + typeDef.getQueryName() + "." + columnName + " selector alias " + selector.getAlias());
}
Function function = factory.getFunction(PropertyAccessor.NAME);
QName propertyQName = cmisMapping.getPropertyQName(definition.getPropertyName());
Argument arg = factory.createPropertyArgument(PropertyAccessor.ARG_PROPERTY, definition.isQueryable(), definition.isOrderable(), selector.getAlias(),
propertyQName);
Argument arg = factory.createPropertyArgument(PropertyAccessor.ARG_PROPERTY, propDef.isQueryable(), propDef.isOrderable(), selector.getAlias(),
propDef.getPropertyId().getQName());
Map<String, Argument> functionArguments = new LinkedHashMap<String, Argument>();
functionArguments.put(arg.getName(), arg);
String alias = (selector.getAlias().length() > 0) ? selector.getAlias() + "." + definition.getPropertyName() : definition.getPropertyName();
String alias = (selector.getAlias().length() > 0) ? selector.getAlias() + "." + propDef.getPropertyId().getName() : propDef.getPropertyId().getName();
orderColumn = factory.createColumn(function, functionArguments, alias);
}
@@ -699,39 +688,23 @@ public class CMISQueryParser
{
for (Selector selector : selectors.values())
{
QName cmisType = cmisMapping.getCmisType(selector.getType());
CMISTypeId typeId = null;
if (cmisMapping.isValidCmisDocument(cmisType))
CMISTypeId typeId = cmisDictionaryService.getTypeId(selector.getType(), null);
if (typeId == null || (typeId.getScope() == CMISScope.RELATIONSHIP))
{
typeId = cmisMapping.getCmisTypeId(CMISScope.DOCUMENT, cmisType);
throw new CMISQueryException("Type unsupported in CMIS queries: " + selector.getAlias());
}
else if (cmisMapping.isValidCmisFolder(cmisType))
{
typeId = cmisMapping.getCmisTypeId(CMISScope.FOLDER, cmisType);
}
else
{
if (options.getQueryMode() == CMISQueryMode.CMS_STRICT)
{
throw new CMISQueryException("Type unsupported in CMIS queries: " + selector.getAlias());
}
else
{
typeId = cmisMapping.getCmisTypeId(CMISScope.POLICY, cmisType);
}
}
Map<String, CMISPropertyDefinition> propDefs = cmisDictionaryService.getPropertyDefinitions(typeId);
CMISTypeDefinition typeDef = cmisDictionaryService.getType(typeId);
Map<CMISPropertyId, CMISPropertyDefinition> propDefs = typeDef.getPropertyDefinitions();
for (CMISPropertyDefinition definition : propDefs.values())
{
if (definition.getCardinality() == CMISCardinalityEnum.SINGLE_VALUED)
{
Function function = factory.getFunction(PropertyAccessor.NAME);
QName propertyQName = cmisMapping.getPropertyQName(definition.getPropertyName());
Argument arg = factory.createPropertyArgument(PropertyAccessor.ARG_PROPERTY, definition.isQueryable(), definition.isOrderable(), selector.getAlias(),
propertyQName);
definition.getPropertyId().getQName());
Map<String, Argument> functionArguments = new LinkedHashMap<String, Argument>();
functionArguments.put(arg.getName(), arg);
String alias = (selector.getAlias().length() > 0) ? selector.getAlias() + "." + definition.getPropertyName() : definition.getPropertyName();
String alias = (selector.getAlias().length() > 0) ? selector.getAlias() + "." + definition.getPropertyId().getName() : definition.getPropertyId().getName();
Column column = factory.createColumn(function, functionArguments, alias);
columns.add(column);
}
@@ -752,40 +725,24 @@ public class CMISQueryParser
{
throw new CMISQueryException("No selector for " + qualifier + " in " + qualifier + ".*");
}
QName cmisType = cmisMapping.getCmisType(selector.getType());
CMISTypeId typeId = null;
if (cmisMapping.isValidCmisDocument(cmisType))
CMISTypeId typeId = cmisDictionaryService.getTypeId(selector.getType(), null);
if (typeId == null || (typeId.getScope() == CMISScope.RELATIONSHIP))
{
typeId = cmisMapping.getCmisTypeId(CMISScope.DOCUMENT, cmisType);
throw new CMISQueryException("Type unsupported in CMIS queries: " + selector.getAlias());
}
else if (cmisMapping.isValidCmisFolder(cmisType))
{
typeId = cmisMapping.getCmisTypeId(CMISScope.FOLDER, cmisType);
}
else
{
if (options.getQueryMode() == CMISQueryMode.CMS_STRICT)
{
throw new CMISQueryException("Type unsupported in CMIS queries: " + selector.getAlias());
}
else
{
typeId = cmisMapping.getCmisTypeId(CMISScope.POLICY, cmisType);
}
}
Map<String, CMISPropertyDefinition> propDefs = cmisDictionaryService.getPropertyDefinitions(typeId);
CMISTypeDefinition typeDef = cmisDictionaryService.getType(typeId);
Map<CMISPropertyId, CMISPropertyDefinition> propDefs = typeDef.getPropertyDefinitions();
for (CMISPropertyDefinition definition : propDefs.values())
{
if (definition.getCardinality() == CMISCardinalityEnum.SINGLE_VALUED)
{
Function function = factory.getFunction(PropertyAccessor.NAME);
QName propertyQName = cmisMapping.getPropertyQName(definition.getPropertyName());
Argument arg = factory.createPropertyArgument(PropertyAccessor.ARG_PROPERTY, definition.isQueryable(), definition.isOrderable(), selector.getAlias(),
propertyQName);
definition.getPropertyId().getQName());
Map<String, Argument> functionArguments = new LinkedHashMap<String, Argument>();
functionArguments.put(arg.getName(), arg);
String alias = (selector.getAlias().length() > 0) ? selector.getAlias() + "." + definition.getPropertyName() : definition.getPropertyName();
String alias = (selector.getAlias().length() > 0) ? selector.getAlias() + "." + definition.getPropertyId().getName() : definition.getPropertyId().getName();
Column column = factory.createColumn(function, functionArguments, alias);
columns.add(column);
}
@@ -808,43 +765,31 @@ public class CMISQueryParser
{
throw new CMISQueryException("No selector for " + qualifier);
}
QName cmisType = cmisMapping.getCmisType(selector.getType());
CMISTypeId typeId = null;
if (cmisMapping.isValidCmisDocument(cmisType))
CMISTypeId typeId = cmisDictionaryService.getTypeId(selector.getType(), null);
if (typeId == null || (typeId.getScope() == CMISScope.RELATIONSHIP))
{
typeId = cmisMapping.getCmisTypeId(CMISScope.DOCUMENT, cmisType);
throw new CMISQueryException("Type unsupported in CMIS queries: " + selector.getAlias());
}
else if (cmisMapping.isValidCmisFolder(cmisType))
CMISTypeDefinition typeDef = cmisDictionaryService.getType(typeId);
CMISPropertyDefinition propDef = null;
CMISPropertyId propId = cmisDictionaryService.getPropertyId(columnName);
if (propId != null)
{
typeId = cmisMapping.getCmisTypeId(CMISScope.FOLDER, cmisType);
propDef = typeDef.getPropertyDefinitions().get(propId);
}
else
if (propDef == null)
{
if (options.getQueryMode() == CMISQueryMode.CMS_STRICT)
{
throw new CMISQueryException("Type unsupported in CMIS queries: " + selector.getAlias());
}
else
{
typeId = cmisMapping.getCmisTypeId(CMISScope.POLICY, cmisType);
}
}
CMISPropertyDefinition definition = cmisDictionaryService.getPropertyDefinition(typeId, columnName);
if (definition == null)
{
throw new CMISQueryException("Invalid column for " + cmisMapping.getQueryName(typeId.getQName()) + "." + columnName);
throw new CMISQueryException("Invalid column for " + typeDef.getQueryName() + "." + columnName);
}
Function function = factory.getFunction(PropertyAccessor.NAME);
QName propertyQName = cmisMapping.getPropertyQName(definition.getPropertyName());
Argument arg = factory.createPropertyArgument(PropertyAccessor.ARG_PROPERTY, definition.isQueryable(), definition.isOrderable(), selector.getAlias(),
propertyQName);
Argument arg = factory.createPropertyArgument(PropertyAccessor.ARG_PROPERTY, propDef.isQueryable(), propDef.isOrderable(), selector.getAlias(),
propDef.getPropertyId().getQName());
Map<String, Argument> functionArguments = new LinkedHashMap<String, Argument>();
functionArguments.put(arg.getName(), arg);
String alias = (selector.getAlias().length() > 0) ? selector.getAlias() + "." + definition.getPropertyName() : definition.getPropertyName();
String alias = (selector.getAlias().length() > 0) ? selector.getAlias() + "." + propDef.getPropertyId().getName() : propDef.getPropertyId().getName();
if (columnNode.getChildCount() > 1)
{
alias = columnNode.getChild(1).getText();
@@ -963,13 +908,12 @@ public class CMISQueryParser
}
else
{
QName propertyQName = cmisMapping.getPropertyQName(id);
CMISTypeId typeId = cmisMapping.getCmisTypeForProperty(propertyQName);
CMISPropertyDefinition propDef = cmisDictionaryService.getPropertyDefinition(typeId, id);
PropertyArgument arg = factory.createPropertyArgument(definition.getName(), propDef.isQueryable(), propDef.isOrderable(), "", propertyQName);
CMISPropertyId propertyId = cmisDictionaryService.getPropertyId(id);
CMISPropertyDefinition propDef = cmisDictionaryService.getProperty(propertyId);
PropertyArgument arg = factory.createPropertyArgument(definition.getName(), propDef.isQueryable(), propDef.isOrderable(), "", propDef.getPropertyId().getQName());
if(!arg.isQueryable())
{
throw new CMISQueryException("Column refers to unqueryable property "+arg.getPropertyName());
throw new CMISQueryException("Column refers to unqueryable property " + arg.getPropertyName());
}
return arg;
}
@@ -1117,12 +1061,12 @@ public class CMISQueryParser
{
alias = singleTableNode.getChild(1).getText();
}
QName classQName = cmisMapping.getAlfrescoClassQNameFromCmisTableName(tableName);
if (classQName == null)
CMISTypeId typeId = cmisDictionaryService.getTypeIdFromTable(tableName);
if (typeId == null)
{
throw new CMISQueryException("Type is unsupported in query " + tableName);
}
CMISTypeId typeId = cmisMapping.getCmisTypeId(classQName);
if (typeId.getScope() != CMISScope.POLICY)
{
CMISTypeDefinition cmisType = cmisDictionaryService.getType(typeId);
@@ -1131,7 +1075,7 @@ public class CMISQueryParser
throw new CMISQueryException("Type is not queryable " + tableName + " -> " + cmisType);
}
}
return factory.createSelector(classQName, alias);
return factory.createSelector(typeId.getQName(), alias);
}
else
{
@@ -1150,12 +1094,11 @@ public class CMISQueryParser
{
alias = singleTableNode.getChild(1).getText();
}
QName classQName = cmisMapping.getAlfrescoClassQNameFromCmisTableName(tableName);
if (classQName == null)
CMISTypeId typeId = cmisDictionaryService.getTypeIdFromTable(tableName);
if (typeId == null)
{
throw new CMISQueryException("Type is unsupported in query " + tableName);
}
CMISTypeId typeId = cmisMapping.getCmisTypeId(classQName);
if (typeId.getScope() != CMISScope.POLICY)
{
CMISTypeDefinition cmisType = cmisDictionaryService.getType(typeId);
@@ -1164,7 +1107,7 @@ public class CMISQueryParser
throw new CMISQueryException("Type is not queryable " + tableName + " -> " + cmisType);
}
}
Source lhs = factory.createSelector(classQName, alias);
Source lhs = factory.createSelector(typeId.getQName(), alias);
List<CommonTree> list = (List<CommonTree>) (source.getChildren());
for (CommonTree joinNode : list)
@@ -1226,18 +1169,9 @@ public class CMISQueryParser
{
qualifer = columnReferenceNode.getChild(1).getText();
}
QName propertyQName = cmisMapping.getPropertyQName(cmisPropertyName);
CMISTypeId typeId = cmisMapping.getCmisTypeForProperty(propertyQName);
CMISPropertyDefinition propDef = cmisDictionaryService.getPropertyDefinition(typeId, cmisPropertyName);
if (typeId.getScope() == CMISScope.POLICY)
{
// TODO: Policy - fix to be correct ....when we have properties
return factory.createPropertyArgument(argumentName, true, true, qualifer, propertyQName);
}
else
{
return factory.createPropertyArgument(argumentName, propDef.isQueryable(), propDef.isOrderable(), qualifer, propertyQName);
}
CMISPropertyId propId = cmisDictionaryService.getPropertyId(cmisPropertyName);
CMISPropertyDefinition propDef = cmisDictionaryService.getProperty(propId);
return factory.createPropertyArgument(argumentName, propDef.isQueryable(), propDef.isOrderable(), qualifer, propDef.getPropertyId().getQName());
}
public String getFunctionName(CommonTree functionNameNode)

View File

@@ -57,8 +57,6 @@ public class CMISQueryServiceImpl implements CMISQueryService
private CMISPropertyService cmisPropertyService;
private CMISMapping cmisMapping;
private QueryEngine queryEngine;
private NodeService nodeService;
@@ -81,15 +79,6 @@ public class CMISQueryServiceImpl implements CMISQueryService
this.cmisDictionaryService = cmisDictionaryService;
}
/**
* @param cmisMapping
* the cmisMapping to set
*/
public void setCmisMapping(CMISMapping cmisMapping)
{
this.cmisMapping = cmisMapping;
}
/**
* @param queryEngine
* the queryEngine to set
@@ -129,7 +118,7 @@ public class CMISQueryServiceImpl implements CMISQueryService
{
joinSupport = CMISJoinEnum.INNER_JOIN_SUPPORT;
}
CMISQueryParser parser = new CMISQueryParser(options, cmisDictionaryService, cmisMapping, joinSupport);
CMISQueryParser parser = new CMISQueryParser(options, cmisDictionaryService, joinSupport);
Query query = parser.parse(queryEngine.getQueryModelFactory());
CmisFunctionEvaluationContext functionContext = new CmisFunctionEvaluationContext();