Archi Forum

Archi => General Archi Discussion => Topic started by: arch.model.user on April 06, 2019, 02:39:30 AM

Title: Create a Jasper report from a standalone Java application
Post by: arch.model.user on April 06, 2019, 02:39:30 AM
Hello all,

Our main goal is to create a Jasper report of an ArchimateModel from a standalone Java program. The idea is to create standardized views like the layered view, service realization, application usage, etc.. programmatically (as IArchimateDiagramModel objects) so that they look consistent across all the apps/services in our portfolio and also make the reports/models automatically updated when the information changes.

I started looking at the Archimate tool source code and noticed that the jasper report of ARCHISURANCE test model is created/exported in JasperReportsExporterTests.java using JasperReportsExporter.

I set up Eclipse as documented and when I run 'Maven install' on a pom.xml of com.archimatetool.jasperreports.tests project in Eclipse, all the tests are PASSED and the Jasper reports are generated. Cool  :)
But when I tried to create/export a Jasper report (same piece of code, similarly how it is done in JasperReportsExporterTests) from a standalone program in Eclipse, I am getting Null pointer exceptions.

What I observed when I execute as a standalone java process is -

Platform.isRunning() returns false.
Platform.getBundle(JasperReportsPlugin.PLUGIN_ID) is null.
Platform.getExtensionRegistry() returns null.
RegistryProviderFactory.getDefault() returns null.
PlatformActivator.getContext() returns null.

I believe the Plugins and the associated bundles are not loaded properly and the Platform is not set up correctly or something to do with OSGi bundles when I execute as a standalone java process.

I have setup the following arguments explicitly for standalone Java process.
-Dosgi.noShutdown=false -Dosgi.os=macosx -Dosgi.ws=cocoa -Dosgi.arch=x86_64 -XstartOnFirstThread -Dosgi.clean=true

I have also added all the Eclipse jars (related to swt, ui, zest, jdt, equinox, emf, ..) to the Classpath of a Java process as external jars.

But no luck. So the question is, How do I make sure the Platform loads correctly for a Standalone Java process (Should run in either in Eclipse or external)?

Any pointers would be greatly appreciated.

Thank you!
Title: Re: Create a Jasper report from a standalone Java application
Post by: Phil Beauvoir on April 06, 2019, 07:57:22 AM
It really needs to run with all Eclipse dependencies loaded, and there are many. Even when running the tests, the Platform is loaded.

Instead you could run Jasper from the command line.

See https://github.com/archimatetool/archi/wiki/Archi-Command-Line-Interface
Title: Re: Create a Jasper report from a standalone Java application
Post by: arch.model.user on April 08, 2019, 23:10:46 PM
Hi Phil,

Thank you for your response.

Based on the documentation I understand that I need to provide model (.archimate) file to CLI so that it exports Jasper report for it.
But my requirement is, creating IArchimateModel object programmatically (based on the information we get from other sources) and export Jasper reports out of that model. 
Is it possible?  Or am I missing something?

Also. I am trying to run CLI on my mac using the following command
Archi.app/Contents/MacOS/launcher/Archi -application com.archimatetool.commandline.app -consoleLog -nosplash --help

But getting the following error.

java.lang.RuntimeException: Application "com.archimatetool.commandline.app" could not be found in the registry. The applications available are: org.eclipse.help.base.infocenterApplication, org.eclipse.help.base.helpApplication, org.eclipse.help.base.indexTool, org.eclipse.equinox.app.error, com.archimatetool.editor.app, org.eclipse.e4.ui.workbench.swt.E4Application, org.eclipse.e4.ui.workbench.swt.GenTopic.

Any help?
Thank you.
Title: Re: Create a Jasper report from a standalone Java application
Post by: Phil Beauvoir on April 09, 2019, 07:53:38 AM
The wiki at https://github.com/archimatetool/archi/wiki/Archi-Command-Line-Interface says:

"Since version 4.2, some Archi functions can be invoked from the Archi Command Line Interface"

And the command line for Mac should be:

Archi.app/Contents/MacOS/Archi -application com.archimatetool.commandline.app -consoleLog -nosplash --help

To create an Archi model programmatically you could do that using jArchi, the scripting language.
Title: Re: Create a Jasper report from a standalone Java application
Post by: arch.model.user on April 11, 2019, 17:05:34 PM
My bad, downloaded version 4.4 and able to launch ACLI. Thank you!

Reg. building models pragmatically - Our goal is to automate the creation of Arch model/views and Jasper reports, without explicitly using Archi UI.

Since we have a Java backend app (not a web app) already, We would like to leverage it (maintenance and DB integration perspective) rather introduce another approach like JArchi.

So, the possibilities seem are -

Creating archimate model programmatically (in java) and Call the ACLI from the same java process to generate Jasper.

Or try to load all the platform required plugins/features at startup of java process and use JasperReportsExporter to create jasper (I know you mentioned that it could be a lot of work to load/launch startup jars)

Do you see any issues on productionalizing any one of these approaches Or do you suggest an alternative?

Thanks so much for your time and help.
Title: Re: Create a Jasper report from a standalone Java application
Post by: Phil Beauvoir on April 11, 2019, 17:12:19 PM
For the Jasper Reports to generate images, text, and the information in a model you have to use most of the Archi code stack and all dependencies. So "without explicitly using Archi" is not possible. You can however run it in "headless" mode which is how JUnit tests and the ACLI do it.

The ACLI calls a "headless" application - com.archimatetool.commandline.app which calls class com.archimatetool.commandline.CentralScrutinizer so you could write your own headless application class, register it as a plugin and work from there.
Title: Re: Create a Jasper report from a standalone Java application
Post by: arch.model.user on April 12, 2019, 19:37:05 PM
Will explore the suggested. Thank you!