Java Code Examples for org.apache.olingo.odata2.api.edm.provider.EntityType#setNavigationProperties()

The following examples show how to use org.apache.olingo.odata2.api.edm.provider.EntityType#setNavigationProperties() . 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: AnnotationEdmProvider.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public EntityType buildEntityType() {
  EntityType entityType = new EntityType();
  if (baseEntityType != null) {
    entityType.setBaseType(baseEntityType);
  }
  if (!keyProperties.isEmpty()) {
    entityType.setKey(new Key().setKeys(keyProperties));
  }
  if (!navProperties.isEmpty()) {
    entityType.setNavigationProperties(navProperties);
  }
  return entityType.setName(name)
      .setAbstract(isAbstract)
      .setHasStream(isMediaResource)
      .setProperties(properties)
      .setMapping(new Mapping().setMediaResourceMimeTypeKey(mediaResourceMimeTypeKey)
                                .setMediaResourceSourceKey(mediaResourceSourceKey));
}
 
Example 2
Source File: JPAEdmEntityType.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void build() throws ODataJPAModelException, ODataJPARuntimeException {

  Set<javax.persistence.metamodel.EntityType<?>> jpaEntityTypes = metaModel.getEntities();

  if (jpaEntityTypes == null || jpaEntityTypes.isEmpty() == true) {
    return;
  } else if (consistentEntityTypes == null) {
    consistentEntityTypes = new EntityTypeList<EntityType>();

  }

  for (javax.persistence.metamodel.EntityType<?> jpaEntityType : jpaEntityTypes) {
    currentEdmEntityType = new EntityType();
    currentJPAEntityType = jpaEntityType;

    // Check for need to Exclude
    if (isExcluded(JPAEdmEntityType.this)) {
      continue;
    }

    JPAEdmNameBuilder.build(JPAEdmEntityType.this);
    JPAEdmMapping jpaEdmMapping = (JPAEdmMapping) currentEdmEntityType.getMapping();
    EntityListeners entityListners = currentJPAEntityType.getJavaType().getAnnotation(EntityListeners.class);
    if (entityListners != null) {
      for (Class<EntityListeners> entityListner : entityListners.value()) {
        if (ODataJPATombstoneEntityListener.class.isAssignableFrom(entityListner)) {
          jpaEdmMapping
              .setODataJPATombstoneEntityListener((Class<? extends ODataJPATombstoneEntityListener>)
              (Object) entityListner);
          break;
        }
      }
    }
    JPAEdmPropertyView propertyView = new JPAEdmProperty(schemaView);
    propertyView.getBuilder().build();

    currentEdmEntityType.setProperties(propertyView.getEdmPropertyList());
    if (propertyView.getJPAEdmNavigationPropertyView() != null) {
      JPAEdmNavigationPropertyView navPropView = propertyView.getJPAEdmNavigationPropertyView();
      if (navPropView.getConsistentEdmNavigationProperties() != null
          && !navPropView.getConsistentEdmNavigationProperties().isEmpty()) {
        currentEdmEntityType.setNavigationProperties(navPropView.getConsistentEdmNavigationProperties());
      }
    }
    JPAEdmKeyView keyView = propertyView.getJPAEdmKeyView();
    currentEdmEntityType.setKey(keyView.getEdmKey());

    consistentEntityTypes.add(currentEdmEntityType);
    consistentEntityTypeMap.put(currentJPAEntityType.getName(), currentEdmEntityType);
  }

}
 
Example 3
Source File: JPAEdmSchema.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public void build() throws ODataJPAModelException, ODataJPARuntimeException {

  schema = new Schema();
  JPAEdmNameBuilder.build(JPAEdmSchema.this);

  associationView = new JPAEdmAssociation(JPAEdmSchema.this);

  complexTypeView = new JPAEdmComplexType(JPAEdmSchema.this);
  complexTypeView.getBuilder().build();

  entityContainerView = new JPAEdmEntityContainer(JPAEdmSchema.this);
  entityContainerView.getBuilder().build();
  schema.setEntityContainers(entityContainerView.getConsistentEdmEntityContainerList());

  JPAEdmEntitySetView entitySetView = entityContainerView.getJPAEdmEntitySetView();
  if (entitySetView.isConsistent() && entitySetView.getJPAEdmEntityTypeView() != null) {
    JPAEdmEntityTypeView entityTypeView = entitySetView.getJPAEdmEntityTypeView();
    if (entityTypeView.isConsistent() && !entityTypeView.getConsistentEdmEntityTypes().isEmpty()) {
      schema.setEntityTypes(entityTypeView.getConsistentEdmEntityTypes());
    }
  }
  if (complexTypeView.isConsistent()) {
    List<ComplexType> complexTypes = complexTypeView.getConsistentEdmComplexTypes();
    List<ComplexType> existingComplexTypes = new ArrayList<ComplexType>();
    for (ComplexType complexType : complexTypes) {
      if (complexType != null && complexTypeView.isReferencedInKey(complexType.getName())) {// null check for
                                                                                            // exclude
        existingComplexTypes.add(complexType);
      }
    }
    if (!existingComplexTypes.isEmpty()) {
      schema.setComplexTypes(existingComplexTypes);
    }
  }

  List<String> existingAssociationList = new ArrayList<String>();
  if (associationView.isConsistent() && !associationView.getConsistentEdmAssociationList().isEmpty()) {

    List<Association> consistentAssociationList = associationView.getConsistentEdmAssociationList();
    schema.setAssociations(consistentAssociationList);
    for (Association association : consistentAssociationList) {
      existingAssociationList.add(association.getName());
    }

  }
  List<EntityType> entityTypes =
      entityContainerView.getJPAEdmEntitySetView().getJPAEdmEntityTypeView().getConsistentEdmEntityTypes();
  List<NavigationProperty> navigationProperties;
  if (entityTypes != null && !entityTypes.isEmpty()) {
    for (EntityType entityType : entityTypes) {

      List<NavigationProperty> consistentNavigationProperties = null;
      navigationProperties = entityType.getNavigationProperties();
      if (navigationProperties != null) {
        consistentNavigationProperties = new ArrayList<NavigationProperty>();
        for (NavigationProperty navigationProperty : navigationProperties) {
          if (existingAssociationList.contains(navigationProperty.getRelationship().getName())) {
            consistentNavigationProperties.add(navigationProperty);
          }
        }
        if (consistentNavigationProperties.isEmpty()) {
          entityType.setNavigationProperties(null);
        } else {
          entityType.setNavigationProperties(consistentNavigationProperties);
        }
      }

    }
  }

  JPAEdmExtension edmExtension = getJPAEdmExtension();
  if (edmExtension != null) {
    edmExtension.extendJPAEdmSchema(JPAEdmSchema.this);
    edmExtension.extendWithOperation(JPAEdmSchema.this);

    JPAEdmFunctionImportView functionImportView = new JPAEdmFunctionImport(JPAEdmSchema.this);
    functionImportView.getBuilder().build();
    if (functionImportView.getConsistentFunctionImportList() != null) {
      entityContainerView.getEdmEntityContainer().setFunctionImports(
          functionImportView.getConsistentFunctionImportList());
    }

  }
}
 
Example 4
Source File: EdmEntityTypeImplProvTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void getEdmEntityContainerImpl() throws Exception {

  edmProvider = mock(EdmProvider.class);
  EdmImplProv edmImplProv = new EdmImplProv(edmProvider);

  List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
  FullQualifiedName fooBarAssocName = new FullQualifiedName("namespace", "fooBarAssoc");
  navigationProperties.add(new NavigationProperty().setName("fooBarNav").setFromRole("fromFoo").setRelationship(
      fooBarAssocName).setToRole("toBar"));

  EntityType fooEntityType = new EntityType().setName("fooEntityType").setNavigationProperties(navigationProperties);
  FullQualifiedName fooEntityTypeFullName = new FullQualifiedName("namespace", "fooEntityType");
  when(edmProvider.getEntityType(fooEntityTypeFullName)).thenReturn(fooEntityType);

  List<Property> keyPropertysFoo = new ArrayList<Property>();
  Property keyPropFoo = new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.String);
  keyPropertysFoo.add(keyPropFoo);
  fooEntityType.setProperties(keyPropertysFoo);

  PropertyRef refToKeyFoo = new PropertyRef().setName("Id");
  List<PropertyRef> propRefKeysFoo = new ArrayList<PropertyRef>();
  propRefKeysFoo.add(refToKeyFoo);

  Key fooTypeKey = new Key().setKeys(propRefKeysFoo);
  fooEntityType.setKey(fooTypeKey);

  edmEntityType = new EdmEntityTypeImplProv(edmImplProv, fooEntityType, "namespace");

  FullQualifiedName barBaseTypeName = new FullQualifiedName("namespace", "barBase");
  EntityType barBase = new EntityType().setName("barBase");
  when(edmProvider.getEntityType(barBaseTypeName)).thenReturn(barBase);

  List<NavigationProperty> navigationPropertiesBarBase = new ArrayList<NavigationProperty>();
  navigationPropertiesBarBase.add(new NavigationProperty().setName("barBaseNav"));
  barBase.setNavigationProperties(navigationPropertiesBarBase);

  List<Property> keyPropertysBarBase = new ArrayList<Property>();
  Property keyPropBarBase = new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.String);
  keyPropertysBarBase.add(keyPropBarBase);
  keyPropBarBase = new SimpleProperty().setName("NotrmalProp").setType(EdmSimpleTypeKind.String);
  keyPropertysBarBase.add(keyPropBarBase);
  barBase.setProperties(keyPropertysBarBase);

  PropertyRef refToKeyBarBase = new PropertyRef().setName("Id");
  List<PropertyRef> propRefKeysBarBase = new ArrayList<PropertyRef>();
  propRefKeysBarBase.add(refToKeyBarBase);

  Key barBaseTypeKey = new Key().setKeys(propRefKeysBarBase);
  barBase.setKey(barBaseTypeKey);

  EntityType barEntityType = new EntityType().setName("barEntityType").setBaseType(barBaseTypeName);
  FullQualifiedName barEntityTypeFullName = new FullQualifiedName("namespace", "barEntityType");
  when(edmProvider.getEntityType(barEntityTypeFullName)).thenReturn(barEntityType);

  edmEntityTypeWithBaseType = new EdmEntityTypeImplProv(edmImplProv, barEntityType, "namespace");

}