Java Code Examples for org.apache.olingo.commons.api.edm.EdmNavigationProperty#getName()

The following examples show how to use org.apache.olingo.commons.api.edm.EdmNavigationProperty#getName() . 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: ODataAdapter.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * This method return the entity collection which are able to navigate from the parent entity (source) using uri navigation properties.
 * <p/>
 * In this method we check the parent entities primary keys and return the entity according to the values.
 * we use ODataDataHandler, navigation properties to get particular foreign keys.
 *
 * @param metadata     Service Metadata
 * @param parentEntity parentEntity
 * @param navigation   UriResourceNavigation
 * @return EntityCollection
 * @throws ODataServiceFault
 */
private EntityCollection getNavigableEntitySet(ServiceMetadata metadata, Entity parentEntity,
                                               EdmNavigationProperty navigation, String url)
        throws ODataServiceFault, ODataApplicationException {
    EdmEntityType type = metadata.getEdm().getEntityType(new FullQualifiedName(parentEntity.getType()));
    String linkName = navigation.getName();
    List<Property> properties = new ArrayList<>();
    Map<String, EdmProperty> propertyMap = new HashMap<>();
    for (NavigationKeys keys : this.dataHandler.getNavigationProperties().get(type.getName())
                                               .getNavigationKeys(linkName)) {
        Property property = parentEntity.getProperty(keys.getPrimaryKey());
        if (property != null && !property.isNull()) {
            propertyMap.put(keys.getForeignKey(), (EdmProperty) type.getProperty(property.getName()));
            property.setName(keys.getForeignKey());
            properties.add(property);
        }
    }
    if(!properties.isEmpty()) {
        return createEntityCollectionFromDataEntryList(linkName, dataHandler
                .readTableWithKeys(linkName, wrapPropertiesToDataEntry(type, properties, propertyMap)), url);
    }
    return null;
}
 
Example 2
Source File: ODataAdapter.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This method return the entity which is able to navigate from the parent entity (source) using uri navigation properties.
 * <p/>
 * In this method we check the parent entities foreign keys and return the entity according to the values.
 * we use ODataDataHandler, navigation properties to get particular foreign keys.
 *
 * @param metadata     Service Metadata
 * @param parentEntity Entity (Source)
 * @param navigation   UriResourceNavigation (Destination)
 * @return Entity (Destination)
 * @throws ODataApplicationException
 * @throws ODataServiceFault
 * @see ODataDataHandler#getNavigationProperties()
 */
private Entity getNavigableEntity(ServiceMetadata metadata, Entity parentEntity, EdmNavigationProperty navigation,
                                  String baseUrl) throws ODataApplicationException, ODataServiceFault {
    EdmEntityType type = metadata.getEdm().getEntityType(new FullQualifiedName(parentEntity.getType()));
    String linkName = navigation.getName();
    List<Property> properties = new ArrayList<>();
    Map<String, EdmProperty> propertyMap = new HashMap<>();
    for (NavigationKeys keys : this.dataHandler.getNavigationProperties().get(linkName)
                                               .getNavigationKeys(type.getName())) {
        Property property = parentEntity.getProperty(keys.getForeignKey());
        if (property != null && !property.isNull()) {
            propertyMap.put(keys.getPrimaryKey(), (EdmProperty) type.getProperty(property.getName()));
            property.setName(keys.getPrimaryKey());
            properties.add(property);
        }
    }
    EntityCollection results = null;
    if (!properties.isEmpty()) {
        results = createEntityCollectionFromDataEntryList(linkName, dataHandler
                .readTableWithKeys(linkName, wrapPropertiesToDataEntry(type, properties, propertyMap)), baseUrl);
    }
    if (results != null && !results.getEntities().isEmpty()) {
        return results.getEntities().get(0);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Reference is not found.");
        }
        return null;
    }
}
 
Example 3
Source File: ODataJsonDeserializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/**
 * Check if jsonNode is not null or if null but nullable or collection navigationProperty
 *
 * @param jsonNode related json node
 * @param edmNavigationProperty related navigation property
 * @throws DeserializerException if jsonNode is not null or if null but nullable or collection navigationProperty
 */
private void checkNotNullOrValidNull(final JsonNode jsonNode,
    final EdmNavigationProperty edmNavigationProperty) throws DeserializerException {
  boolean isNullable = edmNavigationProperty.isNullable();
  if ((jsonNode.isNull() && !isNullable) || (jsonNode.isNull() && edmNavigationProperty.isCollection())) {
    throw new DeserializerException("Property: " + edmNavigationProperty.getName() + " must not be null.",
        MessageKeys.INVALID_NULL_PROPERTY, edmNavigationProperty.getName());
  }
}
 
Example 4
Source File: AbstractUtility.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private NavPropertyBindingDetails getNavigationBindings(
        final EdmStructuredType sourceEntityType, final EdmNavigationProperty property) {

  if (sourceEntityType == null) {
    throw new IllegalStateException("Invalid navigation property " + property.getName());
  }

  try {
    return new NavPropertyBindingDetails(edm, sourceEntityType, property);
  } catch (IllegalStateException ignore) {
    return getNavigationBindingDetails(sourceEntityType.getBaseType(), property);
  }
}
 
Example 5
Source File: ExpandSystemQueryOptionHandler.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private void applyExpandOptionToEntity(final Entity entity, final EdmBindingTarget edmBindingTarget,
    final ExpandOption expandOption, final UriInfoResource uriInfo, final Edm edm) throws ODataApplicationException {

  final EdmEntityType entityType = edmBindingTarget.getEntityType();

  for (ExpandItem item : expandOption.getExpandItems()) {
    if(item.getLevelsOption() != null) {
      throw new ODataApplicationException("$levels is not implemented", 
          HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
    }
    
    List<EdmNavigationProperty> navigationProperties = new ArrayList<EdmNavigationProperty>();
    if(item.isStar()) {
      List<EdmNavigationPropertyBinding> bindings = edmBindingTarget.getNavigationPropertyBindings();
      for (EdmNavigationPropertyBinding binding : bindings) {
        EdmElement property = entityType.getProperty(binding.getPath());
        if(property instanceof EdmNavigationProperty) {
          navigationProperties.add((EdmNavigationProperty) property);
        }
      }
    } else {
      final List<UriResource> uriResourceParts = item.getResourcePath().getUriResourceParts();
      if (uriResourceParts.get(0) instanceof UriResourceNavigation) {
        navigationProperties.add(((UriResourceNavigation) uriResourceParts.get(0)).getProperty());
      }
    }

    for (EdmNavigationProperty navigationProperty: navigationProperties) {
      final String navPropertyName = navigationProperty.getName();
      final EdmBindingTarget targetEdmEntitySet = edmBindingTarget.getRelatedBindingTarget(navPropertyName);

      final Link link = entity.getNavigationLink(navPropertyName);
      if (link != null && entityType.getNavigationProperty(navPropertyName).isCollection()) {
        applyOptionsToEntityCollection(link.getInlineEntitySet(),
            targetEdmEntitySet,
            item.getFilterOption(),
            item.getOrderByOption(),
            item.getCountOption(),
            item.getSkipOption(),
            item.getTopOption(),
            item.getExpandOption(),
            uriInfo, edm);
      }
    }
  }
}