@Test public void testCanvasWithPrePostPad() throws Exception { final MasterReport report = new MasterReport(); report.setDataFactory(new TableDataFactory("query", new DefaultTableModel(10, 1))); report.setQuery("query"); final Band table = TableTestUtil.createTable(1, 1, 6, new CustomProducer()); table.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, 200f); table.getStyle().setStyleProperty(ElementStyleKeys.POS_X, 100f); table.getStyle().setStyleProperty(ElementStyleKeys.POS_Y, 10f); table.setName("table"); report.getReportHeader().addElement(TableTestUtil.createDataItem("Pre-Padding", 100, 10)); report.getReportHeader().addElement(table); Element postPaddingItem = TableTestUtil.createDataItem("Post-Padding", 100, 10); postPaddingItem.getStyle().setStyleProperty(ElementStyleKeys.POS_X, 300f); report.getReportHeader().addElement(postPaddingItem); report.getReportHeader().setLayout("canvas"); PdfReportUtil.createPDF(report, "test-output/PRD-3857-output-canvas.pdf"); List<LogicalPageBox> pages = DebugReportRunner.layoutPages(report, 0, 1, 2); assertPageValid(pages, 0, StrictGeomUtility.toInternalValue(10)); assertPageValid(pages, 1); assertPageValid(pages, 2); }
public void testStandardReport2() throws Exception { if (DebugReportRunner.isSkipLongRunTest()) { return; } final MasterReport report = DebugReportRunner.parseGoldenSampleReport("Prd-3857-001.prpt"); final Group rootGroup = report.getRootGroup(); assertTrue(rootGroup instanceof CrosstabGroup); final CrosstabGroup ct = (CrosstabGroup) rootGroup; ct.setPrintColumnTitleHeader(false); ct.setPrintDetailsHeader(false); // Prints two header rows, and 21 data rows (row 0 to row 20) List<LogicalPageBox> logicalPageBoxes = DebugReportRunner.layoutPages(report, 0, 1); final LogicalPageBox boxP1 = logicalPageBoxes.get(0); // ModelPrinter.INSTANCE.print(boxP1); final RenderNode[] rowsPage1 = MatchFactory.findElementsByNodeType(boxP1, LayoutNodeTypes.TYPE_BOX_TABLE_ROW); assertEquals(23, rowsPage1.length); // Prints two header rows and 7 data rows (row 21 to row 27) final LogicalPageBox boxP2 = logicalPageBoxes.get(1); // ModelPrinter.INSTANCE.print(boxP2); final RenderNode[] rowsPage2 = MatchFactory.findElementsByNodeType(boxP2, LayoutNodeTypes.TYPE_BOX_TABLE_ROW); assertEquals(9, rowsPage2.length); }
public void redo(final ReportDocumentContext renderContext) { final MasterReport report = renderContext.getContextRoot(); final WriteableDocumentBundle bundle = (WriteableDocumentBundle) report.getBundle(); final WriteableDocumentMetaData metaData = bundle.getWriteableDocumentMetaData(); metaData.setBundleAttribute( ODFMetaAttributeNames.Meta.NAMESPACE, ODFMetaAttributeNames.Meta.KEYWORDS, newMetaData.getBundleAttribute( ODFMetaAttributeNames.Meta.NAMESPACE, ODFMetaAttributeNames.Meta.KEYWORDS)); metaData.setBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.CREATOR, newMetaData.getBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.CREATOR)); metaData.setBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.DESCRIPTION, newMetaData.getBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.DESCRIPTION)); metaData.setBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.SUBJECT, newMetaData.getBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.SUBJECT)); metaData.setBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.TITLE, newMetaData.getBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.TITLE)); report.notifyNodePropertiesChanged(); }
public void testRowBoxesEstablishOwnBlockContext() throws Exception { // this report defines that the group as well as all bands within that group are row-layout. // therefore the two itembands end on the same row. // The itemband did not define a width, not even a 100% width, and thus ends with a width of // auto/zero. // therefore the itemband shrinks to the minimal size that still encloses all elements. // the elements that have percentage width are resolved against the block context. // A band without a width defined (the itemband!), does not establish an own block-context, so // it // takes the block context of the parent, or as fallback: page. final File file = GoldTestBase.locateGoldenSampleReport("Prd-3479.prpt"); final ResourceManager mgr = new ResourceManager(); mgr.registerDefaults(); final Resource directly = mgr.createDirectly(file, MasterReport.class); final MasterReport report = (MasterReport) directly.getResource(); report.setCompatibilityLevel(null); final LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage(report, 0); final RenderNode[] itembands = MatchFactory.findElementsByElementType(logicalPageBox, ItemBandType.INSTANCE); assertEquals(2, itembands.length); assertEquals(48208843, itembands[0].getWidth()); assertEquals(48208843, itembands[1].getWidth()); assertEquals(48208843, itembands[1].getX()); }
protected void inspect(final AbstractReportDefinition reportDefinition) { if (reportDefinition instanceof MasterReport) { final MasterReport mr = (MasterReport) reportDefinition; final ReportParameterDefinition parameters = mr.getParameterDefinition(); final ParameterDefinitionEntry[] entries = parameters.getParameterDefinitions(); for (int i = 0; i < entries.length; i++) { final ParameterDefinitionEntry entry = entries[i]; inspectParameter(reportDefinition, parameters, entry); } } final CompoundDataFactory dataFactory = CompoundDataFactory.normalize(reportDefinition.getDataFactory(), false); final int size = dataFactory.size(); for (int i = 0; i < size; i++) { inspectDataSource(reportDefinition, dataFactory); } final ExpressionCollection expressions = reportDefinition.getExpressions(); final Expression[] expressionsArray = expressions.getExpressions(); for (int i = 0; i < expressionsArray.length; i++) { final Expression expression = expressionsArray[i]; inspectExpression(reportDefinition, expression); } inspectElement(reportDefinition); traverseSection(reportDefinition); }
@Test public void testTableColumns() throws Exception { final MasterReport report = DebugReportRunner.parseGoldenSampleReport("Prd-4523.prpt"); report .getReportConfiguration() .setConfigProperty(ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY, "false"); LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage(report, 0); RenderNode[] elementsByNodeType = MatchFactory.findElementsByNodeType(logicalPageBox, LayoutNodeTypes.TYPE_BOX_TABLE); assertEquals(1, elementsByNodeType.length); TableRenderBox table = (TableRenderBox) elementsByNodeType[0]; long width = table.getWidth(); DebugLog.log(width); SeparateColumnModel columnModel = (SeparateColumnModel) table.getColumnModel(); long sum = 0; final ArrayList<TableColumn> expected = new ArrayList<TableColumn>(); expected.add(createTableColumn(4748666, 4222000, 0, 0, 0)); expected.add(createTableColumn(4694666, 4168000, 0, 0, 0)); expected.add(createTableColumn(8415666, 7889000, 0, 0, 2824000)); expected.add(createTableColumn(8415666, 7889000, 0, 0, 0)); expected.add(createTableColumn(8415666, 7889000, 0, 0, 0)); expected.add(createTableColumn(8415666, 7889000, 0, 0, 0)); expected.add(createTableColumn(8415666, 7889000, 0, 0, 2824000)); expected.add(createTableColumn(8415666, 7889000, 0, 0, 0)); expected.add(createTableColumn(8415666, 7889000, 0, 0, 0)); expected.add(createTableColumn(8415666, 7889000, 0, 0, 0)); expected.add(createTableColumn(8415666, 7889000, 2824000, 0, 0)); expected.add(createTableColumn(8415666, 7889000, 0, 0, 0)); TableColumn[] columns = columnModel.getColumns(); for (int i = 0; i < columns.length; i += 1) { TableColumn c = columnModel.getColumn(i); assertColumnsEqual(expected.get(i), c); } }
/** * Validate that the banded subreport contained in an inline subreport page-footer content DOES * NOT show up in the layout-editor * * @throws Exception */ public void testInlineBandedSubReport() throws Exception { final URL resource = getClass().getResource("Prd-4637.prpt"); assertNotNull(resource); final ResourceManager mgr = new ResourceManager(); mgr.registerDefaults(); final MasterReport report = (MasterReport) mgr.createDirectly(resource, MasterReport.class).getResource(); final GlobalAuthenticationStore globalAuthenticationStore = new GlobalAuthenticationStore(); final ReportRenderContext masterContext = new ReportRenderContext(report, report, null, globalAuthenticationStore); final SubReport subReport = (SubReport) report.getReportHeader().getElement(0); final ReportRenderContext subContext = new ReportRenderContext(report, subReport, masterContext, globalAuthenticationStore); final SubReport subReport2 = subReport.getReportHeader().getSubReport(0); final ReportRenderContext subSubContext = new ReportRenderContext(report, subReport2, subContext, globalAuthenticationStore); final TestRootBandRenderer r = new TestRootBandRenderer(subReport.getPageFooter(), subSubContext); final ValidateTextGraphics graphics2D = new ValidateTextGraphics(468, 108); graphics2D.expect("Any Text Printed Is An Error!"); assertTrue(graphics2D.hitClip(10, 10, 1, 1)); r.draw(graphics2D); }
public void testMissingTableRow() throws ReportProcessingException, ContentProcessingException { final Band tableBody = new Band(); tableBody.getStyle().setStyleProperty(BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_TABLE_BODY); tableBody.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, -100f); tableBody.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, 200f); final Band table = new Band(); table.getStyle().setStyleProperty(BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_TABLE); table.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, -100f); table.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, 200f); table.addElement(TableTestUtil.createAutoBox(tableBody)); final MasterReport report = new MasterReport(); final ReportHeader band = report.getReportHeader(); band.addElement(table); final LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand(report, band, false, false); // ModelPrinter.print(logicalPageBox); final DescendantMatcher matcher = new DescendantMatcher(new ElementMatcher("TableCellRenderBox")); final RenderNode[] all = MatchFactory.matchAll(logicalPageBox, matcher); assertEquals(0, all.length); }
public void testRun() throws Exception { final URL url = getClass().getResource("Pre-492.prpt"); assertNotNull(url); final ResourceManager resourceManager = new ResourceManager(); resourceManager.registerDefaults(); final Resource directly = resourceManager.createDirectly(url, MasterReport.class); final MasterReport report = (MasterReport) directly.getResource(); try { final ZipRepository zipRepository = new ZipRepository(new NullOutputStream()); final ContentLocation root = zipRepository.getRoot(); final ContentLocation data = RepositoryUtilities.createLocation( zipRepository, RepositoryUtilities.splitPath("data", "/")); final DebugFlowOutputProcessor outputProcessor = new DebugFlowOutputProcessor(); final HtmlPrinter printer = new AllItemsHtmlPrinter(report.getResourceManager()); printer.setContentWriter(root, new DefaultNameGenerator(root, "report")); printer.setDataWriter(data, new DefaultNameGenerator(data, "content")); printer.setUrlRewriter(new SingleRepositoryURLRewriter()); outputProcessor.setPrinter(printer); final FlowReportProcessor sp = new FlowReportProcessor(report, outputProcessor); sp.processReport(); sp.close(); zipRepository.close(); } catch (IOException ioe) { throw ioe; } catch (ReportProcessingException re) { throw re; } catch (Exception re) { throw new ReportProcessingException("Failed to process the report", re); } }
public void testErrorHandlingBad() throws Exception { final URL url = getClass().getResource("Prd-3985.prpt"); final ResourceManager mgr = new ResourceManager(); final MasterReport report = (MasterReport) mgr.createDirectly(url, MasterReport.class).getResource(); report .getReportConfiguration() .setConfigProperty( "org.pentaho.reporting.engine.classic.core.FailOnAttributeExpressionErrors", "true"); final FormulaExpression function = new FormulaExpression(); function.setName("Test"); function.setFormula("=MULTIVALUEQUERY(\"Bad\")"); report .getReportHeader() .setAttributeExpression(AttributeNames.Core.NAMESPACE, AttributeNames.Core.NAME, function); try { DebugReportRunner.createPDF(report); Assert.fail(); } catch (Exception e) { // ignored } }
public void valueChanged(final ListSelectionEvent e) { final Object value = queryNameList.getSelectedValue(); if (value == null) { nameTextField.setEnabled(false); fileTextField.setEnabled(false); stepsList.setEnabled(false); editParameterAction.setEnabled(false); return; } inUpdateFromList = true; nameTextField.setEnabled(true); fileTextField.setEnabled(true); final AbstractReportDefinition report = designTimeContext.getReport(); final MasterReport masterReport = DesignTimeUtil.getMasterReport(report); final ResourceKey contentBase; if (masterReport == null) { contentBase = null; } else { contentBase = masterReport.getContentBase(); } try { final KettleQueryEntry selectedQuery = (KettleQueryEntry) value; fileTextField.setText(selectedQuery.getFile()); nameTextField.setText(selectedQuery.getName()); final StepMeta[] data = selectedQuery.getSteps(report.getResourceManager(), contentBase); stepsList.setListData(data); final String selectedStepName = selectedQuery.getSelectedStep(); if (selectedStepName != null) { for (int i = 0; i < data.length; i++) { final StepMeta stepMeta = data[i]; if (selectedStepName.equals(stepMeta.getName())) { stepsList.setSelectedValue(stepMeta, true); break; } } } stepsList.setEnabled(true); editParameterAction.setEnabled(true); } catch (ReportDataFactoryException rdfe) { logger.warn("Non-critical failure while executing the query", rdfe); stepsList.setEnabled(false); editParameterAction.setEnabled(false); } catch (Exception e1) { designTimeContext.error(e1); stepsList.setEnabled(false); editParameterAction.setEnabled(false); } catch (Throwable t1) { designTimeContext.error(new StackableRuntimeException("Fatal error", t1)); stepsList.setEnabled(false); editParameterAction.setEnabled(false); } finally { inUpdateFromList = false; } }
public void testGoldRun() throws Exception { final File file = GoldTestBase.locateGoldenSampleReport("Prd-3239.prpt"); final ResourceManager mgr = new ResourceManager(); mgr.registerDefaults(); final Resource directly = mgr.createDirectly(file, MasterReport.class); final MasterReport report = (MasterReport) directly.getResource(); report.setCompatibilityLevel(ClassicEngineBoot.computeVersionId(3, 8, 0)); DebugReportRunner.createXmlFlow(report); }
@Test public void testComplexCrosstab() throws ResourceException, ReportProcessingException { final MasterReport report = DebugReportRunner.parseGoldenSampleReport("Prd-4523.prpt"); report .getReportConfiguration() .setConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.table.base.FailOnCellConflicts", "true"); HtmlReportUtil.createStreamHTML(report, new NullOutputStream()); }
public Object clone() throws CloneNotSupportedException { final MailDefinition mailDefinition = (MailDefinition) super.clone(); mailDefinition.bodyReport = (MasterReport) bodyReport.clone(); mailDefinition.attachmentTypes = (ArrayList) attachmentTypes.clone(); mailDefinition.attachmentReports = (ArrayList) attachmentReports.clone(); mailDefinition.attachmentReports.clear(); for (int i = 0; i < attachmentReports.size(); i++) { final MasterReport report = (MasterReport) attachmentReports.get(i); mailDefinition.attachmentReports.add(report.clone()); } return mailDefinition; }
@Override protected boolean performExport(final MasterReport report, final OutputStream outputStream) { try { String dataDirectory = getInputStringValue(AbstractJFreeReportComponent.REPORTDIRECTORYHTML_DATADIR); if (dataDirectory == null) { dataDirectory = "data"; // $NON-NLS-1$ } final ZipRepository zipRepository = new ZipRepository(); final ContentLocation root = zipRepository.getRoot(); final ContentLocation data = RepositoryUtilities.createLocation( zipRepository, RepositoryUtilities.split(dataDirectory, "/")); // $NON-NLS-1$ final FlowHtmlOutputProcessor outputProcessor = new FlowHtmlOutputProcessor(report.getConfiguration()); final HtmlPrinter printer = new AllItemsHtmlPrinter(report.getResourceManager()); printer.setContentWriter(root, new DefaultNameGenerator(root, "report.html")); // $NON-NLS-1$ printer.setDataWriter(data, new DefaultNameGenerator(data, "content")); // $NON-NLS-1$ printer.setUrlRewriter(new SingleRepositoryURLRewriter()); outputProcessor.setPrinter(printer); final FlowReportProcessor sp = new FlowReportProcessor(report, outputProcessor); final int yieldRate = getYieldRate(); if (yieldRate > 0) { sp.addReportProgressListener(new YieldReportListener(yieldRate)); } sp.processReport(); zipRepository.write(outputStream); close(); return true; } catch (ReportProcessingException e) { error( Messages.getInstance() .getString("JFreeReportZipHtmlComponent.ERROR_0046_FAILED_TO_PROCESS_REPORT"), e); //$NON-NLS-1$ return false; } catch (IOException e) { error( Messages.getInstance() .getString("JFreeReportZipHtmlComponent.ERROR_0046_FAILED_TO_PROCESS_REPORT"), e); //$NON-NLS-1$ return false; } catch (ContentIOException e) { error( Messages.getInstance() .getString("JFreeReportZipHtmlComponent.ERROR_0046_FAILED_TO_PROCESS_REPORT"), e); //$NON-NLS-1$ return false; } }
public void testRichText() throws ReportProcessingException, ContentProcessingException { final Element e = new Element(); e.setElementType(LabelType.INSTANCE); e.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.RICH_TEXT_TYPE, "text/html"); e.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "Hi I am trying to use the <b>rich text type = text/html</b> in PRD version - 3.7."); e.getStyle().setStyleProperty(TextStyleKeys.FONTSIZE, 12); e.getStyle().setStyleProperty(TextStyleKeys.FONT, "Arial"); e.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, 285f); e.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, 20f); final MasterReport report = new MasterReport(); report.getReportHeader().addElement(e); final LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand(report, report.getReportHeader(), false, false); logicalPageBox.getRepeatFooterArea().setY(logicalPageBox.getContentArea().getHeight()); logicalPageBox.getFooterArea().setY(logicalPageBox.getContentArea().getHeight()); // ModelPrinter.INSTANCE.print(logicalPageBox); final RenderNode[] elementsByNodeType = MatchFactory.findElementsByNodeType(logicalPageBox, LayoutNodeTypes.TYPE_NODE_TEXT); assertEquals( 17, elementsByNodeType.length); // quick and easy way to see that all elements are there. // debugPrintText(elementsByNodeType); final LocalFontRegistry registry = new LocalFontRegistry(); registry.initialize(); final GraphicsOutputProcessorMetaData metaData = new GraphicsOutputProcessorMetaData(new DefaultFontStorage(registry)); metaData.initialize(report.getConfiguration()); final LogicalPageDrawable drawable = new LogicalPageDrawable(); drawable.init(logicalPageBox, metaData, report.getResourceManager()); final TracingGraphics g2 = new TracingGraphics(); drawable.draw(g2, new Rectangle2D.Double(0, 0, 500, 500)); /* for (int i = 0; i < g2.records.size(); i++) { final TextTraceRecord record = g2.records.get(i); System.out.println ("goldenSamples.add(new TextTraceRecord(" + record.x + ", " + record.y + ", \"" + record.text +"\"));"); } */ assertEquals(getSamples(), g2.records); }
public AlignmentUtilities( final ReportRenderContext reportRenderContext, final PageDefinition pageDefinition) { context = reportRenderContext; final MasterReport masterReport = reportRenderContext.getMasterReportElement(); currentPageDefinition = masterReport.getPageDefinition(); originalPageDefinition = pageDefinition; final ArrayList<Element> elementArrayList = new ArrayList<Element>(); collectAlignableElements(masterReport, elementArrayList); visualElements = elementArrayList.toArray(new Element[elementArrayList.size()]); builder = new MassElementStyleUndoEntryBuilder(visualElements); }
/** * This method does what the report designer does on save. * * @param report * @param file * @throws Exception */ private void saveReport(final MasterReport report, final File file) throws Exception { BundleWriter.writeReportToZipFile(report, file); final ResourceManager resourceManager = report.getResourceManager(); final Resource bundleResource = resourceManager.createDirectly(file, DocumentBundle.class); final DocumentBundle bundle = (DocumentBundle) bundleResource.getResource(); final ResourceKey bundleKey = bundle.getBundleKey(); final MemoryDocumentBundle mem = new MemoryDocumentBundle(); BundleUtilities.copyStickyInto(mem, bundle); BundleUtilities.copyMetaData(mem, bundle); report.setBundle(mem); report.setContentBase(mem.getBundleMainKey()); report.setDefinitionSource(bundleKey); }
public void testRendering() throws Exception { MasterReport masterReport = new MasterReport(); SubReport element = new SubReport(); masterReport.getReportHeader().addSubReport(element); ReportLayouter l = new ReportLayouter(new ReportRenderContext(masterReport)); LogicalPageBox layout = l.layout(); ModelPrinter.INSTANCE.print(layout); MatchFactory.findElementsByAttribute( layout, AttributeNames.Core.NAMESPACE, AttributeNames.Core.ELEMENT_TYPE, element.getElementType()); }
/** * Creates a new export task. * * @param dialog the progress dialog that will monitor the report progress. * @param report the report that should be exported. */ public ExcelExportTask( final MasterReport report, final ReportProgressDialog dialog, final SwingGuiContext swingGuiContext) throws ReportProcessingException { if (report == null) { throw new NullPointerException( "ExcelExportTask(..): Null report parameter not permitted"); //$NON-NLS-1$ } this.fileName = report .getConfiguration() .getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.gui.xls.FileName"); //$NON-NLS-1$ if (fileName == null) { throw new ReportProcessingException( "ExcelExportTask(): Filename is not defined"); //$NON-NLS-1$ } this.progressDialog = dialog; this.report = report; if (swingGuiContext != null) { this.statusListener = swingGuiContext.getStatusListener(); this.messages = new Messages( swingGuiContext.getLocale(), ExcelExportPlugin.BASE_RESOURCE_CLASS, ObjectUtilities.getClassLoader(ExcelExportPlugin.class)); } }
@Override protected boolean performExport(final MasterReport report) { try { final File targetFile = getInputFileValue(AbstractJFreeReportComponent.REPORTDIRECTORYHTML_TARGETFILE); if (targetFile == null) { return false; } File dataDirectory = getInputFileValue(AbstractJFreeReportComponent.REPORTDIRECTORYHTML_DATADIR); if (dataDirectory == null) { dataDirectory = new File(targetFile, "data/"); // $NON-NLS-1$ } final File targetDirectory = targetFile.getParentFile(); if (dataDirectory.exists() && (dataDirectory.isDirectory() == false)) { dataDirectory = dataDirectory.getParentFile(); if (dataDirectory.isDirectory() == false) { String msg = Messages.getInstance() .getErrorString( "JFreeReportDirectoryComponent.ERROR_0001_INVALID_DIR", //$NON-NLS-1$ dataDirectory.getPath()); throw new ReportProcessingException(msg); } } else if (dataDirectory.exists() == false) { dataDirectory.mkdirs(); } final FileRepository targetRepository = new FileRepository(targetDirectory); final ContentLocation targetRoot = targetRepository.getRoot(); final FileRepository dataRepository = new FileRepository(dataDirectory); final ContentLocation dataRoot = dataRepository.getRoot(); final FlowHtmlOutputProcessor outputProcessor = new FlowHtmlOutputProcessor(); final HtmlPrinter printer = new AllItemsHtmlPrinter(report.getResourceManager()); printer.setContentWriter( targetRoot, new DefaultNameGenerator(targetRoot, targetFile.getName())); printer.setDataWriter( dataRoot, new DefaultNameGenerator(targetRoot, "content")); // $NON-NLS-1$ printer.setUrlRewriter(new FileSystemURLRewriter()); outputProcessor.setPrinter(printer); final FlowReportProcessor sp = new FlowReportProcessor(report, outputProcessor); final int yieldRate = getYieldRate(); if (yieldRate > 0) { sp.addReportProgressListener(new YieldReportListener(yieldRate)); } sp.processReport(); sp.close(); return true; } catch (ReportProcessingException e) { return false; } catch (ContentIOException e) { return false; } }
protected MasterReport tuneForMigrationMode(final MasterReport report) { final CompatibilityUpdater updater = new CompatibilityUpdater(); updater.performUpdate(report); report.setAttribute( AttributeNames.Internal.NAMESPACE, AttributeNames.Internal.COMAPTIBILITY_LEVEL, null); return report; }
@Test public void testRunSimpleReport() throws Exception { final MasterReport report = new MasterReport(); report.setDataFactory(new TableDataFactory("query", new DefaultTableModel(10, 1))); report.setQuery("query"); final Band table = TableTestUtil.createTable(1, 1, 6, true); table.setName("table"); report.getReportHeader().addElement(table); report.getReportHeader().setLayout("block"); List<LogicalPageBox> pages = DebugReportRunner.layoutPages(report, 0, 1, 2); assertPageValid(pages, 0); assertPageValid(pages, 1); assertPageValid(pages, 2); }
public void testWizardDefinitionIsAvailable() throws Exception { final File url = GoldTestBase.locateGoldenSampleReport("prd-2887.prpt"); assertNotNull(url); final ResourceManager resourceManager = new ResourceManager(); resourceManager.registerDefaults(); final Resource directly = resourceManager.createDirectly(url, MasterReport.class); final MasterReport org = (MasterReport) directly.getResource(); assertNotNull(WizardProcessorUtil.loadWizardSpecification(org, resourceManager)); final MasterReport report = postProcess(org); assertNotNull(WizardProcessorUtil.loadWizardSpecification(report, report.getResourceManager())); DetailsHeader detailsHeader = report.getDetailsHeader(); detailsHeader.getElement(0).setName("MagicChange"); LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage(report, 1); ModelPrinter.INSTANCE.print(logicalPageBox); }
protected MasterReport tuneForTesting(final MasterReport report) throws Exception { final ModifiableConfiguration configuration = report.getReportConfiguration(); configuration.setConfigProperty( DefaultReportEnvironment.ENVIRONMENT_KEY + "::internal::report.date", "2011-04-07T15:00:00.000+0000"); configuration.setConfigProperty( DefaultReportEnvironment.ENVIRONMENT_TYPE + "::internal::report.date", "java.util.Date"); return report; }
private IMetadataDomainRepository buildDomainRepository() { try { final AbstractReportDefinition report = context.getReport(); final MasterReport masterReport = DesignTimeUtil.getMasterReport(report); final ResourceKey contentBase; if (masterReport == null) { contentBase = null; } else { contentBase = masterReport.getContentBase(); } final ResourceManager resourceManager = context.getReport().getResourceManager(); return new PmdConnectionProvider() .getMetadataDomainRepository(domainId, resourceManager, contentBase, fileName); } catch (Exception e) { context.error(e); } return new InMemoryMetadataDomainRepository(); }
protected PageableReportProcessor createReportProcessor( final MasterReport report, final int yieldRate) throws ReportProcessingException { proxyOutputStream = new ProxyOutputStream(); printer = new AllItemsHtmlPrinter(report.getResourceManager()); printer.setUrlRewriter(new PentahoURLRewriter(contentHandlerPattern, false)); final PageableHtmlOutputProcessor outputProcessor = new PageableHtmlOutputProcessor(report.getConfiguration()); outputProcessor.setPrinter(printer); proc = new PageableReportProcessor(report, outputProcessor); if (yieldRate > 0) { proc.addReportProgressListener(new YieldReportListener(yieldRate)); } return proc; }
public void testWrite() throws Exception { final JndiConnectionProvider dummy = new JndiConnectionProvider(); dummy.setConnectionPath("Dummy"); final SQLReportDataFactory df = new SQLReportDataFactory(dummy); df.setGlobalScript("GlobalScript"); df.setGlobalScriptLanguage("GlobalScriptLanguage"); df.setQuery("QueryName", "QueryText", "ScriptLanguage", "Script"); final MasterReport report = new MasterReport(); report.setDataFactory(df); final MasterReport masterReport = postProcess(report); final SQLReportDataFactory dataFactory = (SQLReportDataFactory) masterReport.getDataFactory(); assertEquals("QueryName", dataFactory.getQueryNames()[0]); assertEquals("QueryText", dataFactory.getQuery("QueryName")); assertEquals("ScriptLanguage", dataFactory.getScriptingLanguage("QueryName")); assertEquals("Script", dataFactory.getScript("QueryName")); assertEquals("GlobalScript", dataFactory.getGlobalScript()); assertEquals("GlobalScriptLanguage", dataFactory.getGlobalScriptLanguage()); }
/** * Validate that the master-report page-footer content shows up in the layout-editor * * @throws Exception */ public void testOutsidePageFooter() throws Exception { final URL resource = getClass().getResource("Prd-4637.prpt"); assertNotNull(resource); final ResourceManager mgr = new ResourceManager(); mgr.registerDefaults(); final MasterReport report = (MasterReport) mgr.createDirectly(resource, MasterReport.class).getResource(); final GlobalAuthenticationStore globalAuthenticationStore = new GlobalAuthenticationStore(); final ReportRenderContext reportContext = new ReportRenderContext(report, report, null, globalAuthenticationStore); final TestRootBandRenderer r = new TestRootBandRenderer(report.getPageFooter(), reportContext); final ValidateTextGraphics graphics2D = new ValidateTextGraphics(468, 108); graphics2D.expect("Outside", "Page", "Footer"); assertTrue(graphics2D.hitClip(10, 10, 1, 1)); r.draw(graphics2D); }
/** * Shows this dialog and (if the dialog is confirmed) saves the complete report into an PDF file. * * @param report the report being processed. * @return true or false. */ public boolean performExport(final MasterReport report) { final boolean result = performShowExportDialog( report, "org.pentaho.reporting.engine.classic.core.modules.gui.pdf.Dialog"); //$NON-NLS-1$ if (result == false) { // user canceled the dialog ... return false; } final ReportProgressDialog progressDialog; if (isProgressDialogEnabled( report, "org.pentaho.reporting.engine.classic.core.modules.gui.pdf.ProgressDialogEnabled")) { progressDialog = createProgressDialog(); if (report.getTitle() == null) { progressDialog.setTitle(getResources().getString("ProgressDialog.EMPTY_TITLE")); } else { progressDialog.setTitle( getResources().formatMessage("ProgressDialog.TITLE", report.getTitle())); } } else { progressDialog = null; } try { final PdfExportTask task = new PdfExportTask(report, progressDialog, getContext()); final Thread worker = new Thread(task); worker.start(); return true; } catch (Exception e) { PdfExportPlugin.logger.error("Failure while preparing the PDF export", e); // $NON-NLS-1$ getContext() .getStatusListener() .setStatus( StatusType.ERROR, resources.getString("PdfExportPlugin.USER_FAILED"), e); //$NON-NLS-1$ return false; } }