Java Code Examples for org.apache.olingo.commons.api.http.HttpStatusCode#NOT_FOUND

The following examples show how to use org.apache.olingo.commons.api.http.HttpStatusCode#NOT_FOUND . 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: DataProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public void deleteReference(final Entity entity, final EdmNavigationProperty navigationProperty,
    final String entityId, final String rawServiceRoot) throws DataProviderException {

  if (navigationProperty.isCollection()) {
    final Entity targetEntity = getEntityByReference(entityId, rawServiceRoot);
    final Link navigationLink = entity.getNavigationLink(navigationProperty.getName());

    if (navigationLink != null && navigationLink.getInlineEntitySet() != null
        && navigationLink.getInlineEntitySet().getEntities().contains(targetEntity)) {

      // Remove partner single-valued navigation property
      if (navigationProperty.getPartner() != null) {
        final EdmNavigationProperty edmPartnerNavigationProperty = navigationProperty.getPartner();
        if (!edmPartnerNavigationProperty.isCollection() && !edmPartnerNavigationProperty.isNullable()) {
          throw new DataProviderException("Navigation property must not be null", HttpStatusCode.BAD_REQUEST);
        } else if (!edmPartnerNavigationProperty.isCollection()) {
          removeLink(edmPartnerNavigationProperty, targetEntity);
        } else if (edmPartnerNavigationProperty.isCollection()
            && edmPartnerNavigationProperty.getPartner() != null) {
          // Bidirectional referential constraint
          final Link partnerNavigationLink = targetEntity.getNavigationLink(edmPartnerNavigationProperty.getName());
          if (partnerNavigationLink != null && partnerNavigationLink.getInlineEntitySet() != null) {
            partnerNavigationLink.getInlineEntitySet().getEntities().remove(entity);
          }
        }
      }

      // Remove target entity from collection-valued navigation property
      navigationLink.getInlineEntitySet().getEntities().remove(targetEntity);
    } else {
      throw new DataProviderException("Entity not found", HttpStatusCode.NOT_FOUND);
    }
  } else {
    if (navigationProperty.isNullable()) {
      removeLink(navigationProperty, entity);
    } else {
      throw new DataProviderException("Navigation property must not be null", HttpStatusCode.BAD_REQUEST);
    }
  }
}
 
Example 2
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected Entity getEntityByReference(final String entityId, final String rawServiceRoot)
    throws DataProviderException {
  try {
    final UriResourceEntitySet uriResource = odata.createUriHelper().parseEntityId(edm, entityId, rawServiceRoot);
    final Entity targetEntity = read(uriResource.getEntitySet(), uriResource.getKeyPredicates());

    if (targetEntity != null) {
      return targetEntity;
    } else {
      throw new DataProviderException("Entity not found", HttpStatusCode.NOT_FOUND);
    }
  } catch (DeserializerException e) {
    throw new DataProviderException("Invalid entity-id", HttpStatusCode.BAD_REQUEST, e);
  }
}
 
Example 3
Source File: ActionData.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private static Entity getSpecificEntity(EntityCollection entityCollection, List<Object> values, 
    List<String> propertyNames) throws DataProviderException {
  for (Entity entity : entityCollection.getEntities()) {
    Object asPrimitive1 = entity.getProperty(propertyNames.get(0)).asPrimitive();
    Object asPrimitive2 = entity.getProperty(propertyNames.get(1)).asPrimitive();
    if (values.get(0).equals(String.valueOf(asPrimitive1)) && 
        values.get(1).equals(String.valueOf(asPrimitive2))) {
      return entity;
    }
  }
  // Entity Not found
  throw new DataProviderException("Entity not found with key: " + values.get(0) +
      "," + values.get(1), HttpStatusCode.NOT_FOUND);
}
 
Example 4
Source File: ActionData.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private static Entity getSpecificEntity1(EntityCollection entityCollection, List<Object> values, 
    List<String> propertyNames) throws DataProviderException {
  for (Entity entity : entityCollection.getEntities()) {
    Object asPrimitive1 = entity.getProperty(propertyNames.get(0)).asPrimitive();
    if (values.get(0).equals(String.valueOf(asPrimitive1))) {
      return entity;
    }
  }
  // Entity Not found
  throw new DataProviderException("Entity not found with key: " + values.get(0), 
      HttpStatusCode.NOT_FOUND);
}