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

The following examples show how to use org.apache.olingo.odata2.api.edm.provider.PropertyRef. 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: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBaseType() throws XMLStreamException, EntityProviderException {
  int i = 0;
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xmlWithBaseType);
  DataServices result = parser.readMetadata(reader, true);
  assertEquals("2.0", result.getDataServiceVersion());
  for (Schema schema : result.getSchemas()) {
    assertEquals(NAMESPACE, schema.getNamespace());
    assertEquals(2, schema.getEntityTypes().size());
    assertEquals("Employee", schema.getEntityTypes().get(0).getName());
    for (PropertyRef propertyRef : schema.getEntityTypes().get(0).getKey().getKeys()) {
      assertEquals("EmployeeId", propertyRef.getName());
    }
    for (Property property : schema.getEntityTypes().get(0).getProperties()) {
      assertEquals(propertyNames[i], property.getName());
      i++;
    }

  }
}
 
Example #3
Source File: EdmEntityTypeImplProv.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public List<String> getKeyPropertyNames() throws EdmException {
  if (edmKeyPropertyNames == null) {
    if (edmBaseType != null) {
      return ((EdmEntityType) edmBaseType).getKeyPropertyNames();
    }

    edmKeyPropertyNames = new ArrayList<String>();

    if (entityType.getKey() != null) {
      for (final PropertyRef keyProperty : entityType.getKey().getKeys()) {
        edmKeyPropertyNames.add(keyProperty.getName());
      }
    } else {
      // Entity Type does not define a key
      throw new EdmException(EdmException.COMMON);
    }
  }

  return edmKeyPropertyNames;
}
 
Example #4
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private PropertyRef readPropertyRef(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_PROPERTY_REF);
  PropertyRef propertyRef = new PropertyRef();
  propertyRef.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  propertyRef.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_PROPERTY_REF.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      annotationElements.add(readAnnotationElement(reader));
    }
  }
  if (!annotationElements.isEmpty()) {
    propertyRef.setAnnotationElements(annotationElements);
  }
  return propertyRef;
}
 
Example #5
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private Key readEntityTypeKey(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ENTITY_TYPE_KEY);
  List<PropertyRef> keys = new ArrayList<PropertyRef>();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  List<AnnotationAttribute> annotationAttributes = readAnnotationAttribute(reader);
  while (reader.hasNext()
      && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_ENTITY_TYPE_KEY.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      currentHandledStartTagName = reader.getLocalName();
      if (XmlMetadataConstants.EDM_PROPERTY_REF.equals(currentHandledStartTagName)) {
        reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_PROPERTY_REF);
        keys.add(readPropertyRef(reader));
      } else {
        annotationElements.add(readAnnotationElement(reader));
      }
    }
  }
  Key key = new Key().setKeys(keys).setAnnotationAttributes(annotationAttributes);
  if (!annotationElements.isEmpty()) {
    key.setAnnotationElements(annotationElements);
  }
  return key;
}
 
Example #6
Source File: JPAEdmKey.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public void normalizeComplexKey(final ComplexType complexType, final List<PropertyRef> propertyRefList) {
  for (Property property : complexType.getProperties()) {
    try {

      SimpleProperty simpleProperty = (SimpleProperty) property;
      Facets facets = (Facets) simpleProperty.getFacets();
      if (facets == null) {
        simpleProperty.setFacets(new Facets().setNullable(false));
      } else {
        facets.setNullable(false);
      }
      PropertyRef propertyRef = new PropertyRef();
      propertyRef.setName(simpleProperty.getName());
      propertyRefList.add(propertyRef);

    } catch (ClassCastException e) {
      ComplexProperty complexProperty = (ComplexProperty) property;
      normalizeComplexKey(complexTypeView.searchEdmComplexType(complexProperty.getType()), propertyRefList);
    }

  }
}
 
Example #7
Source File: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void entityTypeAbstractBaseType() throws Exception {
  // validate employee
  EntityType baseType = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Base"));
  assertEquals("Base", baseType.getName());
  final List<PropertyRef> keys = baseType.getKey().getKeys();
  assertEquals(1, keys.size());
  assertEquals("Id", keys.get(0).getName());
  assertEquals(2, baseType.getProperties().size());
  assertTrue(baseType.isAbstract());

  // validate base for 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());
}
 
Example #8
Source File: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void loadAnnotatedClassesFromPackage() throws Exception {
  AnnotationEdmProvider localAep = new AnnotationEdmProvider(TEST_MODEL_PACKAGE);

  // validate employee
  EntityType employee = localAep.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());

  List<Schema> schemas = localAep.getSchemas();
  assertEquals(1, schemas.size());
  EntityContainerInfo info = localAep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1);
  assertTrue(info.isDefaultEntityContainer());
}
 
Example #9
Source File: EdmAssociationImplProvTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void getEdmEntityContainerImpl() throws Exception {

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

  AssociationEnd end1 =
      new AssociationEnd().setRole("end1Role").setMultiplicity(EdmMultiplicity.ONE).setType(
          EdmSimpleTypeKind.String.getFullQualifiedName());
  AssociationEnd end2 =
      new AssociationEnd().setRole("end2Role").setMultiplicity(EdmMultiplicity.ONE).setType(
          EdmSimpleTypeKind.String.getFullQualifiedName());

  List<PropertyRef> propRef = new ArrayList<PropertyRef>();
  propRef.add(new PropertyRef().setName("prop1"));
  List<PropertyRef> propRef2 = new ArrayList<PropertyRef>();
  propRef2.add(new PropertyRef().setName("prop2"));

  ReferentialConstraintRole dependent = new ReferentialConstraintRole().setRole("end1Role");
  ReferentialConstraintRole principal = new ReferentialConstraintRole().setRole("end2Role");

  ReferentialConstraint referentialConstraint =
      new ReferentialConstraint().setDependent(dependent).setPrincipal(principal);

  Association association = new Association().setName("association").setEnd1(end1).setEnd2(end2);
  association.setReferentialConstraint(referentialConstraint);

  associationProv = new EdmAssociationImplProv(edmImplProv, association, "namespace");
}
 
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: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testOtherEdmNamespace() throws XMLStreamException, EntityProviderException {
  int i = 0;
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xml2);
  DataServices result = parser.readMetadata(reader, true);
  assertEquals("2.0", result.getDataServiceVersion());
  for (Schema schema : result.getSchemas()) {
    assertEquals(NAMESPACE, schema.getNamespace());
    assertEquals(1, schema.getEntityTypes().size());
    assertEquals("Employee", schema.getEntityTypes().get(0).getName());
    for (PropertyRef propertyRef : schema.getEntityTypes().get(0).getKey().getKeys()) {
      assertEquals("EmployeeId", propertyRef.getName());
    }
    for (Property property : schema.getEntityTypes().get(0).getProperties()) {
      assertEquals(propertyNames[i], property.getName());
      if ("Location".equals(property.getName())) {
        ComplexProperty cProperty = (ComplexProperty) property;
        assertEquals("c_Location", cProperty.getType().getName());
      } else if ("EmployeeName".equals(property.getName())) {
        assertNotNull(property.getCustomizableFeedMappings());
      }
      i++;
    }
    for (AnnotationElement annoElement : schema.getAnnotationElements()) {
      assertEquals("prefix", annoElement.getPrefix());
      assertEquals("namespace", annoElement.getNamespace());
      assertEquals("schemaElement", annoElement.getName());
      assertEquals("text3", annoElement.getText());
    }
  }
}
 
Example #12
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws XMLStreamException, EntityProviderException {
  int i = 0;
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xml);
  DataServices result = parser.readMetadata(reader, true);
  assertEquals("2.0", result.getDataServiceVersion());
  for (Schema schema : result.getSchemas()) {
    assertEquals(NAMESPACE, schema.getNamespace());
    assertEquals(1, schema.getEntityTypes().size());
    assertEquals("Employee", schema.getEntityTypes().get(0).getName());
    assertEquals(Boolean.TRUE, schema.getEntityTypes().get(0).isHasStream());
    for (PropertyRef propertyRef : schema.getEntityTypes().get(0).getKey().getKeys()) {
      assertEquals("EmployeeId", propertyRef.getName());
    }
    for (Property property : schema.getEntityTypes().get(0).getProperties()) {
      assertEquals(propertyNames[i], property.getName());
      if ("Location".equals(property.getName())) {
        ComplexProperty cProperty = (ComplexProperty) property;
        assertEquals(NAMESPACE, cProperty.getType().getNamespace());
        assertEquals("c_Location", cProperty.getType().getName());
      } else if ("EmployeeName".equals(property.getName())) {
        assertNotNull(property.getCustomizableFeedMappings());
        assertEquals("SyndicationTitle", property.getCustomizableFeedMappings().getFcTargetPath());
        assertNull(property.getCustomizableFeedMappings().getFcContentKind());
      }
      i++;
    }
    assertEquals(1, schema.getComplexTypes().size());
    assertEquals("c_Location", schema.getComplexTypes().get(0).getName());
  }
}
 
Example #13
Source File: RestrictionEntitySet.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<> ();

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

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

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

   Key key = new Key ();
   List<PropertyRef> propertyRefs = Collections.singletonList (
         new PropertyRef ().setName (UUID));
   key.setKeys (propertyRefs);

   EntityType entityType = new EntityType ();
   entityType.setName (ENTITY_NAME);
   entityType.setProperties (properties);
   entityType.setKey (key);

   return entityType;
}
 
Example #14
Source File: EdmReferentialConstraintRoleImplProv.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getPropertyRefNames() {
  if (refNames == null) {
    refNames = new ArrayList<String>();
    for (PropertyRef ref : role.getPropertyRefs()) {
      refNames.add(ref.getName());
    }
  }
  return refNames;
}
 
Example #15
Source File: ItemEntitySet.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)));
   properties.add (new SimpleProperty ()
      .setName (NAME)
      .setType (EdmSimpleTypeKind.String)
      .setCustomizableFeedMappings (
         new CustomizableFeedMappings ()
            .setFcTargetPath (EdmTargetPath.SYNDICATION_TITLE)));
   properties.add (new SimpleProperty ().setName (CONTENT_TYPE).setType (
      EdmSimpleTypeKind.String));
   properties.add (new SimpleProperty ().setName (CONTENT_LENGTH).setType (
      EdmSimpleTypeKind.Int64));

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

   // TODO (OData v3) setOpenType(true) setAbstract(true)
   return new EntityType ().setName (ENTITY_NAME).setProperties (properties)
      .setKey (key);
}
 
Example #16
Source File: EdmTestProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private Key getKey(final String... keyNames) {
  final List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
  for (final String keyName : keyNames) {
    keyProperties.add(new PropertyRef().setName(keyName));
  }
  return new Key().setKeys(keyProperties);
}
 
Example #17
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private ReferentialConstraintRole readReferentialConstraintRole(final XMLStreamReader reader)
    throws EntityProviderException, XMLStreamException {
  ReferentialConstraintRole rcRole = new ReferentialConstraintRole();
  rcRole.setRole(reader.getAttributeValue(null, XmlMetadataConstants.EDM_ROLE));
  List<PropertyRef> propertyRefs = new ArrayList<PropertyRef>();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  rcRole.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && (XmlMetadataConstants.EDM_ASSOCIATION_PRINCIPAL.equals(reader.getLocalName())
      || XmlMetadataConstants.EDM_ASSOCIATION_DEPENDENT.equals(reader.getLocalName())))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      currentHandledStartTagName = reader.getLocalName();
      if (XmlMetadataConstants.EDM_PROPERTY_REF.equals(currentHandledStartTagName)) {
        propertyRefs.add(readPropertyRef(reader));
      } else {
        annotationElements.add(readAnnotationElement(reader));
      }
    }
  }
  if (!annotationElements.isEmpty()) {
    rcRole.setAnnotationElements(annotationElements);
  }
  rcRole.setPropertyRefs(propertyRefs);
  return rcRole;
}
 
Example #18
Source File: EdmSchemaMock.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private static Key createKey(final String[] keyNames) {
  Key key = new Key();
  List<PropertyRef> keys = new ArrayList<PropertyRef>();
  for (String keyName : keyNames) {
    keys.add(new PropertyRef().setName(keyName));
  }
  key.setKeys(keys);
  return null;
}
 
Example #19
Source File: NetworkStatisticEntitySet.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)));

   properties.add (new SimpleProperty ()
      .setName (ACTIVITYPERIOD)
      .setType (EdmSimpleTypeKind.Int64));

   properties.add (new SimpleProperty ()
      .setName (CONNECTIONNUMBER)
      .setType (EdmSimpleTypeKind.Int64));
   // Key
   Key key =
      new Key ().setKeys (Collections.singletonList (new PropertyRef ()
         .setName (ID)));

   return new EntityType ().setName (ENTITY_NAME).setProperties (properties)
      .setKey (key);
}
 
Example #20
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 #21
Source File: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private PropertyRef getPropertyRef(final List<PropertyRef> properties, final String name) {
  for (PropertyRef property : properties) {
    if (name.equals(property.getName())) {
      return property;
    }
  }
  return null;
}
 
Example #22
Source File: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void entityTypePhotoWithTwoKeyProperties() throws Exception {
  // validate team
  EntityType photo = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Photo"));
  assertEquals("Photo", photo.getName());
  final List<Property> properties = photo.getProperties();
  assertEquals(5, properties.size());
  assertTrue(containsProperty(properties, "Name"));
  assertTrue(containsProperty(properties, "ImageFormat"));
  assertTrue(containsProperty(properties, "MimeType"));
  assertTrue(containsProperty(properties, "ImageUrl"));
  assertTrue(containsProperty(properties, "Image"));
  assertFalse(photo.isAbstract());
  assertTrue(photo.isHasStream());
  assertEquals("MimeType",photo.getMapping().getMediaResourceMimeTypeKey());
  assertEquals("ImageUrl",photo.getMapping().getMediaResourceSourceKey());

  Key photoKey = photo.getKey();
  List<PropertyRef> keyReferences = photoKey.getKeys();
  assertEquals(2, keyReferences.size());
  PropertyRef name = getPropertyRef(keyReferences, "Name");
  assertEquals("Name", name.getName());
  PropertyRef imageFormat = getPropertyRef(keyReferences, "ImageFormat");
  assertEquals("ImageFormat", imageFormat.getName());

  // assertEquals(0, photo.getNavigationProperties().size());
  assertNull(photo.getNavigationProperties());
}
 
Example #23
Source File: TechnicalScenarioEdmProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private Key createKey(final String... keyNames) {
  final List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
  for (final String keyName : keyNames) {
    keyProperties.add(new PropertyRef().setName(keyName));
  }
  return new Key().setKeys(keyProperties);
}
 
Example #24
Source File: AnnotationEdmProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private PropertyRef createKeyProperty(final EdmProperty et, final Field field) {
  PropertyRef keyProperty = new PropertyRef();
  String entityName = et.name();
  if (entityName.isEmpty()) {
    entityName = getCanonicalName(field);
  }
  return keyProperty.setName(entityName);
}
 
Example #25
Source File: EdmReferentialConstraintRoleImplProvTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void getEdmEntityContainerImpl() throws Exception {
  List<PropertyRef> propertyRefs = new ArrayList<PropertyRef>();
  PropertyRef propertyRef = new PropertyRef().setName("ID");
  propertyRefs.add(propertyRef);

  ReferentialConstraintRole dependent = new ReferentialConstraintRole()
      .setRole("end1Role")
      .setPropertyRefs(propertyRefs);

  referentialConstraintRoleProv = new EdmReferentialConstraintRoleImplProv(dependent);
}
 
Example #26
Source File: SystemRoleEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public EntityType getEntityType ()
{
   Key key = new Key ();
   List<PropertyRef> property_refs =
         Collections.singletonList (new PropertyRef ().setName (NAME));
   key.setKeys (property_refs);

   SimpleProperty name = new SimpleProperty ();
   name.setName (NAME);
   name.setType (EdmSimpleTypeKind.String);
   name.setFacets (new Facets ().setNullable (false));
   name.setCustomizableFeedMappings (new CustomizableFeedMappings ()
         .setFcTargetPath (EdmTargetPath.SYNDICATION_TITLE));

   SimpleProperty description = new SimpleProperty ();
   description.setName (DESCRIPTION);
   description.setType (EdmSimpleTypeKind.String);
   description.setFacets (new Facets ().setNullable (false));

   List<Property> properties = new ArrayList<> ();
   properties.add (name);
   properties.add (description);

   EntityType entityType = new EntityType ();
   entityType.setName (ENTITY_NAME);
   entityType.setProperties (properties);
   entityType.setKey (key);

   return entityType;
}
 
Example #27
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 #28
Source File: ScenarioEdmProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private Key getKey(final String... keyNames) {
  List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
  for (final String keyName : keyNames) {
    keyProperties.add(new PropertyRef().setName(keyName));
  }
  return new Key().setKeys(keyProperties);
}
 
Example #29
Source File: EdmTestProvider.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public Association getAssociation(final FullQualifiedName edmFQName) throws ODataException {
  if (NAMESPACE_1.equals(edmFQName.getNamespace())) {
    if (ASSOCIATION_1_1.getName().equals(edmFQName.getName())) {
      return new Association().setName(ASSOCIATION_1_1.getName())
          .setEnd1(
              new AssociationEnd().setType(ENTITY_TYPE_1_1).setRole(ROLE_1_1).setMultiplicity(EdmMultiplicity.MANY))
          .setEnd2(
              new AssociationEnd().setType(ENTITY_TYPE_1_4).setRole(ROLE_1_4).setMultiplicity(EdmMultiplicity.ONE));
    } else if (ASSOCIATION_1_2.getName().equals(edmFQName.getName())) {
      return new Association().setName(ASSOCIATION_1_2.getName())
          .setEnd1(
              new AssociationEnd().setType(ENTITY_TYPE_1_1).setRole(ROLE_1_1).setMultiplicity(EdmMultiplicity.MANY))
          .setEnd2(
              new AssociationEnd().setType(ENTITY_TYPE_1_2).setRole(ROLE_1_2).setMultiplicity(EdmMultiplicity.ONE));
    } else if (ASSOCIATION_1_3.getName().equals(edmFQName.getName())) {
      return new Association().setName(ASSOCIATION_1_3.getName())
          .setEnd1(
              new AssociationEnd().setType(ENTITY_TYPE_1_1).setRole(ROLE_1_1).setMultiplicity(EdmMultiplicity.MANY))
          .setEnd2(
              new AssociationEnd().setType(ENTITY_TYPE_1_3).setRole(ROLE_1_3).setMultiplicity(EdmMultiplicity.ONE));
    } else if (ASSOCIATION_1_4.getName().equals(edmFQName.getName())) {
      final List<PropertyRef> propertyRefsPrincipal = new ArrayList<PropertyRef>();
      propertyRefsPrincipal.add(new PropertyRef().setName("Id"));
      propertyRefsPrincipal.add(new PropertyRef().setName("Id2"));
      final List<PropertyRef> propertyRefsDependent = new ArrayList<PropertyRef>();
      propertyRefsDependent.add(new PropertyRef().setName("Id"));
      propertyRefsDependent.add(new PropertyRef().setName("Id2"));
      return new Association().setName(ASSOCIATION_1_4.getName())
          .setEnd1(
              new AssociationEnd().setType(ENTITY_TYPE_1_5).setRole(ROLE_1_5).setMultiplicity(EdmMultiplicity.ONE))
          .setEnd2(
              new AssociationEnd().setType(ENTITY_TYPE_1_3).setRole(ROLE_1_3).setMultiplicity(EdmMultiplicity.MANY))
          .setReferentialConstraint(
              new ReferentialConstraint().setPrincipal(
                  new ReferentialConstraintRole().setRole("BuildingToRoom").setPropertyRefs(propertyRefsPrincipal))
                  .setDependent(
                      new ReferentialConstraintRole().setRole("RoomToBuilding")
                          .setPropertyRefs(propertyRefsDependent)));
    }
  }
  return null;
}
 
Example #30
Source File: MapProvider.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private void buildSchema() {
  propertyRef = new PropertyRef();
  propertyRef.setName("p1");

  key = new Key();
  key.setKeys(Arrays.asList(propertyRef));

  property1 =
      new SimpleProperty().setName(mapping[P1][EDM]).setType(EdmSimpleTypeKind.String).setMapping(
          new Mapping().setObject(mapping[P1][BACKEND]));
  property2 =
      new SimpleProperty().setName(mapping[P2][EDM]).setType(EdmSimpleTypeKind.String).setMapping(
          new Mapping().setObject(mapping[P2][BACKEND]));
  property3 =
      new SimpleProperty().setName(mapping[P3][EDM]).setType(EdmSimpleTypeKind.String).setMapping(
          new Mapping().setObject(mapping[P3][BACKEND]));

  entityType = new EntityType();
  entityType.setName(mapping[ENTITYTYPE][EDM]);
  entityType.setKey(key);
  entityType.setProperties(Arrays.asList(property1, property2, property3));
  entityType.setMapping(new Mapping().setObject(mapping[ENTITYTYPE][BACKEND]));

  entitySet = new EntitySet();
  entitySet.setName(mapping[ENTITYSET][EDM]);
  entitySet.setEntityType(new FullQualifiedName(NAMESPACE, mapping[ENTITYTYPE][EDM]));
  entitySet.setMapping(new Mapping().setObject(mapping[ENTITYSET][BACKEND]));

  entityContainer = new EntityContainer();
  entityContainer.setDefaultEntityContainer(true);
  entityContainer.setName(MAPPING_CONTAINER);
  entityContainer.setEntitySets(Arrays.asList(entitySet));

  schema = new Schema();
  schema.setNamespace("mapping");
  schema.setAlias(NAMESPACE);
  schema.setEntityContainers(Arrays.asList(entityContainer));
  schema.setEntityTypes(Arrays.asList(entityType));

  schemas = Arrays.asList(schema);
}