Skip to content

Commit

Permalink
Merge pull request #20 from Nuix/batch_load_date_range
Browse files Browse the repository at this point in the history
support for scoping sheet by batch load date (since cannot be queried)
  • Loading branch information
JuicyDragon authored Sep 16, 2022
2 parents 06919b3 + fba5e8a commit 3982b8a
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.aspose.cells.Style;
import com.nuix.superutilities.misc.FormatUtility;

import nuix.BatchLoadDetails;
import nuix.Case;

/***
Expand Down Expand Up @@ -158,6 +159,53 @@ public void generate(Case nuixCase, String sheetName, IntersectionReportSheetCon
List<Object> rowValues = new ArrayList<Object>();
String parenScopeQuery = parenExpression(sheetConfig.getScopeQuery());

// If we have batch load dates we wish to constrain the results to, we must go look at all the batch loads
// in the case and filter to those within our date range. Using that filtered set we then get their batch
// load GUIDs and use that to attach additional scope query for those batch loads.
if(sheetConfig.hasBatchLoadDateCriteria()) {
List<String> inRangeBatchLoadGuids = new ArrayList<String>();
List<BatchLoadDetails> allBatchLoads = nuixCase.getBatchLoads();

// Filter all batch loads by whether their loaded date falls within
// the range specifies by the min/max values
for(BatchLoadDetails bld : allBatchLoads) {
boolean satisfiesMin = true;
boolean satisfiesMax = true;

if(sheetConfig.getBatchLoadMinDate() != null) {
satisfiesMin = bld.getLoaded().isAfter(sheetConfig.getBatchLoadMinDate());
}

if(sheetConfig.getBatchLoadMaxDate() != null) {
satisfiesMax = bld.getLoaded().isBefore(sheetConfig.getBatchLoadMaxDate());
}

if(satisfiesMin && satisfiesMax) {
inRangeBatchLoadGuids.add(bld.getBatchId());
}
}

String batchLoadGuidQuery = "";
if(inRangeBatchLoadGuids.size() > 0) {
// We have batch loads that met our criteria so we update the scope
// query to restrict to those batch loads
batchLoadGuidQuery = String.format("(batch-load-guid:%s)",String.join(" OR ", inRangeBatchLoadGuids));

} else {
// We have a funny situation now, user specified to filter to particular batch loads based on their
// loaded date and no batch loads met the required criteria. If we do nothing now, effectively no
// batch loads matching is the same as all batch loads matching. We are going to better represent no
// batch loads matching by modifying scope criteria to accept no batch loads. This will yield 0 results in the
// report, which technically is an accurate representation of our results. Should probably have logic long
// before we reach this point that would catch batch load date criteria matching nothing and warning that user
// then, before we have reached this point.
batchLoadGuidQuery = "(NOT batch-load-guid:*)";
}

// Add batch load criteria we calculated above to the scope query
parenScopeQuery = andExpressions(parenScopeQuery,batchLoadGuidQuery);
}

// Start out by building out headers
fireMessage("Building headers...");
sheet.setValue(0, 0, sheetConfig.getColPrimaryCategoryLabel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.List;
import java.util.function.BiFunction;

import org.joda.time.DateTime;

import nuix.Case;

public class IntersectionReportSheetConfiguration {
Expand All @@ -14,6 +16,8 @@ public class IntersectionReportSheetConfiguration {
private String rowCategoryLabel = "Term";
private String colPrimaryCategoryLabel = "Column Category";
private String scopeQuery = "";
private DateTime batchLoadMinDate = null;
private DateTime batchLoadMaxDate = null;
private boolean freezePanes = false;

/***
Expand Down Expand Up @@ -164,6 +168,42 @@ public String getScopeQuery() {
public void setScopeQuery(String scopeQuery) {
this.scopeQuery = scopeQuery;
}

/***
* Gets the minimum batch load date an item must have to be reported. A null value means batch load date is not to be considered.
* @return the minimum batch load date an item must have to be reported
*/
public DateTime getBatchLoadMinDate() {
return batchLoadMinDate;
}

/***
* Sets the minimum batch load date an item must have to be reported. A null value means batch load date is not to be considered.
* @param batchLoadMinDate the minimum batch load date an item must have to be reported
*/
public void setBatchLoadMinDate(DateTime batchLoadMinDate) {
this.batchLoadMinDate = batchLoadMinDate;
}

/***
* Gets the maximum batch load date an item must have to be reported. A null value means batch load date is not to be considered.
* @return the maximum batch load date an item must have to be reported
*/
public DateTime getBatchLoadMaxDate() {
return batchLoadMaxDate;
}

/***
* Sets the maximum batch load date an item must have to be reported. A null value means batch load date is not to be considered.
* @param batchLoadMaxDate the maximum batch load date an item must have to be reported
*/
public void setBatchLoadMaxDate(DateTime batchLoadMaxDate) {
this.batchLoadMaxDate = batchLoadMaxDate;
}

public boolean hasBatchLoadDateCriteria() {
return batchLoadMinDate != null || batchLoadMaxDate != null;
}

/***
* Gets whether "freeze panes" will be applied to this sheet. When true, first column and first 2 rows will be frozen into place.
Expand Down

0 comments on commit 3982b8a

Please sign in to comment.