Java Code Examples for org.apache.olingo.odata2.api.edm.EdmProperty#isSimple()

The following examples show how to use org.apache.olingo.odata2.api.edm.EdmProperty#isSimple() . 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 <T> Map<String, Object> getStructuralTypeTypeMap(final T data, final EdmStructuralType type)
    throws ODataException {
  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "getStructuralTypeTypeMap");

  Map<String, Object> typeMap = new HashMap<String, Object>();
  for (final String propertyName : type.getPropertyNames()) {
    final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
    if (property.isSimple()) {
      typeMap.put(propertyName, valueAccess.getPropertyType(data, property));
    } else {
      typeMap.put(propertyName, getStructuralTypeTypeMap(valueAccess.getPropertyValue(data, property),
          (EdmStructuralType) property.getType()));
    }
  }

  context.stopRuntimeMeasurement(timingHandle);

  return typeMap;
}
 
Example 2
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 (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 3
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 4
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 {
  if (data == null) {
    throw new ODataException("Unable to set structural type values to NULL data.");
  }
  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;
        Object complexData = valueAccess.getPropertyValue(data, property);
        if (complexData == null) {
          Class<?> complexClass = valueAccess.getPropertyType(data, property);
          complexData = createInstance(complexClass);
          valueAccess.setPropertyValue(data, property, complexData);
        }
        setStructuralTypeValuesFromMap(complexData,
            (EdmStructuralType) property.getType(), values, merge);
      }
    }
  }

  context.stopRuntimeMeasurement(timingHandle);
}
 
Example 5
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 6
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 7
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 8
Source File: BeanPropertyAccess.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private boolean isBooleanProperty(final EdmProperty property) throws EdmException {
  return property.isSimple()
      && property.getType() == EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance();
}
 
Example 9
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 10
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(uriInfo.getTargetEntitySet(), 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 11
Source File: BeanPropertyAccess.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private boolean isBooleanProperty(final EdmProperty property) throws EdmException {
  return property.isSimple()
      && property.getType() == EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance();
}