Skip to content
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

Feature/473710 Common Data Integration #45

Merged
merged 32 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5631daf
First cut.
JulianYoungEviden Dec 2, 2024
f13bebf
Amended some test coverage control over some Dtos
JulianYoungEviden Dec 2, 2024
28fda31
Added some tests for some gaps.
JulianYoungEviden Dec 2, 2024
8e852b8
Merge branch 'main' into feature/473710-CommonData-Integration
JulianYoungEviden Dec 2, 2024
f222d66
Protected against empty results from CommonData, returning an empty P…
JulianYoungEviden Dec 2, 2024
e6a546f
Changed MemberId to a string for Cso Dto
JulianYoungEviden Dec 3, 2024
fc0b2ed
Added preliminary synch code
JulianYoungEviden Dec 3, 2024
ac77c6a
Added Synchronisation of Cosmos Data.
JulianYoungEviden Dec 4, 2024
232ac8d
Merge branch 'feature/synchronise-cosmos-events' into feature/473710-…
JulianYoungEviden Dec 4, 2024
8a68b36
fix build error, and tests plus refactor. WIP: Improve coverage
karthikeviden Dec 4, 2024
47b2f65
Removed erroneous Enum parse and assignment
shehzad-ismail8 Dec 4, 2024
1646810
Delete the other else statement
shehzad-ismail8 Dec 4, 2024
d3fac05
Corrected a return null error
JulianYoungEviden Dec 4, 2024
5147f50
Added SubmissionStatus assignment to submodel for Submission details
JulianYoungEviden Dec 4, 2024
04b62d8
Adjusted the way the decision date is assigned in the Submission API …
JulianYoungEviden Dec 4, 2024
132f14b
Ensured latest comments are not overwriten.
JulianYoungEviden Dec 4, 2024
ff05460
Refactored some code
JulianYoungEviden Dec 4, 2024
cca1f1c
Date-parsing scope-widening
JulianYoungEviden Dec 4, 2024
fb5a6a3
Merge branch 'main' into feature/473710-CommonData-Integration
JulianYoungEviden Dec 4, 2024
22f1993
Added unit tests for commonDataservice
Dec 5, 2024
c3e315e
[feature/473710-CommonData-Integration: Added unit tests for GetDelta…
shehzad-ismail8 Dec 5, 2024
82bea98
Added unit tests for HandleGetOrganisationRegistrationSubmissionDetails
Dec 5, 2024
7a6bba3
Added unit tests for HandleGetRegistrationSubmissionList
Dec 5, 2024
5643524
Added more unit tests
Dec 5, 2024
2967caf
Added units tests for the Synchronisation code and other new elements.
JulianYoungEviden Dec 5, 2024
910b9d9
Merge branch 'main' of https://github.com/DEFRA/epr-regulator-service…
karthikeviden Dec 6, 2024
7b35242
remove throws
karthikeviden Dec 6, 2024
da09672
Amended synchronisation logic
JulianYoungEviden Dec 9, 2024
99de8c6
Corrected date parsing logic for Details Response
JulianYoungEviden Dec 9, 2024
13f89d0
small refactor - comment update
karthikeviden Dec 10, 2024
595f83d
refactor
karthikeviden Dec 10, 2024
d2efd65
Removed updated status from Cosmos merge logic
JulianYoungEviden Dec 12, 2024
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 @@ -99,15 +99,15 @@ public async Task<IActionResult> GetRegistrationSubmissionList(
return ValidationProblem();
}

var result = await organisationRegistrationSubmissionService.HandleGetRegistrationSubmissionList(filter);
var result = await organisationRegistrationSubmissionService.HandleGetRegistrationSubmissionList(filter, User.UserId());

return Ok(result);
}
catch (Exception ex)
{
logger.LogError(ex, $"Exception during {nameof(GetRegistrationSubmissionList)}");
return Problem($"Exception occured processing {nameof(GetRegistrationSubmissionList)}",
HttpContext.Request.Path,
HttpContext?.Request?.Path,
StatusCodes.Status500InternalServerError);
}
}
Expand All @@ -128,9 +128,9 @@ public async Task<IActionResult> GetRegistrationSubmissionDetails([Required] Gui
}

var result =
await organisationRegistrationSubmissionService.HandleGetOrganisationRegistrationSubmissionDetails(submissionId);
await organisationRegistrationSubmissionService.HandleGetOrganisationRegistrationSubmissionDetails(submissionId, User.UserId());

if (null == result)
if (result is null)
{
return NotFound();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public async Task<IActionResult> GetRegistrationSubmissions([FromQuery] Registra
{
if (!ModelState.IsValid)
{
return ValidationProblem();
return ValidationProblem(ModelState);
}

var lastSyncResponse = await _commonDataService.GetSubmissionLastSyncTime();
Expand All @@ -195,7 +195,7 @@ public async Task<IActionResult> GetRegistrationSubmissions([FromQuery] Registra
return HandleError.HandleErrorWithStatusCode(lastSyncResponse.StatusCode);
}

var submissionEventsLastSync = lastSyncResponse.Content.ReadFromJsonAsync<SubmissionEventsLastSync>().Result;
var submissionEventsLastSync = await lastSyncResponse.Content.ReadFromJsonAsync<SubmissionEventsLastSync>();

var deltaRegistrationDecisionsResponse = await _submissionService.GetDeltaRegistrationSubmissions(submissionEventsLastSync.LastSyncTime, User.UserId());

Expand All @@ -204,7 +204,7 @@ public async Task<IActionResult> GetRegistrationSubmissions([FromQuery] Registra
return HandleError.HandleErrorWithStatusCode(deltaRegistrationDecisionsResponse.StatusCode);
}

var deltaRegistrationDecisions = deltaRegistrationDecisionsResponse.Content.ReadFromJsonAsync<RegulatorRegistrationDecision[]>().Result;
var deltaRegistrationDecisions = await deltaRegistrationDecisionsResponse.Content.ReadFromJsonAsync<RegulatorRegistrationDecision[]>();

var registrationSubmissionsRequest = new GetRegistrationSubmissionsRequest
{
Expand Down
10 changes: 6 additions & 4 deletions src/EPR.RegulatorService.Facade.API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@
},
"SubmissionsApiConfig": {
"BaseUrl": "https://devrwdwebwaX408.azurewebsites.net",
"Timeout": 30,
"Timeout": 300,
"ServiceRetryCount": 6,
"ApiVersion": 1,
"Endpoints": {
"CreateSubmissionEvent": "v{0}/submissions/{1}/events",
"GetPoMSubmissions": "v{0}/submissions/events/get-regulator-pom-decision",
"GetRegistrationSubmissions": "v{0}/submissions/events/get-regulator-registration-decision"
"GetRegistrationSubmissions": "v{0}/submissions/events/get-regulator-registration-decision",
"GetOrganisationRegistrationEvents": "v{0}/submissions/events/organisation-registration"
}
},
"CommonDataApiConfig": {
Expand All @@ -57,8 +58,9 @@
"GetSubmissionEventsLastSyncTime": "submission-events/get-last-sync-time",
"GetPoMSubmissions": "submissions/pom/summary",
"GetRegistrationSubmissions": "submissions/registrations/summary",
"GetRegistrationSubmissionDetails": "organisationRegistrationSubmissions/submission/details",
"GetOrganisationRegistrationSubmissions": "organisationRegistrationSubmissions/submission/list"
"GetRegistrationSubmissionDetails": "submissions/organisation-registration-submission",
"GetOrganisationRegistrationSubmissionsSummaries": "submissions/organisation-registrations",
"GetOrganisationRegistrationSubmissionDetails": "submissions/organisation-registration-submission"
}
},
"MessagingConfig": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ public class CommonDataServiceEndpoints

public string GetOrganisationRegistrationSubmissionDetails { get; set; } = null!;

public string GetOrganisationRegistrationSubmissions { get; set; } = null!;
public string GetOrganisationRegistrationSubmissionsSummaries { get; set; } = null!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public class SubmissionsServiceEndpoints
public string GetPoMSubmissions { get; set; } = null!;

public string GetRegistrationSubmissions { get; set; } = null!;

public string GetOrganisationRegistrationEvents { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using EPR.RegulatorService.Facade.Core.Models.Requests.RegistrationSubmissions;
using System.Web;

namespace EPR.RegulatorService.Facade.Core.Extensions;

public static class GetOrganisationRegistrationSubmissionsFilterExtensions
{
public static string GenerateQueryString(this GetOrganisationRegistrationSubmissionsCommonDataFilter source)
{
static string? convertSpaceToComma(string? input) =>
string.IsNullOrWhiteSpace(input)
? null
: string.Join(",", input.Split(' ', StringSplitOptions.RemoveEmptyEntries));

var queryParams = new Dictionary<string, string?>
{
{ "OrganisationNameCommaSeparated", convertSpaceToComma(source.OrganisationName) },
{ "OrganisationIDCommaSeparated", convertSpaceToComma(source.OrganisationReference) },
{ "RelevantYearCommaSeparated", convertSpaceToComma(source.RelevantYears) },
{ "SubmissionStatusCommaSeparated", convertSpaceToComma(source.Statuses) },
{ "OrganisationTypesCommaSeparated", convertSpaceToComma(source.OrganisationType) },
{ "ApplicationReferenceNumbers", convertSpaceToComma(source.ApplicationReferenceNumbers) },
{ "PageNumber", source.PageNumber?.ToString() },
{ "PageSize", source.PageSize?.ToString() }
};

// Filter out null or empty values and encode the parameters
var queryString = string.Join("&",
queryParams
.Where(kv => !string.IsNullOrEmpty(kv.Value))
.Select(kv => $"{HttpUtility.UrlEncode(kv.Key)}={HttpUtility.UrlEncode(kv.Value)}"));

return queryString;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ namespace EPR.RegulatorService.Facade.Core.Helpers.Filters;

using System;
using EPR.RegulatorService.Facade.Core.Models.Requests.RegistrationSubmissions;
using EPR.RegulatorService.Facade.Core.Models.Responses.OrganisationRegistrations;
using EPR.RegulatorService.Facade.Core.Models.Responses.RegistrationSubmissions;

[ExcludeFromCodeCoverage]
public static class OrganisationRegistrationSubmissionsFilters
{
public static IQueryable<RegistrationSubmissionOrganisationDetails> Filter(
this IQueryable<RegistrationSubmissionOrganisationDetails> queryable,
public static IQueryable<RegistrationSubmissionOrganisationDetailsResponse> Filter(
this IQueryable<RegistrationSubmissionOrganisationDetailsResponse> queryable,
GetOrganisationRegistrationSubmissionsFilter filters) => queryable
.FilterByOrganisationName(filters.OrganisationName)
.FilterByOrganisationRef(filters.OrganisationReference)
.FilterByApplicationRef(filters.ApplicationReferenceNumber)
.FilterByRegistrationRef(filters.RegistrationReferenceNumber)
.FilterByOrganisationType(filters.OrganisationType)
.FilterBySubmissionStatus(filters.Statuses)
.FilterByRelevantYear(filters.RelevantYears);

public static IQueryable<RegistrationSubmissionOrganisationDetails> FilterByOrganisationName(
this IQueryable<RegistrationSubmissionOrganisationDetails> queryable, string? organisationName)
public static IQueryable<RegistrationSubmissionOrganisationDetailsResponse> FilterByOrganisationName(
this IQueryable<RegistrationSubmissionOrganisationDetailsResponse> queryable, string? organisationName)
{
if (string.IsNullOrWhiteSpace(organisationName)) return queryable;
var nameParts = organisationName.Split(' ', StringSplitOptions.RemoveEmptyEntries);
Expand All @@ -37,8 +36,8 @@ where nameParts.Any(part => q.OrganisationName.Contains(part, StringComparison.O
return queryable;
}

public static IQueryable<RegistrationSubmissionOrganisationDetails> FilterByOrganisationRef(
this IQueryable<RegistrationSubmissionOrganisationDetails> queryable, string? organisationRef)
public static IQueryable<RegistrationSubmissionOrganisationDetailsResponse> FilterByOrganisationRef(
this IQueryable<RegistrationSubmissionOrganisationDetailsResponse> queryable, string? organisationRef)
{
if (string.IsNullOrWhiteSpace(organisationRef)) return queryable;
var nameParts = organisationRef.Split(' ', StringSplitOptions.RemoveEmptyEntries);
Expand All @@ -48,8 +47,8 @@ where nameParts.Any(part => q.OrganisationReference.Contains(part, StringCompari
return queryable;
}

public static IQueryable<RegistrationSubmissionOrganisationDetails> FilterByApplicationRef(
this IQueryable<RegistrationSubmissionOrganisationDetails> queryable, string? applicationRef)
public static IQueryable<RegistrationSubmissionOrganisationDetailsResponse> FilterByApplicationRef(
this IQueryable<RegistrationSubmissionOrganisationDetailsResponse> queryable, string? applicationRef)
{
if (string.IsNullOrWhiteSpace(applicationRef)) return queryable;
var nameParts = applicationRef.Split(' ', StringSplitOptions.RemoveEmptyEntries);
Expand All @@ -59,8 +58,8 @@ where nameParts.Any(part => q.ApplicationReferenceNumber.Contains(part, StringCo
return queryable;
}

public static IQueryable<RegistrationSubmissionOrganisationDetails> FilterByRegistrationRef(
this IQueryable<RegistrationSubmissionOrganisationDetails> queryable, string? registrationRef)
public static IQueryable<RegistrationSubmissionOrganisationDetailsResponse> FilterByRegistrationRef(
this IQueryable<RegistrationSubmissionOrganisationDetailsResponse> queryable, string? registrationRef)
{
if (string.IsNullOrWhiteSpace(registrationRef)) return queryable;
var nameParts = registrationRef.Split(' ', StringSplitOptions.RemoveEmptyEntries);
Expand All @@ -70,8 +69,8 @@ where nameParts.Any(part => q.RegistrationReferenceNumber.Contains(part, StringC
return queryable;
}

public static IQueryable<RegistrationSubmissionOrganisationDetails> FilterByOrganisationType(
this IQueryable<RegistrationSubmissionOrganisationDetails> queryable, string? organisationType)
public static IQueryable<RegistrationSubmissionOrganisationDetailsResponse> FilterByOrganisationType(
this IQueryable<RegistrationSubmissionOrganisationDetailsResponse> queryable, string? organisationType)
{
if (string.IsNullOrWhiteSpace(organisationType) || organisationType == "none") return queryable;
queryable = from q in queryable
Expand All @@ -81,8 +80,8 @@ where organisationType.Contains(q.OrganisationType.ToString())
return queryable;
}

public static IQueryable<RegistrationSubmissionOrganisationDetails> FilterBySubmissionStatus(
this IQueryable<RegistrationSubmissionOrganisationDetails> queryable, string? submissionStatus)
public static IQueryable<RegistrationSubmissionOrganisationDetailsResponse> FilterBySubmissionStatus(
this IQueryable<RegistrationSubmissionOrganisationDetailsResponse> queryable, string? submissionStatus)
{
if (string.IsNullOrWhiteSpace(submissionStatus) || submissionStatus == "none") return queryable;
queryable = from q in queryable
Expand All @@ -92,12 +91,12 @@ where submissionStatus.Contains(q.SubmissionStatus.ToString())
return queryable;
}

public static IQueryable<RegistrationSubmissionOrganisationDetails> FilterByRelevantYear(
this IQueryable<RegistrationSubmissionOrganisationDetails> queryable, string? relevantYear)
public static IQueryable<RegistrationSubmissionOrganisationDetailsResponse> FilterByRelevantYear(
this IQueryable<RegistrationSubmissionOrganisationDetailsResponse> queryable, string? relevantYear)
{
if (string.IsNullOrWhiteSpace(relevantYear)) return queryable;
queryable = from q in queryable
where relevantYear.Contains(q.RegistrationYear)
where relevantYear.Contains(q.RelevantYear.ToString())
select q;

return queryable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace EPR.RegulatorService.Facade.Core.Helpers
public static class LocalPaginationHelper
{
public static Tuple<int, List<OrganisationRegistrationSubmissionSummaryResponse>> FilterAndOrder(
List<RegistrationSubmissionOrganisationDetails> data,
List<RegistrationSubmissionOrganisationDetailsResponse> data,
GetOrganisationRegistrationSubmissionsFilter filter)
{
var rawItems = data.AsQueryable();
Expand All @@ -30,7 +30,7 @@ public static Tuple<int, List<OrganisationRegistrationSubmissionSummaryResponse>
.ThenBy(x => x.SubmissionStatus == RegistrationSubmissionStatus.Granted)
.ThenBy(x => x.SubmissionStatus == RegistrationSubmissionStatus.Queried)
.ThenBy(x => x.SubmissionStatus == RegistrationSubmissionStatus.Pending)
.ThenBy(x => x.RegistrationDateTime)
.ThenBy(x => x.SubmissionDate)
.Skip((filter.PageNumber.Value - 1) * filter.PageSize.Value)
.Take(filter.PageSize.Value)
.Select(x => (OrganisationRegistrationSubmissionSummaryResponse)x)
Expand All @@ -45,18 +45,18 @@ public static PaginatedResponse<T> Paginate<T>(List<T>? items, int currentPage,

if (items.Count == 0)
return new PaginatedResponse<T>
{ Items = [], CurrentPage = currentPage, PageSize = pageSize, TotalItems = 0 };
{ items = [], currentPage = currentPage, pageSize = pageSize, totalItems = 0 };
if (currentPage > (int)Math.Ceiling(totalItems / (double)pageSize))
{
currentPage = (int)Math.Ceiling(totalItems / (double)pageSize);
}

return new PaginatedResponse<T>
{
Items = items,
CurrentPage = currentPage,
TotalItems = totalItems,
PageSize = pageSize
items = items,
currentPage = currentPage,
totalItems = totalItems,
pageSize = pageSize
};
}
}
Expand Down
Loading