Skip to content
This repository has been archived by the owner on Jun 17, 2020. It is now read-only.

Commit

Permalink
Included MIT license to indicate that this whole project is licensed …
Browse files Browse the repository at this point in the history
…under these terms. (Source header update)
  • Loading branch information
tmorgner committed Jan 21, 2016
1 parent 2fb6a68 commit 21a59d3
Show file tree
Hide file tree
Showing 8 changed files with 2,171 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions build.properties
Expand Up @@ -7,6 +7,5 @@ modules=sample-module,\
sample-expression,\
sample-formula-function,\
sample-drilldown-profile,\
sample-report-preprocessor, \
sample-server
sample-report-preprocessor
# sample-generate-report-files
1,977 changes: 1,977 additions & 0 deletions sample-generate-report-files/build-res/subfloor.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sample-generate-report-files/build.xml
Expand Up @@ -7,7 +7,7 @@
See build-res/subfloor.xml for more details
============================================================================-->
<project name="sample-use-full" basedir="." default="default">
<project name="sample-generate-report-files" basedir="." default="default">

<description>
This build file is used to create the API project
Expand Down
1 change: 1 addition & 0 deletions sample-generate-report-files/ivy.xml
Expand Up @@ -34,5 +34,6 @@

<dependency org="org.slf4j" name="slf4j-jcl" rev="1.6.4" transitive="false"/>
<dependency org="org.slf4j" name="slf4j-api" rev="1.6.4" transitive="false"/>
<dependency org="net.sf.jopt-simple" name="jopt-simple" rev="4.8" transitive="false"/>
</dependencies>
</ivy-module>
10 changes: 10 additions & 0 deletions sample-generate-report-files/sample-generate-report-files.iml
Expand Up @@ -7,6 +7,16 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" exported="">
<library>
<CLASSES>
<root url="file://$MODULE_DIR$/lib/internal" />
</CLASSES>
<JAVADOC />
<SOURCES />
<jarDirectory url="file://$MODULE_DIR$/lib/internal" recursive="false" />
</library>
</orderEntry>
</component>
</module>

@@ -0,0 +1,150 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Thomas Morgner
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package sdk.generate.patch;

import joptsimple.OptionException;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.pentaho.reporting.engine.classic.core.AbstractReportDefinition;
import org.pentaho.reporting.engine.classic.core.CompoundDataFactory;
import org.pentaho.reporting.engine.classic.core.DataFactory;
import org.pentaho.reporting.engine.classic.core.MasterReport;
import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.ConnectionProvider;
import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.DriverConnectionProvider;
import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.JndiConnectionProvider;
import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.SimpleSQLReportDataFactory;
import org.pentaho.reporting.engine.classic.core.modules.parser.bundle.writer.BundleWriter;
import org.pentaho.reporting.engine.classic.core.modules.parser.bundle.writer.BundleWriterException;
import org.pentaho.reporting.engine.classic.core.util.AbstractStructureVisitor;
import org.pentaho.reporting.libraries.repository.ContentIOException;
import org.pentaho.reporting.libraries.resourceloader.ResourceException;
import org.pentaho.reporting.libraries.resourceloader.ResourceManager;

import java.io.File;
import java.io.IOException;

public class PatchAReportSample {
public static void _main(String[] args) throws IOException {
OptionParser parser = new OptionParser();
OptionSpec<String> source = parser.accepts("source").withRequiredArg().ofType(String.class).required().describedAs("Source File");
OptionSpec<String> target = parser.accepts("target").withOptionalArg().ofType(String.class).required().describedAs("Target File");

try {
OptionSet parse = parser.parse(args);
String sourceText = parse.valueOf(source);
String targetText = parse.valueOf(target);

processReport(sourceText, targetText);

} catch (OptionException oe) {
parser.printHelpOn(System.out);
} catch (ResourceException | ContentIOException | BundleWriterException e) {
e.printStackTrace();
}
}

public static void main(String[] args) throws ResourceException, ContentIOException, BundleWriterException, IOException {
processReport(args[0], args[1]);
}

private static void processReport(String sourceText, String targetText)
throws ResourceException, IOException, BundleWriterException, ContentIOException {

File sourceFile = new File(sourceText);
MasterReport report = (MasterReport) new ResourceManager().createDirectly(sourceFile, MasterReport.class).getResource();

MasterReport processedReport = manipulateReport(report);

BundleWriter.writeReportToZipFile(report, new File(targetText));
}

private static MasterReport manipulateReport(MasterReport report) {
new DataSourceStructureVisitor().inspect(report);
return report;
}

private static class DataSourceStructureVisitor extends AbstractStructureVisitor {
@Override
protected void inspect(AbstractReportDefinition reportDefinition) {

processAllDataSources(reportDefinition);
processSingleDataSource(reportDefinition, "query");
super.inspect(reportDefinition);
}

private void processSingleDataSource(AbstractReportDefinition reportDefinition, String query) {
CompoundDataFactory dataFactory = CompoundDataFactory.normalize(reportDefinition.getDataFactory());
DataFactory dataFactoryForQuery = dataFactory.getDataFactoryForQuery(query);
if (dataFactoryForQuery != null) {
int idx = dataFactory.indexOfByReference(dataFactory);
dataFactory.set(idx, handleDataSource(reportDefinition, dataFactory));
}
reportDefinition.setDataFactory(dataFactory);
}


private void processAllDataSources(AbstractReportDefinition reportDefinition) {
CompoundDataFactory dataFactory = CompoundDataFactory.normalize(reportDefinition.getDataFactory());
final int size = dataFactory.size();
for (int i = 0; i < size; i++) {
dataFactory.set(i, handleDataSource(reportDefinition, dataFactory.getReference(i)));
}
reportDefinition.setDataFactory(dataFactory);
}

private DataFactory handleDataSource(AbstractReportDefinition reportDefinition, DataFactory dataFactory) {
return dataFactory;
}
}


private static DataFactory handleDataSource(AbstractReportDefinition reportDefinition, DataFactory dataFactory) {
// do whatever you want here.
if (dataFactory instanceof SimpleSQLReportDataFactory) {
SimpleSQLReportDataFactory sdf = (SimpleSQLReportDataFactory) dataFactory;
if (isLocalSampleData(sdf)) {
JndiConnectionProvider connectionProvider = new JndiConnectionProvider();
connectionProvider.setConnectionPath("SampleData");
sdf.setConnectionProvider(connectionProvider);
}
}
return dataFactory;
}

private static boolean isLocalSampleData(SimpleSQLReportDataFactory sdf) {
ConnectionProvider cp = sdf.getConnectionProvider();
if (cp instanceof DriverConnectionProvider) {
DriverConnectionProvider jcp = (DriverConnectionProvider) cp;
if ("org.hsqldb.jdbcDriver".equals(jcp.getDriver()) &&
"jdbc:hsqldb:file:./sql/sampledata".equalsIgnoreCase(jcp.getUrl())) {
return true;
}
}

return false;
}

}
26 changes: 26 additions & 0 deletions sample-server/sample-server.iml
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" exported="">
<library>
<CLASSES>
<root url="file://$MODULE_DIR$/lib/internal" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$MODULE_DIR$/lib/internal" />
<root url="jar://$USER_HOME$/.ideaLibSources/servlet-api-2.5-sources.jar!/" />
</SOURCES>
<jarDirectory url="file://$MODULE_DIR$/lib/internal" recursive="false" />
<jarDirectory url="file://$MODULE_DIR$/lib/internal" recursive="false" type="SOURCES" />
</library>
</orderEntry>
</component>
</module>

0 comments on commit 21a59d3

Please sign in to comment.