GithubHelp home page GithubHelp logo

doytsujin / json-to-xls Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sel-columbia/json-to-xls

0.0 1.0 0.0 12.75 MB

Micro service to generate XLS files from a template and data which is in JSON format

License: Other

Java 100.00%

json-to-xls's Introduction

##JSON-to-XLS SERVICE

This is a service that can be used to generate XLS files from given XLS template and data in JSON format

The following are the dependencies to run this project:

  • Gradle for build
  • jxls internally to generate the XLS files
  • JsonToJava from this repo which converts json structure to equivalent Java Classes

Firstly, you need to save an excel template. It can be done by POSTing to the API: /templates, with the excel template to be saved as the payload.

e.g., We can send sampleTemplate.xls as payload to http://localhost:8080/templates.

Here, the sampleTemplate.xls should be a valid excel file. If it is not valid, it throws an exception.

When the excel template is a valid one, the template is stored in postgres db in template table and returns a unique template token, uniqueTemplateToken which corresponds to that particular template. This token can be used to generate XLS files for the template referred by it.

Lets consider that POSTing the sampleTemplate.xls in our example returned a unique token something like 9afc1c3878e94f5eaf4bf2d2c5c25b40. We can use this token to refer to the sampleTemplate.xls later.

Next, we can generate the XLS files by POSTing to the API: /xls/uniqueTemplateToken with data in JSON format as the payload.

This will generate an Excel file using the template corresponding to the uniqueTemplateToken and JSON data. The generated Excel file is saved in postgres db in excel table. It returns a URL in the response, which can be used to download the excel file generated.

We can generate any number of XLS files for a given XLS template with different JSON data

In our example, POST http://localhost:8080/xls/9afc1c3878e94f5eaf4bf2d2c5c25b40 with the sample JSON data : { "loc": { "state": "Karnataka", "district": "Mysore" }, "ind": { "anc": "1", "anc_12": "2", "anc_jsy": "3" } }

will generate an excel by filling all these details in the sampleTemplate.xls. It returns the URL, /xls/c2e39e3699214316a08af350c3969cbf

Here, internally this JSON data is converted to Java objects using JsonToJava. These objects are used by XLSTransformer, a class that generates an Excel by inserting java objects in the sample template.

Now, we can download the excel generated by using the API: GET /xls/generatedExcelToken.

In our example, doing a GET request on http://localhost:8080/xls/{c2e39e3699214316a08af350c3969cbf} downloads the generated excel that maps to the unique generated excel token c2e39e3699214316a08af350c3969cbf

###Validations done

  • When we POST a request as : /templates with an invalid excel template, an exception would be thrown saying that "Template is not a valid Excel"

  • When we POST a request as : /templates with an excel template and it was not successfully saved for some reason, an exception would be thrown saying that "Unable to save template due to internal error"

  • When we POST a request with a invalid template token in the URL as : /xls/invalidTemplateToken with JSON data as payload, an exception would be thrown saying that "Could not find a valid template for the given token. Token: invalidTemplateToken"

  • When we POST a request with a valid template token in the URL as : /xls/validTemplateToken with an empty JSON data, an exception would be thrown saying that "JSON data cannot be empty"

  • When we POST a request with a valid template token in the URL as : /xls/validTemplateToken with invalid JSON data, an exception would be thrown saying that "JSON is not valid"

  • When we POST a request with a valid template token in the URL as : /xls/validTemplateToken with a valid JSON data, and if there is an internal error for some reason, an exception would be thrown saying that "Unable to generate excel from template and JSON due to internal error"

  • When we POST a request with an invalid excel token in the URL as : /xls/invalidExcelToken, an exception would be thrown saying that "Could not find a valid excel for the given token. Token: invalidExcelToken"

json-to-xls's People

Contributors

thirunar avatar kirang20 avatar sowmyasmr avatar mberg avatar sushmitharaos avatar

Watchers

 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.