org.apache.olingo.commons.api.edm.EdmType Java Examples

The following examples show how to use org.apache.olingo.commons.api.edm.EdmType. 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: ParserHelper.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private static UriParameter keyValuePair(UriTokenizer tokenizer,
    final String keyPredicateName, final EdmEntityType edmEntityType,
    final Edm edm, final EdmType referringType, final Map<String, AliasQueryOption> aliases)
    throws UriParserException, UriValidationException {
  final EdmKeyPropertyRef keyPropertyRef = edmEntityType.getKeyPropertyRef(keyPredicateName);
  final EdmProperty edmProperty = keyPropertyRef == null ? null : keyPropertyRef.getProperty();
  if (edmProperty == null) {
    throw new UriValidationException(keyPredicateName + " is not a valid key property name.",
        UriValidationException.MessageKeys.INVALID_KEY_PROPERTY, keyPredicateName);
  }
  ParserHelper.requireNext(tokenizer, TokenKind.EQ);
  if (tokenizer.next(TokenKind.COMMA) || tokenizer.next(TokenKind.CLOSE) || tokenizer.next(TokenKind.EOF)) {
    throw new UriParserSyntaxException("Key value expected.", UriParserSyntaxException.MessageKeys.SYNTAX);
  }
  if (nextPrimitiveTypeValue(tokenizer, (EdmPrimitiveType) edmProperty.getType(), edmProperty.isNullable())) {
    return createUriParameter(edmProperty, keyPredicateName, tokenizer.getText(), edm, referringType, aliases);
  } else {
    throw new UriParserSemanticException(keyPredicateName + " has not a valid  key value.",
        UriParserSemanticException.MessageKeys.INVALID_KEY_VALUE, keyPredicateName);
  }
}
 
Example #2
Source File: EdmParameterImplTest.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);
  CsdlParameter parameterProvider = new CsdlParameter();
  parameterProvider.setType(typeName);
  final EdmParameter parameter = new EdmParameterImpl(edm, parameterProvider);
  final EdmType type = parameter.getType();
  assertEquals(EdmTypeKind.DEFINITION, type.getKind());
  assertEquals("ns", type.getNamespace());
  assertEquals("definition", type.getName());
}
 
Example #3
Source File: ODataBinderImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private EdmTypeInfo buildTypeInfo(final ContextURL contextURL, final String metadataETag,
    final String propertyName, final String propertyType) {

  FullQualifiedName typeName = null;
  final EdmType type = findType(null, contextURL, metadataETag);
  if (type instanceof EdmStructuredType) {
    final EdmProperty edmProperty = ((EdmStructuredType) type).getStructuralProperty(propertyName);
    if (edmProperty != null) {
      typeName = edmProperty.getType().getFullQualifiedName();
    }
  }
  if (typeName == null && type != null) {
    typeName = type.getFullQualifiedName();
  }

  return buildTypeInfo(typeName, propertyType);
}
 
Example #4
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 #5
Source File: ExpandSelectMock.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private static UriInfoResource mockResourceMultiLevelOnDerivedComplexTypes(final EdmEntitySet edmEntitySet, 
    final String pathSegmentBeforeCast,
    final String name, final EdmType derivedType, final String pathSegmentAfterCast) {
  EdmStructuredType type = edmEntitySet.getEntityType();
  List<UriResource> elements = new ArrayList<UriResource>();
  final EdmElement edmElement = type.getProperty(name);
  final EdmProperty property = (EdmProperty) edmElement;
  UriResourceComplexProperty element = Mockito.mock(UriResourceComplexProperty.class);
  Mockito.when(element.getProperty()).thenReturn(property);
  elements.add(element);
  
  if (pathSegmentBeforeCast != null) {
    mockComplexPropertyWithTypeFilter(pathSegmentBeforeCast, (EdmComplexType) derivedType, 
        (EdmStructuredType) edmElement.getType(), elements);
  }
  
  mockPropertyOnDerivedType(derivedType, pathSegmentAfterCast, elements);
  
  UriInfoResource resource = Mockito.mock(UriInfoResource.class);
  Mockito.when(resource.getUriResourceParts()).thenReturn(elements);
  return resource;
}
 
Example #6
Source File: Parser.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void parseExpandOption(ExpandOption expandOption, final EdmType contextType, final boolean isAll,
    final List<String> entitySetNames, final Map<String, AliasQueryOption> aliases)
    throws UriParserException, UriValidationException {
  if (expandOption != null) {
    if (!(contextType instanceof EdmStructuredType || isAll
    || (entitySetNames != null && !entitySetNames.isEmpty()))) {
      throw new UriValidationException("Expand is only allowed on structured types!",
          UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED, expandOption.getName());
    }
    final String optionValue = expandOption.getText();
    UriTokenizer expandTokenizer = new UriTokenizer(optionValue);
    final ExpandOption option = new ExpandParser(edm, odata, aliases, entitySetNames).parse(expandTokenizer,
        contextType instanceof EdmStructuredType ? (EdmStructuredType) contextType : null);
    checkOptionEOF(expandTokenizer, expandOption.getName(), optionValue);
    for (final ExpandItem item : option.getExpandItems()) {
      ((ExpandOptionImpl) expandOption).addExpandItem(item);
    }
  }
}
 
Example #7
Source File: ResourcePathParser.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void requireMediaResourceInCaseOfEntity(UriResource resource) throws UriParserSemanticException {
  // If the resource is an entity or navigatio
  if (resource instanceof UriResourceEntitySet && !((UriResourceEntitySet) resource).getEntityType().hasStream()
      || resource instanceof UriResourceNavigation
      && !((EdmEntityType) ((UriResourceNavigation) resource).getType()).hasStream()) {
    throw new UriParserSemanticException("$value on entity is only allowed on media resources.",
        UriParserSemanticException.MessageKeys.NOT_A_MEDIA_RESOURCE, resource.getSegmentValue());
  }

  // Functions can also deliver an entity. In this case we have to check if the returned entity is a media resource
  if (resource instanceof UriResourceFunction) {
    EdmType returnType = ((UriResourceFunction) resource).getFunction().getReturnType().getType();
    //Collection check is above so not needed here
    if (returnType instanceof EdmEntityType && !((EdmEntityType) returnType).hasStream()) {
      throw new UriParserSemanticException("$value on returned entity is only allowed on media resources.",
          UriParserSemanticException.MessageKeys.NOT_A_MEDIA_RESOURCE, resource.getSegmentValue());
    }
  }
}
 
Example #8
Source File: ODataXmlDeserializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void collection(final Valuable valuable, final XMLEventReader reader, final StartElement start,
    final EdmType edmType, final boolean isNullable, final Integer maxLength, final Integer precision,
    final Integer scale, final boolean isUnicode) throws XMLStreamException, EdmPrimitiveTypeException,
    DeserializerException {

  List<Object> values = new ArrayList<Object>();
  boolean foundEndProperty = false;
  while (reader.hasNext() && !foundEndProperty) {
    final XMLEvent event = reader.nextEvent();
    if (event.isStartElement()) {
      if (edmType instanceof EdmPrimitiveType) {
        values.add(primitive(reader, event.asStartElement(), edmType, isNullable,
            maxLength, precision, scale, isUnicode));
      } else if (edmType instanceof EdmComplexType) {
        values.add(complex(reader, event.asStartElement(), (EdmComplexType) edmType));
      }
      // do not add null or empty values
    }

    if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
      foundEndProperty = true;
    }
  }
  valuable.setValue(getValueType(edmType, true), values);
}
 
Example #9
Source File: CoreUtils.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
public static ClientAnnotation getODataAnnotation(
    final EdmEnabledODataClient client, final String term, final EdmType type, final Object obj) {

  ClientAnnotation annotation;

  if (obj == null) {
    annotation = new ClientAnnotationImpl(term, null);
  } else {
    final EdmTypeInfo valueType = type == null
        ? guessTypeFromObject(client, obj)
        : new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()).
            setTypeExpression(type.getFullQualifiedName().toString()).build();

    annotation = new ClientAnnotationImpl(term, getODataValue(client, valueType, obj));
  }

  return annotation;
}
 
Example #10
Source File: MemberImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public EdmType getType() {
  UriInfoImpl uriInfo = (UriInfoImpl) path;
  UriResourceImpl lastResourcePart = (UriResourceImpl) uriInfo.getLastResourcePart();

  if (lastResourcePart instanceof UriResourceWithKeysImpl) {
    UriResourceWithKeysImpl lastKeyPred = (UriResourceWithKeysImpl) lastResourcePart;
    if (lastKeyPred.getTypeFilterOnEntry() != null) {
      return lastKeyPred.getTypeFilterOnEntry();
    } else if (lastKeyPred.getTypeFilterOnCollection() != null) {
      return lastKeyPred.getTypeFilterOnCollection();
    }
    return lastKeyPred.getType();
  } else if (lastResourcePart instanceof UriResourceTypedImpl) {
    UriResourceTypedImpl lastTyped = (UriResourceTypedImpl) lastResourcePart;
    EdmType type = lastTyped.getTypeFilter();
    if (type != null) {
      return type;
    }
    return lastTyped.getType();
  } else if (lastResourcePart instanceof UriResourceActionImpl) {
    return ((UriResourceActionImpl) lastResourcePart).getType();
  } else {
    return null;
  }
}
 
Example #11
Source File: ExpressionParser.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void checkEqualityTypes(final Expression left, final Expression right) throws UriParserException {
  checkNoCollection(left);
  checkNoCollection(right);

  final EdmType leftType = getType(left);
  final EdmType rightType = getType(right);
  if (leftType == null || rightType == null || leftType.equals(rightType)) {
    return;
  }

  // Numeric promotion for Edm.Byte and Edm.SByte
  if (isType(leftType, EdmPrimitiveTypeKind.Byte, EdmPrimitiveTypeKind.SByte)
      && isType(rightType, EdmPrimitiveTypeKind.Byte, EdmPrimitiveTypeKind.SByte)) {
    return;
  }

  if (leftType.getKind() != EdmTypeKind.PRIMITIVE
      || rightType.getKind() != EdmTypeKind.PRIMITIVE
      || !(((EdmPrimitiveType) leftType).isCompatible((EdmPrimitiveType) rightType)
      || ((EdmPrimitiveType) rightType).isCompatible((EdmPrimitiveType) leftType))) {
    throw new UriParserSemanticException("Incompatible types.",
        UriParserSemanticException.MessageKeys.TYPES_NOT_COMPATIBLE,
        leftType.getFullQualifiedName().getFullQualifiedNameAsString(),
        rightType.getFullQualifiedName().getFullQualifiedNameAsString());
  }
}
 
Example #12
Source File: ExpressionParser.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void parseFunction(final FullQualifiedName fullQualifiedName, UriInfoImpl uriInfo,
    final EdmType lastType, final boolean lastIsCollection) throws UriParserException, UriValidationException {

  final List<UriParameter> parameters =
      ParserHelper.parseFunctionParameters(tokenizer, edm, referringType, true, aliases);
  final List<String> parameterNames = ParserHelper.getParameterNames(parameters);
  final EdmFunction boundFunction = edm.getBoundFunction(fullQualifiedName,
      lastType.getFullQualifiedName(), lastIsCollection, parameterNames);

  if (boundFunction != null) {
    ParserHelper.validateFunctionParameters(boundFunction, parameters, edm, referringType, aliases);
    parseFunctionRest(uriInfo, boundFunction, parameters);
    return;
  }

  final EdmFunction unboundFunction = edm.getUnboundFunction(fullQualifiedName, parameterNames);
  if (unboundFunction != null) {
    ParserHelper.validateFunctionParameters(unboundFunction, parameters, edm, referringType, aliases);
    parseFunctionRest(uriInfo, unboundFunction, parameters);
    return;
  }

  throw new UriParserSemanticException("No function '" + fullQualifiedName + "' found.",
      UriParserSemanticException.MessageKeys.FUNCTION_NOT_FOUND, fullQualifiedName.getFullQualifiedNameAsString());
}
 
Example #13
Source File: EdmTypeImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void getterTest() {
  EdmType type = new EdmTypeImplTester(new FullQualifiedName("namespace", "name"), EdmTypeKind.PRIMITIVE);
  assertEquals("name", type.getName());
  assertEquals("namespace", type.getNamespace());
  assertEquals(EdmTypeKind.PRIMITIVE, type.getKind());
  EdmAnnotatable an = (EdmAnnotatable) type;
  assertNotNull(an.getAnnotations().get(0));
}
 
Example #14
Source File: ResourceValidator.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public ResourceValidator isType(final FullQualifiedName type) {
  assertTrue("invalid resource kind: "
      + (uriPathInfo.getKind() == null ? "null" : uriPathInfo.getKind().toString()),
      uriPathInfo instanceof UriResourcePartTyped);
  final EdmType actualType = ((UriResourcePartTyped) uriPathInfo).getType();
  assertNotNull("type information not set", actualType);
  assertEquals(type, actualType.getFullQualifiedName());
  return this;
}
 
Example #15
Source File: ODataXmlDeserializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private ValueType getValueType(final EdmType edmType, final boolean isCollection) {
  if (edmType instanceof EdmPrimitiveType) {
    if (edmType instanceof EdmEnumType) {
      return isCollection ? ValueType.COLLECTION_ENUM : ValueType.ENUM;
    } else {
      return isCollection ? ValueType.COLLECTION_PRIMITIVE : ValueType.PRIMITIVE;
    }
  } else if (edmType instanceof EdmComplexType) {
    return isCollection ? ValueType.COLLECTION_COMPLEX : ValueType.COMPLEX;
  } else {
    return ValueType.PRIMITIVE;
  }
}
 
Example #16
Source File: ExpandSelectMock.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/**
 * @param name
 * @param derivedComplexType
 * @param type
 * @param elements
 */
private static void mockComplexPropertyWithTypeFilter(final String name, final EdmType derivedComplexType,
    EdmStructuredType type, List<UriResource> elements) {
  final EdmElement edmElement = type.getProperty(name);
  final EdmProperty property = (EdmProperty) edmElement;
  UriResourceComplexProperty element = Mockito.mock(UriResourceComplexProperty.class);
  Mockito.when(element.getProperty()).thenReturn(property);
  Mockito.when(element.getComplexTypeFilter()).thenReturn((EdmComplexType) derivedComplexType);
  elements.add(element);
}
 
Example #17
Source File: EdmTypeInfo.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public EdmType getType() {
  return isPrimitiveType() ? EdmPrimitiveTypeFactory.getInstance(getPrimitiveTypeKind()) :
      isTypeDefinition() ? getTypeDefinition() :
      isEnumType() ? getEnumType() :
      isComplexType() ? getComplexType() :
      isEntityType() ? getEntityType() :
      null;
}
 
Example #18
Source File: ExpressionParser.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/**
 * @param expressionList
 * @param leftExprType
 * @throws UriParserException
 * @throws UriParserSemanticException
 */
private void checkInExpressionTypes(List<Expression> expressionList, EdmType leftExprType)
    throws UriParserException, UriParserSemanticException {
  for (Expression expr : expressionList) {
    EdmType inExprType = getType(expr);
    
    if (!(((EdmPrimitiveType) leftExprType).isCompatible((EdmPrimitiveType) inExprType))) {
      throw new UriParserSemanticException("Incompatible types.",
          UriParserSemanticException.MessageKeys.TYPES_NOT_COMPATIBLE,
          inExprType == null ? "" : inExprType.getFullQualifiedName().getFullQualifiedNameAsString(),
          leftExprType.getFullQualifiedName().getFullQualifiedNameAsString());
    }
  }
}
 
Example #19
Source File: ExpressionParserTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/**
 * @param propertyName
 * @return
 */
private EdmProperty mockProperty(final String propertyName, final EdmType type) {
  EdmProperty keyProperty = Mockito.mock(EdmProperty.class);
  Mockito.when(keyProperty.getType()).thenReturn(type);
  Mockito.when(keyProperty.getDefaultValue()).thenReturn("");
  Mockito.when(keyProperty.getName()).thenReturn(propertyName);
  return keyProperty;
}
 
Example #20
Source File: ApplyParser.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private ExpandOption parseExpandTrafo(final EdmStructuredType referencedType)
    throws UriParserException, UriValidationException {
  ExpandItemImpl item = new ExpandItemImpl();
  item.setResourcePath(ExpandParser.parseExpandPath(tokenizer, edm, referencedType, item));
  final EdmType type = ParserHelper.getTypeInformation((UriResourcePartTyped)
      ((UriInfoImpl) item.getResourcePath()).getLastResourcePart());
  if (tokenizer.next(TokenKind.COMMA)) {
    if (tokenizer.next(TokenKind.FilterTrafo)) {
      item.setSystemQueryOption(
          new FilterParser(edm, odata).parse(tokenizer,type, crossjoinEntitySetNames, aliases));
      ParserHelper.requireNext(tokenizer, TokenKind.CLOSE);
    } else {
      ParserHelper.requireNext(tokenizer, TokenKind.ExpandTrafo);
      item.setSystemQueryOption(parseExpandTrafo((EdmStructuredType) type));
    }
  }
  while (tokenizer.next(TokenKind.COMMA)) {
    ParserHelper.requireNext(tokenizer, TokenKind.ExpandTrafo);
    final ExpandOption nestedExpand = parseExpandTrafo((EdmStructuredType) type);
    if (item.getExpandOption() == null) {
      item.setSystemQueryOption(nestedExpand);
    } else {
      // Add to the existing items.
      ((ExpandOptionImpl) item.getExpandOption())
          .addExpandItem(nestedExpand.getExpandItems().get(0));
    }
  }
  ParserHelper.requireNext(tokenizer, TokenKind.CLOSE);
  ExpandOptionImpl expand = new ExpandOptionImpl();
  expand.addExpandItem(item);
  return expand;
}
 
Example #21
Source File: ExpandSelectMock.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public static SelectItem mockSelectItemMultiLevelOnDerivedComplexTypes(
    final EdmEntitySet edmEntitySet, final String name, 
    final String pathSegmentBeforeCast, final EdmType type, final String pathSegmentAfterCast) {
  final UriInfoResource resource = mockResourceMultiLevelOnDerivedComplexTypes(
      edmEntitySet, pathSegmentBeforeCast, name, type, pathSegmentAfterCast);
  SelectItem selectItem = Mockito.mock(SelectItem.class);
  Mockito.when(selectItem.getResourcePath()).thenReturn(resource);
  return selectItem;
}
 
Example #22
Source File: BinaryImpl.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public BinaryImpl(final Expression left, final BinaryOperatorKind operator, final Expression right,
    final EdmType type) {
  this.left = left;
  this.operator = operator;
  this.right = right;
  this.type = type;
  this.expressions = null;
}
 
Example #23
Source File: BinaryImpl.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public BinaryImpl(final Expression left, final BinaryOperatorKind operator, final List<Expression> right,
    final EdmType type) {
  this.left = left;
  this.operator = operator;
  this.right = null;
  this.type = type;
  this.expressions = right;
}
 
Example #24
Source File: PropertyResponse.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public void writeProperty(EdmType edmType, Property property) throws SerializerException {
  assert (!isClosed());

  if (property == null) {
    writeNotFound(true);
    return;
  }

  if (property.getValue() == null) {
    writeNoContent(true);
    return;
  }
  
  if (ContentTypeHelper.isODataMetadataFull(this.responseContentType)) {
    ContextURL contextURL = (this.complexOptions != null)
        ? this.complexOptions.getContextURL()
        : this.primitiveOptions.getContextURL();
    EdmAction action = this.metadata.getEdm().getBoundActionWithBindingType(
        edmType.getFullQualifiedName(), this.collection);
    if (action != null) {
      property.getOperations().add(buildOperation(action, buildOperationTarget(contextURL)));
    }
    
    List<EdmFunction> functions = this.metadata.getEdm()
        .getBoundFunctionsWithBindingType(edmType.getFullQualifiedName(), this.collection);
    
    for (EdmFunction function:functions) {
      property.getOperations().add(buildOperation(function, buildOperationTarget(contextURL)));
    }
  }    

  if (edmType.getKind() == EdmTypeKind.PRIMITIVE) {
    writePrimitiveProperty((EdmPrimitiveType) edmType, property);
  } else {
    writeComplexProperty((EdmComplexType) edmType, property);
  }
}
 
Example #25
Source File: EdmReturnTypeImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void enumType() {
  EdmProviderImpl mock = mock(EdmProviderImpl.class);
  FullQualifiedName baseType = new FullQualifiedName("namespace", "type");
  EdmEnumType edmType = mock(EdmEnumType.class);
  when(mock.getEnumType(baseType)).thenReturn(edmType);
  CsdlReturnType providerType = new CsdlReturnType().setType(baseType);
  EdmReturnType typeImpl = new EdmReturnTypeImpl(mock, providerType);
  EdmType returnedType = typeImpl.getType();
  assertEquals(edmType, returnedType);
}
 
Example #26
Source File: EdmReturnTypeImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void complexType() {
  EdmProviderImpl mock = mock(EdmProviderImpl.class);
  FullQualifiedName baseType = new FullQualifiedName("namespace", "type");
  EdmComplexType edmType = mock(EdmComplexType.class);
  when(mock.getComplexType(baseType)).thenReturn(edmType);
  CsdlReturnType providerType = new CsdlReturnType().setType(baseType);
  EdmReturnType typeImpl = new EdmReturnTypeImpl(mock, providerType);
  EdmType returnedType = typeImpl.getType();
  assertEquals(edmType, returnedType);
}
 
Example #27
Source File: ExpressionParser.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void parseBoundFunction(final FullQualifiedName fullQualifiedName, UriInfoImpl uriInfo,
    final UriResourcePartTyped lastResource) throws UriParserException, UriValidationException {
  final EdmType type = lastResource.getType();
  final List<UriParameter> parameters =
      ParserHelper.parseFunctionParameters(tokenizer, edm, referringType, true, aliases);
  final List<String> parameterNames = ParserHelper.getParameterNames(parameters);
  final EdmFunction boundFunction = edm.getBoundFunction(fullQualifiedName,
      type.getFullQualifiedName(), lastResource.isCollection(), parameterNames);
  if (boundFunction == null) {
    throw new UriParserSemanticException("Bound function '" + fullQualifiedName + "' not found.",
        UriParserSemanticException.MessageKeys.FUNCTION_NOT_FOUND, fullQualifiedName.getFullQualifiedNameAsString());
  }
  ParserHelper.validateFunctionParameters(boundFunction, parameters, edm, referringType, aliases);
  parseFunctionRest(uriInfo, boundFunction, parameters);
}
 
Example #28
Source File: ParserHelper.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected static AliasQueryOption parseAliasValue(final String name, final EdmType type, final boolean isNullable,
    final boolean isCollection, final Edm edm, final EdmType referringType,
    final Map<String, AliasQueryOption> aliases) throws UriParserException, UriValidationException {
  final EdmTypeKind kind = type == null ? null : type.getKind();
  final AliasQueryOption alias = aliases.get(name);
  if (alias != null && alias.getText() != null) {
    UriTokenizer aliasTokenizer = new UriTokenizer(alias.getText());
    if (kind == null
        || !((isCollection || kind == EdmTypeKind.COMPLEX || kind == EdmTypeKind.ENTITY ?
        aliasTokenizer.next(TokenKind.jsonArrayOrObject) :
        nextPrimitiveTypeValue(aliasTokenizer, (EdmPrimitiveType) type, isNullable))
        && aliasTokenizer.next(TokenKind.EOF))) {
      // The alias value is not an allowed literal value, so parse it again as expression.
      aliasTokenizer = new UriTokenizer(alias.getText());
      // Don't pass on the current alias to avoid circular references.
      Map<String, AliasQueryOption> aliasesInner = new HashMap<>(aliases);
      aliasesInner.remove(name);
      final Expression expression = new ExpressionParser(edm, odata)
          .parse(aliasTokenizer, referringType, null, aliasesInner);
      final EdmType expressionType = ExpressionParser.getType(expression);
      if (aliasTokenizer.next(TokenKind.EOF)
          && (expressionType == null || type == null || expressionType.equals(type))) {
        ((AliasQueryOptionImpl) alias).setAliasValue(expression);
      } else {
        throw new UriParserSemanticException("Illegal value for alias '" + alias.getName() + "'.",
            UriParserSemanticException.MessageKeys.UNKNOWN_PART, alias.getText());
      }
    }
  }
  return alias;
}
 
Example #29
Source File: EdmPropertyImpl.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public EdmType getType() {
  if (propertyType == null) {
    if (typeInfo == null) {
      buildTypeInfo();
    }
    propertyType = typeInfo.getType();
    if (propertyType == null) {
      throw new EdmException("Cannot find type with name: " + typeInfo.getFullQualifiedName());
    }
  }

  return propertyType;
}
 
Example #30
Source File: ResourcePathParser.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private UriResource boundOperationOrTypeCast(UriResource previous)
    throws UriParserException, UriValidationException {
  final FullQualifiedName name = new FullQualifiedName(tokenizer.getText());
  requireTyped(previous, name.getFullQualifiedNameAsString());
  final UriResourcePartTyped previousTyped = (UriResourcePartTyped) previous;
  final EdmType previousTypeFilter = getPreviousTypeFilter(previousTyped);
  final EdmType previousType = previousTypeFilter == null ? previousTyped.getType() : previousTypeFilter;

  // We check for bound actions first because they cannot be followed by anything.
  final EdmAction boundAction =
      edm.getBoundAction(name, previousType.getFullQualifiedName(), previousTyped.isCollection());
  if (boundAction != null) {
    ParserHelper.requireTokenEnd(tokenizer);
    return new UriResourceActionImpl(boundAction);
  }

  // Type casts can be syntactically indistinguishable from bound function calls in the case of additional keys.
  // But normally they are shorter, so they come next.
  final EdmStructuredType type = previousTyped.getType() instanceof EdmEntityType ?
      edm.getEntityType(name) :
      edm.getComplexType(name);
  if (type != null) {
    return typeCast(name, type, previousTyped);
  }
  if (tokenizer.next(TokenKind.EOF)) {
    throw new UriParserSemanticException("Type '" + name.getFullQualifiedNameAsString() + "' not found.",
        UriParserSemanticException.MessageKeys.UNKNOWN_TYPE, name.getFullQualifiedNameAsString());
  }

  // Now a bound function call is the only remaining option.
  return functionCall(null, name, previousType.getFullQualifiedName(), previousTyped.isCollection());
}