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

feat/filter out product positions from GetDepartmentPersonnel #671

Merged
merged 6 commits into from
Sep 2, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public GetDepartmentPersonnel IncludeSubdepartments(bool includeSubdepartments)
this.includeSubdepartments = includeSubdepartments;
return this;
}

public GetDepartmentPersonnel IncludeCurrentAllocations(bool includeCurrentAllocations)
{
this.includeCurrentAllocations = includeCurrentAllocations;
Expand Down Expand Up @@ -92,12 +92,15 @@ public async Task<IEnumerable<QueryInternalPersonnelPerson>> Handle(GetDepartmen
var departmentRequests = await GetPendingRequests(request.Department);
var requestsWithStateNullOrCreated = await GetRequestsWithStateNullOrCreatedAsync(request.Department);
var departmentPersonnel = await GetDepartmentFromSearchIndexAsyncV2(request.Department, requestsWithStateNullOrCreated);


var departmentAbsence = await GetPersonsAbsenceAsync(departmentPersonnel.Select(p => p.AzureUniqueId));

departmentPersonnel.ForEach(p =>
{
// Filter out all positions of type products
p.PositionInstances = p.PositionInstances.Where(pis => !pis.BasePosition.ProjectType.Equals("Product")).ToList();

p.Absence = departmentAbsence[p.AzureUniqueId];
if (departmentRequests.ContainsKey(p.AzureUniqueId))
p.PendingRequests = departmentRequests[p.AzureUniqueId];
Expand All @@ -121,7 +124,7 @@ public async Task<IEnumerable<QueryInternalPersonnelPerson>> Handle(GetDepartmen
.WithAbsences(p.Absence)
.WithPendingRequests(p.PendingRequests)
.Build();

}

if (request.includeCurrentAllocations)
Expand Down Expand Up @@ -177,15 +180,16 @@ private async Task<List<QueryResourceAllocationRequest>> GetRequestsWithStateNul
private async Task<List<QueryInternalPersonnelPerson>> GetDepartmentFromSearchIndexAsync(string fullDepartmentString, bool includeSubDepartments, List<QueryResourceAllocationRequest> requests)
{
var department = await mediator.Send(new GetDepartment(fullDepartmentString));
if (department is null) return new List<QueryInternalPersonnelPerson>();
if (department is null)
return new List<QueryInternalPersonnelPerson>();

var peopleClient = httpClientFactory.CreateClient(HttpClientNames.ApplicationPeople);

List<QueryInternalPersonnelPerson> personnel;

if (includeSubDepartments || department.LineOrgResponsible?.AzureUniqueId is null)
{
personnel = await PeopleSearchUtils.GetDepartmentFromSearchIndexAsync(peopleClient, requests, fullDepartmentString);
personnel = await PeopleSearchUtils.GetDepartmentFromSearchIndexAsync(peopleClient, requests, fullDepartmentString);
}
else
{
Expand All @@ -210,11 +214,11 @@ private async Task<List<QueryInternalPersonnelPerson>> GetDepartmentFromSearchIn
.Where(m => string.Equals(m.FullDepartment, orgUnit.FullDepartment, StringComparison.OrdinalIgnoreCase))
.Select(m => m.AzureUniqueId)
.ToList() ?? new List<Guid>();

var removeManagerQuery = string.Join(" and ", managers.Select(m => $"azureUniqueId ne '{m}'"));
var queryString = (managers.Any() ? removeManagerQuery + " and " : "") + $"fullDepartment eq '{fullDepartmentString}' and isExpired eq false";


if (managers.Any())
queryString += " or " + string.Join(" or ", managers.Select(m => $"managerAzureId eq '{m}' and isResourceOwner eq true"));

Expand All @@ -224,6 +228,7 @@ private async Task<List<QueryInternalPersonnelPerson>> GetDepartmentFromSearchIn

var personnel = await PeopleSearchUtils.GetFromSearchIndexAsync(peopleClient, queryString, requests: requests);


return personnel;
}

Expand Down
Loading