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

The following examples show how to use org.apache.olingo.commons.api.edm.EdmNavigationProperty#getPartner() . 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: EdmNavigationPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void navigationPropertyWithPartner() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  EdmProviderImpl edm = new EdmProviderImpl(provider);
  final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity");
  CsdlEntityType entityTypeProvider = new CsdlEntityType();
  entityTypeProvider.setKey(Collections.<CsdlPropertyRef> emptyList());

  List<CsdlNavigationProperty> navigationProperties = new ArrayList<CsdlNavigationProperty>();
  navigationProperties.add(new CsdlNavigationProperty().setName("partnerName").setType(entityTypeName));
  entityTypeProvider.setNavigationProperties(navigationProperties);
  when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider);
  CsdlNavigationProperty propertyProvider = new CsdlNavigationProperty();
  propertyProvider.setType(entityTypeName);
  propertyProvider.setNullable(false);
  propertyProvider.setPartner("partnerName");
  EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, propertyProvider);
  EdmNavigationProperty partner = property.getPartner();
  assertNotNull(partner);

  // Caching
  assertTrue(partner == property.getPartner());
}
 
Example 3
Source File: EdmNavigationPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test(expected = EdmException.class)
public void navigationPropertyWithNonexistentPartner() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  EdmProviderImpl edm = new EdmProviderImpl(provider);
  final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity");
  CsdlEntityType entityTypeProvider = new CsdlEntityType();
  entityTypeProvider.setKey(Collections.<CsdlPropertyRef> emptyList());

  List<CsdlNavigationProperty> navigationProperties = new ArrayList<CsdlNavigationProperty>();
  navigationProperties.add(new CsdlNavigationProperty().setName("partnerName").setType(entityTypeName));
  entityTypeProvider.setNavigationProperties(navigationProperties);
  when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider);
  CsdlNavigationProperty propertyProvider = new CsdlNavigationProperty();
  propertyProvider.setType(entityTypeName);
  propertyProvider.setNullable(false);
  propertyProvider.setPartner("wrong");
  EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, propertyProvider);
  property.getPartner();
}
 
Example 4
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void createLink(final EdmNavigationProperty navigationProperty, final Entity srcEntity,
    final Entity destEntity) {
  setLink(navigationProperty, srcEntity, destEntity);

  final EdmNavigationProperty partnerNavigationProperty = navigationProperty.getPartner();
  if (partnerNavigationProperty != null) {
    setLink(partnerNavigationProperty, destEntity, srcEntity);
  }
}
 
Example 5
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 6
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void createLink(final EdmNavigationProperty navigationProperty, final Entity srcEntity,
    final Entity destEntity) {
  setLink(navigationProperty, srcEntity, destEntity);

  final EdmNavigationProperty partnerNavigationProperty = navigationProperty.getPartner();
  if (partnerNavigationProperty != null) {
    setLink(partnerNavigationProperty, destEntity, srcEntity);
  }
}
 
Example 7
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void createLink(final EdmNavigationProperty navigationProperty, final Entity srcEntity,
    final Entity destEntity) {
  setLink(navigationProperty, srcEntity, destEntity);

  final EdmNavigationProperty partnerNavigationProperty = navigationProperty.getPartner();
  if (partnerNavigationProperty != null) {
    setLink(partnerNavigationProperty, destEntity, srcEntity);
  }
}
 
Example 8
Source File: MetadataDocumentJsonSerializer.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private void appendNavigationProperties(final JsonGenerator json, 
    final EdmStructuredType type) throws SerializerException, IOException {
  List<String> navigationPropertyNames = new ArrayList<>(type.getNavigationPropertyNames());
  if (type.getBaseType() != null) {
    navigationPropertyNames.removeAll(type.getBaseType().getNavigationPropertyNames());
  }
  for (String navigationPropertyName : navigationPropertyNames) {
    EdmNavigationProperty navigationProperty = type.getNavigationProperty(navigationPropertyName);
    json.writeObjectFieldStart(navigationPropertyName);
    json.writeStringField(KIND, Kind.NavigationProperty.name());
    
    json.writeStringField(TYPE, getAliasedFullQualifiedName(navigationProperty.getType()));
    if (navigationProperty.isCollection()) {
      json.writeBooleanField(COLLECTION, navigationProperty.isCollection());
    }
    
    if (!navigationProperty.isNullable()) {
      json.writeBooleanField(NULLABLE, navigationProperty.isNullable());
    }

    if (navigationProperty.getPartner() != null) {
      EdmNavigationProperty partner = navigationProperty.getPartner();
      json.writeStringField(PARTNER, partner.getName());
    }

    if (navigationProperty.containsTarget()) {
      json.writeBooleanField(CONTAINS_TARGET, navigationProperty.containsTarget());
    }

    if (navigationProperty.getReferentialConstraints() != null) {
      for (EdmReferentialConstraint constraint : navigationProperty.getReferentialConstraints()) {
        json.writeObjectFieldStart(REFERENTIAL_CONSTRAINT);
        json.writeStringField(constraint.getPropertyName(), constraint.getReferencedPropertyName());
        for (EdmAnnotation annotation : constraint.getAnnotations()) {
          appendAnnotations(json, annotation, null);
        }
        json.writeEndObject();
      }
    }
    
    if (navigationProperty.getOnDelete() != null) {
      json.writeObjectFieldStart(ON_DELETE);
      json.writeStringField(ON_DELETE_PROPERTY, navigationProperty.getOnDelete().getAction());
      appendAnnotations(json, navigationProperty.getOnDelete(), null);
      json.writeEndObject();
    }

    appendAnnotations(json, navigationProperty, null);

    json.writeEndObject();
  }
}
 
Example 9
Source File: MetadataDocumentXmlSerializer.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private void appendNavigationProperties(final XMLStreamWriter writer, final EdmStructuredType type)
    throws XMLStreamException {
  List<String> navigationPropertyNames = new ArrayList<>(type.getNavigationPropertyNames());
  if (type.getBaseType() != null) {
    navigationPropertyNames.removeAll(type.getBaseType().getNavigationPropertyNames());
  }
  for (String navigationPropertyName : navigationPropertyNames) {
    EdmNavigationProperty navigationProperty = type.getNavigationProperty(navigationPropertyName);

    writer.writeStartElement(XML_NAVIGATION_PROPERTY);
    writer.writeAttribute(XML_NAME, navigationPropertyName);
    writer.writeAttribute(XML_TYPE, getAliasedFullQualifiedName(navigationProperty.getType(), navigationProperty
        .isCollection()));
    if (!navigationProperty.isNullable()) {
      writer.writeAttribute(XML_NULLABLE, "" + navigationProperty.isNullable());
    }

    if (navigationProperty.getPartner() != null) {
      EdmNavigationProperty partner = navigationProperty.getPartner();
      writer.writeAttribute(XML_PARTNER, partner.getName());
    }

    if (navigationProperty.containsTarget()) {
      writer.writeAttribute(XML_CONTAINS_TARGET, "" + navigationProperty.containsTarget());
    }

    if (navigationProperty.getReferentialConstraints() != null) {
      for (EdmReferentialConstraint constraint : navigationProperty.getReferentialConstraints()) {
        writer.writeStartElement("ReferentialConstraint");
        writer.writeAttribute(XML_PROPERTY, constraint.getPropertyName());
        writer.writeAttribute("ReferencedProperty", constraint.getReferencedPropertyName());
        appendAnnotations(writer, constraint);
        writer.writeEndElement();
      }
    }
    
    if (navigationProperty.getOnDelete() != null) {
      writer.writeStartElement(XML_ON_DELETE);
      writer.writeAttribute(XML_ON_DELETE_PROPERTY, navigationProperty.getOnDelete().getAction());
      appendAnnotations(writer, navigationProperty.getOnDelete());
      writer.writeEndElement();
    }

    appendAnnotations(writer, navigationProperty);

    writer.writeEndElement();
  }
}