From e945dca07433be871449059bfcd9386f22c50640 Mon Sep 17 00:00:00 2001 From: Aleksander Lund Date: Wed, 14 Aug 2024 16:01:07 +0200 Subject: [PATCH 1/2] Filter out product positions for GetDepartmentPersonnel --- .../Departments/GetDepartmentPersonnel.cs | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/backend/api/Fusion.Resources.Domain/Queries/Departments/GetDepartmentPersonnel.cs b/src/backend/api/Fusion.Resources.Domain/Queries/Departments/GetDepartmentPersonnel.cs index dfa933c51..b679f0376 100644 --- a/src/backend/api/Fusion.Resources.Domain/Queries/Departments/GetDepartmentPersonnel.cs +++ b/src/backend/api/Fusion.Resources.Domain/Queries/Departments/GetDepartmentPersonnel.cs @@ -50,7 +50,7 @@ public GetDepartmentPersonnel IncludeSubdepartments(bool includeSubdepartments) this.includeSubdepartments = includeSubdepartments; return this; } - + public GetDepartmentPersonnel IncludeCurrentAllocations(bool includeCurrentAllocations) { this.includeCurrentAllocations = includeCurrentAllocations; @@ -92,12 +92,15 @@ public async Task> 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]; @@ -121,7 +124,7 @@ public async Task> Handle(GetDepartmen .WithAbsences(p.Absence) .WithPendingRequests(p.PendingRequests) .Build(); - + } if (request.includeCurrentAllocations) @@ -177,7 +180,8 @@ private async Task> GetRequestsWithStateNul private async Task> GetDepartmentFromSearchIndexAsync(string fullDepartmentString, bool includeSubDepartments, List requests) { var department = await mediator.Send(new GetDepartment(fullDepartmentString)); - if (department is null) return new List(); + if (department is null) + return new List(); var peopleClient = httpClientFactory.CreateClient(HttpClientNames.ApplicationPeople); @@ -185,7 +189,7 @@ private async Task> GetDepartmentFromSearchIn if (includeSubDepartments || department.LineOrgResponsible?.AzureUniqueId is null) { - personnel = await PeopleSearchUtils.GetDepartmentFromSearchIndexAsync(peopleClient, requests, fullDepartmentString); + personnel = await PeopleSearchUtils.GetDepartmentFromSearchIndexAsync(peopleClient, requests, fullDepartmentString); } else { @@ -210,11 +214,11 @@ private async Task> GetDepartmentFromSearchIn .Where(m => string.Equals(m.FullDepartment, orgUnit.FullDepartment, StringComparison.OrdinalIgnoreCase)) .Select(m => m.AzureUniqueId) .ToList() ?? new List(); - + 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")); @@ -224,6 +228,7 @@ private async Task> GetDepartmentFromSearchIn var personnel = await PeopleSearchUtils.GetFromSearchIndexAsync(peopleClient, queryString, requests: requests); + return personnel; } From f952fa54d98f7486e85610358c25ac005f866028 Mon Sep 17 00:00:00 2001 From: Aleksander Lund Date: Mon, 2 Sep 2024 06:49:04 +0200 Subject: [PATCH 2/2] Added null checks for baseposition and projecttype --- .../Queries/Departments/GetDepartmentPersonnel.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/backend/api/Fusion.Resources.Domain/Queries/Departments/GetDepartmentPersonnel.cs b/src/backend/api/Fusion.Resources.Domain/Queries/Departments/GetDepartmentPersonnel.cs index b679f0376..e5cbea997 100644 --- a/src/backend/api/Fusion.Resources.Domain/Queries/Departments/GetDepartmentPersonnel.cs +++ b/src/backend/api/Fusion.Resources.Domain/Queries/Departments/GetDepartmentPersonnel.cs @@ -99,7 +99,7 @@ public async Task> Handle(GetDepartmen departmentPersonnel.ForEach(p => { // Filter out all positions of type products - p.PositionInstances = p.PositionInstances.Where(pis => !pis.BasePosition.ProjectType.Equals("Product")).ToList(); + p.PositionInstances = p.PositionInstances.Where(pis => pis.BasePosition != null && pis.BasePosition.ProjectType != null && !pis.BasePosition.ProjectType.Equals("Product")).ToList(); p.Absence = departmentAbsence[p.AzureUniqueId]; if (departmentRequests.ContainsKey(p.AzureUniqueId)) @@ -222,8 +222,6 @@ private async Task> GetDepartmentFromSearchIn if (managers.Any()) queryString += " or " + string.Join(" or ", managers.Select(m => $"managerAzureId eq '{m}' and isResourceOwner eq true")); - - var peopleClient = httpClientFactory.CreateClient(HttpClientNames.ApplicationPeople); var personnel = await PeopleSearchUtils.GetFromSearchIndexAsync(peopleClient, queryString, requests: requests);