This is an automated email from the ASF dual-hosted git repository.
ramyav pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata2.git
The following commit(s) were added to refs/heads/master by this push:
new d0bd01e [OLINGO-1497]Select option on Function Import returning
collection of entities
d0bd01e is described below
commit d0bd01eec1ebb650f0a860345142a7f511a6967e
Author: ramya vasanth <[email protected]>
AuthorDate: Wed Mar 3 15:12:27 2021 +0530
[OLINGO-1497]Select option on Function Import returning collection of
entities
---
.../odata2/client/core/uri/UriParserTest.java | 7 ++++
.../olingo/odata2/core/uri/UriParserImpl.java | 38 +++++++++++++++++++++-
2 files changed, 44 insertions(+), 1 deletion(-)
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 @@ public class UriParserTest {
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 @@ public class UriParserImpl extends UriParser {
}
}
+ 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 @@ public class UriParserImpl extends UriParser {
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 @@ public class UriParserImpl extends UriParser {
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()));