Java Code Examples for org.apache.olingo.odata2.api.ep.EntityProvider#writeText()
The following examples show how to use
org.apache.olingo.odata2.api.ep.EntityProvider#writeText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListsProcessor.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Override public ODataResponse executeFunctionImportValue(final GetFunctionImportUriInfo uriInfo, final String contentType) throws ODataException { final EdmFunctionImport functionImport = uriInfo.getFunctionImport(); final EdmSimpleType type = (EdmSimpleType) functionImport.getReturnType().getType(); final Object data = dataSource.readData( functionImport, mapFunctionParameters(uriInfo.getFunctionImportParameters()), null); if (data == null) { throw new ODataNotFoundException(ODataHttpException.COMMON); } ODataResponse response; if (type == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance()) { response = EntityProvider.writeBinary(((BinaryData) data).getMimeType(), ((BinaryData) data).getData()); } else { final String value = type.valueToString(data, EdmLiteralKind.DEFAULT, null); response = EntityProvider.writeText(value == null ? "" : value); } return ODataResponse.fromResponse(response).build(); }
Example 2
Source File: ListsProcessor.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Override public ODataResponse executeFunctionImportValue(final GetFunctionImportUriInfo uriInfo, final String contentType) throws ODataException { final EdmFunctionImport functionImport = uriInfo.getFunctionImport(); final EdmSimpleType type = (EdmSimpleType) functionImport.getReturnType().getType(); final Object data = dataSource.readData( functionImport, mapFunctionParameters(uriInfo.getFunctionImportParameters()), null); if (data == null) { throw new ODataNotFoundException(ODataHttpException.COMMON); } ODataResponse response; if (type == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance()) { response = EntityProvider.writeBinary(((BinaryData) data).getMimeType(), ((BinaryData) data).getData()); } else { final String value = type.valueToString(data, EdmLiteralKind.DEFAULT, null); response = EntityProvider.writeText(value == null ? "" : value); } return ODataResponse.fromResponse(response).build(); }
Example 3
Source File: Processor.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
@Override public ODataResponse executeFunctionImportValue(GetFunctionImportUriInfo uri_info, String content_type) throws ODataException { EdmFunctionImport function_import = uri_info.getFunctionImport(); Map<String, EdmLiteral> params = uri_info.getFunctionImportParameters(); // FIXME: returned type might not be a simple type ... EdmSimpleType type = (EdmSimpleType) function_import.getReturnType().getType(); AbstractOperation op = Model.getServiceOperation(function_import.getName()); fr.gael.dhus.database.object.User current_user = ApplicationContextProvider.getBean(SecurityService.class).getCurrentUser(); if (!op.canExecute(current_user)) { throw new NotAllowedException(); } Object res = op.execute(params); /* To handle binary results (NYI): if (type == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance()) { response = EntityProvider.writeBinary( ((BinaryData) data).getMimeType(), // BinaryData is an meta-object holding the data ((BinaryData) data).getData() // and its mime type ); }//*/ final String value = type.valueToString(res, EdmLiteralKind.DEFAULT, null); return EntityProvider.writeText(value == null ? "" : value); }
Example 4
Source File: ODataJPAResponseBuilderDefault.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Override public ODataResponse build(final long jpaEntityCount) throws ODataJPARuntimeException { ODataResponse odataResponse = null; try { odataResponse = EntityProvider.writeText(String.valueOf(jpaEntityCount)); odataResponse = ODataResponse.fromResponse(odataResponse).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } return odataResponse; }