mirror of
https://github.com/apache/olingo-odata4.git
synced 2025-03-07 00:59:08 +00:00
[OLINGO-507] Changes and test for FunctionImports support
This commit is contained in:
parent
b441a524b6
commit
186d67241d
@ -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.",
|
||||
|
@ -280,18 +280,39 @@ public class ODataHandlerTest {
|
||||
|
||||
@Test
|
||||
public void dispatchFunction() throws Exception {
|
||||
final String uri = "FICRTCollString()";
|
||||
final PrimitiveCollectionProcessor processor = mock(PrimitiveCollectionProcessor.class);
|
||||
|
||||
dispatch(HttpMethod.GET, uri, processor);
|
||||
verify(processor).readPrimitiveCollection(
|
||||
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).readEntity(
|
||||
// any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
||||
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));
|
||||
|
||||
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||
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));
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
|
@ -336,6 +336,15 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
|
||||
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
|
||||
}
|
||||
|
||||
@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,
|
||||
@ -345,6 +354,15 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
|
||||
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
|
||||
}
|
||||
|
||||
@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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user