Skip to content

Commit

Permalink
Use BeanQuery in SearchResultGeneration.getResultsWithFilter()
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-ronge committed Aug 29, 2024
1 parent 9b0782f commit 050daa4
Showing 1 changed file with 10 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.kitodo.data.database.beans.BaseBean;
import org.kitodo.data.database.beans.Process;
import org.kitodo.data.interfaces.ProcessInterface;
import org.kitodo.production.services.ServiceManager;
import org.kitodo.production.services.data.BeanQuery;

public class SearchResultGeneration {

Expand Down Expand Up @@ -57,35 +57,17 @@ public HSSFWorkbook getResult() {
}

private List<Process> getResultsWithFilter() {
List<Process> processInterfaces;
processInterfaces = ServiceManager.getProcessService().getByQuery(getQueryForFilter(Process.class)
+ " ORDER BY id ASC");
return processInterfaces;
}

/**
* Gets the query with filters.
*
* @param objectType
* Type of object that should be filtered
* @return A query
*/
public String getQueryForFilter(Class<? extends BaseBean> objectType) {
String query = "FROM Process AS process";
String operator = " WHERE";
if (!StringUtils.isBlank(filter)) {
query += operator + " process.title LIKE '%" + filter + "%'";
operator = " AND";
BeanQuery query = new BeanQuery(Process.class);
if (StringUtils.isNotBlank(filter)) {
query.forIdOrInTitle(filter);
}
if (!this.showClosedProcesses) {
query += operator + " process.sortHelperStatus != '100000000000'";
operator = " AND";
query.restrictToNotCompletedProcesses();
}
if (!this.showInactiveProjects) {
query += operator + " process.project.active = 0";
operator = " AND";
query.addBooleanRestriction("project.active", Boolean.FALSE);
}
return query;
return ServiceManager.getProcessService().getByQuery(query.formQueryForAll(), query.getQueryParameters());
}

private HSSFWorkbook getWorkbook() {
Expand All @@ -107,9 +89,9 @@ private HSSFWorkbook getWorkbook() {

private void insertRowData(HSSFSheet sheet) {
int rowCounter = 2;
List<? extends ProcessInterface> resultsWithFilter = getResultsWithFilter();
for (ProcessInterface processDTO : resultsWithFilter) {
prepareRow(rowCounter, sheet, processDTO);
List<Process> resultsWithFilter = getResultsWithFilter();
for (Process process : resultsWithFilter) {
prepareRow(rowCounter, sheet, process);
rowCounter++;
}
}
Expand Down

0 comments on commit 050daa4

Please sign in to comment.