Commit Graph

123 Commits

Author SHA1 Message Date
Joseph Doherty 6074424524 refactor(data-access): update ISearchQueryBuilder to use SearchId only
- Change interface methods to accept int searchId instead of SearchModel
- Update SqlKataSearchQueryBuilder to generate SQL using extraction functions
- SQL now calls dbo.fn_GetSearchWorkOrders(@SearchId) etc instead of TVPs
- Update SearchProcessor to pass model.Id to query builder
- Update tests for new method signatures
2026-01-06 14:08:47 -05:00
Joseph Doherty 7508001be1 refactor(datasync): remove old ETL DI registrations 2026-01-06 14:07:28 -05:00
Joseph Doherty 981c410cb3 feat(datasync): wire TableSyncOperation to use EtlPipelineFactory
Replace the old sync logic (fetchers, merge configurations, bulk merge
helper, post processors) with the new ETL pipeline factory.

Changes:
- Inject IEtlPipelineFactory instead of old dependencies
- Remove IServiceProvider, IDbConnectionFactory, IBulkMergeHelper,
  IMergeConfigurationRegistry dependencies
- Simplify ExecuteSyncCoreAsync to build and execute pipeline
- Keep DataUpdateRepository calls for tracking sync timestamps
- Determine SyncMode from UpdateType (Mass vs Incremental)
2026-01-06 14:05:56 -05:00
Joseph Doherty 01da261d6c docs: add MessagePack cache conversion design plan
Design for converting CACHED_DB_FILES from zstd-compressed JSON
to zstd-compressed MessagePack for faster deserialization and
smaller file sizes.
2026-01-06 14:03:47 -05:00
Joseph Doherty 7b3592df96 feat(datasync): register EtlPipelineFactory in DI 2026-01-06 14:03:31 -05:00
Joseph Doherty e75cd70d94 fix(datasync): correct MisData postScript and query filtering
- Replace placeholder postScript with actual MIS data post-processing:
  1. Sets ObsoleteDate based on BackLevel records
  2. Sets ObsoleteDate for remaining NULL cases
  3. Rebuilds PK_MisData index

- Add massQuery support to SourceConfig for mode-specific queries
- MisData mass sync now uses query without date filter (like legacy)
- EtlPipelineFactory selects massQuery when in mass mode if available
- Remove unnecessary minDtOffset from MisData mass mode config
2026-01-06 14:01:26 -05:00
Joseph Doherty 4298fb8147 feat(datasync): add pipelines.json config for all sync tables
Configure ETL pipelines for all 9 sync tables:
- WorkOrder_Curr, Lot, LotUsage_Curr (JDE)
- Item, WorkCenter, ProfitCenter (JDE)
- JdeUser, Branch (JDE)
- MisData (CMS) with postScript for ProcessedFlag update

Each pipeline includes:
- Source query with JDE Julian date/time parameters
- Sync modes for mass (365 day lookback, prePurge, reIndex)
  and incremental (7 day lookback) operations
- Destination table with match columns and updateWhen conditions
2026-01-06 13:53:30 -05:00
Joseph Doherty 832911c5f2 test(db): add validation stored procedure tests 2026-01-06 13:48:16 -05:00
Joseph Doherty 795c15df56 feat(datasync): add EtlPipelineFactory with JSON config support
- Implement IEtlPipelineFactory with ForTable() method returning a builder
- Load pipeline config from JSON file path (from PipelineOptions)
- Parse config using System.Text.Json with PropertyNameCaseInsensitive
- Builder supports WithMode() and WithMinimumDate() fluent methods
- Create DbQuerySource for source with ParameterFormatConverter for JDE dates
- Create DbBulkMergeDestination or DbBulkImportDestination based on sync mode
- Mass mode defaults to bulkImport, incremental defaults to bulkMerge
- Support destination override in sync mode config
- Execute pre/post scripts from config (prePurge, reIndex, custom scripts)
- Validate config: require mass and incremental modes, reject runtime params
- Add comprehensive tests for factory, builder, and config validation
2026-01-06 13:45:36 -05:00
Joseph Doherty afb6ad4f09 test(db): add complex table extraction function tests 2026-01-06 13:44:32 -05:00
Joseph Doherty e0d0ffa8fc test(db): add simple table extraction function tests
Add comprehensive tests for the 5 simple table extraction functions:
- fn_GetSearchWorkOrders
- fn_GetSearchItemNumbers
- fn_GetSearchProfitCenters
- fn_GetSearchWorkCenters
- fn_GetSearchOperatorIDs

Each function tested for:
- Valid array returns all values
- Empty array returns empty
- Missing property returns empty
- Search not found returns empty
- NULL criteria returns empty
- Invalid JSON returns empty
- Bad type values (nulls) filtered out

Additional edge case tests for large arrays and long values.
Total: 38 tests (7 per function + 2 additional edge cases).
2026-01-06 13:40:22 -05:00
Joseph Doherty 0d9e6db7f2 feat(datasync): add IEtlPipelineFactory and SyncMode contracts 2026-01-06 13:38:51 -05:00
Joseph Doherty 13ae0091dd test(db): add scalar extraction function tests
Tests all 3 scalar functions:
- fn_GetSearchMinimumDt
- fn_GetSearchMaximumDt
- fn_GetSearchExtractMisData

Test cases cover:
- Valid JSON extraction
- Missing property returns NULL
- Search not found returns NULL
- NULL criteria returns NULL
- Invalid JSON returns NULL

Uses DatabaseTestBase infrastructure with FluentAssertions and Dapper.
2026-01-06 13:36:12 -05:00
Joseph Doherty 8af4f9915f feat(datasync): extend DbBulkMergeDestination with excludeFromUpdate and updateCondition 2026-01-06 13:35:25 -05:00
Joseph Doherty 61f927bd0e feat(tests): add database test infrastructure
Add DatabaseTestBase.cs with xUnit Collection for test isolation:
- DatabaseTestCollection disables parallel execution
- DatabaseTestFixture verifies database connectivity
- DatabaseTestBase provides connection and cleanup helpers
- InsertTestSearchAsync for creating test data with SearchCriteria
- InsertTestSearchWithRawCriteriaAsync for testing invalid JSON scenarios

Also adds required packages: Dapper, FluentAssertions, Microsoft.Data.SqlClient
2026-01-06 13:30:34 -05:00
Joseph Doherty eb85ab6f34 feat(datasync): add generic DbQuerySource for JDE/CMS/LotFinder
Extend DbQuerySource to support multiple connection types:
- Add connectionType parameter ("jde", "cms", "lotfinder")
- Use appropriate IDbConnectionFactory method for each type
- Support Dictionary<string, object> parameters
- Use DbConnection/DbCommand for cross-database compatibility
2026-01-06 13:30:00 -05:00
Joseph Doherty 1f7fd9f0f2 feat(datasync): add ParameterFormatConverter with JDE date/time support 2026-01-06 13:25:15 -05:00
Joseph Doherty 5f8b4422b3 chore: remove obsolete Table Type scripts (033-039) 2026-01-06 13:24:38 -05:00
Joseph Doherty 2fd1cb1fe7 feat(db): add validation stored procedure with THROW errors 2026-01-06 13:20:42 -05:00
Joseph Doherty e875244c8f feat(datasync): add pipeline configuration models 2026-01-06 13:20:35 -05:00
Joseph Doherty 28d2fd30c9 feat(db): add inline TVFs for complex object extraction from SearchCriteria 2026-01-06 13:17:23 -05:00
Joseph Doherty 250323f8b0 feat(db): add inline TVFs for simple array extraction from SearchCriteria 2026-01-06 13:14:18 -05:00
Joseph Doherty 5ee348dc98 feat(db): add scalar extraction functions for SearchCriteria JSON 2026-01-06 13:11:11 -05:00
Joseph Doherty 397b339c86 docs: update plans based on Codex review
Codex review findings applied:
- Use CTE pattern to pre-filter valid JSON before OPENJSON
- Use OPENJSON...WITH for type-safe extraction (avoids double TRY_CONVERT)
- Keep script gaps instead of renumbering (prevents migration drift)
- Add xUnit Collection for test isolation (prevents parallel execution issues)
2026-01-06 13:09:10 -05:00
Joseph Doherty f2eb3d2fe1 docs: update design with inline TVFs based on Codex review
Key changes from Codex feedback:
- THROW cannot be used in UDFs (SQL Server restriction)
- Multi-statement TVFs have poor performance (no stats)
- Changed to inline TVFs for extraction (optimal performance)
- Added validation stored procedure for strict error handling
- Use TRY_CONVERT for safe type conversion
- Use OPENJSON...WITH for complex object extraction
2026-01-06 13:01:25 -05:00
Joseph Doherty 4d0b5a7941 docs: add search criteria SQL extraction functions design 2026-01-06 12:56:50 -05:00
Joseph Doherty 3d63f8f2fc docs: fix ApiResult property names in test implementation plan
- Replace IsApiError with IsError
- Replace ApiError. with Error.
- Replace ValidationError.Errors with ValidationError.FieldErrors

These match the actual ApiResult<T> implementation. The tests
themselves were already correct - subagents adapted during implementation.
2026-01-06 11:54:31 -05:00
Joseph Doherty bff947d1e8 test: add AuthApiClientIntegrationTests
Add 5 integration tests for AuthApiClient:
- GetPublicKeyAsync_ReturnsValidPublicKey
- LoginAsync_WithValidCredentials_ReturnsSuccess
- GetCurrentUserAsync_AfterLogin_ReturnsUserInfo
- GetCurrentUserAsync_WithoutAuth_ReturnsUnauthorized
- LogoutAsync_AfterLogin_InvalidatesSession

Tests use RSA encryption pattern for login credentials and
verify auth cookie behavior across requests.
2026-01-06 11:39:09 -05:00
Joseph Doherty f7e683703d test: add SearchApiClientIntegrationTests for search endpoint validation
Add integration tests for SearchApiClient covering:
- GetUserSearchesAsync with authentication returns success
- GetUserSearchesAsync without authentication returns unauthorized
- GetSearchAsync with non-existent ID returns not found
2026-01-06 11:37:43 -05:00
Joseph Doherty 54de0ce1c3 test: add LookupApiClientIntegrationTests for lookup endpoint validation
Add 4 integration tests for LookupApiClient that verify lookup endpoints
work correctly through the actual HTTP pipeline without authentication.
2026-01-06 11:37:36 -05:00
Joseph Doherty 3ed2d7324d test: add ClientIntegrationTestBase with shared auth HttpClient 2026-01-06 11:36:13 -05:00
Joseph Doherty 7e5ac56525 build: add Client project reference to integration tests
Add JdeScoping.Client project reference to Api.IntegrationTests
to enable testing API client classes against the real API.
2026-01-06 11:34:23 -05:00
Joseph Doherty 6cb852c164 test: add FileApiClientTests with route, success, and error tests
Add comprehensive unit tests for FileApiClient covering:
- Route verification tests for all 4 download endpoints (POST method)
- Route verification tests for 2 upload endpoints (POST method)
- Success tests for downloads returning byte arrays
- Success tests verifying existing data can be passed to downloads
- Success tests for uploads returning IReadOnlyList<T>
- Multipart content-type and filename verification test
- Error tests (404 for download, 400 validation error for upload)
2026-01-06 11:33:31 -05:00
Joseph Doherty 55bfdb3532 test: add AuthApiClientTests with route and success tests
Add unit tests for AuthApiClient covering:
- Route verification tests for GetPublicKey, Login, Logout, GetCurrentUser
- Success tests for all 4 methods
- Proper handling of 204 NoContent for Logout (returns Unit)
2026-01-06 11:31:49 -05:00
Joseph Doherty d06d5f27e2 test: add LookupApiClientTests with route and encoding tests
- Route verification tests for all 4 methods (FindItems, FindProfitCenters,
  FindWorkCenters, FindOperators)
- Query string encoding tests verifying special characters (&, =) and spaces
  are properly URL-encoded
- Success tests for all lookup methods verifying deserialization
- Representative error test for 500 status code
2026-01-06 11:29:46 -05:00
Joseph Doherty 76ce35458c test: add SearchApiClientTests with route and success/error tests
Add comprehensive unit tests for SearchApiClient covering:
- Route verification tests for all 6 methods (GetUserSearches, GetQueuedSearches,
  GetSearch, CopySearch, CreateSearch, GetResults)
- Success tests verifying deserialization for all methods
- Representative error tests (404 for GetSearch, 401 for GetUserSearches)

Uses MockHttpMessageHandler to verify correct API routes are called
and ApiResult<T> pattern maps responses correctly.
2026-01-06 11:27:33 -05:00
Joseph Doherty 299099f716 test: add POST and bytes tests to ApiClientBaseTests
Added 11 new tests covering:
- POST method tests (200 success, 401 unauthorized, no-body variant)
- Bytes tests (GET 200, GET 404, POST 200)
- Non-GET status code tests (POST 400 validation, bytes 500, multipart 401/200)

All 23 ApiClientBaseTests now pass.
2026-01-06 11:25:49 -05:00
Joseph Doherty c626ffbd69 test: add edge case tests to ApiClientBaseTests
Add 7 edge case tests for ApiClientBase:
- GetAsync_Returns200_EmptyBody_MapsToApiError
- GetAsync_Returns200_InvalidJson_MapsToApiError
- GetAsync_Returns204_ForUnitType_MapsToSuccess
- GetAsync_Returns204_ForNonUnitType_MapsToApiError
- GetAsync_NetworkException_MapsToApiError
- GetAsync_Timeout_MapsToApiError
- GetAsync_Returns400_WithoutValidationFormat_MapsToApiError

Also fix bug in ApiClientBase where 204 NoContent for Unit type
failed due to incorrect type casting. The implicit conversion from
Unit to ApiResult<Unit> must be applied before the runtime cast.
2026-01-06 11:23:54 -05:00
Joseph Doherty 6af5a4f9d6 test: add all 6 status code mapping tests to ApiClientBaseTests
- Add GetAsync_Returns404_MapsToNotFound test
- Add GetAsync_Returns400_WithValidationErrors_MapsToValidationError test
- Add GetAsync_Returns401_MapsToUnauthorized test
- Add GetAsync_Returns403_MapsToForbidden test
- Add GetAsync_Returns500_MapsToApiError test
- Add FrameworkReference to Microsoft.AspNetCore.App for ValidationProblemDetails
2026-01-06 11:20:43 -05:00
Joseph Doherty e75ebe1ffb test: add ApiClientBaseTests with 200 OK mapping test 2026-01-06 11:17:19 -05:00
Joseph Doherty 626b7a63f2 test: add TestableApiClient helper for ApiClientBase unit tests 2026-01-06 11:15:10 -05:00
Joseph Doherty a8f79c26b2 refactor: add ApiRoutes import to FileControllerIntegrationTests
Added using statement for JdeScoping.Core.ApiContracts. The existing
routes (/api/file/...) are left unchanged as they test legacy download
by cache key endpoints which differ from the new FileIO routes.
2026-01-06 11:13:55 -05:00
Joseph Doherty 13976dea3b refactor: use ApiRoutes constants in AuthenticationTests
Replace hardcoded route strings with ApiRoutes.* constants:
- ApiRoutes.Auth.PublicKey, Login, Logout, Me
- ApiRoutes.Search.Base
- ApiRoutes.Lookup.Items, ProfitCenters, WorkCenters, Operators
2026-01-06 11:12:17 -05:00
Joseph Doherty 6bd6138b2a chore(client): add Extensions namespace to global imports
Add @using JdeScoping.Client.Extensions to _Imports.razor so that
extension methods (like ViewModelMappingExtensions) are available
globally in Razor components without explicit using statements.
2026-01-06 10:39:44 -05:00
Joseph Doherty 4e1cd2c221 chore(client): delete old service files replaced by API clients
Delete old service interfaces and implementations that have been
replaced by the new typed API clients:
- ISearchService/SearchService -> ISearchApiClient/SearchApiClient
- ILookupService/LookupService -> ILookupApiClient/LookupApiClient
- IFileService/FileService -> IFileApiClient/FileApiClient

Also remove unused IFileService injection from SearchEdit.razor
(download functionality now uses SearchApi.GetResultsAsync).
2026-01-06 10:38:41 -05:00
Joseph Doherty 6701da137d chore(client): remove old service registrations
Remove ISearchService, ILookupService, and IFileService registrations
from Program.cs as these are now replaced by the typed API clients
(ISearchApiClient, ILookupApiClient, IFileApiClient).
2026-01-06 10:37:15 -05:00
Joseph Doherty 828034d0e2 feat(client): migrate PartOperationFilterPanel to API clients 2026-01-06 10:35:33 -05:00
Joseph Doherty 251e2f910f feat(client): migrate ComponentLotFilterPanel to API clients 2026-01-06 10:34:33 -05:00
Joseph Doherty ead947bf57 feat(client): migrate WorkOrderFilterPanel to API clients 2026-01-06 10:33:36 -05:00
Joseph Doherty 8e05afb34f feat(client): migrate OperatorFilterPanel to API clients 2026-01-06 10:32:54 -05:00