Java Code Examples for org.apache.olingo.odata2.api.processor.ODataContext#stopRuntimeMeasurement()

The following examples show how to use org.apache.olingo.odata2.api.processor.ODataContext#stopRuntimeMeasurement() . 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 vote down vote up
private Map<String, Object> parseLinkUri(final EdmEntitySet targetEntitySet, final String uriString)
    throws EdmException {
  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement("UriParser", "getKeyPredicatesFromEntityLink");

  List<KeyPredicate> key = null;
  try {
    key = UriParser.getKeyPredicatesFromEntityLink(targetEntitySet, uriString,
        context.getPathInfo().getServiceRoot());
  } catch (ODataException e) {
    // We don't understand the link target. This could also be seen as an error.
  }

  context.stopRuntimeMeasurement(timingHandle);

  return key == null ? null : mapKey(key);
}
 
Example 2
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private <T> ODataResponse writeEntry(final EdmEntitySet entitySet, final ExpandSelectTreeNode expandSelectTree,
    final T data, final String contentType) throws ODataException, EntityProviderException {
  final EdmEntityType entityType = entitySet.getEntityType();
  final Map<String, Object> values = getStructuralTypeValueMap(data, entityType);

  ODataContext context = getContext();
  EntityProviderWriteProperties writeProperties = EntityProviderWriteProperties
      .serviceRoot(context.getPathInfo().getServiceRoot())
      .expandSelectTree(expandSelectTree)
      .callbacks(getCallbacks(data, entityType))
      .build();

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

  final ODataResponse response = EntityProvider.writeEntry(contentType, entitySet, values, writeProperties);

  context.stopRuntimeMeasurement(timingHandle);

  return response;
}
 
Example 3
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public ODataResponse updateEntityMedia(final PutMergePatchUriInfo uriInfo, final InputStream content,
    final String requestContentType, final String contentType) throws ODataException {
  final Object data = retrieveData(
      uriInfo.getStartEntitySet(),
      uriInfo.getKeyPredicates(),
      uriInfo.getFunctionImport(),
      mapFunctionParameters(uriInfo.getFunctionImportParameters()),
      uriInfo.getNavigationSegments());

  if (!appliesFilter(data, uriInfo.getFilter())) {
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
  }

  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "readBinary");

  final byte[] value = EntityProvider.readBinary(content);

  context.stopRuntimeMeasurement(timingHandle);

  final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
  dataSource.writeBinaryData(entitySet, data, new BinaryData(value, requestContentType));

  return ODataResponse.newBuilder().eTag(constructETag(entitySet, data)).build();
}
 
Example 4
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private ODataEntry parseEntry(final EdmEntitySet entitySet, final InputStream content,
    final String requestContentType, final EntityProviderReadProperties properties) throws ODataBadRequestException {
  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readEntry");

  ODataEntry entryValues;
  try {
    entryValues = EntityProvider.readEntry(requestContentType, entitySet, content, properties);
  } catch (final EntityProviderException e) {
    throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
  }

  context.stopRuntimeMeasurement(timingHandle);

  return entryValues;
}
 
Example 5
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private <T> void setStructuralTypeValuesFromMap(final T data, final EdmStructuralType type,
    final Map<String, Object> valueMap, final boolean merge) throws ODataException {
  ODataContext context = getContext();
  final int timingHandle =
      context.startRuntimeMeasurement(getClass().getSimpleName(), "setStructuralTypeValuesFromMap");

  for (final String propertyName : type.getPropertyNames()) {
    final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
    if (type instanceof EdmEntityType && ((EdmEntityType) type).getKeyProperties().contains(property)) {
      Object v = valueAccess.getPropertyValue(data, property);
      if (v != null) {
        continue;
      }
    }

    if (!merge || valueMap != null && valueMap.containsKey(propertyName)) {
      final Object value = valueMap == null ? null : valueMap.get(propertyName);
      if (property.isSimple()) {
        valueAccess.setPropertyValue(data, property, value);
      } else {
        @SuppressWarnings("unchecked")
        final Map<String, Object> values = (Map<String, Object>) value;
        setStructuralTypeValuesFromMap(valueAccess.getPropertyValue(data, property),
            (EdmStructuralType) property.getType(), values, merge);
      }
    }
  }

  context.stopRuntimeMeasurement(timingHandle);
}
 
Example 6
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private Object retrieveData(final EdmEntitySet startEntitySet, final List<KeyPredicate> keyPredicates,
    final EdmFunctionImport functionImport, final Map<String, Object> functionImportParameters,
    final List<NavigationSegment> navigationSegments) throws ODataException {
  Object data;
  final Map<String, Object> keys = mapKey(keyPredicates);

  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "retrieveData");

  try {
    data = functionImport == null ?
        keys.isEmpty() ?
            dataSource.readData(startEntitySet) : dataSource.readData(startEntitySet, keys) :
        dataSource.readData(functionImport, functionImportParameters, keys);

    EdmEntitySet currentEntitySet =
        functionImport == null ? startEntitySet : functionImport.getEntitySet();
    for (NavigationSegment navigationSegment : navigationSegments) {
      data = dataSource.readRelatedData(
          currentEntitySet,
          data,
          navigationSegment.getEntitySet(),
          mapKey(navigationSegment.getKeyPredicates()));
      currentEntitySet = navigationSegment.getEntitySet();
    }
  } finally {
    context.stopRuntimeMeasurement(timingHandle);
  }
  return data;
}
 
Example 7
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private <T> Map<String, Object> getStructuralTypeValueMap(final T data, final EdmStructuralType type)
    throws ODataException {
  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "getStructuralTypeValueMap");

  Map<String, Object> valueMap = new HashMap<String, Object>();

  EdmMapping mapping = type.getMapping();
  if (mapping != null) {
    handleMimeType(data, mapping, valueMap);
  }

  for (final String propertyName : type.getPropertyNames()) {
    final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
    final Object value = valueAccess.getPropertyValue(data, property);

    if (property.isSimple()) {
      if (property.getMapping() == null || property.getMapping().getMediaResourceMimeTypeKey() == null) {
        valueMap.put(propertyName, value);
      } else {
        // TODO: enable MIME type mapping outside the current subtree
        valueMap.put(propertyName, getSimpleTypeValueMap(data, Arrays.asList(property)));
      }
    } else {
      valueMap.put(propertyName, getStructuralTypeValueMap(value, (EdmStructuralType) property.getType()));
    }
  }

  context.stopRuntimeMeasurement(timingHandle);

  return valueMap;
}
 
Example 8
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private <T> Map<String, Object> getStructuralTypeValueMap(final T data, final EdmStructuralType type)
    throws ODataException {
  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "getStructuralTypeValueMap");

  Map<String, Object> valueMap = new HashMap<String, Object>();

  EdmMapping mapping = type.getMapping();
  if (mapping != null) {
    handleMimeType(data, mapping, valueMap);
  }

  for (final String propertyName : type.getPropertyNames()) {
    final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
    final Object value = valueAccess.getPropertyValue(data, property);

    if (property.isSimple()) {
      if (property.getMapping() == null || property.getMapping().getMediaResourceMimeTypeKey() == null) {
        valueMap.put(propertyName, value);
      } else {
        // TODO: enable MIME type mapping outside the current subtree
        valueMap.put(propertyName, getSimpleTypeValueMap(data, Arrays.asList(property)));
      }
    } else {
      valueMap.put(propertyName, getStructuralTypeValueMap(value, (EdmStructuralType) property.getType()));
    }
  }

  context.stopRuntimeMeasurement(timingHandle);

  return valueMap;
}
 
Example 9
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private <T> boolean appliesFilter(final EdmEntitySet entitySet, final T data, final FilterExpression filter)
    throws ODataException {
  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "appliesFilter");

  try {
    return data != null
        && (filter == null || evaluateExpression(entitySet, data, filter.getExpression()).equals("true"));
  } catch (final RuntimeException e) {
    return false;
  } finally {
    context.stopRuntimeMeasurement(timingHandle);
  }
}
 
Example 10
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataResponse readEntityComplexProperty(final GetComplexPropertyUriInfo uriInfo, final String contentType)
    throws ODataException {
  Object data = retrieveData(
      uriInfo.getStartEntitySet(),
      uriInfo.getKeyPredicates(),
      uriInfo.getFunctionImport(),
      mapFunctionParameters(uriInfo.getFunctionImportParameters()),
      uriInfo.getNavigationSegments());

  // if (!appliesFilter(data, uriInfo.getFilter()))
  if (data == null) {
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
  }

  final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
  final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
  final Object value = property.isSimple() ?
      property.getMapping() == null || property.getMapping().getMediaResourceMimeTypeKey() == null ?
          getPropertyValue(data, propertyPath) : getSimpleTypeValueMap(data, propertyPath) :
      getStructuralTypeValueMap(getPropertyValue(data, propertyPath), (EdmStructuralType) property.getType());

  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeProperty");

  final ODataResponse response = EntityProvider.writeProperty(contentType, property, value);

  context.stopRuntimeMeasurement(timingHandle);

  return ODataResponse.fromResponse(response).eTag(constructETag(uriInfo.getTargetEntitySet(), data)).build();
}
 
Example 11
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataResponse updateEntitySimplePropertyValue(final PutMergePatchUriInfo uriInfo, final InputStream content,
    final String requestContentType, final String contentType) throws ODataException {
  Object data = retrieveData(
      uriInfo.getStartEntitySet(),
      uriInfo.getKeyPredicates(),
      uriInfo.getFunctionImport(),
      mapFunctionParameters(uriInfo.getFunctionImportParameters()),
      uriInfo.getNavigationSegments());

  if (!appliesFilter(data, uriInfo.getFilter())) {
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
  }

  final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
  final EdmProperty property = propertyPath.get(propertyPath.size() - 1);

  data = getPropertyValue(data, propertyPath.subList(0, propertyPath.size() - 1));

  ODataContext context = getContext();
  int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readPropertyValue");

  Object value;
  try {
    value = EntityProvider.readPropertyValue(property, content);
  } catch (final EntityProviderException e) {
    throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
  }

  context.stopRuntimeMeasurement(timingHandle);

  valueAccess.setPropertyValue(data, property, value);
  valueAccess.setMappingValue(data, property.getMapping(), requestContentType);

  return ODataResponse.newBuilder().eTag(constructETag(uriInfo.getTargetEntitySet(), data)).build();
}
 
Example 12
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private Map<String, Object> parseLink(final EdmEntitySet entitySet, final InputStream content,
    final String contentType) throws ODataException {
  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "readLink");

  final String uriString = EntityProvider.readLink(contentType, entitySet, content);

  context.stopRuntimeMeasurement(timingHandle);

  final Map<String, Object> targetKeys = parseLinkUri(entitySet, uriString);
  if (targetKeys == null) {
    throw new ODataBadRequestException(ODataBadRequestException.BODY);
  }
  return targetKeys;
}
 
Example 13
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataResponse readEntityLink(final GetEntityLinkUriInfo uriInfo, final String contentType)
    throws ODataException {
  final Object data = retrieveData(
      uriInfo.getStartEntitySet(),
      uriInfo.getKeyPredicates(),
      uriInfo.getFunctionImport(),
      mapFunctionParameters(uriInfo.getFunctionImportParameters()),
      uriInfo.getNavigationSegments());

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

  final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();

  Map<String, Object> values = new HashMap<String, Object>();
  for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) {
    values.put(property.getName(), valueAccess.getPropertyValue(data, property));
  }

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

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

  final ODataResponse response = EntityProvider.writeLink(contentType, entitySet, values, entryProperties);

  context.stopRuntimeMeasurement(timingHandle);

  return ODataResponse.fromResponse(response).build();
}
 
Example 14
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private <T> Integer applySystemQueryOptions(final EdmEntitySet entitySet, final List<T> data,
    final FilterExpression filter, final InlineCount inlineCount, final OrderByExpression orderBy,
    final String skipToken, final Integer skip, final Integer top) throws ODataException {
  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "applySystemQueryOptions");

  if (filter != null) {
    // Remove all elements the filter does not apply for.
    // A for-each loop would not work with "remove", see Java documentation.
    for (Iterator<T> iterator = data.iterator(); iterator.hasNext();) {
      if (!appliesFilter(entitySet, iterator.next(), filter)) {
        iterator.remove();
      }
    }
  }

  final Integer count = inlineCount == InlineCount.ALLPAGES ? data.size() : null;

  if (orderBy != null) {
    sort(entitySet, data, orderBy);
  } else if (skipToken != null || skip != null || top != null) {
    sortInDefaultOrder(entitySet, data);
  }

  if (skipToken != null) {
    while (!data.isEmpty() && !getSkipToken(entitySet, data.get(0)).equals(skipToken)) {
      data.remove(0);
    }
  }

  if (skip != null) {
    if (skip >= data.size()) {
      data.clear();
    } else {
      for (int i = 0; i < skip; i++) {
        data.remove(0);
      }
    }
  }

  if (top != null) {
    while (data.size() > top) {
      data.remove(top.intValue());
    }
  }

  context.stopRuntimeMeasurement(timingHandle);

  return count;
}
 
Example 15
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public ODataResponse updateEntityComplexProperty(final PutMergePatchUriInfo uriInfo, final InputStream content,
    final String requestContentType, final boolean merge, final String contentType) throws ODataException {
  Object data = retrieveData(
      uriInfo.getStartEntitySet(),
      uriInfo.getKeyPredicates(),
      uriInfo.getFunctionImport(),
      mapFunctionParameters(uriInfo.getFunctionImportParameters()),
      uriInfo.getNavigationSegments());

  if (!appliesFilter(data, uriInfo.getFilter())) {
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
  }

  final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
  final EdmProperty property = propertyPath.get(propertyPath.size() - 1);

  data = getPropertyValue(data, propertyPath.subList(0, propertyPath.size() - 1));

  ODataContext context = getContext();
  int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readProperty");

  Map<String, Object> values;
  try {
    values =
        EntityProvider.readProperty(requestContentType, property, content, EntityProviderReadProperties.init()
            .mergeSemantic(merge).build());
  } catch (final EntityProviderException e) {
    throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
  }

  context.stopRuntimeMeasurement(timingHandle);

  final Object value = values.get(property.getName());
  if (property.isSimple()) {
    valueAccess.setPropertyValue(data, property, value);
  } else {
    @SuppressWarnings("unchecked")
    final Map<String, Object> propertyValue = (Map<String, Object>) value;
    setStructuralTypeValuesFromMap(valueAccess.getPropertyValue(data, property),
        (EdmStructuralType) property.getType(), propertyValue, merge);
  }

  return ODataResponse.newBuilder().eTag(constructETag(uriInfo.getTargetEntitySet(), data)).build();
}
 
Example 16
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private <T> Integer applySystemQueryOptions(final EdmEntitySet entitySet, final List<T> data,
    final FilterExpression filter, final InlineCount inlineCount, final OrderByExpression orderBy,
    final String skipToken, final Integer skip, final Integer top) throws ODataException {
  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "applySystemQueryOptions");

  if (filter != null) {
    // Remove all elements the filter does not apply for.
    // A for-each loop would not work with "remove", see Java documentation.
    for (Iterator<T> iterator = data.iterator(); iterator.hasNext();) {
      if (!appliesFilter(iterator.next(), filter)) {
        iterator.remove();
      }
    }
  }

  final Integer count = inlineCount == InlineCount.ALLPAGES ? data.size() : null;

  if (orderBy != null) {
    sort(data, orderBy);
  } else if (skipToken != null || skip != null || top != null) {
    sortInDefaultOrder(entitySet, data);
  }

  if (skipToken != null) {
    while (!data.isEmpty() && !getSkipToken(entitySet, data.get(0)).equals(skipToken)) {
      data.remove(0);
    }
  }

  if (skip != null) {
    if (skip >= data.size()) {
      data.clear();
    } else {
      for (int i = 0; i < skip; i++) {
        data.remove(0);
      }
    }
  }

  if (top != null) {
    while (data.size() > top) {
      data.remove(top.intValue());
    }
  }

  context.stopRuntimeMeasurement(timingHandle);

  return count;
}
 
Example 17
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public ODataResponse readEntityLinks(final GetEntitySetLinksUriInfo uriInfo, final String contentType)
    throws ODataException {
  ArrayList<Object> data = new ArrayList<Object>();
  try {
    data.addAll((List<?>) retrieveData(
        uriInfo.getStartEntitySet(),
        uriInfo.getKeyPredicates(),
        uriInfo.getFunctionImport(),
        mapFunctionParameters(uriInfo.getFunctionImportParameters()),
        uriInfo.getNavigationSegments()));
  } catch (final ODataNotFoundException e) {
    data.clear();
  }

  final Integer count = applySystemQueryOptions(
      uriInfo.getTargetEntitySet(),
      data,
      uriInfo.getFilter(),
      uriInfo.getInlineCount(),
      null, // uriInfo.getOrderBy(),
      uriInfo.getSkipToken(),
      uriInfo.getSkip(),
      uriInfo.getTop());

  final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();

  List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
  for (final Object entryData : data) {
    Map<String, Object> entryValues = new HashMap<String, Object>();
    for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) {
      entryValues.put(property.getName(), valueAccess.getPropertyValue(entryData, property));
    }
    values.add(entryValues);
  }

  ODataContext context = getContext();
  final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties
      .serviceRoot(context.getPathInfo().getServiceRoot())
      .inlineCountType(uriInfo.getInlineCount())
      .inlineCount(count)
      .build();

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

  final ODataResponse response = EntityProvider.writeLinks(contentType, entitySet, values, entryProperties);

  context.stopRuntimeMeasurement(timingHandle);

  return ODataResponse.fromResponse(response).build();
}
 
Example 18
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public ODataResponse readEntitySet(final GetEntitySetUriInfo uriInfo, final String contentType)
    throws ODataException {
  ArrayList<Object> data = new ArrayList<Object>();
  try {
    data.addAll((List<?>) retrieveData(
        uriInfo.getStartEntitySet(),
        uriInfo.getKeyPredicates(),
        uriInfo.getFunctionImport(),
        mapFunctionParameters(uriInfo.getFunctionImportParameters()),
        uriInfo.getNavigationSegments()));
  } catch (final ODataNotFoundException e) {
    data.clear();
  }

  final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
  final InlineCount inlineCountType = uriInfo.getInlineCount();
  final Integer count = applySystemQueryOptions(
      entitySet,
      data,
      uriInfo.getFilter(),
      inlineCountType,
      uriInfo.getOrderBy(),
      uriInfo.getSkipToken(),
      uriInfo.getSkip(),
      uriInfo.getTop());

  ODataContext context = getContext();
  String nextLink = null;

  // Limit the number of returned entities and provide a "next" link
  // if there are further entities.
  // Almost all system query options in the current request must be carried
  // over to the URI for the "next" link, with the exception of $skiptoken
  // and $skip.
  if (data.size() > SERVER_PAGING_SIZE) {
    if (uriInfo.getOrderBy() == null
        && uriInfo.getSkipToken() == null
        && uriInfo.getSkip() == null
        && uriInfo.getTop() == null) {
      sortInDefaultOrder(entitySet, data);
    }

    nextLink = context.getPathInfo().getServiceRoot().relativize(context.getPathInfo().getRequestUri()).toString();
    nextLink = percentEncodeNextLink(nextLink);

    nextLink += (nextLink.contains("?") ? "&" : "?")
        + "$skiptoken=" + getSkipToken(entitySet, data.get(SERVER_PAGING_SIZE));

    while (data.size() > SERVER_PAGING_SIZE) {
      data.remove(SERVER_PAGING_SIZE);
    }
  }

  final EdmEntityType entityType = entitySet.getEntityType();
  List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
  for (final Object entryData : data) {
    values.add(getStructuralTypeValueMap(entryData, entityType));
  }

  final EntityProviderWriteProperties feedProperties = EntityProviderWriteProperties
      .serviceRoot(context.getPathInfo().getServiceRoot())
      .inlineCountType(inlineCountType)
      .inlineCount(count)
      .expandSelectTree(UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand()))
      .callbacks(getCallbacks(data, entityType))
      .nextLink(nextLink)
      .build();

  final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeFeed");
  final ODataResponse response = EntityProvider.writeFeed(contentType, entitySet, values, feedProperties);

  context.stopRuntimeMeasurement(timingHandle);

  return ODataResponse.fromResponse(response).build();
}
 
Example 19
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public ODataResponse readEntityLinks(final GetEntitySetLinksUriInfo uriInfo, final String contentType)
    throws ODataException {
  ArrayList<Object> data = new ArrayList<Object>();
  try {
    data.addAll((List<?>) retrieveData(
        uriInfo.getStartEntitySet(),
        uriInfo.getKeyPredicates(),
        uriInfo.getFunctionImport(),
        mapFunctionParameters(uriInfo.getFunctionImportParameters()),
        uriInfo.getNavigationSegments()));
  } catch (final ODataNotFoundException e) {
    data.clear();
  }

  final Integer count = applySystemQueryOptions(
      uriInfo.getTargetEntitySet(),
      data,
      uriInfo.getFilter(),
      uriInfo.getInlineCount(),
      null, // uriInfo.getOrderBy(),
      uriInfo.getSkipToken(),
      uriInfo.getSkip(),
      uriInfo.getTop());

  final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();

  List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
  for (final Object entryData : data) {
    Map<String, Object> entryValues = new HashMap<String, Object>();
    for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) {
      entryValues.put(property.getName(), valueAccess.getPropertyValue(entryData, property));
    }
    values.add(entryValues);
  }

  ODataContext context = getContext();
  final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties
      .serviceRoot(context.getPathInfo().getServiceRoot())
      .inlineCountType(uriInfo.getInlineCount())
      .inlineCount(count)
      .build();

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

  final ODataResponse response = EntityProvider.writeLinks(contentType, entitySet, values, entryProperties);

  context.stopRuntimeMeasurement(timingHandle);

  return ODataResponse.fromResponse(response).build();
}
 
Example 20
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public ODataResponse readEntitySet(final GetEntitySetUriInfo uriInfo, final String contentType)
    throws ODataException {
  ArrayList<Object> data = new ArrayList<Object>();
  try {
    data.addAll((List<?>) retrieveData(
        uriInfo.getStartEntitySet(),
        uriInfo.getKeyPredicates(),
        uriInfo.getFunctionImport(),
        mapFunctionParameters(uriInfo.getFunctionImportParameters()),
        uriInfo.getNavigationSegments()));
  } catch (final ODataNotFoundException e) {
    data.clear();
  }

  final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
  final InlineCount inlineCountType = uriInfo.getInlineCount();
  final Integer count = applySystemQueryOptions(
      entitySet,
      data,
      uriInfo.getFilter(),
      inlineCountType,
      uriInfo.getOrderBy(),
      uriInfo.getSkipToken(),
      uriInfo.getSkip(),
      uriInfo.getTop());

  ODataContext context = getContext();
  String nextLink = null;

  // Limit the number of returned entities and provide a "next" link
  // if there are further entities.
  // Almost all system query options in the current request must be carried
  // over to the URI for the "next" link, with the exception of $skiptoken
  // and $skip.
  if (data.size() > SERVER_PAGING_SIZE) {
    if (uriInfo.getOrderBy() == null
        && uriInfo.getSkipToken() == null
        && uriInfo.getSkip() == null
        && uriInfo.getTop() == null) {
      sortInDefaultOrder(entitySet, data);
    }

    nextLink = context.getPathInfo().getServiceRoot().relativize(context.getPathInfo().getRequestUri()).toString();
    nextLink = percentEncodeNextLink(nextLink);
    nextLink += (nextLink.contains("?") ? "&" : "?")
        + "$skiptoken=" + getSkipToken(entitySet, data.get(SERVER_PAGING_SIZE));

    while (data.size() > SERVER_PAGING_SIZE) {
      data.remove(SERVER_PAGING_SIZE);
    }
  }

  final EdmEntityType entityType = entitySet.getEntityType();
  List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
  for (final Object entryData : data) {
    values.add(getStructuralTypeValueMap(entryData, entityType));
  }

  final EntityProviderWriteProperties feedProperties = EntityProviderWriteProperties
      .serviceRoot(context.getPathInfo().getServiceRoot())
      .inlineCountType(inlineCountType)
      .inlineCount(count)
      .expandSelectTree(UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand()))
      .callbacks(getCallbacks(data, entityType))
      .nextLink(nextLink)
      .build();

  final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeFeed");
  final ODataResponse response = EntityProvider.writeFeed(contentType, entitySet, values, feedProperties);

  context.stopRuntimeMeasurement(timingHandle);

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