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

PCO Updates from 9 Embers #80

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
124 changes: 82 additions & 42 deletions Slingshot.PCO/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}" );
}
}

Expand Down
4 changes: 4 additions & 0 deletions Slingshot.PCO/Models/DTO/PersonDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -86,6 +88,7 @@ public PersonDTO( DataItem data, Dictionary<string, DataItem> 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;
Expand Down Expand Up @@ -119,6 +122,7 @@ private void SetAvatar( DataItem data )
Avatar = avatar;
}

private void SetGrade( DataItem data )
private void SetContactInfo( DataItem data, Dictionary<string, DataItem> included )
{
ContactData = new ContactDataDTO();
Expand Down
1 change: 1 addition & 0 deletions Slingshot.PCO/Utilities/PCOApi/PCOApi.Groups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ private static List<GroupDTO> GetGroups( GroupTypeDTO groupType, bool isUnique )

var apiOptions = new Dictionary<string, string>
{
{ "where[archive_status]", "include" },
{ "per_page", "100" }
};

Expand Down
9 changes: 9 additions & 0 deletions Slingshot.PCO/Utilities/PCOApi/PCOApi.Individuals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@ public static void ExportIndividuals( DateTime modifiedSince, int peoplePerPage
var headOfHouseholdMap = GetHeadOfHouseholdMap( PCOPeople );
var personAttributes = WritePersonAttributes();

var personIds = new List<int>();

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 ) )
{
Expand Down Expand Up @@ -102,6 +110,7 @@ public static void ExportIndividuals( DateTime modifiedSince, int peoplePerPage
}
}
}

// save notes.
if ( PCONotes != null )
{
Expand Down
22 changes: 22 additions & 0 deletions Slingshot.PCO/Utilities/Translators/PCOImportPerson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ public static Person Translate( PersonDTO inputPerson, List<FieldDefinitionDTO>
MaritalStatus = inputPerson.GetMaritalStatus(),
Birthdate = inputPerson.Birthdate,
AnniversaryDate = inputPerson.Anniversary,
Grade = inputPerson.Grade?.ToString(),
CreatedDateTime = inputPerson.CreatedAt,
ModifiedDateTime = inputPerson.UpdatedAt,
FamilyId = inputPerson.Household?.Id,
FamilyName = inputPerson.Household?.Name,
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() )
};
Expand Down Expand Up @@ -129,6 +131,26 @@ private static string GetEmail( this PersonDTO inputPerson )
return emailAddress;
}

private static List<PersonSearchKey> GetSearchKeys(this PersonDTO inputPerson)
{
var primaryEmail = GetEmail( inputPerson );

var searchKeys = new List<PersonSearchKey>();
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<PersonAddress> GetAddresses( this PersonDTO inputPerson )
{
var addresses = new List<PersonAddress>();
Expand Down