This commit is contained in:
Zeeshaun
2026-03-13 09:11:35 -05:00
parent f004c8205a
commit c2d6bda458
197 changed files with 14970 additions and 0 deletions
@@ -0,0 +1,25 @@
using System;
using System.Globalization;
using System.Numerics;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace LCU.Library.Internal.DocumentModels.Converter;
public class BigIntegerConverter : JsonConverter<BigInteger>
{
public override BigInteger Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.Number)
throw new JsonException($"Found token {reader.TokenType} but expected token {JsonTokenType.Number}");
using var doc = JsonDocument.ParseValue(ref reader);
return BigInteger.Parse(doc.RootElement.GetRawText(), NumberFormatInfo.InvariantInfo);
}
public override void Write(Utf8JsonWriter writer, BigInteger value, JsonSerializerOptions options)
{
var s = value.ToString(NumberFormatInfo.InvariantInfo);
using var doc = JsonDocument.Parse(s);
doc.WriteTo(writer);
}
}
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Dynamic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace LCU.Library.Internal.DocumentModels.Converter;
public class DynamicObjectJsonConverter : Newtonsoft.Json.JsonConverter
{
public override void WriteJson(JsonWriter writer, dynamic value, JsonSerializer serializer)
{
serializer.Serialize(writer, value);
}
public override dynamic ReadJson(JsonReader reader, Type objectType, dynamic existingValue, JsonSerializer serializer)
{
if (reader.TokenType != JsonToken.StartObject) return reader.Value;
var node = JObject.Load(reader);
var definition = new ExpandoObject();
var definitionPropertyBag = definition as IDictionary<string, object>;
foreach (var property in node.Properties())
{
definitionPropertyBag[property.Name] = property.Value.ToObject<object>();
}
return JsonConvert.DeserializeAnonymousType(node.ToString(), definition);
}
public override bool CanConvert(Type _) => true;
}
@@ -0,0 +1,14 @@
using System;
namespace LCU.Library.Internal.DocumentModels.Converter;
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)]
public class JsonKnownTypesAttribute : Attribute
{
public Type[] Subclasses { get; }
public JsonKnownTypesAttribute(params Type[] knownTypes)
{
Subclasses = knownTypes;
}
}
@@ -0,0 +1,48 @@
using System;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace LCU.Library.Internal.DocumentModels.Converter
{
public class FromJsonQueryAttribute : ModelBinderAttribute
{
public FromJsonQueryAttribute()
{
BinderType = typeof(JsonQueryBinder);
}
}
public class JsonQueryBinder : IModelBinder
{
public JsonQueryBinder()
{
}
public Task BindModelAsync(ModelBindingContext bindingContext)
{
var value = bindingContext.ValueProvider.GetValue(bindingContext.FieldName).FirstValue;
if (value == null)
{
return Task.CompletedTask;
}
try
{
var parsed = JsonSerializer.Deserialize(
value,
bindingContext.ModelType,
new JsonSerializerOptions(JsonSerializerDefaults.Web)
);
bindingContext.Result = ModelBindingResult.Success(parsed);
}
catch (Exception e)
{
bindingContext.Result = ModelBindingResult.Failed();
}
return Task.CompletedTask;
}
}
}
@@ -0,0 +1,107 @@
using System;
using System.Linq;
using System.Reflection;
using System.Text.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using JsonSerializer = System.Text.Json.JsonSerializer;
namespace LCU.Library.Internal.DocumentModels.Converter;
internal static class PolymorphicJsonConverter
{
public const string TypeProperty = "_t";
public static Exception NotSupported<T>() => new NotSupportedException($"{typeof(T).Name} must specify known deserialization types");
public static bool IsSerializationSupportedFor<T>(Type actualType) => typeof(T).GetCustomAttribute<JsonKnownTypesAttribute>() is { } knownTypes
&& knownTypes.Subclasses.Contains(actualType);
public static Type DeserializationTypeFor<T>(string actualType) => typeof(T)
.GetCustomAttribute<JsonKnownTypesAttribute>()
.Subclasses
.Single(t => t.Name == actualType);
}
public class SystemPolymorphicJsonConverter<T> : System.Text.Json.Serialization.JsonConverter<T>
{
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var document = JsonDocument.ParseValue(ref reader);
var type = document.RootElement.GetProperty(PolymorphicJsonConverter.TypeProperty).GetString();
var deserializationType = PolymorphicJsonConverter.DeserializationTypeFor<T>(type);
return (T)document.Deserialize(deserializationType, options);
}
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
{
var actualType = value.GetType();
if (!PolymorphicJsonConverter.IsSerializationSupportedFor<T>(actualType))
{
throw PolymorphicJsonConverter.NotSupported<T>();
}
writer.WriteStartObject();
writer.WriteString(PolymorphicJsonConverter.TypeProperty, actualType.Name);
var actualValue = JsonSerializer.Serialize(value, actualType, options);
writer.WriteRawValue(actualValue.Substring(1, actualValue.Length - 2), true);
writer.WriteEndObject();
}
}
public class NewtonsoftPolymorphicJsonConverter<T> : Newtonsoft.Json.JsonConverter<T>
{
public override bool CanRead => _canRead;
private bool _canRead = true;
public override T ReadJson(JsonReader reader, Type objectType, T existingValue, bool hasExistingValue, Newtonsoft.Json.JsonSerializer serializer)
{
var document = JObject.Load(reader);
var type = document.GetValue(PolymorphicJsonConverter.TypeProperty)!.Value<string>();
var deserializationType = PolymorphicJsonConverter.DeserializationTypeFor<T>(type);
T result;
lock (this)
{
_canRead = false;
result = (T)JsonConvert.DeserializeObject(document.ToString(), deserializationType);
_canRead = true;
}
return result;
}
public override bool CanWrite => _canWrite;
private bool _canWrite = true;
public override void WriteJson(JsonWriter writer, T value, Newtonsoft.Json.JsonSerializer serializer)
{
var actualType = value.GetType();
if (!PolymorphicJsonConverter.IsSerializationSupportedFor<T>(actualType))
{
throw PolymorphicJsonConverter.NotSupported<T>();
}
writer.WriteStartObject();
writer.WritePropertyName(PolymorphicJsonConverter.TypeProperty);
writer.WriteValue(actualType.Name);
JObject jValue;
lock (this)
{
_canWrite = false;
jValue = JObject.FromObject(value);
_canWrite = true;
}
foreach (var property in jValue.Properties())
{
property.WriteTo(writer);
}
writer.WriteEndObject();
}
}
@@ -0,0 +1,86 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.8.4</Version>
<PackageVersion>1.8.5</PackageVersion>
<Description>
1.0.0 - Initial Setup
1.0.1 - Delete Date is now an optional field in requests and responses, and source on update requests has been renamed to updateSource
1.0.2 - TraceId has been added as an optional field to documentInformation
1.0.3 - DocumentSearchRequest object has been added
1.0.4 - EncodeDocumentInformationFilterUri added to DocumentInformationFilter object
1.0.5 - Updating DocumentInformationResponse to have a JsonConverter for BigInt
1.0.6 - Separating JsonConverter for BigInt to own class
1.0.7 - Adding in DataSource field in request and response models and search filter
1.0.8 - Adding in CreatedDate field in request and response models and search filter
1.0.9 - Updating Filter Query Creation method to not shorten dates
1.1.0 - Add AccountNumbers, PersonNumbers and OrganizationNumbers to models and search filter
1.1.1 - Add document action notification route for actions on documents not fulfilled by Document API directly
1.1.2 - contract type definition for document audit logs
1.1.3 - document filter query string serialization fix
1.2.0 - Add Sorter to easily create sortable fields
1.2.1 - Change PersonNumberEquals and OrganizationNumberEquals to singular string
1.3.0 - Add DocumentInformationFilteredSearch
1.3.1 - fixed multiple serialization for DocumentFieldAudit Current and Previous Value properties
1.3.2 - fixed serialization of Current and Previous Value properties that aren't objects (e.g. null or boolean)
1.4.0 - document search filters can no longer be used in query strings, method EncodeDocumentInformationFilterUri removed
1.5.0 - Added document action for upload
1.5.1 - Removed ArchiveDate and DeleteDate from DocumentInformation
1.6.0 - Add GetDocumentCleanupRequest
1.7.0 - Add DocumentAction for Delete and DeleteContent, Add DeleteDocumentContentRequest
1.8.0 - Make DocumentInformation.DocumentBlobId a nullable Guid for deletion
1.8.1 - Add TypeContainsAny
1.8.2 - Add BusinessName to DocumentInformationFilter
1.8.3 - Reverted MongoDB.Driver version
1.8.4 - MongoDB.Driver version
1.8.5 - Nuget update DocumentIngestor Model
</Description>
<PackageReleaseNotes>
1.0.0 - Initial Setup
1.0.1 - Delete Date is now an optional field in requests and responses, and source on update requests has been renamed to updateSource
1.0.2 - TraceId has been added as an optional field to documentInformation
1.0.3 - DocumentSearchRequest object has been added
1.0.4 - EncodeDocumentInformationFilterUri added to DocumentInformationFilter object
1.0.5 - Updating DocumentInformationResponse to have a JsonConverter for BigInt
1.0.6 - Separating JsonConverter for BigInt to own class
1.0.7 - Adding in DataSource field in request and response models and search filter
1.0.8 - Adding in CreatedDate field in request and response models and search filter
1.0.9 - Updating Filter Query Creation method to not shorten dates
1.1.0 - Add AccountNumbers, PersonNumbers and OrganizationNumbers to models and search filter
1.1.1 - Add document action notification route for actions on documents not fulfilled by Document API directly
1.1.2 - contract type definition for document audit logs
1.1.3 - document filter query string serialization fix
1.2.0 - Add Sorter to easily create sortable fields
1.2.1 - Change PersonNumberEquals and OrganizationNumberEquals to singular string
1.3.0 - Add DocumentInformationFilteredSearch
1.3.1 - fixed multiple serialization for DocumentFieldAudit Current and Previous Value properties
1.3.2 - fixed serialization of Current and Previous Value properties that aren't objects (e.g. null or boolean)
1.4.0 - document search filters can no longer be used in query strings, method EncodeDocumentInformationFilterUri removed
1.5.0 - Added document action for upload
1.5.1 - Removed ArchiveDate and DeleteDate from DocumentInformation
1.6.0 - Add GetDocumentCleanupRequest
1.7.0 - Add DocumentAction for Delete and DeleteContent, Add DeleteDocumentContentRequest
1.8.0 - Make DocumentInformation.DocumentBlobId a nullable Guid for deletion
1.8.1 - Add TypeContainsAny
1.8.2 - Add BusinessName to DocumentInformationFilter
1.8.3 - Reverted MongoDB.Driver version
1.8.4 - MongoDB.Driver version
1.8.5 - Nuget update DocumentIngestor Model
</PackageReleaseNotes>
<RootNamespace>LCU.Library.Internal.DocumentModels</RootNamespace>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LCU.Library.Internal.DocumentIngestorModels" Version="1.19.19" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.OpenApi" Version="1.4.3" />
<PackageReference Include="MongoDB.Driver" Version="2.20.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Text.Json" Version="6.0.10" />
</ItemGroup>
</Project>
@@ -0,0 +1,11 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace LCU.Library.Internal.DocumentModels.Requests;
public class DeleteDocumentContentRequest
{
[Required] public Guid DocumentId { get; set; }
public string? Reason { get; set; }
public string UserName { get; set; } = "System";
}
@@ -0,0 +1,9 @@
namespace LCU.Library.Internal.DocumentModels.Requests;
public enum DocumentAction
{
Download,
Upload,
Delete,
DeleteContent
}
@@ -0,0 +1,9 @@
using System.ComponentModel.DataAnnotations;
namespace LCU.Library.Internal.DocumentModels.Requests;
public class DocumentActionNotificationRequest
{
[Required] public DocumentAction Action { get; set; }
[Required] public string Source { get; set; }
}
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace LCU.Library.Internal.DocumentModels.Requests;
public class DocumentRequest
{
[Required] public string Name { get; set; }
[Required] public string Type { get; set; }
[Required] public byte[] Content { get; set; }
[Required] public string Source { get; set; }
[Required] public string DataSource { get; set; }
[Required] public DateTime CreatedDate { get; set; }
public Guid? TraceId { get; set; }
public string[] PersonNumbers { get; set; }
public string[] OrganizationNumbers { get; set; }
public string AccountNumber { get; set; }
public Dictionary<string, string> Attributes { get; set; }
}
@@ -0,0 +1,37 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Web;
using Microsoft.AspNetCore.Mvc;
namespace LCU.Library.Internal.DocumentModels.Requests.Search;
public class DocumentInformationFilter
{
public string? Name { get; set; }
public string? Type { get; set; }
public string? BusinessName { get; set; }
public string[]? TypeContainsAny { get; set; }
public bool? ScanStatus { get; set; }
public string? Source { get; set; }
public string? DataSource { get; set; }
public Guid? TraceId { get; set; }
public string? PersonNumbersEquals { get; set; }
public string[]? PersonNumbersContains { get; set; }
public string[]? PersonNumbersContainsAny { get; set; }
public string? OrganizationNumbersEquals { get; set; }
public string[]? OrganizationNumbersContains { get; set; }
public string[]? OrganizationNumbersContainsAny { get; set; }
public string? AccountNumberEquals { get; set; }
public string[]? AccountNumberContainsAny { get; set; }
public Dictionary<string, string>? AttributesEquals { get; set; }
public Dictionary<string, string>? AttributesContains { get; set; }
public Dictionary<string, string>? AttributesContainsAny { get; set; }
public DateTime? CreatedDateMinimum { get; set; }
public DateTime? CreatedDateMaximum { get; set; }
public DateTime? UploadDateMinimum { get; set; }
public DateTime? UploadDateMaximum { get; set; }
public DateTime? LastModifiedMinimum { get; set; }
public DateTime? LastModifiedDateMaximum { get; set; }
}
@@ -0,0 +1,12 @@
using System.Collections.Generic;
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
namespace LCU.Library.Internal.DocumentModels.Requests.Search;
public class DocumentInformationFilteredSearch
{
public DocumentInformationFilter Filter { get; set; }
public int? Skip { get; set; }
public int? Take { get; set; }
public List<SortableField>? SortDefinition { get; set; }
}
@@ -0,0 +1,10 @@
using System.Collections.Generic;
using LCU.Library.DocumentType.Models.Responses;
namespace LCU.Library.Internal.DocumentModels.Requests.Search;
public class GetDocumentCleanupRequest
{
public List<DocumentCodeDetailsResponse> DocumentCodeDetailInfos { get; set; }
public int Limit { get; set; }
}
@@ -0,0 +1,34 @@
using System.Collections.Generic;
using MongoDB.Driver;
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
namespace LCU.Library.Internal.DocumentModels.Requests.Search;
public class Sorter<T>
{
public static SortDefinition<T> GetSorter(List<SortableField> fields)
{
SortDefinition<T>? sortDefinition = null;
if(fields == null)
{
return sortDefinition;
}
fields.Sort((a, b) => a.Position.CompareTo(b.Position));
foreach (var field in fields)
{
if (sortDefinition == null)
{
sortDefinition = field.IsDescending ? Builders<T>.Sort.Descending(field.Field) : Builders<T>.Sort.Ascending(field.Field);
}
else
{
sortDefinition = field.IsDescending ? sortDefinition.Descending(field.Field) : sortDefinition.Ascending(field.Field);
}
}
return sortDefinition;
}
}
@@ -0,0 +1,10 @@
using System.ComponentModel.DataAnnotations;
namespace LCU.Library.Internal.DocumentModels.Requests;
public class UpdateDocumentContentRequest
{
[Required] public byte[] Content { get; set; }
[Required] public string UpdateSource { get; set; }
}
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace LCU.Library.Internal.DocumentModels.Requests;
public class UpdateDocumentInformationRequest
{
[Required] public string Name { get; set; }
[Required] public string Type { get; set; }
[Required] public string UpdateSource { get; set; }
public string[] PersonNumbers { get; set; }
public string[] OrganizationNumbers { get; set; }
public string AccountNumber { get; set; }
public Dictionary<string, string> Attributes { get; set; }
}
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace LCU.Library.Internal.DocumentModels.Requests;
public class UpdateDocumentRequest
{
[Required] public string Name { get; set; }
[Required] public string Type { get; set; }
[Required] public byte[] Content { get; set; }
[Required] public string UpdateSource { get; set; }
public string[] PersonNumbers { get; set; }
public string[] OrganizationNumbers { get; set; }
public string AccountNumber { get; set; }
public Dictionary<string, string> Attributes { get; set; }
}
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace LCU.Library.Internal.DocumentModels.Requests;
public class UpdateDocumentScanStatusRequest
{
[Required] public List<Guid> DocumentBlobIds { get; set; }
[Required] public bool ScanStatus { get; set; }
}
@@ -0,0 +1,33 @@
using LCU.Library.Internal.DocumentModels.Requests;
using System;
using LCU.Library.Internal.DocumentModels.Converter;
namespace LCU.Library.Internal.DocumentModels.Responses;
[JsonKnownTypes(typeof(DocumentFieldAuditResponse), typeof(DocumentActionAuditResponse))]
[System.Text.Json.Serialization.JsonConverter(typeof(SystemPolymorphicJsonConverter<DocumentAuditResponse>))]
[Newtonsoft.Json.JsonConverter(typeof(NewtonsoftPolymorphicJsonConverter<DocumentAuditResponse>))]
public abstract class DocumentAuditResponse
{
public Guid DocumentId { get; set; }
public string Source { get; set; }
public DateTime Date { get; set; }
public string UserId { get; set; }
}
public class DocumentFieldAuditResponse : DocumentAuditResponse
{
public string Field { get; set; }
[Newtonsoft.Json.JsonConverter(typeof(DynamicObjectJsonConverter))]
public dynamic PreviousValue { get; set; }
[Newtonsoft.Json.JsonConverter(typeof(DynamicObjectJsonConverter))]
public dynamic CurrentValue { get; set; }
}
public class DocumentActionAuditResponse : DocumentAuditResponse
{
public DocumentAction Action { get; set; }
public string ActionDescription { get; set; }
}
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Text.Json.Serialization;
using LCU.Library.Internal.DocumentModels.Converter;
namespace LCU.Library.Internal.DocumentModels.Responses;
public class DocumentInformationResponse
{
public Guid DocumentId { get; set; }
public Guid? DocumentBlobId { get; set; }
public Guid? TraceId { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public string Source { get; set; }
public string DataSource { get; set; }
[JsonConverter(typeof(BigIntegerConverter))]
public BigInteger FileSize { get; set; }
public bool? ScanStatus { get; set; }
public DateTime UploadDate { get; set; }
public DateTime? LastModifiedDate { get; set; }
public DateTime CreatedDate { get; set; }
public string[] PersonNumbers { get; set; }
public string[] OrganizationNumbers { get; set; }
public string AccountNumber { get; set; }
public Dictionary<string, string> Attributes { get; set; }
}
@@ -0,0 +1,7 @@
namespace LCU.Library.Internal.DocumentModels.Responses;
public class DocumentResponse
{
public byte[] Content { get; set; }
public DocumentInformationResponse DocumentInformation { get; set; }
}