/// <summary> /// Gets the shifts for a given Kronos user id. /// </summary> /// <param name="kronosUserId">A Kronos user id.</param> /// <param name="queryStartDate">The query start date.</param> /// <param name="queryEndDate">The query end date.</param> /// <returns>The schedule response.</returns> public async Task <App.KronosWfc.Models.ResponseEntities.Shifts.UpcomingShifts.Response> GetShiftsForUser(string kronosUserId, string queryStartDate, string queryEndDate) { App.KronosWfc.Models.ResponseEntities.Shifts.UpcomingShifts.Response shiftsResponse = null; this.utility.SetQuerySpan(Convert.ToBoolean(false, CultureInfo.InvariantCulture), out string shiftStartDate, out string shiftEndDate); var allRequiredConfigurations = await this.utility.GetAllConfigurationsAsync().ConfigureAwait(false); // Check whether date range are in correct format. var isCorrectDateRange = Utility.CheckDates(shiftStartDate, shiftEndDate); if (!isCorrectDateRange) { throw new Exception($"{Resource.SyncShiftsFromKronos} - Query date was invalid."); } if ((bool)allRequiredConfigurations?.IsAllSetUpExists) { var user = new List <ResponseHyperFindResult>() { new ResponseHyperFindResult { PersonNumber = kronosUserId }, }; // Get shift response for a batch of users. shiftsResponse = await this.upcomingShiftsActivity.ShowUpcomingShiftsInBatchAsync( new Uri(allRequiredConfigurations.WfmEndPoint), allRequiredConfigurations.KronosSession, queryStartDate, queryEndDate, user).ConfigureAwait(false); } return(shiftsResponse); }
/// <summary> /// Method to process the shift entities in a batch manner. /// </summary> /// <param name="configurationDetails">The configuration details.</param> /// <param name="lookUpEntriesFoundList">The lookUp entries that have been found.</param> /// <param name="shiftsNotFoundList">The shifts that have not been found.</param> /// <param name="userModelList">The users list.</param> /// <param name="userModelNotFoundList">The list of users that have not been found.</param> /// <param name="lookUpData">The look up data from the Shift Entity Mapping table.</param> /// <param name="processKronosUsersQueueInBatch">The Kronos users in the queue.</param> /// <param name="shiftsResponse">The Shifts Response from MS Graph.</param> /// <param name="monthPartitionKey">The monthwise partition.</param> /// <returns>A unit of execution.</returns> private async Task ProcessShiftEntitiesBatchAsync( IntegrationApi.SetupDetails configurationDetails, List <TeamsShiftMappingEntity> lookUpEntriesFoundList, List <Shift> shiftsNotFoundList, List <UserDetailsModel> userModelList, List <UserDetailsModel> userModelNotFoundList, List <TeamsShiftMappingEntity> lookUpData, IEnumerable <UserDetailsModel> processKronosUsersQueueInBatch, App.KronosWfc.Models.ResponseEntities.Shifts.UpcomingShifts.Response shiftsResponse, string monthPartitionKey) { this.telemetryClient.TrackTrace($"ShiftController - ProcessShiftEntitiesBatchAsync started at: {DateTime.UtcNow.ToString("O", CultureInfo.InvariantCulture)}"); var shiftNotes = string.Empty; // This foreach loop processes each user in the batch. foreach (var user in processKronosUsersQueueInBatch) { // This foreach loop will process the shift(s) that belong to each user. foreach (var kronosShift in shiftsResponse?.Schedule?.ScheduleItems?.ScheduleShift) { if (user.KronosPersonNumber == kronosShift.Employee.FirstOrDefault().PersonNumber) { this.telemetryClient.TrackTrace($"ShiftController - Processing the shifts for user: {user.KronosPersonNumber}"); var shift = this.GenerateTeamsShiftObject(user, kronosShift); shift.KronosUniqueId = this.utility.CreateUniqueId(shift, user.KronosTimeZone); this.telemetryClient.TrackTrace($"ShiftController-KronosHash: {shift.KronosUniqueId}"); userModelList.Add(user); if (lookUpData.Count == 0) { shiftsNotFoundList.Add(shift); userModelNotFoundList.Add(user); } else { var kronosUniqueIdExists = lookUpData.Where(c => c.KronosUniqueId == shift.KronosUniqueId); if (kronosUniqueIdExists.Any() && (kronosUniqueIdExists != default(List <TeamsShiftMappingEntity>))) { lookUpEntriesFoundList.Add(kronosUniqueIdExists.FirstOrDefault()); } else { shiftsNotFoundList.Add(shift); userModelNotFoundList.Add(user); } } } } } if (lookUpData.Except(lookUpEntriesFoundList).Any()) { await this.DeleteOrphanDataShiftsEntityMappingAsync(configurationDetails, lookUpEntriesFoundList, userModelList, lookUpData).ConfigureAwait(false); } await this.CreateEntryShiftsEntityMappingAsync(configurationDetails, userModelNotFoundList, shiftsNotFoundList, monthPartitionKey).ConfigureAwait(false); this.telemetryClient.TrackTrace($"ShiftController - ProcessShiftEntitiesBatchAsync ended at: {DateTime.UtcNow.ToString("O", CultureInfo.InvariantCulture)}"); }