Java Code Examples for org.apache.olingo.odata2.api.ep.EntityProvider#writeFunctionImport()

The following examples show how to use org.apache.olingo.odata2.api.ep.EntityProvider#writeFunctionImport() . 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: Processor.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public ODataResponse executeFunctionImport(GetFunctionImportUriInfo uri_info, String content_type)
      throws ODataException
{
   EdmFunctionImport function_import = uri_info.getFunctionImport();
   Map<String, EdmLiteral> params = uri_info.getFunctionImportParameters();
   EntityProviderWriteProperties entry_props =
         EntityProviderWriteProperties.serviceRoot(makeLink()).build();

   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);

   return EntityProvider.writeFunctionImport(content_type, function_import, res, entry_props);
}
 
Example 2
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public ODataResponse executeFunctionImport(final GetFunctionImportUriInfo uriInfo, final String contentType)
    throws ODataException {
  final EdmFunctionImport functionImport = uriInfo.getFunctionImport();
  final EdmType type = functionImport.getReturnType().getType();

  final Object data = dataSource.readData(
      functionImport,
      mapFunctionParameters(uriInfo.getFunctionImportParameters()),
      null);

  if (data == null) {
    throw new ODataNotFoundException(ODataHttpException.COMMON);
  }

  Object value;
  if (type.getKind() == EdmTypeKind.SIMPLE) {
    value = type == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance() ?
        ((BinaryData) data).getData() : data;
  } else if (functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY) {
    List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
    for (final Object typeData : (List<?>) data) {
      values.add(getStructuralTypeValueMap(typeData, (EdmStructuralType) type));
    }
    value = values;
  } else {
    value = getStructuralTypeValueMap(data, (EdmStructuralType) type);
  }

  ODataContext context = getContext();

  final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties
      .serviceRoot(context.getPathInfo().getServiceRoot()).build();

  final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeFunctionImport");

  final ODataResponse response =
      EntityProvider.writeFunctionImport(contentType, functionImport, value, entryProperties);

  context.stopRuntimeMeasurement(timingHandle);

  return ODataResponse.fromResponse(response).build();
}
 
Example 3
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public ODataResponse executeFunctionImport(final GetFunctionImportUriInfo uriInfo, final String contentType)
    throws ODataException {
  final EdmFunctionImport functionImport = uriInfo.getFunctionImport();
  final EdmType type = functionImport.getReturnType().getType();

  final Object data = dataSource.readData(
      functionImport,
      mapFunctionParameters(uriInfo.getFunctionImportParameters()),
      null);

  if (data == null) {
    throw new ODataNotFoundException(ODataHttpException.COMMON);
  }

  Object value;
  if (type.getKind() == EdmTypeKind.SIMPLE) {
    value = type == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance() ?
        ((BinaryData) data).getData() : data;
  } else if (functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY) {
    List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
    for (final Object typeData : (List<?>) data) {
      values.add(getStructuralTypeValueMap(typeData, (EdmStructuralType) type));
    }
    value = values;
  } else {
    value = getStructuralTypeValueMap(data, (EdmStructuralType) type);
  }

  ODataContext context = getContext();

  final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties
      .serviceRoot(context.getPathInfo().getServiceRoot()).build();

  final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeFunctionImport");

  final ODataResponse response =
      EntityProvider.writeFunctionImport(contentType, functionImport, value, entryProperties);

  context.stopRuntimeMeasurement(timingHandle);

  return ODataResponse.fromResponse(response).build();
}