public void extractData(Report report, Map<String, Object> params, BandData rootBand) { List<Map<String, Object>> rootBandData = controllerFactory.defaultController().extractData( contextFactory.context(report.getRootBand(), null, params) ); if (CollectionUtils.isNotEmpty(rootBandData)) { rootBand.getData().putAll(rootBandData.get(0)); } List<ReportBand> firstLevelBands = report.getRootBand().getChildren(); if (firstLevelBands != null) { for (ReportBand definition : firstLevelBands) { List<BandData> bands = createBands(definition, rootBand, params); rootBand.addChildren(bands); rootBand.getFirstLevelBandDefinitionNames().add(definition.getName()); } } }
public void extractData(Report report, Map<String, Object> params, BandData rootBand) { List<Map<String, Object>> rootBandData = controllerFactory.defaultController().extractData( contextFactory.context(report.getRootBand(), null, params) ); if (CollectionUtils.isNotEmpty(rootBandData)) { rootBand.getData().putAll(rootBandData.get(0)); } List<ReportBand> firstLevelBands = report.getRootBand().getChildren(); if (firstLevelBands != null) { for (ReportBand definition : firstLevelBands) { List<BandData> bands = createBands(definition, rootBand, params); rootBand.addChildren(bands); rootBand.getFirstLevelBandDefinitionNames().add(definition.getName()); } } }
root.getFirstLevelBandDefinitionNames().add("Band1");
@Test public void testXlsxCharts() throws Exception { BandData root = new BandData("Root", null, BandOrientation.HORIZONTAL); root.addChild(new BandData("Header", root, BandOrientation.HORIZONTAL)); Random random = new Random(); for (int i = 1; i <= 10; i++) { BandData band = new BandData("Band", root, BandOrientation.HORIZONTAL); band.addData("i", i); double value1 = 15 + i + Math.abs(random.nextDouble()) * 30; band.addData("value1", value1); double value2 = 20 + i + Math.abs(random.nextDouble()) * 60; band.addData("value2", value2); double value3 = 25 + i + Math.abs(random.nextDouble()) * 90; band.addData("value3", value3); band.addData("value4", (value1 + value2 + value3) / 3); root.addChild(band); } root.addChild(new BandData("Charts", root, BandOrientation.HORIZONTAL)); root.setFirstLevelBandDefinitionNames(new HashSet<String>()); root.getFirstLevelBandDefinitionNames().add("Header"); root.getFirstLevelBandDefinitionNames().add("Band"); root.getFirstLevelBandDefinitionNames().add("Charts"); FileOutputStream outputStream = new FileOutputStream("./result/smoke/charts.xlsx"); DefaultFormatterFactory defaultFormatterFactory = new DefaultFormatterFactory(); ReportFormatter formatter = defaultFormatterFactory.createFormatter(new FormatterFactoryInput("xlsx", root, new ReportTemplateImpl("", "./modules/core/test/smoketest/charts.xlsx", "./modules/core/test/smoketest/charts.xlsx", ReportOutputType.xlsx), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); }
protected void fillTables(XDispatchHelper xDispatchHelper) throws com.sun.star.uno.Exception { List<String> tablesNames = TableManager.getTablesNames(xComponent); for (String tableName : tablesNames) { TableManager tableManager = new TableManager(xComponent, tableName); BandFinder bandFinder = new BandFinder(tableManager).find(); BandData band = bandFinder.getBand(); String bandName = bandFinder.getBandName(); int numberOfRowWithAliases = tableManager.findRowWithAliases(); if (band != null && numberOfRowWithAliases > -1) { XTextTable xTextTable = tableManager.getXTextTable(); // try to select one cell without it workaround int columnCount = xTextTable.getColumns().getCount(); if (columnCount < 2) { xTextTable.getColumns().insertByIndex(columnCount, 1); } fillTable(band.getName(), band.getParentBand(), tableManager, xDispatchHelper, numberOfRowWithAliases); // end of workaround -> if (columnCount < 2) { xTextTable.getColumns().removeByIndex(columnCount, 1); } } else if (numberOfRowWithAliases > -1 && rootBand.getFirstLevelBandDefinitionNames() != null && rootBand.getFirstLevelBandDefinitionNames().contains(bandName)) { //if table is linked with band and has aliases on it, but no band data found - //we are removing the row tableManager.deleteRow(numberOfRowWithAliases); } } }
@Test public void testXlsxRowBreaks() throws Exception { BandData root = new BandData("Root", null, BandOrientation.HORIZONTAL); root.addChild(new BandData("Header", root, BandOrientation.HORIZONTAL)); Random random = new Random(); for (int i = 1; i <= 100; i++) { BandData band = new BandData("Band", root, BandOrientation.HORIZONTAL); band.addData("i", i); double value1 = 15 + i + Math.abs(random.nextDouble()) * 30; band.addData("value1", value1); double value2 = 20 + i + Math.abs(random.nextDouble()) * 60; band.addData("value2", value2); double value3 = 25 + i + Math.abs(random.nextDouble()) * 90; band.addData("value3", value3); band.addData("value4", (value1 + value2 + value3) / 3); root.addChild(band); if (i % 10 == 0) { band.addChild(new BandData("Footer", band)); } } root.setFirstLevelBandDefinitionNames(new HashSet<String>()); root.getFirstLevelBandDefinitionNames().add("Header"); root.getFirstLevelBandDefinitionNames().add("Band"); FileOutputStream outputStream = new FileOutputStream("./result/smoke/row_breaks.xlsx"); DefaultFormatterFactory defaultFormatterFactory = new DefaultFormatterFactory(); ReportFormatter formatter = defaultFormatterFactory.createFormatter(new FormatterFactoryInput("xlsx", root, new ReportTemplateImpl("", "./modules/core/test/smoketest/row_breaks.xlsx", "./modules/core/test/smoketest/row_breaks.xlsx", ReportOutputType.xlsx), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); }
@Test public void testHtmlFormatter() throws Exception { BandData root = new BandData("Root", null, BandOrientation.HORIZONTAL); BandData userBand = new BandData("User", root, BandOrientation.HORIZONTAL); userBand.addData("active", true); userBand.addData("login", "admin"); root.addChild(userBand); root.setFirstLevelBandDefinitionNames(new HashSet<String>()); root.getFirstLevelBandDefinitionNames().add("User"); FileOutputStream outputStream = new FileOutputStream("./result/integration/html-groovy-test-result.html"); ReportFormatter formatter = new DefaultFormatterFactory().createFormatter(new FormatterFactoryInput("html", root, new ReportTemplateImpl("", "./modules/core/test/integration/html-groovy-test-template.html", "./modules/core/test/integration/html-groovy-test-template.html", ReportOutputType.html, true), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); File sample = new File("./modules/core/test/integration/html-groovy-test-template-result.html"); File result = new File("./result/integration/html-groovy-test-result.html"); boolean isTwoEqual = FileUtils.contentEqualsIgnoreEOL(sample, result, null); Assert.assertTrue("Files are not equal", isTwoEqual); } }
protected void fillTables(XDispatchHelper xDispatchHelper) throws com.sun.star.uno.Exception { List<String> tablesNames = TableManager.getTablesNames(xComponent); for (String tableName : tablesNames) { TableManager tableManager = new TableManager(xComponent, tableName); BandFinder bandFinder = new BandFinder(tableManager).find(); BandData band = bandFinder.getBand(); String bandName = bandFinder.getBandName(); int numberOfRowWithAliases = tableManager.findRowWithAliases(); if (band != null && numberOfRowWithAliases > -1) { XTextTable xTextTable = tableManager.getXTextTable(); // try to select one cell without it workaround int columnCount = xTextTable.getColumns().getCount(); if (columnCount < 2) { xTextTable.getColumns().insertByIndex(columnCount, 1); } fillTable(band.getName(), band.getParentBand(), tableManager, xDispatchHelper, numberOfRowWithAliases); // end of workaround -> if (columnCount < 2) { xTextTable.getColumns().removeByIndex(columnCount, 1); } } else if (numberOfRowWithAliases > -1 && rootBand.getFirstLevelBandDefinitionNames() != null && rootBand.getFirstLevelBandDefinitionNames().contains(bandName)) { //if table is linked with band and has aliases on it, but no band data found - //we are removing the row tableManager.deleteRow(numberOfRowWithAliases); } } }
root.getFirstLevelBandDefinitionNames().add("Band1"); root.getFirstLevelBandDefinitionNames().add("Band2"); root.getFirstLevelBandDefinitionNames().add("Band3"); root.getFirstLevelBandDefinitionNames().add("Split1"); root.getFirstLevelBandDefinitionNames().add("Split2");
@Test public void testSqlExtractionForCrosstabBand() throws IOException, URISyntaxException { ReportBand band = YmlDataUtil.bandFrom(FileLoader.load("extraction/fixture/cross_sql_report_band.yml")); BandData rootBand = new BandData(BandData.ROOT_BAND_NAME); rootBand.setData(new HashMap<>()); rootBand.setFirstLevelBandDefinitionNames(new HashSet<>()); Multimap<String, BandData> reportBandMap = HashMultimap.create(); for (ReportBand definition : band.getChildren()) { List<BandData> data = controllerFactory.controllerBy(definition.getBandOrientation()) .extract(contextFactory.context(definition, rootBand, new HashMap<>())); Assert.assertNotNull(data); data.forEach(b-> { Assert.assertNotNull(b); Assert.assertTrue(StringUtils.isNotEmpty(b.getName())); reportBandMap.put(b.getName(), b); }); rootBand.addChildren(data); rootBand.getFirstLevelBandDefinitionNames().add(definition.getName()); } checkHeader(reportBandMap.get("crosstab_header"), 12, "MONTH_NAME", "MONTH_ID"); checkMasterData(reportBandMap.get("crosstab_master_data"), 3, 12, "USER_ID", "LOGIN", "HOURS"); }
@Test public void testGroovyExtractionForBand() throws IOException, URISyntaxException { ReportBand band = YmlDataUtil.bandFrom(FileLoader.load("extraction/fixture/cross_groovy_report_band.yml")); BandData rootBand = new BandData(BandData.ROOT_BAND_NAME); rootBand.setData(new HashMap<>()); rootBand.setFirstLevelBandDefinitionNames(new HashSet<>()); Multimap<String, BandData> reportBandMap = HashMultimap.create(); for (ReportBand definition : band.getChildren()) { List<BandData> data = controllerFactory.controllerBy(definition.getBandOrientation()) .extract(contextFactory.context(definition, rootBand, new HashMap<>())); Assert.assertNotNull(data); data.forEach(b-> { Assert.assertNotNull(b); Assert.assertTrue(StringUtils.isNotEmpty(b.getName())); reportBandMap.put(b.getName(), b); }); rootBand.addChildren(data); rootBand.getFirstLevelBandDefinitionNames().add(definition.getName()); } checkHeader(reportBandMap.get("crosstab_header"), 2, "name", "id"); checkMasterData(reportBandMap.get("crosstab_master_data"), 2, 2, "id", "name", "crosstab_dynamic_header_id", "crosstab_master_data_id", "value"); }
@Test public void testSqlExtractionForCrosstabBand() throws IOException, URISyntaxException { ReportBand band = YmlDataUtil.bandFrom(FileLoader.load("extraction/fixture/default_sql_report_band.yml")); BandData rootBand = new BandData(BandData.ROOT_BAND_NAME); rootBand.setData(new HashMap<>()); rootBand.setFirstLevelBandDefinitionNames(new HashSet<>()); Multimap<String, BandData> reportBandMap = HashMultimap.create(); for (ReportBand definition : band.getChildren()) { List<BandData> data = controllerFactory.controllerBy(definition.getBandOrientation()) .extract(contextFactory.context(definition, rootBand, new HashMap<>())); Assert.assertNotNull(data); data.forEach(b-> { Assert.assertNotNull(b); Assert.assertTrue(StringUtils.isNotEmpty(b.getName())); reportBandMap.put(b.getName(), b); }); rootBand.addChildren(data); rootBand.getFirstLevelBandDefinitionNames().add(definition.getName()); } checkHeader(reportBandMap.get("header"), 12, "MONTH_NAME", "MONTH_ID"); checkMasterData(reportBandMap.get("master_data"), 3, 12, "USER_ID", "LOGIN", "HOURS"); }
@Test public void testGroovyExtractionForBand() throws IOException, URISyntaxException { ReportBand band = YmlDataUtil.bandFrom(FileLoader.load("extraction/fixture/default_groovy_report_band.yml")); BandData rootBand = new BandData(BandData.ROOT_BAND_NAME); rootBand.setData(new HashMap<>()); rootBand.setFirstLevelBandDefinitionNames(new HashSet<>()); Multimap<String, BandData> reportBandMap = HashMultimap.create(); for (ReportBand definition : band.getChildren()) { List<BandData> data = controllerFactory.controllerBy(definition.getBandOrientation()) .extract(contextFactory.context(definition, rootBand, new HashMap<>())); Assert.assertNotNull(data); data.forEach(b-> { Assert.assertNotNull(b); Assert.assertTrue(StringUtils.isNotEmpty(b.getName())); reportBandMap.put(b.getName(), b); }); rootBand.addChildren(data); rootBand.getFirstLevelBandDefinitionNames().add(definition.getName()); } checkHeader(reportBandMap.get("header"), 2, "name", "id"); checkMasterData(reportBandMap.get("master_data"), 2, 2, "id", "name", "value", "user_id"); }
@Test public void testJsonExtractionForBand() throws IOException, URISyntaxException { ReportBand band = YmlDataUtil.bandFrom(FileLoader.load("extraction/fixture/default_json_report_band.yml")); BandData rootBand = new BandData(BandData.ROOT_BAND_NAME); rootBand.setData(new HashMap<>()); rootBand.setFirstLevelBandDefinitionNames(new HashSet<>()); Multimap<String, BandData> reportBandMap = HashMultimap.create(); for (ReportBand definition : band.getChildren()) { List<BandData> data = controllerFactory.controllerBy(definition.getBandOrientation()) .extract(contextFactory.context(definition, rootBand, ExtractionUtils.getParams(definition))); Assert.assertNotNull(data); data.forEach(b-> { Assert.assertNotNull(b); Assert.assertTrue(StringUtils.isNotEmpty(b.getName())); reportBandMap.put(b.getName(), b); }); rootBand.addChildren(data); rootBand.getFirstLevelBandDefinitionNames().add(definition.getName()); } checkHeader(reportBandMap.get("header"), 2, "name", "id"); checkMasterData(reportBandMap.get("master_data"), 2, 2, "id", "name", "value", "user_id"); }
private BandData createRootBandForAggregation() { BandData root = new BandData("Root", null, BandOrientation.HORIZONTAL); HashMap<String, Object> rootData = new HashMap<String, Object>(); root.setData(rootData); BandData band1_1 = band(1, 2, BandOrientation.HORIZONTAL, null, "Band1"); BandData band2_1 = band(11, 22, BandOrientation.HORIZONTAL, null, "Band2"); BandData band2_2 = band(12, 23, BandOrientation.HORIZONTAL, null, "Band2"); band1_1.addChildren(Arrays.asList(band2_1, band2_2)); BandData band1_2 = band(2, 3, BandOrientation.HORIZONTAL, null, "Band1"); BandData band2_3 = band(13, 24, BandOrientation.HORIZONTAL, null, "Band2"); BandData band3_1 = band(111, null, BandOrientation.VERTICAL, band2_3, "Band3"); BandData band3_2 = band(222, null, BandOrientation.VERTICAL, band2_3, "Band3"); band1_2.addChildren(Collections.singletonList(band2_3)); band2_3.addChildren(Arrays.asList(band3_1, band3_2)); BandData band1_3 = band(3, 4, BandOrientation.HORIZONTAL, null, "Band1"); root.addChild(band1_1); root.addChild(band1_2); root.addChild(band1_3); root.setFirstLevelBandDefinitionNames(new HashSet<String>()); root.getFirstLevelBandDefinitionNames().add("Band1"); return root; }
rootBand.getFirstLevelBandDefinitionNames().add(definition.getName());
root.getFirstLevelBandDefinitionNames().add("Header"); root.getFirstLevelBandDefinitionNames().add("DateHeader"); root.getFirstLevelBandDefinitionNames().add("Band1");
@Test public void testXlsxCrosstabFeature() throws Exception { FileOutputStream outputStream = new FileOutputStream("./result/integration/result-crosstab-feature.xlsx"); ReportBand band = YmlDataUtil.bandFrom(FileLoader.load("integration/fixture/cross_sql_report_band.yml")); BandData rootBand = new BandData(BandData.ROOT_BAND_NAME); rootBand.setData(new HashMap<>()); rootBand.setFirstLevelBandDefinitionNames(new HashSet<>()); for (ReportBand definition : band.getChildren()) { List<BandData> data = controllerFactory.controllerBy(definition.getBandOrientation()) .extract(contextFactory.context(definition, rootBand, new HashMap<>())); assertNotNull(data); data.forEach(b-> { assertNotNull(b); assertTrue(StringUtils.isNotEmpty(b.getName())); }); rootBand.addChildren(data); rootBand.getFirstLevelBandDefinitionNames().add(definition.getName()); } DefaultFormatterFactory defaultFormatterFactory = new DefaultFormatterFactory(); ReportFormatter formatter = defaultFormatterFactory.createFormatter( new FormatterFactoryInput("xlsx", rootBand, new ReportTemplateImpl("", "./modules/core/test/integration/test-crosstab-feature.xlsx", "./modules/core/test/integration/test-crosstab-feature.xlsx", ReportOutputType.xlsx), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); compareFiles("./result/integration/result-crosstab-feature.xlsx", "./modules/core/test/integration/etalon-crosstab-feature.xlsx"); }
root.getFirstLevelBandDefinitionNames().add("Band1"); root.getFirstLevelBandDefinitionNames().add("Band2");
root.getFirstLevelBandDefinitionNames().add("Band1");