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

Fix report search for "pending approval of" #3445

Merged
merged 5 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions client/tests/webdriver/baseSpecs/homeTiles.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expect } from "chai"
import Home from "../pages/home.page"

describe("When checking the home page tiles", () => {
it("Should see correct number of pendingApprovalOf reports count when logged in as Arthur", () => {
Home.openAsAdminUser()
Home.homeTilesContainer.waitForExist()
Home.homeTilesContainer.waitForDisplayed()
// Depends on test data
expect(Home.pendingMyApprovalOfCount.getText()).to.eq("2")
})
})
10 changes: 10 additions & 0 deletions client/tests/webdriver/pages/home.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ class Home extends Page {
return browser.$("#searchBarInput")
}

get homeTilesContainer() {
return browser.$("fieldset.home-tile-row")
}

get pendingMyApprovalOfCount() {
return browser
.$('//button[contains(text(), "Reports pending my approval")]')
.$("h1")
}

get submitSearch() {
return browser.$("#topbar #searchBarSubmit")
}
Expand Down
33 changes: 31 additions & 2 deletions src/main/java/mil/dds/anet/search/AbstractReportSearcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -46,6 +47,20 @@ public AbstractReportSearcher(AbstractSearchQueryBuilder<Report, ReportSearchQue
super(qb);
}

protected ReportSearchQuery getQueryForPostProcessing(ReportSearchQuery query) {
if (query.getPendingApprovalOf() == null) {
return query;
}
try {
final ReportSearchQuery modifiedQuery = query.clone();
// pagination will be done after post-processing
modifiedQuery.setPageSize(0);
return modifiedQuery;
} catch (CloneNotSupportedException e) {
return query; // what else can we do?
}
}

protected CompletableFuture<AnetBeanList<Report>> postProcessResults(Map<String, Object> context,
ReportSearchQuery query, AnetBeanList<Report> result) {
if (query.getPendingApprovalOf() == null) {
Expand All @@ -62,15 +77,29 @@ protected CompletableFuture<AnetBeanList<Report>> postProcessResults(Map<String,
r.getApprovalStepUuid(), r.getAdvisorOrgUuid()))
.toArray(CompletableFuture<?>[]::new);
return CompletableFuture.allOf(allReports).thenCompose(v -> {

final Iterator<Report> iterator = list.iterator();
for (final CompletableFuture<Boolean> cf : allReports) {
iterator.next();
if (!cf.join()) {
iterator.remove();
}
}
result.setTotalCount(list.size());
final int totalCount = list.size();
final int pageNum = query.getPageNum();
final int pageSize = query.getPageSize();
result.setTotalCount(totalCount);
result.setPageNum(pageNum);
result.setPageSize(pageSize);
if (pageSize > 0) {
// Do pagination
final int fromIndex = pageNum * pageSize;
final int toIndex = Math.min(totalCount, fromIndex + pageSize);
if (fromIndex >= totalCount || fromIndex > toIndex) {
result.setList(Collections.emptyList());
} else {
result.setList(list.subList(fromIndex, toIndex));
}
}
return CompletableFuture.completedFuture(result);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ public MssqlReportSearcher() {
@Override
public CompletableFuture<AnetBeanList<Report>> runSearch(Map<String, Object> context,
Set<String> subFields, ReportSearchQuery query) {
buildQuery(subFields, query);
final ReportSearchQuery modifiedQuery = getQueryForPostProcessing(query);
buildQuery(subFields, modifiedQuery);
outerQb.addSelectClause("*");
outerQb.addTotalCount();
outerQb.addFromClause("( " + qb.build() + " ) l");
outerQb.addSqlArgs(qb.getSqlArgs());
outerQb.addListArgs(qb.getListArgs());
addOrderByClauses((AbstractSearchQueryBuilder<Report, ReportSearchQuery>) outerQb, query);
return postProcessResults(context, query,
(outerQb).buildAndRun(getDbHandle(), query, new ReportMapper()));
(outerQb).buildAndRun(getDbHandle(), modifiedQuery, new ReportMapper()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public PostgresqlReportSearcher() {
@Override
public CompletableFuture<AnetBeanList<Report>> runSearch(Map<String, Object> context,
Set<String> subFields, ReportSearchQuery query) {
buildQuery(subFields, query);
final ReportSearchQuery modifiedQuery = getQueryForPostProcessing(query);
buildQuery(subFields, modifiedQuery);
return postProcessResults(context, query,
qb.buildAndRun(getDbHandle(), query, new ReportMapper()));
qb.buildAndRun(getDbHandle(), modifiedQuery, new ReportMapper()));
}

@Override
Expand Down
Loading