[OLINGO-553] Fixed dispatching for FunctionImport

This commit is contained in:
Michael Bolz 2015-03-10 14:21:17 +01:00
parent ae165feedc
commit 65166b4112
2 changed files with 54 additions and 7 deletions

View File

@ -90,6 +90,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 @Test
public void countEntityCollection() throws Exception { public void countEntityCollection() throws Exception {
final ODataRawRequest request = getClient().getRetrieveRequestFactory() final ODataRawRequest request = getClient().getRetrieveRequestFactory()

View File

@ -299,8 +299,12 @@ public class ODataHandler {
throw new ODataHandlerException("No unbound function defined for function import", throw new ODataHandlerException("No unbound function defined for function import",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED); ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
} }
if(uriResourceFunction.getKeyPredicates().isEmpty()) {
EdmReturnType returnType = unboundFunctions.get(0).getReturnType(); EdmReturnType returnType = unboundFunctions.get(0).getReturnType();
handleOperationDispatching(request, response, false, returnType); handleOperationDispatching(request, response, false, returnType);
} else {
handleEntityDispatching(request, response, false, false, false);
}
} }
private void handleActionDispatching(final ODataRequest request, final ODataResponse response, 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, 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, throws ODataHandlerException, SerializerException, ContentNegotiatorException,
ODataApplicationException, DeserializerException { ODataApplicationException, DeserializerException {
switch (edmReturnTypeKind.getType().getKind()) { switch (edmReturnType.getType().getKind()) {
case ENTITY: case ENTITY:
handleEntityDispatching(request, response, edmReturnTypeKind.isCollection(), false, isAction); handleEntityDispatching(request, response, edmReturnType.isCollection(), false, isAction);
break; break;
case PRIMITIVE: case PRIMITIVE:
handlePrimitivePropertyDispatching(request, response, isAction, edmReturnTypeKind.isCollection()); handlePrimitivePropertyDispatching(request, response, isAction, edmReturnType.isCollection());
break; break;
case COMPLEX: case COMPLEX:
handleComplexPropertyDispatching(request, response, isAction, edmReturnTypeKind.isCollection()); handleComplexPropertyDispatching(request, response, isAction, edmReturnType.isCollection());
break; break;
default: default:
throw new ODataHandlerException("not implemented", throw new ODataHandlerException("not implemented",