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

The following examples show how to use org.apache.olingo.odata2.api.edm.provider.ComplexProperty. 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: 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 #2
Source File: JPAEdmNameBuilder.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public static void build(final JPAEdmComplexPropertyView complexView,
    final String parentComplexTypeName, final boolean skipDefaultNaming) {
  ComplexProperty complexProperty = complexView.getEdmComplexProperty();

  JPAEdmMappingModelAccess mappingModelAccess = complexView.getJPAEdmMappingModelAccess();
  JPAEdmPropertyView propertyView = ((JPAEdmPropertyView) complexView);
  String jpaAttributeName = propertyView.getJPAAttribute().getName();
  String propertyName = null;
  if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
    propertyName = mappingModelAccess.mapJPAEmbeddableTypeAttribute(parentComplexTypeName, jpaAttributeName);
  }
  if (skipDefaultNaming == false && propertyName == null) {
    propertyName = Character.toUpperCase(jpaAttributeName.charAt(0)) + jpaAttributeName.substring(1);
  } else if (propertyName == null) {
    propertyName = jpaAttributeName;
  }

  JPAEdmMapping mapping = new JPAEdmMappingImpl();
  ((Mapping) mapping).setInternalName(jpaAttributeName);
  mapping.setJPAType(propertyView.getJPAAttribute().getJavaType());
  complexProperty.setMapping((Mapping) mapping);
  complexProperty.setName(propertyName);

}
 
Example #3
Source File: JPAEdmNameBuilderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testBuildJPAEdmComplexPropertyViewWithNoDefaultNaming() {
  JPAEdmComplexPropertyView complexPropertyView = EasyMock.createMock(JPAEdmComplexPropertyView.class);
  ComplexProperty complexProperty = new ComplexProperty();
  EasyMock.expect(complexPropertyView.getEdmComplexProperty()).andStubReturn(complexProperty);
  ODataJPAContextImpl oDataJPAContext = new ODataJPAContextImpl();
  JPAEdmMappingModelService mappingModelService = new JPAEdmMappingModelService(oDataJPAContext);
  EasyMock.expect(complexPropertyView.getJPAEdmMappingModelAccess()).andStubReturn(mappingModelService);

  // Mocking EDMProperty
  JPAEdmPropertyView propertyView = EasyMock.createMock(JPAEdmPropertyView.class);
  JPAEdmEntityTypeView entityTypeView = EasyMock.createMock(JPAEdmEntityTypeView.class);
  EasyMock.expect(entityTypeView.getJPAEntityType()).andStubReturn(new JPAEntityType());
  EasyMock.replay(entityTypeView);
  EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JPAAttribute());
  EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView);
  EasyMock.replay(complexPropertyView);
  EasyMock.replay(propertyView);

  JPAEdmNameBuilder.build(complexPropertyView, propertyView, true);
  assertEquals("id", complexPropertyView.getEdmComplexProperty().getName());

}
 
Example #4
Source File: JPAEdmNameBuilderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testBuildJPAEdmComplexPropertyView() {
  JPAEdmComplexPropertyView complexPropertyView = EasyMock.createMock(JPAEdmComplexPropertyView.class);
  ComplexProperty complexProperty = new ComplexProperty();
  EasyMock.expect(complexPropertyView.getEdmComplexProperty()).andStubReturn(complexProperty);
  ODataJPAContextImpl oDataJPAContext = new ODataJPAContextImpl();
  JPAEdmMappingModelService mappingModelService = new JPAEdmMappingModelService(oDataJPAContext);
  EasyMock.expect(complexPropertyView.getJPAEdmMappingModelAccess()).andStubReturn(mappingModelService);

  // Mocking EDMProperty
  JPAEdmPropertyView propertyView = EasyMock.createMock(JPAEdmPropertyView.class);
  JPAEdmEntityTypeView entityTypeView = EasyMock.createMock(JPAEdmEntityTypeView.class);
  EasyMock.expect(entityTypeView.getJPAEntityType()).andStubReturn(new JPAEntityType());
  EasyMock.replay(entityTypeView);
  EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JPAAttribute());
  EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView);
  EasyMock.replay(complexPropertyView);
  EasyMock.replay(propertyView);

  JPAEdmNameBuilder.build(complexPropertyView, propertyView, false);
  assertEquals("Id", complexPropertyView.getEdmComplexProperty().getName());

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

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

  Mapping propertySimpleMapping = new Mapping().setInternalName("value");
  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);

  Facets facets = new Facets().setNullable(false);
  SimpleProperty propertySimpleWithFacets =
      new SimpleProperty().setName("PropertyName").setType(EdmSimpleTypeKind.String).setFacets(facets);
  propertySimpleWithFacetsProvider = new EdmSimplePropertyImplProv(edmImplProv, propertySimpleWithFacets);

  Facets facets2 = new Facets().setNullable(true);
  SimpleProperty propertySimpleWithFacets2 =
      new SimpleProperty().setName("PropertyName").setType(EdmSimpleTypeKind.String).setFacets(facets2);
  propertySimpleWithFacetsProvider2 = new EdmSimplePropertyImplProv(edmImplProv, propertySimpleWithFacets2);

  ComplexType complexType = new ComplexType().setName("complexType");
  FullQualifiedName complexName = new FullQualifiedName("namespace", "complexType");
  when(edmProvider.getComplexType(complexName)).thenReturn(complexType);

  ComplexProperty propertyComplex = new ComplexProperty().setName("complexProperty").setType(complexName);
  propertyComplexProvider = new EdmComplexPropertyImplProv(edmImplProv, propertyComplex);

}
 
Example #6
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 #7
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 #8
Source File: EdmStructuralTypeImplProv.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
protected EdmTyped createProperty(final Property property) throws EdmException {
  if (property instanceof SimpleProperty) {
    return new EdmSimplePropertyImplProv(edm, (SimpleProperty) property);
  } else if (property instanceof ComplexProperty) {
    return new EdmComplexPropertyImplProv(edm, (ComplexProperty) property);
  } else {
    throw new EdmException(EdmException.COMMON);
  }
}
 
Example #9
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private Property readComplexProperty(final XMLStreamReader reader, final FullQualifiedName fqName)
    throws XMLStreamException {
  ComplexProperty property = new ComplexProperty();
  property.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  property.setType(fqName);
  return property;
}
 
Example #10
Source File: XmlMetadataProducer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private static void writeProperties(final Collection<Property> properties,
    final Map<String, String> predefinedNamespaces, final XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
  for (Property property : properties) {
    xmlStreamWriter.writeStartElement(XmlMetadataConstants.EDM_PROPERTY);
    xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_NAME, property.getName());
    if (property instanceof SimpleProperty) {
      xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_TYPE, ((SimpleProperty) property).getType()
          .getFullQualifiedName().toString());
    } else if (property instanceof ComplexProperty) {
      xmlStreamWriter
          .writeAttribute(XmlMetadataConstants.EDM_TYPE, ((ComplexProperty) property).getType().toString());
    } else {
      throw new ODataRuntimeException();
    }

    writeFacets(xmlStreamWriter, property.getFacets());

    if (property.getMimeType() != null) {
      xmlStreamWriter.writeAttribute(Edm.PREFIX_M, Edm.NAMESPACE_M_2007_08, XmlMetadataConstants.M_MIMETYPE, property
          .getMimeType());
    }

    writeCustomizableFeedMappings(property.getCustomizableFeedMappings(), xmlStreamWriter);

    writeAnnotationAttributes(property.getAnnotationAttributes(), predefinedNamespaces, null, xmlStreamWriter);

    writeDocumentation(property.getDocumentation(), predefinedNamespaces, xmlStreamWriter);

    writeAnnotationElements(property.getAnnotationElements(), predefinedNamespaces, xmlStreamWriter);

    xmlStreamWriter.writeEndElement();
  }
}
 
Example #11
Source File: JPAEdmNameBuilder.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public static void build(final JPAEdmComplexPropertyView complexView,
    final JPAEdmPropertyView propertyView, final boolean skipDefaultNaming) {

  ComplexProperty complexProperty = complexView.getEdmComplexProperty();

  String jpaAttributeName = propertyView.getJPAAttribute().getName();
  String jpaEntityTypeName = propertyView.getJPAEdmEntityTypeView().getJPAEntityType().getName();

  JPAEdmMappingModelAccess mappingModelAccess = complexView.getJPAEdmMappingModelAccess();
  String propertyName = null;

  if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
    propertyName = mappingModelAccess.mapJPAAttribute(jpaEntityTypeName, jpaAttributeName);
  }

  if (skipDefaultNaming == false && propertyName == null) {
    propertyName = Character.toUpperCase(jpaAttributeName.charAt(0)) + jpaAttributeName.substring(1);
  } else if (propertyName == null) {
    propertyName = jpaAttributeName;
  }

  // change for navigation property issue
  JPAEdmMapping mapping = new JPAEdmMappingImpl();
  ((Mapping) mapping).setInternalName(jpaAttributeName);
  mapping.setJPAType(propertyView.getJPAAttribute().getJavaType());
  complexProperty.setMapping((Mapping) mapping);

  complexProperty.setName(propertyName);

}
 
Example #12
Source File: JPAEdmComplexType.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public void expandEdmComplexType(final ComplexType complexType, List<Property> expandedList,
    final String embeddablePropertyName) {

  if (expandedList == null) {
    expandedList = new ArrayList<Property>();
  }
  for (Property property : complexType.getProperties()) {
    try {
      SimpleProperty newSimpleProperty = new SimpleProperty();
      SimpleProperty oldSimpleProperty = (SimpleProperty) property;
      newSimpleProperty.setAnnotationAttributes(oldSimpleProperty.getAnnotationAttributes());
      newSimpleProperty.setAnnotationElements(oldSimpleProperty.getAnnotationElements());
      newSimpleProperty.setCustomizableFeedMappings(oldSimpleProperty.getCustomizableFeedMappings());
      newSimpleProperty.setDocumentation(oldSimpleProperty.getDocumentation());
      newSimpleProperty.setFacets(oldSimpleProperty.getFacets());
      newSimpleProperty.setMimeType(oldSimpleProperty.getMimeType());
      newSimpleProperty.setName(oldSimpleProperty.getName());
      newSimpleProperty.setType(oldSimpleProperty.getType());
      JPAEdmMappingImpl newMapping = new JPAEdmMappingImpl();
      Mapping mapping = oldSimpleProperty.getMapping();
      JPAEdmMapping oldMapping = (JPAEdmMapping) mapping;
      newMapping.setJPAColumnName(oldMapping.getJPAColumnName());
      newMapping.setInternalName(embeddablePropertyName + "." + mapping.getInternalName());
      newMapping.setObject(mapping.getObject());
      newMapping.setJPAType(oldMapping.getJPAType());
      newSimpleProperty.setMapping(newMapping);
      expandedList.add(newSimpleProperty);
    } catch (ClassCastException e) {
      ComplexProperty complexProperty = (ComplexProperty) property;
      String name = embeddablePropertyName + "." + complexProperty.getMapping().getInternalName();
      expandEdmComplexType(searchComplexTypeByName(complexProperty.getName()), expandedList, name);
    }
  }

}
 
Example #13
Source File: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void defaultNameAndNamespaceGeneration() throws ODataException {
  Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
  localAnnotatedClasses.add(GeneratedNamesTestClass.class);
  localAnnotatedClasses.add(GeneratedNamesComplexTestClass.class);
  AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
  // validate
  EntityType testType = localAep.getEntityType(new FullQualifiedName(
      GeneratedNamesTestClass.class.getPackage().getName(),
      GeneratedNamesTestClass.class.getSimpleName()));
  assertNotNull("Requested entity not found.", testType);
  assertEquals("GeneratedNamesTestClass", testType.getName());
  assertNull("This should not have a base type", testType.getBaseType());
  List<Property> properties = testType.getProperties();
  assertEquals(1, properties.size());
  ComplexProperty propComplex = (ComplexProperty) properties.get(0);
  assertEquals("MyComplexProperty", propComplex.getName());
  assertEquals(GeneratedNamesComplexTestClass.class.getPackage().getName(), propComplex.getType().getNamespace());
  assertEquals(GeneratedNamesComplexTestClass.class.getSimpleName(), propComplex.getType().getName());


  ComplexType testComplexType = localAep.getComplexType(
      new FullQualifiedName(GeneratedNamesComplexTestClass.class.getPackage().getName(),
          GeneratedNamesComplexTestClass.class.getSimpleName()));
  assertNotNull("Requested entity not found.", testComplexType);
  assertEquals("GeneratedNamesComplexTestClass", testComplexType.getName());
  assertNull("This should not have a base type", testComplexType.getBaseType());
}
 
Example #14
Source File: AnnotationEdmProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private Property createComplexProperty(EdmProperty ep, final Field field) {
  ComplexProperty cp = new ComplexProperty();
  // settings from property
  String entityName = ANNOTATION_HELPER.getPropertyName(field);
  cp.setName(entityName);

  // settings from related complex entity
  FullQualifiedName fqn = ANNOTATION_HELPER.extractComplexTypeFqn(field.getType());
  cp.setType(fqn);

  cp.setFacets(createFacets(ep.facets(), field.getAnnotation(EdmConcurrencyControl.class)));
  
  return cp;
}
 
Example #15
Source File: JPAEdmTestModelView.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public ComplexProperty getEdmComplexProperty() {
  return null;
}
 
Example #16
Source File: JPAEdmProperty.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public ComplexProperty getEdmComplexProperty() {
  return currentComplexProperty;
}
 
Example #17
Source File: EdmComplexPropertyImplProv.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
public EdmComplexPropertyImplProv(final EdmImplProv edm, final ComplexProperty property) throws EdmException {
  super(edm, property.getType(), property);
  this.property = property;
}
 
Example #18
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 #19
Source File: JPAEdmComplexPropertyView.java    From olingo-odata2 with Apache License 2.0 2 votes vote down vote up
/**
 * The method returns a complex property for a complex type.
 * 
 * @return an instance of {@link org.apache.olingo.odata2.api.edm.provider.ComplexProperty}
 */
ComplexProperty getEdmComplexProperty();