protected BandData createNewBand(String bandName) { BandData newParentBand = new BandData(bandName); List<BandData> childrenList = root.getChildrenByName(bandName); root.getChildrenBands().remove(bandName); newParentBand.addChildren(childrenList); childrenList.forEach(childBand -> childBand.setParentBand(newParentBand)); visitedBands.put(newParentBand, newParentBand.getChildrenList().iterator()); return newParentBand; }
protected BandData createNewBand(String bandName) { BandData newParentBand = new BandData(bandName); List<BandData> childrenList = root.getChildrenByName(bandName); root.getChildrenBands().remove(bandName); newParentBand.addChildren(childrenList); childrenList.forEach(childBand -> childBand.setParentBand(newParentBand)); visitedBands.put(newParentBand, newParentBand.getChildrenList().iterator()); return newParentBand; }
protected BandData loadBandData(Report report, Map<String, Object> handledParams) { BandData rootBand = new BandData(BandData.ROOT_BAND_NAME); rootBand.setData(new HashMap<>(handledParams)); rootBand.addReportFieldFormats(report.getReportFieldFormats()); rootBand.setFirstLevelBandDefinitionNames(new HashSet<>()); dataExtractor.extractData(report, handledParams, rootBand); return rootBand; }
protected BandData loadBandData(Report report, Map<String, Object> handledParams) { BandData rootBand = new BandData(BandData.ROOT_BAND_NAME); rootBand.setData(new HashMap<>(handledParams)); rootBand.addReportFieldFormats(report.getReportFieldFormats()); rootBand.setFirstLevelBandDefinitionNames(new HashSet<>()); dataExtractor.extractData(report, handledParams, rootBand); return rootBand; }
private BandData band(int col1, Integer col2, BandOrientation orientation, BandData parentBand, String name) { BandData band1_1 = new BandData(name, parentBand, orientation); Map<String, Object> datamap = new HashMap<String, Object>(); datamap.put("col1", col1); datamap.put("col2", col2); band1_1.setData(datamap); return band1_1; } }
@Override protected BandData wrapData(ExtractionContext context, Map<String, Object> data) { final BandData bandData = new BandData(context.getBand().getName(), context.getParentBandData(), BandOrientation.VERTICAL); bandData.setData(ObjectUtils.defaultIfNull(data, new HashMap<>())); return bandData; }
@Override protected BandData wrapData(ExtractionContext context, Map<String, Object> data) { final BandData bandData = new BandData(context.getBand().getName(), context.getParentBandData(), BandOrientation.VERTICAL); bandData.setData(ObjectUtils.defaultIfNull(data, new HashMap<>())); return bandData; }
private BandData rootBand() { BandData rootBand = new BandData(BandData.ROOT_BAND_NAME); rootBand.setData(new HashMap<String, Object>()); rootBand.setFirstLevelBandDefinitionNames(new HashSet<String>()); return rootBand; }
private BandData band(String name, BandData root) { BandData band1 = new BandData(name, root, BandOrientation.HORIZONTAL); band1.setData(new HashMap<>()); root.addChild(band1); return band1; }
private BandData createBand(String name, BandData root, BandOrientation horizontal) { BandData hor11 = new BandData(name, root, horizontal); hor11.setData(new ConstantMap(name)); return hor11; }
private AbstractFormatter createFormatter(String formatName, String formatValue) { BandData rootBand = new BandData(BandData.ROOT_BAND_NAME); rootBand.addReportFieldFormats(Collections.singletonList(new ReportFieldFormatImpl(formatName, formatValue))); FormatterFactoryInput formatterFactoryInput = new FormatterFactoryInput("xlsx", rootBand, reportTemplate, ReportOutputType.xlsx, null); return new AbstractFormatter(formatterFactoryInput) { @Override public void renderDocument() { } }; } }
@Test public void testReplaceSingleCondition() throws Exception { String query = "select id as id from user where id = ${param1}"; HashMap<String, Object> params = new HashMap<String, Object>(); AbstractDbDataLoader.QueryPack queryPack = prepareQuery(query, new BandData(""), params); System.out.println(queryPack.getQuery()); Assert.assertFalse(queryPack.getQuery().contains("${")); writeParams(queryPack); params.put("param1", "param1"); queryPack = prepareQuery(query, new BandData(""), params); System.out.println(queryPack.getQuery()); Assert.assertEquals(1, StringUtils.countMatches(queryPack.getQuery(), "?")); writeParams(queryPack); }
private BandData randomBand(String name, BandData root) { BandData band1 = new BandData(name, root, BandOrientation.HORIZONTAL); band1.setData(new RandomMap()); root.addChild(band1); return band1; }
private BandData createBand(String name, int multiplier, BandData root, BandOrientation childOrient) { BandData band1_1 = new BandData(name, root, BandOrientation.HORIZONTAL); band1_1.addData("col1", 1 * multiplier); band1_1.addData("col2", 2 * multiplier); BandData band11_1 = new BandData(name + "1", band1_1, childOrient); band11_1.addData("col1", 10 * multiplier); band11_1.addData("col2", 20 * multiplier); BandData band11_2 = new BandData(name + "1", band1_1, childOrient); band11_2.addData("col1", 100 * multiplier); band11_2.addData("col2", 200 * multiplier); band1_1.addChild(band11_1); band1_1.addChild(band11_2); return band1_1; }
@Test public void testUrl() throws Exception { BandData root = new BandData("Root", null, BandOrientation.HORIZONTAL); HashMap<String, Object> rootData = new HashMap<>(); rootData.put("url", "https://www.google.ru/#newwindow=1&q=YARG"); rootData.put("urlCaption", "URL"); root.setData(rootData); FileOutputStream outputStream = new FileOutputStream("./result/smoke/url.docx"); ReportFormatter formatter = new DefaultFormatterFactory().createFormatter(new FormatterFactoryInput("docx", root, new ReportTemplateImpl("", "./modules/core/test/smoketest/url.docx", "./modules/core/test/smoketest/url.docx", ReportOutputType.docx), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); }
@Test public void testAggregationsEmpty() throws Exception { BandData root = new BandData("Root", null, BandOrientation.HORIZONTAL); HashMap<String, Object> rootData = new HashMap<String, Object>(); root.setData(rootData); FileOutputStream outputStream = new FileOutputStream("./result/integration/result-empty.xls"); ReportFormatter formatter = new DefaultFormatterFactory().createFormatter(new FormatterFactoryInput("xls", root, new ReportTemplateImpl("", "smoketest/test.xls", "./modules/core/test/integration/test-with-aggregation.xls", ReportOutputType.xls), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); compareFiles("./modules/core/test/integration/etalon-empty.xls", "./result/integration/result-empty.xls"); }
@Test public void testGroovyLoader() throws Exception { GroovyDataLoader groovyDataLoader = new GroovyDataLoader(new DefaultScriptingImpl()); BandData rootBand = new BandData("band1", null, BandOrientation.HORIZONTAL); rootBand.setData(Collections.<String, Object>emptyMap()); List<Map<String, Object>> result = groovyDataLoader.loadData( new ReportQueryImpl("", "return [['a':123, 'b':321], ['a':456, 'b':654]]", "groovy", null, null) , rootBand, Collections.<String, Object>emptyMap()); printResult(result); }
@Test public void testDocxToHtml() throws Exception { BandData root = createRootBand(); root.addReportFieldFormats(Collections.singletonList(new ReportFieldFormatImpl("Band1.col2", "${html}"))); BandData footer = root.getChildByName("Footer"); BandData footerChild = new BandData("FooterChild", footer); footerChild.addData("nestedData", "NESTED_DATA"); footer.addChild(footerChild); FileOutputStream outputStream = new FileOutputStream("./result/smoke/result_docx.html"); ReportFormatter formatter = new DefaultFormatterFactory().createFormatter(new FormatterFactoryInput("docx", root, new ReportTemplateImpl("", "./modules/core/test/smoketest/test.docx", "./modules/core/test/smoketest/test.docx", ReportOutputType.html), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); }
@Test public void testDocx() throws Exception { BandData root = createRootBand(); root.addReportFieldFormats(Collections.singletonList(new ReportFieldFormatImpl("Band1.col2", "${html}"))); BandData footer = root.getChildByName("Footer"); BandData footerChild = new BandData("FooterChild", footer); footerChild.addData("nestedData", "NESTED_DATA"); footerChild.addData("nestedData.withPoint", "NESTED_DATA_WITH_POINT"); footer.addChild(footerChild); FileOutputStream outputStream = new FileOutputStream("./result/smoke/result.docx"); ReportFormatter formatter = new DefaultFormatterFactory().createFormatter(new FormatterFactoryInput("docx", root, new ReportTemplateImpl("", "./modules/core/test/smoketest/test.docx", "./modules/core/test/smoketest/test.docx", ReportOutputType.docx), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); }
@Test public void testDocxToPdf() throws Exception { BandData root = createRootBand(); BandData footer = root.getChildByName("Footer"); BandData footerChild = new BandData("FooterChild", footer); footerChild.addData("nestedData", "NESTED_DATA"); footer.addChild(footerChild); FileOutputStream outputStream = new FileOutputStream("./result/smoke/result_docx.pdf"); DefaultFormatterFactory defaultFormatterFactory = new DefaultFormatterFactory(); defaultFormatterFactory.setOfficeIntegration(new OfficeIntegration(openOfficePath, 8100)); ReportFormatter formatter = defaultFormatterFactory.createFormatter(new FormatterFactoryInput("docx", root, new ReportTemplateImpl("", "./modules/core/test/smoketest/test.docx", "./modules/core/test/smoketest/test.docx", ReportOutputType.pdf), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); }