Adding
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace LCU.API.Internal.DocumentIngestorLib.Extensions;
|
||||
|
||||
public static class FilterNullsAndZerosOrDefaultExtension
|
||||
{
|
||||
public static string[] FilterNullsAndZerosOrDefault(this IEnumerable<string> list)
|
||||
{
|
||||
var filteredList = list?.Where(x =>
|
||||
!string.IsNullOrWhiteSpace(x) && int.Parse(x) != 0
|
||||
).ToList();
|
||||
if (filteredList == null || !filteredList.Any())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return filteredList.ToArray();
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Entities;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
|
||||
using System;
|
||||
|
||||
namespace LCU.Api.Internal.DocumentIngestorLib.Extensions.Queryables
|
||||
{
|
||||
public static class DocumentProcessingInfoCreatedDateQueryable
|
||||
{
|
||||
public static IQueryable<DocumentProcessingInfo> FilterByCreatedDate(this IQueryable<DocumentProcessingInfo> queryable, Filter filter)
|
||||
{
|
||||
if (filter?.CreatedDateStart == null && filter?.CreatedDateEnd == null)
|
||||
{
|
||||
return queryable;
|
||||
}
|
||||
|
||||
if (filter?.CreatedDateStart == null)
|
||||
{
|
||||
filter.CreatedDateStart = DateTime.MinValue;
|
||||
}
|
||||
|
||||
if (filter?.CreatedDateEnd == null || filter?.CreatedDateEnd == DateTime.MinValue)
|
||||
{
|
||||
filter.CreatedDateEnd = DateTime.MaxValue;
|
||||
}
|
||||
|
||||
return queryable.Where(DocumentProcessingInfo => DocumentProcessingInfo.CreatedDate >= filter.CreatedDateStart &&
|
||||
DocumentProcessingInfo.CreatedDate <= filter.CreatedDateEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Entities;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
|
||||
|
||||
namespace LCU.Api.Internal.DocumentIngestorLib.Extensions.Queryables
|
||||
{
|
||||
public static class DocumentProcessingInfoDocBusinessNameQueryable
|
||||
{
|
||||
public static IQueryable<DocumentProcessingInfo> FilterDocBusinessName(this IQueryable<DocumentProcessingInfo> queryable, Filter filter)
|
||||
{
|
||||
if (filter?.DocBusinessName == null)
|
||||
{
|
||||
return queryable;
|
||||
}
|
||||
|
||||
return queryable.Where(documentProcessingInfo => documentProcessingInfo.DocumentBusinessName.Contains(filter.DocBusinessName));
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Entities;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace LCU.Api.Internal.DocumentIngestorLib.Extensions.Queryables
|
||||
{
|
||||
public static class DocumentProcessingInfoDocTypeQueryable
|
||||
{
|
||||
public static IQueryable<DocumentProcessingInfo> FilterDocType(this IQueryable<DocumentProcessingInfo> queryable, Filter filter)
|
||||
{
|
||||
if (filter?.DocType == null)
|
||||
{
|
||||
return queryable;
|
||||
}
|
||||
|
||||
var filterDocType = Regex.Replace(filter.DocType, @"\s", "");
|
||||
|
||||
return queryable.Where(documentProcessingInfo => documentProcessingInfo.DocumentType.Contains(filterDocType));
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Entities;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
|
||||
using LCU.API.Internal.DocumentIngestorLib.Persistence;
|
||||
using System.Linq;
|
||||
|
||||
namespace LCU.Api.Internal.DocumentIngestorLib.Extensions.Queryables;
|
||||
|
||||
public static class DocumentProcessingInfoIndexJsonEqualsFilter
|
||||
{
|
||||
public static IQueryable<DocumentProcessingInfo> FilterByIndexFileJsonKeyValueEquals(
|
||||
this IQueryable<DocumentProcessingInfo> queryable, Filter filter)
|
||||
{
|
||||
if (filter?.CustomIndexFileFiltersEquals is null) return queryable;
|
||||
|
||||
var result = queryable;
|
||||
foreach (var indexFilter in filter.CustomIndexFileFiltersEquals)
|
||||
{
|
||||
result = result.Where(d => AppDbContext.JSON_VALUE(d.DocumentValuePayload, "$." + indexFilter.Key) == indexFilter.Value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using LCU.API.Internal.DocumentIngestorLib.Persistence;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Entities;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LCU.Api.Internal.DocumentIngestorLib.Extensions.Queryables;
|
||||
|
||||
public static class DocumentProcessingInfoIndexJsonLikeOrFilter
|
||||
{
|
||||
public static IQueryable<DocumentProcessingInfo> FilterByIndexFileJsonKeyValueLikeOr(
|
||||
this IQueryable<DocumentProcessingInfo> queryable, Filter filter)
|
||||
{
|
||||
if (filter?.CustomIndexFileFiltersLikeOr is null) return queryable;
|
||||
|
||||
var result = queryable;
|
||||
|
||||
Expression<Func<DocumentProcessingInfo, bool>> predicate = f => false;
|
||||
foreach (var indexFilter in filter.CustomIndexFileFiltersLikeOr)
|
||||
{
|
||||
Expression<Func<DocumentProcessingInfo, bool>> expression = d =>
|
||||
EF.Functions.Like(AppDbContext.JSON_VALUE(d.DocumentValuePayload, "$." + indexFilter.Key),
|
||||
$"%{indexFilter.Value.Replace(" ", "%")}%");
|
||||
var invokedExpr = Expression.Invoke(expression, predicate.Parameters);
|
||||
|
||||
predicate = Expression.Lambda<Func<DocumentProcessingInfo, bool>>(Expression.OrElse(predicate.Body, invokedExpr),
|
||||
predicate.Parameters);
|
||||
}
|
||||
|
||||
result = result.Where(predicate);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Entities;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
|
||||
|
||||
namespace LCU.Api.Internal.DocumentIngestorLib.Extensions.Queryables
|
||||
{
|
||||
public static class DocumentProcessingInfoIngestorRunInfoIdQueryable
|
||||
{
|
||||
public static IQueryable<DocumentProcessingInfo> FilterIngestorRunInfoId(this IQueryable<DocumentProcessingInfo> queryable, Filter filter)
|
||||
{
|
||||
if (filter.IngestorRunInfoId == null)
|
||||
{
|
||||
return queryable;
|
||||
}
|
||||
|
||||
return queryable.Where(documentProcessingInfo => documentProcessingInfo.IngestorRunInfoId == filter.IngestorRunInfoId);
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
using System.Linq;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Entities;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
|
||||
|
||||
namespace LCU.Api.Internal.DocumentIngestorLib.Extensions.Queryables;
|
||||
|
||||
public static class DocumentProcessingInfoNotificationStatusQueryable
|
||||
{
|
||||
public static IQueryable<DocumentProcessingInfo> FilterByNotificationStatusType
|
||||
(
|
||||
this IQueryable<DocumentProcessingInfo> queryable,
|
||||
Filter filter
|
||||
) => filter?.NotificationStatusFilters is { Count: > 0 } statusFilter
|
||||
? queryable
|
||||
.Where(q => q.MemberNotificationInfos != null)
|
||||
.Where(q => q.MemberNotificationInfos.Any(m => statusFilter.Contains(m.NotificationStatusType)))
|
||||
: queryable;
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Entities;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
|
||||
|
||||
namespace LCU.Api.Internal.DocumentIngestorLib.Extensions.Queryables
|
||||
{
|
||||
public static class DocumentProcessingInfoStatusTypeQueryable
|
||||
{
|
||||
public static IQueryable<DocumentProcessingInfo> FilterByStatusType(this IQueryable<DocumentProcessingInfo> queryable, Filter filter)
|
||||
{
|
||||
if (filter?.StatusFilters == null || !filter.StatusFilters.Any())
|
||||
{
|
||||
return queryable;
|
||||
}
|
||||
|
||||
var enabledStatusFilters = filter.StatusFilters.Where(statusFilter => statusFilter.IsEnabled).ToList();
|
||||
|
||||
var unknownStatusTypes = enabledStatusFilters.Where(status => status.IsUnknown).Select(status => status.StatusType);
|
||||
var knownStatusTypes = enabledStatusFilters.Where(status => !status.IsUnknown).Select(status => status.StatusType);
|
||||
|
||||
return queryable.Where(documentProcessingInfo =>
|
||||
(documentProcessingInfo.EntityUnknown && unknownStatusTypes.Contains(documentProcessingInfo.StatusType)) ||
|
||||
(!documentProcessingInfo.EntityUnknown && knownStatusTypes.Contains(documentProcessingInfo.StatusType))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Entities;
|
||||
|
||||
namespace LCU.Api.Internal.DocumentIngestorLib.Extensions.Queryables
|
||||
{
|
||||
public static class IncludeAllQueryable
|
||||
{
|
||||
public static IQueryable<DocumentProcessingInfo> IncludeAll(this IQueryable<DocumentProcessingInfo> queryable)
|
||||
{
|
||||
return queryable.Include(documentProcessingInfo => documentProcessingInfo.IngestorRunInfo)
|
||||
.Include(documentProcessingInfo => documentProcessingInfo.ProcessingLogs)
|
||||
.Include(documentProcessingInfo => documentProcessingInfo.MemberNotificationInfos);
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
using System.Linq;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Entities;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
|
||||
|
||||
namespace LCU.Api.Internal.DocumentIngestorLib.Extensions.Queryables
|
||||
{
|
||||
public static class IncludeFiltersQueryable
|
||||
{
|
||||
public static IQueryable<DocumentProcessingInfo> IncludeFilters(this IQueryable<DocumentProcessingInfo> queryable, Filter filter)
|
||||
{
|
||||
return queryable.FilterDocType(filter)
|
||||
.FilterDocBusinessName(filter)
|
||||
.FilterByStatusType(filter)
|
||||
.FilterByCreatedDate(filter)
|
||||
.FilterByIndexFileJsonKeyValueEquals(filter)
|
||||
.FilterByIndexFileJsonKeyValueLikeOr(filter)
|
||||
.FilterIngestorRunInfoId(filter)
|
||||
.FilterByNotificationStatusType(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Entities;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
|
||||
using System.Linq;
|
||||
using System.Linq.Dynamic.Core;
|
||||
using System.Text;
|
||||
|
||||
namespace LCU.Api.Internal.DocumentIngestorLib.Extensions.Queryables
|
||||
{
|
||||
public static class SortableFieldsQueryable
|
||||
{
|
||||
public static IQueryable<DocumentProcessingInfo> OrderBySortableFields(this IQueryable<DocumentProcessingInfo> queryable, Filter filter)
|
||||
{
|
||||
if (filter?.SortableFields == null || !filter.SortableFields.Any())
|
||||
{
|
||||
return queryable;
|
||||
}
|
||||
|
||||
var orderBy = new StringBuilder();
|
||||
foreach (var field in filter.SortableFields.OrderBy(sortableField => sortableField.Position))
|
||||
{
|
||||
var addedComma = orderBy.ToString() == "" ? "" : " ,";
|
||||
var desc = field.IsDescending ? " desc" : "";
|
||||
orderBy.Append($"{addedComma}{field.Field}{desc}");
|
||||
}
|
||||
|
||||
return queryable.OrderBy(orderBy.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using TimeZoneConverter;
|
||||
|
||||
namespace LCU.Api.Internal.DocumentIngestorLib.Extensions
|
||||
{
|
||||
public static class TimeZoneDateTime
|
||||
{
|
||||
public static DateTime ConvertToTimeZone(this DateTime dateTime, string timeZone)
|
||||
{
|
||||
var assumedTimezone = TZConvert.GetTimeZoneInfo(timeZone);
|
||||
return TimeZoneInfo.ConvertTime(dateTime, assumedTimezone);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user