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

The following examples show how to use org.apache.olingo.odata2.api.edm.provider.SimpleProperty. 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: JPAEdmProperty.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private SimpleProperty buildSimpleProperty(final Attribute<?, ?> jpaAttribute, final SimpleProperty simpleProperty,
    final JoinColumn joinColumn)
    throws ODataJPAModelException, ODataJPARuntimeException {

  boolean isForeignKey = joinColumn != null;
  JPAEdmNameBuilder.build(JPAEdmProperty.this, isBuildModeComplexType, skipDefaultNaming, isForeignKey);
  EdmSimpleTypeKind simpleTypeKind = JPATypeConverter
      .convertToEdmSimpleType(jpaAttribute
          .getJavaType(), jpaAttribute);
  simpleProperty.setType(simpleTypeKind);
  Facets facets = JPAEdmFacets.createAndSet(jpaAttribute, simpleProperty);
  if(isForeignKey) {
    facets.setNullable(joinColumn.nullable());
  }

  return simpleProperty;

}
 
Example #2
Source File: JPAEdmComplexTypeTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testExpandEdmComplexType() {
  ComplexType complexType = new ComplexType();
  List<Property> properties = new ArrayList<Property>();
  JPAEdmMapping mapping1 = new JPAEdmMappingImpl();
  mapping1.setJPAColumnName("LINEITEMID");
  ((Mapping) mapping1).setInternalName("LineItemKey.LiId");
  JPAEdmMapping mapping2 = new JPAEdmMappingImpl();
  mapping2.setJPAColumnName("LINEITEMNAME");
  ((Mapping) mapping2).setInternalName("LineItemKey.LiName");
  properties.add(new SimpleProperty().setName("LIID").setMapping((Mapping) mapping1));
  properties.add(new SimpleProperty().setName("LINAME").setMapping((Mapping) mapping2));
  complexType.setProperties(properties);
  List<Property> expandedList = null;
  try {
    objComplexType.expandEdmComplexType(complexType, expandedList, "SalesOrderItemKey");
  } catch (ClassCastException e) {
    assertTrue(false);
  }
  assertTrue(true);

}
 
Example #3
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 #4
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 #5
Source File: JPAEdmNameBuilderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testBuildJPAEdmPropertyView() {

  SimpleProperty simpleProperty = new SimpleProperty();

  // Mocking EDMProperty
  JPAEdmPropertyView propertyView = EasyMock.createMock(JPAEdmPropertyView.class);
  JPAEdmEntityTypeView entityTypeView = EasyMock.createMock(JPAEdmEntityTypeView.class);

  EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JPAAttribute());
  EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView);
  EasyMock.expect(propertyView.getJPAEdmMappingModelAccess()).andStubReturn(null);
  EasyMock.expect(propertyView.getEdmSimpleProperty()).andStubReturn(simpleProperty);
  EasyMock.replay(propertyView);

  JPAEdmNameBuilder.build(propertyView, false, false, false);
  assertEquals("Id", simpleProperty.getName());
}
 
Example #6
Source File: JPAEdmNameBuilderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testBuildJPAEdmPropertyViewWithNoDefaultNaming() {

  SimpleProperty simpleProperty = new SimpleProperty();

  // Mocking EDMProperty
  JPAEdmPropertyView propertyView = EasyMock.createMock(JPAEdmPropertyView.class);
  JPAEdmEntityTypeView entityTypeView = EasyMock.createMock(JPAEdmEntityTypeView.class);

  EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JPAAttribute());
  EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView);
  EasyMock.expect(propertyView.getJPAEdmMappingModelAccess()).andStubReturn(null);
  EasyMock.expect(propertyView.getEdmSimpleProperty()).andStubReturn(simpleProperty);
  EasyMock.replay(propertyView);

  JPAEdmNameBuilder.build(propertyView, false, true, false);
  assertEquals("id", simpleProperty.getName());
}
 
Example #7
Source File: EdmNamedImplProvTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EdmException.class)
public void testPropertyIllegalStartWithNumber() throws Exception {

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

  SimpleProperty propertySimple = new SimpleProperty().setName("1_PropertyName").setType(EdmSimpleTypeKind.String);
  new EdmSimplePropertyImplProv(edmImplProv, propertySimple);
  expectedEx.expect(RuntimeException.class);
  expectedEx.expectMessage("'Prop;ertyName' name pattern not valid.");
}
 
Example #8
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 #9
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private Property readSimpleProperty(final XMLStreamReader reader, final FullQualifiedName fqName)
    throws XMLStreamException {
  SimpleProperty property = new SimpleProperty();
  property.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  property.setType(EdmSimpleTypeKind.valueOf(fqName.getName()));
  return property;
}
 
Example #10
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 #11
Source File: EdmNamedImplProvTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EdmException.class)
public void testPropertySimple() throws Exception {

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

  SimpleProperty propertySimple = new SimpleProperty().setName("Prop;ertyName").setType(EdmSimpleTypeKind.String);
  new EdmSimplePropertyImplProv(edmImplProv, propertySimple);
}
 
Example #12
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 #13
Source File: EdmNamedImplProvTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testPropertyWithNumber() throws Exception {

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

  SimpleProperty propertySimple = new SimpleProperty().setName("Prop_1_Name").setType(EdmSimpleTypeKind
      .String);
  new EdmSimplePropertyImplProv(edmImplProv, propertySimple);
  assertEquals("Prop_1_Name", new EdmSimplePropertyImplProv(edmImplProv, propertySimple).getName());
}
 
Example #14
Source File: EdmNamedImplProvTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testPropertyUmlaut() throws Exception {
  EdmProvider edmProvider = mock(EdmProvider.class);
  EdmImplProv edmImplProv = new EdmImplProv(edmProvider);

  SimpleProperty propertySimple = new SimpleProperty().setName("ÄropertyName").setType(EdmSimpleTypeKind.String);
  assertEquals("ÄropertyName", new EdmSimplePropertyImplProv(edmImplProv, propertySimple).getName());
}
 
Example #15
Source File: EdmNamedImplProvTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testPropertyUnicode() throws Exception {
  EdmProvider edmProvider = mock(EdmProvider.class);
  EdmImplProv edmImplProv = new EdmImplProv(edmProvider);

  SimpleProperty propertySimple = new SimpleProperty().setName("\u00C0roperty\u00C1ame\u00C0\u00D5\u00D6")
      .setType(EdmSimpleTypeKind.String);
  assertEquals("ÀropertyÁameÀÕÖ", new EdmSimplePropertyImplProv(edmImplProv, propertySimple).getName());
}
 
Example #16
Source File: EdmNamedImplProvTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testPropertyUnicodeTwo() throws Exception {
  EdmProvider edmProvider = mock(EdmProvider.class);
  EdmImplProv edmImplProv = new EdmImplProv(edmProvider);

  SimpleProperty propertySimple = new SimpleProperty().setName("Содержание")
      .setType(EdmSimpleTypeKind.String);
  assertEquals("Содержание", new EdmSimplePropertyImplProv(edmImplProv, propertySimple).getName());
}
 
Example #17
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 #18
Source File: EdmComplexTypeImplProvTest.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);

  ComplexType fooComplexType = new ComplexType().setName("fooComplexType");

  List<Property> keyPropertysFoo = new ArrayList<Property>();
  keyPropertysFoo.add(new SimpleProperty().setName("Name").setType(EdmSimpleTypeKind.String));
  keyPropertysFoo.add(new SimpleProperty().setName("Address").setType(EdmSimpleTypeKind.String));
  fooComplexType.setProperties(keyPropertysFoo);

  edmComplexType = new EdmComplexTypeImplProv(edmImplProv, fooComplexType, "namespace");

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

  List<Property> propertysBarBase = new ArrayList<Property>();
  propertysBarBase.add(new SimpleProperty().setName("Name").setType(EdmSimpleTypeKind.String));
  propertysBarBase.add(new SimpleProperty().setName("Address").setType(EdmSimpleTypeKind.String));
  barBase.setProperties(propertysBarBase);

  ComplexType barComplexType = new ComplexType().setName("barComplexType").setBaseType(barBaseTypeName);
  edmComplexTypeWithBaseType = new EdmComplexTypeImplProv(edmImplProv, barComplexType, "namespace");

}
 
Example #19
Source File: CarEdmProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ComplexType getComplexType(final FullQualifiedName edmFQName) throws ODataException {
  if (NAMESPACE.equals(edmFQName.getNamespace())) {
    if (COMPLEX_TYPE.getName().equals(edmFQName.getName())) {
      List<Property> properties = new ArrayList<Property>();
      properties.add(new SimpleProperty().setName("Street").setType(EdmSimpleTypeKind.String));
      properties.add(new SimpleProperty().setName("City").setType(EdmSimpleTypeKind.String));
      properties.add(new SimpleProperty().setName("ZipCode").setType(EdmSimpleTypeKind.String));
      properties.add(new SimpleProperty().setName("Country").setType(EdmSimpleTypeKind.String));
      return new ComplexType().setName(COMPLEX_TYPE.getName()).setProperties(properties);
    }
  }

  return null;
}
 
Example #20
Source File: MyEdmProvider.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Override
public ComplexType getComplexType(FullQualifiedName edmFQName) throws ODataException {
    if (NAMESPACE.equals(edmFQName.getNamespace())) {
        if (COMPLEX_TYPE.getName().equals(edmFQName.getName())) {
            List<Property> properties = new ArrayList<>();
            properties.add(new SimpleProperty().setName("Street").setType(EdmSimpleTypeKind.String));
            properties.add(new SimpleProperty().setName("City").setType(EdmSimpleTypeKind.String));
            properties.add(new SimpleProperty().setName("ZipCode").setType(EdmSimpleTypeKind.String));
            properties.add(new SimpleProperty().setName("Country").setType(EdmSimpleTypeKind.String));
            return new ComplexType().setName(COMPLEX_TYPE.getName()).setProperties(properties);
        }
    }

    return null;
}
 
Example #21
Source File: AnnotationEdmProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private Property createSimpleProperty(final EdmProperty ep, final Field field) {
  SimpleProperty sp = new SimpleProperty();
  String entityName = ANNOTATION_HELPER.getPropertyName(field);
  sp.setName(entityName);
  //
  EdmType type = ep.type();
  if (type == EdmType.NULL) {
    type = getEdmType(field.getType());
  }
  sp.setType(ANNOTATION_HELPER.mapTypeKind(type));
  sp.setFacets(createFacets(ep.facets(), field.getAnnotation(EdmConcurrencyControl.class)));
  return sp;
}
 
Example #22
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 #23
Source File: AttributeEntitySet.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();

   List<Property> properties = res.getProperties ();
   properties.add ((Property) new SimpleProperty ().setName (VALUE)
         .setType (EdmSimpleTypeKind.String));
   properties.add((Property) new SimpleProperty().setName(CATEGORY)
         .setType(EdmSimpleTypeKind.String)
         .setFacets(new Facets().setDefaultValue(null)));

   return res.setName (ENTITY_NAME).setProperties (properties);
}
 
Example #24
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 #25
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 #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: Model.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
private static List<ComplexType> getComplexTypes()
{
   List<ComplexType> complexTypeList = new ArrayList<>();

   // Defines complex type TimeRange
   List<Property> timeRangeProperties = new ArrayList<>();
   timeRangeProperties.add(
         new SimpleProperty()
               .setName(TIME_RANGE_START)
               .setType(EdmSimpleTypeKind.DateTime));
   timeRangeProperties.add(
         new SimpleProperty()
               .setName(TIME_RANGE_END)
               .setType(EdmSimpleTypeKind.DateTime));
   complexTypeList.add(
         new ComplexType()
               .setName(TIME_RANGE.getName())
               .setProperties(timeRangeProperties));

   // Defines complex type Checksum
   List<Property> checksumProperties = new ArrayList<>();
   checksumProperties.add(
         new SimpleProperty()
               .setName(ALGORITHM)
               .setType(EdmSimpleTypeKind.String));
   checksumProperties.add(
         new SimpleProperty()
               .setName(VALUE)
               .setType(EdmSimpleTypeKind.String));
   complexTypeList.add(
         new ComplexType()
               .setName(CHECKSUM.getName())
               .setProperties(checksumProperties));

   return complexTypeList;
}
 
Example #28
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 #29
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 #30
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;
}