[New] Allow reports to work in parallel if enabled
This commit is contained in:
parent
d33549f13d
commit
c363952547
|
@ -38,6 +38,7 @@ import li.strolch.persistence.api.StrolchTransaction;
|
|||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.privilege.model.SimpleRestrictable;
|
||||
import li.strolch.report.Report;
|
||||
import li.strolch.report.ReportElement;
|
||||
import li.strolch.report.ReportSearch;
|
||||
import li.strolch.rest.RestfulStrolchComponent;
|
||||
import li.strolch.rest.StrolchRestfulConstants;
|
||||
|
@ -123,7 +124,7 @@ public class ReportResource {
|
|||
List<String> types = new ArrayList<>(criteria.keySet());
|
||||
JsonObject finalLocaleJ = localeJ;
|
||||
types.stream().sorted(comparing(type -> {
|
||||
JsonElement translatedJ = finalLocaleJ.get(type);
|
||||
JsonElement translatedJ = finalLocaleJ == null ? null : finalLocaleJ.get(type);
|
||||
return translatedJ == null ? type : translatedJ.getAsString();
|
||||
})).forEach(type -> {
|
||||
Set<StrolchRootElement> elements = criteria.getSet(type);
|
||||
|
@ -283,7 +284,10 @@ public class ReportResource {
|
|||
// add rows to response
|
||||
JsonObject finalResult = new JsonObject();
|
||||
JsonArray rows = new JsonArray();
|
||||
json.forEach(rows::add);
|
||||
if (report.isParallel())
|
||||
json.forEachOrdered(rows::add);
|
||||
else
|
||||
json.forEach(rows::add);
|
||||
|
||||
finalResult.add(PARAM_ROWS, rows);
|
||||
|
||||
|
@ -432,18 +436,23 @@ public class ReportResource {
|
|||
try (CSVPrinter csvP = new CSVPrinter(new OutputStreamWriter(out),
|
||||
CSVFormat.DEFAULT.withHeader(headers).withDelimiter(';'))) {
|
||||
|
||||
report.doReport().forEach(row -> {
|
||||
try {
|
||||
csvP.printRecord(row.valueStream().collect(Collectors.toList())); // add to CSV
|
||||
} catch (Exception e) {
|
||||
logger.error("Could not write CSV row", e);
|
||||
}
|
||||
});
|
||||
if (report.isParallel())
|
||||
report.doReport().forEachOrdered(row -> writeCsv(csvP, row));
|
||||
else
|
||||
report.doReport().forEach(row -> writeCsv(csvP, row));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void writeCsv(CSVPrinter csvP, ReportElement row) {
|
||||
try {
|
||||
csvP.printRecord(row.valueStream().collect(Collectors.toList())); // add to CSV
|
||||
} catch (Exception e) {
|
||||
logger.error("Could not write CSV row", e);
|
||||
}
|
||||
}
|
||||
|
||||
private MapOfSets<String, String> getFiltersFromJson(JsonArray filters) {
|
||||
MapOfSets<String, String> result = new MapOfSets<>();
|
||||
if (filters == null) {
|
||||
|
|
|
@ -35,6 +35,10 @@ public class Report implements AutoCloseable {
|
|||
return this.reportPolicy;
|
||||
}
|
||||
|
||||
public boolean isParallel() {
|
||||
return this.reportPolicy.isParallel();
|
||||
}
|
||||
|
||||
public boolean hasDateRangeSelector() {
|
||||
return this.reportPolicy.hasDateRangeSelector();
|
||||
}
|
||||
|
|
|
@ -186,6 +186,11 @@ public class GenericReport extends ReportPolicy {
|
|||
return this.descending;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isParallel() {
|
||||
return this.parallel;
|
||||
}
|
||||
|
||||
public void setI18nData(JsonObject i18nData) {
|
||||
this.i18nData = i18nData;
|
||||
}
|
||||
|
@ -807,7 +812,7 @@ public class GenericReport extends ReportPolicy {
|
|||
* @return the stream of {@link StrolchRootElement StrolchRootElement}
|
||||
*/
|
||||
protected Stream<? extends StrolchRootElement> queryRows() {
|
||||
if (this.parallel)
|
||||
if (isParallel())
|
||||
return getStreamFor(getObjectTypeParam()).parallel();
|
||||
return getStreamFor(getObjectTypeParam());
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ public abstract class ReportPolicy extends StrolchPolicy {
|
|||
super(tx);
|
||||
}
|
||||
|
||||
public abstract boolean isParallel();
|
||||
|
||||
public abstract void setI18nData(JsonObject i18nData);
|
||||
|
||||
public abstract void initialize(String reportId);
|
||||
|
|
Loading…
Reference in New Issue