[OLINGO-507] Changes and test for FunctionImports support
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/186d6724 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/186d6724 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/186d6724 Branch: refs/heads/master Commit: 186d67241da3501fe3577eca3ac42d025a48ff5a Parents: b441a52 Author: Michael Bolz <[email protected]> Authored: Mon Jan 12 10:15:06 2015 +0100 Committer: Michael Bolz <[email protected]> Committed: Mon Jan 12 10:15:06 2015 +0100 ---------------------------------------------------------------------- .../apache/olingo/server/core/ODataHandler.java | 54 +++++++++++--------- .../olingo/server/core/ODataHandlerTest.java | 37 +++++++++++--- .../server/sample/processor/CarsProcessor.java | 18 +++++++ 3 files changed, 77 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/186d6724/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 89f6d63..dc78647 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 @@ -273,8 +273,8 @@ public class ODataHandler { } } - private void handleFunctionDispatching(ODataRequest request, ODataResponse response, - UriResourceFunction uriResourceFunction) + private void handleFunctionDispatching(final ODataRequest request, final ODataResponse response, + final UriResourceFunction uriResourceFunction) throws ODataHandlerException, SerializerException, ContentNegotiatorException, ODataApplicationException, DeserializerException { final HttpMethod method = request.getMethod(); @@ -286,10 +286,9 @@ public class ODataHandler { EdmFunctionImport functionImport = uriResourceFunction.getFunctionImport(); // could be null for bound functions if(functionImport == null) { - throw new ODataHandlerException("not implemented", + throw new ODataHandlerException("Bound functions are not implemented yet", ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED); } - // List<EdmFunction> unboundFunctions = functionImport.getUnboundFunctions(); if(unboundFunctions == null || unboundFunctions.isEmpty()) { @@ -297,11 +296,11 @@ public class ODataHandler { ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED); } EdmReturnType returnType = unboundFunctions.get(0).getReturnType(); - handleOperationDispatching(request, response, uriResourceFunction, false, returnType); + handleOperationDispatching(request, response, false, returnType); } - private void handleActionDispatching(ODataRequest request, ODataResponse response, - UriResourceAction uriResourceAction) + private void handleActionDispatching(final ODataRequest request, final ODataResponse response, + final UriResourceAction uriResourceAction) throws ODataHandlerException, SerializerException, ContentNegotiatorException, ODataApplicationException, DeserializerException { @@ -311,37 +310,38 @@ public class ODataHandler { ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString()); } - EdmActionImport functionImport = uriResourceAction.getActionImport(); - // could be null for bound functions - if(functionImport == null) { - throw new ODataHandlerException("not implemented", + EdmActionImport actionImport = uriResourceAction.getActionImport(); + // could be null for bound actions + if(actionImport == null) { + throw new ODataHandlerException("Bound actions are not implemented yet", ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED); } - // - EdmAction unboundFunctions = functionImport.getUnboundAction(); - if(unboundFunctions == null) { + EdmAction unboundActions = actionImport.getUnboundAction(); + if(unboundActions == null) { throw new ODataHandlerException("No unbound function defined for function import", ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED); } - EdmReturnType returnType = unboundFunctions.getReturnType(); - handleOperationDispatching(request, response, uriResourceAction, true, returnType); + EdmReturnType returnType = unboundActions.getReturnType(); + handleOperationDispatching(request, response, true, returnType); } - private void handleOperationDispatching(ODataRequest request, ODataResponse response, - UriResourcePartTyped uriResource, - boolean isAction, EdmReturnType edmReturnTypeKind) + private void handleOperationDispatching(final ODataRequest request, final ODataResponse response, + final boolean isAction, final EdmReturnType edmReturnTypeKind) throws ODataHandlerException, SerializerException, ContentNegotiatorException, ODataApplicationException, DeserializerException { switch (edmReturnTypeKind.getType().getKind()) { case ENTITY: - handleEntityDispatching(request, response, uriResource); + handleEntityDispatching(request, response, edmReturnTypeKind.isCollection(), false); break; case PRIMITIVE: handlePrimitivePropertyDispatching(request, response, isAction, edmReturnTypeKind.isCollection()); break; + case COMPLEX: + handleComplexPropertyDispatching(request, response, isAction, edmReturnTypeKind.isCollection()); + break; default: throw new ODataHandlerException("not implemented", ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED); @@ -349,7 +349,6 @@ public class ODataHandler { } - private void handleReferenceDispatching(final ODataRequest request, final ODataResponse response, final int lastPathSegmentIndex) throws ContentNegotiatorException, ODataApplicationException, SerializerException, ODataHandlerException, @@ -575,9 +574,16 @@ public class ODataHandler { final UriResourcePartTyped uriResourcePart) throws ContentNegotiatorException, ODataApplicationException, SerializerException, ODataHandlerException, DeserializerException { + handleEntityDispatching(request, response, uriResourcePart.isCollection(), isMedia(uriResourcePart)); + } + + private void handleEntityDispatching(final ODataRequest request, final ODataResponse response, + final boolean isCollection, final boolean isMedia) + throws ContentNegotiatorException, ODataApplicationException, SerializerException, ODataHandlerException, + DeserializerException { final HttpMethod method = request.getMethod(); - if (uriResourcePart.isCollection()) { + if (isCollection) { if (method == HttpMethod.GET) { final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, customContentTypeSupport, RepresentationType.COLLECTION_ENTITY); @@ -585,7 +591,7 @@ public class ODataHandler { selectProcessor(EntityCollectionProcessor.class) .readEntityCollection(request, response, uriInfo, requestedContentType); } else if (method == HttpMethod.POST) { - if (isMedia(uriResourcePart)) { + if (isMedia) { final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE)); final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, customContentTypeSupport, RepresentationType.ENTITY); @@ -616,7 +622,7 @@ public class ODataHandler { request, customContentTypeSupport, RepresentationType.ENTITY); selectProcessor(EntityProcessor.class).updateEntity(request, response, uriInfo, requestFormat, responseFormat); } else if (method == HttpMethod.DELETE) { - selectProcessor(isMedia(uriResourcePart) ? MediaEntityProcessor.class : EntityProcessor.class) + selectProcessor(isMedia ? MediaEntityProcessor.class : EntityProcessor.class) .deleteEntity(request, response, uriInfo); } else { throw new ODataHandlerException("HTTP method " + method + " is not allowed.", http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/186d6724/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java index b32af89..03e5213 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java @@ -280,18 +280,39 @@ public class ODataHandlerTest { @Test public void dispatchFunction() throws Exception { - final String uri = "FICRTCollString()"; - final PrimitiveCollectionProcessor processor = mock(PrimitiveCollectionProcessor.class); + EntityProcessor entityProcessor = mock(EntityProcessor.class); + dispatch(HttpMethod.GET, "FICRTETKeyNav()", entityProcessor); + verify(entityProcessor).readEntity( + any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class)); - dispatch(HttpMethod.GET, uri, processor); - verify(processor).readPrimitiveCollection( + EntityCollectionProcessor entityCollectionProcessor = mock(EntityCollectionProcessor.class); + dispatch(HttpMethod.GET, "FICRTESTwoKeyNavParam(ParameterInt16=123)", entityCollectionProcessor); + verify(entityCollectionProcessor).readEntityCollection( any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class)); -// dispatch(HttpMethod.GET, uri, processor); -// verify(processor).readEntity( -// any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class)); + PrimitiveProcessor primitiveProcessor = mock(PrimitiveProcessor.class); + dispatch(HttpMethod.GET, "FICRTString()", primitiveProcessor); + verify(primitiveProcessor).readPrimitive( + any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class)); - dispatchMethodNotAllowed(HttpMethod.POST, uri, processor); + PrimitiveCollectionProcessor primitiveCollectionProcessor = mock(PrimitiveCollectionProcessor.class); + dispatch(HttpMethod.GET, "FICRTCollString()", primitiveCollectionProcessor); + verify(primitiveCollectionProcessor).readPrimitiveCollection( + any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class)); + + ComplexProcessor complexProcessor = mock(ComplexProcessor.class); + dispatch(HttpMethod.GET, "FICRTCTTwoPrim()", complexProcessor); + verify(complexProcessor).readComplex( + any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class)); + + ComplexCollectionProcessor complexCollectionProcessor = mock(ComplexCollectionProcessor.class); + dispatch(HttpMethod.GET, "FICRTCollCTTwoPrim()", complexCollectionProcessor); + verify(complexCollectionProcessor).readComplexCollection( + any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class)); + + dispatchMethodNotAllowed(HttpMethod.POST, "FICRTCollString()", mock(Processor.class)); + dispatchMethodNotAllowed(HttpMethod.PUT, "FICRTCollString()", mock(Processor.class)); + dispatchMethodNotAllowed(HttpMethod.DELETE, "FICRTCollString()", mock(Processor.class)); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/186d6724/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java ---------------------------------------------------------------------- diff --git a/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java b/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java index 3f15483..f3747dc 100644 --- a/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java +++ b/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java @@ -337,6 +337,15 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor } @Override + public void processPrimitive(final ODataRequest request, final ODataResponse response, + final UriInfo uriInfo, final ContentType requestFormat, + final ContentType responseFormat) + throws ODataApplicationException, DeserializerException, SerializerException { + throw new ODataApplicationException("Process Primitive property update is not supported yet.", + HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT); + } + + @Override public void updateComplex(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo, final ContentType requestFormat, final ContentType responseFormat) @@ -346,6 +355,15 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor } @Override + public void processComplex(final ODataRequest request, final ODataResponse response, + final UriInfo uriInfo, final ContentType requestFormat, + final ContentType responseFormat) + throws ODataApplicationException, DeserializerException, SerializerException { + throw new ODataApplicationException("Process Complex property update is not supported yet.", + HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT); + } + + @Override public void deleteComplex(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo) throws ODataApplicationException { throw new ODataApplicationException("Complex property delete is not supported yet.",
