/// <summary> /// Build a wildcard selection item /// </summary> /// <param name="tokenIn">the token to bind to a wildcard</param> /// <param name="model">the model to search for this wildcard</param> /// <param name="item">the new wildcard selection item, if we found one</param> /// <returns>true if we successfully bound to a wildcard, false otherwise</returns> public static bool TryBindAsWildcard(PathSegmentToken tokenIn, IEdmModel model, out SelectItem item) { bool isTypeToken = tokenIn.IsNamespaceOrContainerQualified(); bool wildcard = tokenIn.Identifier.EndsWith("*", StringComparison.Ordinal); if (isTypeToken && wildcard) { string namespaceName = tokenIn.Identifier.Substring(0, tokenIn.Identifier.Length - 2); if (model.DeclaredNamespaces.Any(declaredNamespace => declaredNamespace.Equals(namespaceName, StringComparison.Ordinal))) { item = new NamespaceQualifiedWildcardSelectItem(namespaceName); return(true); } } if (tokenIn.Identifier == "*") { item = new WildcardSelectItem(); return(true); } item = null; return(false); }
public void NamespaceQualifiedWithWildcardResultsNamespaceQualifiedWildcardSelectItem() { // Arrange SelectItem selectItem; PathSegmentToken pathSegment = new NonSystemToken("Fully.Qualified.Namespace.*", null, null); // Act var result = SelectPathSegmentTokenBinder.TryBindAsWildcard(pathSegment, HardCodedTestModel.TestModel, out selectItem); // Assert Assert.True(result); Assert.NotNull(selectItem); NamespaceQualifiedWildcardSelectItem namesapceQualifiedSelectItem = Assert.IsType <NamespaceQualifiedWildcardSelectItem>(selectItem); Assert.NotNull(namesapceQualifiedSelectItem); Assert.Equal("Fully.Qualified.Namespace", namesapceQualifiedSelectItem.Namespace); }
public void NamespaceWildcardSelectionItemPreemptsStructuralProperties() { // Arrange : $select=* SelectToken selectToken = new SelectToken(new SelectTermToken[] { new SelectTermToken(new NonSystemToken("Fully.Qualified.Namespace.*", null, null)) }); // Act SelectExpandClause clause = BinderForPerson.Bind(null, selectToken); // Assert Assert.NotNull(clause); Assert.False(clause.AllSelected); SelectItem selectItem = Assert.Single(clause.SelectedItems); NamespaceQualifiedWildcardSelectItem namespaceSelectItem = Assert.IsType <NamespaceQualifiedWildcardSelectItem>(selectItem); Assert.Equal("Fully.Qualified.Namespace", namespaceSelectItem.Namespace); }
private void AddNamespaceWildcardOperation(NamespaceQualifiedWildcardSelectItem namespaceSelectItem, ISet <IEdmAction> allActions, ISet <IEdmFunction> allFunctions) { if (allActions == null) { SelectedActions = null; } else { SelectedActions = new HashSet <IEdmAction>(allActions.Where(a => a.Namespace == namespaceSelectItem.Namespace)); } if (allFunctions == null) { SelectedFunctions = null; } else { SelectedFunctions = new HashSet <IEdmFunction>(allFunctions.Where(a => a.Namespace == namespaceSelectItem.Namespace)); } }
/// <summary> /// Handle a ContainerQualifiedWildcardSelectItem /// </summary> /// <param name="item">the item to Handle</param> public override void Handle(NamespaceQualifiedWildcardSelectItem item) { throw new NotImplementedException(); }
/// <summary> /// Handle a ContainerQualifiedWildcardSelectItem /// </summary> /// <param name="item">the item to Handle</param> public virtual void Handle(NamespaceQualifiedWildcardSelectItem item) { throw new NotImplementedException(); }
private void BuildSelections( SelectExpandClause selectExpandClause, HashSet<IEdmStructuralProperty> allStructuralProperties, HashSet<IEdmStructuralProperty> allNestedProperties, HashSet<IEdmNavigationProperty> allNavigationProperties, HashSet<IEdmAction> allActions, HashSet<IEdmFunction> allFunctions) { foreach (SelectItem selectItem in selectExpandClause.SelectedItems) { if (selectItem is ExpandedNavigationSelectItem) { continue; } PathSelectItem pathSelectItem = selectItem as PathSelectItem; if (pathSelectItem != null) { ValidatePathIsSupported(pathSelectItem.SelectedPath); ODataPathSegment segment = pathSelectItem.SelectedPath.LastSegment; NavigationPropertySegment navigationPropertySegment = segment as NavigationPropertySegment; if (navigationPropertySegment != null) { IEdmNavigationProperty navigationProperty = navigationPropertySegment.NavigationProperty; if (allNavigationProperties.Contains(navigationProperty)) { SelectedNavigationProperties.Add(navigationProperty); } continue; } PropertySegment structuralPropertySegment = segment as PropertySegment; if (structuralPropertySegment != null) { IEdmStructuralProperty structuralProperty = structuralPropertySegment.Property; if (allStructuralProperties.Contains(structuralProperty)) { SelectedStructuralProperties.Add(structuralProperty); } else if (allNestedProperties.Contains(structuralProperty)) { SelectedComplexProperties.Add(structuralProperty); } continue; } OperationSegment operationSegment = segment as OperationSegment; if (operationSegment != null) { AddOperations(allActions, allFunctions, operationSegment); continue; } DynamicPathSegment dynamicPathSegment = segment as DynamicPathSegment; if (dynamicPathSegment != null) { SelectedDynamicProperties.Add(dynamicPathSegment.Identifier); continue; } throw new ODataException(Error.Format(SRResources.SelectionTypeNotSupported, segment.GetType().Name)); } WildcardSelectItem wildCardSelectItem = selectItem as WildcardSelectItem; if (wildCardSelectItem != null) { SelectedStructuralProperties = allStructuralProperties; SelectedComplexProperties = allNestedProperties; SelectedNavigationProperties = allNavigationProperties; SelectAllDynamicProperties = true; continue; } NamespaceQualifiedWildcardSelectItem wildCardActionSelection = selectItem as NamespaceQualifiedWildcardSelectItem; if (wildCardActionSelection != null) { SelectedActions = allActions; SelectedFunctions = allFunctions; continue; } throw new ODataException(Error.Format(SRResources.SelectionTypeNotSupported, selectItem.GetType().Name)); } }
/// <summary> /// Translate a ContainerQualifiedWildcardSelectItem /// </summary> /// <param name="item">the item to Translate</param> /// <returns>Defined by the implementer</returns> public override string Translate(NamespaceQualifiedWildcardSelectItem item) { return(item.Namespace); }
/// <summary> /// Build a wildcard selection item /// </summary> /// <param name="tokenIn">the token to bind to a wildcard</param> /// <param name="model">the model to search for this wildcard</param> /// <param name="item">the new wildcard selection item, if we found one</param> /// <returns>true if we successfully bound to a wildcard, false otherwise</returns> public static bool TryBindAsWildcard(PathSegmentToken tokenIn, IEdmModel model, out SelectItem item) { bool isTypeToken = tokenIn.IsNamespaceOrContainerQualified(); bool wildcard = tokenIn.Identifier.EndsWith("*", StringComparison.Ordinal); if (isTypeToken && wildcard) { string namespaceName = tokenIn.Identifier.Substring(0, tokenIn.Identifier.Length - 2); if (model.DeclaredNamespaces.Any(declaredNamespace => declaredNamespace.Equals(namespaceName, StringComparison.Ordinal))) { item = new NamespaceQualifiedWildcardSelectItem(namespaceName); return true; } } if (tokenIn.Identifier == "*") { item = new WildcardSelectItem(); return true; } item = null; return false; }
/// <summary> /// Build $select and $expand clause /// </summary> /// <param name="selectExpandClause">The select expand clause</param> /// <param name="structuralTypeInfo">The structural type properties.</param> private void BuildSelectExpand(SelectExpandClause selectExpandClause, EdmStructuralTypeInfo structuralTypeInfo) { Contract.Assert(selectExpandClause != null); Contract.Assert(structuralTypeInfo != null); var currentLevelPropertiesInclude = new Dictionary <IEdmStructuralProperty, SelectExpandIncludedProperty>(); // Explicitly set SelectAllDynamicProperties as false, // Below will re-set it as true if it meets the select all condition. SelectAllDynamicProperties = false; foreach (SelectItem selectItem in selectExpandClause.SelectedItems) { // $expand=... ExpandedReferenceSelectItem expandReferenceItem = selectItem as ExpandedReferenceSelectItem; if (expandReferenceItem != null) { BuildExpandItem(expandReferenceItem, currentLevelPropertiesInclude, structuralTypeInfo); continue; } PathSelectItem pathSelectItem = selectItem as PathSelectItem; if (pathSelectItem != null) { // $select=abc/.../xyz BuildSelectItem(pathSelectItem, currentLevelPropertiesInclude, structuralTypeInfo); continue; } WildcardSelectItem wildCardSelectItem = selectItem as WildcardSelectItem; if (wildCardSelectItem != null) { // $select=* MergeAllStructuralProperties(structuralTypeInfo.AllStructuralProperties, currentLevelPropertiesInclude); MergeSelectedNavigationProperties(structuralTypeInfo.AllNavigationProperties); SelectAllDynamicProperties = true; continue; } NamespaceQualifiedWildcardSelectItem wildCardActionSelection = selectItem as NamespaceQualifiedWildcardSelectItem; if (wildCardActionSelection != null) { // $select=NS.* AddNamespaceWildcardOperation(wildCardActionSelection, structuralTypeInfo.AllActions, structuralTypeInfo.AllFunctions); continue; } throw new ODataException(Error.Format(SRResources.SelectionTypeNotSupported, selectItem.GetType().Name)); } if (selectExpandClause.AllSelected) { MergeAllStructuralProperties(structuralTypeInfo.AllStructuralProperties, currentLevelPropertiesInclude); MergeSelectedNavigationProperties(structuralTypeInfo.AllNavigationProperties); MergeSelectedAction(structuralTypeInfo.AllActions); MergeSelectedFunction(structuralTypeInfo.AllFunctions); SelectAllDynamicProperties = true; } // to make sure the structural properties are in the same order defined in the type. if (structuralTypeInfo.AllStructuralProperties != null) { foreach (var structuralProperty in structuralTypeInfo.AllStructuralProperties) { SelectExpandIncludedProperty includeProperty; if (!currentLevelPropertiesInclude.TryGetValue(structuralProperty, out includeProperty)) { continue; } PathSelectItem pathSelectItem = includeProperty == null ? null : includeProperty.ToPathSelectItem(); AddStructuralProperty(structuralProperty, pathSelectItem); } } }
public void ContainerIsSetFromConstructor() { var item = new NamespaceQualifiedWildcardSelectItem("name.space"); item.Namespace.Should().Be("name.space"); }
public void ContainerIsSetFromConstructor() { var item = new NamespaceQualifiedWildcardSelectItem("name.space"); Assert.Equal("name.space", item.Namespace); }
/// <summary> /// Translate a ContainerQualifiedWildcardSelectItem /// </summary> /// <param name="item">the item to Translate</param> /// <returns>Defined by the implementer</returns> public virtual T Translate(NamespaceQualifiedWildcardSelectItem item) { throw new NotImplementedException(); }
/// <summary> /// Writes Selection Item of type ContainerQualifiedWildcardSelectItem node to string /// </summary> /// <param name="node">Node to write to string</param> /// <returns>String representation of node.</returns> private static string ToString(NamespaceQualifiedWildcardSelectItem node) { return(String.Format("(ContainerQualifiedWildcard)")); }
/// <summary> /// Writes Selection Item of type ContainerQualifiedWildcardSelectItem node to string /// </summary> /// <param name="node">Node to write to string</param> /// <returns>String representation of node.</returns> private static string ToString(NamespaceQualifiedWildcardSelectItem node) { return String.Format("(ContainerQualifiedWildcard)"); }