Java Code Examples for org.apache.olingo.commons.api.edm.EdmEntityType#getNavigationPropertyNames()

The following examples show how to use org.apache.olingo.commons.api.edm.EdmEntityType#getNavigationPropertyNames() . 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 6 votes vote down vote up
private void handleDeleteSingleNavigationProperties(final EdmEntitySet edmEntitySet, final Entity entity,
    final Entity changedEntity) throws DataProviderException {
  final EdmEntityType entityType = edmEntitySet.getEntityType();
  final List<String> navigationPropertyNames = entityType.getNavigationPropertyNames();

  for (final String navPropertyName : navigationPropertyNames) {
    final Link navigationLink = changedEntity.getNavigationLink(navPropertyName);
    final EdmNavigationProperty navigationProperty = entityType.getNavigationProperty(navPropertyName);
    if (!navigationProperty.isCollection() && navigationLink != null && navigationLink.getInlineEntity() == null) {

      // Check if partner is available
      if (navigationProperty.getPartner() != null && entity.getNavigationLink(navPropertyName) != null) {
        Entity partnerEntity = entity.getNavigationLink(navPropertyName).getInlineEntity();
        removeLink(navigationProperty.getPartner(), partnerEntity);
      }

      // Remove link
      removeLink(navigationProperty, entity);
    }
  }
}
 
Example 2
Source File: ODataJsonDeserializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void consumeExpandedNavigationProperties(final EdmEntityType edmEntityType, final ObjectNode node,
    final Entity entity, final ExpandTreeBuilder expandBuilder) throws DeserializerException {
  List<String> navigationPropertyNames = edmEntityType.getNavigationPropertyNames();
  for (String navigationPropertyName : navigationPropertyNames) {
    // read expanded navigation property
    JsonNode jsonNode = node.get(navigationPropertyName);
    if (jsonNode != null) {
      EdmNavigationProperty edmNavigationProperty = edmEntityType.getNavigationProperty(navigationPropertyName);
      checkNotNullOrValidNull(jsonNode, edmNavigationProperty);

      Link link = createLink(expandBuilder, navigationPropertyName, jsonNode, edmNavigationProperty);
      entity.getNavigationLinks().add(link);
      node.remove(navigationPropertyName);
    }
  }
}
 
Example 3
Source File: ODataJsonDeserializer.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private void consumeDeltaJsonNodeFields(EdmEntityType edmEntityType, ObjectNode node,
    Entity entity, ExpandTreeBuilder expandBuilder) 
    throws DeserializerException {
  if (constants instanceof Constantsv01) {
    List<String> navigationPropertyNames = edmEntityType.getNavigationPropertyNames();
    for (String navigationPropertyName : navigationPropertyNames) {
      // read expanded navigation property for delta
      String delta = navigationPropertyName + Constants.AT + Constants.DELTAVALUE;
      JsonNode jsonNode = node.get(delta);
      EdmNavigationProperty edmNavigationProperty = edmEntityType.getNavigationProperty(navigationPropertyName);
      if (jsonNode != null && jsonNode.isArray() && edmNavigationProperty.isCollection()) {
        checkNotNullOrValidNull(jsonNode, edmNavigationProperty);
        Link link = new Link();
        link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE);
        link.setTitle(navigationPropertyName);
        Delta deltaValue = new Delta();
        for (JsonNode arrayElement : jsonNode) {
          String removed = Constants.AT + Constants.REMOVED;
          if (arrayElement.get(removed) != null) {
            //if @removed is present create a DeletedEntity Object
            JsonNode reasonNode = arrayElement.get(removed);
            DeletedEntity deletedEntity = new DeletedEntity();
            Reason reason = null;
            if (reasonNode.get(REASON) != null) {
              if(reasonNode.get(REASON).asText().equals(Reason.changed.name())){
                reason = Reason.changed;
              }else if(reasonNode.get(REASON).asText().equals(Reason.deleted.name())){
                reason = Reason.deleted;
              }
            }else{
              throw new DeserializerException("DeletedEntity reason is null.",
                  SerializerException.MessageKeys.MISSING_DELTA_PROPERTY, Constants.REASON);
            }
            deletedEntity.setReason(reason);
            try {
              deletedEntity.setId(new URI(arrayElement.get(constants.getId()).asText()));
            } catch (URISyntaxException e) {
              throw new DeserializerException("Could not set Id for deleted Entity", e,
                  DeserializerException.MessageKeys.UNKNOWN_CONTENT);
            }
            deltaValue.getDeletedEntities().add(deletedEntity);
          } else {
            //For @id and properties create normal entity
            Entity inlineEntity = consumeEntityNode(edmEntityType, (ObjectNode) arrayElement, expandBuilder);
            deltaValue.getEntities().add(inlineEntity);
          }
        }
        link.setInlineEntitySet(deltaValue);
        entity.getNavigationLinks().add(link);
        node.remove(navigationPropertyName);
      }
    }
  }

}