Repository: olingo-odata4 Updated Branches: refs/heads/master ae165feed -> 65166b411
[OLINGO-553] Fixed dispatching for FunctionImport Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/65166b41 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/65166b41 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/65166b41 Branch: refs/heads/master Commit: 65166b4112752055b9a0b024d67cb77a36241f82 Parents: ae165fe Author: Michael Bolz <[email protected]> Authored: Tue Mar 10 14:21:17 2015 +0100 Committer: Michael Bolz <[email protected]> Committed: Tue Mar 10 14:21:17 2015 +0100 ---------------------------------------------------------------------- .../fit/tecsvc/client/FunctionImportITCase.java | 43 ++++++++++++++++++++ .../apache/olingo/server/core/ODataHandler.java | 18 ++++---- 2 files changed, 54 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/65166b41/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FunctionImportITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FunctionImportITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FunctionImportITCase.java index b2d5738..2e51fd2 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FunctionImportITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FunctionImportITCase.java @@ -91,6 +91,49 @@ public class FunctionImportITCase extends AbstractBaseTestITCase { @Test + public void entityCollectionWithAppendedKey() { + // .../odata.svc/FICRTCollESMedia()(1) + final ODataInvokeRequest<ODataEntity> request = getClient().getInvokeRequestFactory() + .getFunctionInvokeRequest(getClient().newURIBuilder(TecSvcConst.BASE_URI) + .appendOperationCallSegment("FICRTCollESMedia") + .appendKeySegment(getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(1)) + .build(), ODataEntity.class); + assertNotNull(request); + + final ODataInvokeResponse<ODataEntity> response = request.execute(); + assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode()); + + final ODataEntity entity = response.getBody(); + assertNotNull(entity); + final ODataProperty property = entity.getProperty("PropertyInt16"); + assertNotNull(property); + assertNotNull(property.getPrimitiveValue()); + assertEquals(1, property.getPrimitiveValue().toValue()); + } + + + @Test + public void entityCollectionWithAppendedKeyAndProperty() { + // .../odata.svc/FICRTCollESMedia()(2)/PropertyInt16 + final ODataInvokeRequest<ODataProperty> request = getClient().getInvokeRequestFactory() + .getFunctionInvokeRequest(getClient().newURIBuilder(TecSvcConst.BASE_URI) + .appendOperationCallSegment("FICRTCollESMedia") + .appendKeySegment(getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(2)) + .appendPropertySegment("PropertyInt16") + .build(), ODataProperty.class); + assertNotNull(request); + + final ODataInvokeResponse<ODataProperty> response = request.execute(); + assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode()); + + final ODataProperty property = response.getBody(); + assertNotNull(property); + assertNotNull(property.getPrimitiveValue()); + assertEquals(2, property.getPrimitiveValue().toValue()); + } + + + @Test public void countEntityCollection() throws Exception { final ODataRawRequest request = getClient().getRetrieveRequestFactory() .getRawRequest(getClient().newURIBuilder(TecSvcConst.BASE_URI) http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/65166b41/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java index 282b482..bafc231 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java @@ -299,8 +299,12 @@ public class ODataHandler { throw new ODataHandlerException("No unbound function defined for function import", ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED); } - EdmReturnType returnType = unboundFunctions.get(0).getReturnType(); - handleOperationDispatching(request, response, false, returnType); + if(uriResourceFunction.getKeyPredicates().isEmpty()) { + EdmReturnType returnType = unboundFunctions.get(0).getReturnType(); + handleOperationDispatching(request, response, false, returnType); + } else { + handleEntityDispatching(request, response, false, false, false); + } } private void handleActionDispatching(final ODataRequest request, final ODataResponse response, @@ -331,19 +335,19 @@ public class ODataHandler { } private void handleOperationDispatching(final ODataRequest request, final ODataResponse response, - final boolean isAction, final EdmReturnType edmReturnTypeKind) + final boolean isAction, final EdmReturnType edmReturnType) throws ODataHandlerException, SerializerException, ContentNegotiatorException, ODataApplicationException, DeserializerException { - switch (edmReturnTypeKind.getType().getKind()) { + switch (edmReturnType.getType().getKind()) { case ENTITY: - handleEntityDispatching(request, response, edmReturnTypeKind.isCollection(), false, isAction); + handleEntityDispatching(request, response, edmReturnType.isCollection(), false, isAction); break; case PRIMITIVE: - handlePrimitivePropertyDispatching(request, response, isAction, edmReturnTypeKind.isCollection()); + handlePrimitivePropertyDispatching(request, response, isAction, edmReturnType.isCollection()); break; case COMPLEX: - handleComplexPropertyDispatching(request, response, isAction, edmReturnTypeKind.isCollection()); + handleComplexPropertyDispatching(request, response, isAction, edmReturnType.isCollection()); break; default: throw new ODataHandlerException("not implemented",
