Skip to content
19 changes: 13 additions & 6 deletions Bulldozer.CSV/CSVComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ protected void LoadGroupAttributeDict( RockContext lookupContext = null )
lookupContext = new RockContext();
}
var groupAttributes = new AttributeService( lookupContext ).Queryable().AsNoTracking().Where( a => a.EntityTypeId == GroupEntityTypeId ).ToList();
this.GroupAttributeDict = groupAttributes.ToDictionary( k => $"{k.Key}_{k.EntityTypeQualifierValue}", v => v, StringComparer.OrdinalIgnoreCase );
this.GroupAttributeDict = groupAttributes.ToDictionary( k => string.Format( "{0}_{1}_{2}", k.Key, k.EntityTypeQualifierValue == "10" ? "Family" : "Group", k.EntityTypeQualifierValue ), v => v, StringComparer.OrdinalIgnoreCase );
Comment thread
guymaness2 marked this conversation as resolved.
Outdated
}

/// <summary>
Expand Down Expand Up @@ -2876,23 +2876,29 @@ private string AddAttributes()

if ( this.GroupAttributeCsvList.Count > 0 )
{
if ( this.GroupTypeDict == null )
if ( this.GroupTypeDict == null )
Comment thread
guymaness2 marked this conversation as resolved.
Outdated
{
LoadGroupTypeDict();
}
newGroupAttributes = this.GroupAttributeCsvList.Where( a => !GroupAttributeDict.Values.Any( ad => ad.Key.Equals( a.Key, StringComparison.OrdinalIgnoreCase ) ) ).ToList();
foreach ( var groupAttribute in newGroupAttributes )
var newGroupAttributesQuery = this.GroupAttributeCsvList.Where( a => !GroupAttributeDict.Keys.Any( k => k.Equals( a.Key + "_" + this.GroupTypeDict.GetValueOrNull( string.Format( "{0}^{1}", ImportInstanceFKPrefix, a.GroupTypeId ) )?.Id ) ) );
Comment thread
nateh777 marked this conversation as resolved.
foreach ( var groupAttribute in newGroupAttributesQuery )
{
groupAttribute.AttributeEntityTypeEnum = AttributeEntityType.Group;
}
newGroupAttributes = newGroupAttributesQuery
.GroupBy( a => new { a.AttributeEntityTypeEnum, a.Key, a.GroupTypeId } )
.Select( grp => grp.First() )
.ToList();
}

var newAttributes = newPersonAttributes
.Concat( newBusinessAttributes )
.Concat( newFamilyAttributes )
.Concat( newGroupAttributes )
.GroupBy( a => new { a.AttributeEntityTypeEnum, a.Key } )
.Select( grp => grp.First() );
.Select( grp => grp.First() )
.ToList();

newAttributes.AddRange( newGroupAttributes );

ReportProgress( 0, string.Format( "Creating {0} new Person, Family, or Group Attributes...", newAttributes.Count() ) );
var invalidDefinedTypeAttributes = new List<string>();
Expand Down Expand Up @@ -2940,6 +2946,7 @@ private string AddAttributes()
newAttribute.EntityTypeId = GroupEntityTypeId;
newAttribute.EntityTypeQualifierColumn = "GroupTypeId";
newAttribute.EntityTypeQualifierValue = groupTypeId.Value.ToString();
newAttribute.ForeignKey = newAttribute.ForeignKey + $"_{groupTypeId}";
}
}

Expand Down
2 changes: 1 addition & 1 deletion Bulldozer.CSV/Maps/Group.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ private int ImportGroupAttributeValues( List<GroupAttributeValueCsv> groupAttrib
continue;
}

var attribute = this.GroupAttributeDict.GetValueOrNull( $"{attributeValueCsv.AttributeKey}_{group.GroupTypeId}" );
var attribute = this.GroupAttributeDict.GetValueOrNull( $"{attributeValueCsv.AttributeKey}_Group_{group.GroupTypeId}" );

if ( attribute == null )
{
Expand Down