From 75cf0dcd5ae989a241bd9c43f09517402e2d2e40 Mon Sep 17 00:00:00 2001 From: David Turner Date: Wed, 29 Dec 2021 18:06:40 +0000 Subject: [PATCH 1/5] PCO: Added check for processing of same person (can happen if records are updated in PCO while export is running) --- Slingshot.PCO/Utilities/PCOApi/PCOApi.Individuals.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Slingshot.PCO/Utilities/PCOApi/PCOApi.Individuals.cs b/Slingshot.PCO/Utilities/PCOApi/PCOApi.Individuals.cs index 65d6b19..c172948 100644 --- a/Slingshot.PCO/Utilities/PCOApi/PCOApi.Individuals.cs +++ b/Slingshot.PCO/Utilities/PCOApi/PCOApi.Individuals.cs @@ -64,8 +64,16 @@ public static void ExportIndividuals( DateTime modifiedSince, int peoplePerPage var headOfHouseholdMap = GetHeadOfHouseholdMap( PCOPeople ); var personAttributes = WritePersonAttributes(); + var personIds = new List(); + foreach ( var person in PCOPeople ) { + if ( personIds.Contains(person.Id)) + { + continue; + } + personIds.Add(person.Id); + PersonDTO headOfHouse = person; // Default headOfHouse to person, in case they are not assigned to a household in PCO. if( person.Household != null && headOfHouseholdMap.ContainsKey( person.Household.Id ) ) { @@ -102,6 +110,7 @@ public static void ExportIndividuals( DateTime modifiedSince, int peoplePerPage } } } + // save notes. if ( PCONotes != null ) { From 7ca1ac8e8f98fbb749779f8619aeb48fed4e9a83 Mon Sep 17 00:00:00 2001 From: David Turner Date: Wed, 29 Dec 2021 18:07:31 +0000 Subject: [PATCH 2/5] PCO: Updates so additional email addresses are saved as person search values --- .../Utilities/Translators/PCOImportPerson.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Slingshot.PCO/Utilities/Translators/PCOImportPerson.cs b/Slingshot.PCO/Utilities/Translators/PCOImportPerson.cs index f816653..7a06df8 100755 --- a/Slingshot.PCO/Utilities/Translators/PCOImportPerson.cs +++ b/Slingshot.PCO/Utilities/Translators/PCOImportPerson.cs @@ -41,6 +41,7 @@ public static Person Translate( PersonDTO inputPerson, List FamilyRole = ( inputPerson.Child == true ) ? FamilyRole.Child : FamilyRole.Adult, InactiveReason = inputPerson.InactiveReason, Campus = headOfHouse.GetCampus(), + PersonSearchKeys = inputPerson.GetSearchKeys(), Attributes = inputPerson.GetAttributes( personAttributes, backgroundCheckPerson ), Note = string.Join( ",", inputPerson.GetNotes() ) }; @@ -129,6 +130,26 @@ private static string GetEmail( this PersonDTO inputPerson ) return emailAddress; } + private static List GetSearchKeys(this PersonDTO inputPerson) + { + var primaryEmail = GetEmail( inputPerson ); + + var searchKeys = new List(); + foreach (var email in inputPerson.ContactData.EmailAddresses) + { + if (email.Address != primaryEmail) + { + searchKeys.Add(new PersonSearchKey + { + PersonId = inputPerson.Id, + SearchValue = email.Address + }); + } + } + + return searchKeys; + } + private static List GetAddresses( this PersonDTO inputPerson ) { var addresses = new List(); From 8df1906d8fa4ec8d0d969b37c6971cc6def92f4a Mon Sep 17 00:00:00 2001 From: David Turner Date: Fri, 17 Jun 2022 11:52:15 -0500 Subject: [PATCH 3/5] Update to include archived (inactive) groups --- Slingshot.PCO/Utilities/PCOApi/PCOApi.Groups.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Slingshot.PCO/Utilities/PCOApi/PCOApi.Groups.cs b/Slingshot.PCO/Utilities/PCOApi/PCOApi.Groups.cs index bcc60b5..eea7f1a 100644 --- a/Slingshot.PCO/Utilities/PCOApi/PCOApi.Groups.cs +++ b/Slingshot.PCO/Utilities/PCOApi/PCOApi.Groups.cs @@ -295,6 +295,7 @@ private static List GetGroups( GroupTypeDTO groupType, bool isUnique ) var apiOptions = new Dictionary { + { "where[archive_status]", "include" }, { "per_page", "100" } }; From d933edd2265ae651bf22ae25cd3caa24b9cfc531 Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 3 Nov 2022 14:45:51 -0700 Subject: [PATCH 4/5] Add exception handling --- Slingshot.PCO/MainWindow.xaml.cs | 124 ++++++++++++++++++++----------- 1 file changed, 82 insertions(+), 42 deletions(-) diff --git a/Slingshot.PCO/MainWindow.xaml.cs b/Slingshot.PCO/MainWindow.xaml.cs index cf0fc3f..1ad99be 100755 --- a/Slingshot.PCO/MainWindow.xaml.cs +++ b/Slingshot.PCO/MainWindow.xaml.cs @@ -100,48 +100,65 @@ private void ExportWorker_DoWork( object sender, DoWorkEventArgs e ) // export individuals if ( !_errorHasOccurred && exportSettings.ExportIndividuals ) { - exportWorker.ReportProgress( 1, "Exporting Individuals..." ); - PCOApi.ExportIndividuals( exportSettings.ModifiedSince ); + try + { + exportWorker.ReportProgress( 1, "Exporting Individuals..." ); + PCOApi.ExportIndividuals( exportSettings.ModifiedSince ); - if ( PCOApi.ErrorMessage.IsNotNullOrWhitespace() ) + if ( PCOApi.ErrorMessage.IsNotNullOrWhitespace() ) + { + _errorHasOccurred = true; + this.Dispatcher.Invoke( () => + { + exportWorker.ReportProgress( 2, $"Error exporting individuals: {PCOApi.ErrorMessage}" ); + } ); + } + } + catch ( Exception ex ) { _errorHasOccurred = true; - this.Dispatcher.Invoke( () => - { - exportWorker.ReportProgress( 2, $"Error exporting individuals: {PCOApi.ErrorMessage}" ); - } ); + exportWorker.ReportProgress( 2, $"Exception exporting individuals: {ex.Message}" ); } } // export contributions if ( !_errorHasOccurred && exportSettings.ExportContributions ) { - exportWorker.ReportProgress( 30, "Exporting Financial Accounts..." ); - - PCOApi.ExportFinancialAccounts(); - if ( PCOApi.ErrorMessage.IsNotNullOrWhitespace() ) + try { - _errorHasOccurred = true; - exportWorker.ReportProgress( 31, $"Error exporting financial accounts: {PCOApi.ErrorMessage}" ); - } + exportWorker.ReportProgress( 30, "Exporting Financial Accounts..." ); + + PCOApi.ExportFinancialAccounts(); + if ( PCOApi.ErrorMessage.IsNotNullOrWhitespace() ) + { + _errorHasOccurred = true; + exportWorker.ReportProgress( 31, $"Error exporting financial accounts: {PCOApi.ErrorMessage}" ); + } - exportWorker.ReportProgress( 34, "Exporting Financial Batches..." ); + exportWorker.ReportProgress( 34, "Exporting Financial Batches..." ); - PCOApi.ExportFinancialBatches( exportSettings.ModifiedSince ); - if ( PCOApi.ErrorMessage.IsNotNullOrWhitespace() ) - { - _errorHasOccurred = true; - exportWorker.ReportProgress( 35, $"Error exporting financial batches: {PCOApi.ErrorMessage}" ); - } + PCOApi.ExportFinancialBatches( exportSettings.ModifiedSince ); + if ( PCOApi.ErrorMessage.IsNotNullOrWhitespace() ) + { + _errorHasOccurred = true; + exportWorker.ReportProgress( 35, $"Error exporting financial batches: {PCOApi.ErrorMessage}" ); + } - exportWorker.ReportProgress( 36, "Exporting Contribution Information..." ); + exportWorker.ReportProgress( 36, "Exporting Contribution Information..." ); - PCOApi.ExportContributions( exportSettings.ModifiedSince ); - if ( PCOApi.ErrorMessage.IsNotNullOrWhitespace() ) + PCOApi.ExportContributions( exportSettings.ModifiedSince ); + if ( PCOApi.ErrorMessage.IsNotNullOrWhitespace() ) + { + _errorHasOccurred = true; + exportWorker.ReportProgress( 37, $"Error exporting financial contributions: {PCOApi.ErrorMessage}" ); + } + } + catch ( Exception ex ) { _errorHasOccurred = true; - exportWorker.ReportProgress( 37, $"Error exporting financial batches: {PCOApi.ErrorMessage}" ); + exportWorker.ReportProgress( 2, $"Exception exporting contributions: {ex.Message}" ); } + } // export group types @@ -154,44 +171,67 @@ private void ExportWorker_DoWork( object sender, DoWorkEventArgs e ) if ( !_errorHasOccurred && exportSettings.ExportGroupTypes.Count > 0 ) { - exportWorker.ReportProgress( 54, $"Exporting Groups..." ); + try + { + exportWorker.ReportProgress( 54, $"Exporting Groups..." ); - var exportGroupTypes = ExportGroupTypes.Where( t => exportSettings.ExportGroupTypes.Contains( t.Id ) ).ToList(); - groupExportResult = PCOApi.ExportGroups( exportGroupTypes, exportSettings.ExportGroupAttendance ); + var exportGroupTypes = ExportGroupTypes.Where( t => exportSettings.ExportGroupTypes.Contains( t.Id ) ).ToList(); + groupExportResult = PCOApi.ExportGroups( exportGroupTypes, exportSettings.ExportGroupAttendance ); - if ( PCOApi.ErrorMessage.IsNotNullOrWhitespace() ) + if ( PCOApi.ErrorMessage.IsNotNullOrWhitespace() ) + { + _errorHasOccurred = true; + exportWorker.ReportProgress( 54, $"Error exporting groups: {PCOApi.ErrorMessage}" ); + } + } + catch ( Exception ex ) { _errorHasOccurred = true; - exportWorker.ReportProgress( 54, $"Error exporting groups: {PCOApi.ErrorMessage}" ); + exportWorker.ReportProgress( 2, $"Exception exporting groups: {ex.Message}" ); } } if ( !_errorHasOccurred && exportSettings.ExportServices ) { - exportWorker.ReportProgress( 74, $"Exporting Services/Teams..." ); - - if ( groupExportResult.MaxGroupId <= Utilities.Translators.PCOImportTeam.TEAM_ID_BASE - && groupExportResult.MaxGroupTypeId <= Utilities.Translators.PCOImportServiceType.SERVICE_TYPE_ID_BASE ) + try { - PCOApi.ExportServices(); - if ( PCOApi.ErrorMessage.IsNotNullOrWhitespace() ) + exportWorker.ReportProgress( 74, $"Exporting Services/Teams..." ); + + if ( groupExportResult.MaxGroupId <= Utilities.Translators.PCOImportTeam.TEAM_ID_BASE + && groupExportResult.MaxGroupTypeId <= Utilities.Translators.PCOImportServiceType.SERVICE_TYPE_ID_BASE ) { - _errorHasOccurred = true; - exportWorker.ReportProgress( 74, $"Error exporting services/teams: {PCOApi.ErrorMessage}" ); + PCOApi.ExportServices(); + if ( PCOApi.ErrorMessage.IsNotNullOrWhitespace() ) + { + _errorHasOccurred = true; + exportWorker.ReportProgress( 74, $"Error exporting services/teams: {PCOApi.ErrorMessage}" ); + } } } + catch ( Exception ex ) + { + _errorHasOccurred = true; + exportWorker.ReportProgress( 2, $"Exception exporting service/teams: {ex.Message}" ); + } } // export attendance if ( !_errorHasOccurred && exportSettings.ExportAttendance ) { - exportWorker.ReportProgress( 80, "Exporting Attendance..." ); + try { + exportWorker.ReportProgress( 80, "Exporting Attendance..." ); - PCOApi.ExportAttendance( exportSettings.ModifiedSince ); - if ( PCOApi.ErrorMessage.IsNotNullOrWhitespace() ) + PCOApi.ExportAttendance( exportSettings.ModifiedSince ); + if ( PCOApi.ErrorMessage.IsNotNullOrWhitespace() ) + { + _errorHasOccurred = true; + exportWorker.ReportProgress( 81, $"Error exporting attendance: {PCOApi.ErrorMessage}" ); + } + } + catch ( Exception ex ) { _errorHasOccurred = true; - exportWorker.ReportProgress( 81, $"Error exporting attendance: {PCOApi.ErrorMessage}" ); + exportWorker.ReportProgress( 2, $"Exception exporting attendance: {ex.Message}" ); } } From 64bdb1fc1618adfd875ee2017ed65320ca091f31 Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 3 Nov 2022 14:45:58 -0700 Subject: [PATCH 5/5] Add Grade --- Slingshot.PCO/Models/DTO/PersonDTO.cs | 4 ++++ Slingshot.PCO/Utilities/Translators/PCOImportPerson.cs | 1 + 2 files changed, 5 insertions(+) diff --git a/Slingshot.PCO/Models/DTO/PersonDTO.cs b/Slingshot.PCO/Models/DTO/PersonDTO.cs index f8f1122..a0a79bc 100644 --- a/Slingshot.PCO/Models/DTO/PersonDTO.cs +++ b/Slingshot.PCO/Models/DTO/PersonDTO.cs @@ -27,6 +27,8 @@ public class PersonDTO public DateTime? Anniversary { get; set; } + public int? Grade { get; set; } + public bool Services { get; set; } public string Permissions { get; set; } @@ -86,6 +88,7 @@ public PersonDTO( DataItem data, Dictionary includedItems ) Gender = data.Item.gender; Birthdate = data.Item.birthdate; Anniversary = data.Item.anniversary; + Grade = data.Item.grade; CreatedAt = data.Item.created_at; UpdatedAt = data.Item.updated_at; Member = data.Item.membership; @@ -119,6 +122,7 @@ private void SetAvatar( DataItem data ) Avatar = avatar; } + private void SetGrade( DataItem data ) private void SetContactInfo( DataItem data, Dictionary included ) { ContactData = new ContactDataDTO(); diff --git a/Slingshot.PCO/Utilities/Translators/PCOImportPerson.cs b/Slingshot.PCO/Utilities/Translators/PCOImportPerson.cs index 7a06df8..096658b 100755 --- a/Slingshot.PCO/Utilities/Translators/PCOImportPerson.cs +++ b/Slingshot.PCO/Utilities/Translators/PCOImportPerson.cs @@ -34,6 +34,7 @@ public static Person Translate( PersonDTO inputPerson, List MaritalStatus = inputPerson.GetMaritalStatus(), Birthdate = inputPerson.Birthdate, AnniversaryDate = inputPerson.Anniversary, + Grade = inputPerson.Grade?.ToString(), CreatedDateTime = inputPerson.CreatedAt, ModifiedDateTime = inputPerson.UpdatedAt, FamilyId = inputPerson.Household?.Id,