Author: jens
Date: Tue Feb 14 13:51:53 2017
New Revision: 1782965
URL: http://svn.apache.org/viewvc?rev=1782965&view=rev
Log:
InMemory server process queries according to CMIS-1012
Fix bug: https://issues.apache.org/jira/browse/CMIS-1012
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTypesTest.java
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java?rev=1782965&r1=1782964&r2=1782965&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java
Tue Feb 14 13:51:53 2017
@@ -270,7 +270,7 @@ public final class PropertyCreationHelpe
return props;
}
- public static Properties getPropertiesFromObject(StoredObject so,
ObjectStore objectStore,
+ public static Properties getPropertiesFromObject(TypeManager tm,
StoredObject so, ObjectStore objectStore,
TypeDefinition primaryType, List<TypeDefinition> secondaryTypes,
Map<String, String> requestedIds,
Map<String, String> requestedFuncs) {
// build properties collection
@@ -347,6 +347,20 @@ public final class PropertyCreationHelpe
}
}
}
+
+ // add secondary properties that are not part of a JOIN in a query,
e.g.
+ // SELECT cmis:name, mySecondaryProp FROM cmis:document ...
+ // we do not have an exact type definition in this case
mySecondaryProp can be part of multiple
+ // type definitions, take the first one found.
+ if (!requestedIds.containsValue("*")) {
+ for (Map.Entry<String, String> prop :
requestedIds.entrySet()) {
+ if
(!mappedProperties.containsKey(prop.getValue())) {
+ PropertyData<?> pd =
properties.get(prop.getValue());
+ TypeDefinition typeDef =
findFirstTypeDefHavingProperty(tm, so, pd);
+ addPropertyToMap(mappedProperties,
typeDef, pd, prop.getKey());
+ }
+ }
+ }
// add functions:
for (Entry<String, String> funcEntry : requestedFuncs.entrySet()) {
@@ -372,7 +386,19 @@ public final class PropertyCreationHelpe
return props;
}
- private static void addNotSetPropertyToMap(Map<String, PropertyData<?>>
mappedProperties, TypeDefinition typeDef,
+ private static TypeDefinition findFirstTypeDefHavingProperty(TypeManager
tm, StoredObject so, PropertyData<?> pd) {
+ List<String> typeIds = so.getSecondaryTypeIds();
+ for (String typeId : typeIds) {
+ TypeDefinition typeDef =
tm.getTypeById(typeId).getTypeDefinition();
+ Map<String, PropertyDefinition<?>> propMap =
typeDef.getPropertyDefinitions();
+ if (propMap.containsKey(pd.getId())) {
+ return typeDef;
+ }
+ }
+ return null;
+ }
+
+ private static void addNotSetPropertyToMap(Map<String, PropertyData<?>>
mappedProperties, TypeDefinition typeDef,
String propId, String queryNameOrAlias) {
PropertyDefinition<?> propDef =
typeDef.getPropertyDefinitions().get(propId);
if (null != propDef) {
@@ -468,7 +494,7 @@ public final class PropertyCreationHelpe
ObjectDataImpl od = new ObjectDataImpl();
// build properties collection
- Properties props = getPropertiesFromObject(so, objectStore,
primaryType, secondaryTypes, requestedProperties,
+ Properties props = getPropertiesFromObject(tm, so, objectStore,
primaryType, secondaryTypes, requestedProperties,
requestedFuncs);
// fill output object
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java?rev=1782965&r1=1782964&r2=1782965&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
Tue Feb 14 13:51:53 2017
@@ -1099,7 +1099,23 @@ public class EvalQueryTest extends Abstr
log.debug("...Stop testSecondaryJoin.");
}
-
+
+ @Test
+ public void testAskForSecondaryPropertyOnSimpleQuery() {
+ log.debug("Start testAskForSecondaryPropertyOnSimpleQuery...");
+ dataCreator.createSecondaryTestDocuments();
+ String statement = "SELECT cmis:name, cmis:objectId, " +
UnitTestTypeSystemCreator.SECONDARY_INTEGER_PROP
+ + " AS SecInt, " +
UnitTestTypeSystemCreator.SECONDARY_STRING_PROP + " FROM " + COMPLEX_TYPE +
+ " WHERE cmis:name LIKE 'docwithsecondary%'";
+ ObjectList res = doQuery(statement);
+ assertEquals(2, res.getObjects().size());
+ assertTrue(resultContainsProperty(PropertyIds.NAME, res));
+ assertTrue(resultContainsProperty(PropertyIds.OBJECT_ID, res));
+
assertTrue(resultContainsProperty(UnitTestTypeSystemCreator.SECONDARY_STRING_PROP,
res));
+ assertTrue(resultContainsQueryName("SecInt", res));
+ log.debug("...Stop testAskForSecondaryPropertyOnSimpleQuery.");
+ }
+
@Test
public void testMultipleContains() {
log.debug("Start testMultipleContains...");
@@ -1201,5 +1217,16 @@ public class EvalQueryTest extends Abstr
}
return true;
}
+
+ private static boolean resultContainsQueryName(String queryName,
ObjectList results) {
+ for (ObjectData od : results.getObjects()) {
+ for (PropertyData<?> propData :
od.getProperties().getProperties().values()) {
+ if (queryName.equals(propData.getQueryName())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTypesTest.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTypesTest.java?rev=1782965&r1=1782964&r2=1782965&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTypesTest.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTypesTest.java
Tue Feb 14 13:51:53 2017
@@ -127,14 +127,22 @@ public class QueryTypesTest extends Abst
}
@Test
- public void resolveTypesTest7() {
+ public void resolveTypesTest7() throws Exception {
String statement = "SELECT UnknownProperty FROM BookType WHERE ISBN =
'100'";
- try {
- verifyResolveSelect(statement);
- fail("Select of unknown property in type should fail.");
- } catch (Exception e) {
- assertTrue(e instanceof CmisInvalidArgumentException);
- assertTrue(e.toString().contains("is not a property query name in
any"));
+
+ CmisQueryWalker walker = getWalker(statement);
+ assertNotNull(queryObj);
+ assertNotNull(walker);
+ Map<String, String> types = queryObj.getTypes();
+ assertTrue(1 == types.size());
+ List<CmisSelector> selects = queryObj.getSelectReferences();
+ assertTrue(1 == selects.size());
+ for (CmisSelector select : selects) {
+ assertTrue(select instanceof ColumnReference);
+ ColumnReference colRef = ((ColumnReference) select);
+ assertTrue(null == colRef.getTypeDefinition());
+
assertTrue(colRef.getPropertyQueryName().equals("UnknownProperty"));
+ assertTrue(null == colRef.getPropertyId());
}
}