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

The following examples show how to use org.apache.olingo.commons.api.edm.provider.CsdlProperty. 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: EdmPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void getTypeReturnsComplexType() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  EdmProviderImpl edm = new EdmProviderImpl(provider);
  final FullQualifiedName complexTypeName = new FullQualifiedName("ns", "complex");
  CsdlComplexType complexTypeProvider = new CsdlComplexType();
  when(provider.getComplexType(complexTypeName)).thenReturn(complexTypeProvider);
  CsdlProperty propertyProvider = new CsdlProperty();
  propertyProvider.setType(complexTypeName);
  final EdmProperty property = new EdmPropertyImpl(edm, propertyProvider);
  assertFalse(property.isCollection());
  assertFalse(property.isPrimitive());
  final EdmType type = property.getType();
  assertEquals(EdmTypeKind.COMPLEX, type.getKind());
  assertEquals("ns", type.getNamespace());
  assertEquals("complex", type.getName());
}
 
Example #3
Source File: EdmPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void getTypeReturnsEnumType() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  EdmProviderImpl edm = new EdmProviderImpl(provider);
  final FullQualifiedName enumTypeName = new FullQualifiedName("ns", "enum");
  CsdlEnumType enumTypeProvider = new CsdlEnumType();
  when(provider.getEnumType(enumTypeName)).thenReturn(enumTypeProvider);
  CsdlProperty propertyProvider = new CsdlProperty();
  propertyProvider.setType(enumTypeName);
  final EdmProperty property = new EdmPropertyImpl(edm, propertyProvider);
  assertFalse(property.isCollection());
  assertFalse(property.isPrimitive());
  final EdmType type = property.getType();
  assertEquals(EdmTypeKind.ENUM, type.getKind());
  assertEquals("ns", type.getNamespace());
  assertEquals("enum", type.getName());
}
 
Example #4
Source File: EdmPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void getTypeReturnsTypeDefinition() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  EdmProviderImpl edm = new EdmProviderImpl(provider);
  final FullQualifiedName typeName = new FullQualifiedName("ns", "definition");
  CsdlTypeDefinition typeProvider =
      new CsdlTypeDefinition().setUnderlyingType(new FullQualifiedName("Edm", "String"));
  when(provider.getTypeDefinition(typeName)).thenReturn(typeProvider);
  CsdlProperty propertyProvider = new CsdlProperty();
  propertyProvider.setType(typeName);
  final EdmProperty property = new EdmPropertyImpl(edm, propertyProvider);
  assertFalse(property.isPrimitive());
  final EdmType type = property.getType();
  assertEquals(EdmTypeKind.DEFINITION, type.getKind());
  assertEquals("ns", type.getNamespace());
  assertEquals("definition", type.getName());
}
 
Example #5
Source File: EdmPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void facets() {
  EdmProviderImpl edm = new EdmProviderImpl(mock(CsdlEdmProvider.class));
  CsdlProperty propertyProvider = new CsdlProperty();
  propertyProvider.setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
  propertyProvider.setPrecision(42);
  propertyProvider.setScale(12);
  propertyProvider.setMaxLength(128);
  propertyProvider.setUnicode(true);
  propertyProvider.setNullable(false);
  propertyProvider.setDefaultValue("x");
  final EdmProperty property = new EdmPropertyImpl(edm, propertyProvider);
  assertTrue(property.isPrimitive());
  assertNull(property.getMapping());
  assertNull(property.getMimeType());
  assertEquals(Integer.valueOf(42), property.getPrecision());
  assertEquals(Integer.valueOf(12), property.getScale());
  assertEquals(Integer.valueOf(128), property.getMaxLength());
  assertTrue(property.isUnicode());
  assertFalse(property.isNullable());
  assertEquals("x", property.getDefaultValue());
  assertNull(property.getSrid());
}
 
Example #6
Source File: EdmMappingTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void initialMappingMustBeNull() {
  CsdlProperty property = new CsdlProperty().setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName());
  EdmProperty edmProperty = new EdmPropertyImpl(null, property);
  assertNull(edmProperty.getMapping());

  CsdlParameter parameter = new CsdlParameter().setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName());
  EdmParameter edmParameter = new EdmParameterImpl(null, parameter);
  assertNull(edmParameter.getMapping());

  CsdlEntitySet es = new CsdlEntitySet().setName("test");
  EdmEntitySet edmES = new EdmEntitySetImpl(null, null, es);
  assertNull(edmES.getMapping());

  CsdlSingleton si = new CsdlSingleton().setName("test");
  EdmSingleton edmSi = new EdmSingletonImpl(null, null, si);
  assertNull(edmSi.getMapping());
}
 
Example #7
Source File: EdmMappingTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
public void getInternalNameViaMapping() {
  CsdlMapping mapping = new CsdlMapping().setInternalName("internalName");

  CsdlProperty property =
      new CsdlProperty().setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName()).setMapping(mapping);
  EdmProperty edmProperty = new EdmPropertyImpl(null, property);
  assertNotNull(edmProperty.getMapping());
  assertEquals("internalName", edmProperty.getMapping().getInternalName());

  CsdlParameter parameter =
      new CsdlParameter().setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName()).setMapping(mapping);
  EdmParameter edmParameter = new EdmParameterImpl(null, parameter);
  assertNotNull(edmParameter.getMapping());
  assertEquals("internalName", edmParameter.getMapping().getInternalName());

  CsdlEntitySet es = new CsdlEntitySet().setName("test").setMapping(mapping);
  EdmEntitySet edmES = new EdmEntitySetImpl(null, null, es);
  assertNotNull(edmES.getMapping());
  assertEquals("internalName", edmES.getMapping().getInternalName());

  CsdlSingleton si = new CsdlSingleton().setName("test").setMapping(mapping);
  EdmSingleton edmSi = new EdmSingletonImpl(null, null, si);
  assertNotNull(edmSi.getMapping());
  assertEquals("internalName", edmSi.getMapping().getInternalName());
}
 
Example #8
Source File: EdmMappingTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void getDataClassForPrimTypeViaMapping() {
  CsdlMapping mapping = new CsdlMapping().setMappedJavaClass(Date.class);
  CsdlProperty property = new CsdlProperty()
      .setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName())
      .setMapping(mapping);
  EdmProperty edmProperty = new EdmPropertyImpl(null, property);

  assertNotNull(edmProperty.getMapping());
  assertEquals(Date.class, edmProperty.getMapping().getMappedJavaClass());

  CsdlParameter parameter = new CsdlParameter()
      .setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName())
      .setMapping(mapping);
  EdmParameter edmParameter = new EdmParameterImpl(null, parameter);

  assertNotNull(edmParameter.getMapping());
  assertEquals(Date.class, edmParameter.getMapping().getMappedJavaClass());
}
 
Example #9
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 #10
Source File: EdmEntityContainerImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
/** Adds annotations to Entity type Properties derived from entity set
 * E.g of target paths 
 * MySchema.MyEntityContainer/MyEntitySet/MyProperty
 * MySchema.MyEntityContainer/MyEntitySet/MyNavigationProperty
 * MySchema.MyEntityContainer/MyEntitySet/MyComplexProperty/MyProperty
 * MySchema.MyEntityContainer/MyEntitySet/MyComplexProperty/MyNavigationProperty
 * @param entitySet
 * @param entityContainerName
 * @param entityType 
 * @return
 */
private void addAnnotationsToPropertiesIncludedFromES(CsdlEntitySet entitySet,
    FullQualifiedName entityContainerName, CsdlEntityType entityType) {
  for (CsdlProperty property : entityType.getProperties()) {
    removeAnnotationsAddedToPropertiesOfEntityType(entityType, property, entityContainerName);
      if (isPropertyComplex(property)) {
        CsdlComplexType complexType = getComplexTypeFromProperty(property);
        addAnnotationsToComplexTypeIncludedFromES(entitySet, entityContainerName,
           property, complexType);
      } else {
        addAnnotationsToETProperties(entitySet, entityContainerName, entityType, property);
      }
    }
   for (CsdlNavigationProperty navProperty : entityType.getNavigationProperties()) {
     removeAnnotationAddedToNavProperties(entityType, navProperty, entityContainerName);
     addAnnotationsToETNavProperties(entitySet, entityContainerName, entityType, navProperty);
   }
}
 
Example #11
Source File: MetadataParserTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void testComplexType() throws ODataException {
  // Test Complex Type
  CsdlComplexType ct = provider.getComplexType(new FullQualifiedName(NS, "City"));
  assertNotNull(ct);
  assertEquals(3, ct.getProperties().size());
  CsdlProperty p = ct.getProperties().get(0);
  assertEquals("CountryRegion", p.getName());
  assertEquals("Edm.String", p.getType());
  assertFalse(p.isNullable());

  ct = provider.getComplexType(new FullQualifiedName(NS, "Location"));
  assertNotNull(ct);

  ct = provider.getComplexType(new FullQualifiedName(NS, "EventLocation"));
  assertNotNull(ct);
}
 
Example #12
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 #13
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 #14
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 #15
Source File: ProductsEdmProvider.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Override
public CsdlComplexType getComplexType(FullQualifiedName complexTypeName) {
    if (complexTypeName.equals(ET_SPEC_FQN)) {
        CsdlProperty type = new CsdlProperty().setName(SPEC_PRODUCT_TYPE)
            .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty detail1 = new CsdlProperty().setName(SPEC_DETAIL_1)
            .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty detail2 = new CsdlProperty().setName(SPEC_DETAIL_2)
            .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
        CsdlProperty powerType = new CsdlProperty().setName(SPEC_POWER_TYPE)
            .setType(ET_POWER_TYPE_FQN);
        CsdlComplexType complexType = new CsdlComplexType();
        complexType.setName(ET_SPEC_NAME);
        complexType.setProperties(Arrays.asList(type, detail1, detail2, powerType));
        return complexType;
    }

    return null;
}
 
Example #16
Source File: EdmProviderImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
/**
 * @param bindingParameterTypeName
 * @param parameter 
 * @param isBindingParameterCollection 
 * @return
 * @throws ODataException
 */
private boolean isComplexPreviousTypeCompatibleToBindingParam(
    final FullQualifiedName bindingParameterTypeName, final CsdlParameter parameter, 
    Boolean isBindingParameterCollection)
    throws ODataException {
  CsdlComplexType complexType = provider.getComplexType(bindingParameterTypeName);
  if(provider.getEntityType(parameter.getTypeFQN()) == null){
    return false;
  }
  List<CsdlProperty> properties = provider.getEntityType(parameter.getTypeFQN()).getProperties();
  for (CsdlProperty property : properties) {
    String paramPropertyTypeName = property.getTypeAsFQNObject().getFullQualifiedNameAsString();
    if ((complexType != null && complexType.getBaseType() != null && 
        complexType.getBaseTypeFQN().getFullQualifiedNameAsString().equals(paramPropertyTypeName)) || 
        paramPropertyTypeName.equals(bindingParameterTypeName.getFullQualifiedNameAsString()) && 
        isBindingParameterCollection.booleanValue() == property.isCollection()) {
      return true;
    }
  }
  return false;
}
 
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: EdmPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void getTypeReturnsPrimitiveType() {
  EdmProviderImpl edm = new EdmProviderImpl(mock(CsdlEdmProvider.class));
  CsdlProperty propertyProvider = new CsdlProperty();
  propertyProvider.setType(EdmPrimitiveTypeKind.Binary.getFullQualifiedName());
  final EdmProperty property = new EdmPropertyImpl(edm, propertyProvider);
  assertTrue(property.isPrimitive());
  final EdmType type = property.getType();
  assertEquals(EdmTypeKind.PRIMITIVE, type.getKind());
  assertEquals(EdmPrimitiveType.EDM_NAMESPACE, type.getNamespace());
  assertEquals(EdmPrimitiveTypeKind.Binary.toString(), type.getName());
}
 
Example #19
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 #20
Source File: ODataAdapter.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This method returns Map with table names as key, and contains list of CsdlProperty of tables.
 * This map is used to initialize the EDMProvider.
 *
 * @return Map
 * @see #initializeEdmProvider(String)
 */
private Map<String, List<CsdlProperty>> getPropertiesMap() {
    Map<String, List<CsdlProperty>> propertiesMap = new HashMap<>();
    for (String tableName : this.dataHandler.getTableList()) {
        propertiesMap.put(tableName, getProperties(tableName));
    }
    return propertiesMap;
}
 
Example #21
Source File: EdmPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EdmException.class)
public void getTypeReturnsWrongType() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  EdmProviderImpl edm = new EdmProviderImpl(provider);
  final CsdlProperty propertyProvider = new CsdlProperty()
      .setType(new FullQualifiedName("ns", "wrong"));
  final EdmProperty property = new EdmPropertyImpl(edm, propertyProvider);
  property.getType();
  fail();
}
 
Example #22
Source File: EdmPropertyImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EdmException.class)
public void getTypeReturnsNoTypeKind() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  EdmProviderImpl edm = new EdmProviderImpl(provider);
  final CsdlProperty propertyProvider = new CsdlProperty()
      .setType(new FullQualifiedName(EdmPrimitiveType.EDM_NAMESPACE, "type"));
  final EdmProperty property = new EdmPropertyImpl(edm, propertyProvider);
  property.getType();
  fail();
}
 
Example #23
Source File: CarsEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public CsdlComplexType getComplexType(final FullQualifiedName complexTypeName) throws ODataException {
  if (CT_ADDRESS.equals(complexTypeName)) {
    return new CsdlComplexType().setName(CT_ADDRESS.getName()).setProperties(Arrays.asList(
        new CsdlProperty().setName("Street").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()),
        new CsdlProperty().setName("City").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()),
        new CsdlProperty().setName("ZipCode").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()),
        new CsdlProperty().setName("Country").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())
        ));
  }
  return null;
}
 
Example #24
Source File: EdmComplexTypeImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Before
public void setupTypes() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  EdmProviderImpl edm = new EdmProviderImpl(provider);

  FullQualifiedName baseName = new FullQualifiedName("namespace", "BaseTypeName");
  CsdlComplexType baseComplexType = new CsdlComplexType();
  List<CsdlProperty> baseProperties = new ArrayList<CsdlProperty>();
  baseProperties.add(new CsdlProperty().setName("prop1").setType(
      EdmPrimitiveTypeKind.String.getFullQualifiedName()));
  List<CsdlNavigationProperty> baseNavigationProperties = new ArrayList<CsdlNavigationProperty>();
  baseNavigationProperties.add(new CsdlNavigationProperty().setName("nav1"));
  baseComplexType.setName("BaseTypeName").setAbstract(false).setOpenType(false).setProperties(baseProperties)
      .setNavigationProperties(baseNavigationProperties);
  when(provider.getComplexType(baseName)).thenReturn(baseComplexType);

  baseType = new EdmComplexTypeImpl(edm, baseName, baseComplexType);

  FullQualifiedName name = new FullQualifiedName("namespace", "typeName");
  CsdlComplexType complexType = new CsdlComplexType().setBaseType(baseName);
  List<CsdlProperty> properties = new ArrayList<CsdlProperty>();
  properties.add(new CsdlProperty().setName("prop2").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
  List<CsdlNavigationProperty> navigationProperties = new ArrayList<CsdlNavigationProperty>();
  navigationProperties.add(new CsdlNavigationProperty().setName("nav2"));
  complexType.setName("BaseTypeName").setAbstract(false).setOpenType(false).setProperties(properties)
      .setNavigationProperties(navigationProperties);
  when(provider.getComplexType(name)).thenReturn(complexType);

  type = new EdmComplexTypeImpl(edm, name, complexType);
}
 
Example #25
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 #26
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 #27
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlComplexType getComplexType(final FullQualifiedName complexTypeName) {
  CsdlComplexType complexType = null;
  if (complexTypeName.equals(CT_ADDRESS_FQN)) {
    complexType = new CsdlComplexType().setName(CT_ADDRESS_NAME)
        .setProperties(Arrays.asList(
            new CsdlProperty()
                .setName("City")
                .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()),
            new CsdlProperty()
            .setName("Country")
            .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())));
  }
  return complexType;
}
 
Example #28
Source File: MetadataParser.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private CsdlProperty readProperty(XMLEventReader reader, StartElement element)
    throws XMLStreamException {
  CsdlProperty property = new CsdlProperty();
  property.setName(attr(element, "Name"));
  property.setType(readType(element));
  property.setCollection(isCollectionType(element));
  property.setNullable(Boolean.parseBoolean(attr(element, "Nullable") == null ? "true" : attr(
      element, "Nullable")));
  if (attr(element, "Unicode") != null) {
    property.setUnicode(Boolean.parseBoolean(attr(element, "Unicode")));
  }

  String maxLength = attr(element, "MaxLength");
  if (maxLength != null) {
    property.setMaxLength(Integer.parseInt(maxLength));
  }
  String precision = attr(element, "Precision");
  if (precision != null) {
    property.setPrecision(Integer.parseInt(precision));
  }
  String scale = attr(element, "Scale");
  if (scale != null) {
    property.setScale(Integer.parseInt(scale));
  }
  String srid = attr(element, "SRID");
  if (srid != null) {
    property.setSrid(SRID.valueOf(srid));
  }
  String defaultValue = attr(element, "DefaultValue");
  if (defaultValue != null) {
    property.setDefaultValue(defaultValue);
  }
  peekAnnotations(reader, element.getName().getLocalPart(), property);
  return property;
}
 
Example #29
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 #30
Source File: MetadataParser.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void readComplexType(XMLEventReader reader, StartElement element, CsdlSchema schema)
    throws XMLStreamException {
  CsdlComplexType complexType = new CsdlComplexType();
  complexType.setProperties(new ArrayList<CsdlProperty>());
  complexType.setNavigationProperties(new ArrayList<CsdlNavigationProperty>());
  complexType.setName(attr(element, "Name"));
  if (attr(element, "BaseType") != null) {
    complexType.setBaseType(new FullQualifiedName(attr(element, "BaseType")));
  }
  complexType.setAbstract(Boolean.parseBoolean(attr(element, "Abstract")));
  complexType.setOpenType(Boolean.parseBoolean(attr(element, "OpenType")));
  readProperties(reader, complexType);

  schema.getComplexTypes().add(complexType);
}