Example #1
0
 private void expandManufacturer(
     GetEntityUriInfo uriInfo,
     URI serviceRoot,
     ODataEntityProviderPropertiesBuilder propertiesBuilder)
     throws EdmException {
   Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
   callbacks.put(ENTITY_NAME_MANUFACTURER, new MyCallback(dataStore, serviceRoot));
   ExpandSelectTreeNode expandSelectTreeNode =
       UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand());
   propertiesBuilder.expandSelectTree(expandSelectTreeNode).callbacks(callbacks);
 }
Example #2
0
  public ODataResponse readEntity(GetEntityUriInfo uriInfo, String contentType)
      throws ODataException {
    LOG.debug("Reading Entity: " + uriInfo);

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

      if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
        int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
        Map<String, Object> data = dataStore.getCar(id);

        if (data != null) {
          URI serviceRoot = getContext().getPathInfo().getServiceRoot();
          ODataEntityProviderPropertiesBuilder propertiesBuilder =
              EntityProviderWriteProperties.serviceRoot(serviceRoot);
          expandManufacturer(uriInfo, serviceRoot, propertiesBuilder);
          return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
        }
      } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
        int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
        Map<String, Object> data = dataStore.getManufacturer(id);

        if (data != null) {
          URI serviceRoot = getContext().getPathInfo().getServiceRoot();
          ODataEntityProviderPropertiesBuilder propertiesBuilder =
              EntityProviderWriteProperties.serviceRoot(serviceRoot);
          expandCars(uriInfo, serviceRoot, propertiesBuilder);
          return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
        }
      }

      throw new ODataNotFoundException(ODataNotFoundException.ENTITY);

    } else if (uriInfo.getNavigationSegments().size() == 1) {
      // navigation first level, simplified example for illustration
      // purposes only
      EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
      if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
        int carKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
        return EntityProvider.writeEntry(
            contentType,
            uriInfo.getTargetEntitySet(),
            dataStore.getManufacturer(carKey),
            EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot())
                .build());
      }

      throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
    }

    throw new ODataNotImplementedException();
  }