Skip to content

Commit

Permalink
feat/filter out product positions from GetDepartmentPersonnel (#671)
Browse files Browse the repository at this point in the history
- [x] New feature
- [ ] Bug fix
- [ ] High impact

**Description of work:**
We don't want product positions (instances) to show up in the list over
all allocations in Personnel Allocation, and therefore we need to filter
out all these positions.



[AB#55286](https://statoil-proview.visualstudio.com/787035c2-8cf2-4d73-a83e-bb0e6d937eec/_workitems/edit/55286)

[AB#53017](https://statoil-proview.visualstudio.com/787035c2-8cf2-4d73-a83e-bb0e6d937eec/_workitems/edit/53017)

**Testing:**
- [x] Can be tested
- [ ] Automatic tests created / updated
- [x] Local tests are passing

Can be tested with using endpoint:

https://resources-api-pr-671.fusion-dev.net/departments/{departmentString}/resources/personnel?api-version=2.0

Change departmentString with the department you want to check. Example
"PDP PRD PMC PCA PCA4".
PDP PRD PMC PCA PCA4 should have a person that are assigned to a
positions instance with baseposition of type "Project". This should not
be shown in the result here


Should not get any product (instances) of type Product when getting
DepartmentPersonnel. Should still give all the other positions




**Checklist:**
- [x] Considered automated tests
- [ ] ~~Considered updating specification / documentation~~
- [x] Considered work items 
- [x] Considered security
- [x] Performed developer testing
- [x] Checklist finalized / ready for review
  • Loading branch information
aleklundeq authored Sep 2, 2024
1 parent 601da0d commit 582b125
Showing 1 changed file with 14 additions and 11 deletions.
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 != null && pis.BasePosition.ProjectType != null && !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,20 +214,19 @@ 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"));



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

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


return personnel;
}

Expand Down

0 comments on commit 582b125

Please sign in to comment.