Java Code Examples for org.apache.olingo.commons.api.edm.Edm#getComplexType()

The following examples show how to use org.apache.olingo.commons.api.edm.Edm#getComplexType() . 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: EdmProviderImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void nothingSpecifiedMustNotResultInExceptions() throws Exception {
  CsdlEdmProvider localProvider = mock(CsdlEdmProvider.class);
  when(localProvider.getActions(FQN)).thenReturn(null);
  when(localProvider.getFunctions(FQN)).thenReturn(null);
  Edm localEdm = new EdmProviderImpl(localProvider);
  localEdm.getUnboundAction(FQN);
  localEdm.getUnboundFunction(FQN, null);
  localEdm.getBoundAction(FQN, FQN, true);
  localEdm.getBoundFunction(FQN, FQN, true, null);
  localEdm.getComplexType(FQN);
  localEdm.getEntityContainer(FQN);
  localEdm.getEntityType(FQN);
  localEdm.getEnumType(FQN);
  localEdm.getTypeDefinition(FQN);
}
 
Example 2
Source File: ParserHelper.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
protected static EdmStructuredType parseTypeCast(UriTokenizer tokenizer, final Edm edm,
    final EdmStructuredType referencedType) throws UriParserException {
  if (tokenizer.next(TokenKind.QualifiedName)) {
    final FullQualifiedName qualifiedName = new FullQualifiedName(tokenizer.getText());
    final EdmStructuredType type = referencedType.getKind() == EdmTypeKind.ENTITY ?
        edm.getEntityType(qualifiedName) :
        edm.getComplexType(qualifiedName);
    if (type == null) {
      throw new UriParserSemanticException("Type '" + qualifiedName + "' not found.",
          UriParserSemanticException.MessageKeys.UNKNOWN_PART, qualifiedName.getFullQualifiedNameAsString());
    } else {
      if (!type.compatibleTo(referencedType)) {
        throw new UriParserSemanticException("The type cast '" + qualifiedName + "' is not compatible.",
            UriParserSemanticException.MessageKeys.INCOMPATIBLE_TYPE_FILTER, type.getName());
      }
    }
    return type;
  }
  return null;
}
 
Example 3
Source File: EdmTypeInfo.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private EdmTypeInfo(final Edm edm, final String typeExpression, final boolean includeAnnotations) {
  String baseType;
  final int collStartIdx = typeExpression.indexOf("Collection(");
  final int collEndIdx = typeExpression.lastIndexOf(')');
  if (collStartIdx == -1) {
    baseType = typeExpression;
    collection = false;
  } else {
    if (collEndIdx == -1) {
      throw new IllegalArgumentException("Malformed type: " + typeExpression);
    }

    collection = true;
    baseType = typeExpression.substring(collStartIdx + 11, collEndIdx);
  }

  if (baseType.startsWith("#")) {
    baseType = baseType.substring(1);
  }

  String typeName;
  String namespace;

  final int lastDotIdx = baseType.lastIndexOf('.');
  if (lastDotIdx == -1) {
    namespace = EdmPrimitiveType.EDM_NAMESPACE;
    typeName = baseType;
  } else {
    namespace = baseType.substring(0, lastDotIdx);
    typeName = baseType.substring(lastDotIdx + 1);
  }

  if (typeName == null || typeName.isEmpty()) {
    throw new IllegalArgumentException("Null or empty type name in " + typeExpression);
  }

  fullQualifiedName = new FullQualifiedName(namespace, typeName);

  primitiveType = EdmPrimitiveTypeKind.getByName(typeName);

  if (primitiveType == null && edm != null) {
    typeDefinition = edm.getTypeDefinition(fullQualifiedName);
    if (typeDefinition == null) {
      enumType = edm.getEnumType(fullQualifiedName);
      if (enumType == null) {
        if (includeAnnotations) {
          complexType = ((AbstractEdm)edm).
              getComplexTypeWithAnnotations(fullQualifiedName, true);
        } else {
          complexType = edm.getComplexType(fullQualifiedName);
        }
        if (complexType == null) {
          entityType = edm.getEntityType(fullQualifiedName);
        }
      }
    }
  }
}
 
Example 4
Source File: MetadataTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void parse() {
  final Edm edm = client.getReader().readMetadata(getClass().getResourceAsStream("metadata.xml"));
  assertNotNull(edm);

  // 1. Enum
  final EdmEnumType responseEnumType = edm.getEnumType(
      new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "ResponseType"));
  assertNotNull(responseEnumType);
  assertEquals(6, responseEnumType.getMemberNames().size());
  assertEquals("3", responseEnumType.getMember("Accepted").getValue());
  assertEquals(EdmTypeKind.ENUM, responseEnumType.getKind());

  // 2. Complex
  final EdmComplexType responseStatus = edm.getComplexType(
      new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "ResponseStatus"));
  assertNotNull(responseStatus);
  assertTrue(responseStatus.getNavigationPropertyNames().isEmpty());
  assertEquals("Recipient", responseStatus.getBaseType().getName());
  assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.DateTimeOffset),
      responseStatus.getProperty("Time").getType());

  // 3. Entity
  final EdmEntityType user = edm.getEntityType(
      new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "User"));
  assertNotNull(user);
  assertFalse(user.getPropertyNames().isEmpty());
  assertFalse(user.getNavigationPropertyNames().isEmpty());

  final EdmEntityType entity = edm.getEntityType(
      new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Entity"));
  assertEquals(entity, user.getBaseType());
  assertFalse(entity.getPropertyNames().isEmpty());
  assertTrue(entity.getNavigationPropertyNames().isEmpty());

  final EdmEntityType folder = edm.getEntityType(
      new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Folder"));
  assertEquals(folder, user.getNavigationProperty("Inbox").getType());

  // 4. Action
  final EdmAction move = edm.getBoundAction(
      new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Move"),
      new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Folder"),
      false);
  assertNotNull(move);
  assertTrue(move.isBound());
  assertEquals(2, move.getParameterNames().size());
  assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String),
      move.getParameter("DestinationId").getType());

  // 5. EntityContainer
  final EdmEntityContainer container = edm.getEntityContainer(
      new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "EntityContainer"));
  assertNotNull(container);
  final EdmEntitySet users = container.getEntitySet("Users");
  assertNotNull(users);
  assertEquals(edm.getEntityType(new FullQualifiedName(container.getNamespace(), "User")),
      users.getEntityType());
  assertEquals(container.getEntitySet("Folders"), users.getRelatedBindingTarget("Folders"));
}