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

The following examples show how to use org.apache.olingo.odata2.api.edm.provider.EntityType#getNavigationProperties() . 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: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void entityTypeEmployee() throws Exception {
  // validate employee
  EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
  assertEquals("Employee", employee.getName());
  final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
  assertEquals(1, employeeKeys.size());
  assertEquals("EmployeeId", employeeKeys.get(0).getName());
  assertEquals(6, employee.getProperties().size());
  assertEquals(3, employee.getNavigationProperties().size());
  Property name = getProperty(employee, "EmployeeName");
  assertEquals(Integer.valueOf(20), name.getFacets().getMaxLength());

  for (NavigationProperty navigationProperty : employee.getNavigationProperties()) {
    if (navigationProperty.getName().equals("ne_Manager")) {
      validateNavProperty(navigationProperty, "ManagerEmployees", "r_Employees", "r_Manager");
    } else if (navigationProperty.getName().equals("ne_Team")) {
      validateNavProperty(navigationProperty, "TeamEmployees", "r_Employees", "r_Team");
    } else if (navigationProperty.getName().equals("ne_Room")) {
      validateNavProperty(navigationProperty, "r_Employees_2_r_Room", "r_Employees", "r_Room");
    } else {
      fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
    }
  }
}
 
Example 2
Source File: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void entityTypeRoomWithNavigation() throws Exception {
  // validate employee
  EntityType room = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Room"));
  assertEquals("Room", room.getName());
  assertEquals("Base", room.getBaseType().getName());
  assertEquals(2, room.getProperties().size());
  final List<NavigationProperty> navigationProperties = room.getNavigationProperties();
  assertEquals(2, navigationProperties.size());

  for (NavigationProperty navigationProperty : navigationProperties) {
    if (navigationProperty.getName().equals("nr_Employees")) {
      validateNavProperty(navigationProperty, "r_Employees_2_r_Room", "r_Room", "r_Employees");
    } else if (navigationProperty.getName().equals("nr_Building")) {
      validateNavProperty(navigationProperty, "BuildingRooms", "r_Rooms", "r_Building");
    } else {
      fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
    }
  }
}
 
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());
    }

  }
}