Repository: olingo-odata4
Updated Branches:
  refs/heads/master ecf7f56ec -> f6dd0deac


[OLINGO-1122]Addressing derived types in filter and expand


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/f6dd0dea
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/f6dd0dea
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/f6dd0dea

Branch: refs/heads/master
Commit: f6dd0deacc27a21ec2273cb58735005712fe1dd7
Parents: ecf7f56
Author: ramya vasanth <ramya.vasa...@sap.com>
Authored: Tue Jul 25 09:43:57 2017 +0530
Committer: ramya vasanth <ramya.vasa...@sap.com>
Committed: Tue Jul 25 09:43:57 2017 +0530

----------------------------------------------------------------------
 .../fit/tecsvc/client/BatchClientITCase.java    |   2 +-
 .../tecsvc/client/EntityReferencesITCase.java   |   2 +-
 .../http/DerivedAndMixedTypeTestITCase.java     | 378 +++++++++++++++++++
 .../fit/tecsvc/http/DerivedTypeTestITCase.java  | 176 ---------
 .../core/uri/parser/ExpressionParser.java       |  22 +-
 lib/server-tecsvc/pom.xml                       |   2 +-
 .../olingo/server/tecsvc/data/DataCreator.java  |  35 +-
 .../tecsvc/processor/TechnicalProcessor.java    |  20 +
 .../expression/ExpressionVisitorImpl.java       |  67 +++-
 .../json/ODataJsonSerializerTest.java           |  20 +-
 .../serializer/xml/ODataXmlSerializerTest.java  |  45 ++-
 11 files changed, 555 insertions(+), 214 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f6dd0dea/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
----------------------------------------------------------------------
diff --git 
a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
index 9e1537d..aa77ced 100644
--- 
a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
+++ 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
@@ -421,7 +421,7 @@ public class BatchClientITCase extends 
AbstractParamTecSvcITCase {
     assertEquals(1, oDataResponse.getHeader(HttpHeader.ODATA_VERSION).size());
     assertEquals("4.0", 
oDataResponse.getHeader(HttpHeader.ODATA_VERSION).iterator().next());
     assertEquals(1, oDataResponse.getHeader(HttpHeader.CONTENT_LENGTH).size());
-    assertEquals(isJson() ? "517" : "2138", 
oDataResponse.getHeader(HttpHeader.CONTENT_LENGTH).iterator().next());
+    assertEquals(isJson() ? "517" : "2114", 
oDataResponse.getHeader(HttpHeader.CONTENT_LENGTH).iterator().next());
     assertContentType(oDataResponse.getContentType());
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f6dd0dea/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java
----------------------------------------------------------------------
diff --git 
a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java
 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java
index bac2927..30c95d4 100644
--- 
a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java
+++ 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java
@@ -168,7 +168,7 @@ public class EntityReferencesITCase extends 
AbstractParamTecSvcITCase {
   @Test
   public void responseNonExistingEntity() {
     final URI uri = getClient().newURIBuilder(SERVICE_URI)
-                          
.appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(0)
+                          
.appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(-32768)
                           
.appendNavigationSegment(NAV_PROPERTY_ET_TWO_PRIM_ONE).appendRefSegment().build();
     
     try {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f6dd0dea/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/DerivedAndMixedTypeTestITCase.java
----------------------------------------------------------------------
diff --git 
a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/DerivedAndMixedTypeTestITCase.java
 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/DerivedAndMixedTypeTestITCase.java
new file mode 100644
index 0000000..75967b6
--- /dev/null
+++ 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/DerivedAndMixedTypeTestITCase.java
@@ -0,0 +1,378 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.fit.tecsvc.http;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.olingo.client.api.ODataClient;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.api.http.HttpMethod;
+import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.fit.AbstractBaseTestITCase;
+import org.apache.olingo.fit.tecsvc.TecSvcConst;
+import org.junit.Test;
+
+public class DerivedAndMixedTypeTestITCase extends AbstractBaseTestITCase {
+
+  private static final String SERVICE_URI = TecSvcConst.BASE_URI + "/";
+
+  @Test
+  public void queryESCompCollDerivedJson() throws Exception {
+    URL url = new URL(SERVICE_URI + "ESCompCollDerived?$format=json");
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    connection.setRequestMethod(HttpMethod.GET.name());
+    connection.connect();
+
+    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
+    assertEquals(ContentType.JSON, 
ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE)));
+
+    final String content = IOUtils.toString(connection.getInputStream());
+
+    assertTrue(content.contains(
+        
"[{\"PropertyInt16\":32767,\"PropertyCompAno\":null,\"CollPropertyCompAno\":[{\"PropertyString\":"
 +
+        
"\"TEST9876\"}]},{\"PropertyInt16\":12345,\"PropertyCompAno\":{\"@odata.type\":"
 +
+        
"\"#olingo.odata.test1.CTBaseAno\",\"PropertyString\":\"Num111\",\"AdditionalPropString\":"
 +
+        
"\"Test123\"},\"CollPropertyCompAno\":[{\"@odata.type\":\"#olingo.odata.test1.CTBaseAno\","
 +
+        
"\"PropertyString\":\"TEST12345\",\"AdditionalPropString\":\"Additional12345\"},"
 +
+        "{\"PropertyString\":\"TESTabcd\"}]}]}" ));
+  }
+
+  @Test
+  public void queryESCompCollDerivedXml() throws Exception {
+    URL url = new URL(SERVICE_URI + "ESCompCollDerived?$format=xml");
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    connection.setRequestMethod(HttpMethod.GET.name());
+    connection.connect();
+
+    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
+    assertEquals(ContentType.APPLICATION_XML, 
ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE)));
+
+    final String content = IOUtils.toString(connection.getInputStream());
+    assertTrue(content.contains("<d:PropertyCompAno 
m:type=\"#olingo.odata.test1.CTBaseAno\">" +
+        "<d:PropertyString>Num111</d:PropertyString>" +
+        "<d:AdditionalPropString>Test123</d:AdditionalPropString>" +
+        "</d:PropertyCompAno>" +
+        "<d:CollPropertyCompAno 
m:type=\"#Collection(olingo.odata.test1.CTTwoPrimAno)\">" +
+        "<m:element m:type=\"olingo.odata.test1.CTBaseAno\">" +
+        "<d:PropertyString>TEST12345</d:PropertyString>" +
+        "<d:AdditionalPropString>Additional12345</d:AdditionalPropString>" ));
+  }
+
+  @Test
+  public void queryESAllPrimDerivedJson() throws Exception {
+    URL url = new URL(SERVICE_URI + 
"ESAllPrimDerived(0)?$expand=NavPropertyETTwoPrimMany&$format=json");
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    connection.setRequestMethod(HttpMethod.GET.name());
+    connection.connect();
+
+    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
+
+    final String content = IOUtils.toString(connection.getInputStream());
+    
assertTrue(content.contains("\"@odata.type\":\"#olingo.odata.test1.ETBase\"," +
+        "\"PropertyInt16\":32766," +
+        "\"PropertyString\":\"Test String1\"," +
+        "\"AdditionalPropertyString_5\":\"Additional String1\"" ));
+  }
+  
+  @Test
+  public void queryESAllPrimDerivedXml() throws Exception {
+    URL url = new URL(SERVICE_URI + 
"ESAllPrimDerived(0)?$expand=NavPropertyETTwoPrimMany&$format=xml");
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    connection.setRequestMethod(HttpMethod.GET.name());
+    connection.connect();
+
+    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
+
+    final String content = IOUtils.toString(connection.getInputStream());
+    assertTrue(content.contains("term=\"#olingo.odata.test1.ETBase\"/>"));
+    assertTrue(content.contains(
+        "<d:PropertyInt16 m:type=\"Int16\">32766</d:PropertyInt16>" +
+        "<d:PropertyString>Test String1</d:PropertyString>" +
+        "<d:AdditionalPropertyString_5>Additional 
String1</d:AdditionalPropertyString_5>"));
+  }
+  
+  @Test
+  public void queryESCompCollDerivedJsonNone() throws Exception {
+    URL url = new URL(SERVICE_URI + "ESCompCollDerived");
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    connection.setRequestMethod(HttpMethod.GET.name());
+    connection.setRequestProperty(HttpHeader.ACCEPT, 
"application/json;odata.metadata=none");
+    connection.connect();
+
+    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
+    assertEquals(ContentType.JSON_NO_METADATA, 
ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE)));
+
+    final String content = IOUtils.toString(connection.getInputStream());
+
+    assertTrue(content.contains(
+        
"[{\"PropertyInt16\":32767,\"PropertyCompAno\":null,\"CollPropertyCompAno\":[{\"PropertyString\":"
 +
+        "\"TEST9876\"}]},{\"PropertyInt16\":12345,\"PropertyCompAno\":{"+
+        "\"PropertyString\":\"Num111\",\"AdditionalPropString\":" +
+        "\"Test123\"},\"CollPropertyCompAno\":[{" +
+        
"\"PropertyString\":\"TEST12345\",\"AdditionalPropString\":\"Additional12345\"},"
 +
+        "{\"PropertyString\":\"TESTabcd\"}]}]}" ));
+  }
+  @Test
+  public void queryESCompCollDerivedJsonFull() throws Exception {
+    URL url = new URL(SERVICE_URI + "ESCompCollDerived");
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    connection.setRequestProperty(HttpHeader.ACCEPT, 
"application/json;odata.metadata=full");
+    connection.setRequestMethod(HttpMethod.GET.name());
+    connection.connect();
+
+    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
+    assertEquals(ContentType.JSON_FULL_METADATA, 
+        
ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE)));
+
+    final String content = IOUtils.toString(connection.getInputStream());
+
+    
assertTrue(content.contains("\"PropertyInt16\":32767,\"PropertyCompAno\":null," 
+
+        
"\"collpropertycomp...@odata.type\":\"#Collection(olingo.odata.test1.CTTwoPrimAno)\","
 +
+        "\"CollPropertyCompAno\":[{\"@odata.type\":" +
+        
"\"#olingo.odata.test1.CTTwoPrimAno\",\"PropertyString\":\"TEST9876\"}]}," +
+        
"{\"@odata.type\":\"#olingo.odata.test1.ETDeriveCollComp\",\"@odata.id\":\"ESCompCollDerived(12345)\","
 +
+        
"\"propertyin...@odata.type\":\"#Int16\",\"PropertyInt16\":12345,\"PropertyCompAno\":"
 +
+        "{\"@odata.type\":\"#olingo.odata.test1.CTBaseAno\"," +
+        "\"PropertyString\":\"Num111\",\"AdditionalPropString\":\"Test123\"}," 
+
+        
"\"collpropertycomp...@odata.type\":\"#Collection(olingo.odata.test1.CTTwoPrimAno)\",\"CollPropertyCompAno\":"
 +
+        "[{\"@odata.type\":\"#olingo.odata.test1.CTBaseAno\"," +
+        
"\"PropertyString\":\"TEST12345\",\"AdditionalPropString\":\"Additional12345\"},"
 +
+        
"{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrimAno\",\"PropertyString\":\"TESTabcd\"}]}]}"
 ));
+  }
+
+  @Override
+  protected ODataClient getClient() {
+    return null;
+  }
+
+  @Test
+  public void queryESMixPrimWithLambdaDerived_JsonFull_Olingo1122() throws 
Exception {
+    URL url = new URL(SERVICE_URI + 
"ESMixPrimCollComp?$filter=CollPropertyComp/any"
+        + 
"(f:f/olingo.odata.test1.CTBase/AdditionalPropString%20eq%20%27ADD%20TEST%27)");
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    connection.setRequestMethod(HttpMethod.GET.name());
+    connection.setRequestProperty(HttpHeader.ACCEPT, 
"application/json;odata.metadata=full");
+    connection.connect();
+
+    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
+    assertEquals(ContentType.JSON_FULL_METADATA, 
+        
ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE)));
+
+    final String content = IOUtils.toString(connection.getInputStream());
+    assertTrue(content.contains("\"value\":"
+        + "[{\"@odata.type\":\"#olingo.odata.test1.ETMixPrimCollComp\","
+        + "\"@odata.id\":\"ESMixPrimCollComp(32767)\","
+        + "\"propertyin...@odata.type\":\"#Int16\","
+        + "\"PropertyInt16\":32767,"
+        + "\"collpropertystr...@odata.type\":\"#Collection(String)\","
+        + "\"CollPropertyString\":"
+        + "[\"Employee1@company.example\",\"Employee2@company.example\","
+        + "\"Employee3@company.example\"],"
+        + "\"PropertyComp\":"
+        + "{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\","
+        + "\"propertyin...@odata.type\":\"#Int16\",\"PropertyInt16\":111,"
+        + "\"PropertyString\":\"TEST A\"},"
+        + 
"\"collpropertyc...@odata.type\":\"#Collection(olingo.odata.test1.CTTwoPrim)\","
+        + "\"CollPropertyComp\":"
+        + "[{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\","
+        + "\"propertyin...@odata.type\":\"#Int16\",\"PropertyInt16\":123,"
+        + "\"PropertyString\":\"TEST 1\"},"
+        + "{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\","
+        + "\"propertyin...@odata.type\":\"#Int16\","
+        + "\"PropertyInt16\":456,"
+        + "\"PropertyString\":\"TEST 2\"},"
+        + "{\"@odata.type\":\"#olingo.odata.test1.CTBase\","
+        + "\"propertyin...@odata.type\":\"#Int16\","
+        + "\"PropertyInt16\":789,"
+        + "\"PropertyString\":\"TEST 3\","
+        + "\"AdditionalPropString\":\"ADD TEST\"}]},"
+        + "{\"@odata.type\":\"#olingo.odata.test1.ETMixPrimCollComp\","
+        + "\"@odata.id\":\"ESMixPrimCollComp(7)\","
+        + "\"propertyin...@odata.type\":\"#Int16\","
+        + 
"\"PropertyInt16\":7,\"collpropertystr...@odata.type\":\"#Collection(String)\","
+        + "\"CollPropertyString\":[\"Employee1@company.example\","
+        + "\"Employee2@company.example\","
+        + "\"Employee3@company.example\"],"
+        + 
"\"PropertyComp\":{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\","
+        + 
"\"propertyin...@odata.type\":\"#Int16\",\"PropertyInt16\":222,\"PropertyString\":\"TEST
 B\"},"
+        + 
"\"collpropertyc...@odata.type\":\"#Collection(olingo.odata.test1.CTTwoPrim)\","
+        + 
"\"CollPropertyComp\":[{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\","
+        + 
"\"propertyin...@odata.type\":\"#Int16\",\"PropertyInt16\":123,\"PropertyString\":\"TEST
 1\"},"
+        + 
"{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\",\"propertyin...@odata.type\":\"#Int16\","
+        + "\"PropertyInt16\":456,\"PropertyString\":\"TEST 
2\"},{\"@odata.type\":\"#olingo.odata.test1.CTBase\","
+        + 
"\"propertyin...@odata.type\":\"#Int16\",\"PropertyInt16\":789,\"PropertyString\":\"TEST
 3\","
+        + "\"AdditionalPropString\":\"ADD 
TEST\"}]},{\"@odata.type\":\"#olingo.odata.test1.ETMixPrimCollComp\","
+        + 
"\"@odata.id\":\"ESMixPrimCollComp(0)\",\"propertyin...@odata.type\":\"#Int16\",\"PropertyInt16\":0,"
+        + 
"\"collpropertystr...@odata.type\":\"#Collection(String)\",\"CollPropertyString\":"
+        + 
"[\"Employee1@company.example\",\"Employee2@company.example\",\"Employee3@company.example\"],"
+        + 
"\"PropertyComp\":{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\",\"propertyin...@odata.type\":\"#Int16\","
+        + "\"PropertyInt16\":333,\"PropertyString\":\"TEST C\"},"
+        + 
"\"collpropertyc...@odata.type\":\"#Collection(olingo.odata.test1.CTTwoPrim)\","
+        + "\"CollPropertyComp\":"
+        + "[{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\","
+        + 
"\"propertyin...@odata.type\":\"#Int16\",\"PropertyInt16\":123,\"PropertyString\":\"TEST
 1\"},"
+        + "{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\","
+        + 
"\"propertyin...@odata.type\":\"#Int16\",\"PropertyInt16\":456,\"PropertyString\":\"TEST
 2\"},"
+        + "{\"@odata.type\":\"#olingo.odata.test1.CTBase\","
+        + 
"\"propertyin...@odata.type\":\"#Int16\",\"PropertyInt16\":789,\"PropertyString\":\"TEST
 3\","
+        + "\"AdditionalPropString\":\"ADD TEST\"}]}]"));
+  }
+  
+  @Test
+  public void queryESMixPrimWithLambdaDerived_JsonMinimal_Olingo1122() throws 
Exception {
+    URL url = new URL(SERVICE_URI + 
"ESMixPrimCollComp?$filter=CollPropertyComp/any"
+        + 
"(f:f/olingo.odata.test1.CTBase/AdditionalPropString%20eq%20%27ADD%20TEST%27)");
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    connection.setRequestMethod(HttpMethod.GET.name());
+    connection.setRequestProperty(HttpHeader.ACCEPT, 
"application/json;odata.metadata=minimal");
+    connection.connect();
+
+    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
+    assertEquals(ContentType.JSON, 
+        
ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE)));
+
+    final String content = IOUtils.toString(connection.getInputStream());
+    assertTrue(content.contains("\"value\":[{\"PropertyInt16\":32767,"
+        + "\"CollPropertyString\":[\"Employee1@company.example\","
+        + "\"Employee2@company.example\","
+        + "\"Employee3@company.example\"],"
+        + "\"PropertyComp\":{\"PropertyInt16\":111,\"PropertyString\":\"TEST 
A\"},"
+        + "\"CollPropertyComp\":["
+        + "{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"},"
+        + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
+        + "{\"@odata.type\":\"#olingo.odata.test1.CTBase\","
+        + "\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\","
+        + "\"AdditionalPropString\":\"ADD TEST\"}]},"
+        + "{\"PropertyInt16\":7,\"CollPropertyString\":"
+        + "[\"Employee1@company.example\","
+        + "\"Employee2@company.example\","
+        + "\"Employee3@company.example\"],"
+        + "\"PropertyComp\":{\"PropertyInt16\":222,\"PropertyString\":\"TEST 
B\"},"
+        + 
"\"CollPropertyComp\":[{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"},"
+        + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
+        + "{\"@odata.type\":\"#olingo.odata.test1.CTBase\","
+        + "\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\","
+        + "\"AdditionalPropString\":\"ADD TEST\"}]},"
+        + "{\"PropertyInt16\":0,\"CollPropertyString\":["
+        + "\"Employee1@company.example\","
+        + "\"Employee2@company.example\","
+        + "\"Employee3@company.example\"],"
+        + "\"PropertyComp\":{\"PropertyInt16\":333,\"PropertyString\":\"TEST 
C\"},"
+        + "\"CollPropertyComp\":["
+        + "{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"},"
+        + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
+        + "{\"@odata.type\":\"#olingo.odata.test1.CTBase\","
+        + "\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\","
+        + "\"AdditionalPropString\":\"ADD TEST\"}]}]"));
+  }
+  
+  @Test
+  public void queryESTwoPrimWithEntityTypeCast() throws Exception {
+    URL url = new URL(SERVICE_URI + 
"ESTwoPrim(111)/olingo.odata.test1.ETBase");
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    connection.setRequestMethod(HttpMethod.GET.name());
+    connection.setRequestProperty(HttpHeader.ACCEPT, 
"application/json;odata.metadata=full");
+    connection.connect();
+
+    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
+    assertEquals(ContentType.JSON_FULL_METADATA, 
+        
ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE)));
+
+    final String content = IOUtils.toString(connection.getInputStream());
+    
assertTrue(content.contains("\"@odata.type\":\"#olingo.odata.test1.ETBase\","
+        + "\"@odata.id\":\"ESBase(111)\","
+        + "\"propertyin...@odata.type\":\"#Int16\","
+        + "\"PropertyInt16\":111,"
+        + "\"PropertyString\":\"TEST A\","
+        + "\"AdditionalPropertyString_5\":\"TEST A 0815\""));
+  }
+  
+  @Test
+  public void queryESTwoPrimWithEntityTypeCastInFilter() throws Exception {
+    URL url = new URL(SERVICE_URI + 
"ESTwoPrim?$filter=olingo.odata.test1.ETBase/"
+        + "AdditionalPropertyString_5%20eq%20%27TEST%20A%200815%27");
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    connection.setRequestMethod(HttpMethod.GET.name());
+    connection.setRequestProperty(HttpHeader.ACCEPT, 
"application/json;odata.metadata=full");
+    connection.connect();
+
+    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
+    assertEquals(ContentType.JSON_FULL_METADATA, 
+        
ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE)));
+
+    final String content = IOUtils.toString(connection.getInputStream());
+    
assertTrue(content.contains("\"value\":[{\"@odata.type\":\"#olingo.odata.test1.ETBase\","
+        + "\"@odata.id\":\"ESBase(111)\","
+        + "\"propertyin...@odata.type\":\"#Int16\","
+        + "\"PropertyInt16\":111,"
+        + "\"PropertyString\":\"TEST A\","
+        + "\"AdditionalPropertyString_5\":\"TEST A 0815\"}]"));
+  }
+  
+  @Test
+  public void queryESAllPrimWithEntityTypeCastInExpand() throws Exception {
+    URL url = new URL(SERVICE_URI + 
"ESAllPrim(0)?$expand=NavPropertyETTwoPrimOne/olingo.odata.test1.ETBase");
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    connection.setRequestMethod(HttpMethod.GET.name());
+    connection.setRequestProperty(HttpHeader.ACCEPT, 
"application/json;odata.metadata=minimal");
+    connection.connect();
+
+    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
+    assertEquals(ContentType.JSON, 
+        
ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE)));
+
+    final String content = IOUtils.toString(connection.getInputStream());
+    assertTrue(content.contains("\"PropertyInt16\":0,"
+        + "\"PropertyString\":\"\","
+        + "\"PropertyBoolean\":false,"
+        + "\"PropertyByte\":0,"
+        + "\"PropertySByte\":0,"
+        + "\"PropertyInt32\":0,"
+        + "\"PropertyInt64\":0,"
+        + "\"PropertySingle\":0.0,"
+        + "\"PropertyDouble\":0.0,"
+        + "\"PropertyDecimal\":0,"
+        + "\"PropertyBinary\":\"\","
+        + "\"PropertyDate\":\"1970-01-01\","
+        + "\"PropertyDateTimeOffset\":\"2005-12-03T00:00:00Z\","
+        + "\"PropertyDuration\":\"PT0S\","
+        + "\"PropertyGuid\":\"76543201-23ab-cdef-0123-456789cccddd\","
+        + "\"PropertyTimeOfDay\":\"00:01:01\",\"NavPropertyETTwoPrimOne\":{"
+        + "\"@odata.type\":\"#olingo.odata.test1.ETBase\","
+        + "\"PropertyInt16\":111,\"PropertyString\":\"TEST A\","
+        + "\"AdditionalPropertyString_5\":\"TEST A 0815\"}"));
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f6dd0dea/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/DerivedTypeTestITCase.java
----------------------------------------------------------------------
diff --git 
a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/DerivedTypeTestITCase.java
 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/DerivedTypeTestITCase.java
deleted file mode 100644
index e7d4a80..0000000
--- 
a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/DerivedTypeTestITCase.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.fit.tecsvc.http;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.net.HttpURLConnection;
-import java.net.URL;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.olingo.client.api.ODataClient;
-import org.apache.olingo.commons.api.format.ContentType;
-import org.apache.olingo.commons.api.http.HttpHeader;
-import org.apache.olingo.commons.api.http.HttpMethod;
-import org.apache.olingo.commons.api.http.HttpStatusCode;
-import org.apache.olingo.fit.AbstractBaseTestITCase;
-import org.apache.olingo.fit.tecsvc.TecSvcConst;
-import org.junit.Test;
-
-public class DerivedTypeTestITCase extends AbstractBaseTestITCase {
-
-  private static final String SERVICE_URI = TecSvcConst.BASE_URI + "/";
-
-  @Test
-  public void queryESCompCollDerivedJson() throws Exception {
-    URL url = new URL(SERVICE_URI + "ESCompCollDerived?$format=json");
-
-    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-    connection.setRequestMethod(HttpMethod.GET.name());
-    connection.connect();
-
-    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
-    assertEquals(ContentType.JSON, 
ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE)));
-
-    final String content = IOUtils.toString(connection.getInputStream());
-
-    assertTrue(content.contains(
-        
"[{\"PropertyInt16\":32767,\"PropertyCompAno\":null,\"CollPropertyCompAno\":[{\"PropertyString\":"
 +
-        
"\"TEST9876\"}]},{\"PropertyInt16\":12345,\"PropertyCompAno\":{\"@odata.type\":"
 +
-        
"\"#olingo.odata.test1.CTBaseAno\",\"PropertyString\":\"Num111\",\"AdditionalPropString\":"
 +
-        
"\"Test123\"},\"CollPropertyCompAno\":[{\"@odata.type\":\"#olingo.odata.test1.CTBaseAno\","
 +
-        
"\"PropertyString\":\"TEST12345\",\"AdditionalPropString\":\"Additional12345\"},"
 +
-        "{\"PropertyString\":\"TESTabcd\"}]}]}" ));
-  }
-
-  @Test
-  public void queryESCompCollDerivedXml() throws Exception {
-    URL url = new URL(SERVICE_URI + "ESCompCollDerived?$format=xml");
-
-    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-    connection.setRequestMethod(HttpMethod.GET.name());
-    connection.connect();
-
-    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
-    assertEquals(ContentType.APPLICATION_XML, 
ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE)));
-
-    final String content = IOUtils.toString(connection.getInputStream());
-    assertTrue(content.contains("<d:PropertyCompAno 
m:type=\"#olingo.odata.test1.CTBaseAno\">" +
-        "<d:PropertyString>Num111</d:PropertyString>" +
-        "<d:AdditionalPropString>Test123</d:AdditionalPropString>" +
-        "</d:PropertyCompAno>" +
-        "<d:CollPropertyCompAno 
m:type=\"#Collection(olingo.odata.test1.CTTwoPrimAno)\">" +
-        "<m:element m:type=\"olingo.odata.test1.CTBaseAno\">" +
-        "<d:PropertyString>TEST12345</d:PropertyString>" +
-        "<d:AdditionalPropString>Additional12345</d:AdditionalPropString>" ));
-  }
-
-  @Test
-  public void queryESAllPrimDerivedJson() throws Exception {
-    URL url = new URL(SERVICE_URI + 
"ESAllPrimDerived(0)?$expand=NavPropertyETTwoPrimMany&$format=json");
-
-    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-    connection.setRequestMethod(HttpMethod.GET.name());
-    connection.connect();
-
-    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
-
-    final String content = IOUtils.toString(connection.getInputStream());
-    
assertTrue(content.contains("\"@odata.type\":\"#olingo.odata.test1.ETBase\"," +
-        "\"PropertyInt16\":32766," +
-        "\"PropertyString\":\"Test String1\"," +
-        "\"AdditionalPropertyString_5\":\"Additional String1\"" ));
-  }
-  
-  @Test
-  public void queryESAllPrimDerivedXml() throws Exception {
-    URL url = new URL(SERVICE_URI + 
"ESAllPrimDerived(0)?$expand=NavPropertyETTwoPrimMany&$format=xml");
-
-    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-    connection.setRequestMethod(HttpMethod.GET.name());
-    connection.connect();
-
-    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
-
-    final String content = IOUtils.toString(connection.getInputStream());
-    assertTrue(content.contains("term=\"#olingo.odata.test1.ETBase\"/>"));
-    assertTrue(content.contains(
-        "<d:PropertyInt16 m:type=\"Int16\">32766</d:PropertyInt16>" +
-        "<d:PropertyString>Test String1</d:PropertyString>" +
-        "<d:AdditionalPropertyString_5>Additional 
String1</d:AdditionalPropertyString_5>"));
-  }
-  
-  @Test
-  public void queryESCompCollDerivedJsonNone() throws Exception {
-    URL url = new URL(SERVICE_URI + "ESCompCollDerived");
-
-    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-    connection.setRequestMethod(HttpMethod.GET.name());
-    connection.setRequestProperty(HttpHeader.ACCEPT, 
"application/json;odata.metadata=none");
-    connection.connect();
-
-    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
-    assertEquals(ContentType.JSON_NO_METADATA, 
ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE)));
-
-    final String content = IOUtils.toString(connection.getInputStream());
-
-    assertTrue(content.contains(
-        
"[{\"PropertyInt16\":32767,\"PropertyCompAno\":null,\"CollPropertyCompAno\":[{\"PropertyString\":"
 +
-        "\"TEST9876\"}]},{\"PropertyInt16\":12345,\"PropertyCompAno\":{"+
-        "\"PropertyString\":\"Num111\",\"AdditionalPropString\":" +
-        "\"Test123\"},\"CollPropertyCompAno\":[{" +
-        
"\"PropertyString\":\"TEST12345\",\"AdditionalPropString\":\"Additional12345\"},"
 +
-        "{\"PropertyString\":\"TESTabcd\"}]}]}" ));
-  }
-  @Test
-  public void queryESCompCollDerivedJsonFull() throws Exception {
-    URL url = new URL(SERVICE_URI + "ESCompCollDerived");
-
-    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-    connection.setRequestProperty(HttpHeader.ACCEPT, 
"application/json;odata.metadata=full");
-    connection.setRequestMethod(HttpMethod.GET.name());
-    connection.connect();
-
-    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
-    assertEquals(ContentType.JSON_FULL_METADATA, 
-        
ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE)));
-
-    final String content = IOUtils.toString(connection.getInputStream());
-
-    
assertTrue(content.contains("\"PropertyInt16\":32767,\"PropertyCompAno\":null," 
+
-        
"\"collpropertycomp...@odata.type\":\"#Collection(olingo.odata.test1.CTTwoPrimAno)\","
 +
-        "\"CollPropertyCompAno\":[{\"@odata.type\":" +
-        
"\"#olingo.odata.test1.CTTwoPrimAno\",\"PropertyString\":\"TEST9876\"}]}," +
-        
"{\"@odata.type\":\"#olingo.odata.test1.ETDeriveCollComp\",\"@odata.id\":\"ESCompCollDerived(12345)\","
 +
-        
"\"propertyin...@odata.type\":\"#Int16\",\"PropertyInt16\":12345,\"PropertyCompAno\":"
 +
-        "{\"@odata.type\":\"#olingo.odata.test1.CTBaseAno\"," +
-        "\"PropertyString\":\"Num111\",\"AdditionalPropString\":\"Test123\"}," 
+
-        
"\"collpropertycomp...@odata.type\":\"#Collection(olingo.odata.test1.CTTwoPrimAno)\",\"CollPropertyCompAno\":"
 +
-        "[{\"@odata.type\":\"#olingo.odata.test1.CTBaseAno\"," +
-        
"\"PropertyString\":\"TEST12345\",\"AdditionalPropString\":\"Additional12345\"},"
 +
-        
"{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrimAno\",\"PropertyString\":\"TESTabcd\"}]}]}"
 ));
-  }
-
-  @Override
-  protected ODataClient getClient() {
-    return null;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f6dd0dea/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java
 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java
index 29ef5cb..ff61fc8 100644
--- 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java
+++ 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java
@@ -753,7 +753,7 @@ public class ExpressionParser {
           throws UriParserException, UriValidationException {
 
     if (lastTokenKind == TokenKind.QualifiedName) {
-      // Type cast or bound function
+      // Type cast to an entity type or complex type or bound function
       final FullQualifiedName fullQualifiedName = new 
FullQualifiedName(tokenizer.getText());
       final EdmEntityType edmEntityType = edm.getEntityType(fullQualifiedName);
 
@@ -777,6 +777,26 @@ public class ExpressionParser {
               
lastResource.getType().getFullQualifiedName().getFullQualifiedNameAsString(),
               fullQualifiedName.getFullQualifiedNameAsString());
         }
+      } else if (edm.getComplexType(fullQualifiedName) != null) {
+        if (allowTypeFilter) {
+          setTypeFilter(lastResource, edm.getComplexType(fullQualifiedName));
+          
+          if (tokenizer.next(TokenKind.SLASH)) {
+            if (tokenizer.next(TokenKind.QualifiedName)) {
+              parseBoundFunction(fullQualifiedName, uriInfo, lastResource);
+            } else if (tokenizer.next(TokenKind.ODataIdentifier)) {
+              parsePropertyPathExpr(uriInfo, lastResource);
+            } else {
+              throw new UriParserSyntaxException("Expected OData Identifier or 
Full Qualified Name.",
+                  UriParserSyntaxException.MessageKeys.SYNTAX);
+            }
+          }
+        } else {
+          throw new UriParserSemanticException("Type filters are not 
chainable.",
+              UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
+              
lastResource.getType().getFullQualifiedName().getFullQualifiedNameAsString(),
+              fullQualifiedName.getFullQualifiedNameAsString());
+        }
       } else {
         parseBoundFunction(fullQualifiedName, uriInfo, lastResource);
       }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f6dd0dea/lib/server-tecsvc/pom.xml
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/pom.xml b/lib/server-tecsvc/pom.xml
index add7dfa..3202779 100644
--- a/lib/server-tecsvc/pom.xml
+++ b/lib/server-tecsvc/pom.xml
@@ -132,7 +132,7 @@
       <groupId>org.apache.olingo</groupId>
       <artifactId>odata-server-core</artifactId>
       <version>${project.version}</version>
-      <scope>runtime</scope>
+      <!-- <scope>runtime</scope> -->
     </dependency>
 
     <dependency>

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f6dd0dea/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
----------------------------------------------------------------------
diff --git 
a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
 
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
index e3d932f..0b8ec36 100644
--- 
a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
+++ 
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
@@ -1371,19 +1371,29 @@ public class DataCreator {
       return entityCollection;
     }  
   
-  @SuppressWarnings("unchecked")
   private Property createCollPropertyComp() {
-    return createComplexCollection("CollPropertyComp",
+    return createComplexDerievedCollection("CollPropertyComp",
         ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
-        Arrays.asList(
-            createPrimitive("PropertyInt16", (short) 123),
-            createPrimitive("PropertyString", "TEST 1")),
-        Arrays.asList(
-            createPrimitive("PropertyInt16", (short) 456),
-            createPrimitive("PropertyString", "TEST 2")),
-        Arrays.asList(
-            createPrimitive("PropertyInt16", (short) 789),
-            createPrimitive("PropertyString", "TEST 3")));
+        Arrays.asList(new ComplexValue[] {
+            
createComplexValue(ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
+                Arrays.asList(new Property[] {
+                    createPrimitive("PropertyInt16", (short) 123),
+                    createPrimitive("PropertyString", "TEST 1")
+                }
+          )),
+            
createComplexValue(ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
+                Arrays.asList(new Property[] {
+                    createPrimitive("PropertyInt16", (short) 456),
+                    createPrimitive("PropertyString", "TEST 2")
+                }
+          )),
+            
createComplexValue(ComplexTypeProvider.nameCTBase.getFullQualifiedNameAsString(),
+                Arrays.asList(new Property[] {
+                    createPrimitive("PropertyInt16", (short) 789),
+                    createPrimitive("PropertyString", "TEST 3"),
+                    createPrimitive("AdditionalPropString", "ADD TEST")
+                }
+          ))}));
   }
 
   private EntityCollection createESAllKey(final Edm edm, final OData odata) {
@@ -1526,6 +1536,7 @@ public class DataCreator {
   private void linkESAllPrim(final Map<String, EntityCollection> data) {
     final EntityCollection entityCollection = data.get("ESAllPrim");
     final List<Entity> targetEntities = data.get("ESTwoPrim").getEntities();
+    final List<Entity> targetESBaseEntities = data.get("ESBase").getEntities();
 
     setLinks(entityCollection.getEntities().get(0), 
"NavPropertyETTwoPrimMany", targetEntities.get(1));
     setLink(entityCollection.getEntities().get(0), "NavPropertyETTwoPrimOne", 
targetEntities.get(3));
@@ -1533,6 +1544,8 @@ public class DataCreator {
     setLinks(entityCollection.getEntities().get(2), 
"NavPropertyETTwoPrimMany", targetEntities.get(0),
         targetEntities.get(2),
         targetEntities.get(3));
+    
+    setLink(entityCollection.getEntities().get(2), "NavPropertyETTwoPrimOne", 
targetESBaseEntities.get(0));
   }
   
   private void linkESAllPrimDerived(final Map<String, EntityCollection> data) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f6dd0dea/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
----------------------------------------------------------------------
diff --git 
a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
 
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
index 2a6f072..03d02dd 100644
--- 
a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
+++ 
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
@@ -46,6 +46,8 @@ import org.apache.olingo.server.api.uri.UriResourceEntitySet;
 import org.apache.olingo.server.api.uri.UriResourceFunction;
 import org.apache.olingo.server.api.uri.UriResourceNavigation;
 import org.apache.olingo.server.api.uri.UriResourceSingleton;
+import org.apache.olingo.server.api.uri.queryoption.expression.Binary;
+import org.apache.olingo.server.api.uri.queryoption.expression.Member;
 import org.apache.olingo.server.tecsvc.data.DataProvider;
 
 /**
@@ -241,6 +243,24 @@ public abstract class TechnicalProcessor implements 
Processor {
         return 
dataProvider.readFunctionEntityCollection(uriResource.getFunction(), 
uriResource.getParameters(),
             uriInfo);
       } else {
+        if (uriInfo.getFilterOption() != null) {
+          if (uriInfo.getFilterOption().getExpression() instanceof Binary) {
+            Binary expression = (Binary) 
uriInfo.getFilterOption().getExpression();
+            if (expression.getLeftOperand() instanceof Member) {
+              Member member = (Member) expression.getLeftOperand();
+              if (member.getStartTypeFilter() != null) {
+                EdmEntityType entityType = (EdmEntityType) 
member.getStartTypeFilter();
+                EdmEntityContainer container = 
this.serviceMetadata.getEdm().getEntityContainer();
+                List<EdmEntitySet> entitySets = container.getEntitySets();
+                for (EdmEntitySet entitySet : entitySets) {
+                  if 
(entityType.getName().equals(entitySet.getEntityType().getName())) {
+                    return dataProvider.readAll(entitySet);
+                  }
+                }
+              }
+            }
+          }
+        }
         EdmEntitySet entitySet = 
getEntitySetBasedOnTypeCast(((UriResourceEntitySet)resourcePaths.get(0)));
         return dataProvider.readAll(entitySet);
       }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f6dd0dea/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java
----------------------------------------------------------------------
diff --git 
a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java
 
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java
index 475925c..d02b892 100644
--- 
a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java
+++ 
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java
@@ -18,15 +18,19 @@
  */
 package org.apache.olingo.server.tecsvc.processor.queryoptions.expression;
 
+import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 
+import org.apache.olingo.commons.api.data.ComplexValue;
 import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.Property;
 import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmComplexType;
 import org.apache.olingo.commons.api.edm.EdmEnumType;
 import org.apache.olingo.commons.api.edm.EdmFunction;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
 import org.apache.olingo.commons.api.edm.EdmProperty;
 import org.apache.olingo.commons.api.edm.EdmType;
 import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
@@ -37,7 +41,10 @@ import org.apache.olingo.server.api.uri.UriInfoResource;
 import org.apache.olingo.server.api.uri.UriParameter;
 import org.apache.olingo.server.api.uri.UriResource;
 import org.apache.olingo.server.api.uri.UriResourceFunction;
+import org.apache.olingo.server.api.uri.UriResourceLambdaAny;
+import org.apache.olingo.server.api.uri.UriResourceLambdaVariable;
 import org.apache.olingo.server.api.uri.UriResourceProperty;
+import org.apache.olingo.server.api.uri.queryoption.expression.Binary;
 import 
org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind;
 import org.apache.olingo.server.api.uri.queryoption.expression.Expression;
 import 
org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException;
@@ -46,6 +53,7 @@ import 
org.apache.olingo.server.api.uri.queryoption.expression.Literal;
 import org.apache.olingo.server.api.uri.queryoption.expression.Member;
 import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind;
 import 
org.apache.olingo.server.api.uri.queryoption.expression.UnaryOperatorKind;
+import org.apache.olingo.server.core.uri.UriResourceLambdaVarImpl;
 import org.apache.olingo.server.tecsvc.data.DataProvider;
 import 
org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operand.TypedOperand;
 import 
org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operand.UntypedOperand;
@@ -56,9 +64,10 @@ import 
org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operati
 
 public class ExpressionVisitorImpl implements 
ExpressionVisitor<VisitorOperand> {
 
-  private final Entity entity;
+  private Entity entity;
   private final UriInfoResource uriInfo;
   private final Edm edm;
+  private ComplexValue complexValue;
 
   public ExpressionVisitorImpl(final Entity entity, final UriInfoResource 
uriInfo, final Edm edm) {
     this.entity = entity;
@@ -66,6 +75,12 @@ public class ExpressionVisitorImpl implements 
ExpressionVisitor<VisitorOperand>
     this.edm = edm;
   }
 
+  public ExpressionVisitorImpl(final ComplexValue complexValue, final 
UriInfoResource uriInfo, final Edm edm) {
+    this.complexValue = complexValue;
+    this.uriInfo = uriInfo;
+    this.edm = edm;
+  }
+
   @Override
   public VisitorOperand visitBinaryOperator(final BinaryOperatorKind operator, 
final VisitorOperand left,
       final VisitorOperand right) throws ExpressionVisitException, 
ODataApplicationException {
@@ -184,6 +199,7 @@ public class ExpressionVisitorImpl implements 
ExpressionVisitor<VisitorOperand>
     return new UntypedOperand(literal.getText());
   }
 
+  @SuppressWarnings("unchecked")
   @Override
   public VisitorOperand visitMember(final Member member) throws 
ExpressionVisitException,
       ODataApplicationException {
@@ -197,18 +213,39 @@ public class ExpressionVisitorImpl implements 
ExpressionVisitor<VisitorOperand>
       Property currentProperty = 
entity.getProperty(currentEdmProperty.getName());
       for (int i = 1; i < uriResourceParts.size(); i++) {
         if (currentProperty.isComplex()) {
-          currentEdmProperty = ((UriResourceProperty) 
uriResourceParts.get(i)).getProperty();
-          final List<Property> complex = 
currentProperty.asComplex().getValue();
-          for (final Property innerProperty : complex) {
-            if (innerProperty.getName().equals(currentEdmProperty.getName())) {
-              currentProperty = innerProperty;
-              break;
+          if (uriResourceParts.get(i) instanceof UriResourceLambdaAny) {
+            UriResourceLambdaAny any = ((UriResourceLambdaAny) 
uriResourceParts.get(i));
+            if (any.getExpression() instanceof Binary) {
+              Binary expression = (Binary) any.getExpression();
+              if (currentProperty.isCollection()) {
+                final List<ComplexValue> complex = (List<ComplexValue>) 
currentProperty.asCollection();
+                Iterator<ComplexValue> itr = complex.iterator();
+                while (itr.hasNext()) {
+                  final ComplexValue value = itr.next();
+                  VisitorOperand operand = expression.accept(new 
ExpressionVisitorImpl(value, uriInfo, edm));
+                  final TypedOperand typedOperand = operand.asTypedOperand();
+                  if 
(typedOperand.is(OData.newInstance().createPrimitiveTypeInstance
+                      (EdmPrimitiveTypeKind.Boolean))) {
+                    if 
(Boolean.TRUE.equals(typedOperand.getTypedValue(Boolean.class))) {
+                      return operand;
+                    }
+                  }
+                }
+              } 
+            }
+          } else {
+            currentEdmProperty = ((UriResourceProperty) 
uriResourceParts.get(i)).getProperty();
+            final List<Property> complex = 
currentProperty.asComplex().getValue();
+            for (final Property innerProperty : complex) {
+              if 
(innerProperty.getName().equals(currentEdmProperty.getName())) {
+                currentProperty = innerProperty;
+                break;
+              }
             }
           }
         }
       }
       return new TypedOperand(currentProperty.getValue(), 
currentEdmProperty.getType(), currentEdmProperty);
-
     } else if (initialPart instanceof UriResourceFunction) {
       final EdmFunction function = ((UriResourceFunction) 
initialPart).getFunction();
       if (uriResourceParts.size() > 1) {
@@ -225,6 +262,20 @@ public class ExpressionVisitorImpl implements 
ExpressionVisitor<VisitorOperand>
             dataProvider.readFunctionPrimitiveComplex(function, parameters, 
uriInfo),
         type);
 
+    } else if (initialPart instanceof UriResourceLambdaVariable) {
+      EdmComplexType complexType = (EdmComplexType) 
((UriResourceLambdaVarImpl)initialPart).getTypeFilter();
+      EdmProperty currentEdmProperty = ((UriResourceProperty) 
uriResourceParts.get(1)).getProperty();
+      Property currentProperty = null;
+      List<Property> properties = complexValue.getValue();
+      for (final Property innerProperty : properties) {
+        if (innerProperty.getName().equals(currentEdmProperty.getName()) && 
+            complexType.getProperty(innerProperty.getName()) != null) {
+          currentProperty = innerProperty;
+          break;
+        }
+      }
+      return new TypedOperand(currentProperty == null ? null : 
currentProperty.getValue(), 
+          currentEdmProperty.getType(), currentEdmProperty);
     } else {
       return throwNotImplemented();
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f6dd0dea/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --git 
a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
 
b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index 90cd593..ef7880e 100644
--- 
a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ 
b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -626,7 +626,8 @@ public class ODataJsonSerializerTest {
         + "\"CollPropertyComp\":["
         + "{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"},"
         + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
-        + "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}";
+        + 
"{\"@odata.type\":\"#olingo.odata.test1.CTBase\",\"PropertyInt16\":789,"
+        + "\"PropertyString\":\"TEST 3\",\"AdditionalPropString\":\"ADD 
TEST\"}]}";
     Assert.assertEquals(expectedResult, resultString);
   }
   
@@ -1574,7 +1575,9 @@ public class ODataJsonSerializerTest {
         + "\"NavPropertyETAllPrimMany\":["
         + "{\"@odata.id\":\"ESAllPrim(-32768)\",\"PropertyInt32\":-2147483648,"
         + "\"NavPropertyETTwoPrimOne\":null,\"NavPropertyETTwoPrimMany\":[]},"
-        + 
"{\"@odata.id\":\"ESAllPrim(0)\",\"PropertyInt32\":0,\"NavPropertyETTwoPrimOne\":null,"
+        + 
"{\"@odata.id\":\"ESAllPrim(0)\",\"PropertyInt32\":0,\"NavPropertyETTwoPrimOne\":{"
+        + 
"\"@odata.type\":\"#olingo.odata.test1.ETBase\",\"PropertyInt16\":111,"
+        + "\"PropertyString\":\"TEST A\",\"AdditionalPropertyString_5\":\"TEST 
A 0815\"},"
         + "\"NavPropertyETTwoPrimMany\":["
         + "{\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"},"
         + "{\"PropertyInt16\":-32766,\"PropertyString\":null},"
@@ -1621,7 +1624,9 @@ public class ODataJsonSerializerTest {
         + 
"\"PropertyDouble\":0.0,\"PropertyDecimal\":0,\"PropertyBinary\":\"\","
         + 
"\"PropertyDate\":\"1970-01-01\",\"PropertyDateTimeOffset\":\"2005-12-03T00:00:00Z\","
         + 
"\"PropertyDuration\":\"PT0S\",\"PropertyGuid\":\"76543201-23ab-cdef-0123-456789cccddd\","
-        + 
"\"PropertyTimeOfDay\":\"00:01:01\",\"NavPropertyETTwoPrimOne\":null,"
+        + "\"PropertyTimeOfDay\":\"00:01:01\",\"NavPropertyETTwoPrimOne\":{"
+        + 
"\"@odata.type\":\"#olingo.odata.test1.ETBase\",\"PropertyInt16\":111,"
+        + "\"PropertyString\":\"TEST A\",\"AdditionalPropertyString_5\":\"TEST 
A 0815\"},"
         + "\"NavPropertyETTwoPrimMany\":["
         + "{\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"},"
         + "{\"PropertyInt16\":-32766,\"PropertyString\":null},"
@@ -1811,7 +1816,8 @@ public class ODataJsonSerializerTest {
         + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
         + "\"value\":[{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"},"
         + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
-        + "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}",
+        + 
"{\"@odata.type\":\"#olingo.odata.test1.CTBase\",\"PropertyInt16\":789,"
+        + "\"PropertyString\":\"TEST 3\",\"AdditionalPropString\":\"ADD 
TEST\"}]}",
         resultString);
   }
 
@@ -1824,7 +1830,7 @@ public class ODataJsonSerializerTest {
         .complexCollection(metadata, (EdmComplexType) edmProperty.getType(), 
property, null).getContent());
     
Assert.assertEquals("{\"value\":[{\"PropertyInt16\":123,\"PropertyString\":\"TEST
 1\"},"
         + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
-        + "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}",
+        + "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 
3\",\"AdditionalPropString\":\"ADD TEST\"}]}",
         resultString);
   }
 
@@ -1850,9 +1856,9 @@ public class ODataJsonSerializerTest {
         + "{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\","
         + "\"propertyin...@odata.type\":\"#Int16\",\"PropertyInt16\":456,"
         + "\"PropertyString\":\"TEST 2\"},"
-        + "{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\","
+        + "{\"@odata.type\":\"#olingo.odata.test1.CTBase\","
         + "\"propertyin...@odata.type\":\"#Int16\",\"PropertyInt16\":789,"
-        + "\"PropertyString\":\"TEST 3\"}]}";
+        + "\"PropertyString\":\"TEST 3\",\"AdditionalPropString\":\"ADD 
TEST\"}]}";
     Assert.assertEquals(expectedResult, resultString);
   }
   

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f6dd0dea/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
----------------------------------------------------------------------
diff --git 
a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
 
b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
index 166f402..9097d72 100644
--- 
a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
+++ 
b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
@@ -288,8 +288,8 @@ public class ODataXmlSerializerTest {
         "      </a:author>\n" + 
         "      <a:link rel=\"edit\" href=\"ESAllPrim(0)\" />\n" + 
         "      <a:link 
rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETTwoPrimOne\"; "
-        + "type=\"application/atom+xml;type=feed\" 
title=\"NavPropertyETTwoPrimOne\" "
-        + "href=\"ESAllPrim(0)/NavPropertyETTwoPrimOne\" />\n" + 
+        + "type=\"application/atom+xml;type=entry\" 
title=\"NavPropertyETTwoPrimOne\" "
+        + "href=\"ESBase(111)\" />\n" + 
         "      <a:link 
rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETTwoPrimMany\"; "
         + "type=\"application/atom+xml;type=feed\" 
title=\"NavPropertyETTwoPrimMany\" "
         + "href=\"ESAllPrim(0)/NavPropertyETTwoPrimMany\" />\n" + 
@@ -670,9 +670,10 @@ public class ODataXmlSerializerTest {
         "            <d:PropertyInt16 
m:type=\"Int16\">456</d:PropertyInt16>\n" +
         "            <d:PropertyString>TEST 2</d:PropertyString>\n" +
         "          </m:element>\n" +
-        "          <m:element>\n" +
+        "          <m:element m:type=\"olingo.odata.test1.CTBase\">\n" +
         "            <d:PropertyInt16 
m:type=\"Int16\">789</d:PropertyInt16>\n" +
         "            <d:PropertyString>TEST 3</d:PropertyString>\n" +
+        "            <d:AdditionalPropString>ADD 
TEST</d:AdditionalPropString>\n" +
         "          </m:element>\n" +
         "        </d:CollPropertyComp>\n" +
         "    </m:properties>\n" +
@@ -2321,15 +2322,42 @@ public class ODataXmlSerializerTest {
         "          <a:link rel=\"edit\" href=\"ESAllPrim(0)\" />\n" +
         "         <a:link\n" +
         "            
rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETTwoPrimOne\"\n"; +
-        "            type=\"application/atom+xml;type=feed\" 
title=\"NavPropertyETTwoPrimOne\"\n" +
-        "            href=\"ESAllPrim(0)/NavPropertyETTwoPrimOne\">\n" +
-        "            <m:inline />\n" +
+        "            type=\"application/atom+xml;type=entry\" 
title=\"NavPropertyETTwoPrimOne\"\n" +
+        "            href=\"ESBase(111)\">\n" +
+        "           <m:inline>\n "+
+        "           <a:entry>\n "+
+        "           <a:id>ESBase(111)</a:id>\n "+
+        "           <a:title/>\n "+
+        "           <a:summary/>\n "+
+        "                  <a:updated>" + UPDATED_FORMAT.format(new 
Date(currentTimeMillis))
+        + "</a:updated>" +
+        "           <a:author>\n "+
+        "             <a:name/>\n "+
+        "           </a:author>\n "+
+        "           <a:link rel=\"edit\" href=\"ESBase(111)\"/>\n "+
+        "           <a:link 
rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETAllPrimOne\"; "
+        + "type=\"application/atom+xml;type=feed\" 
title=\"NavPropertyETAllPrimOne\" "
+        + "href=\"ESBase(111)/NavPropertyETAllPrimOne\"/>\n "+
+        "           <a:link 
rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETAllPrimMany\"; "
+        + "type=\"application/atom+xml;type=feed\" 
title=\"NavPropertyETAllPrimMany\" "
+        + "href=\"ESBase(111)/NavPropertyETAllPrimMany\"/>\n "+
+        "           <a:category 
scheme=\"http://docs.oasis-open.org/odata/ns/scheme\"; "
+        + "term=\"#olingo.odata.test1.ETBase\"/>\n "+
+        "           <a:content type=\"application/xml\">\n "+
+        "             <m:properties>\n "+
+        "               <d:PropertyInt16 
m:type=\"Int16\">111</d:PropertyInt16>\n "+
+        "               <d:PropertyString>TEST A</d:PropertyString>\n "+
+        "               <d:AdditionalPropertyString_5>TEST A 
0815</d:AdditionalPropertyString_5>\n "+
+        "             </m:properties>\n "+
+        "           </a:content>\n "+
+        "           </a:entry>\n "+
+        "           </m:inline>\n "+
         "          </a:link>" +
         "          <a:link\n" +
         "            
rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETTwoPrimMany\"\n"; 
+
         "            type=\"application/atom+xml;type=feed\" 
title=\"NavPropertyETTwoPrimMany\"\n" +
         "            href=\"ESAllPrim(0)/NavPropertyETTwoPrimMany\">\n" +
-        "            <m:inline>\n" +
+        "            <m:inline>\n "+
         "              <a:feed>\n" +
         "                <a:entry>\n" +
         "                  <a:id>ESTwoPrim(32766)</a:id>\n" +
@@ -2630,9 +2658,10 @@ public class ODataXmlSerializerTest {
         "    <d:PropertyInt16 m:type=\"Int16\">456</d:PropertyInt16>\n" +
         "    <d:PropertyString>TEST 2</d:PropertyString>\n" +
         "  </m:element>\n" +
-        "  <m:element>\n" +
+        "  <m:element m:type=\"olingo.odata.test1.CTBase\">\n" +
         "    <d:PropertyInt16 m:type=\"Int16\">789</d:PropertyInt16>\n" +
         "    <d:PropertyString>TEST 3</d:PropertyString>\n" +
+        "    <d:AdditionalPropString>ADD TEST</d:AdditionalPropString>\n" +
         "  </m:element>\n" +
         "</m:value>";
     checkXMLEqual(expected, resultString);

Reply via email to