org.apache.olingo.odata2.api.edm.provider.NavigationProperty Java Examples

The following examples show how to use org.apache.olingo.odata2.api.edm.provider.NavigationProperty. 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: EdmMappingTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws Exception {

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

  mappedObject = new EdmMappingTest();

  Mapping propertySimpleMapping = new Mapping().setInternalName("value").setObject(mappedObject);
  CustomizableFeedMappings propertySimpleFeedMappings = new CustomizableFeedMappings().setFcKeepInContent(true);
  SimpleProperty propertySimple =
      new SimpleProperty().setName("PropertyName").setType(EdmSimpleTypeKind.String)
          .setMimeType("mimeType").setMapping(propertySimpleMapping).setCustomizableFeedMappings(
              propertySimpleFeedMappings);
  propertySimpleProvider = new EdmSimplePropertyImplProv(edmImplProv, propertySimple);

  NavigationProperty navProperty =
      new NavigationProperty().setName("navProperty").setFromRole("fromRole").setToRole("toRole").setMapping(
          propertySimpleMapping);
  navPropertyProvider = new EdmNavigationPropertyImplProv(edmImplProv, navProperty);
}
 
Example #2
Source File: EdmNavigationPropertyImplProvTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws Exception {

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

  FullQualifiedName relationship = new FullQualifiedName("namespace", "associationName");
  Association association = new Association().setName("associationName");
  when(edmProvider.getAssociation(relationship)).thenReturn(association);

  AssociationEnd end1 = new AssociationEnd().setRole("fromRole");
  FullQualifiedName entityName = new FullQualifiedName("namespace", "entityName");
  AssociationEnd end2 =
      new AssociationEnd().setRole("toRole").setMultiplicity(EdmMultiplicity.ONE).setType(entityName);
  association.setEnd1(end1).setEnd2(end2);

  EntityType entityType = new EntityType().setName("entityName");
  when(edmProvider.getEntityType(entityName)).thenReturn(entityType);

  NavigationProperty navProperty =
      new NavigationProperty().setName("navProperty").setFromRole("fromRole").setToRole("toRole").setRelationship(
          relationship);
  navPropertyProvider = new EdmNavigationPropertyImplProv(edmImplProv, navProperty);
}
 
Example #3
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private void validateRelationship() throws EntityProviderException {
  for (NavigationProperty navProperty : navProperties) {
    if (associationsMap.containsKey(navProperty.getRelationship())) {
      Association assoc = associationsMap.get(navProperty.getRelationship());
      if (!(assoc.getEnd1().getRole().equals(navProperty.getFromRole())
          ^ assoc.getEnd1().getRole().equals(navProperty.getToRole())
          && (assoc.getEnd2().getRole().equals(navProperty.getFromRole()) ^ assoc.getEnd2().getRole().equals(
          navProperty.getToRole())))) {
        throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT
            .addContent("Invalid end of association"));
      }
      if (!entityTypesMap.containsKey(assoc.getEnd1().getType())) {
        validateEntityTypeWithAlias(assoc.getEnd1().getType());
      }
      if (!entityTypesMap.containsKey(assoc.getEnd2().getType())) {
        validateEntityTypeWithAlias(assoc.getEnd2().getType());
      }
    } else {
      throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT.addContent("Invalid Relationship"));
    }
  }

}
 
Example #4
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 #5
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 #6
Source File: JPAEdmNavigationProperty.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public void build() throws ODataJPAModelException {

  currentNavigationProperty = new NavigationProperty();
  JPAEdmNameBuilder.build(associationView, propertyView, JPAEdmNavigationProperty.this, skipDefaultNaming, count);
  consistentNavigationProperties.add(currentNavigationProperty);
}
 
Example #7
Source File: EdmEntityTypeImplProv.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getNavigationPropertyNames() throws EdmException {
  if (edmNavigationPropertyNames == null) {
    edmNavigationPropertyNames = new ArrayList<String>();
    if (edmBaseType != null) {
      edmNavigationPropertyNames.addAll(((EdmEntityType) edmBaseType).getNavigationPropertyNames());
    }
    if (entityType.getNavigationProperties() != null) {
      for (final NavigationProperty navigationProperty : entityType.getNavigationProperties()) {
        edmNavigationPropertyNames.add(navigationProperty.getName());
      }
    }
  }
  return edmNavigationPropertyNames;
}
 
Example #8
Source File: EdmEntityTypeImplProv.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void buildNavigationPropertiesInternal() throws EdmException {
  navigationProperties = new HashMap<String, NavigationProperty>();

  if (entityType.getNavigationProperties() != null) {
    for (final NavigationProperty navigationProperty : entityType.getNavigationProperties()) {
      navigationProperties.put(navigationProperty.getName(), navigationProperty);
    }
  }
}
 
Example #9
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private NavigationProperty readNavigationProperty(final XMLStreamReader reader) throws XMLStreamException,
    EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_NAVIGATION_PROPERTY);

  NavigationProperty navProperty = new NavigationProperty();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  navProperty.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  String relationship = reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAVIGATION_RELATIONSHIP);
  if (relationship != null) {
    FullQualifiedName fqName = extractFQName(relationship);
    navProperty.setRelationship(fqName);

  } else {
    throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE
        .addContent(XmlMetadataConstants.EDM_NAVIGATION_RELATIONSHIP).addContent(
            XmlMetadataConstants.EDM_NAVIGATION_PROPERTY));
  }

  navProperty.setFromRole(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAVIGATION_FROM_ROLE));
  navProperty.setToRole(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAVIGATION_TO_ROLE));
  navProperty.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_NAVIGATION_PROPERTY.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      annotationElements.add(readAnnotationElement(reader));
    }
  }
  if (!annotationElements.isEmpty()) {
    navProperty.setAnnotationElements(annotationElements);
  }
  navProperties.add(navProperty);
  return navProperty;
}
 
Example #10
Source File: NetworkEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public EntityType getEntityType ()
{
   // Properties
   List<Property> properties = new ArrayList<Property> ();

   properties.add (new SimpleProperty ()
   .setName (ID)
   .setType (EdmSimpleTypeKind.Int64)
   .setFacets (new Facets ().setNullable (false))
   .setCustomizableFeedMappings (
      new CustomizableFeedMappings ()
         .setFcTargetPath (EdmTargetPath.SYNDICATION_TITLE)));

   // Key
   Key key =
      new Key ().setKeys (Collections.singletonList (new PropertyRef ()
         .setName (ID)));

   // Navigation Properties
   List<NavigationProperty> navigationProperties =
      new ArrayList<NavigationProperty> ();

   if (Security.currentUserHasRole(Role.STATISTICS))
   {
      navigationProperties.add (new NavigationProperty ()
         .setName ("NetworkStatistic")
         .setRelationship (ASSO_NETWORK_NETWORKSTATISTIC)
         .setFromRole (ROLE_NETWORKSTATISTIC_NETWORK)
         .setToRole (ROLE_NETWORK_NETWORKSTATISTIC));
   }

   return new EntityType ().setName (ENTITY_NAME).setProperties (properties)
      .setKey (key).setNavigationProperties (navigationProperties);
}
 
Example #11
Source File: JPAEdmNavigationProperty.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public JPAEdmNavigationProperty(final JPAEdmAssociationView associationView, final JPAEdmPropertyView propertyView,
    final int countNumber) {
  super(associationView);
  this.associationView = associationView;
  this.propertyView = propertyView;
  count = countNumber;
  if (consistentNavigationProperties == null) {
    consistentNavigationProperties = new ArrayList<NavigationProperty>();
  }
}
 
Example #12
Source File: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void validateNavProperty(final NavigationProperty navigationProperty, final String name,
    final String relationship, final String fromRole, final String toRole) {
  if (name != null) {
    assertEquals(name, navigationProperty.getName());
  }
  FullQualifiedName fqn = new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, relationship);
  assertEquals("Wrong relationship for navigation property.", fqn, navigationProperty.getRelationship());
  assertEquals("Wrong fromRole for navigation property.", fromRole, navigationProperty.getFromRole());
  assertEquals("Wrong toRole for navigation property.", toRole, navigationProperty.getToRole());
}
 
Example #13
Source File: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void entityTypeTeam() throws Exception {
  // validate team
  EntityType team = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Team"));
  assertEquals("Team", team.getName());
  assertEquals("Base", team.getBaseType().getName());
  assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());

  assertEquals(1, team.getProperties().size());
  assertEquals(2, team.getNavigationProperties().size());
  NavigationProperty navPropTeamEmployess = team.getNavigationProperties().get(0);
  validateNavProperty(navPropTeamEmployess, "TeamEmployees", "r_Team", "r_Employees");
  NavigationProperty navPropTeamTeam = team.getNavigationProperties().get(1);
  validateNavProperty(navPropTeamTeam, "Team_2_r_SubTeam", "Team", "r_SubTeam");
}
 
Example #14
Source File: AnnotationEdmProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private NavigationProperty createNavigationProperty(final String namespace, Field field,
                                                    AnnotationHelper.AnnotatedNavInfo navInfo) {
  NavigationProperty navProp = new NavigationProperty();
  navProp.setName(ANNOTATION_HELPER.getPropertyName(field));
  String fromRole = navInfo.getFromRoleName();
  navProp.setFromRole(fromRole);
  navProp.setToRole(navInfo.getToRoleName());

  String relationshipName = navInfo.getRelationshipName();
  navProp.setRelationship(new FullQualifiedName(namespace, relationshipName));

  return navProp;
}
 
Example #15
Source File: NodeEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public EntityType getEntityType ()
{
   EntityType res = Model.ITEM.getEntityType();

   res.getProperties ().add (
      new SimpleProperty ().setName (CHILDREN_NUMBER).setType (
         EdmSimpleTypeKind.Int64));
   res.getProperties ().add (
      new SimpleProperty ().setName (VALUE).setType (
         EdmSimpleTypeKind.String));

   // Navigation Properties
   List<NavigationProperty> navigationProperties =
      new ArrayList<NavigationProperty> ();
   // TODO (OData v3) setContainsTarget(true)
   navigationProperties.add (new NavigationProperty ().setName (getName ())
      .setRelationship (ASSO_NODE_NODE).setFromRole (ROLE_NODE_PARENT)
      .setToRole (ROLE_NODE_NODES));
   navigationProperties.add (new NavigationProperty ()
      .setName(Model.ATTRIBUTE.getName())
      .setRelationship (ASSO_NODE_ATTRIBUTE)
      .setFromRole (ROLE_ATTRIBUTE_NODE).setToRole (ROLE_NODE_ATTRIBUTES));
   navigationProperties.add (new NavigationProperty ()
      .setName ("Class")
      .setRelationship (ASSO_NODE_CLASS)
      .setFromRole (ROLE_CLASS_NODES)
      .setToRole (ROLE_NODE_CLASS));

   // TODO (OData v3) setAbstract(true) setBaseType(ENTITY_ITEM)
   return res.setName (ENTITY_NAME)
      .setNavigationProperties (navigationProperties).setHasStream (true);
}
 
Example #16
Source File: ClassEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public EntityType getEntityType ()
{
   List<Property> properties = new ArrayList<Property> ();
   properties.add (new SimpleProperty ()
   .setName (ID)
   .setType (EdmSimpleTypeKind.String)
   .setFacets (new Facets ().setNullable (false))
   .setCustomizableFeedMappings (
      new CustomizableFeedMappings ()
         .setFcTargetPath (EdmTargetPath.SYNDICATION_TITLE)));
   
   properties.add (new SimpleProperty ().setName (URI).setType (
      EdmSimpleTypeKind.String));
  
   // Navigation Properties
   List<NavigationProperty> navigationProperties =
      new ArrayList<NavigationProperty> ();
   // TODO (OData v3) setContainsTarget(true)
   navigationProperties.add (new NavigationProperty ().setName (getName ())
      .setRelationship (ASSO_CLASS_CLASS).setFromRole (ROLE_CLASS_PARENT)
      .setToRole (ROLE_CLASS_CLASSES));

   // Key
   Key key =
      new Key ().setKeys (Collections.singletonList (new PropertyRef ()
         .setName (ID)));

   return new EntityType ().setName (ENTITY_NAME).setProperties (properties)
      .setKey (key).setNavigationProperties (navigationProperties);
}
 
Example #17
Source File: CollectionEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public EntityType getEntityType ()
{
   List<Property> properties = new ArrayList<>();
   properties.add (new SimpleProperty ()
      .setName (NAME)
      .setType (EdmSimpleTypeKind.String)
      .setFacets (new Facets ().setNullable (false))
      .setCustomizableFeedMappings (
         new CustomizableFeedMappings ()
            .setFcTargetPath (EdmTargetPath.SYNDICATION_TITLE)));
   properties.add (new SimpleProperty ().setName (DESCRIPTION).setType (
      EdmSimpleTypeKind.String));

   // Navigation Properties
   List<NavigationProperty> navigationProperties =
      Collections.singletonList(new NavigationProperty()
         .setName(Model.PRODUCT.getName())
         .setRelationship(ASSO_COLLECTION_PRODUCT)
         .setFromRole(ROLE_PRODUCT_COLLECTIONS)
         .setToRole(ROLE_COLLECTION_PRODUCTS));

   // Key
   Key key =
      new Key ().setKeys (Collections.singletonList (new PropertyRef ()
         .setName (NAME)));

   return new EntityType ().setName (ENTITY_NAME).setProperties (properties)
      .setKey (key).setNavigationProperties (navigationProperties);
}
 
Example #18
Source File: AnnotationEdmProvider.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
public TypeBuilder addNavigationProperty(final NavigationProperty property) {
  navProperties.add(property);
  return this;
}
 
Example #19
Source File: SynchronizerEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public EntityType getEntityType ()
{
   List<Property> properties = new ArrayList<> ();
   properties.add (new SimpleProperty ().setName (ID)
         .setType (EdmSimpleTypeKind.Int64)
         .setFacets (new Facets ().setNullable (false)));

   properties.add (new SimpleProperty ().setName (LABEL)
         .setType (EdmSimpleTypeKind.String));

   properties.add (new SimpleProperty ().setName (CREATION_DATE)
         .setType (EdmSimpleTypeKind.DateTime)
         .setFacets (new Facets ().setNullable (false)));

   properties.add (new SimpleProperty ().setName (MODIFICATION_DATE)
         .setType (EdmSimpleTypeKind.DateTime)
         .setFacets (new Facets ().setNullable (false)));

   properties.add (new SimpleProperty ().setName (SERVICE_URL)
         .setType (EdmSimpleTypeKind.String)
         .setFacets (new Facets ().setNullable (false)));

   properties.add (new SimpleProperty ().setName (SERVICE_LOGIN)
         .setType (EdmSimpleTypeKind.String));

   properties.add (new SimpleProperty ().setName (SERVICE_PASSWORD)
         .setType (EdmSimpleTypeKind.String));

   properties.add (new SimpleProperty ().setName (REMOTE_INCOMING)
         .setType (EdmSimpleTypeKind.String));

   properties.add (new SimpleProperty ().setName (SCHEDULE)
         .setType (EdmSimpleTypeKind.String)
         .setFacets (new Facets ().setNullable (false)));

   properties.add (new SimpleProperty ().setName (PAGE_SIZE)
         .setType (EdmSimpleTypeKind.Int32)
         .setFacets (
               new Facets ()
                     .setNullable (false)
                     .setDefaultValue ("30")
         )
   );

   properties.add(new SimpleProperty ().setName(COPY_PRODUCT)
         .setType (EdmSimpleTypeKind.Boolean)
         .setFacets (
               new Facets ()
                  .setNullable (false)
                  .setDefaultValue ("false")
         )
   );

   properties.add (new SimpleProperty ().setName (FILTER_PARAM)
         .setType (EdmSimpleTypeKind.String));

   properties.add (new SimpleProperty ().setName (SOURCE_COLLECTION)
         .setType (EdmSimpleTypeKind.String));

   properties.add (new SimpleProperty ().setName (LAST_INGESTION_DATE)
         .setType (EdmSimpleTypeKind.DateTime));

   properties.add (new SimpleProperty ().setName (REQUEST)
         .setType (EdmSimpleTypeKind.String)
         .setFacets (
            new Facets ()
               .setNullable (false)
               .setDefaultValue ("stop")
         )
   );

   properties.add (new SimpleProperty ().setName (STATUS)
         .setType (EdmSimpleTypeKind.String)
         .setFacets (new Facets ().setNullable (false)));

   properties.add (new SimpleProperty ().setName (STATUS_DATE)
         .setType (EdmSimpleTypeKind.DateTime));

   properties.add (new SimpleProperty ().setName (STATUS_MESSAGE)
         .setType (EdmSimpleTypeKind.String));

   // Navigation Properties
   List<NavigationProperty> navigationProperties = Collections.singletonList (
      new NavigationProperty ()
         .setName (TARGET_COLLECTION)
         .setRelationship (ASSO_SYNC_COLLECTION)
         .setFromRole (ROLE_COLLECTION_SYNCS)
         .setToRole (ROLE_SYNC_COLLECTION)
   );

   // Key
   Key key = new Key ().setKeys (
         Collections.singletonList (new PropertyRef ().setName (ID)));

   return new EntityType ().setName (ENTITY_NAME).setProperties (properties)
         .setNavigationProperties (navigationProperties).setKey (key);
}
 
Example #20
Source File: EdmEntitySetProvTest.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);

  EntityContainerInfo entityContainer = new EntityContainerInfo().setName("Container");
  when(edmProvider.getEntityContainerInfo("Container")).thenReturn(entityContainer);
  EdmEntityContainerImplProv edmEntityContainer = new EdmEntityContainerImplProv(edmImplProv, entityContainer);

  EntitySet entitySetFoo = new EntitySet().setName("foo");
  when(edmProvider.getEntitySet("Container", "foo")).thenReturn(entitySetFoo);

  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");
  entitySetFoo.setEntityType(fooEntityTypeFullName);
  when(edmProvider.getEntityType(fooEntityTypeFullName)).thenReturn(fooEntityType);

  EntitySet entitySetBar = new EntitySet().setName("bar");
  when(edmProvider.getEntitySet("Container", "bar")).thenReturn(entitySetBar);

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

  AssociationEnd fooEnd = new AssociationEnd().setRole("fromFoo");
  AssociationEnd barEnd = new AssociationEnd().setRole("toBar");

  Association fooBarAssoc = new Association().setName("fooBarAssoc").setEnd1(fooEnd).setEnd2(barEnd);
  when(edmProvider.getAssociation(fooBarAssocName)).thenReturn(fooBarAssoc);

  AssociationSet associationSet =
      new AssociationSet().setName("fooBarRelation").setEnd1(
          new AssociationSetEnd().setRole("fromFoo").setEntitySet("foo")).setEnd2(
          new AssociationSetEnd().setRole("toBar").setEntitySet("bar"));
  FullQualifiedName assocFQName = new FullQualifiedName("namespace", "fooBarAssoc");
  when(edmProvider.getAssociationSet("Container", assocFQName, "foo", "fromFoo")).thenReturn(associationSet);

  edmEntitySetFoo = new EdmEntitySetImplProv(edmImplProv, entitySetFoo, edmEntityContainer);
  edmEnitiySetBar = new EdmEntitySetImplProv(edmImplProv, entitySetBar, edmEntityContainer);
}
 
Example #21
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");

}
 
Example #22
Source File: EdmNavigationPropertyImplProv.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
public EdmNavigationPropertyImplProv(final EdmImplProv edm, final NavigationProperty property) throws EdmException {
  super(edm, property.getName(), null, null);
  navigationProperty = property;
}
 
Example #23
Source File: EdmEntityTypeImplProv.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
protected EdmTyped createNavigationProperty(final NavigationProperty property) throws EdmException {
  return new EdmNavigationPropertyImplProv(edm, property);
}
 
Example #24
Source File: UserEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public EntityType getEntityType ()
{
   // Properties
   List<Property> properties = new ArrayList<Property> ();

   properties.add (new SimpleProperty ()
      .setName (USERNAME)
      .setType (EdmSimpleTypeKind.String)
      .setFacets (new Facets ().setNullable (false))
      .setCustomizableFeedMappings (
         new CustomizableFeedMappings ()
            .setFcTargetPath (EdmTargetPath.SYNDICATION_TITLE)));

   properties.add (new SimpleProperty ().setName (EMAIL).setType (
      EdmSimpleTypeKind.String));
   properties.add (new SimpleProperty ().setName (FIRSTNAME).setType (
      EdmSimpleTypeKind.String));
   properties.add (new SimpleProperty ().setName (LASTNAME).setType (
      EdmSimpleTypeKind.String));
   properties.add (new SimpleProperty ().setName (COUNTRY).setType (
      EdmSimpleTypeKind.String));
   properties.add (new SimpleProperty ().setName (PHONE).setType (
      EdmSimpleTypeKind.String));
   properties.add (new SimpleProperty ().setName (ADDRESS).setType (
      EdmSimpleTypeKind.String));
   properties.add (new SimpleProperty ().setName (DOMAIN).setType (
      EdmSimpleTypeKind.String));
   properties.add (new SimpleProperty ().setName (SUBDOMAIN).setType (
      EdmSimpleTypeKind.String));
   properties.add (new SimpleProperty ().setName (USAGE).setType (
      EdmSimpleTypeKind.String));
   properties.add (new SimpleProperty ().setName (SUBUSAGE).setType (
      EdmSimpleTypeKind.String));
   properties.add(new SimpleProperty().setName(HASH)
         .setType(EdmSimpleTypeKind.String));
   properties.add(new SimpleProperty().setName(PASSWORD)
         .setType(EdmSimpleTypeKind.String));
   properties.add(new SimpleProperty().setName(CREATED)
         .setType(EdmSimpleTypeKind.DateTime)
         .setCustomizableFeedMappings(new CustomizableFeedMappings()
               .setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));

   // Navigation Properties
   List<NavigationProperty> navigationProperties =
      new ArrayList<NavigationProperty> ();

   if (Security.currentUserHasRole(Role.SYSTEM_MANAGER, Role.STATISTICS))
   {
      navigationProperties.add (new NavigationProperty ()
         .setName(Model.CONNECTION.getName())
         .setRelationship(ASSO_USER_CONNECTION)
         .setFromRole(ROLE_CONNECTION_USER)
         .setToRole(ROLE_USER_CONNECTIONS));
   }

   // navigate to user restrictions
   navigationProperties.add (new NavigationProperty ()
         .setName(Model.RESTRICTION.getName())
         .setRelationship (ASSO_USER_RESTRICTION)
         .setFromRole (ROLE_RESTRICTION_USER)
         .setToRole (ROLE_USER_RESTRICTIONS));

   // navigate to user roles
   navigationProperties.add (new NavigationProperty ()
         .setName(Model.SYSTEM_ROLE.getName())
         .setRelationship (ASSO_USER_SYSTEMROLE)
         .setFromRole (ROLE_SYSTEMROLE_USER)
         .setToRole (ROLE_USER_SYSTEMROLES));

   // navigate to Products (user cart)
   navigationProperties.add(new NavigationProperty()
         .setName(CART)
         .setRelationship(ASSO_USER_PRODUCT)
         .setFromRole(ROLE_PRODUCTS_USER)
         .setToRole(ROLE_USER_PRODUCTS));

   // Key
   Key key =
      new Key ().setKeys (Collections.singletonList (new PropertyRef ()
         .setName (USERNAME)));

   return new EntityType ().setName (ENTITY_NAME).setProperties (properties)
      .setKey (key).setNavigationProperties (navigationProperties);
}
 
Example #25
Source File: ProductEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public EntityType getEntityType ()
{
   EntityType res = Model.NODE.getEntityType();

   // Properties
   List<Property> properties = res.getProperties ();

   properties.add (new SimpleProperty ().setName (CREATION_DATE)
      .setType (EdmSimpleTypeKind.DateTime)
      .setFacets (new Facets ().setNullable (false)));
   properties.add (new SimpleProperty ()
      .setName (INGESTION_DATE)
      .setType (EdmSimpleTypeKind.DateTime)
      .setCustomizableFeedMappings (
         new CustomizableFeedMappings ()
            .setFcTargetPath (EdmTargetPath.SYNDICATION_UPDATED)));
   properties.add (new SimpleProperty ().setName (EVICTION_DATE).setType (
      EdmSimpleTypeKind.DateTime));
   properties.add(new ComplexProperty().setName(CONTENT_DATE).setType(Model.TIME_RANGE));
   properties.add(new ComplexProperty().setName(CHECKSUM).setType(Model.CHECKSUM));
   properties.add (new SimpleProperty ().setName (CONTENT_GEOMETRY).setType (
      EdmSimpleTypeKind.String));
   properties.add (new SimpleProperty ().setName (METALINK).setType (
      EdmSimpleTypeKind.String));

   if (Security.currentUserHasRole(Role.ARCHIVE_MANAGER))
   {
      properties.add (new SimpleProperty ().setName (LOCAL_PATH).setType (
         EdmSimpleTypeKind.String));
   }

   // Navigation Properties
   List<NavigationProperty> navigationProperties =
      new ArrayList<NavigationProperty> ();

   navigationProperties.add (new NavigationProperty ().setName (getName ())
      .setRelationship (ASSO_PRODUCT_PRODUCT)
      .setFromRole (ROLE_PRODUCT_PRODUCT).setToRole (ROLE_PRODUCT_PRODUCTS));
   navigationProperties.add (new NavigationProperty ()
      .setName(Model.NODE.getName()).setRelationship(ASSO_PRODUCT_NODE)
      .setFromRole (ROLE_NODE_PRODUCT).setToRole (ROLE_PRODUCT_NODES));
   navigationProperties.add (new NavigationProperty ()
      .setName(Model.ATTRIBUTE.getName())
      .setRelationship (ASSO_PRODUCT_ATTRIBUTE)
      .setFromRole (ROLE_ATTRIBUTE_PRODUCT)
      .setToRole (ROLE_PRODUCT_ATTRIBUTES));
   navigationProperties.add (new NavigationProperty ().setName ("Class")
      .setRelationship (ASSO_PRODUCT_CLASS)
      .setFromRole (ROLE_CLASS_PRODUCTS).setToRole (ROLE_PRODUCT_CLASS));

   // TODO (OData v3) setContainsTarget(true) setBaseType(ENTITY_ITEM)
   return res.setName (ENTITY_NAME).setProperties (properties)
      .setHasStream (true).setNavigationProperties (navigationProperties);
}
 
Example #26
Source File: ConnectionEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public EntityType getEntityType ()
{
   // Properties
   List<Property> properties = new ArrayList<Property> ();

   properties.add (new SimpleProperty ()
      .setName (ID)
      .setType (EdmSimpleTypeKind.String)
      .setFacets (new Facets ().setNullable (false))
      .setCustomizableFeedMappings (
         new CustomizableFeedMappings ()
            .setFcTargetPath (EdmTargetPath.SYNDICATION_TITLE)));

   properties.add (new SimpleProperty ().setName (DATE).setType (
      EdmSimpleTypeKind.DateTime));
   properties.add (new SimpleProperty ().setName (REMOTEIP).setType (
      EdmSimpleTypeKind.String));
   properties.add (new SimpleProperty ().setName (REQUEST).setType (
      EdmSimpleTypeKind.String));
   properties.add (new SimpleProperty ().setName (DURATION).setType (
      EdmSimpleTypeKind.Double));
   properties.add (new SimpleProperty ().setName (CONTENT_LENGTH).setType (
      EdmSimpleTypeKind.Int64));
   properties.add (new SimpleProperty ().setName (WRITTEN_CONTENT_LENGTH).
      setType (EdmSimpleTypeKind.Int64));
   properties.add (new SimpleProperty ().setName (STATUS).setType (
         EdmSimpleTypeKind.String));
   properties.add (new SimpleProperty ().setName (STATUS_MESSAGE).setType (
         EdmSimpleTypeKind.String).
         setFacets (new Facets ().setNullable (true)));

   // Navigation Properties
   List<NavigationProperty> navigationProperties =
      new ArrayList<NavigationProperty> ();

   if (Security.currentUserHasRole(Role.SYSTEM_MANAGER))
   {
   navigationProperties.add (new NavigationProperty ().setName ("User")
      .setRelationship (ASSO_CONNECTION_USER)
      .setFromRole (ROLE_USER_CONNECTIONS).setToRole (ROLE_CONNECTION_USER));
   }

   // Key
   Key key =
      new Key ().setKeys (Collections.singletonList (new PropertyRef ()
         .setName (ID)));

   return new EntityType ().setName (ENTITY_NAME).setProperties (properties)
      .setKey (key).setNavigationProperties (navigationProperties);
}
 
Example #27
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private EntityType readEntityType(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ENTITY_TYPE);
  EntityType entityType = new EntityType();
  List<Property> properties = new ArrayList<Property>();
  List<NavigationProperty> navPropertiesList = new ArrayList<NavigationProperty>();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  Key key = null;

  entityType.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  String hasStream = reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, XmlMetadataConstants.M_ENTITY_TYPE_HAS_STREAM);
  if (hasStream != null) {
    entityType.setHasStream("true".equalsIgnoreCase(hasStream));
  }

  if (reader.getAttributeValue(null, XmlMetadataConstants.EDM_TYPE_ABSTRACT) != null) {
    entityType.setAbstract("true".equalsIgnoreCase(reader.getAttributeValue(null,
        XmlMetadataConstants.EDM_TYPE_ABSTRACT)));
  }
  String baseType = reader.getAttributeValue(null, XmlMetadataConstants.EDM_BASE_TYPE);
  if (baseType != null) {
    entityType.setBaseType(extractFQName(baseType));
  }
  entityType.setCustomizableFeedMappings(readCustomizableFeedMappings(reader));
  entityType.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext()
      && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_ENTITY_TYPE.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      currentHandledStartTagName = reader.getLocalName();
      if (XmlMetadataConstants.EDM_ENTITY_TYPE_KEY.equals(currentHandledStartTagName)) {
        key = readEntityTypeKey(reader);
      } else if (XmlMetadataConstants.EDM_PROPERTY.equals(currentHandledStartTagName)) {
        properties.add(readProperty(reader));
      } else if (XmlMetadataConstants.EDM_NAVIGATION_PROPERTY.equals(currentHandledStartTagName)) {
        navPropertiesList.add(readNavigationProperty(reader));
      } else {
        annotationElements.add(readAnnotationElement(reader));
      }
      extractNamespaces(reader);
    }
  }
  if (!annotationElements.isEmpty()) {
    entityType.setAnnotationElements(annotationElements);
  }
  entityType.setKey(key).setProperties(properties).setNavigationProperties(navPropertiesList);
  if (entityType.getName() != null) {
    FullQualifiedName fqName = new FullQualifiedName(currentNamespace, entityType.getName());
    entityTypesMap.put(fqName, entityType);
  } else {
    throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE.addContent("Name"));
  }
  return entityType;
}
 
Example #28
Source File: JPAEdmTestModelView.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public NavigationProperty getEdmNavigationProperty() {
  return null;
}
 
Example #29
Source File: JPAEdmTestModelView.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public List<NavigationProperty> getConsistentEdmNavigationProperties() {
  return null;
}
 
Example #30
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());
    }

  }
}