@Override public EdmReturnType getReturnType() { return getFunction().getReturnType(); }
@Override public EdmReturnType getReturnType() { return getFunction().getReturnType(); }
@Override public EdmType getType() { return function.getReturnType().getType(); }
@Override public EdmType getType() { return function.getReturnType().getType(); }
@Override public boolean isCollection() { return keyPredicates == null && function.getReturnType().isCollection(); }
@Override public boolean isCollection() { return keyPredicates == null && function.getReturnType().isCollection(); }
@Override public boolean isCollection() { return getFunction().getReturnType().isCollection(); }
@Override public boolean isCollection() { return getFunction().getReturnType().isCollection(); }
@Override @SuppressWarnings("unchecked") public <RES extends ClientInvokeResult> ODataInvokeRequest<RES> getBoundFunctionInvokeRequest( final URI bindingParameterURI, final FullQualifiedName functionName, final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection, final Map<String, ClientValue> parameters) { final EdmFunction function = edmClient.getCachedEdm().getBoundFunction( functionName, bindingParameterTypeName, isBindingParameterCollection, parameters == null ? null : new ArrayList<String>(parameters.keySet())); if (function == null) { throw new IllegalArgumentException("Could not find Function for name " + functionName); } return (ODataInvokeRequest<RES>) getInvokeRequest(HttpMethod.GET, edmClient.newURIBuilder(bindingParameterURI.toASCIIString()). appendOperationCallSegment(function.getFullQualifiedName().toString()).build(), getResultReference(function.getReturnType()), parameters); }
@Override @SuppressWarnings("unchecked") public <RES extends ClientInvokeResult> ODataInvokeRequest<RES> getBoundFunctionInvokeRequest( final URI bindingParameterURI, final FullQualifiedName functionName, final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection, final Map<String, ClientValue> parameters) { final EdmFunction function = edmClient.getCachedEdm().getBoundFunction( functionName, bindingParameterTypeName, isBindingParameterCollection, parameters == null ? null : new ArrayList<String>(parameters.keySet())); if (function == null) { throw new IllegalArgumentException("Could not find Function for name " + functionName); } return (ODataInvokeRequest<RES>) getInvokeRequest(HttpMethod.GET, edmClient.newURIBuilder(bindingParameterURI.toASCIIString()). appendOperationCallSegment(function.getFullQualifiedName().toString()).build(), getResultReference(function.getReturnType()), parameters); }
private EdmTypeKind determineReturnEdmTypeKind(final UriResourcePartTyped operation) { if (operation instanceof UriResourceFunction) return ((UriResourceFunction) operation).getFunction().getReturnType().getType().getKind(); else return ((UriResourceAction) operation).getAction().getReturnType().getType().getKind(); }
@Override @SuppressWarnings("unchecked") public <RES extends ClientInvokeResult> ODataInvokeRequest<RES> getFunctionImportInvokeRequest( final String functionImportName, final Map<String, ClientValue> parameters) { EdmFunctionImport efi = null; for (EdmSchema schema : edmClient.getCachedEdm().getSchemas()) { final EdmEntityContainer container = schema.getEntityContainer(); if (container != null) { efi = container.getFunctionImport(functionImportName); } } if (efi == null) { throw new IllegalArgumentException("Could not find FunctionImport for name " + functionImportName); } final EdmFunction function = edmClient.getCachedEdm(). getUnboundFunction(efi.getFunctionFqn(), parameters == null ? null : new ArrayList<String>(parameters.keySet())); if (function == null) { throw new IllegalArgumentException("Could not find Function " + efi.getFunctionFqn()); } return (ODataInvokeRequest<RES>) getInvokeRequest(HttpMethod.GET, edmClient.newURIBuilder().appendOperationCallSegment(functionImportName).build(), getResultReference(function.getReturnType()), parameters); }
@Override public void retrieveData(final ODataRequest request, final ODataResponse response, final ContentType responseFormat) throws ODataApplicationException, ODataLibraryException { Object result = null; final UriResourceFunction uriResourceFunction = (UriResourceFunction) uriInfo.getUriResourceParts().get(uriInfo.getUriResourceParts().size() - 1); final JPAFunction jpaFunction = sd.getFunction(uriResourceFunction.getFunction()); if (jpaFunction.getFunctionType() == EdmFunctionType.JavaClass) { result = processJavaFunction(uriResourceFunction, (JPAJavaFunction) jpaFunction, em); } else if (jpaFunction.getFunctionType() == EdmFunctionType.UserDefinedFunction) result = processJavaUDF(uriInfo.getUriResourceParts(), (JPADataBaseFunction) jpaFunction); final EdmType returnType = uriResourceFunction.getFunction().getReturnType().getType(); final Annotatable annotatable = convertResult(result, returnType, jpaFunction); serializeResult(returnType, response, responseFormat, annotatable); }
private UriType getUriTypeForFunction(final UriResource lastPathSegment) throws UriValidationException { final UriResourceFunction uriFunction = (UriResourceFunction) lastPathSegment; final boolean isCollection = uriFunction.isCollection(); final EdmTypeKind typeKind = uriFunction.getFunction().getReturnType().getType().getKind(); UriType uriType; switch (typeKind) { case ENTITY: uriType = isCollection ? UriType.entitySet : UriType.entity; break; case PRIMITIVE: case ENUM: case DEFINITION: uriType = isCollection ? UriType.propertyPrimitiveCollection : UriType.propertyPrimitive; break; case COMPLEX: uriType = isCollection ? UriType.propertyComplexCollection : UriType.propertyComplex; break; default: throw new UriValidationException("Unsupported function return type: " + typeKind, UriValidationException.MessageKeys.UNSUPPORTED_FUNCTION_RETURN_TYPE, typeKind.toString()); } return uriType; }
private UriType getUriTypeForFunction(final UriResource lastPathSegment) throws UriValidationException { final UriResourceFunction uriFunction = (UriResourceFunction) lastPathSegment; final boolean isCollection = uriFunction.isCollection(); final EdmTypeKind typeKind = uriFunction.getFunction().getReturnType().getType().getKind(); UriType uriType; switch (typeKind) { case ENTITY: uriType = isCollection ? UriType.entitySet : UriType.entity; break; case PRIMITIVE: case ENUM: case DEFINITION: uriType = isCollection ? UriType.propertyPrimitiveCollection : UriType.propertyPrimitive; break; case COMPLEX: uriType = isCollection ? UriType.propertyComplexCollection : UriType.propertyComplex; break; default: throw new UriValidationException("Unsupported function return type: " + typeKind, UriValidationException.MessageKeys.UNSUPPORTED_FUNCTION_RETURN_TYPE, typeKind.toString()); } return uriType; }
private UriType getUriTypeForValue(final UriResource secondLastPathSegment) throws UriValidationException { UriType uriType; switch (secondLastPathSegment.getKind()) { case primitiveProperty: uriType = UriType.propertyPrimitiveValue; break; case entitySet: case navigationProperty: case singleton: uriType = UriType.mediaStream; break; case function: UriResourceFunction uriFunction = (UriResourceFunction) secondLastPathSegment; final EdmFunction function = uriFunction.getFunction(); uriType = function.getReturnType().getType().getKind() == EdmTypeKind.ENTITY ? UriType.mediaStream : UriType.propertyPrimitiveValue; break; default: throw new UriValidationException( "Unexpected kind in path segment before $value: " + secondLastPathSegment.getKind(), UriValidationException.MessageKeys.UNALLOWED_KIND_BEFORE_VALUE, secondLastPathSegment.toString()); } return uriType; }
private void handleFunctionDispatching(final ODataRequest request, final ODataResponse response, final UriResourceFunction uriResourceFunction) throws ODataApplicationException, ODataLibraryException { EdmFunction function = uriResourceFunction.getFunction(); if (function == null) { function = uriResourceFunction.getFunctionImport().getUnboundFunctions().get(0); } final EdmReturnType returnType = function.getReturnType(); switch (returnType.getType().getKind()) { case ENTITY: handleEntityDispatching(request, response, returnType.isCollection() && uriResourceFunction.getKeyPredicates().isEmpty(), false); break; case PRIMITIVE: handlePrimitiveDispatching(request, response, returnType.isCollection()); break; case COMPLEX: handleComplexDispatching(request, response, returnType.isCollection()); break; default: throw new ODataHandlerException(NOT_IMPLEMENTED_MESSAGE, ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED); } }
private UriType getUriTypeForValue(final UriResource secondLastPathSegment) throws UriValidationException { UriType uriType; switch (secondLastPathSegment.getKind()) { case primitiveProperty: uriType = UriType.propertyPrimitiveValue; break; case entitySet: case navigationProperty: case singleton: uriType = UriType.mediaStream; break; case function: UriResourceFunction uriFunction = (UriResourceFunction) secondLastPathSegment; final EdmFunction function = uriFunction.getFunction(); uriType = function.getReturnType().getType().getKind() == EdmTypeKind.ENTITY ? UriType.mediaStream : UriType.propertyPrimitiveValue; break; default: throw new UriValidationException( "Unexpected kind in path segment before $value: " + secondLastPathSegment.getKind(), UriValidationException.MessageKeys.UNALLOWED_KIND_BEFORE_VALUE, secondLastPathSegment.toString()); } return uriType; }
private void requireMediaResourceInCaseOfEntity(UriResource resource) throws UriParserSemanticException { // If the resource is an entity or navigatio if (resource instanceof UriResourceEntitySet && !((UriResourceEntitySet) resource).getEntityType().hasStream() || resource instanceof UriResourceNavigation && !((EdmEntityType) ((UriResourceNavigation) resource).getType()).hasStream()) { throw new UriParserSemanticException("$value on entity is only allowed on media resources.", UriParserSemanticException.MessageKeys.NOT_A_MEDIA_RESOURCE, resource.getSegmentValue()); } // Functions can also deliver an entity. In this case we have to check if the returned entity is a media resource if (resource instanceof UriResourceFunction) { EdmType returnType = ((UriResourceFunction) resource).getFunction().getReturnType().getType(); //Collection check is above so not needed here if (returnType instanceof EdmEntityType && !((EdmEntityType) returnType).hasStream()) { throw new UriParserSemanticException("$value on returned entity is only allowed on media resources.", UriParserSemanticException.MessageKeys.NOT_A_MEDIA_RESOURCE, resource.getSegmentValue()); } } }
private void requireMediaResourceInCaseOfEntity(UriResource resource) throws UriParserSemanticException { // If the resource is an entity or navigatio if (resource instanceof UriResourceEntitySet && !((UriResourceEntitySet) resource).getEntityType().hasStream() || resource instanceof UriResourceNavigation && !((EdmEntityType) ((UriResourceNavigation) resource).getType()).hasStream()) { throw new UriParserSemanticException("$value on entity is only allowed on media resources.", UriParserSemanticException.MessageKeys.NOT_A_MEDIA_RESOURCE, resource.getSegmentValue()); } // Functions can also deliver an entity. In this case we have to check if the returned entity is a media resource if (resource instanceof UriResourceFunction) { EdmType returnType = ((UriResourceFunction) resource).getFunction().getReturnType().getType(); //Collection check is above so not needed here if (returnType instanceof EdmEntityType && !((EdmEntityType) returnType).hasStream()) { throw new UriParserSemanticException("$value on returned entity is only allowed on media resources.", UriParserSemanticException.MessageKeys.NOT_A_MEDIA_RESOURCE, resource.getSegmentValue()); } } }