org.apache.olingo.commons.api.edm.EdmElement Java Examples
The following examples show how to use
org.apache.olingo.commons.api.edm.EdmElement.
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: ExpandSelectMock.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private static UriInfoResource mockResourceOnDerivedEntityAndComplexTypes( final String name, final EdmType derivedEntityType, final EdmType derivedComplexType, final String pathSegment) { EdmStructuredType type = (EdmStructuredType) derivedEntityType; List<UriResource> elements = new ArrayList<UriResource>(); mockComplexPropertyWithTypeFilter(name, derivedComplexType, type, elements); final EdmElement edmElement1 = ((EdmStructuredType) derivedComplexType).getProperty(pathSegment); UriResourceNavigation element1 = Mockito.mock(UriResourceNavigation.class); Mockito.when(element1.getProperty()).thenReturn((EdmNavigationProperty) edmElement1); elements.add(element1); UriInfoResource resource = Mockito.mock(UriInfoResource.class); Mockito.when(resource.getUriResourceParts()).thenReturn(elements); return resource; }
Example #2
Source File: CoreUtils.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private static ClientProperty getODataProperty( final EdmEnabledODataClient client, final EdmElement edmProperty, final String property, final Object obj) { final EdmTypeInfo type; if (edmProperty == null) { // maybe opentype ... type = null; } else { final EdmType edmType = edmProperty.getType(); type = new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()).setTypeExpression( edmProperty.isCollection() ? "Collection(" + edmType.getFullQualifiedName().toString() + ")" : edmType.getFullQualifiedName().toString()).build(); } return getODataProperty(client, property, type, obj); }
Example #3
Source File: ApplyParser.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private UriResource parsePathSegment(final EdmElement property) throws UriParserException { if (property == null || !(property.getType().getKind() == EdmTypeKind.COMPLEX || property instanceof EdmNavigationProperty)) { // Could be a customAggregate or $count. return null; } if (tokenizer.next(TokenKind.SLASH)) { final EdmStructuredType typeCast = ParserHelper.parseTypeCast(tokenizer, edm, (EdmStructuredType) property.getType()); if (typeCast != null) { ParserHelper.requireNext(tokenizer, TokenKind.SLASH); } return property.getType().getKind() == EdmTypeKind.COMPLEX ? new UriResourceComplexPropertyImpl((EdmProperty) property).setTypeFilter(typeCast) : new UriResourceNavigationPropertyImpl((EdmNavigationProperty) property).setCollectionTypeFilter(typeCast); } else { return null; } }
Example #4
Source File: ExpandSelectMock.java From olingo-odata4 with Apache License 2.0 | 6 votes |
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 #5
Source File: ExpandSelectMock.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private static UriInfoResource mockResourceOnComplexTypesWithNav(final EdmEntitySet edmEntitySet, final String name, final String navProperty) { 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); mockNavPropertyOnEdmType(navProperty, elements, property); UriInfoResource resource = Mockito.mock(UriInfoResource.class); Mockito.when(resource.getUriResourceParts()).thenReturn(elements); return resource; }
Example #6
Source File: EdmKeyPropertyRefImplTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test(expected = EdmException.class) public void aliasForPropertyInComplexPropertyButWrongPath2() { CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("wrong/Id").setAlias("alias"); EdmEntityType etMock = mock(EdmEntityType.class); EdmProperty keyPropertyMock = mock(EdmProperty.class); EdmElement compMock = mock(EdmProperty.class); EdmComplexType compTypeMock = mock(EdmComplexType.class); when(compTypeMock.getProperty("Id")).thenReturn(keyPropertyMock); when(compMock.getType()).thenReturn(compTypeMock); when(etMock.getProperty("comp")).thenReturn(compMock); new EdmKeyPropertyRefImpl(etMock, providerRef).getProperty(); }
Example #7
Source File: CoreUtils.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private static ClientProperty getODataComplexProperty( final EdmEnabledODataClient client, final FullQualifiedName complex, final String property, final Object obj) { final EdmElement edmProperty = client.getCachedEdm().getComplexType(complex).getProperty(property); return getODataProperty(client, edmProperty, property, obj); }
Example #8
Source File: CoreUtils.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private static ClientProperty getODataEntityProperty( final EdmEnabledODataClient client, final FullQualifiedName entity, final String property, final Object obj) { final EdmElement edmProperty = client.getCachedEdm().getEntityType(entity).getProperty(property); return getODataProperty(client, edmProperty, property, obj); }
Example #9
Source File: DynamicStructuredType.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public EdmElement getProperty(final String name) { final EdmElement property = startType.getProperty(name); return property == null ? properties == null ? null : properties.get(name) : property; }
Example #10
Source File: AbstractEdmStructuredType.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public EdmElement getProperty(final String name) { EdmElement property = getStructuralProperty(name); if (property == null) { property = getNavigationProperty(name); } return property; }
Example #11
Source File: ApplyParser.java From olingo-odata4 with Apache License 2.0 | 5 votes |
/** * Parses the path prefix and a following OData identifier as one path, deviating from the ABNF. * @param uriInfo object to be filled with path segments * @return a parsed but not used OData identifier */ private String parsePathPrefix(UriInfoImpl uriInfo, final EdmStructuredType referencedType) throws UriParserException { final EdmStructuredType typeCast = ParserHelper.parseTypeCast(tokenizer, edm, referencedType); if (typeCast != null) { uriInfo.addResourcePart(new UriResourceStartingTypeFilterImpl(typeCast, true)); ParserHelper.requireNext(tokenizer, TokenKind.SLASH); } EdmStructuredType type = typeCast == null ? referencedType : typeCast; while (tokenizer.next(TokenKind.ODataIdentifier)) { final String name = tokenizer.getText(); final EdmElement property = type.getProperty(name); final UriResource segment = parsePathSegment(property); if (segment == null) { if (property == null) { return name; } else { uriInfo.addResourcePart( property instanceof EdmNavigationProperty ? new UriResourceNavigationPropertyImpl((EdmNavigationProperty) property) : property.getType().getKind() == EdmTypeKind.COMPLEX ? new UriResourceComplexPropertyImpl((EdmProperty) property) : new UriResourcePrimitivePropertyImpl((EdmProperty) property)); return null; } } else { uriInfo.addResourcePart(segment); } type = (EdmStructuredType) ParserHelper.getTypeInformation((UriResourcePartTyped) segment); } return null; }
Example #12
Source File: ExpandSelectMock.java From olingo-odata4 with Apache License 2.0 | 5 votes |
/** * @param derivedType * @param pathSegment * @param elements */ private static void mockPropertyOnDerivedType(final EdmType derivedType, final String pathSegment, List<UriResource> elements) { if (pathSegment != null) { final EdmElement edmElement1 = ((EdmStructuredType) derivedType).getProperty(pathSegment); final EdmProperty property1 = (EdmProperty) edmElement1; UriResourceProperty element1 = Mockito.mock(UriResourceProperty.class); Mockito.when(element1.getProperty()).thenReturn(property1); elements.add(element1); } }
Example #13
Source File: EdmEntityTypeImplTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void complexKeyWithAlias() { List<String> keyPredicateNames = typeWithComplexKey.getKeyPredicateNames(); assertEquals(2, keyPredicateNames.size()); assertEquals("Id", keyPredicateNames.get(0)); assertEquals("alias", keyPredicateNames.get(1)); EdmKeyPropertyRef keyPropertyRef = typeWithComplexKey.getKeyPropertyRef("Id"); assertNotNull(keyPropertyRef); assertEquals("Id", keyPropertyRef.getName()); assertNull(keyPropertyRef.getAlias()); EdmProperty keyProperty = keyPropertyRef.getProperty(); assertNotNull(keyProperty); assertEquals(typeWithComplexKey.getProperty("Id"), keyProperty); keyPropertyRef = typeWithComplexKey.getKeyPropertyRef("alias"); assertNotNull(keyPropertyRef); assertEquals("Comp/ComplexPropName", keyPropertyRef.getName()); assertEquals("alias", keyPropertyRef.getAlias()); keyProperty = keyPropertyRef.getProperty(); assertNotNull(keyProperty); EdmElement complexProperty = typeWithComplexKey.getProperty("Comp"); EdmComplexType complexType = (EdmComplexType) complexProperty.getType(); assertNotNull(complexType); assertEquals(complexType.getProperty("ComplexPropName"), keyProperty); }
Example #14
Source File: ExpandSelectMock.java From olingo-odata4 with Apache License 2.0 | 5 votes |
/** * @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 #15
Source File: EdmTypeConvertor.java From syndesis with Apache License 2.0 | 5 votes |
public PropertyMetadata visit(EdmElement property) { this.name = property.getName(); if (property instanceof EdmNavigationProperty) { return visit((EdmNavigationProperty) property); } else if (property instanceof EdmParameter) { return visit((EdmParameter) property); } else if (property instanceof EdmProperty) { return visit((EdmProperty) property); } throw new UnsupportedOperationException(); }
Example #16
Source File: ExpandSelectMock.java From olingo-odata4 with Apache License 2.0 | 5 votes |
/** * @param navProperty * @param elements * @param property */ private static void mockNavPropertyOnEdmType(final String navProperty, List<UriResource> elements, final EdmProperty property) { final EdmElement edmElement1 = ((EdmStructuredType) property.getType()).getProperty(navProperty); UriResourceNavigation element1 = Mockito.mock(UriResourceNavigation.class); Mockito.when(element1.getProperty()).thenReturn((EdmNavigationProperty) edmElement1); elements.add(element1); }
Example #17
Source File: EdmEntityTypeImplTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void propertyCaching() { EdmElement property = typeWithBaseType.getProperty("Id"); assertTrue(property == typeWithBaseType.getProperty("Id")); property = typeWithBaseType.getProperty("address"); assertTrue(property == typeWithBaseType.getProperty("address")); property = typeWithBaseType.getProperty("nav1"); assertTrue(property == typeWithBaseType.getProperty("nav1")); property = typeWithBaseType.getProperty("nav2"); assertTrue(property == typeWithBaseType.getProperty("nav2")); }
Example #18
Source File: ResourceValidator.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private ResourceValidator isProperty(final UriResourceKind kind, final String name, final FullQualifiedName type, final boolean isCollection) { isUriPathInfoKind(kind); final EdmElement property = kind == UriResourceKind.navigationProperty ? ((UriResourceNavigation) uriPathInfo).getProperty() : ((UriResourceProperty) uriPathInfo).getProperty(); assertEquals(name, property.getName()); isType(type, isCollection); return this; }
Example #19
Source File: EdmComplexTypeImplTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void propertyCaching() { EdmElement property = type.getProperty("prop1"); assertTrue(property == type.getProperty("prop1")); property = type.getProperty("prop2"); assertTrue(property == type.getProperty("prop2")); property = type.getProperty("nav1"); assertTrue(property == type.getProperty("nav1")); property = type.getProperty("nav2"); assertTrue(property == type.getProperty("nav2")); }
Example #20
Source File: EdmKeyPropertyRefImplTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test(expected = EdmException.class) public void aliasForPropertyInComplexPropertyButWrongPath() { CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("comp/wrong").setAlias("alias"); EdmEntityType etMock = mock(EdmEntityType.class); EdmProperty keyPropertyMock = mock(EdmProperty.class); EdmElement compMock = mock(EdmProperty.class); EdmComplexType compTypeMock = mock(EdmComplexType.class); when(compTypeMock.getProperty("Id")).thenReturn(keyPropertyMock); when(compMock.getType()).thenReturn(compTypeMock); when(etMock.getProperty("comp")).thenReturn(compMock); new EdmKeyPropertyRefImpl(etMock, providerRef).getProperty(); }
Example #21
Source File: ExpressionParser.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private void parsePropertyPathExpr(UriInfoImpl uriInfo, final UriResourcePartTyped lastResource) throws UriParserException, UriValidationException { final String oDataIdentifier = tokenizer.getText(); final EdmType lastType = lastResource == null ? referringType : ParserHelper.getTypeInformation(lastResource); if (!(lastType instanceof EdmStructuredType)) { throw new UriParserSemanticException("Property paths must follow a structured type.", UriParserSemanticException.MessageKeys.ONLY_FOR_STRUCTURAL_TYPES, oDataIdentifier); } final EdmStructuredType structuredType = (EdmStructuredType) lastType; final EdmElement property = structuredType.getProperty(oDataIdentifier); if (property == null) { throw new UriParserSemanticException("Unknown property.", UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE, lastType.getFullQualifiedName().getFullQualifiedNameAsString(), oDataIdentifier); } if (property.getType() instanceof EdmComplexType) { final UriResourceComplexPropertyImpl complexResource = new UriResourceComplexPropertyImpl((EdmProperty) property); uriInfo.addResourcePart(complexResource); if (property.isCollection()) { if (tokenizer.next(TokenKind.SLASH)) { parseCollectionPathExpr(uriInfo, complexResource); } } else { parseComplexPathExpr(uriInfo, complexResource); } } else if (property instanceof EdmNavigationProperty) { // Nav. property; maybe a collection final UriResourceNavigationPropertyImpl navigationResource = new UriResourceNavigationPropertyImpl((EdmNavigationProperty) property); navigationResource.setKeyPredicates( ParserHelper.parseNavigationKeyPredicate(tokenizer, (EdmNavigationProperty) property, edm, referringType, aliases)); uriInfo.addResourcePart(navigationResource); if (navigationResource.isCollection()) { parseCollectionNavigationExpr(uriInfo, navigationResource); } else { parseSingleNavigationExpr(uriInfo, navigationResource); } } else { // Primitive type or Enum type final UriResourcePrimitivePropertyImpl primitiveResource = new UriResourcePrimitivePropertyImpl((EdmProperty) property); uriInfo.addResourcePart(primitiveResource); if (property.isCollection()) { if (tokenizer.next(TokenKind.SLASH)) { parseCollectionPathExpr(uriInfo, primitiveResource); } } else { parseSinglePathExpr(uriInfo, primitiveResource); } } }
Example #22
Source File: ExpandSystemQueryOptionHandler.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private void applyExpandOptionToEntity(final Entity entity, final EdmBindingTarget edmBindingTarget, final ExpandOption expandOption, final UriInfoResource uriInfo, final Edm edm) throws ODataApplicationException { final EdmEntityType entityType = edmBindingTarget.getEntityType(); for (ExpandItem item : expandOption.getExpandItems()) { if(item.getLevelsOption() != null) { throw new ODataApplicationException("$levels is not implemented", HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT); } List<EdmNavigationProperty> navigationProperties = new ArrayList<EdmNavigationProperty>(); if(item.isStar()) { List<EdmNavigationPropertyBinding> bindings = edmBindingTarget.getNavigationPropertyBindings(); for (EdmNavigationPropertyBinding binding : bindings) { EdmElement property = entityType.getProperty(binding.getPath()); if(property instanceof EdmNavigationProperty) { navigationProperties.add((EdmNavigationProperty) property); } } } else { final List<UriResource> uriResourceParts = item.getResourcePath().getUriResourceParts(); if (uriResourceParts.get(0) instanceof UriResourceNavigation) { navigationProperties.add(((UriResourceNavigation) uriResourceParts.get(0)).getProperty()); } } for (EdmNavigationProperty navigationProperty: navigationProperties) { final String navPropertyName = navigationProperty.getName(); final EdmBindingTarget targetEdmEntitySet = edmBindingTarget.getRelatedBindingTarget(navPropertyName); final Link link = entity.getNavigationLink(navPropertyName); if (link != null && entityType.getNavigationProperty(navPropertyName).isCollection()) { applyOptionsToEntityCollection(link.getInlineEntitySet(), targetEdmEntitySet, item.getFilterOption(), item.getOrderByOption(), item.getCountOption(), item.getSkipOption(), item.getTopOption(), item.getExpandOption(), uriInfo, edm); } } } }