-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ODS-6512] Modify batched page queries in NHibernate to use AggregateId instead of Id for page-level inclusion criteria #1165
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...pi/Security/Authorization/Repositories/GetEntitiesByAggregateIdsAuthorizationDecorator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using EdFi.Ods.Common; | ||
using EdFi.Ods.Common.Repositories; | ||
|
||
namespace EdFi.Ods.Api.Security.Authorization.Repositories; | ||
|
||
/// <summary> | ||
/// Authorizes calls to the "GetByAggregateIds" repository method. | ||
/// </summary> | ||
/// <typeparam name="T">The Type of entity being queried.</typeparam> | ||
public class GetEntitiesByAggregateIdsAuthorizationDecorator<T> : IGetEntitiesByAggregateIds<T> | ||
where T : class, IHasIdentifier, IDateVersionedEntity | ||
{ | ||
private readonly IGetEntitiesByAggregateIds<T> _next; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="GetEntitiesByAggregateIdsAuthorizationDecorator{T}"/> class. | ||
/// </summary> | ||
/// <param name="next">The decorated instance for which authorization is being performed.</param> | ||
public GetEntitiesByAggregateIdsAuthorizationDecorator(IGetEntitiesByAggregateIds<T> next) | ||
{ | ||
_next = next; | ||
} | ||
|
||
/// <summary> | ||
/// Authorizes a call to get multiple records by their record identifiers. | ||
/// </summary> | ||
/// <param name="aggregateIds">The values of the record identifiers to be retrieved.</param> | ||
/// <returns>The specified entity if found; otherwise null.</returns> | ||
public async Task<IList<T>> GetByAggregateIdsAsync(IList<int> aggregateIds, CancellationToken cancellationToken) | ||
{ | ||
return await _next.GetByAggregateIdsAsync(aggregateIds, cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
Application/EdFi.Ods.Common/Infrastructure/Repositories/GetEntitiesByAggregateIds.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using EdFi.Common; | ||
using EdFi.Ods.Common.Context; | ||
using EdFi.Ods.Common.Infrastructure.Activities; | ||
using EdFi.Ods.Common.Models; | ||
using EdFi.Ods.Common.Models.Domain; | ||
using EdFi.Ods.Common.Repositories; | ||
using EdFi.Ods.Common.Security.Claims; | ||
using NHibernate; | ||
|
||
namespace EdFi.Ods.Common.Infrastructure.Repositories; | ||
|
||
public class GetEntitiesByAggregateIds<TEntity> : GetEntitiesBase<TEntity>, IGetEntitiesByAggregateIds<TEntity> | ||
where TEntity : DomainObjectBase, IHasIdentifier, IDateVersionedEntity | ||
{ | ||
private readonly IParameterListSetter _parameterListSetter; | ||
|
||
public GetEntitiesByAggregateIds( | ||
ISessionFactory sessionFactory, | ||
IDomainModelProvider domainModelProvider, | ||
IParameterListSetter parameterListSetter, | ||
IContextProvider<DataManagementResourceContext> dataManagementResourceContextProvider) | ||
: base(sessionFactory, domainModelProvider, dataManagementResourceContextProvider) | ||
{ | ||
_parameterListSetter = Preconditions.ThrowIfNull(parameterListSetter, nameof(parameterListSetter)); | ||
} | ||
|
||
public async Task<IList<TEntity>> GetByAggregateIdsAsync(IList<int> aggregateIds, CancellationToken cancellationToken) | ||
{ | ||
using (new SessionScope(SessionFactory)) | ||
{ | ||
IEnumerable<TEntity> results; | ||
|
||
if (aggregateIds.Count == 1) | ||
{ | ||
results = await GetAggregateResultsAsync( | ||
"where a.AggregateId = :id", | ||
q => q.SetParameter("id", aggregateIds[0]), cancellationToken); | ||
} | ||
else | ||
{ | ||
results = await GetAggregateResultsAsync( | ||
"where a.AggregateId IN (:ids)", | ||
q => _parameterListSetter.SetParameterList(q ,"ids", aggregateIds), | ||
cancellationToken, | ||
"order by a.AggregateId"); | ||
} | ||
|
||
// Process multiple results in the first-level cache to a list of complete aggregates | ||
return results.ToList(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
Application/EdFi.Ods.Common/Repositories/IGetEntitiesByAggregateIds.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace EdFi.Ods.Common.Repositories; | ||
|
||
/// <summary> | ||
/// Defines a method for retrieving a list of entities by their record identifiers. | ||
/// </summary> | ||
/// <typeparam name="TEntity">The Type of the entities to be retrieved.</typeparam> | ||
public interface IGetEntitiesByAggregateIds<TEntity> | ||
where TEntity : IHasIdentifier, IDateVersionedEntity | ||
{ | ||
/// <summary> | ||
/// Get a list of entities by their record identifiers. | ||
/// </summary> | ||
/// <param name="aggregateIds">The list of aggregate identifiers.</param> | ||
/// <returns>The list of matching entities.</returns> | ||
Task<IList<TEntity>> GetByAggregateIdsAsync(IList<int> aggregateIds, CancellationToken cancellationToken); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Key/values were inverted in the dictionary here because the key should be the implementation, not the common interface (wasn't accounting for the possibility of multiple decorators implementing the same interface).