public static MasterReport loadMasterReport( String sourceFilename ) throws Exception { ResourceManager manager = new ResourceManager(); manager.registerDefaults(); FileObject fileObject = KettleVFS.getFileObject( sourceFilename ); URL url = new URL( fileObject.getName().getURI() ); Resource resource = manager.createDirectly( url, MasterReport.class ); MasterReport report = (MasterReport) resource.getResource(); return report; }
public Object getRaw() { try { return content.getResource(); } catch ( ResourceException e ) { return null; } }
public Object getResource() throws ResourceException { return parent.getResource(); }
private StyleSheet parseStyleSheet( final ResourceKey key, final ResourceKey context ) { try { final Resource resource = resourceManager.create ( key, context, StyleSheet.class ); return (StyleSheet) resource.getResource(); } catch ( ResourceException e ) { // Log.info("Unable to parse StyleSheet: " + e.getLocalizedMessage()); } return null; }
private ElementStyleDefinition parseStyleSheet( final ResourceKey key, final ResourceKey context ) { try { final Resource resource = resourceManager.create( key, context, ElementStyleDefinition.class ); return (ElementStyleDefinition) resource.getResource(); } catch ( ResourceException e ) { // Log.info("Unable to parse StyleSheet: " + e.getLocalizedMessage()); } return null; }
public static DocumentBundle getBundle( final File file ) throws ResourceException { if ( file == null ) { throw new NullPointerException(); } final ResourceManager resManager = new ResourceManager(); final Resource directly = resManager.createDirectly( file, DocumentBundle.class ); return (DocumentBundle) directly.getResource(); }
@Test( expected = ResourceException.class ) public void testDefaultCreationWithImageResource() throws ResourceException { Resource imageResource = mock( Resource.class ); doReturn( null ).when( imageResource ).getResource(); new DefaultImageReference( imageResource ); }
private BundleMetaData createMetaData( final ResourceManager resourceManager, final ResourceKey bundleKey ) throws ResourceException { try { final ResourceKey metaDataKey = resourceManager.deriveKey( bundleKey, "/meta.xml" ); // make sure we trigger a resource-loading exception .. final ResourceData metaDataBytes = resourceManager.load( metaDataKey ); final Resource metaDataResource = resourceManager.create( metaDataKey, null, BundleMetaData.class ); return (BundleMetaData) metaDataResource.getResource(); } catch ( ResourceKeyCreationException e ) { return new DefaultBundleMetaData(); } catch ( ResourceLoadingException e ) { return new DefaultBundleMetaData(); } }
public void initialize() { try { final ResourceManager resourceManager = new ResourceManager(); resourceManager.registerDefaults(); final Resource resource = resourceManager.createDirectly( "res://fonts.xml", FontMetricsCollection.class ); this.fontMetricsCollection = (FontMetricsCollection) resource.getResource(); } catch ( ResourceException e ) { throw new IllegalStateException( e ); } }
public static MasterReport parseReport( final Object file ) throws ResourceException { final ResourceManager manager = new ResourceManager(); manager.registerDefaults(); final Resource resource = manager.createDirectly( file, MasterReport.class ); return (MasterReport) resource.getResource(); }
public static MasterReport parseLocalReport( final String name, Class<?> context ) throws ResourceException { final URL file = context.getResource( name ); if ( file == null ) { throw new ResourceException( "Unable to locate report '" + name + "' near class " + context ); } final ResourceManager mgr = new ResourceManager(); mgr.registerDefaults(); return (MasterReport) mgr.createDirectly( file, MasterReport.class ).getResource(); }
@Test public void testCSV() throws ResourceException { URL url = getClass().getResource( "BACKLOG-6818.prpt" ); MasterReport report = (MasterReport) new ResourceManager().createDirectly( url, MasterReport.class ).getResource(); try ( ByteArrayOutputStream stream = new ByteArrayOutputStream() ) { CSVReportUtil.createCSV( report, stream, "UTF-8" ); final byte[] bytes = stream.toByteArray(); assertNotNull( bytes ); assertTrue( bytes.length > 0 ); assertTrue( StringUtils.isNotBlank( new String( bytes, "UTF-8" ).replaceAll( ",", "" ) ) ); } catch ( final IOException | ReportProcessingException e ) { fail(); } }
@Test public void testTxt() throws ResourceException { URL url = getClass().getResource( "BACKLOG-6818.prpt" ); MasterReport report = (MasterReport) new ResourceManager().createDirectly( url, MasterReport.class ).getResource(); try ( ByteArrayOutputStream stream = new ByteArrayOutputStream() ) { PlainTextReportUtil.createPlainText( report, stream ); final byte[] bytes = stream.toByteArray(); assertNotNull( bytes ); assertTrue( bytes.length > 0 ); assertTrue( StringUtils.isNotBlank( new String( bytes, "UTF-8" ) ) ); } catch ( final IOException | ReportProcessingException e ) { fail(); } }
static List<LogicalPageBox> loadPages( String file, int expectedPages ) throws Exception { ResourceManager resourceManager = new ResourceManager(); resourceManager.registerDefaults(); Resource resource = resourceManager .createDirectly( LayoutValidationUtils.class.getResource( "pagination/" + file ), MasterReport.class ); MasterReport report = (MasterReport) resource.getResource(); int[] pages = new int[ expectedPages ]; for ( int i = 0; i < expectedPages; i++ ) { pages[ i ] = i; } return DebugReportRunner.layoutPagesStrict( report, expectedPages, pages ); }
private MasterReport saveAndLoad( final MasterReport originalReport ) throws Exception { final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream(); BundleWriter.writeReportToZipStream( originalReport, bout ); assertTrue( bout.getLength() > 0 ); /* * final File f = File.createTempFile("test-output-", ".prpt", new File ("test-output")); final FileOutputStream * outputStream = new FileOutputStream(f); outputStream.write(bout.toByteArray()); outputStream.close(); */ final ResourceManager mgr = new ResourceManager(); final Resource reportRes = mgr.createDirectly( bout.toByteArray(), MasterReport.class ); return (MasterReport) reportRes.getResource(); }
public static MasterReport parseGoldenSampleReport( final String name ) throws ResourceException { final File file = GoldTestBase.locateGoldenSampleReport( name ); if ( file == null ) { throw new ResourceException( "Unable to locate report '" + name + "' in the golden samples." ); } final ResourceManager mgr = new ResourceManager(); mgr.registerDefaults(); return (MasterReport) mgr.createDirectly( file, MasterReport.class ).getResource(); }
public static MasterReport saveAndLoad( MasterReport report ) throws Exception { final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream(); BundleWriter.writeReportToZipStream( report, bout ); final ResourceManager mgr = new ResourceManager(); mgr.registerDefaults(); final Resource resource = mgr.createDirectly( bout.toByteArray(), MasterReport.class ); return (MasterReport) resource.getResource(); } }
@Test public void testIsLimitReachedForNumberOfRowsGreaterQueryLimit() throws Exception { //When data source enforce limit itself // report with 148 rows final URL url = getClass().getResource( "report1.prpt" ); assertNotNull( url ); final ResourceManager resourceManager = new ResourceManager(); resourceManager.registerDefaults(); final Resource directly = resourceManager.createDirectly( url, MasterReport.class ); final MasterReport report = (MasterReport) directly.getResource(); report.setQueryLimit( 147 ); final AbstractReportProcessor reportProcessor = new DummyReportProcessor( report ); reportProcessor.prepareReportProcessing(); assertEquals( reportProcessor.isQueryLimitReached(), true ); }
@Test public void testIsLimitNotReachedForNumberOfRowsEqualQueryLimit() throws Exception { //When data source enforce limit itself // report with 148 rows final URL url = getClass().getResource( "report1.prpt" ); assertNotNull( url ); final ResourceManager resourceManager = new ResourceManager(); resourceManager.registerDefaults(); final Resource directly = resourceManager.createDirectly( url, MasterReport.class ); final MasterReport report = (MasterReport) directly.getResource(); report.setQueryLimit( 148 ); final AbstractReportProcessor reportProcessor = new DummyReportProcessor( report ); reportProcessor.prepareReportProcessing(); assertEquals( reportProcessor.isQueryLimitReached(), false ); }
public static DataFactory loadAndSaveOnReport( final DataFactory dataFactory ) throws IOException, BundleWriterException, ContentIOException, ResourceException { final MasterReport report = new MasterReport(); report.setDataFactory( dataFactory ); final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream(); BundleWriter.writeReportToZipStream( report, bout ); final ResourceManager mgr = new ResourceManager(); mgr.registerDefaults(); final Resource resource = mgr.createDirectly( bout.toByteArray(), MasterReport.class ); final MasterReport r2 = (MasterReport) resource.getResource(); return r2.getDataFactory(); }