org.apache.olingo.commons.api.edm.provider.CsdlPropertyRef Java Examples

The following examples show how to use org.apache.olingo.commons.api.edm.provider.CsdlPropertyRef. 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: EDMProvider.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public EDMProvider(List<String> tableList, String containerName, String namespace,
                   Map<String, List<CsdlProperty>> propertiesMap, Map<String, List<CsdlPropertyRef>> pkeys,
                   List<String> entitySet, Map<String, NavigationTable> navigationProperties) {
    this.containerFullQName = new FullQualifiedName(namespace, containerName);
    this.namespace = namespace;
    if (navigationProperties != null) {
        this.manyToOneRelationList = generateManyToOneRelationships(navigationProperties);
        this.oneToManyRelationList = generateOneToManyRelationships(navigationProperties);
    } else {
        this.manyToOneRelationList = null;
        this.oneToManyRelationList = null;
    }
    this.csdlEntityTypesMap = generateEntityTypes(propertiesMap, tableList, pkeys);
    this.csdlEntitySetMap = generateEntitySets(entitySet);
    this.csdlEntityContainer = generateCsdlEntityContainer();
    this.csdlEntityContainerInfo = generateCsdlEntityContainerInfo();
    this.csdlSchemaList = generateSchemaList();
}
 
Example #2
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) {

  // this method is called for one of the EntityTypes that are configured in the Schema
  if(entityTypeName.equals(ET_PRODUCT_FQN)){

    //create EntityType properties
    CsdlProperty id = new CsdlProperty().setName("ID").setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
    CsdlProperty name = new CsdlProperty().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
    CsdlProperty  description = new CsdlProperty().setName("Description").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());

    // create CsdlPropertyRef for Key element
    CsdlPropertyRef propertyRef = new CsdlPropertyRef();
    propertyRef.setName("ID");

    // configure EntityType
    CsdlEntityType entityType = new CsdlEntityType();
    entityType.setName(ET_PRODUCT_NAME);
    entityType.setProperties(Arrays.asList(id, name , description));
    entityType.setKey(Collections.singletonList(propertyRef));

    return entityType;
  }

  return null;
}
 
Example #3
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) {
  // this method is called for one of the EntityTypes that are configured in the Schema
  if(ET_PRODUCT_FQN.equals(entityTypeName)){

    //create EntityType properties
    CsdlProperty id = new CsdlProperty().setName("ID").setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
    CsdlProperty name = new CsdlProperty().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
    CsdlProperty  description = new CsdlProperty().setName("Description").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());

    // create PropertyRef for Key element
    CsdlPropertyRef propertyRef = new CsdlPropertyRef();
    propertyRef.setName("ID");

    // configure EntityType
    CsdlEntityType entityType = new CsdlEntityType();
    entityType.setName(ET_PRODUCT_NAME);
    entityType.setProperties(Arrays.asList(id, name, description));
    entityType.setKey(Collections.singletonList(propertyRef));

    return entityType;
  }

  return null;

}
 
Example #4
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) {
  // this method is called for one of the EntityTypes that are configured in the Schema
  if(ET_PRODUCT_FQN.equals(entityTypeName)){

    //create EntityType properties
    CsdlProperty id = new CsdlProperty().setName("ID").setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
    CsdlProperty name = new CsdlProperty().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
    CsdlProperty  description = new CsdlProperty().setName("Description").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());

    // create PropertyRef for Key element
    CsdlPropertyRef propertyRef = new CsdlPropertyRef();
    propertyRef.setName("ID");

    // configure EntityType
    CsdlEntityType entityType = new CsdlEntityType();
    entityType.setName(ET_PRODUCT_NAME);
    entityType.setProperties(Arrays.asList(id, name, description));
    entityType.setKey(Collections.singletonList(propertyRef));

    return entityType;
  }

  return null;

}
 
Example #5
Source File: ClientCsdlPropertyRef.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected CsdlPropertyRef doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException {

  final CsdlPropertyRef propertyRef = new ClientCsdlPropertyRef();

  for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
    final JsonToken token = jp.getCurrentToken();
    if (token == JsonToken.FIELD_NAME) {
      if ("Name".equals(jp.getCurrentName())) {
        propertyRef.setName(jp.nextTextValue());
      } else if ("Alias".equals(jp.getCurrentName())) {
        propertyRef.setAlias(jp.nextTextValue());
      }
    }
  }
  return propertyRef;
}
 
Example #6
Source File: MetadataParser.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void readEntityType(XMLEventReader reader, StartElement element, CsdlSchema schema)
    throws XMLStreamException {
  CsdlEntityType entityType = new CsdlEntityType();
  entityType.setProperties(new ArrayList<CsdlProperty>());
  entityType.setNavigationProperties(new ArrayList<CsdlNavigationProperty>());
  entityType.setKey(new ArrayList<CsdlPropertyRef>());
  entityType.setName(attr(element, "Name"));
  if (attr(element, "BaseType") != null) {
    entityType.setBaseType(new FullQualifiedName(attr(element, "BaseType")));
  }
  entityType.setAbstract(Boolean.parseBoolean(attr(element, "Abstract")));
  entityType.setOpenType(Boolean.parseBoolean(attr(element, "OpenType")));
  entityType.setHasStream(Boolean.parseBoolean(attr(element, "HasStream")));
  readEntityProperties(reader, entityType);
  schema.getEntityTypes().add(entityType);
}
 
Example #7
Source File: MetadataDocumentXmlSerializerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public CsdlEntityType getEntityType(final FullQualifiedName entityTypeName) throws ODataException {
  if (entityTypeName.equals(nameETAbstract)) {
    return new CsdlEntityType()
    .setName("ETAbstract")
    .setAbstract(true)
    .setProperties(Collections.singletonList(propertyString));

  } else if (entityTypeName.equals(nameETAbstractBase)) {
    return new CsdlEntityType()
    .setName("ETAbstractBase")
    .setBaseType(nameETAbstract)
    .setKey(Collections.singletonList(new CsdlPropertyRef().setName("PropertyInt16")))
    .setProperties(Collections.singletonList(propertyInt16_NotNullable));
  } else if (entityTypeName.equals(nameET)) {
    return new CsdlEntityType()
    .setName("ET")
    .setKey(Collections.singletonList(new CsdlPropertyRef().setName("PropertyInt16")))
    .setProperties(Collections.singletonList(propertyInt16_NotNullable))
    .setNavigationProperties(Collections.singletonList(navProperty));
  }
  return null;
}
 
Example #8
Source File: EdmKeyPropertyRefImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void aliasForPropertyInComplexPropertyTwoLevels() {
  CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("comp/comp2/Id").setAlias("alias");
  EdmEntityType etMock = mock(EdmEntityType.class);
  EdmProperty keyPropertyMock = mock(EdmProperty.class);
  EdmProperty compMock = mock(EdmProperty.class);
  EdmComplexType compTypeMock = mock(EdmComplexType.class);
  EdmProperty comp2Mock = mock(EdmProperty.class);
  EdmComplexType comp2TypeMock = mock(EdmComplexType.class);
  when(comp2TypeMock.getStructuralProperty("Id")).thenReturn(keyPropertyMock);
  when(comp2Mock.getType()).thenReturn(comp2TypeMock);
  when(compTypeMock.getStructuralProperty("comp2")).thenReturn(comp2Mock);
  when(compMock.getType()).thenReturn(compTypeMock);
  when(etMock.getStructuralProperty("comp")).thenReturn(compMock);
  EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef);

  EdmProperty property = ref.getProperty();
  assertNotNull(property);
  assertTrue(property == keyPropertyMock);
}
 
Example #9
Source File: EdmKeyPropertyRefImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void aliasForPropertyInComplexPropertyOneLevel() {
  CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("comp/Id").setAlias("alias");
  EdmEntityType etMock = mock(EdmEntityType.class);
  EdmProperty keyPropertyMock = mock(EdmProperty.class);
  EdmProperty compMock = mock(EdmProperty.class);
  EdmComplexType compTypeMock = mock(EdmComplexType.class);
  when(compTypeMock.getStructuralProperty("Id")).thenReturn(keyPropertyMock);
  when(compMock.getType()).thenReturn(compTypeMock);
  when(etMock.getStructuralProperty("comp")).thenReturn(compMock);
  EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef);
  assertEquals("alias", ref.getAlias());

  EdmProperty property = ref.getProperty();
  assertNotNull(property);
  assertTrue(property == keyPropertyMock);
}
 
Example #10
Source File: EdmNavigationPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test(expected = EdmException.class)
public void navigationPropertyWithNonexistentPartner() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  EdmProviderImpl edm = new EdmProviderImpl(provider);
  final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity");
  CsdlEntityType entityTypeProvider = new CsdlEntityType();
  entityTypeProvider.setKey(Collections.<CsdlPropertyRef> emptyList());

  List<CsdlNavigationProperty> navigationProperties = new ArrayList<CsdlNavigationProperty>();
  navigationProperties.add(new CsdlNavigationProperty().setName("partnerName").setType(entityTypeName));
  entityTypeProvider.setNavigationProperties(navigationProperties);
  when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider);
  CsdlNavigationProperty propertyProvider = new CsdlNavigationProperty();
  propertyProvider.setType(entityTypeName);
  propertyProvider.setNullable(false);
  propertyProvider.setPartner("wrong");
  EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, propertyProvider);
  property.getPartner();
}
 
Example #11
Source File: EdmNavigationPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void navigationPropertyWithPartner() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  EdmProviderImpl edm = new EdmProviderImpl(provider);
  final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity");
  CsdlEntityType entityTypeProvider = new CsdlEntityType();
  entityTypeProvider.setKey(Collections.<CsdlPropertyRef> emptyList());

  List<CsdlNavigationProperty> navigationProperties = new ArrayList<CsdlNavigationProperty>();
  navigationProperties.add(new CsdlNavigationProperty().setName("partnerName").setType(entityTypeName));
  entityTypeProvider.setNavigationProperties(navigationProperties);
  when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider);
  CsdlNavigationProperty propertyProvider = new CsdlNavigationProperty();
  propertyProvider.setType(entityTypeName);
  propertyProvider.setNullable(false);
  propertyProvider.setPartner("partnerName");
  EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, propertyProvider);
  EdmNavigationProperty partner = property.getPartner();
  assertNotNull(partner);

  // Caching
  assertTrue(partner == property.getPartner());
}
 
Example #12
Source File: EdmEntityTypeImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected void checkBaseType() {
  if (!baseTypeChecked) {
    if (baseTypeName != null) {
      baseType = buildBaseType(baseTypeName);
      entityBaseType = (EdmEntityType) baseType;
    }
    if (baseType == null
        || (baseType.isAbstract() && ((EdmEntityType) baseType).getKeyPropertyRefs().isEmpty())) {
      final List<CsdlPropertyRef> key = entityType.getKey();
      if (key != null) {
        final List<EdmKeyPropertyRef> edmKey = new ArrayList<EdmKeyPropertyRef>();
        for (CsdlPropertyRef ref : key) {
          edmKey.add(new EdmKeyPropertyRefImpl(this, ref));
        }
        setEdmKeyPropertyRef(edmKey);
      }
    }
    baseTypeChecked = true;
  }
}
 
Example #13
Source File: EdmNavigationPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void navigationProperty() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  EdmProviderImpl edm = new EdmProviderImpl(provider);
  final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity");
  CsdlEntityType entityTypeProvider = new CsdlEntityType();
  entityTypeProvider.setKey(Collections.<CsdlPropertyRef> emptyList());
  when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider);
  CsdlNavigationProperty propertyProvider = new CsdlNavigationProperty();
  propertyProvider.setType(entityTypeName);
  propertyProvider.setNullable(false);
  EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, propertyProvider);
  assertFalse(property.isCollection());
  assertFalse(property.isNullable());
  EdmType type = property.getType();
  assertEquals(EdmTypeKind.ENTITY, type.getKind());
  assertEquals("ns", type.getNamespace());
  assertEquals("entity", type.getName());
  assertNull(property.getReferencingPropertyName("referencedPropertyName"));
  assertNull(property.getPartner());
  assertFalse(property.containsTarget());

  // Test caching
  EdmType cachedType = property.getType();
  assertTrue(type == cachedType);
}
 
Example #14
Source File: CrossServiceTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private CsdlProvider(final String name) {
   this.name = name;
namespace = NAMESPACE_PREFIX + name;
   other = name.equals("One") ? "Two" : "One";
   entitySet = new CsdlEntitySet().setName(ENTITY_SET_PREFIX + name)
       .setType(new FullQualifiedName(namespace, ENTITY_TYPE_PREFIX + name));
   entityType = new CsdlEntityType().setName(ENTITY_TYPE_PREFIX + name)
       .setKey(Collections.singletonList(new CsdlPropertyRef().setName("ID" + name)))
       .setProperties(Collections.singletonList(
           new CsdlProperty().setName("ID" + name).setNullable(false).setType("Edm.Guid")))
       .setNavigationProperties(Collections.singletonList(
           new CsdlNavigationProperty().setName("Navigation" + other)
               .setType(new FullQualifiedName(ALIAS_PREFIX + other, ENTITY_TYPE_PREFIX + other))));
 }
 
Example #15
Source File: DemoEdmProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) {

    // this method is called for one of the EntityTypes that are configured in the Schema
    if (entityTypeName.equals(ET_PRODUCT_FQN)) {

        //create EntityType properties
        CsdlProperty id = new CsdlProperty()
            .setName("ID")
            .setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
        CsdlProperty name = new CsdlProperty()
            .setName("Name")
            .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty description = new CsdlProperty()
            .setName("Description")
            .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());

        // create CsdlPropertyRef for Key element
        CsdlPropertyRef propertyRef = new CsdlPropertyRef();
        propertyRef.setName("ID");

        // configure EntityType
        CsdlEntityType entityType = new CsdlEntityType();
        entityType.setName(ET_PRODUCT_NAME);
        entityType.setProperties(Arrays.asList(id, name, description));
        entityType.setKey(Collections.singletonList(propertyRef));

        return entityType;
    }

    return null;
}
 
Example #16
Source File: CarsEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlEntityType getEntityType(final FullQualifiedName entityTypeName) throws ODataException {
  if (ET_CAR.equals(entityTypeName)) {
    return new CsdlEntityType()
        .setName(ET_CAR.getName())
        .setKey(Arrays.asList(
            new CsdlPropertyRef().setName("Id")))
        .setProperties(
            Arrays.asList(
                new CsdlProperty().setName("Id").setType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName()),
                new CsdlProperty().setName("Model").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()),
                new CsdlProperty().setName("ModelYear").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())
                    .setMaxLength(4),
                new CsdlProperty().setName("Price").setType(EdmPrimitiveTypeKind.Decimal.getFullQualifiedName())
                    .setScale(2),
                new CsdlProperty().setName("Currency").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())
                    .setMaxLength(3)
                )
        ).setNavigationProperties(Arrays.asList(
            new CsdlNavigationProperty().setName("Manufacturer").setType(ET_MANUFACTURER)
            )
        );

  } else if (ET_MANUFACTURER.equals(entityTypeName)) {
    return new CsdlEntityType()
        .setName(ET_MANUFACTURER.getName())
        .setKey(Arrays.asList(
            new CsdlPropertyRef().setName("Id")))
        .setProperties(Arrays.asList(
            new CsdlProperty().setName("Id").setType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName()),
            new CsdlProperty().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()),
            new CsdlProperty().setName("Address").setType(CT_ADDRESS))
        ).setNavigationProperties(Arrays.asList(
            new CsdlNavigationProperty().setName("Cars").setType(ET_CAR).setCollection(true)
            )
        );
  }

  return null;
}
 
Example #17
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) {
  // this method is called for one of the EntityTypes that are configured in the Schema
  if(entityTypeName.equals(ET_PRODUCT_FQN)){

    //create EntityType properties
    CsdlProperty id = new CsdlProperty().setName("ID")
            .setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
    CsdlProperty name = new CsdlProperty().setName("Name")
            .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
    CsdlProperty  description = new CsdlProperty().setName("Description")
            .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());

    // create CsdlPropertyRef for Key element
    CsdlPropertyRef propertyRef = new CsdlPropertyRef();
    propertyRef.setName("ID");

    // configure EntityType
    CsdlEntityType entityType = new CsdlEntityType();
    entityType.setName(ET_PRODUCT_NAME);
    entityType.setProperties(Arrays.asList(id, name, description));
    entityType.setKey(Collections.singletonList(propertyRef));

    return entityType;
  }

  return null;

}
 
Example #18
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) {
  // this method is called for one of the EntityTypes that are configured in the Schema
  if (ET_PRODUCT_FQN.equals(entityTypeName)) {

    // create EntityType properties
    CsdlProperty id = new CsdlProperty().setName("ID").setType(
        EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
    CsdlProperty name = new CsdlProperty().setName("Name").setType(
        EdmPrimitiveTypeKind.String.getFullQualifiedName());
    CsdlProperty description = new CsdlProperty().setName("Description").setType(
        EdmPrimitiveTypeKind.String.getFullQualifiedName());

    // create PropertyRef for Key element
    CsdlPropertyRef propertyRef = new CsdlPropertyRef();
    propertyRef.setName("ID");

    // configure EntityType
    CsdlEntityType entityType = new CsdlEntityType();
    entityType.setName(ET_PRODUCT_NAME);
    entityType.setProperties(Arrays.asList(id, name, description));
    entityType.setKey(Collections.singletonList(propertyRef));

    return entityType;
  }

  return null;

}
 
Example #19
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) {
  // this method is called for one of the EntityTypes that are configured in the Schema
  if(entityTypeName.equals(ET_PRODUCT_FQN)){

    //create EntityType properties
    CsdlProperty id = new CsdlProperty().setName("ID")
            .setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
    CsdlProperty name = new CsdlProperty().setName("Name")
            .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
    CsdlProperty  description = new CsdlProperty().setName("Description")
            .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());

    // create CsdlPropertyRef for Key element
    CsdlPropertyRef propertyRef = new CsdlPropertyRef();
    propertyRef.setName("ID");

    // configure EntityType
    CsdlEntityType entityType = new CsdlEntityType();
    entityType.setName(ET_PRODUCT_NAME);
    entityType.setProperties(Arrays.asList(id, name, description));
    entityType.setKey(Collections.singletonList(propertyRef));

    return entityType;
  }

  return null;

}
 
Example #20
Source File: ODataAdapter.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private Map<String, List<CsdlPropertyRef>> getKeysCsdlMap() throws ODataServiceFault {
    Map<String, List<CsdlPropertyRef>> keyMap = new HashMap<>();
    for (String tableName : this.dataHandler.getTableList()) {
        List<CsdlPropertyRef> propertyList = new ArrayList<>();
        for (String element : this.dataHandler.getPrimaryKeys().get(tableName)) {
            propertyList.add(new CsdlPropertyRef().setName(element));
        }
        keyMap.put(tableName, propertyList);
    }
    return keyMap;
}
 
Example #21
Source File: ProductsEdmProvider.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) {
    // this method is called for one of the EntityTypes that are configured in the Schema
    if (entityTypeName.equals(ET_PRODUCT_FQN)) {

        //create EntityType properties
        CsdlProperty id = new CsdlProperty().setName(PRODUCT_ID).setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
        CsdlProperty name = new CsdlProperty().setName(PRODUCT_NAME).setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty description = new CsdlProperty().setName(PRODUCT_DESCRIPTION).setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty serialNums = new CsdlProperty()
            .setName(PRODUCT_SERIALS)
            .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())
            .setCollection(true);
        CsdlProperty specification = new CsdlProperty()
            .setName(PRODUCT_SPEC)
            .setType(ET_SPEC_FQN);

        // create CsdlPropertyRef for Key element
        CsdlPropertyRef propertyRef = new CsdlPropertyRef();
        propertyRef.setName(PRODUCT_ID);

        // configure EntityType
        CsdlEntityType entityType = new CsdlEntityType();
        entityType.setName(ET_PRODUCT_NAME);
        entityType.setProperties(Arrays.asList(id, name, description, serialNums, specification));
        entityType.setKey(Collections.singletonList(propertyRef));

        return entityType;
    }

    return null;
}
 
Example #22
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) {
  // this method is called for one of the EntityTypes that are configured in the Schema
  if(ET_PRODUCT_FQN.equals(entityTypeName)){

    //create EntityType properties
    CsdlProperty id = new CsdlProperty().setName("ID")
                                        .setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
    CsdlProperty name = new CsdlProperty().setName("Name")
                                          .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
    CsdlProperty  description = new CsdlProperty().setName("Description")
                                                  .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());

    // create PropertyRef for Key element
    CsdlPropertyRef propertyRef = new CsdlPropertyRef();
    propertyRef.setName("ID");

    // configure EntityType
    CsdlEntityType entityType = new CsdlEntityType();
    entityType.setName(ET_PRODUCT_NAME);
    entityType.setProperties(Arrays.asList(id, name, description));
    entityType.setKey(Collections.singletonList(propertyRef));

    return entityType;
  }

  return null;

}
 
Example #23
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) {
  // this method is called for one of the EntityTypes that are configured in the Schema
  if(ET_PRODUCT_FQN.equals(entityTypeName)){

    //create EntityType properties
    CsdlProperty id = new CsdlProperty().setName("ID").setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
    CsdlProperty name = new CsdlProperty().setName("Name")
                                          .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
    CsdlProperty  description = new CsdlProperty().setName("Description")
                                                  .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());

    // create PropertyRef for Key element
    CsdlPropertyRef propertyRef = new CsdlPropertyRef();
    propertyRef.setName("ID");

    // configure EntityType
    CsdlEntityType entityType = new CsdlEntityType();
    entityType.setName(ET_PRODUCT_NAME);
    entityType.setProperties(Arrays.asList(id, name, description));
    entityType.setKey(Collections.singletonList(propertyRef));

    return entityType;
  }

  return null;
}
 
Example #24
Source File: EdmProviderImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  CsdlEntityContainerInfo containerInfo = new CsdlEntityContainerInfo().setContainerName(FQN);
  when(provider.getEntityContainerInfo(FQN)).thenReturn(containerInfo);
  when(provider.getEntityContainerInfo(null)).thenReturn(containerInfo);

  CsdlEnumType enumType = new CsdlEnumType().setName(FQN.getName());
  when(provider.getEnumType(FQN)).thenReturn(enumType);

  CsdlTypeDefinition typeDefinition =
      new CsdlTypeDefinition().setName(FQN.getName()).setUnderlyingType(new FullQualifiedName("Edm", "String"));
  when(provider.getTypeDefinition(FQN)).thenReturn(typeDefinition);

  CsdlEntityType entityType = new CsdlEntityType().setName(FQN.getName()).setKey(new ArrayList<CsdlPropertyRef>());
  when(provider.getEntityType(FQN)).thenReturn(entityType);

  CsdlComplexType complexType = new CsdlComplexType().setName(FQN.getName());
  when(provider.getComplexType(FQN)).thenReturn(complexType);

  List<CsdlAliasInfo> aliasInfos = new ArrayList<CsdlAliasInfo>();
  aliasInfos.add(new CsdlAliasInfo().setAlias("alias").setNamespace("namespace"));
  when(provider.getAliasInfos()).thenReturn(aliasInfos);

  CsdlAnnotations annotationsGroup = new CsdlAnnotations();
  annotationsGroup.setTarget("FQN.FQN");
  when(provider.getAnnotationsGroup(FQN, null)).thenReturn(annotationsGroup);

  edm = new EdmProviderImpl(provider);
}
 
Example #25
Source File: EdmKeyPropertyRefImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EdmException.class)
public void aliasForPropertyInComplexPropertyButWrongPath2() {
  CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("wrong/Id").setAlias("alias");
  EdmEntityType etMock = mock(EdmEntityType.class);
  EdmProperty keyPropertyMock = mock(EdmProperty.class);
  EdmElement compMock = mock(EdmProperty.class);
  EdmComplexType compTypeMock = mock(EdmComplexType.class);
  when(compTypeMock.getProperty("Id")).thenReturn(keyPropertyMock);
  when(compMock.getType()).thenReturn(compTypeMock);
  when(etMock.getProperty("comp")).thenReturn(compMock);
  new EdmKeyPropertyRefImpl(etMock, providerRef).getProperty();
}
 
Example #26
Source File: EdmKeyPropertyRefImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EdmException.class)
public void aliasForPropertyInComplexPropertyButWrongPath() {
  CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("comp/wrong").setAlias("alias");
  EdmEntityType etMock = mock(EdmEntityType.class);
  EdmProperty keyPropertyMock = mock(EdmProperty.class);
  EdmElement compMock = mock(EdmProperty.class);
  EdmComplexType compTypeMock = mock(EdmComplexType.class);
  when(compTypeMock.getProperty("Id")).thenReturn(keyPropertyMock);
  when(compMock.getType()).thenReturn(compTypeMock);
  when(etMock.getProperty("comp")).thenReturn(compMock);
  new EdmKeyPropertyRefImpl(etMock, providerRef).getProperty();
}
 
Example #27
Source File: EdmKeyPropertyRefImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void noAlias() {
  CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("Id");
  EdmEntityType etMock = mock(EdmEntityType.class);
  EdmProperty keyPropertyMock = mock(EdmProperty.class);
  when(etMock.getStructuralProperty("Id")).thenReturn(keyPropertyMock);
  EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef);
  assertEquals("Id", ref.getName());
  assertNull(ref.getAlias());

  EdmProperty property = ref.getProperty();
  assertNotNull(property);
  assertTrue(property == keyPropertyMock);
  assertTrue(property == ref.getProperty());
}
 
Example #28
Source File: EdmNavigationPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void navigationPropertyWithReferntialConstraint() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  EdmProviderImpl edm = new EdmProviderImpl(provider);
  final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity");
  CsdlEntityType entityTypeProvider = new CsdlEntityType();
  entityTypeProvider.setKey(Collections.<CsdlPropertyRef> emptyList());
  when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider);
  CsdlNavigationProperty propertyProvider = new CsdlNavigationProperty();
  propertyProvider.setType(entityTypeName);
  propertyProvider.setNullable(false);
  propertyProvider.setContainsTarget(true);
  List<CsdlReferentialConstraint> referentialConstraints = new ArrayList<CsdlReferentialConstraint>();
  referentialConstraints.add(new CsdlReferentialConstraint().setProperty("property").setReferencedProperty(
      "referencedProperty"));
  propertyProvider.setReferentialConstraints(referentialConstraints);

  EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, propertyProvider);
  assertEquals("property", property.getReferencingPropertyName("referencedProperty"));
  assertNull(property.getReferencingPropertyName("wrong"));
  assertTrue(property.containsTarget());
  
  assertNotNull(property.getReferentialConstraints());
  List<EdmReferentialConstraint> edmReferentialConstraints = property.getReferentialConstraints();
  assertEquals(1, edmReferentialConstraints.size());
  assertTrue(edmReferentialConstraints == property.getReferentialConstraints());
  
}
 
Example #29
Source File: MetadataDocumentJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
public CsdlEntityType getEntityType(final FullQualifiedName entityTypeName) throws ODataException {
  if (entityTypeName.equals(nameETAbstract)) {
    return new CsdlEntityType()
    .setName("ETAbstract")
    .setAbstract(true)
    .setNavigationProperties(Arrays.asList(
        new CsdlNavigationProperty().setName("NavPropertyETTwoKeyNavOne").setType(nameETTwoKeyNavOne)))
    .setProperties(Collections.singletonList(propertyString));
  } else if (entityTypeName.equals(nameETAbstractBase)) {
    CsdlAnnotation annotation = new CsdlAnnotation()
        .setTerm("Core.Description")
        .setQualifier("Target")
        .setExpression(new CsdlConstantExpression(ConstantExpressionType.String, "Description of Type"));
    propertyInt16_NotNullable.setAnnotations(Arrays.asList(annotation));
    
    return new CsdlEntityType()
    .setName("ETAbstractBase")
    .setBaseType(nameETAbstract)
    .setKey(Collections.singletonList(new CsdlPropertyRef().setName("PropertyInt16")))
    .setProperties(Collections.singletonList(propertyInt16_NotNullable))
    .setAnnotations(Arrays.asList(annotation));
  } else if (entityTypeName.equals(nameET)) {
    return new CsdlEntityType()
        .setName("ET")
        .setKey(Arrays.asList(new CsdlPropertyRef().setAlias("EntityInfoID").setName("Info/ID"), 
            new CsdlPropertyRef().setName("name")))
        .setNavigationProperties(Arrays.asList(
            new CsdlNavigationProperty().setName("NavPropertyETOne").setType(nameETOne), navProperty))
        .setProperties(Arrays.asList(nameProperty, infoProperty));
  } else if (entityTypeName.equals(nameETTwoKeyNav)) {
    return new CsdlEntityType()
        .setName("ETTwoKeyNav")
        .setKey(Arrays.asList(new CsdlPropertyRef().setName("PropertyInt16"), 
            new CsdlPropertyRef().setName("PropertyString")))
        .setNavigationProperties(Arrays.asList(
            new CsdlNavigationProperty().setName("NavPropertyETTwoKeyNavOne").setType(nameETTwoKeyNavOne),
            new CsdlNavigationProperty().setName("NavPropertyETOne").setType(nameETOne)))
        .setProperties(Arrays.asList(propertyInt16_NotNullable, propertyString));
  } else if (entityTypeName.equals(nameETOne)) {
    return new CsdlEntityType()
        .setName("ETOne")
        .setKey(Collections.singletonList(new CsdlPropertyRef().setName("PropertyInt16")))
        .setNavigationProperties(Arrays.asList(
            new CsdlNavigationProperty().setName("NavPropertyET").setType(nameET)))
        .setProperties(Collections.singletonList(propertyInt16_NotNullable));
  } else if (entityTypeName.equals(nameETTwoKeyNavOne)) {
    return new CsdlEntityType()
        .setName("ETTwoKeyNavOne")
        .setBaseType(nameETOne)
        .setHasStream(true)
        .setProperties(Collections.singletonList(propertyString))
        .setNavigationProperties(Arrays.asList(
            new CsdlNavigationProperty().setName("NavPropertyETAbstract")
            .setCollection(true).setType(nameETAbstract)
            .setContainsTarget(true).setPartner("NavPropertyETTwoKeyNavOne").setNullable(false)
            .setReferentialConstraints(Collections.singletonList(new CsdlReferentialConstraint()
                .setProperty("PropertyString").setReferencedProperty("PropertyString")
                .setAnnotations(Collections.singletonList(new CsdlAnnotation()
        .setTerm("Core.Description")
        .setQualifier("Target")
        .setExpression(new CsdlConstantExpression(
            ConstantExpressionType.String, "Description of Complex Type"))))))));
  }
  return null;
}
 
Example #30
Source File: EdmKeyPropertyRefImplTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test(expected = EdmException.class)
public void aliasButEmptyPath() {
  CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("").setAlias("alias");
  EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(mock(EdmEntityType.class), providerRef);
  ref.getProperty();
}