Skip to content

Commit

Permalink
Squashing Commits
Browse files Browse the repository at this point in the history
Squashing Commits
Update DeltaOfTStructuralType.cs

test change

Update Microsoft.AspNetCore.OData.Test.csproj

Update Microsoft.Test.E2E.AspNetCore3x.OData.csproj

updates

Update WebStack.versions.settings.targets

Update WebStack.versions.settings.targets

Update GetNugetPackageMetadata.proj

Update WebStack.versions.settings.targets

For testing

update

Update BulkInsertController.cs

Updates

updates

updates

Update NuGet.Config

Update BulkOperationPatchHandlersEF.cs

updates
  • Loading branch information
Sreejithpin committed Oct 28, 2021
1 parent 5d20b2d commit c42f50f
Show file tree
Hide file tree
Showing 21 changed files with 552 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public DataModificationExceptionType(DataModificationOperationKind failedOperati
}

/// <summary>
/// Represents king of <see cref="DataModificationOperationKind"/> type of operation
/// Represents kind of <see cref="DataModificationOperationKind"/> type of operation
/// </summary>
public DataModificationOperationKind FailedOperation { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private void PatchItem(EdmStructuredObject changedObj, EdmStructuredObject origi
/// <summary>
/// This applies ODataId parsed Navigation paths, get the value identified by that and copy it on original object, for typeless entities
/// </summary>
private void ApplyODataId(ODataIdContainer container, EdmStructuredObject original, ODataEdmAPIHandlerFactory apiHandlerFactory)
private void ApplyODataId(IODataIdContainer container, EdmStructuredObject original, ODataEdmAPIHandlerFactory apiHandlerFactory)
{
EdmODataAPIHandler edmApiHandler = apiHandlerFactory.GetHandler(container.ODataIdNavigationPath);

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.AspNet.OData.Shared/EdmEntityObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public EdmEntityObject(IEdmEntityType edmType, bool isNullable)
/// <summary>
/// Container to hold ODataId
/// </summary>
public ODataIdContainer ODataIdContainer { get; set; }
public IODataIdContainer ODataIdContainer { get; set; }

/// <summary>
/// DeltaKind as Entry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ private static ODataPath GetODataPath(string id, ODataDeserializerContext readCo
private static void ApplyODataIDContainer(object resource, ODataResourceWrapper resourceWrapper,
ODataDeserializerContext readContext)
{
//if id null check, add delta case as well c
//Setting Odataid , for POCO classes, as a property in the POCO object itself(if user has OdataIDContainer property),
//for Delta and EdmEntity object setting as an added property ODataIdcontianer in those classes
if (resourceWrapper.ResourceBase?.Id != null)
{
string odataId = resourceWrapper.ResourceBase.Id.OriginalString;
Expand All @@ -578,7 +579,7 @@ private static void ApplyODataIDContainer(object resource, ODataResourceWrapper

if (odataPath != null)
{
ODataIdContainer container = new ODataIdContainer();
IODataIdContainer container = new ODataIdContainer();

NavigationPath navigationPath = new NavigationPath(odataId, odataPath.Segments);
container.ODataIdNavigationPath = navigationPath;
Expand All @@ -593,10 +594,19 @@ private static void ApplyODataIDContainer(object resource, ODataResourceWrapper
}
else
{
PropertyInfo containerPropertyInfo = EdmLibHelpers.GetClrType(odataPath.EdmType, readContext.Model).GetProperties().Where(x => x.PropertyType == typeof(ODataIdContainer)).FirstOrDefault();
PropertyInfo containerPropertyInfo = EdmLibHelpers.GetClrType(odataPath.EdmType, readContext.Model).GetProperties().Where(x => x.PropertyType == typeof(IODataIdContainer)).FirstOrDefault();
if (containerPropertyInfo != null)
{
containerPropertyInfo.SetValue(resource, container);
IODataIdContainer resourceContainer = containerPropertyInfo.GetValue(resource) as IODataIdContainer;
if (resourceContainer != null)
{
resourceContainer.ODataIdNavigationPath = navigationPath;
containerPropertyInfo.SetValue(resource, resourceContainer);
}
else
{
containerPropertyInfo.SetValue(resource, container);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,13 @@ private void WriteDeltaResource(object graph, ODataWriter writer, ODataSerialize
{
writer.WriteStart(resource);
WriteDeltaComplexProperties(selectExpandNode, resourceContext, writer);
WriteDeltaNavigationProperties(selectExpandNode, resourceContext, writer);
//TODO: Need to add support to write Navigation Links, etc. using Delta Writer
//https://github.com/OData/odata.net/issues/155
//CLEANUP: merge delta logic with regular logic; requires common base between ODataWriter and ODataDeltaWriter
//WriteDynamicComplexProperties(resourceContext, writer);
//WriteNavigationLinks(selectExpandNode.SelectedNavigationProperties, resourceContext, writer);
//WriteExpandedNavigationProperties(selectExpandNode.ExpandedNavigationProperties, resourceContext, writer);
//WriteExpandedNavigationProperties(selectExpandNode, resourceContext, writer);

writer.WriteEnd();
}
Expand All @@ -226,6 +227,7 @@ private async Task WriteDeltaResourceAsync(object graph, ODataWriter writer, ODa
{
await writer.WriteStartAsync(resource);
await WriteDeltaComplexPropertiesAsync(selectExpandNode, resourceContext, writer);
await WriteDeltaNavigationPropertiesAsync(selectExpandNode, resourceContext, writer);
//TODO: Need to add support to write Navigation Links, etc. using Delta Writer
//https://github.com/OData/odata.net/issues/155
//CLEANUP: merge delta logic with regular logic; requires common base between ODataWriter and ODataDeltaWriter
Expand Down Expand Up @@ -275,6 +277,48 @@ internal void WriteDeltaComplexProperties(SelectExpandNode selectExpandNode,
}
}

internal void WriteDeltaNavigationProperties(SelectExpandNode selectExpandNode, ResourceContext resourceContext, ODataWriter writer)
{
Contract.Assert(resourceContext != null);
Contract.Assert(writer != null);

IEnumerable<KeyValuePair<IEdmNavigationProperty, Type>> navigationProperties = GetNavigationPropertiesToWrite(selectExpandNode, resourceContext);

foreach (KeyValuePair<IEdmNavigationProperty, Type> navigationProperty in navigationProperties)
{
ODataNestedResourceInfo nestedResourceInfo = new ODataNestedResourceInfo
{
IsCollection = navigationProperty.Key.Type.IsCollection(),
Name = navigationProperty.Key.Name
};

writer.WriteStart(nestedResourceInfo);
WriteDeltaComplexAndExpandedNavigationProperty(navigationProperty.Key, null, resourceContext, writer, navigationProperty.Value);
writer.WriteEnd();
}
}

internal async Task WriteDeltaNavigationPropertiesAsync(SelectExpandNode selectExpandNode, ResourceContext resourceContext, ODataWriter writer)
{
Contract.Assert(resourceContext != null);
Contract.Assert(writer != null);

IEnumerable<KeyValuePair<IEdmNavigationProperty, Type>> navigationProperties = GetNavigationPropertiesToWrite(selectExpandNode, resourceContext);

foreach (KeyValuePair<IEdmNavigationProperty, Type> navigationProperty in navigationProperties)
{
ODataNestedResourceInfo nestedResourceInfo = new ODataNestedResourceInfo
{
IsCollection = navigationProperty.Key.Type.IsCollection(),
Name = navigationProperty.Key.Name
};

await writer.WriteStartAsync(nestedResourceInfo);
await WriteDeltaComplexAndExpandedNavigationPropertyAsync(navigationProperty.Key, null, resourceContext, writer, navigationProperty.Value);
await writer.WriteEndAsync();
}
}

private async Task WriteDeltaComplexPropertiesAsync(SelectExpandNode selectExpandNode,
ResourceContext resourceContext, ODataWriter writer)
{
Expand All @@ -298,7 +342,7 @@ private async Task WriteDeltaComplexPropertiesAsync(SelectExpandNode selectExpan
}

private void WriteDeltaComplexAndExpandedNavigationProperty(IEdmProperty edmProperty, SelectExpandClause selectExpandClause,
ResourceContext resourceContext, ODataWriter writer)
ResourceContext resourceContext, ODataWriter writer, Type type = null)
{
Contract.Assert(edmProperty != null);
Contract.Assert(resourceContext != null);
Expand Down Expand Up @@ -331,6 +375,7 @@ private void WriteDeltaComplexAndExpandedNavigationProperty(IEdmProperty edmProp
{
// create the serializer context for the complex and expanded item.
ODataSerializerContext nestedWriteContext = new ODataSerializerContext(resourceContext, selectExpandClause, edmProperty);
nestedWriteContext.Type = type;

// write object.

Expand All @@ -355,7 +400,7 @@ private void WriteDeltaComplexAndExpandedNavigationProperty(IEdmProperty edmProp
}

private async Task WriteDeltaComplexAndExpandedNavigationPropertyAsync(IEdmProperty edmProperty, SelectExpandClause selectExpandClause,
ResourceContext resourceContext, ODataWriter writer)
ResourceContext resourceContext, ODataWriter writer, Type type = null)
{
Contract.Assert(edmProperty != null);
Contract.Assert(resourceContext != null);
Expand Down Expand Up @@ -388,6 +433,7 @@ await writer.WriteStartAsync(new ODataResourceSet
{
// create the serializer context for the complex and expanded item.
ODataSerializerContext nestedWriteContext = new ODataSerializerContext(resourceContext, selectExpandClause, edmProperty);
nestedWriteContext.Type = type;

// write object.

Expand Down Expand Up @@ -1351,6 +1397,43 @@ private IEnumerable<KeyValuePair<IEdmStructuralProperty, PathSelectItem>> GetPro
}
}

private IEnumerable<KeyValuePair<IEdmNavigationProperty, Type>> GetNavigationPropertiesToWrite(SelectExpandNode selectExpandNode, ResourceContext resourceContext)
{
ISet<IEdmNavigationProperty> navigationProperties = selectExpandNode.SelectedNavigationProperties;

if (navigationProperties != null)
{
IEnumerable<string> changedProperties = null;

if (null != resourceContext.ResourceInstance && resourceContext.ResourceInstance is IDelta deltaObject)
{
changedProperties = deltaObject.GetChangedPropertyNames();
dynamic delta = deltaObject;

foreach (IEdmNavigationProperty navigationProperty in navigationProperties)
{
Object obj = null;
if (changedProperties == null || changedProperties.Contains(navigationProperty.Name) && delta.DeltaNestedResources.TryGetValue(navigationProperty.Name, out obj))
{
yield return new KeyValuePair<IEdmNavigationProperty, Type>(navigationProperty, obj.GetType());
}
}
}
else if(null != resourceContext.EdmObject && resourceContext.EdmObject is IDelta changedObject)
{
changedProperties = changedObject.GetChangedPropertyNames();

foreach (IEdmNavigationProperty navigationProperty in navigationProperties)
{
if (changedProperties == null || changedProperties.Contains(navigationProperty.Name))
{
yield return new KeyValuePair<IEdmNavigationProperty, Type>(navigationProperty, typeof(IEdmChangedObject));
}
}
}
}
}

private void WriteExpandedNavigationProperties(SelectExpandNode selectExpandNode, ResourceContext resourceContext, ODataWriter writer)
{
Contract.Assert(resourceContext != null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ internal bool IsUntyped
get
{ if (_isUntyped == null)
{
_isUntyped = typeof(IEdmObject).IsAssignableFrom(Type);
_isUntyped = typeof(IEdmObject).IsAssignableFrom(Type) || typeof(EdmChangedObjectCollection).IsAssignableFrom(Type);
}

return _isUntyped.Value;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.AspNet.OData.Shared/IDeltaSetItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public interface IDeltaSetItem
/// <summary>
/// Container to hold ODataId
/// </summary>
ODataIdContainer ODataIdContainer { get; set; }
IODataIdContainer ODataIdContainer { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@
<Compile Include="$(MSBuildThisFileDirectory)IDeltaSet.cs" />
<Compile Include="$(MSBuildThisFileDirectory)IDeltaSetItem.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DefaultEdmPatchMethodHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)EdmPatchMethodHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)EdmODataAPIHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DefaultODataAPIHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ODataEdmAPIHandlerFactory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ODataAPIHandlerFactory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)IODataAPIHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ODataIdResolver.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PathItem.cs" />
<Compile Include="$(MSBuildThisFileDirectory)NavigationPath.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ODataIdContainer.cs" />
Expand Down
47 changes: 20 additions & 27 deletions src/Microsoft.AspNet.OData.Shared/NavigationPath.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
//-----------------------------------------------------------------------------
// <copyright file="NavigationPath.cs" company=".NET Foundation">
// Copyright (c) .NET Foundation and Contributors. All rights reserved.
// See License.txt in the project root for license information.
// </copyright>
//------------------------------------------------------------------------------

using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using Microsoft.OData.UriParser;

Expand All @@ -14,52 +18,41 @@ namespace Microsoft.AspNet.OData
/// </summary>
public class NavigationPath
{
private string navigationPathName;
private string _navigationPathName;
private ReadOnlyCollection<ODataPathSegment> _pathSegments;
private ConcurrentDictionary<string, PathItem[]> _pathItemCache = new ConcurrentDictionary<string, PathItem[]>();
PathItem[] _pathItems;

/// <summary>
/// Constructor which takes and odataId and creates PathItems
/// </summary>
public NavigationPath()
{

}

/// <summary>
/// Constructor which takes and odataId and creates PathItems
/// Initializes a new instance of the <see cref="NavigationPath"/> class.
/// </summary>
/// <param name="navigationPath">ODataId in string format</param>
/// <param name="pathSegments">Pathsegment collection</param>
public NavigationPath(string navigationPath, ReadOnlyCollection<ODataPathSegment> pathSegments)
{
navigationPathName = navigationPath;
Debug.Assert(navigationPath != null);

_navigationPathName = navigationPath;
_pathSegments = pathSegments;
}


/// <summary>
/// NavigationPath/ODataId in string
/// Gets the NavigationPath name
/// </summary>
public string NavigationPathName { get { return navigationPathName; } }
public string NavigationPathName { get { return _navigationPathName; } }

/// <summary>
/// To Get ODataId in Parsed format
/// </summary>
/// <returns>Array of PathItems</returns>
public PathItem[] GetNavigationPathItems()
{
PathItem[] pathItems;
if(!_pathItemCache.TryGetValue(navigationPathName, out pathItems))
{
if(_pathItems == null && _pathSegments != null)
{
if (_pathSegments != null)
{
pathItems = ParseODataId();
_pathItemCache.TryAdd(navigationPathName, pathItems);
}
_pathItems = ParseODataId();
}

return pathItems;
return _pathItems;
}

private PathItem[] ParseODataId()
Expand All @@ -69,7 +62,7 @@ private PathItem[] ParseODataId()

foreach (ODataPathSegment segment in _pathSegments)
{
if (segment is EntitySetSegment || segment is NavigationPropertySegment)
if (segment is EntitySetSegment || segment is NavigationPropertySegment || segment is PropertySegment)
{
pathItems.Add(new PathItem());
currentPathItem = pathItems.Last();
Expand Down
15 changes: 12 additions & 3 deletions src/Microsoft.AspNet.OData.Shared/ODataIdContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@
namespace Microsoft.AspNet.OData
{
/// <summary>
/// Sealed class to hold ODataID in parsed format, it will be used by POCO objects as well as Delta{TStructuralType}
/// Interface to hold ODataID in parsed format, it will be used by POCO objects as well as Delta{TStructuralType}
/// </summary>
public sealed class ODataIdContainer
public interface IODataIdContainer
{
/// <summary>
/// The Navigation path corresponding to the ODataId
/// </summary>
public NavigationPath ODataIdNavigationPath { set; get; }
NavigationPath ODataIdNavigationPath { set; get; }
}

/// <summary>
/// Default implementation of IOdataIdContainer
/// </summary>
public class ODataIdContainer : IODataIdContainer
{
///<inheritdoc/>
public NavigationPath ODataIdNavigationPath { get; set; }
}
}
Loading

0 comments on commit c42f50f

Please sign in to comment.