Java Code Examples for org.apache.olingo.odata2.api.exception.ODataNotFoundException#ENTITY

The following examples show how to use org.apache.olingo.odata2.api.exception.ODataNotFoundException#ENTITY . 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
@Override
public ODataResponse readEntity(final GetEntityUriInfo uriInfo, final String contentType) throws ODataException {
  final Object data = retrieveData(
      uriInfo.getStartEntitySet(),
      uriInfo.getKeyPredicates(),
      uriInfo.getFunctionImport(),
      mapFunctionParameters(uriInfo.getFunctionImportParameters()),
      uriInfo.getNavigationSegments());

  final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
  if (!appliesFilter(entitySet, data, uriInfo.getFilter())) {
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
  }

  final ExpandSelectTreeNode expandSelectTreeNode =
      UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand());

  return ODataResponse.fromResponse(writeEntry(entitySet, expandSelectTreeNode, data, contentType))
      .build();
}
 
Example 2
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public ODataResponse readEntity(final GetEntityUriInfo uriInfo, 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);
  }

  final ExpandSelectTreeNode expandSelectTreeNode =
      UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand());
  ODataResponse odr =
      ODataResponse.fromResponse(writeEntry(uriInfo.getTargetEntitySet(), expandSelectTreeNode, data, contentType))
          .build();

  return odr;
}
 
Example 3
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public ODataResponse updateEntity(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 EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
  final EdmEntityType entityType = entitySet.getEntityType();
  final EntityProviderReadProperties properties = EntityProviderReadProperties.init()
      .mergeSemantic(merge)
      .addTypeMappings(getStructuralTypeTypeMap(data, entityType))
      .build();
  final ODataEntry entryValues = parseEntry(entitySet, content, requestContentType, properties);

  setStructuralTypeValuesFromMap(data, entityType, entryValues.getProperties(), merge);

  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
@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 5
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public ODataResponse deleteEntityMedia(final DeleteUriInfo 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);
  }

  dataSource.writeBinaryData(uriInfo.getTargetEntitySet(), data, new BinaryData(null, null));

  return ODataResponse.newBuilder().build();
}
 
Example 6
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public ODataResponse updateEntity(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());

  final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
  if (!appliesFilter(entitySet, data, uriInfo.getFilter())) {
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
  }

  final EdmEntityType entityType = entitySet.getEntityType();
  final EntityProviderReadProperties properties = EntityProviderReadProperties.init()
      .mergeSemantic(merge)
      .addTypeMappings(getStructuralTypeTypeMap(data, entityType))
      .build();
  final ODataEntry entryValues = parseEntry(entitySet, content, requestContentType, properties);

  setStructuralTypeValuesFromMap(data, entityType, entryValues.getProperties(), merge);

  return ODataResponse.newBuilder().eTag(constructETag(entitySet, data)).build();
}
 
Example 7
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public ODataResponse deleteEntityMedia(final DeleteUriInfo 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);
  }

  dataSource.writeBinaryData(uriInfo.getTargetEntitySet(), data, new BinaryData(null, null));

  return ODataResponse.newBuilder().build();
}
 
Example 8
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 9
Source File: ODataExceptionMapperImplTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testWrappedODataNotFoundException() throws Exception {
  // prepare
  Exception causeException = new ODataNotFoundException(ODataNotFoundException.ENTITY);
  String exceptionMessage = "Some odd exception";
  Exception exception = new ODataException(exceptionMessage, causeException);

  // execute
  Response response = exceptionMapper.toResponse(exception);

  // verify
  verifyResponse(response, MessageService.getMessage(Locale.ENGLISH, ODataNotFoundException.ENTITY).getText(),
      HttpStatusCodes.NOT_FOUND);
}
 
Example 10
Source File: ODataJPAResponseBuilderDefault.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataResponse build(final DeleteUriInfo deleteUriInfo, final Object deletedObject)
    throws ODataJPARuntimeException, ODataNotFoundException {

  if (deletedObject == null) {
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
  }
  return ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
}
 
Example 11
Source File: CarODataSingleProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataResponse readEntitySet(final GetEntitySetUriInfo uriInfo, final String contentType) 
    throws ODataException {

  EdmEntitySet entitySet;

  if (uriInfo.getNavigationSegments().size() == 0) {
    entitySet = uriInfo.getStartEntitySet();

    if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
      return EntityProvider.writeFeed(contentType, entitySet, dataStore.getCars(),
          EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
    } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
      return EntityProvider.writeFeed(contentType, entitySet, dataStore.getManufacturers(),
          EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
    }

    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);

  } else if (uriInfo.getNavigationSegments().size() == 1) {
    // navigation first level, simplified example for illustration purposes only
    entitySet = uriInfo.getTargetEntitySet();

    if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
      int manufacturerKey = getKeyValue(uriInfo.getKeyPredicates().get(0));

      List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
      cars.addAll(dataStore.getCarsFor(manufacturerKey));

      return EntityProvider.writeFeed(contentType, entitySet, cars, EntityProviderWriteProperties.serviceRoot(
          getContext().getPathInfo().getServiceRoot()).build());
    }

    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
  }

  throw new ODataNotImplementedException();
}
 
Example 12
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataResponse updateEntityLink(final PutMergePatchUriInfo uriInfo, final InputStream content,
    final String requestContentType, final String contentType) throws ODataException {
  final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
  final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);

  final Object sourceData = retrieveData(
      uriInfo.getStartEntitySet(),
      uriInfo.getKeyPredicates(),
      uriInfo.getFunctionImport(),
      mapFunctionParameters(uriInfo.getFunctionImportParameters()),
      previousSegments);

  final EdmEntitySet entitySet = previousSegments.isEmpty() ?
      uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
  final EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
  final Map<String, Object> keys = mapKey(uriInfo.getTargetKeyPredicates());

  final Object targetData = dataSource.readRelatedData(entitySet, sourceData, targetEntitySet, keys);

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

  dataSource.deleteRelation(entitySet, sourceData, targetEntitySet, keys);

  final Map<String, Object> newKeys = parseLink(targetEntitySet, content, requestContentType);

  dataSource.writeRelation(entitySet, sourceData, targetEntitySet, newKeys);

  return ODataResponse.newBuilder().build();
}
 
Example 13
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 14
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataResponse updateEntityLink(final PutMergePatchUriInfo uriInfo, final InputStream content,
    final String requestContentType, final String contentType) throws ODataException {
  final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
  final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);

  final Object sourceData = retrieveData(
      uriInfo.getStartEntitySet(),
      uriInfo.getKeyPredicates(),
      uriInfo.getFunctionImport(),
      mapFunctionParameters(uriInfo.getFunctionImportParameters()),
      previousSegments);

  final EdmEntitySet entitySet = previousSegments.isEmpty() ?
      uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
  final EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
  final Map<String, Object> keys = mapKey(uriInfo.getTargetKeyPredicates());

  final Object targetData = dataSource.readRelatedData(entitySet, sourceData, targetEntitySet, keys);

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

  dataSource.deleteRelation(entitySet, sourceData, targetEntitySet, keys);

  final Map<String, Object> newKeys = parseLink(targetEntitySet, content, requestContentType);

  dataSource.writeRelation(entitySet, sourceData, targetEntitySet, newKeys);

  return ODataResponse.newBuilder().build();
}
 
Example 15
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataResponse deleteEntityLink(final DeleteUriInfo uriInfo, final String contentType) throws ODataException {
  final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
  final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);

  final Object sourceData = retrieveData(
      uriInfo.getStartEntitySet(),
      uriInfo.getKeyPredicates(),
      uriInfo.getFunctionImport(),
      mapFunctionParameters(uriInfo.getFunctionImportParameters()),
      previousSegments);

  final EdmEntitySet entitySet = previousSegments.isEmpty() ?
      uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
  final EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
  final Map<String, Object> keys = mapKey(uriInfo.getTargetKeyPredicates());

  final Object targetData = dataSource.readRelatedData(entitySet, sourceData, targetEntitySet, keys);

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

  dataSource.deleteRelation(entitySet, sourceData, targetEntitySet, keys);

  return ODataResponse.newBuilder().build();
}
 
Example 16
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 17
Source File: AnnotationInMemoryDs.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public List<?> readData(final EdmEntitySet entitySet) throws ODataNotImplementedException,
    ODataNotFoundException, EdmException, ODataApplicationException {

  DataStore<Object> holder = getDataStore(entitySet);
  if (holder != null) {
    return new ArrayList<Object>(holder.read());
  }

  throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
}
 
Example 18
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 19
Source File: ScenarioDataSource.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
public Object readData(final EdmFunctionImport function, final Map<String, Object> parameters,
    final Map<String, Object> keys) throws ODataNotImplementedException, ODataNotFoundException, EdmException {
  if (function.getName().equals("EmployeeSearch")) {
    if (parameters.get("q") == null) {
      throw new ODataNotFoundException(null);
    } else {
      final List<Employee> found = searchEmployees((String) parameters.get("q"));
      if (keys.isEmpty()) {
        return found;
      } else {
        for (final Employee employee : found) {
          if (employee.getId().equals(keys.get("EmployeeId"))) {
            return employee;
          }
        }
      }
      throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
    }

  } else if (function.getName().equals("AllLocations")) {
    return Arrays.asList(getLocations().keySet().toArray());

  } else if (function.getName().equals("AllUsedRoomIds")) {
    List<String> data = new ArrayList<String>();
    for (final Room room : dataContainer.getRooms()) {
      if (!room.getEmployees().isEmpty()) {
        data.add(room.getId());
      }
    }
    if (data.isEmpty()) {
      throw new ODataNotFoundException(null);
    } else {
      return data;
    }

  } else if (function.getName().equals("MaximalAge")) {
    return getOldestEmployee().getAge();

  } else if (function.getName().equals("MostCommonLocation")) {
    return getMostCommonLocation();

  } else if (function.getName().equals("ManagerPhoto")) {
    if (parameters.get("Id") == null) {
      throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
    }
    for (final Manager manager : dataContainer.getManagers()) {
      if (manager.getId().equals(parameters.get("Id"))) {
        return new BinaryData(manager.getImage(), manager.getImageType());
      }
    }
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);

  } else if (function.getName().equals("AddEmployee")) {
      return null;

  }  else if (function.getName().equals("OldestEmployee")) {
    return getOldestEmployee();

  } else {
    throw new ODataNotImplementedException();
  }
}
 
Example 20
Source File: ScenarioDataSource.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
public Object readData(final EdmEntitySet entitySet, final Map<String, Object> keys)
    throws ODataNotImplementedException, ODataNotFoundException, EdmException {
  if (ENTITYSET_1_1.equals(entitySet.getName())) {
    for (final Employee employee : dataContainer.getEmployees()) {
      if (employee.getId().equals(keys.get("EmployeeId"))) {
        return employee;
      }
    }
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);

  } else if (ENTITYSET_1_2.equals(entitySet.getName())) {
    for (final Team team : dataContainer.getTeams()) {
      if (team.getId().equals(keys.get("Id"))) {
        return team;
      }
    }
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);

  } else if (ENTITYSET_1_3.equals(entitySet.getName())) {
    for (final Room room : dataContainer.getRooms()) {
      if (room.getId().equals(keys.get("Id"))) {
        return room;
      }
    }
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);

  } else if (ENTITYSET_1_4.equals(entitySet.getName())) {
    for (final Manager manager : dataContainer.getManagers()) {
      if (manager.getId().equals(keys.get("EmployeeId"))) {
        return manager;
      }
    }
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);

  } else if (ENTITYSET_1_5.equals(entitySet.getName())) {
    for (final Building building : dataContainer.getBuildings()) {
      if (building.getId().equals(keys.get("Id"))) {
        return building;
      }
    }
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);

  } else if (ENTITYSET_2_1.equals(entitySet.getName())) {
    for (final Photo photo : dataContainer.getPhotos()) {
      if (photo.getId() == (Integer) keys.get("Id")
          && photo.getType().equals(keys.get("Type"))) {
        return photo;
      }
    }
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
  }

  throw new ODataNotImplementedException();
}