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

The following examples show how to use org.apache.olingo.commons.api.edm.provider.CsdlComplexType. 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: CarsEdmProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public List<CsdlSchema> getSchemas() throws ODataException {
  List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
  CsdlSchema schema = new CsdlSchema();
  schema.setNamespace(NAMESPACE);
  // EntityTypes
  List<CsdlEntityType> entityTypes = new ArrayList<CsdlEntityType>();
  entityTypes.add(getEntityType(ET_CAR));
  entityTypes.add(getEntityType(ET_MANUFACTURER));
  schema.setEntityTypes(entityTypes);

  // ComplexTypes
  List<CsdlComplexType> complexTypes = new ArrayList<CsdlComplexType>();
  complexTypes.add(getComplexType(CT_ADDRESS));
  schema.setComplexTypes(complexTypes);

  // EntityContainer
  schema.setEntityContainer(getEntityContainer());
  schemas.add(schema);

  return schemas;
}
 
Example #2
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 #3
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 #4
Source File: EdmParameterImplTest.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);
  CsdlParameter parameterProvider = new CsdlParameter();
  parameterProvider.setType(complexTypeName);
  final EdmParameter parameter = new EdmParameterImpl(edm, parameterProvider);
  assertFalse(parameter.isCollection());
  final EdmType type = parameter.getType();
  assertEquals(EdmTypeKind.COMPLEX, type.getKind());
  assertEquals("ns", type.getNamespace());
  assertEquals("complex", type.getName());
}
 
Example #5
Source File: MetadataDocumentXmlSerializerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public CsdlComplexType getComplexType(final FullQualifiedName complexTypeName) throws ODataException {
  if (complexTypeName.equals(nameCTTwoPrim)) {
    return new CsdlComplexType()
    .setName("CTTwoPrim")
    .setProperties(Arrays.asList(propertyInt16_NotNullable, propertyString));

  }
  if (complexTypeName.equals(nameCTTwoPrimBase)) {
    return new CsdlComplexType()
    .setName("CTTwoPrimBase")
    .setBaseType(nameCTTwoPrim)
    .setProperties(Arrays.asList(propertyInt16_NotNullable, propertyString));
  }
  return null;

}
 
Example #6
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 #7
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 #8
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 #9
Source File: EdmProviderImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public EdmComplexType createComplexType(final FullQualifiedName complexTypeName) {
  try {
    final CsdlComplexType complexType = provider.getComplexType(complexTypeName);
    if (complexType != null) {
      List<CsdlAnnotation> annotations = getAnnotationsMap().get(complexTypeName.getFullQualifiedNameAsString());
      if (null != annotations && !annotations.isEmpty()) {
        addAnnotationsOnStructuralType(complexType, annotations);
      }
      String aliasName = getAliasInfo(complexTypeName.getNamespace());
      List<CsdlAnnotation> annotationsOnAlias = getAnnotationsMap().get(aliasName + DOT + complexTypeName.getName());
      if (null != annotationsOnAlias && !annotationsOnAlias.isEmpty()) {
        addAnnotationsOnStructuralType(complexType, annotationsOnAlias);
      }
      
  if (!isComplexDerivedFromES()) {
        addStructuralTypeAnnotations(complexType, complexTypeName, provider.getEntityContainer());
      }
      return new EdmComplexTypeImpl(this, complexTypeName, complexType);
    }
    return null;
  } catch (ODataException e) {
    throw new EdmException(e);
  }
}
 
Example #10
Source File: CsdlTypeValidator.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
/**
 * fetch the actual navigation property from the remaning path
 * @param remainingPath
 * @param strNavProperty
 * @param sourceTypeHavingNavProp
 * @return CsdlNavigationProperty
 */
private CsdlNavigationProperty fetchNavigationProperty(String remainingPath,
    String strNavProperty, CsdlStructuralType sourceTypeHavingNavProp) {
  String[] paths = remainingPath.split("/");
  for (String path : paths) {
    FullQualifiedName fqName = null;
    if (sourceTypeHavingNavProp instanceof CsdlComplexType) {
      fqName = ((CsdlComplexType)sourceTypeHavingNavProp).getProperty(path).getTypeAsFQNObject();
    } else if (sourceTypeHavingNavProp instanceof CsdlEntityType) {
      fqName = ((CsdlEntityType)sourceTypeHavingNavProp).getProperty(path).getTypeAsFQNObject();
    }
    if (fqName != null) {
      String namespace = aliasNamespaceMap.get(fqName.getNamespace());
      fqName = namespace != null ? new FullQualifiedName(namespace, fqName.getName()) : fqName;
    }
    
    sourceTypeHavingNavProp = csdlEntityTypesMap.get(fqName) != null ? 
        csdlEntityTypesMap.get(fqName) : 
          csdlComplexTypesMap.get(fqName);
  }
  return sourceTypeHavingNavProp.getNavigationProperty(strNavProperty);
}
 
Example #11
Source File: ObservationCsdlEdmProvider.java    From arctic-sea with Apache License 2.0 6 votes vote down vote up
@Override
public CsdlComplexType getComplexType(FullQualifiedName name) throws ODataException {
    if (name.equals(FQN.ABSTRACT_TIME_OBJECT)) {
        return newAbstractComplexType(FQN.ABSTRACT_TIME_OBJECT);
    } else if (name.equals(FQN.TIME_INSTANT)) {
        return newComplexType(FQN.TIME_INSTANT, FQN.ABSTRACT_TIME_OBJECT);
    } else if (name.equals(FQN.TIME_PERIOD)) {
        return newComplexType(FQN.TIME_PERIOD,
                              FQN.ABSTRACT_TIME_OBJECT,
                              newProperty(Prop.EN_BEGIN_POSITION, FQN.DATE_TIME),
                              newProperty(Prop.EN_END_POSITION, FQN.DATE_TIME));
    } else if (name.equals(FQN.FEATURE_OF_INTEREST)) {
        return newComplexType(FQN.FEATURE_OF_INTEREST,
                              newProperty(Prop.ID, FQN.STRING),
                              newProperty(Prop.SHAPE, FQN.GEOMETRY_POINT));
    } else if (name.equals(FQN.RESULT)) {
        return newAbstractComplexType(FQN.RESULT);
    } else {
        return super.getComplexType(name);
    }
}
 
Example #12
Source File: CsdlTypeValidator.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param aliasNamespaceMap
 * @param csdlContainersMap
 * @param csdlEntityTypesMap
 * @param csdlComplexTypesMap
 * @param csdlActionsMap
 * @param csdlFunctionsMap
 * @param csdlTermsMap
 */
public CsdlTypeValidator(Map<String, String> aliasNamespaceMap, 
    Map<FullQualifiedName, CsdlEntityContainer> csdlContainersMap,
    Map<FullQualifiedName, CsdlEntityType> csdlEntityTypesMap,
    Map<FullQualifiedName, CsdlComplexType> csdlComplexTypesMap,
    Map<FullQualifiedName, CsdlAction> csdlActionsMap,
    Map<FullQualifiedName, CsdlFunction> csdlFunctionsMap) {
  this.aliasNamespaceMap = aliasNamespaceMap;
  this.csdlContainersMap = csdlContainersMap;
  this.csdlEntityTypesMap = csdlEntityTypesMap;
  this.csdlComplexTypesMap = csdlComplexTypesMap;
  this.csdlActionsMap = csdlActionsMap;
  this.csdlFunctionsMap = csdlFunctionsMap;
}
 
Example #13
Source File: CsdlTypeValidator.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/**
 * This method validates Csdl Complex types.
 * Looks for correct namespace aliases and correct complex base types
 */
private void validateCsdlComplexTypes() {
  for (Map.Entry<FullQualifiedName, CsdlComplexType> complexTypes : csdlComplexTypesMap.entrySet()) {
    if (complexTypes.getValue() != null && complexTypes.getKey() != null) {
      CsdlComplexType complexType = complexTypes.getValue();
      if (complexType.getBaseType() != null) {
        FullQualifiedName baseTypeFQName = complexType.getBaseTypeFQN();
        if (!csdlComplexTypesMap.containsKey(baseTypeFQName)) {
          validateCsdlComplexTypeWithAlias(baseTypeFQName);
        }
      }
    }
  }
}
 
Example #14
Source File: CsdlTypeValidator.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/**
 * This looks for the last fully qualified identifier to fetch the navigation property
 * e.g if navigation property path is Microsoft.Exchange.Services.OData.Model.ItemAttachment/Item 
 * then it fetches the entity ItemAttachment and fetches the navigation property Item
 * if navigation property path is EntityType/ComplexType/OData.Model.DerivedComplexType/Item
 * then it fetches the complex type DerivedComplexType and fetches the navigation property Item
 * @param navBindingPath
 * @return CsdlNavigationProperty
 */
private CsdlNavigationProperty findLastQualifiedNameHavingNavigationProperty(String navBindingPath,
    CsdlEntityType sourceEntityType) {
  String[] paths = navBindingPath.split("/");
  String lastFullQualifiedName = "";
  for (String path : paths) {
    if (path.contains(".")) {
      lastFullQualifiedName = path;
    }
  }
  String strNavProperty = paths[paths.length - 1];
  String remainingPath = navBindingPath.substring(navBindingPath.indexOf(lastFullQualifiedName) 
      + lastFullQualifiedName.length() + (lastFullQualifiedName.length() == 0 ? 0 : 1), 
      navBindingPath.lastIndexOf(strNavProperty));
  if (remainingPath.length() > 0) {
    remainingPath = remainingPath.substring(0, remainingPath.length() - 1);
  }
  CsdlNavigationProperty navProperty = null;
  CsdlEntityType sourceEntityTypeHavingNavProp = lastFullQualifiedName.length() == 0 ? sourceEntityType : 
    (csdlEntityTypesMap.containsKey(new FullQualifiedName(lastFullQualifiedName)) ? 
        csdlEntityTypesMap.get(new FullQualifiedName(lastFullQualifiedName)) : 
          csdlEntityTypesMap.get(fetchCorrectNamespaceFromAlias(new FullQualifiedName(lastFullQualifiedName))));
  if (sourceEntityTypeHavingNavProp == null) {
    CsdlComplexType sourceComplexTypeHavingNavProp = 
        csdlComplexTypesMap.containsKey(new FullQualifiedName(lastFullQualifiedName)) ?
        csdlComplexTypesMap.get(new FullQualifiedName(lastFullQualifiedName)) : 
          csdlComplexTypesMap.get(fetchCorrectNamespaceFromAlias(new FullQualifiedName(lastFullQualifiedName)));
    if (sourceComplexTypeHavingNavProp == null) {
      throw new RuntimeException("The fully Qualified type " + lastFullQualifiedName + 
          " mentioned in navigation binding path not found ");
    }
    navProperty = remainingPath.length() > 0 ? fetchNavigationProperty(remainingPath, strNavProperty, 
        sourceComplexTypeHavingNavProp) : sourceComplexTypeHavingNavProp.getNavigationProperty(strNavProperty);
  } else {
    navProperty = remainingPath.length() > 0 ? fetchNavigationProperty(remainingPath, strNavProperty, 
        sourceEntityTypeHavingNavProp) : sourceEntityTypeHavingNavProp.getNavigationProperty(strNavProperty);
  }
  return navProperty;
}
 
Example #15
Source File: ClientCsdlEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlComplexType getComplexType(final FullQualifiedName complexTypeName) throws ODataException {
  CsdlSchema schema = xmlSchemas.get(complexTypeName.getNamespace());
  if (schema != null) {
    return schema.getComplexType(complexTypeName.getName());
  }
  return null;
}
 
Example #16
Source File: ClientCsdlComplexType.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
protected CsdlComplexType doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException {

  final ClientCsdlComplexType complexType = new ClientCsdlComplexType();

  for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
    final JsonToken token = jp.getCurrentToken();
    if (token == JsonToken.FIELD_NAME) {
      if ("Name".equals(jp.getCurrentName())) {
        complexType.setName(jp.nextTextValue());
      } else if ("Abstract".equals(jp.getCurrentName())) {
        complexType.setAbstract(BooleanUtils.toBoolean(jp.nextTextValue()));
      } else if ("BaseType".equals(jp.getCurrentName())) {
        complexType.setBaseType(jp.nextTextValue());
      } else if ("OpenType".equals(jp.getCurrentName())) {
        complexType.setOpenType(BooleanUtils.toBoolean(jp.nextTextValue()));
      } else if ("Property".equals(jp.getCurrentName())) {
        jp.nextToken();
        complexType.getProperties().add(jp.readValueAs(ClientCsdlProperty.class));
      } else if ("NavigationProperty".equals(jp.getCurrentName())) {
        jp.nextToken();
        complexType.getNavigationProperties().add(jp.readValueAs(ClientCsdlNavigationProperty.class));
      } else if ("Annotation".equals(jp.getCurrentName())) {
        jp.nextToken();
        complexType.getAnnotations().add(jp.readValueAs(ClientCsdlAnnotation.class));
      }
    }
  }

  return complexType;
}
 
Example #17
Source File: SchemaBasedEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlComplexType getComplexType(final FullQualifiedName fqn) throws ODataException {
  CsdlSchema schema = getSchema(fqn.getNamespace());
  if (schema != null && schema.getComplexTypes() != null) {
    for (CsdlComplexType type : schema.getComplexTypes()) {
      if (type.getName().equals(fqn.getName())) {
        return type;
      }
    }
  }
  return null;
}
 
Example #18
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 #19
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);
}
 
Example #20
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public List<CsdlSchema> getSchemas() {
  // create Schema
  CsdlSchema schema = new CsdlSchema();
  schema.setNamespace(NAMESPACE);

  // add EntityTypes
  List<CsdlEntityType> entityTypes = new ArrayList<CsdlEntityType>();
  entityTypes.add(getEntityType(ET_PRODUCT_FQN));
  entityTypes.add(getEntityType(ET_CATEGORY_FQN));
  entityTypes.add(getEntityType(ET_SUPPLIER_FQN));
  schema.setEntityTypes(entityTypes);

  // add Complex Types
  List<CsdlComplexType> complexTypes = new ArrayList<CsdlComplexType>();
  complexTypes.add(getComplexType(CT_ADDRESS_FQN));
  schema.setComplexTypes(complexTypes);
  
  // add EntityContainer
  schema.setEntityContainer(getEntityContainer());

  // finally
  List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
  schemas.add(schema);

  return schemas;
}
 
Example #21
Source File: MetadataDocumentJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlComplexType getComplexType(final FullQualifiedName complexTypeName) throws ODataException {
  if (complexTypeName.equals(nameCTTwoPrim)) {
    return new CsdlComplexType()
    .setName("CTTwoPrim")
    .setAbstract(true)
    .setProperties(Arrays.asList(propertyInt16_NotNullable, propertyString));

  }
  if (complexTypeName.equals(nameCTTwoPrimBase)) {
    CsdlAnnotation annotation = new CsdlAnnotation()
        .setTerm("Core.Description")
        .setQualifier("Target")
        .setExpression(new CsdlConstantExpression(ConstantExpressionType.String, "Description of Complex Type"));
    
    return new CsdlComplexType()
    .setName("CTTwoPrimBase")
    .setBaseType(nameCTTwoPrim)
    .setProperties(Arrays.asList(propertyInt16_NotNullable, propertyString))
    .setAnnotations(Arrays.asList(annotation));
  }
  if (complexTypeName.equals(nameCTEntityInfo)) {
    return new CsdlComplexType()
        .setName("CTEntityInfo")
        .setProperties(Arrays.asList(idProperty, createdProperty));
  }
  if (complexTypeName.equals(nameCTPrimComp)) {
    return new CsdlComplexType()
    .setName("CTPrimComp")
    .setProperties(Arrays.asList(propertyString));
  }
  return null;

}
 
Example #22
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 #23
Source File: EdmComplexTypeImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EdmException.class)
public void nonExistingBaseType() throws Exception {
  CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
  EdmProviderImpl edm = new EdmProviderImpl(provider);
  FullQualifiedName typeWithNonexistingBaseTypeName = new FullQualifiedName("namespace", "typeName");
  CsdlComplexType complexTypeForNonexistingBaseType =
      new CsdlComplexType().setBaseType(new FullQualifiedName("wrong", "wrong"));
  complexTypeForNonexistingBaseType.setName("typeName");
  when(provider.getComplexType(typeWithNonexistingBaseTypeName)).thenReturn(complexTypeForNonexistingBaseType);
  EdmComplexTypeImpl instance =
      new EdmComplexTypeImpl(edm, typeWithNonexistingBaseTypeName, complexTypeForNonexistingBaseType);
  instance.getBaseType();
}
 
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: EdmEntityContainerImpl.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/** adds annotations to entity type properties derived from singleton
 * E.g of target paths
 * MySchema.MyEntityContainer/MySingleton/MyComplexProperty/MyNavigationProperty
 * @param singleton
 * @param isPropAnnotationsCleared
 * @param isNavPropAnnotationsCleared
 * @param entityType
 * @param entityContainerName
 * @param annotationGrp
 */
private void addAnnotationsToPropertiesDerivedFromSingleton(CsdlSingleton singleton, 
    CsdlEntityType entityType, FullQualifiedName entityContainerName) {
  String entitySetName = null;
  String schemaName = null;
  String containerName = null;
  try {
    List<CsdlEntitySet> entitySets = this.provider.getEntityContainer() != null ? 
        this.provider.getEntityContainer().getEntitySets() : new ArrayList<CsdlEntitySet>();
    for (CsdlEntitySet entitySet : entitySets) {
      entitySetName = entitySet.getName();
      String entityTypeName = entitySet.getTypeFQN().getFullQualifiedNameAsString();
      if ((null != entityTypeName && entityTypeName.equalsIgnoreCase(
          entitySet.getTypeFQN().getNamespace() + DOT + entityType.getName()))) {
        containerName = this.provider.getEntityContainer().getName();
        schemaName = entitySet.getTypeFQN().getNamespace();
        for (CsdlProperty property : entityType.getProperties()) {
          if (isPropertyComplex(property)) {
            CsdlComplexType complexType = getComplexTypeFromProperty(property);
            addAnnotationsToComplexTypeIncludedFromSingleton(singleton, property, complexType);
          }
          removeAnnotationsAddedToPropertiesOfEntityType(entityType, property, entityContainerName);
          removeAnnotationsAddedToPropertiesViaEntitySet(entityType, property, 
              schemaName, containerName, entitySetName);
        }
      }
    }
  } catch (ODataException e) {
    throw new EdmException(e);
  }
}
 
Example #26
Source File: ProductsEdmProvider.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public List<CsdlSchema> getSchemas() {

    // create Schema
    CsdlSchema schema = new CsdlSchema();
    schema.setNamespace(NAMESPACE);

    List<CsdlEnumType> enumTypes = new ArrayList<>();
    enumTypes.add(getEnumType(ET_POWER_TYPE_FQN));
    schema.setEnumTypes(enumTypes);

    List<CsdlComplexType> complexTypes = new ArrayList<>();
    complexTypes.add(getComplexType(ET_SPEC_FQN));
    schema.setComplexTypes(complexTypes);

    // add EntityTypes
    List<CsdlEntityType> entityTypes = new ArrayList<>();
    entityTypes.add(getEntityType(ET_PRODUCT_FQN));
    schema.setEntityTypes(entityTypes);

    // add EntityContainer
    schema.setEntityContainer(getEntityContainer());

    // finally
    List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
    schemas.add(schema);

    return schemas;
}
 
Example #27
Source File: EdmProviderImpl.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/** Check if annotations are added on navigation properties of a structural type
 * @param structuralType
 * @param typeName
 * @param csdlEntityContainer 
 * @param isNavPropAnnotationsCleared
 * @param annotationGrp
 */
private void updateAnnotationsOnStructuralNavProperties(CsdlStructuralType structuralType, 
    FullQualifiedName typeName, CsdlEntityContainer csdlEntityContainer) {
  List<CsdlNavigationProperty> navProperties = structuralType.getNavigationProperties();
  String containerName = null;
  String schemaName = null;
  String entitySetName = null;
  List<CsdlEntitySet> entitySets = csdlEntityContainer != null ? 
      csdlEntityContainer.getEntitySets() : new ArrayList<CsdlEntitySet>();
  if (structuralType instanceof CsdlComplexType) {
    removeAnnotationsAddedToCTNavPropFromES(structuralType, typeName, csdlEntityContainer, navProperties, entitySets);
  } else {
    for (CsdlEntitySet entitySet : entitySets) {
      entitySetName = entitySet.getName();
      String entityTypeName = entitySet.getTypeFQN().getFullQualifiedNameAsString();
      if (null != entityTypeName && entityTypeName.equalsIgnoreCase(typeName.getFullQualifiedNameAsString())) {
        containerName = csdlEntityContainer.getName();
        schemaName = typeName.getNamespace();
        break;
      }
    }
    for (CsdlNavigationProperty navProperty : navProperties) {
      List<CsdlAnnotation> annotPropDerivedFromES = getAnnotationsMap().get(schemaName + DOT + 
          containerName + SLASH +  entitySetName + SLASH + navProperty.getName());
      removeAnnotationsOnNavPropDerivedFromEntitySet(structuralType, navProperty, annotPropDerivedFromES);
      String aliasName = getAliasInfo(schemaName);
      List<CsdlAnnotation> annotPropDerivedFromESOnAlias = getAnnotationsMap().get(aliasName + DOT + 
          containerName + SLASH +  entitySetName + SLASH + navProperty.getName());
      removeAnnotationsOnNavPropDerivedFromEntitySet(structuralType, navProperty, annotPropDerivedFromESOnAlias);
      
      List<CsdlAnnotation> navPropAnnotations = getAnnotationsMap().get(
          typeName + SLASH + navProperty.getName());
      addAnnotationsOnNavProperties(structuralType, navProperty, navPropAnnotations);
      aliasName = getAliasInfo(typeName.getNamespace());
      List<CsdlAnnotation> navPropAnnotationsOnAlias = getAnnotationsMap().get(
          aliasName + DOT + typeName.getName() + SLASH + navProperty.getName());
      addAnnotationsOnNavProperties(structuralType, navProperty, navPropAnnotationsOnAlias);
    }
  }
}
 
Example #28
Source File: EdmProviderImpl.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/** Check if annotations are added on properties of a structural type
 * @param structuralType
 * @param typeName
 * @param csdlEntityContainer
 */
private void updateAnnotationsOnStructuralProperties(CsdlStructuralType structuralType, FullQualifiedName typeName,
    CsdlEntityContainer csdlEntityContainer) {
  List<CsdlProperty> properties = structuralType.getProperties();
  String containerName = null;
  String schemaName = null;
  String entitySetName = null;
  List<CsdlEntitySet> entitySets = null != csdlEntityContainer ? 
      csdlEntityContainer.getEntitySets() : new ArrayList<>();
  if (structuralType instanceof CsdlComplexType) {
    removeAnnotationsAddedToCTTypePropFromES(structuralType, typeName, csdlEntityContainer, properties, entitySets);
  } else {
    for (CsdlEntitySet entitySet : entitySets) {
      entitySetName = entitySet.getName();
      String entityTypeName = entitySet.getTypeFQN().getFullQualifiedNameAsString();
      if (null != entityTypeName && entityTypeName.equalsIgnoreCase(typeName.getFullQualifiedNameAsString())) {
        containerName = csdlEntityContainer.getName();
        schemaName = typeName.getNamespace();
        break;
      }
    }
    for (CsdlProperty property : properties) {
      List<CsdlAnnotation> annotPropDerivedFromES = getAnnotationsMap().get(schemaName + DOT + 
          containerName + SLASH +  entitySetName + SLASH + property.getName());
      removeAnnotationsOnPropDerivedFromEntitySet(structuralType, property, annotPropDerivedFromES);
      String aliasName = getAliasInfo(schemaName);
      List<CsdlAnnotation> annotPropDerivedFromESOnAlias = getAnnotationsMap().get(aliasName + DOT + 
          containerName + SLASH +  entitySetName + SLASH + property.getName());
      removeAnnotationsOnPropDerivedFromEntitySet(structuralType, property, annotPropDerivedFromESOnAlias);
      List<CsdlAnnotation> propAnnotations = getAnnotationsMap().
          get(typeName.getFullQualifiedNameAsString() + SLASH + property.getName());
      addAnnotationsOnPropertiesOfStructuralType(structuralType, property, propAnnotations);
      aliasName = getAliasInfo(typeName.getNamespace());
      List<CsdlAnnotation> propAnnotationsOnAlias = getAnnotationsMap().
          get(aliasName + DOT + typeName.getName() + SLASH + property.getName());
      addAnnotationsOnPropertiesOfStructuralType(structuralType, property, propAnnotationsOnAlias);
    }
  }
}
 
Example #29
Source File: EdmSchemaImpl.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected List<EdmComplexType> createComplexTypes() {
  final List<EdmComplexType> edmComplexTypes = new ArrayList<>();
  final List<CsdlComplexType> providerComplexTypes = schema.getComplexTypes();
  if (providerComplexTypes != null) {
    for (CsdlComplexType complexType : providerComplexTypes) {
      FullQualifiedName comlexTypeName = new FullQualifiedName(namespace, complexType.getName());
      edm.addStructuralTypeAnnotations(complexType, comlexTypeName, schema.getEntityContainer());
      EdmComplexTypeImpl complexTypeImpl = new EdmComplexTypeImpl(edm, comlexTypeName, complexType);
      edmComplexTypes.add(complexTypeImpl);
      edm.cacheComplexType(comlexTypeName, complexTypeImpl);
    }
  }
  return edmComplexTypes;
}
 
Example #30
Source File: EdmEntityContainerImpl.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/**
 * Adds annotations on complex type navigation properties
 * @param complexType
 * @param complexNavProperty
 * @param annotations
 */
private void addAnnotationsOnComplexTypeNavProperties(CsdlComplexType complexType,
    CsdlNavigationProperty complexNavProperty, List<CsdlAnnotation> annotations) {
  if (null != annotations && !annotations.isEmpty()) {
    isAnnotationsIncluded = true;
    for (CsdlAnnotation annotation : annotations) {
      if (!compareAnnotations(complexType.getNavigationProperty(
          complexNavProperty.getName()).getAnnotations(), annotation)) {
        complexType.getNavigationProperty(complexNavProperty.getName()).getAnnotations().add(annotation); 
      }
    }
  }
}