From 65166b4112752055b9a0b024d67cb77a36241f82 Mon Sep 17 00:00:00 2001 From: Michael Bolz Date: Tue, 10 Mar 2015 14:21:17 +0100 Subject: [PATCH] [OLINGO-553] Fixed dispatching for FunctionImport --- .../tecsvc/client/FunctionImportITCase.java | 43 +++++++++++++++++++ .../olingo/server/core/ODataHandler.java | 18 +++++--- 2 files changed, 54 insertions(+), 7 deletions(-) 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 b2d5738c7..2e51fd298 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 @@ -90,6 +90,49 @@ public class FunctionImportITCase extends AbstractBaseTestITCase { } + @Test + public void entityCollectionWithAppendedKey() { + // .../odata.svc/FICRTCollESMedia()(1) + final ODataInvokeRequest request = getClient().getInvokeRequestFactory() + .getFunctionInvokeRequest(getClient().newURIBuilder(TecSvcConst.BASE_URI) + .appendOperationCallSegment("FICRTCollESMedia") + .appendKeySegment(getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(1)) + .build(), ODataEntity.class); + assertNotNull(request); + + final ODataInvokeResponse 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 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 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() 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 282b482d4..bafc2314d 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",