[OLINGO-1497]Select option on Function Import returning collection of entities
diff --git a/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/uri/UriParserTest.java b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/uri/UriParserTest.java
index c654e62..a61420b 100644
--- a/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/uri/UriParserTest.java
+++ b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/uri/UriParserTest.java
@@ -657,6 +657,13 @@
result = parse("OldestEmployee");
assertEquals("OldestEmployee", result.getFunctionImport().getName());
assertEquals(UriType.URI10, result.getUriType());
+
+ result = parse("EmployeeSearch?$filter=EmployeeId%20eq%20%271%27&$select=EmployeeName");
+ assertEquals("Employee", result.getFunctionImport().getReturnType().getType().getName());
+ assertEquals(EdmMultiplicity.MANY, result.getFunctionImport().getReturnType().getMultiplicity());
+ assertEquals(UriType.URI10a, result.getUriType());
+ assertNotNull(result.getFilter());
+ assertEquals(1, result.getSelect().size());
}
@Test
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java
index 1d28fae..881e97b 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java
@@ -221,6 +221,37 @@
}
}
+ private void handleFunctionImportCollection(
+ final EdmEntitySet entitySet, final String keyPredicate) throws UriSyntaxException,
+ UriNotMatchingException, EdmException {
+ final EdmEntityType entityType = entitySet.getEntityType();
+
+ uriResult.setTargetType(entityType);
+ uriResult.setTargetEntitySet(entitySet);
+
+ if (keyPredicate == null) {
+ if (pathSegments.isEmpty()) {
+ uriResult.setUriType(UriType.URI10a);
+ } else {
+ currentPathSegment = pathSegments.remove(0);
+ checkCount();
+ if (uriResult.isCount()) {
+ uriResult.setUriType(UriType.URI15);
+ } else {
+ throw new UriSyntaxException(
+ UriSyntaxException.ENTITYSETINSTEADOFENTITY.addContent(entitySet.getName()));
+ }
+ }
+ } else {
+ uriResult.setKeyPredicates(parseKey(keyPredicate, entityType));
+ if (pathSegments.isEmpty()) {
+ uriResult.setUriType(UriType.URI2);
+ } else {
+ handleNavigationPathOptions();
+ }
+ }
+ }
+
private void handleEntitySet(final EdmEntitySet entitySet, final String keyPredicate) throws UriSyntaxException,
UriNotMatchingException, EdmException {
final EdmEntityType entityType = entitySet.getEntityType();
@@ -551,6 +582,11 @@
final EdmType type = returnType.getType();
final boolean isCollection = returnType.getMultiplicity() == EdmMultiplicity.MANY;
+ if (type.getKind() == EdmTypeKind.ENTITY && isCollection) {
+ handleFunctionImportCollection(functionImport.getEntitySet(), keyPredicate);
+ return;
+ }
+
if (emptyParentheses != null) {
throw new UriSyntaxException(UriSyntaxException.INVALIDSEGMENT.addContent(emptyParentheses));
}
@@ -564,7 +600,7 @@
uriResult.setUriType(isCollection ? UriType.URI11 : UriType.URI12);
break;
case ENTITY:
- uriResult.setUriType(isCollection ? UriType.URI10a : UriType.URI10);
+ uriResult.setUriType(UriType.URI10);
break;
default:
throw new UriSyntaxException(UriSyntaxException.INVALIDRETURNTYPE.addContent(type.getKind()));