How can I import JSON data from a REST API into BIRT? - json

I want to use BIRT to generate reports against data that comes from a JSON based REST API. How can I import this data?

The process for doing this is described at http://developer.actuate.com/community/forum/?app=blog&blogid=45&showentry=471, but it turns out that there are a few important steps missing. I'll fill in a few blanks here.
The original instructions describe creating a Scripted Data Source, with an "open" script that makes use of the com.actuate.json.JSONParser class. First, it is important to realise that this class is not part of BIRT, and needs to be manually added (along with any dependencies).
The download provided by the original instructions provides the com.actuate.json.JSONParser class, but leaves it up to you to source the dependencies. To make things easier I have reimplemented the JSONParser library in Maven, which will then download and package the dependencies for you. It also includes some bug fixes and enhancements like GZIP compression support. You can get the Maven project from https://github.com/mcasperson/birt-jsonparser, and to build the JSONParser library and package the dependencies, run the command
mvn clean package dependency:copy-dependencies
This will result in the birt-jsonparser-0.0.1-SNAPSHOT.jar file being created in the target directory, and all the dependencies copied into the target\dependency directory. Copy all of these JAR files into the {BIRT_INSTALL}/plugins/org.eclipse.birt.report.viewer_{BIRT_VIEWER_VERSION}/birt/scriptlib directory to allow the JSONParser class to be accessed from within your BIRT report.
If you want to debug your report, these JAR files will also have to be referenced in the Debug profile.

Related

Best tool for .json file schema validation

There are probably a lot of tools/libraries to validate JSON schemas.
I have a library and want users of my library to have configuration files that match the expected API.
Using Webstorm, the IDE will tell me that my Webpack config file schema is incorrect, something like this:
The Webpack files that are responsible are here:
https://github.com/webpack/webpack/blob/master/schemas/webpackOptionsSchema.json
Integration with existing IDEs like Webstorm, VSCode, Atom, ST3, etc, would be a huge plus.
I haven't figured out how to do this right...anybody know?
To integrate with various IDEs, consider uploading your json schema to JSON Schema Store.
Here is the GitHub Repo
https://github.com/SchemaStore/schemastore
This contains json schemas for many well known json files and gets integrated with Visual Studio and VS Code easily.
Also look at step by step integrations steps for Visual Studio
https://scottaddie.com/2016/08/02/community-driven-json-schemas-in-visual-studio-2015/

How to access unexported functions in the same package but from different file

I am trying to build godoc.org source code in my local to make some changes. My working directory is /Users/Dany/go/src/github.com/golang/gddo. In gddo-server package there several files. One of the go file uses a function from another file which is in the same package but unexported. It is throwing Undefined: <function-name> exception.
Folder is structure is,
golang/gddo/
gddo-server
main.go
crawl.go
How do we use unexported function from the same package in a different file? Could anyone help me with this. Also if anyone has any idea about how to build godoc.org code?
Source files of the same package can refer to identifiers defined in any of the source files without any effort. If they are in the same folder and if they have the same package declaration, you can refer all package-level exported and unexported identifiers as if all would have been defined in one file.
See Spec: Packages:
A package in turn is constructed from one or more source files that together declare constants, types, variables and functions belonging to the package and which are accessible in all files of the same package.
And Spec: Package clause:
A set of files sharing the same PackageName form the implementation of a package. An implementation may require that all source files for a package inhabit the same directory.
One thing to note: your example seems to be the special main package. If you want to run it with go run, you have to enumerate all the source files.
To run your example with go run, navigate to the gddo-server folder and type:
go run background.go browse.go client.go crawl.go graph.go main.go play.go template.go
Or simpler if you first build it. Navigate to the gddo-server folder and type:
go build
This will generate a native executable binary in the same folder. To run it type: gddo-server (on Windows) or ./gddo-server (on Linux).
Or you can install it with go install which will place the result executable binary in your $GOPATH/bin folder.

How to make an F# JSON type provider sample available for test project?

I am using an F# JSON type provider to create a type from a reference JSON document. The reference document "ReferenceItem.json" is part of the F# library. In addition I have a unit test project which tests the library. I am struggling with making the reference document available for the test project without duplicating it.
No matter how I mark "ReferenceItem.json" in Visual Studio (Content, None, Copy to Output etc.) my test project fails to compile because the statement JsonProvider<"ReferenceItem.json"> expects "Reference.json" to be present in the project source folder at compilation time. Including it as a linked item from the library project doesn't help: it's not copied at compile time to the test source folder. So I need to make a duplicate copy of the file in the test project.
I noticed that in F# projects I can mark files as "DesignData" or "DesignDataWithDesignTimeCreatableTypes", but I wasn't able to figure out how I can use them.
This is a tricky problem - when F# compiler references the library, it will invoke the type provider and so the type provider needs to be able to access the sample.
The easiest solution is to just always copy the sample json file so that it is in the folder from where the application is starting. This is obviously sub-optimal, and so we have another way of handling this using resources.
See the "Using JSON provider in a library" section of the documentation. The idea is that you can embed the sample document as a resource in the library and specify the resource name as an additional parameter:
type WB = JsonProvider<"../data/WorldBank.json",
EmbeddedResource="MyLib, worldbank.json">
This will then load the resource when using the library (but it still needs the file name in the original compilation mode). This is still somewhat experimental, so please open an issue on GitHub if you cannot get it to work!

Maven Plugin for Validating JSON Files

I am looking for a maven plugin that will simply compare a json file with an associated JSON Schema file. Essentially we are getting plagued with invalid configuration files which are only run in a single environment. So testing of the "dev" environment will pass with flying colors though when the application is launched with the "prod" configurations the application will fail to start is the config is say missing a comma or otherwise the JSON doesn't parse.
Looking for a non-intrusive solution to verify that the config files are at least in the expected format before marking the build as successful (say like within a CI environment).
Posting this for completeness. The maven plugin was opensourced by Groupon and can be found here : https://github.com/groupon/json-schema-validator
Lacking a Maven plugin, I would do this with a small Java unit test which runs a schema validator over your example inputs - you could use a Maven filter to choose which file to parse based on your environment. If all configurations are stored in your SCM, you should be able to validate all configurations with one unit test.
If you're looking for a library to use in your unit test, have a look at the JSON schema validator:
<dependency>
<groupId>com.github.fge</groupId>
<artifactId>json-schema-validator</artifactId>
<version>2.0.1</version>
<scope>test</scope>
Another thought - if your configuration needs runtime validation, you should use the above library to validate when it changes. If you make your configuration update process interactive, you could validate as it changes and reject configuration updates which are invalid.

Get HTML file produced by JavaDocs

I understand that Javadoc is a documentation generator from Sun Microsystems for generating API documentation in HTML format from Java source code.
I infer that the documentation is stored onto an HTML file.
Is there a way I can access it?
If yes where is it stored?
The word Javadoc can refer to
special comments in Java source files (preceding a declaration, and of the form /** ... */)
a program which converts these comments (as well as the declarations themselves) to readable output
the output itself, usually in HTML form.
The Javadoc program is contained in Sun's (or now Oracle's) Java Development Kit (JDK).
If you have installed a JDK (which you should if you do Java development), you can call it on the command line, passing it the package names to document, or some source file names. You should also indicate the output directory, using the -d option.
I'm assuming the following directory (and package) structure in my example below:
current directory
source
de
dclj
paul
examples
HelloWorld.java [containing package de.dclj.paul.examples; and public class HelloWorld { ... }]
docs
Then you use the following command line:
javadoc -sourcpath source -d docs de.dclj.paul.examples
It will then create a the documentation in the docs directory, with an index.html which you can open in your web browser, and other files reachable from it.
For more details have a look at the documentation linked above. For an example output, have a look at the Java Standard API Javadoc.
If you are using an IDE, you likely have a generate Javadoc button there, and the IDE might even show the formatted output of documentation of single classes or methods on the fly.