Refactor: GetTree => GetAllBelow, GetLine => GetRootLineage

This commit is contained in:
Rick Falkvinge
2015-05-01 16:48:56 +02:00
parent 6b96e835b8
commit ed3d33064e
22 changed files with 58 additions and 58 deletions
+2 -2
View File
@@ -342,7 +342,7 @@ namespace Swarmops
writer.WriteLine("Förening,Namn (medlemsnr),kön,födelsedatum,bidragsgrund,email,telefon");
Organizations orgTree = Organization.FromIdentity(2).GetTree();
Organizations orgTree = Organization.FromIdentity(2).GetAllBelow();
foreach (Organization org in orgTree)
{
@@ -905,7 +905,7 @@ namespace Swarmops
{
// For each suborg to UP,
Organizations orgs = Organization.FromIdentity (2).GetTree();
Organizations orgs = Organization.FromIdentity (2).GetAllBelow();
foreach (Organization org in orgs)
{
+1 -1
View File
@@ -51,7 +51,7 @@ namespace Swarmops.Logic.Cache
{
List<BasicMailTemplate> tmplList = GetCachedTemplates (templateName);
Organizations orgLine = (org != null) ? org.GetLine() : new Organizations();
Organizations orgLine = (org != null) ? org.GetRootLineage() : new Organizations();
int[] lineIDs = orgLine.Identities;
List<int> idlist = new List<int> (lineIDs);
@@ -15,10 +15,10 @@ namespace Swarmops.Logic.DataObjects
#endif
public static GeographyWithPeople[] SelectSortedStatic (int orgId)
{
Organizations orgs = Organization.FromIdentity (orgId).GetTree();
Organizations orgs = Organization.FromIdentity (orgId).GetAllBelow();
List<GeographyWithPeople> resList = new List<GeographyWithPeople>();
Geographies tree = Geography.Root.GetTree();
Geographies tree = Geography.Root.GetAllBelow();
foreach (Geography geo in tree)
{
GeographyWithPeople row = new GeographyWithPeople();
@@ -29,7 +29,7 @@ namespace Swarmops.Logic.DataObjects
row.LeadContent = "";
row.SecondsContent = "";
row.OrgId = orgId;
Geographies gTree = geo.GetTree();
Geographies gTree = geo.GetAllBelow();
int[] members = SwarmDb.GetDatabaseForReading()
.GetMembersForOrganizationsAndGeographies (orgs.Identities, gTree.Identities);
}
+1 -1
View File
@@ -312,7 +312,7 @@ namespace Swarmops.Logic.DataObjects
private static int FindDefaultCountry (Org org)
{
//Find default country = Country of anchor.
Geographies line = Geography.FromIdentity (org.AnchorGeographyId).GetLine();
Geographies line = Geography.FromIdentity (org.AnchorGeographyId).GetRootLineage();
Geography[] arrLine = line.ToArray();
Array.Reverse (arrLine);
Countries countries = Countries.All;
+2 -2
View File
@@ -418,9 +418,9 @@ namespace Swarmops.Logic.Financial
return FromIdentityAggressive (accountId);
}
public FinancialAccounts GetTree()
public FinancialAccounts GetAllBelow()
{
return FinancialAccounts.GetTree (this);
return FinancialAccounts.GetAllBelow (this);
}
}
}
+4 -4
View File
@@ -116,11 +116,11 @@ namespace Swarmops.Logic.Financial
}
public static FinancialAccounts GetTree (FinancialAccount rootAccount)
public static FinancialAccounts GetAllBelow (FinancialAccount rootAccount)
{
Dictionary<int, FinancialAccounts> nodes = GetHashedAccounts (rootAccount.Organization);
return GetTree (nodes, rootAccount.Identity, 0);
return GetAllBelow (nodes, rootAccount.Identity, 0);
}
@@ -140,7 +140,7 @@ namespace Swarmops.Logic.Financial
}*/
private static FinancialAccounts GetTree (Dictionary<int, FinancialAccounts> accounts, int startNodeId,
private static FinancialAccounts GetAllBelow (Dictionary<int, FinancialAccounts> accounts, int startNodeId,
int generation)
{
FinancialAccounts result = new FinancialAccounts();
@@ -155,7 +155,7 @@ namespace Swarmops.Logic.Financial
// Add recursively
FinancialAccounts children = GetTree (accounts, account.Identity, generation + 1);
FinancialAccounts children = GetAllBelow (accounts, account.Identity, generation + 1);
if (children.Count > 0)
{
+2 -2
View File
@@ -329,7 +329,7 @@ namespace Swarmops.Logic.Security
// Org lookup will always be needed. Geo lookup may be needed for case 3.
Organizations orgStructure = this.Organization.GetTree();
Organizations orgStructure = this.Organization.GetAllBelow();
int[] orgIds = orgStructure.Identities;
foreach (int orgId in orgIds)
{
@@ -395,7 +395,7 @@ namespace Swarmops.Logic.Security
return new People(); // also return empty list
}
Geographies geoStructure = this.Position.Geography.GetTree();
Geographies geoStructure = this.Position.Geography.GetAllBelow();
int[] geoIds = geoStructure.Identities;
foreach (int geoId in geoIds)
{
+3 -3
View File
@@ -92,7 +92,7 @@ namespace Swarmops.Logic.Structure
// Build lookup
Geographies filterLine = topGeography.GetLine();
Geographies filterLine = topGeography.GetRootLineage();
Dictionary<int, bool> lineLookup = new Dictionary<int, bool>();
foreach (Geography node in filterLine)
{
@@ -135,7 +135,7 @@ namespace Swarmops.Logic.Structure
foreach (Geography currentNode in this)
{
Geographies currentLine = Geography.FromIdentity (currentNode.GeographyId).GetLine();
Geographies currentLine = Geography.FromIdentity (currentNode.GeographyId).GetRootLineage();
foreach (Geography comparedNode in this)
{
@@ -278,7 +278,7 @@ namespace Swarmops.Logic.Structure
object testObject = GuidCache.Get(cacheKey);
if (testObject == null)
{
Geographies geographies = Geography.Root.GetTree();
Geographies geographies = Geography.Root.GetAllBelow();
Tree<Geography> geoTree = Tree<Geography>.FromCollection(geographies);
GuidCache.Set(cacheKey, geoTree);
+3 -3
View File
@@ -87,13 +87,13 @@ namespace Swarmops.Logic.Structure
get { return FromIdentity (ParentIdentity); }
}
public Geographies GetTree()
public Geographies GetAllBelow()
{
return Geographies.FromArray (GeographyCache.GetGeographyTree (Identity));
// return Geographies.FromArray(SwarmDb.GetDatabaseForReading().GetGeographyTree(Identity));
}
public Geographies GetLine()
public Geographies GetRootLineage()
{
return Geographies.FromArray (GeographyCache.GetGeographyLine (Identity));
//return Geographies.FromArray(SwarmDb.GetDatabaseForReading().GetGeographyLine(Identity));
@@ -108,7 +108,7 @@ namespace Swarmops.Logic.Structure
{
// Returns true if prospectiveParent is a parent of ours.
Geographies line = GetLine();
Geographies line = GetRootLineage();
for (int index = 0; index < line.Count - 1; index++)
{
+3 -3
View File
@@ -45,7 +45,7 @@ namespace Swarmops.Logic.Structure
{
People members =
People.FromMemberships (
Memberships.ForOrganizations (Organization.FromIdentity (orgId).GetTree()));
Memberships.ForOrganizations (Organization.FromIdentity (orgId).GetAllBelow()));
foreach (Person person in members)
{
@@ -88,11 +88,11 @@ namespace Swarmops.Logic.Structure
// Step 3 - add up the totals for every intermediate node (expensive!)
Geographies allGeographies = Geography.Root.GetTree();
Geographies allGeographies = Geography.Root.GetAllBelow();
foreach (Geography geography in allGeographies)
{
Geographies localTree = geography.GetTree();
Geographies localTree = geography.GetAllBelow();
int voterCount = 0;
GeographyOrganizationDataPoint[] tempOrgData = new GeographyOrganizationDataPoint[2]; // HACK
tempOrgData[0] = new GeographyOrganizationDataPoint();
+5 -5
View File
@@ -400,7 +400,7 @@ namespace Swarmops.Logic.Structure
{
// Returns true if prospectiveParent is a parent of ours.
Organizations line = GetLine();
Organizations line = GetRootLineage();
for (int index = 0; index < line.Count - 1; index++)
{
@@ -413,14 +413,14 @@ namespace Swarmops.Logic.Structure
return false;
}
public Organizations GetLine()
public Organizations GetRootLineage()
{
return Organizations.FromArray (OrganizationCache.GetOrganizationLine (Identity));
//return Organizations.FromArray(SwarmDb.GetDatabaseForReading().GetOrganizationLine(Identity));
}
public Organizations GetTree()
public Organizations GetAllBelow()
{
return Organizations.FromArray (OrganizationCache.GetOrganizationTree (Identity));
//return Organizations.FromArray(SwarmDb.GetDatabaseForReading().GetOrganizationTree(Identity));
@@ -578,7 +578,7 @@ namespace Swarmops.Logic.Structure
if (string.IsNullOrEmpty (this.mailPrefixInherited))
{
Organizations orgLine = GetLine();
Organizations orgLine = GetRootLineage();
orgLine.Reverse();
@@ -858,7 +858,7 @@ namespace Swarmops.Logic.Structure
public Person GetTreasurer()
{
Organizations line = GetLine();
Organizations line = GetRootLineage();
BasicPersonRole[] treasurers
= SwarmDb.GetDatabaseForReading()
.GetPeopleWithRoleType (RoleType.OrganizationTreasurer, line.Identities, new int[] {});
+5 -5
View File
@@ -95,7 +95,7 @@ namespace Swarmops.Logic.Structure
foreach (Organization currentOrg in this)
{
Organizations currentLine = currentOrg.GetLine();
Organizations currentLine = currentOrg.GetRootLineage();
foreach (Organization comparedOrg in this)
{
@@ -143,7 +143,7 @@ namespace Swarmops.Logic.Structure
foreach (Organization orgMajor in this)
{
Organizations orgTree = orgMajor.GetTree();
Organizations orgTree = orgMajor.GetAllBelow();
foreach (Organization orgMinor in orgTree)
{
@@ -372,7 +372,7 @@ namespace Swarmops.Logic.Structure
}
// For each remaining organization, find the one with the longest organization line.
// This is slightly inefficient as the queries for Geography.GetLine() are repeated.
// This is slightly inefficient as the queries for Geography.GetRootLineage() are repeated.
if (table.Count == 0)
{
@@ -391,7 +391,7 @@ namespace Swarmops.Logic.Structure
{
foreach (Geography uptakeGeo in org.UptakeGeographies)
{
Geographies geoLine = Geography.FromIdentity (org.AnchorGeographyId).GetLine();
Geographies geoLine = Geography.FromIdentity (org.AnchorGeographyId).GetRootLineage();
if (geoLine.Count > maxLength && org.AutoAssignNewMembers)
{
bestFit = org;
@@ -399,7 +399,7 @@ namespace Swarmops.Logic.Structure
}
if (geoLine.Count == maxLength && org.AutoAssignNewMembers && bestFit != null)
{
if (bestFit.GetLine().Count < org.GetLine().Count)
if (bestFit.GetRootLineage().Count < org.GetRootLineage().Count)
{
bestFit = org;
maxLength = geoLine.Count;
+2 -2
View File
@@ -41,14 +41,14 @@ namespace Swarmops.Logic.Swarm
public static int GetCountForGeography (Geography geography)
{
Geographies geographies = geography.GetTree();
Geographies geographies = geography.GetAllBelow();
return SwarmDb.GetDatabaseForReading().GetActivistCountForGeographies (geographies.Identities);
}
public static Activists FromGeography (Geography geography)
{
Geographies geographies = geography.GetTree();
Geographies geographies = geography.GetAllBelow();
return new Activists (SwarmDb.GetDatabaseForReading().GetActivistPersonIds (geographies.Identities));
}
+4 -4
View File
@@ -257,7 +257,7 @@ namespace Swarmops.Logic.Swarm
public static People FromOrganizationAndGeographyWithPattern (Organization organization, Geography geography,
string pattern)
{
Geographies geoTree = geography.GetTree();
Geographies geoTree = geography.GetAllBelow();
pattern = pattern.Trim();
if (pattern.Length == 0)
@@ -281,7 +281,7 @@ namespace Swarmops.Logic.Swarm
public static People FromOrganizationAndGeography (Organization organization, Geography geography)
{
Geographies geoTree = geography.GetTree();
Geographies geoTree = geography.GetAllBelow();
// First, get list of people in the geography, then filter on memberships
@@ -297,7 +297,7 @@ namespace Swarmops.Logic.Swarm
{
// Get the organization tree
Organizations orgTree = organization.GetTree();
Organizations orgTree = organization.GetAllBelow();
// Build a lookup table of this organization tree. For each person in 'people'
// that has at least one membership in an organization in the lookup table,
@@ -344,7 +344,7 @@ namespace Swarmops.Logic.Swarm
public static People FromGeography (int geographyId)
{
Geographies geoTree = Geography.FromIdentity (geographyId).GetTree();
Geographies geoTree = Geography.FromIdentity (geographyId).GetAllBelow();
// First, get list of people in the geography, then filter on memberships
+8 -8
View File
@@ -49,8 +49,8 @@ namespace Swarmops.Logic.Swarm
/// <returns>A list of person Ids that hold roles above this point.</returns>
public static int[] GetAllUpwardRoles (int organizationId, int geographyId, RoleType[] roleTypes)
{
Organizations orgLine = Organization.FromIdentity (organizationId).GetLine();
Geographies nodeLine = Geography.FromIdentity (geographyId).GetLine();
Organizations orgLine = Organization.FromIdentity (organizationId).GetRootLineage();
Geographies nodeLine = Geography.FromIdentity (geographyId).GetRootLineage();
int[] nodeIds = nodeLine.Identities;
@@ -92,10 +92,10 @@ namespace Swarmops.Logic.Swarm
Organizations orgTree = null;
Geographies nodeTree = null;
int[] nodeIds;
orgTree = Organization.FromIdentity (organizationId).GetTree();
orgTree = Organization.FromIdentity (organizationId).GetAllBelow();
if (geographyId > 0)
{
nodeTree = Geography.FromIdentity (geographyId).GetTree();
nodeTree = Geography.FromIdentity (geographyId).GetAllBelow();
nodeIds = nodeTree.Identities;
}
else
@@ -137,12 +137,12 @@ namespace Swarmops.Logic.Swarm
int[] nodeIds;
int[] orgIds;
orgTree = Organization.FromIdentity (organizationId).GetTree();
orgTree = Organization.FromIdentity (organizationId).GetAllBelow();
orgIds = orgTree.Identities;
if (geographyId > 0)
{
nodeTree = Geography.FromIdentity (geographyId).GetTree();
nodeTree = Geography.FromIdentity (geographyId).GetAllBelow();
nodeIds = nodeTree.Identities;
}
else
@@ -235,8 +235,8 @@ namespace Swarmops.Logic.Swarm
// Expensive op:
BasicPersonRole[] basicPersonRoles =
SwarmDb.GetDatabaseForReading().GetRolesForOrganizationsGeographies (organization.GetTree().Identities,
geography.GetTree().Identities);
SwarmDb.GetDatabaseForReading().GetRolesForOrganizationsGeographies (organization.GetAllBelow().Identities,
geography.GetAllBelow().Identities);
Dictionary<int, bool> lookup = new Dictionary<int, bool>();
foreach (BasicPersonRole basicRole in basicPersonRoles)
+1 -1
View File
@@ -105,7 +105,7 @@ namespace Swarmops.Frontend.Automation
cityArray.Add (dataPoint);
}
Geographies geographies = Country.FromCode (countryCode).Geography.GetTree();
Geographies geographies = Country.FromCode (countryCode).Geography.GetAllBelow();
foreach (Geography geography in geographies)
{
GeographyData dataPoint = new GeographyData
@@ -129,7 +129,7 @@ namespace Swarmops.Frontend.Pages.v5.Admin.Hacks
geoNameLookup[countryCode] = countryGeoId;
}
Geographies countryGeographies = Geography.FromIdentity(countryGeoId).GetTree();
Geographies countryGeographies = Geography.FromIdentity(countryGeoId).GetAllBelow();
foreach (Geography geography in countryGeographies)
{
+2 -2
View File
@@ -53,8 +53,8 @@ namespace Swarmops.Frontend.Pages.Comms
AuthenticationData authData = GetAuthenticationDataAndCulture();
Geography geography = Geography.FromIdentity (geographyId);
Geographies geoTree = geography.GetTree();
Organizations orgTree = authData.CurrentOrganization.GetTree();
Geographies geoTree = geography.GetAllBelow();
Organizations orgTree = authData.CurrentOrganization.GetAllBelow();
switch (recipientTypeId)
{
+2 -2
View File
@@ -115,7 +115,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
throw new UnauthorizedAccessException ("A million nopes");
}
FinancialAccounts accountTree = account.GetTree();
FinancialAccounts accountTree = account.GetAllBelow();
int year = DateTime.Today.Year;
JsonAccountData result = new JsonAccountData();
@@ -380,7 +380,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
newTreeBudget *= 100; // convert to cents
int year = DateTime.Today.Year;
FinancialAccounts accountTree = account.GetTree();
FinancialAccounts accountTree = account.GetAllBelow();
Int64 currentTreeBudget = accountTree.GetBudgetSumCents (year);
Int64 currentSingleBudget = account.GetBudgetCents (year);
Int64 suballocatedBudget = currentTreeBudget - currentSingleBudget;
+1 -1
View File
@@ -52,7 +52,7 @@ namespace Swarmops.Utility.BotCode
// Populate voters, then open for voting
Organizations orgTree = poll.Organization.GetTree();
Organizations orgTree = poll.Organization.GetAllBelow();
Memberships memberships = Memberships.ForOrganizations (orgTree);
+2 -2
View File
@@ -185,8 +185,8 @@ namespace Swarmops.Utility.BotCode
{
// for this person, iterate over all applicable geographies and organizations
Organizations orgLine = organization.GetLine();
Geographies geoLine = person.Geography.GetLine();
Organizations orgLine = organization.GetRootLineage();
Geographies geoLine = person.Geography.GetRootLineage();
orgLine.Reverse(); // Start at the most local org
+1 -1
View File
@@ -19,7 +19,7 @@ namespace Swarmops.Utility.BotCode
public static string ExportMemberList (int organizationIdRoot, DateTime membersAfter, DateTime membersBefore)
{
Organizations orgs = Organization.FromIdentity (organizationIdRoot).GetTree();
Organizations orgs = Organization.FromIdentity (organizationIdRoot).GetAllBelow();
StringBuilder result = new StringBuilder();
result.Append (