Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ public async Task<List<CohortDistributionParticipantDto>> GetUnextractedCohortDi
}
else
{
var participantsList = await _cohortDistributionDataServiceClient.GetByFilter(x => x.IsExtracted.Equals(0) && x.RequestId == Guid.Empty);
participantsToBeExtracted = participantsList.OrderBy(x => x.RecordUpdateDateTime ?? x.RecordInsertDateTime).Take(rowCount).ToList();

participantsToBeExtracted = (await _cohortDistributionDataServiceClient.GetByFilter(x => x.IsExtracted.Equals(0) && x.RequestId == Guid.Empty,
x => x.RecordUpdateDateTime ?? x.RecordInsertDateTime ?? DateTime.MinValue,rowCount)).ToList();

}

//TODO do this filtering on the data services
var CohortDistributionParticipantList = participantsToBeExtracted.Select(x => new CohortDistributionParticipant(x)).ToList();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ public async Task<IEnumerable<TEntity>> GetByFilter(Expression<Func<TEntity, boo
return result;
}

public async Task<IEnumerable<TEntity>> GetByFilter(Expression<Func<TEntity, bool>> predicate, Expression<Func<TEntity, object>> orderBy, int take)
{

var result = await GetByFilter(predicate);
var orderByFunction = orderBy.Compile();
return result.OrderBy(orderByFunction).Take(take).ToList();

}

public virtual async Task<TEntity> GetSingle(string id)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ public async Task<IEnumerable<TEntity>> GetByFilter(Expression<Func<TEntity, boo
return _data.Where(predicateFunction).ToList();
}

public async Task<IEnumerable<TEntity>> GetByFilter(Expression<Func<TEntity, bool>> predicate, Expression<Func<TEntity, object>> orderBy, int take)
{

_logger.LogInformation("Getting By Filter ordered from static data service {EntityName}", typeof(TEntity).FullName);
await Task.CompletedTask;

var predicateFunction = predicate.Compile();
var orderByFunction = orderBy.Compile();
return _data.Where(predicateFunction).OrderBy(orderByFunction).Take(take).ToList();

}

public Task<bool> Add(TEntity entity)
{
throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public interface IDataServiceClient<TEntity>
/// <summary>
/// Adds a given records to the database
/// </summary>
/// <param name="predicate">linq query defining the filter on the table</param>
/// <param name="orderBy">query defining the order</param>
/// <param name="take">number of records to take from the filtered result</param>
Task<IEnumerable<TEntity>> GetByFilter(Expression<Func<TEntity, bool>> predicate, Expression<Func<TEntity, object>> orderBy, int take);
/// <summary>
/// Adds a given records to the database
/// </summary>
/// <param name="entity">object of type TEntity to be inserted in the database</param>
/// <returns>a boolean representing if the record was inserted successfully</returns>
Task<bool> Add(TEntity entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.ComponentModel.DataAnnotations;
using System.Reflection;

// TODO: move to Shared/Utilities
public static class ReflectionUtilities
{
/// <summary>
Expand All @@ -14,14 +13,14 @@
public static PropertyInfo GetKey<TEntity>() where TEntity : class
{
var type = typeof(TEntity);
return type.GetProperties().FirstOrDefault(p =>

Check warning on line 16 in application/CohortManager/src/Functions/Shared/Utilities/ReflectionUtilities.cs

View workflow job for this annotation

GitHub Actions / Test stage / Run consolidated tests

Possible null reference return.
p.CustomAttributes.Any(attr => attr.AttributeType == typeof(KeyAttribute)));
}


public static Type GetPropertyType(Type type, string property)
{
return type.GetProperty(property).PropertyType;

Check warning on line 23 in application/CohortManager/src/Functions/Shared/Utilities/ReflectionUtilities.cs

View workflow job for this annotation

GitHub Actions / Test stage / Run consolidated tests

Dereference of a possibly null reference.
}

public static bool PropertyExists(Type type, string property) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public void Setup()
.Setup(x => x.GetByFilter(It.IsAny<Expression<Func<CohortDistribution, bool>>>()))
.ReturnsAsync((Expression<Func<CohortDistribution, bool>> filter) =>
_participantList.Where(filter.Compile()).ToList());
_cohortDistributionDataServiceClient
.Setup(x => x.GetByFilter(It.IsAny<Expression<Func<CohortDistribution, bool>>>(), It.IsAny<Expression<Func<CohortDistribution, object>>>(), It.IsAny<int>()))
.ReturnsAsync((Expression<Func<CohortDistribution, bool>> filter, Expression<Func<CohortDistribution, object>> orderBy, int take) =>
_participantList.Where(filter.Compile()).OrderBy(orderBy.Compile()).Take(take).ToList());

_cohortDistributionDataServiceClient
.Setup(x => x.GetSingle(It.IsAny<string>()))
Expand Down
Loading