Searching for Applicants should work
This commit is contained in:
@@ -103,6 +103,56 @@ namespace Swarmops.Database
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Dictionary<int, List<BasicApplicant>> GetApplicantsFromPeople(int[] personIds)
|
||||
{
|
||||
Dictionary<int, List<BasicApplicant>> result = new Dictionary<int, List<BasicApplicant>>();
|
||||
|
||||
if (personIds == null || personIds.Length == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
// Optimization: If more than 128 personIds, build a hash table, get _all_ memberships, and return
|
||||
// the matching ones logic wise. We've had _queries_ that exceed 64k text in length...
|
||||
|
||||
/*
|
||||
if (personIds.Length > 128)
|
||||
{
|
||||
return GetParticipationsForPeopleOptimizedForLargeSets(personIds, gracePeriod);
|
||||
}*/
|
||||
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
string commandString = "SELECT " + applicantFieldSequence + " WHERE "
|
||||
+ "Open=1 AND PersonId in (" + JoinIds(personIds) + ")";
|
||||
|
||||
DbCommand command = GetDbCommand(commandString, connection);
|
||||
command.CommandTimeout = 30; // If 30s is too short, something needs optimization.
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
BasicApplicant applicant = ReadApplicantFromDataReader(reader);
|
||||
int personId = applicant.PersonId;
|
||||
|
||||
if (!result.ContainsKey(personId))
|
||||
{
|
||||
result[personId] = new List<BasicApplicant>();
|
||||
}
|
||||
|
||||
result[personId].Add(applicant);
|
||||
// Add to this person's list of memberships
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Creation and manipulation - stored procedures
|
||||
|
||||
@@ -306,7 +306,7 @@ namespace Swarmops.Database
|
||||
result[personId] = new List<BasicParticipation>();
|
||||
}
|
||||
|
||||
result[personId].Add (ReadMembershipFromDataReader (reader));
|
||||
result[personId].Add (participation);
|
||||
// Add to this person's list of memberships
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class ListPersonDataSource
|
||||
{
|
||||
People ppl = People.FromIdentities(this.listedPersons);
|
||||
Dictionary<int, List<BasicParticipation>> membershipTable =
|
||||
Participations.GetParticipationsForPeople(this.listedPersons, Participation.GracePeriod);
|
||||
Participations.GetParticipationsForPeople(ppl, Participation.GracePeriod);
|
||||
Participations participationsToLoad = new Participations();
|
||||
foreach (Person p in ppl)
|
||||
{
|
||||
|
||||
@@ -381,6 +381,7 @@ namespace Swarmops.Logic.Security
|
||||
orgLookup[Organization.Identity] = true;
|
||||
|
||||
Dictionary<int, List<BasicParticipation>> membershipLookup = null;
|
||||
Dictionary<int, List<BasicApplicant>> applicantLookup = null;
|
||||
|
||||
if (HasSystemAccess(AccessType.Read) || HasAccess(new Access(Organization, aspect, AccessType.Read)))
|
||||
{
|
||||
@@ -388,7 +389,8 @@ namespace Swarmops.Logic.Security
|
||||
// or org-wide read access (at least) to participant/personal data at current Organization
|
||||
|
||||
// Optimization: Get all memberships in advance, without instantiating logic objects
|
||||
membershipLookup = Participations.GetParticipationsForPeople (rawList.Identities, 0);
|
||||
membershipLookup = Participations.GetParticipationsForPeople (rawList, 0);
|
||||
applicantLookup = Applicants.GetApplicantsFromPeople(rawList);
|
||||
|
||||
foreach (Person person in rawList)
|
||||
{
|
||||
@@ -396,22 +398,40 @@ namespace Swarmops.Logic.Security
|
||||
// them is visible to this Authority - if it's a membership in an org at or below the
|
||||
// Authority object's organization
|
||||
|
||||
if (membershipLookup.ContainsKey (person.Identity))
|
||||
if (membershipLookup.ContainsKey(person.Identity))
|
||||
{
|
||||
List<BasicParticipation> list = membershipLookup[person.Identity];
|
||||
|
||||
foreach (BasicParticipation basicMembership in list)
|
||||
{
|
||||
if (orgLookup.ContainsKey (basicMembership.OrganizationId))
|
||||
if (orgLookup.ContainsKey(basicMembership.OrganizationId))
|
||||
{
|
||||
// hit - this person has an active membership that makes them visible to this Authority
|
||||
result.Add (person);
|
||||
result.Add(person);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// If membership check fails, then check for membership applications
|
||||
|
||||
if (applicantLookup.ContainsKey(person.Identity))
|
||||
{
|
||||
List<BasicApplicant> applicantList = applicantLookup[person.Identity];
|
||||
|
||||
foreach (Applicant applicant in applicantList)
|
||||
{
|
||||
if (orgLookup.ContainsKey(applicant.OrganizationId))
|
||||
{
|
||||
// hit - this person has an active membership _application_ that makes them visible to this Authority
|
||||
result.Add(person);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -448,7 +468,8 @@ namespace Swarmops.Logic.Security
|
||||
|
||||
// Optimization: Get all memberships in advance, without instantiating logic objects
|
||||
Dictionary<int, List<BasicParticipation>> personLookup =
|
||||
Participations.GetParticipationsForPeople(rawList.Identities, 0);
|
||||
Participations.GetParticipationsForPeople(rawList, 0);
|
||||
applicantLookup = Applicants.GetApplicantsFromPeople(rawList);
|
||||
|
||||
foreach (Person person in rawList)
|
||||
{
|
||||
@@ -462,15 +483,29 @@ namespace Swarmops.Logic.Security
|
||||
{
|
||||
// Geography hit. Test Membership / Organization.
|
||||
|
||||
List<BasicParticipation> list = personLookup[person.Identity];
|
||||
bool added = false;
|
||||
|
||||
foreach (BasicParticipation basicMembership in list)
|
||||
List<BasicParticipation> participationList = personLookup[person.Identity];
|
||||
|
||||
foreach (BasicParticipation basicMembership in participationList)
|
||||
{
|
||||
if (orgLookup.ContainsKey (basicMembership.OrganizationId))
|
||||
if (orgLookup.ContainsKey (basicMembership.OrganizationId) && !added)
|
||||
{
|
||||
// Organization hit - this person has an active membership that makes them visible to this Authority
|
||||
|
||||
result.Add (person);
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
|
||||
List<BasicApplicant> applicantList = applicantLookup[person.Identity];
|
||||
|
||||
foreach (BasicApplicant basicApplicant in applicantList)
|
||||
{
|
||||
if (orgLookup.ContainsKey(basicApplicant.OrganizationId) && !added)
|
||||
{
|
||||
result.Add(person);
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,5 +39,10 @@ namespace Swarmops.Logic.Swarm
|
||||
FromIdentityAggressive(SwarmDb.GetDatabaseForWriting()
|
||||
.CreateApplicant(person.Identity, organization.Identity));
|
||||
}
|
||||
|
||||
public int ScoreTotal
|
||||
{
|
||||
get { return this.Score1 + this.Score2 + this.Score3; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,25 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Swarmops.Basic.Types.Swarm;
|
||||
using Swarmops.Database;
|
||||
using Swarmops.Logic.Structure;
|
||||
using Swarmops.Logic.Support;
|
||||
|
||||
namespace Swarmops.Logic.Swarm
|
||||
{
|
||||
public class Applicants: PluralBase<Applicants, Applicant, BasicApplicant>
|
||||
{
|
||||
|
||||
public static Dictionary<int, List<BasicApplicant>> GetApplicantsFromPeople(People people)
|
||||
{
|
||||
return SwarmDb.GetDatabaseForReading().GetApplicantsFromPeople(people.Identities);
|
||||
}
|
||||
|
||||
public static Applicants FromPeopleInOrganization(People people, Organization organization)
|
||||
{
|
||||
Organizations orgTree = organization.ThisAndBelow();
|
||||
|
||||
return FromArray(SwarmDb.GetDatabaseForReading().GetApplicants(people, orgTree));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,9 +103,9 @@ namespace Swarmops.Logic.Swarm
|
||||
}
|
||||
|
||||
|
||||
public static Dictionary<int, List<BasicParticipation>> GetParticipationsForPeople (int[] personIds, int gracePeriod)
|
||||
public static Dictionary<int, List<BasicParticipation>> GetParticipationsForPeople (People people, int gracePeriod)
|
||||
{
|
||||
return SwarmDb.GetDatabaseForReading().GetParticipationsForPeople (personIds, gracePeriod);
|
||||
return SwarmDb.GetDatabaseForReading().GetParticipationsForPeople (people.Identities, gracePeriod);
|
||||
}
|
||||
}
|
||||
}
|
||||
+51
-2
@@ -275,7 +275,7 @@ namespace Swarmops.Logic.Swarm
|
||||
BasicPerson[] candidates =
|
||||
SwarmDb.GetDatabaseForReading().GetPeopleInGeographiesWithPattern (geoTree.Identities, pattern);
|
||||
|
||||
return FilterByMembership (candidates, organization);
|
||||
return People.LogicalOr(FilterByMembership (candidates, organization), FilterByApplicant(candidates, organization));
|
||||
}
|
||||
|
||||
|
||||
@@ -289,7 +289,7 @@ namespace Swarmops.Logic.Swarm
|
||||
|
||||
// Filter on memberships
|
||||
|
||||
return FilterByMembership (people, organization);
|
||||
return People.LogicalOr(FilterByMembership (people, organization), FilterByApplicant(people, organization));
|
||||
}
|
||||
|
||||
|
||||
@@ -342,6 +342,55 @@ namespace Swarmops.Logic.Swarm
|
||||
return result;
|
||||
}
|
||||
|
||||
private static People FilterByApplicant(BasicPerson[] candidates, Organization organization)
|
||||
{
|
||||
// Get the organization tree
|
||||
|
||||
Organizations orgTree = organization.ThisAndBelow();
|
||||
|
||||
// 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,
|
||||
// add that person to the final result.
|
||||
|
||||
Dictionary<int, BasicOrganization> lookup = new Dictionary<int, BasicOrganization>();
|
||||
|
||||
foreach (Organization org in orgTree)
|
||||
{
|
||||
lookup[org.Identity] = org;
|
||||
}
|
||||
|
||||
// Get the list of all memberships
|
||||
|
||||
Dictionary<int, List<BasicApplicant>> applicants =
|
||||
SwarmDb.GetDatabaseForReading()
|
||||
.GetApplicantsFromPeople(People.FromArray(candidates).Identities);
|
||||
|
||||
People result = new People();
|
||||
|
||||
foreach (BasicPerson basicPerson in candidates)
|
||||
{
|
||||
bool applicantToOrganization = false;
|
||||
|
||||
if (applicants.ContainsKey(basicPerson.Identity))
|
||||
{
|
||||
foreach (BasicApplicant applicant in applicants[basicPerson.Identity])
|
||||
{
|
||||
if (lookup.ContainsKey(applicant.OrganizationId))
|
||||
{
|
||||
applicantToOrganization = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (applicantToOrganization)
|
||||
{
|
||||
result.Add(Person.FromBasic(basicPerson));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static People FromGeography (int geographyId)
|
||||
{
|
||||
Geographies geoTree = Geography.FromIdentity (geographyId).ThisAndBelow();
|
||||
|
||||
@@ -45,11 +45,33 @@ namespace Swarmops.Frontend.Pages.Swarm
|
||||
string editPersonTemplate =
|
||||
"\"actions\":\"<a href='javascript:masterBeginEditPerson({0})'><img src='/Images/Icons/iconshock-wrench-128x96px-centered.png' height='16' width='24' /></a>\"";
|
||||
|
||||
Dictionary<int, Applicant> applicantLookup = new Dictionary<int, Applicant>();
|
||||
|
||||
if (CurrentOrganization.Parameters.ParticipationEntry == "ApplicationApproval")
|
||||
{
|
||||
// There are applications possible for this org; find them and put the Score in the Notes field
|
||||
|
||||
Applicants applicants = Applicants.FromPeopleInOrganization(matches, CurrentOrganization);
|
||||
|
||||
foreach (Applicant applicant in applicants)
|
||||
{
|
||||
applicantLookup[applicant.PersonId] = applicant;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Person person in matches)
|
||||
{
|
||||
string notes = Participant.Localized(CurrentOrganization.RegularLabel, person.Gender);
|
||||
|
||||
if (applicantLookup.ContainsKey(person.Identity))
|
||||
{
|
||||
// If this is an applicant, use the "Notes" field for score
|
||||
notes = applicantLookup[person.Identity].ScoreTotal.ToString("N0");
|
||||
}
|
||||
|
||||
string onePerson = '{' +
|
||||
String.Format (
|
||||
"\"id\":\"{0}\",\"name\":\"<span class='spanUser{0}Name'>{1}</span>\",\"avatar16Url\":\"{2}\",\"geographyName\":\"{3}\",\"mail\":\"<span class='spanUser{0}Mail'>{4}</span>\",\"phone\":\"<span class='spanUser{0}Phone'>{5}</span>\"",
|
||||
"\"id\":\"{0}\",\"name\":\"<span class='spanUser{0}Name'>{1}</span>\",\"avatar16Url\":\"{2}\",\"geographyName\":\"{3}\",\"mail\":\"<span class='spanUser{0}Mail'>{4}</span>\",\"notes\":\"{6}\",\"phone\":\"<span class='spanUser{0}Phone'>{5}</span>\"",
|
||||
person.Identity,
|
||||
JsonSanitize (person.Canonical),
|
||||
person.GetSecureAvatarLink (16),
|
||||
@@ -57,7 +79,8 @@ namespace Swarmops.Frontend.Pages.Swarm
|
||||
JsonSanitize (person.Mail),
|
||||
JsonSanitize (person.Phone)) + "," +
|
||||
String.Format(
|
||||
editPersonTemplate, person.Identity)
|
||||
editPersonTemplate, person.Identity,
|
||||
JsonSanitize(notes))
|
||||
+ '}';
|
||||
jsonPeople.Add (onePerson);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user