diff --git a/src/main/java/de/quinscape/automaton/runtime/export/excel/ExcelExporter.java b/src/main/java/de/quinscape/automaton/runtime/export/excel/ExcelExporter.java index 421f9bc..e144e76 100644 --- a/src/main/java/de/quinscape/automaton/runtime/export/excel/ExcelExporter.java +++ b/src/main/java/de/quinscape/automaton/runtime/export/excel/ExcelExporter.java @@ -3,6 +3,7 @@ import de.quinscape.automaton.runtime.export.ExportResult; import de.quinscape.automaton.runtime.export.GraphQLExporter; import de.quinscape.automaton.runtime.export.GraphQLQueryContext; +import de.quinscape.automaton.runtime.util.SchemaReference; import de.quinscape.domainql.DomainQL; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.slf4j.Logger; @@ -10,13 +11,14 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.util.function.Predicate; /** * GraphQLExport implementation for Excel sheets. Can be configured via builder including a strategy of how many * queries to export into how many excel sheets. * - * @see #newExporter(DomainQL) + * @see #newExporter(DomainQL) */ public class ExcelExporter implements GraphQLExporter @@ -27,14 +29,15 @@ public class ExcelExporter public final static String EXCEL_MEDIA_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; - private final DomainQL domainQL; + private final String metaHeadingName; private final String mediaType; private final ExportStrategy exportStrategy; + ExcelExporter( DomainQL domainQL, ExportStrategy exportStrategy, @@ -48,6 +51,7 @@ public class ExcelExporter this.mediaType = mediaType; } + @Override public ExportResult export(GraphQLQueryContext ctx) throws IOException { @@ -74,7 +78,6 @@ public ExportResult export(GraphQLQueryContext ctx) throws IOException } - /** * Expects a single result that is converted into an Excel sheet name with a configured name, exporting the Excel * file under a configured name. @@ -84,16 +87,44 @@ public static class OneQueryStrategy { public final static OneQueryStrategy DEFAULT = new OneQueryStrategy( "Automaton Export", - "automaton-$now.xlsx"); + "automaton-$now.xlsx" + ); + + private final static Predicate ALL_FILES = ref -> true; private final String sheetName; + private final String fileName; + private final Predicate fieldPredicate; + + /** + * Creates a new OneQueryStrategy with the given sheet name and the given file name and a predicate to filter + * the fields. + * + * @param sheetName sheet name + * @param fileName filename (with optional "$now" placeholder) + */ public OneQueryStrategy(String sheetName, String fileName) + { + this(sheetName, fileName, ALL_FILES); + } + + + /** + * Creates a new OneQueryStrategy with the given sheet name and the given file name and a predicate to filter + * the fields. + * + * @param sheetName sheet name + * @param fileName filename (with optional "$now" placeholder) + * @param fieldPredicate field predicate + */ + public OneQueryStrategy(String sheetName, String fileName, Predicate fieldPredicate) { this.sheetName = sheetName; this.fileName = fileName; + this.fieldPredicate = fieldPredicate; } @@ -101,11 +132,12 @@ public OneQueryStrategy(String sheetName, String fileName) public String generateExport(ExcelExporterContext ctx, GraphQLQueryContext queryContext) { final GraphQLQueryContext.MethodResult mr = queryContext.getOnlyResult(); - ctx.addSheet(sheetName, mr); + ctx.addSheet(sheetName, mr, fieldPredicate); return fileName; } } + public static ExcelExporterBuilder newExporter(DomainQL domainQL) { return new ExcelExporterBuilder(domainQL);