Skip to content

Commit

Permalink
'#2163 Implementation of restore filters for Table Header Filterers.
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdalla committed Jun 4, 2024
1 parent c606d3e commit e8b19e3
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ public class ValueCountQueryFilter implements IQueryFilter {
StringBuffer textualDetail = null;
Set<ValueCount> values = null;
String filterField;
MetadataSearch metadataSearch;
private Query query;

public ValueCountQueryFilter(String filterField, Set<ValueCount> selectedValues) {
public ValueCountQueryFilter(MetadataSearch metadataSearch, String filterField, Set<ValueCount> selectedValues) {
this.filterField = filterField;
this.metadataSearch = metadataSearch;
values = new HashSet<ValueCount>();
if (selectedValues != null) {
values.addAll(selectedValues);
Expand Down Expand Up @@ -110,4 +112,8 @@ public Set<ValueCount> getValues() {
return values;
}

public MetadataSearch getMetadataSearch() {
return metadataSearch;
}

}
2 changes: 1 addition & 1 deletion iped-app/src/main/java/iped/app/ui/MetadataPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ public List getDefinedFilters() {
selectedValues.addAll(list.getSelectedValuesList());
if (isFiltering()) {
ValueCount sample = selectedValues.iterator().next();
result.add(new ValueCountQueryFilter(field, selectedValues));
result.add(new ValueCountQueryFilter(ms, field, selectedValues));
}
return result;
}
Expand Down
93 changes: 74 additions & 19 deletions iped-app/src/main/java/iped/app/ui/TableHeaderFilterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import iped.app.ui.controls.table.MetadataValueSearchList;
import iped.app.ui.filters.EqualsFilter;
import iped.app.ui.filters.StartsWithFilter;
import iped.app.ui.filters.ValueFilter;
import iped.engine.search.MultiSearchResult;
import iped.engine.search.QueryBuilder;
import iped.engine.task.index.IndexItem;
Expand Down Expand Up @@ -60,28 +61,46 @@ public void removeFilter(String field) {
App.get().getFilterManager().notifyFilterChange();
}

private void addQueryFilter(String escapedField, String filterExpression) {
otherFilters.put(escapedField, filterExpression);
definedFilters.put(escapedField, new IQueryFilter() {
private Query query;
class TableHeaderFilter implements IQueryFilter {
private Query query;
private String filterExpression;
private String escapedField;
MetadataSearch metadataSearch;

@Override
public Query getQuery() {
if (query == null) {
try {
query = new QueryBuilder(App.get().appCase).getQuery(filterExpression);
} catch (ParseException | QueryNodeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
public TableHeaderFilter(MetadataSearch metadataSearch, String escapedField, String filterExpression) {
this.filterExpression = filterExpression;
this.escapedField = escapedField;
this.metadataSearch = metadataSearch;
}

@Override
public Query getQuery() {
if (query == null) {
try {
query = new QueryBuilder(App.get().appCase).getQuery(filterExpression);
} catch (ParseException | QueryNodeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return query;
}
return query;
}

public String toString() {
return filterExpression;
}
});
public String toString() {
return filterExpression;
}

public MetadataSearch getMetadataSearch() {
return metadataSearch;
}
// TODO Auto-generated method stub

}

private void addQueryFilter(String escapedField, String filterExpression) {
otherFilters.put(escapedField, filterExpression);
definedFilters.put(escapedField,
new TableHeaderFilter(panels.get(escapedField), escapedField, filterExpression));
selectedValues.remove(escapedField);
App.get().getFilterManager().notifyFilterChange();
}
Expand Down Expand Up @@ -125,7 +144,7 @@ public void removeNonEmptyFilter(String field) {
public void addFilter(String field, Set<ValueCount> selected) {
field = escape(field);
selectedValues.put(field, selected);
definedFilters.put(field, new ValueCountQueryFilter(field, selected));
definedFilters.put(field, new ValueCountQueryFilter(panels.get(field), field, selected));

// clear any other filter defined
otherFilters.remove(field);
Expand Down Expand Up @@ -295,4 +314,40 @@ public void clearFilter() {
public HashMap<String, String> getOtherFilters() {
return otherFilters;
}

@Override
public void restoreDefinedFilters(List<IFilter> filtersToRestore) {
definedFilters.clear();
otherFilters.clear();
selectedValues.clear();
panels.clear();
for (IFilter filter : filtersToRestore) {
String escapedField = null;
if (filter instanceof TableHeaderFilter) {
escapedField = ((TableHeaderFilter) filter).escapedField;
otherFilters.put(escapedField, ((TableHeaderFilter) filter).filterExpression);
definedFilters.put(escapedField, filter);
selectedValues.remove(escapedField);
panels.put(escapedField, ((TableHeaderFilter) filter).getMetadataSearch());
}

if (filter instanceof ValueCountQueryFilter) {
ValueCountQueryFilter vcqFilter = (ValueCountQueryFilter) filter;
escapedField = vcqFilter.getFilterField();
definedFilters.put(escapedField, filter);
selectedValues.put(escapedField, vcqFilter.getValues());
otherFilters.remove(escapedField);
panels.put(escapedField, vcqFilter.getMetadataSearch());
}

if (filter instanceof ValueFilter) {
ValueFilter eqFilter = (ValueFilter) filter;
escapedField = escape(eqFilter.getField());
definedFilters.put(escapedField, filter);
otherFilters.put(escapedField, eqFilter.getValue());
}
}
App.get().getFilterManager().notifyFilterChange();
}

}
8 changes: 8 additions & 0 deletions iped-app/src/main/java/iped/app/ui/filters/ValueFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,12 @@ public IMultiSearchResult filterResult(IMultiSearchResult src) throws IOExceptio
return r;
}

public String getField() {
return field;
}

public String getValue() {
return value;
}

}

0 comments on commit e8b19e3

Please sign in to comment.