public async Task <Models.CourtList.CourtList> CourtListAsync(string agencyId, string roomCode, DateTime proceeding, string divisionCode, string fileNumber) { var proceedingDateString = proceeding.ToString("yyyy-MM-dd"); var agencyCode = await _locationService.GetLocationCodeFromId(agencyId); async Task <CourtList> CourtList() => await _filesClient.FilesCourtlistAsync(_requestAgencyIdentifierId, _requestPartId, _applicationCode, agencyId, roomCode, proceedingDateString, divisionCode, fileNumber); async Task <CourtCalendarDetailByDay> CourtCalendarDetailByDay() => await _filesClient.FilesCourtcalendardetailsbydayAsync(_requestAgencyIdentifierId, _requestPartId, _applicationCode, agencyCode, proceeding.ToString("yyyy-MM-dd HH:mm:ss.S"), roomCode); var courtCalendarDetailsTask = _cache.GetOrAdd($"CourtCalendarDetails-{agencyId}-{roomCode}-{proceedingDateString}-{fileNumber}-{_requestAgencyIdentifierId}", CourtCalendarDetailByDay); var originalCourtListTask = _cache.GetOrAddAsync($"CourtList-{agencyId}-{roomCode}-{proceedingDateString}-{fileNumber}-{_requestAgencyIdentifierId}", CourtList); //Query by courtCalendarDetails, because it returns quite a bit faster than the courtList. var courtCalendarDetails = await courtCalendarDetailsTask; if (courtCalendarDetails.ResponseCd != "0") { _logger.LogInformation("Court calendar details returned responseCd != 0"); } ValidUserHelper.CheckIfValidUser(courtCalendarDetails.ResponseMessageTxt); var civilCourtCalendarAppearances = courtCalendarDetails?.Appearance .WhereToList(app => app.CourtDivisionCd == CourtCalendarDetailAppearanceCourtDivisionCd.I); var criminalCourtCalendarAppearances = courtCalendarDetails?.Appearance .WhereToList(app => app.CourtDivisionCd == CourtCalendarDetailAppearanceCourtDivisionCd.R); var civilFileIds = civilCourtCalendarAppearances.SelectToList(ccl => ccl.PhysicalFileId); var criminalFileIds = criminalCourtCalendarAppearances.SelectToList(ccl => ccl.MdocJustinNo); if (civilFileIds.Count == 0 && criminalFileIds.Count == 0) { return(new Models.CourtList.CourtList()); } //Start file details tasks. var civilFileDetailTasks = CivilFileDetailTasks(civilFileIds); var criminalFileDetailTasks = CriminalFileDetailTasks(criminalFileIds); //Start appearances tasks. var civilAppearanceTasks = CivilAppearancesTasks(proceeding, civilFileIds); var criminalAppearanceTasks = CriminalAppearancesTasks(proceeding, criminalFileIds); //Start file content tasks. var civilFileContentTasks = CivilFileContentTasks(civilFileIds); //Await our asynchronous requests. var civilFileDetails = (await civilFileDetailTasks.WhenAll()).ToList(); var criminalFileDetails = (await criminalFileDetailTasks.WhenAll()).ToList(); var civilAppearances = (await civilAppearanceTasks.WhenAll()).ToList(); var criminalAppearances = (await criminalAppearanceTasks.WhenAll()).ToList(); var civilFileContents = (await civilFileContentTasks.WhenAll()).ToList(); var originalCourtList = await originalCourtListTask; //Note, there is test data that doesn't have a CourtList, but may have CourtCalendarDetails. //If this is the case with real data, or becomes an issue with testing, I'll have to //create a blank courtList object and overlay CourtCalendarDetails on top of it. //Some overlap happens already, but some of the fields aren't passed over (they already exist in CourtList). //PCSS for example isn't aware of CourtList, it only uses CourtCalendarDetails where as SCV uses the CourtList + CourtCalendarDetails. var courtList = _mapper.Map <Models.CourtList.CourtList>(originalCourtList); courtList.CivilCourtList = await PopulateCivilCourtListFromFileDetails(courtList.CivilCourtList, civilFileDetails); courtList.CriminalCourtList = await PopulateCriminalCourtListFromFileDetails(courtList.CriminalCourtList, criminalFileDetails); courtList.CivilCourtList = await PopulateCivilCourtListFromAppearances(courtList.CivilCourtList, civilAppearances); courtList.CriminalCourtList = await PopulateCriminalCourtListFromAppearances(courtList.CriminalCourtList, criminalAppearances); courtList.CivilCourtList = PopulateCivilCourtListFromCourtCalendarDetails(courtList.CivilCourtList, civilCourtCalendarAppearances); courtList.CriminalCourtList = PopulateCriminalCourtListFromCourtCalendarDetails(courtList.CriminalCourtList, criminalCourtCalendarAppearances); courtList.CivilCourtList = PopulateCivilCourtListFromFileContent(courtList.CivilCourtList, civilFileContents); return(courtList); }
public async Task <Models.CourtList.CourtList> CourtListAsync(string agencyId, string roomCode, DateTime proceeding, string divisionCode, string fileNumber) { var proceedingDateString = proceeding.ToString("yyyy-MM-dd"); var agencyCode = await _locationService.GetLocationCodeFromId(agencyId); async Task <CourtList> CourtList() => await _filesClient.FilesCourtlistAsync(agencyId, roomCode, proceedingDateString, divisionCode, fileNumber); async Task <CourtCalendarDetailByDay> CourtCalendarDetailByDay() => await _filesClient.FilesCourtCalendarDetailsByDayAsync(_requestAgencyIdentifierId, _requestPartId, agencyCode, proceeding.ToString("yyyy-MM-dd HH:mm:ss.S"), roomCode); var courtCalendarDetailsTask = _cache.GetOrAdd($"CivilCourtCalendarDetails-{agencyId}-{roomCode}-{proceedingDateString}-{fileNumber}", CourtCalendarDetailByDay); var originalCourtListTask = _cache.GetOrAddAsync($"CourtList-{agencyId}-{roomCode}-{proceedingDateString}-{fileNumber}", CourtList); //Query by courtCalendarDetails, because it returns quite a bit faster than the courtList. var courtCalendarDetails = await courtCalendarDetailsTask; var civilCourtCalendarAppearances = courtCalendarDetails?.Appearance .WhereToList(app => app.CourtDivisionCd == CourtCalendarDetailAppearanceCourtDivisionCd.I); var criminalCourtCalendarAppearances = courtCalendarDetails?.Appearance .WhereToList(app => app.CourtDivisionCd == CourtCalendarDetailAppearanceCourtDivisionCd.R); var civilFileIds = civilCourtCalendarAppearances.SelectToList(ccl => ccl.PhysicalFileId); var criminalFileIds = criminalCourtCalendarAppearances.SelectToList(ccl => ccl.MdocJustinNo); if (civilFileIds.Count == 0 && criminalFileIds.Count == 0) { return(new Models.CourtList.CourtList()); } //Start file details tasks. var civilFileDetailTasks = CivilFileDetailTasks(civilFileIds); var criminalFileDetailTasks = CriminalFileDetailTasks(criminalFileIds); //Start appearances tasks. var civilAppearanceTasks = CivilAppearancesTasks(proceeding, civilFileIds); var criminalAppearanceTasks = CriminalAppearancesTasks(proceeding, criminalFileIds); //Start file content tasks. var civilFileContentTasks = CivilFileContentTasks(civilFileIds); //Await our asynchronous requests. var civilFileDetails = (await civilFileDetailTasks.WhenAll()).ToList(); var criminalFileDetails = (await criminalFileDetailTasks.WhenAll()).ToList(); var civilAppearances = (await civilAppearanceTasks.WhenAll()).ToList(); var criminalAppearances = (await criminalAppearanceTasks.WhenAll()).ToList(); var civilFileContents = (await civilFileContentTasks.WhenAll()).ToList(); var originalCourtList = await originalCourtListTask; var courtList = _mapper.Map <Models.CourtList.CourtList>(originalCourtList); courtList.CivilCourtList = await PopulateCivilCourtListFromFileDetails(courtList.CivilCourtList, civilFileDetails); courtList.CriminalCourtList = await PopulateCriminalCourtListFromFileDetails(courtList.CriminalCourtList, criminalFileDetails); courtList.CivilCourtList = await PopulateCivilCourtListFromAppearances(courtList.CivilCourtList, civilAppearances); courtList.CriminalCourtList = await PopulateCriminalCourtListFromAppearances(courtList.CriminalCourtList, criminalAppearances); courtList.CivilCourtList = PopulateCivilCourtListFromCourtCalendarDetails(courtList.CivilCourtList, civilCourtCalendarAppearances); courtList.CriminalCourtList = PopulateCriminalCourtListFromCourtCalendarDetails(courtList.CriminalCourtList, criminalCourtCalendarAppearances); courtList.CivilCourtList = PopulateCivilCourtListFromFileContent(courtList.CivilCourtList, civilFileContents); return(courtList); }