Giter Club home page Giter Club logo

dwp.pdfrenderer's Introduction

PDF Renderer Microservice

The PDF Renderer is a self contained microservice that uses a supplied jasper report to convert an XML document into either a HTML or PDF report.

The PDF Renderer uses the supplied XML data and a named, versioned Jasper report file to generate the output.  The location of the jasper report files is configured using XXX (jar or directory). The name and version of the report to use is specified when the PDF Renderer is called.

Two versions of the PDF Renderer are built:

  • The PDF Renderer itself without libraries or microservice infrastructure
  • The self contained microservice, which includes an embedded HTTP server (Jetty), all the required libraries and other dependencies and executes from a single Jar file (using Spring Boot)

The PDFs generated are PDF1a format (archival format)

The PDF Renderer is used by the CADS project to generate the PDF equivalent of the paper form. The claim data used in the report is captured by the customer facing application. The PDF is then sent to DRS for processing by the carers allowance claim unit. (The paper forms are also scanned in and sent to DRS).

Releases:

PDF Renderer 4.04

Download the Latest Release of PDF Renderer library here or the microservice (executable jar with embedded webserver) here.

Get the source, release notes, Javadoc API documents

All Releases

All releases are available here

Building the PDF Renderer:

Get a local copy of the code using git clone https://github.com/Department-for-Work-and-Pensions/pdfRenderer.git

The project requires Java 8 (https://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html) and uses gradle to build (https://docs.gradle.org/current/userguide/installation.html)

Using the PDF Renderer

Call the renderer supplying only the claim XML, transaction id, report name and version.

e.g.

claim.xml

  <DWPBody xsi:schemaLocation="http://www.govtalk.gov.uk/dwp/carers-allowance file:/future/0.21/schema/ca/CarersAllowance\_Schema.xsd"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:ds="http://www.w3.org/2000/09/xmldsig"
           xmlns="http://www.govtalk.gov.uk/dwp/carers-allowance"<
      <Version>0.22</Version<
      <DWPCATransaction id="TEST432">
      <TransactionId>TEST432</TransactionId>
      <DateTimeGenerated<12-07-2014 22:07</DateTimeGenerated>
      <DWPCAClaim>
          <DateOfClaim>
              <QuestionLabel>Claim date</QuestionLabel>
              <Answer>01-02-2014>/Answer></DateOfClaim>
          <Claimant>
              <Surname>
                <QuestionLabel>Last name</QuestionLabel>
                <Answer>Karloff</Answer>
              </Surname>
  ...
  ...
  </DWPBody<

Configuration Parameters

Default Configuration file

icc.path=/config/AdobeRGB1998.icc
jasper.local.folder=../XXpdfReports/build/resources/main/config
jasper.jarfile.folder=./pdfreports
jasper.jarfile.subfolder=config
env.name=lab
server.port=9010
metrics.name=p1
metrics.frequency=1
metrics.slf4j=true
health.logging=true
health.logging.frequency=1
spring.config.name=application-info.properties
spring.config.location=/config/
Parameter Name Description
icc.path Path to a font used in the pdf
jasper.local.folder The folder containing the jasper reports, if both are populated this takes precedence over jasper.local.folder
jasper.jarfile.folder The folder containing the jar file containing the jasper reports, if both are populated the jasper.local.folder takes precedence. Note this is not the name of the jar file
jasper.jarfile.subfolder an additional enclosing subfolder within the reports jar file (if used) that contains the reports
env.name used in the logs as the environment name (e.g. lab, preview, production)
server.port the port that the embedded server listens on (http only)
metrics.name ? part of the metrics reporting framework
metrics.frequency ? part of the metrics reporting framework
metrics.slf4j ? part of the metrics reporting framework
health.logging Whether health checks are periodically emmitted to the logs
health.logging.frequency The logging period (seconds)
spring.config.name ?
spring.config.location ?

all parameters are optional, except jasper.jarfile.folder

All parameters can be overridden on the command line using. e.g.

java -jar p1-4.03-SNAPSHOT-full.jar --jasper.jarfile.folder=./pdfreports-1.06-SNAPSHOT.jar

Starting the pdfRender

java -jar <jar name> --jasper.jarfile.folder=<location of reports>

It logs to the console unless you override the logging config, and the last two lines when it starts successfully are:

2016-07-08 09:28:20,136 - \[INFO\] - \[main\] -
o.s.b.c.e.j.JettyEmbeddedServletContainer - Jetty started on port(s)
9010 (http/1.1)

2016-07-08 09:28:20,143 - \[INFO\] - \[main\] -
controllers.PdfServiceApplication - Started PdfServiceApplication in
5.316 seconds (JVM running for 5.901)

Stopping the pdfRenderer

Ctrl-C

Is it alive

To check if the pdfRenderer is alive and reachable, it can be pinged at:

http://<server name>:<server.port>/ping, e.g.

    http://localhost:9010/ping

The health check can be reached at:

http://<server name>:<server.port>/report/health e.g.

    http://localhost:9010/report/health

which returns a json response, e.g.

json

{
    "application name" : "p1",
    "version" : "4.03",
    "name" : "p1-check",
    "Result" : {
        "isHealthy" : "true",
        "message" : "",
        "error" : ""
    }
}

Use PDF Renderer to render a PDF file :

which returns a PDF as a byte stream.

Use PDF Renderer to render a HTML file

which returns HTML as a byte stream 

Testing the PDF Renderer

There are a number of tools that can be used to make sending specific requests to the service easier:

Advanced REST Client (for chrome - https://advancedrestclient.com/), which is friendly and easy to use, and can save the responses to a file

Example

URLhttp://127.0.0.1:9010/html
Parameters
transactionid123456
reportnamereportClaimWithSummary
reportversion0.26
xmlpaste the claim.xml into the field (it is quite large)

and click send, the response will come back as HTML

similarly if you change the url to http://127.0.0.1:9010/pdf

Example Files

claim.xml

claim.html

claim.pdf

Reports

The reports used to render the data are included in the pdfRenderer executable jar (/config/<report version>/...)

The version required is determined from the <DWPBody>/<Version> tag.

Logging

The pdfRenderer uses logback for itself and the spring boot wrapper (which is used to make the jar self contained and executable).

The logging configuration can be overridden by setting the system property to the new configuration location (typically logback.xml), e.g.

        java -Dlogback.configurationFile=/path/to/config.xml for the application logging

<TODO> for the spring boot logging

Next Steps

The code is awaiting code review, so there will be some tidying up to make it clearer, more consistent and adhere to best practices etc.

The end artefact will be made more general and more flexible, e.g being able to define the reports externally

dwp.pdfrenderer's People

Contributors

arcotc avatar chrisruddvaltech avatar magicalbob avatar nedda76 avatar reaandrew avatar ruben-diaz-valtech avatar scottkwalker avatar tudor-malene avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.