├── .coveralls.yml ├── .gitattributes ├── .travis.yml ├── 2permissions.png ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SampleReports ├── TEST_REPORT.csv ├── TEST_REPORT.html └── TEST_REPORT.pdf ├── _config.yml ├── pom.xml ├── src ├── main │ ├── assemblies │ │ └── plugin.xml │ ├── java │ │ └── st │ │ │ └── malike │ │ │ └── elastic │ │ │ └── report │ │ │ └── engine │ │ │ ├── ElasticReportPlugin.java │ │ │ ├── ReportGenerateRestAction.java │ │ │ ├── exception │ │ │ ├── IndexNotFoundException.java │ │ │ ├── JasperGenerationException.java │ │ │ ├── NoDataFoundException.java │ │ │ ├── ReportFormatUnknownException.java │ │ │ ├── ReportGenerationException.java │ │ │ └── TemplateNotFoundException.java │ │ │ ├── generate │ │ │ ├── GenerateData.java │ │ │ └── GenerateResponseListener.java │ │ │ ├── service │ │ │ ├── GenerateCSVReport.java │ │ │ ├── GenerateHTMLReport.java │ │ │ ├── GeneratePDFReport.java │ │ │ ├── GenerateReportService.java │ │ │ └── Generator.java │ │ │ └── util │ │ │ ├── JSONResponse.java │ │ │ └── ReportResponse.java │ └── resources │ │ ├── plugin-descriptor.properties │ │ └── plugin-security.policy └── test │ ├── java │ └── st │ │ └── malike │ │ └── elastic │ │ └── report │ │ └── engine │ │ ├── ElasticReportPluginTest.java │ │ └── service │ │ └── GenerateReportServiceTest.java │ └── resources │ └── log4j.xml └── templates ├── SampleTemplate.jasper └── SampleTemplate.jrxml /.coveralls.yml: -------------------------------------------------------------------------------- 1 | repo_token: 6a984NXOpMvUCaI3HRVl4p5fqpvD5KDJW 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | SampleReports/*.html linguist-language=Java 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | -------------------------------------------------------------------------------- /2permissions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malike/elasticsearch-report-engine/3b9988656c5cc8b7009166a2dc42ab5a96bd6b37/2permissions.png -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | --- 4 | 5 | # Contributor Covenant Code of Conduct 6 | 7 | ## Our Pledge 8 | 9 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 10 | 11 | ## Our Standards 12 | 13 | Examples of behavior that contributes to creating a positive environment include: 14 | 15 | * Using welcoming and inclusive language 16 | * Being respectful of differing viewpoints and experiences 17 | * Gracefully accepting constructive criticism 18 | * Focusing on what is best for the community 19 | * Showing empathy towards other community members 20 | 21 | Examples of unacceptable behavior by participants include: 22 | 23 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 24 | * Trolling, insulting/derogatory comments, and personal or political attacks 25 | * Public or private harassment 26 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 27 | * Other conduct which could reasonably be considered inappropriate in a professional setting 28 | 29 | ## Our Responsibilities 30 | 31 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 32 | 33 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 34 | 35 | ## Scope 36 | 37 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 38 | 39 | ## Enforcement 40 | 41 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at st.malike@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 42 | 43 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 44 | 45 | ## Attribution 46 | 47 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 48 | 49 | [homepage]: http://contributor-covenant.org 50 | [version]: http://contributor-covenant.org/version/1/4/ 51 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | --- 4 | 5 | # Contributing 6 |

 

7 | 8 | ![FOSS](https://github.com/malike/malike.github.io/blob/master/images/foss.jpg?raw=true) 9 | 10 | ## 1. [TDD](https://en.wikipedia.org/wiki/Test-driven_development) 11 | 12 | _"Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: Requirements are turned into very specific test cases, then the software is improved to pass the new tests, only. This is opposed to software development that allows software to be added that is not proven to meet requirements."_ 13 | 14 | #### Resources 15 | 16 | i. [https://technologyconversations.com/2013/12/24/test-driven-development-tdd-best-practices-using-java-examples-2/](https://technologyconversations.com/2013/12/24/test-driven-development-tdd-best-practices-using-java-examples-2/) 17 | 18 | ii. [https://dzone.com/articles/introduction-to-java-tdd](https://dzone.com/articles/introduction-to-java-tdd) 19 | 20 | 21 | ## 2. Where to start? 22 | 23 | #### i. Found a bug 24 | 25 | If you've found a bug in the project. Kindly create a [ticket](https://github.com/malike/elasticsearch-report-engine/issues/new). We'll do our best to respond and/or fix ASAP. 26 | 27 | #### ii. Fix a bug 28 | 29 | Want to go a step further after finding a bug?. Fix it and submit a [PR](https://github.com/malike/elasticsearch-report-engine/compare) 30 | 31 | #### iii. Implement a new feature 32 | 33 | Add it and submit a [PR](https://github.com/malike/elasticsearch-report-engine/compare) 34 | 35 | 36 | 37 | 38 | 39 | 40 |

 

41 |

 

42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/malike/elasticsearch-report-engine.svg?branch=master)](https://travis-ci.org/malike/elasticsearch-report-engine) [![Coverage Status](https://coveralls.io/repos/github/malike/elasticsearch-report-engine/badge.svg?branch=master)](https://coveralls.io/github/malike/elasticsearch-report-engine?branch=master) 2 | 3 | 4 | 5 | Plugin to generate Reports from Elasticsearch Queries. 6 | 7 | - [Basic Overview](#overview) 8 | - [Install](#install) 9 | - [Usage](#usage) 10 | - [PDF](#pdf) 11 | - [HTML](#html) 12 | - [CSV](#csv) 13 | - [Download](#download) 14 | - [Scheduling](#scheduling) 15 | - [Contribute](CONTRIBUTING.md) 16 | - [Code of Conduct](CODE_OF_CONDUCT.md) 17 | - [License](https://github.com/malike/elasticsearch-report-engine/blob/master/LICENSE) 18 | 19 | 20 | 21 | ## Overview 22 | Once this plugin is installed into elasticsearch search,it exposes the url http://{ip}:9200/_generate, you can run queries on your cluster with the right parameters it would return PDF,HTML or CSV file. 23 | 24 |
25 | 26 | ## Install 27 | 28 | _1. Install plugin_ 29 | 30 | ```shell 31 | sudo bin/elasticsearch-plugin install https://github.com/malike/elasticsearch-report-engine/releases/download/5.4.0/st.malike.elasticsearch.report.engine-5.4.0.zip 32 | ``` 33 | 34 | _2. Grant permissions_ 35 | 36 | ![Grant Access](2permissions.png) 37 | 38 | 39 | _3. Folder Structure_ 40 | 41 | Create folders `templates` and `reports` in `ES_HOME`. Store your `*.jasper` and `*.jrxml` 42 | files in the `templates` folder and pass the templateName as the `template` (with the right 43 | extension) parameter for `HTML` and `PDF` reports. 44 | 45 | 46 | 47 |
48 | 49 | ## Usage 50 | 51 | ## PDF 52 | 53 | **1. PDF Report** 54 | 55 | The plugin uses [Jasper Report](https://community.jaspersoft.com/) as core engine for generating PDF reports. 56 | PDF templates can be designed using [iReport Designer](https://community.jaspersoft.com/wiki/ireport-designer-getting-started). This 57 | generates a `jrmxl` file. You can also use the compiled file with the extension `jasper`. 58 | 59 | The plugin generates [base64 encoded](https://en.wikipedia.org/wiki/Base64) stream of the PDF report generated once 60 | you pass the name of the template file and the query to fetch data from Elasticsearch. 61 | 62 | 63 | _**PDF Sample Request**_ 64 | 65 | ```shell 66 | curl -H "Content-Type:application/json" -XPOST "http://localhost:9201/_generate" -d '{"format":"PDF","fileName":"TEST_REPORT","index":"reportindex","template":"filename.jrxml","from":0,"size":10,"query":"{term:{description:Transaction}}"}' 67 | ``` 68 | 69 | _**Parameters**_ 70 | 71 |

72 | i. *format* : Format of Report **[Required]**
73 | ii. *index* : Elasticsearch Index **[Required]**
74 | iii. *template* : Jasper Report Template **[Required]**
75 | iv. *from* : Offset for querying large data **[Optional]**
76 | v. *size* : Size for querying large data **[Optional]**
77 | iv. *query* : Query to search Elasticsearch index **[Optional : Defaults to '*' if nothing is passed]**
78 | vi. *fileName* : File name **[Optional]**
79 | 80 | 81 | 82 | _**Generate PDF Response**_ 83 | 84 | 85 | i. Success 86 | 87 | ```json 88 | {"status":true, 89 | "count":1, 90 | "data": "base 64 encoded string", 91 | "message":"SUCCESS" 92 | } 93 | ``` 94 | 95 | ii. Missing Required Param 96 | 97 | ```json 98 | {"status":false, 99 | "count":0, 100 | "data": null, 101 | "message":"MISSING_PARAM" 102 | } 103 | ``` 104 | 105 | 106 | iii. Report Format Unknown 107 | 108 | ```json 109 | {"status":false, 110 | "count":0, 111 | "data": null, 112 | "message":"REPORT_FORMAT_UNKNOWN" 113 | } 114 | ``` 115 | 116 | iii. System Error Generating Report 117 | 118 | ```json 119 | {"status":false, 120 | "count":0, 121 | "data": null, 122 | "message":"ERROR_GENERATING_REPORT" 123 | } 124 | ``` 125 | 126 | [Sample PDF](https://github.com/malike/elasticsearch-report-engine/blob/master/SampleReports/TEST_REPORT.pdf) 127 |

128 | 129 | ## HTML 130 | 131 | **2. HTML Report** 132 | 133 | Just like the PDF report,the HTML also uses [Jasper Report](https://community.jaspersoft.com/) as core engine for generating reports. 134 | 135 | HTML Reports provides an alternative for use cases where reports should not be sent as an attached file. 136 | 137 | The generates [base64 encoded](https://en.wikipedia.org/wiki/Base64) stream of the HTML report generated. 138 | There's also an option to return the HTML string instead of the base64 encoded string. This 139 | requires passing `returnAs:PLAIN` as part of the request JSON. 140 | 141 | _**HTML Sample Request**_ 142 | 143 | ```shell 144 | curl -H "Content-Type:application/json" -XPOST "http://localhost:9201/_generate" -d '{"format":"HTML","fileName":"TEST_REPORT","index":"reportindex","template":"filename.jrxml","from":0,"size":10,"query":"{term:{description:Transaction}}"}' 145 | ``` 146 | 147 | _**Parameters**_ 148 | 149 |

150 | i. *format* : Format of Report **[Required]**
151 | ii. *index* : Elasticsearch Index **[Required]**
152 | iii. *template* : Jasper Report Template **[Required]**
153 | iv. *from* : Offset for querying large data **[Optional]**
154 | v. *size* : Size for querying large data **[Optional]**
155 | iv. *query* : Query to search Elasticsearch index **[Optional : Defaults to '*' if nothing is passed]**
156 | vi. *fileName* : File name **[Optional]**
157 | vii. *returnAs* : How you want HTML file returned. Possible values _PLAIN_ and _BASE64_ **[Optional : Defaults to BASE64]**
158 | 159 | 160 | _**Generate HTML Response**_ 161 | 162 | 163 | i. Success 164 | 165 | ```json 166 | {"status":true, 167 | "count":1, 168 | "data": "base 64 encoded string", 169 | "message":"SUCCESS" 170 | } 171 | ``` 172 | 173 | ii. Missing Required Param 174 | 175 | ```json 176 | {"status":false, 177 | "count":0, 178 | "data": null, 179 | "message":"MISSING_PARAM" 180 | } 181 | ``` 182 | 183 | iii. Report Format Unknown 184 | 185 | ```json 186 | {"status":false, 187 | "count":0, 188 | "data": null, 189 | "message":"REPORT_FORMAT_UNKNOWN" 190 | } 191 | ``` 192 | 193 | iii. System Error Generating Report 194 | 195 | ```json 196 | {"status":false, 197 | "count":0, 198 | "data": null, 199 | "message":"ERROR_GENERATING_REPORT" 200 | } 201 | ``` 202 | 203 | [Sample HTML](https://github.com/malike/elasticsearch-report-engine/blob/master/SampleReports/TEST_REPORT.html) 204 |

205 | 206 | _*Note: For HTML reports you want returned as HTML string instead of a base64 encoded string. 207 | Send this parameter as part of your default parameters_ : _"returnAs":"PLAIN_ 208 | 209 | ## CSV 210 | 211 | **3. CSV Report** 212 | 213 | Unlike the PDF and HTML reports,the CSV option does not use [Jasper Report](https://community.jaspersoft.com/) as core engine for generating reports. 214 | Generating a CSV report uses the query and returns a [base64 encoded](https://en.wikipedia.org/wiki/Base64) of the file. 215 | 216 | 217 | **_CSV Sample Request_** 218 | 219 | ```shell 220 | curl -H "Content-Type:application/json" -XPOST "http://localhost:9201/_generate" -d '{"format":"CSV","fileName":"TEST_REPORT","index":"reportindex","from":0,"size":10,"query":"{term:{description:Transaction}}"}' 221 | ``` 222 | 223 | Parameters 224 | 225 |

226 | i. *format* : Format of Report **[Required]**
227 | ii. *index* : Elasticsearch Index **[Required]**
228 | iii. *returnAs* : How you want CSV file returned. Possible values _PLAIN_ and _BASE64_ **[Optional : Defaults to BASE64]**
229 | iv. *from* : Offset for querying large data **[Optional]**
230 | v. *size* : Size for querying large data **[Optional]**
231 | iv. *query* : Query to search Elasticsearch index **[Optional : Defaults to '*' if nothing is passed]**
232 | vi. *fileName* : File name **[Optional]**
233 | 234 | _**CSV Sample Response**_ 235 | 236 | 237 | i. Success 238 | 239 | ```json 240 | {"status":true, 241 | "count":1, 242 | "data": "base 64 encoded string", 243 | "message":"SUCCESS" 244 | } 245 | ``` 246 | 247 | ii. Missing Required Param 248 | 249 | ```json 250 | {"status":false, 251 | "count":0, 252 | "data": null, 253 | "message":"MISSING_PARAM" 254 | } 255 | ``` 256 | 257 | iii. Report Format Unknown 258 | 259 | ```json 260 | {"status":false, 261 | "count":0, 262 | "data": null, 263 | "message":"REPORT_FORMAT_UNKNOWN" 264 | } 265 | ``` 266 | 267 | iii. System Error Generating Report 268 | 269 | ```json 270 | {"status":false, 271 | "count":0, 272 | "data": null, 273 | "message":"ERROR_GENERATING_REPORT" 274 | } 275 | ``` 276 | 277 | [Sample CSV](https://github.com/malike/elasticsearch-report-engine/blob/master/SampleReports/TEST_REPORT.csv) 278 | 279 |

280 | 281 | _*Note: For CSV reports you want returned as comma separated values instead of a base64 encoded string. 282 | Send this parameter as part of your default parameters_ : _"returnAs":"PLAIN_ 283 | 284 | 285 |

 

286 |

 

287 | 288 | ## Download 289 | 290 | Elasticsearch versions supported by this plugin include : 291 | 292 | | Elasticsearch Version| Report Plugin Version | Comments | 293 | | --------------------- | -------- |-------- | 294 | | 5.4.0|[zip](https://github.com/malike/elasticsearch-report-engine/releases/download/5.4.0/st.malike.elasticsearch.report.engine-5.4.0.zip)| Tested | 295 | | 5.6.10|[zip](https://github.com/malike/elasticsearch-report-engine/releases/download/5.6.10/st.malike.elasticsearch.report.engine-5.6.10.zip)| Tested | 296 | 297 |

 

298 |

 

299 | 300 | 301 |

 

302 |

 

303 | 304 | ## Scheduling 305 | 306 | This plugin can work with an [alerting system](https://malike.github.io/go-kafka-alert/) and a custom [elasticsearch watcher](https://malike.github.io/elasticsearch-kafka-watch/) to send emailed reports to specific contacts. By creating your watcher events in the [custom elasticsearch watch](https://malike.github.io/elasticsearch-kafka-watch/), events would be pushed to Apache Kafka once there's a _hit_, [go-kafka-alert](https://malike.github.io/go-kafka-alert/) listening on Apache Kafka for events would react by emailing embedded **HTML** reports or attached **CSV** or **PDF** reports. 307 | 308 | This requires no updates to this plugin but setup and configurations in [go-kafka-alert](https://malike.github.io/go-kafka-alert/) and [elasticsearch watcher](https://malike.github.io/elasticsearch-kafka-watch/) 309 | 310 | ## Contribute 311 | 312 | Contributions are always welcome! 313 | Please read the [contribution guidelines](CONTRIBUTING.md) first. 314 | 315 | ## Code of Conduct 316 | 317 | Please read [this](CODE_OF_CONDUCT.md). 318 | 319 | ## License 320 | 321 | [GNU General Public License v3.0](https://github.com/malike/elasticsearch-report-engine/blob/master/LICENSE) 322 | 323 | 324 | -------------------------------------------------------------------------------- /SampleReports/TEST_REPORT.csv: -------------------------------------------------------------------------------- 1 | description ,id ,type 2 | Transaction 100,100,CREDIT 3 | Transaction 99 ,99 ,CREDIT 4 | Transaction 98 ,98 ,CREDIT 5 | Transaction 97 ,97 ,DEBIT 6 | Transaction 96 ,96 ,DEBIT 7 | Transaction 95 ,95 ,DEBIT 8 | Transaction 94 ,94 ,DEBIT 9 | Transaction 93 ,93 ,CREDIT 10 | Transaction 92 ,92 ,CREDIT 11 | Transaction 91 ,91 ,DEBIT 12 | Transaction 90 ,90 ,DEBIT 13 | Transaction 89 ,89 ,CREDIT 14 | Transaction 88 ,88 ,CREDIT 15 | Transaction 87 ,87 ,DEBIT 16 | Transaction 86 ,86 ,DEBIT 17 | Transaction 85 ,85 ,DEBIT 18 | Transaction 84 ,84 ,DEBIT 19 | Transaction 83 ,83 ,CREDIT 20 | Transaction 82 ,82 ,CREDIT 21 | Transaction 81 ,81 ,CREDIT 22 | Transaction 80 ,80 ,CREDIT 23 | Transaction 79 ,79 ,DEBIT 24 | Transaction 78 ,78 ,DEBIT 25 | Transaction 77 ,77 ,DEBIT 26 | Transaction 76 ,76 ,CREDIT 27 | Transaction 75 ,75 ,DEBIT 28 | Transaction 74 ,74 ,CREDIT 29 | Transaction 73 ,73 ,DEBIT 30 | Transaction 72 ,72 ,CREDIT 31 | Transaction 71 ,71 ,CREDIT 32 | Transaction 70 ,70 ,DEBIT 33 | Transaction 69 ,69 ,DEBIT 34 | Transaction 68 ,68 ,DEBIT 35 | Transaction 67 ,67 ,DEBIT 36 | Transaction 66 ,66 ,DEBIT 37 | Transaction 65 ,65 ,DEBIT 38 | Transaction 64 ,64 ,CREDIT 39 | Transaction 63 ,63 ,DEBIT 40 | Transaction 62 ,62 ,CREDIT 41 | Transaction 61 ,61 ,DEBIT 42 | Transaction 60 ,60 ,DEBIT 43 | Transaction 59 ,59 ,DEBIT 44 | Transaction 58 ,58 ,DEBIT 45 | Transaction 57 ,57 ,CREDIT 46 | Transaction 56 ,56 ,CREDIT 47 | Transaction 55 ,55 ,DEBIT 48 | Transaction 54 ,54 ,DEBIT 49 | Transaction 53 ,53 ,CREDIT 50 | Transaction 52 ,52 ,DEBIT 51 | Transaction 51 ,51 ,DEBIT 52 | Transaction 50 ,50 ,DEBIT 53 | Transaction 49 ,49 ,DEBIT 54 | Transaction 48 ,48 ,CREDIT 55 | Transaction 47 ,47 ,CREDIT 56 | Transaction 46 ,46 ,DEBIT 57 | Transaction 45 ,45 ,CREDIT 58 | Transaction 44 ,44 ,CREDIT 59 | Transaction 43 ,43 ,CREDIT 60 | Transaction 42 ,42 ,DEBIT 61 | Transaction 41 ,41 ,DEBIT 62 | Transaction 40 ,40 ,DEBIT 63 | Transaction 39 ,39 ,CREDIT 64 | Transaction 38 ,38 ,CREDIT 65 | Transaction 37 ,37 ,CREDIT 66 | Transaction 36 ,36 ,DEBIT 67 | Transaction 35 ,35 ,CREDIT 68 | Transaction 34 ,34 ,DEBIT 69 | Transaction 33 ,33 ,DEBIT 70 | Transaction 32 ,32 ,CREDIT 71 | Transaction 31 ,31 ,CREDIT 72 | Transaction 30 ,30 ,CREDIT 73 | Transaction 29 ,29 ,DEBIT 74 | Transaction 28 ,28 ,DEBIT 75 | Transaction 27 ,27 ,CREDIT 76 | Transaction 26 ,26 ,DEBIT 77 | Transaction 25 ,25 ,DEBIT 78 | Transaction 24 ,24 ,CREDIT 79 | Transaction 23 ,23 ,DEBIT 80 | Transaction 22 ,22 ,CREDIT 81 | Transaction 21 ,21 ,CREDIT 82 | Transaction 20 ,20 ,DEBIT 83 | Transaction 19 ,19 ,DEBIT 84 | Transaction 18 ,18 ,CREDIT 85 | Transaction 17 ,17 ,CREDIT 86 | Transaction 16 ,16 ,CREDIT 87 | Transaction 15 ,15 ,DEBIT 88 | Transaction 14 ,14 ,CREDIT 89 | Transaction 13 ,13 ,DEBIT 90 | Transaction 12 ,12 ,DEBIT 91 | Transaction 11 ,11 ,DEBIT 92 | Transaction 10 ,10 ,DEBIT 93 | Transaction 9 ,9 ,DEBIT 94 | Transaction 8 ,8 ,DEBIT 95 | Transaction 7 ,7 ,DEBIT 96 | Transaction 6 ,6 ,CREDIT 97 | Transaction 5 ,5 ,CREDIT 98 | Transaction 4 ,4 ,CREDIT 99 | Transaction 3 ,3 ,CREDIT 100 | Transaction 2 ,2 ,DEBIT 101 | Transaction 1 ,1 ,CREDIT 102 | -------------------------------------------------------------------------------- /SampleReports/TEST_REPORT.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malike/elasticsearch-report-engine/3b9988656c5cc8b7009166a2dc42ab5a96bd6b37/SampleReports/TEST_REPORT.pdf -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-architect 2 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | elasticsearch-report-engine 8 | st.malike.elasticsearch.report.engine 9 | 5.6.10 10 | Plugin: Report Engine 11 | A plugin to generate PDF reports with ElasticSearch 12 | 13 | 14 | 15 | org.elasticsearch.distribution.zip 16 | false 17 | 5.6.10 18 | 2.8.2 19 | 20 | 21 | 22 | 23 | GNU General Public License v3.0 24 | https://github.com/malike/elasticsearch-report-engine/blob/master/LICENSE 25 | repo 26 | 27 | 28 | 29 | 30 | 31 | 32 | st.malike@gmail.com 33 | Malike 34 | http://malike.github.io 35 | malike 36 | 37 | 38 | 39 | 40 | 41 | maven 42 | mvn 43 | http://central.maven.org/maven2/ 44 | 45 | 46 | jasper 47 | http://jaspersoft.artifactoryonline.com/jaspersoft/jaspersoft-repo/ 48 | 49 | 50 | 51 | 52 | 53 | 54 | maven 55 | http://central.maven.org/maven2/ 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | org.mockito 64 | mockito-core 65 | 1.9.0 66 | test 67 | 68 | 69 | 70 | org.hamcrest 71 | hamcrest-core 72 | 1.3 73 | test 74 | 75 | 76 | 77 | com.jayway.restassured 78 | rest-assured 79 | 2.9.0 80 | test 81 | 82 | 83 | 84 | org.mockito 85 | mockito-all 86 | 1.9.5 87 | test 88 | 89 | 90 | 91 | org.elasticsearch 92 | elasticsearch 93 | ${elasticsearch.version} 94 | provided 95 | 96 | 97 | org.apache.logging.log4j 98 | log4j-api 99 | ${log4j.version} 100 | provided 101 | 102 | 103 | 104 | org.codelibs 105 | elasticsearch-cluster-runner 106 | 5.6.8.0 107 | test 108 | 109 | 110 | commons-logging 111 | commons-logging 112 | 113 | 114 | 115 | 116 | junit 117 | junit 118 | 4.12 119 | test 120 | 121 | 122 | 123 | net.sf.jasperreports 124 | jasperreports-fonts 125 | 4.0.0 126 | 127 | 128 | net.sf.jasperreports 129 | jasperreports 130 | 6.5.1 131 | 132 | 133 | commons-beanutils 134 | commons-beanutils 135 | 136 | 137 | org.bouncycastle 138 | bcprov-jdk14 139 | 140 | 141 | org.bouncycastle 142 | bcmail-jdk14 143 | 144 | 145 | org.apache.xmlbeans 146 | xmlbeans 147 | 148 | 149 | org.apache.geronimo.specs 150 | geronimo-stax-api_1.0_spec 151 | 152 | 153 | org.apache.lucene 154 | lucene-sandbox 155 | 156 | 157 | org.apache.lucene 158 | lucene-queries 159 | 160 | 161 | org.apache.lucene 162 | lucene-queryparser 163 | 164 | 165 | stax 166 | stax-api 167 | 168 | 169 | com.fasterxml.jackson.core 170 | jackson-core 171 | 172 | 173 | org.apache.lucene 174 | lucene-analyzers-common 175 | 176 | 177 | org.apache.lucene 178 | lucene-core 179 | 180 | 181 | commons-collections 182 | commons-collections 183 | 184 | 185 | org.springframework 186 | spring-aop 187 | 188 | 189 | org.springframework 190 | spring-asm 191 | 192 | 193 | org.springframework 194 | spring-beans 195 | 196 | 197 | org.springframework 198 | spring-context 199 | 200 | 201 | 202 | 203 | org.apache.poi 204 | poi 205 | 3.10-FINAL 206 | 207 | 208 | org.codehaus.groovy 209 | groovy 210 | runtime 211 | 2.3.11 212 | 213 | 214 | org.apache.xmlgraphics 215 | batik-svggen 216 | 1.9 217 | 218 | 219 | xml-apis 220 | xml-apis 221 | 222 | 223 | 224 | 225 | org.apache.xmlgraphics 226 | batik-dom 227 | 1.9 228 | 229 | 230 | org.apache.xmlgraphics 231 | batik-ext 232 | 233 | 234 | xml-apis 235 | xml-apis 236 | 237 | 238 | 239 | 240 | org.apache.xmlgraphics 241 | batik-bridge 242 | 1.9 243 | 244 | 245 | xml-apis 246 | xml-apis 247 | 248 | 249 | xml-apis 250 | xml-apis-ext 251 | 252 | 253 | xalan 254 | xalan 255 | 256 | 257 | 258 | 259 | com.google.code.gson 260 | gson 261 | 2.8.1 262 | 263 | 264 | commons-io 265 | commons-io 266 | 1.3.2 267 | 268 | 269 | commons-beanutils 270 | commons-beanutils 271 | 1.9.2 272 | 273 | 274 | commons-lang 275 | commons-lang 276 | 2.6 277 | jar 278 | 279 | 280 | commons-collections 281 | commons-collections 282 | 3.2.2 283 | jar 284 | 285 | 286 | com.github.wnameless 287 | json-flattener 288 | 0.1.0 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | src/main/resources 297 | false 298 | 299 | *.properties 300 | 301 | 302 | 303 | SampleReports 304 | false 305 | 306 | *.csv 307 | *.pdf 308 | *.html 309 | 310 | 311 | 312 | 313 | 314 | org.apache.maven.plugins 315 | maven-assembly-plugin 316 | 2.6 317 | 318 | false 319 | ${project.build.directory}/releases/ 320 | 321 | ${basedir}/src/main/assemblies/plugin.xml 322 | 323 | 324 | 325 | 326 | package 327 | 328 | single 329 | 330 | 331 | 332 | 333 | 334 | org.apache.maven.plugins 335 | maven-compiler-plugin 336 | 3.3 337 | 338 | 1.8 339 | 1.8 340 | 341 | 342 | 343 | 344 | org.apache.maven.plugins 345 | maven-surefire-plugin 346 | 2.9 347 | 348 | false 349 | 350 | 351 | 352 | com.carrotsearch.randomizedtesting 353 | junit4-maven-plugin 354 | 2.3.3 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | unit-tests 369 | test 370 | 371 | junit4 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | -------------------------------------------------------------------------------- /src/main/assemblies/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | plugin 4 | 5 | zip 6 | 7 | false 8 | 9 | 10 | ${project.basedir}/src/main/resources/plugin-descriptor.properties 11 | elasticsearch 12 | true 13 | 14 | 15 | ${project.basedir}/src/main/resources/plugin-security.policy 16 | elasticsearch 17 | true 18 | 19 | 20 | 21 | 22 | elasticsearch 23 | true 24 | true 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/main/java/st/malike/elastic/report/engine/ElasticReportPlugin.java: -------------------------------------------------------------------------------- 1 | package st.malike.elastic.report.engine; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.function.Supplier; 6 | import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; 7 | import org.elasticsearch.cluster.node.DiscoveryNodes; 8 | import org.elasticsearch.common.settings.ClusterSettings; 9 | import org.elasticsearch.common.settings.IndexScopedSettings; 10 | import org.elasticsearch.common.settings.Settings; 11 | import org.elasticsearch.common.settings.SettingsFilter; 12 | import org.elasticsearch.plugins.ActionPlugin; 13 | import org.elasticsearch.plugins.Plugin; 14 | import org.elasticsearch.rest.RestController; 15 | import org.elasticsearch.rest.RestHandler; 16 | 17 | /** 18 | * @author malike_st 19 | */ 20 | public class ElasticReportPlugin extends Plugin implements ActionPlugin { 21 | 22 | @Override 23 | public List getRestHandlers(Settings settings, 24 | RestController restController, ClusterSettings clusterSettings, 25 | IndexScopedSettings indexScopedSettings, 26 | SettingsFilter settingsFilter, 27 | IndexNameExpressionResolver indexNameExpressionResolver, 28 | Supplier nodesInCluster) { 29 | return Arrays.asList(new ReportGenerateRestAction(settings, restController)); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/st/malike/elastic/report/engine/ReportGenerateRestAction.java: -------------------------------------------------------------------------------- 1 | package st.malike.elastic.report.engine; 2 | 3 | import static org.elasticsearch.rest.RestRequest.Method.POST; 4 | 5 | import java.io.IOException; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | import org.elasticsearch.action.search.SearchRequestBuilder; 9 | import org.elasticsearch.action.search.SearchType; 10 | import org.elasticsearch.client.node.NodeClient; 11 | import org.elasticsearch.common.inject.Inject; 12 | import org.elasticsearch.common.settings.Settings; 13 | import org.elasticsearch.common.unit.TimeValue; 14 | import org.elasticsearch.common.xcontent.XContentHelper; 15 | import org.elasticsearch.index.query.QueryBuilders; 16 | import org.elasticsearch.rest.BaseRestHandler; 17 | import org.elasticsearch.rest.BytesRestResponse; 18 | import org.elasticsearch.rest.RestController; 19 | import org.elasticsearch.rest.RestRequest; 20 | import org.elasticsearch.rest.RestStatus; 21 | import org.elasticsearch.search.sort.SortOrder; 22 | import st.malike.elastic.report.engine.generate.GenerateData; 23 | import st.malike.elastic.report.engine.generate.GenerateResponseListener; 24 | import st.malike.elastic.report.engine.service.Generator; 25 | import st.malike.elastic.report.engine.service.Generator.JSONResponseMessage; 26 | import st.malike.elastic.report.engine.util.JSONResponse; 27 | 28 | /** 29 | * @author malike_st. 30 | */ 31 | public class ReportGenerateRestAction extends BaseRestHandler { 32 | 33 | @Inject 34 | public ReportGenerateRestAction(Settings settings, RestController controller) { 35 | super(settings); 36 | controller.registerHandler(POST, "/_generate", this); 37 | } 38 | 39 | @Override 40 | @SuppressWarnings("unchecked") 41 | protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) 42 | throws IOException { 43 | JSONResponse message = new JSONResponse(); 44 | GenerateData generateData = new GenerateData(); 45 | Integer from = null; 46 | Integer size = null; 47 | Map sort = new HashMap(); 48 | String query = null; 49 | String format = null; 50 | Generator.ReturnAs returnAs = Generator.ReturnAs.BASE64; 51 | String templateLocation = null; 52 | String fileName = null; 53 | String index = null; 54 | Map mapData = new HashMap(); 55 | 56 | if (restRequest.content().length() > 0) { 57 | // Let's try to find the name from the body 58 | Map map = XContentHelper.convertToMap(restRequest.content(), false, null) 59 | .v2(); 60 | if (map.containsKey("query")) { 61 | query = (String) map.get("query"); 62 | } 63 | if (map.containsKey("from")) { 64 | from = (Integer) map.get("from"); 65 | } 66 | if (map.containsKey("size")) { 67 | size = (Integer) map.get("size"); 68 | } 69 | if (map.containsKey("sort")) { 70 | sort = (Map) map.get("sort"); 71 | } 72 | if (map.containsKey("query")) { 73 | query = (String) map.get("query"); 74 | } 75 | if (map.containsKey("format")) { 76 | format = (String) map.get("format"); 77 | } 78 | if (map.containsKey("returnAs")) { 79 | try { 80 | returnAs = Generator.ReturnAs.valueOf(((String) map.get("returnAs")).toUpperCase()); 81 | } catch (Exception e) { 82 | } 83 | } 84 | if (map.containsKey("template")) { 85 | templateLocation = (String) map.get("template"); 86 | } 87 | if (map.containsKey("fileName")) { 88 | fileName = (String) map.get("fileName"); 89 | } 90 | if (map.containsKey("index")) { 91 | index = (String) map.get("index"); 92 | } 93 | if (map.containsKey("template")) { 94 | templateLocation = (String) map.get("template"); 95 | } 96 | if (map.containsKey("mapData")) { 97 | mapData = (Map) map.get("mapData"); 98 | } 99 | } 100 | if ((format == null || index == null) 101 | || ((format.toLowerCase().equals("pdf") || (format.toLowerCase().equals("html"))) 102 | && templateLocation == null)) { 103 | return channel -> { 104 | message.setMessage(JSONResponseMessage.MISSING_PARAM.toString()); 105 | message.setStatus(false); 106 | message.setCount(0L); 107 | channel.sendResponse(new BytesRestResponse(RestStatus.OK, 108 | "application/json", message.toString())); 109 | }; 110 | } 111 | Generator.ReportFormat reportFormat = null; 112 | try { 113 | reportFormat = Generator.ReportFormat.valueOf(format.toUpperCase()); 114 | } catch (Exception e) { 115 | } 116 | if (reportFormat == null) { 117 | return channel -> { 118 | message.setMessage(JSONResponseMessage.REPORT_FORMAT_UNKNOWN.toString()); 119 | message.setStatus(false); 120 | message.setCount(0L); 121 | channel.sendResponse(new BytesRestResponse(RestStatus.OK, 122 | "application/json", message.toString())); 123 | }; 124 | } 125 | SearchRequestBuilder prepareSearch = client.prepareSearch(index); 126 | //limit and offset 127 | if (from != null && size != null) { 128 | prepareSearch.setFrom(from); 129 | prepareSearch.setSize(size); 130 | } 131 | 132 | //sort 133 | if (!sort.isEmpty()) { 134 | for (String key : sort.keySet()) { 135 | try { 136 | prepareSearch.addSort(key, SortOrder.fromString(sort.get(key).toUpperCase())); 137 | } catch (Exception e) { 138 | 139 | } 140 | } 141 | } 142 | 143 | prepareSearch.setSearchType(SearchType.QUERY_THEN_FETCH); 144 | if (query != null && !query.isEmpty()) { 145 | prepareSearch.setQuery(QueryBuilders.wrapperQuery(query)); 146 | } else { 147 | prepareSearch.setQuery(QueryBuilders.matchAllQuery()); 148 | } 149 | prepareSearch.setScroll("3m"); 150 | prepareSearch.setTimeout(TimeValue.timeValueMinutes(3)); 151 | generateData.setFileName(fileName); 152 | generateData.setFormat(reportFormat); 153 | generateData.setIndex(index); 154 | generateData.setMapData(mapData); 155 | generateData.setQuery(query); 156 | generateData.setTemplateLocation(templateLocation); 157 | generateData.setReturnAs(returnAs); 158 | return (channel) -> prepareSearch 159 | .execute(new GenerateResponseListener(generateData, channel, restRequest)); 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /src/main/java/st/malike/elastic/report/engine/exception/IndexNotFoundException.java: -------------------------------------------------------------------------------- 1 | package st.malike.elastic.report.engine.exception; 2 | 3 | /** 4 | * @autor malike_st 5 | */ 6 | public class IndexNotFoundException extends Exception { 7 | 8 | public IndexNotFoundException() { 9 | } 10 | 11 | public IndexNotFoundException(String message) { 12 | super(message); 13 | } 14 | 15 | public IndexNotFoundException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | 19 | public IndexNotFoundException(Throwable cause) { 20 | super(cause); 21 | } 22 | 23 | public IndexNotFoundException(String message, Throwable cause, boolean enableSuppression, 24 | boolean writableStackTrace) { 25 | super(message, cause, enableSuppression, writableStackTrace); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/st/malike/elastic/report/engine/exception/JasperGenerationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package st.malike.elastic.report.engine.exception; 7 | 8 | /** 9 | * @author malike_st 10 | */ 11 | public class JasperGenerationException extends Exception { 12 | 13 | public JasperGenerationException() { 14 | } 15 | 16 | public JasperGenerationException(String message) { 17 | super(message); 18 | } 19 | 20 | public JasperGenerationException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | 24 | public JasperGenerationException(Throwable cause) { 25 | super(cause); 26 | } 27 | 28 | public JasperGenerationException(String message, Throwable cause, boolean enableSuppression, 29 | boolean writableStackTrace) { 30 | super(message, cause, enableSuppression, writableStackTrace); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/st/malike/elastic/report/engine/exception/NoDataFoundException.java: -------------------------------------------------------------------------------- 1 | package st.malike.elastic.report.engine.exception; 2 | 3 | /** 4 | * @autor malike_st 5 | */ 6 | public class NoDataFoundException extends Exception { 7 | 8 | public NoDataFoundException() { 9 | } 10 | 11 | public NoDataFoundException(String message) { 12 | super(message); 13 | } 14 | 15 | public NoDataFoundException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | 19 | public NoDataFoundException(Throwable cause) { 20 | super(cause); 21 | } 22 | 23 | public NoDataFoundException(String message, Throwable cause, boolean enableSuppression, 24 | boolean writableStackTrace) { 25 | super(message, cause, enableSuppression, writableStackTrace); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/st/malike/elastic/report/engine/exception/ReportFormatUnknownException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package st.malike.elastic.report.engine.exception; 7 | 8 | /** 9 | * @author malike_st 10 | */ 11 | public class ReportFormatUnknownException extends Exception { 12 | 13 | public ReportFormatUnknownException() { 14 | } 15 | 16 | public ReportFormatUnknownException(String message) { 17 | super(message); 18 | } 19 | 20 | public ReportFormatUnknownException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | 24 | public ReportFormatUnknownException(Throwable cause) { 25 | super(cause); 26 | } 27 | 28 | public ReportFormatUnknownException(String message, Throwable cause, boolean enableSuppression, 29 | boolean writableStackTrace) { 30 | super(message, cause, enableSuppression, writableStackTrace); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/st/malike/elastic/report/engine/exception/ReportGenerationException.java: -------------------------------------------------------------------------------- 1 | package st.malike.elastic.report.engine.exception; 2 | 3 | /** 4 | * @autor malike_st 5 | */ 6 | public class ReportGenerationException extends Exception { 7 | 8 | public ReportGenerationException() { 9 | } 10 | 11 | public ReportGenerationException(String message) { 12 | super(message); 13 | } 14 | 15 | public ReportGenerationException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | 19 | public ReportGenerationException(Throwable cause) { 20 | super(cause); 21 | } 22 | 23 | public ReportGenerationException(String message, Throwable cause, boolean enableSuppression, 24 | boolean writableStackTrace) { 25 | super(message, cause, enableSuppression, writableStackTrace); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/st/malike/elastic/report/engine/exception/TemplateNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package st.malike.elastic.report.engine.exception; 7 | 8 | /** 9 | * @author malike_st 10 | */ 11 | public class TemplateNotFoundException extends Exception { 12 | 13 | public TemplateNotFoundException() { 14 | } 15 | 16 | public TemplateNotFoundException(String message) { 17 | super(message); 18 | } 19 | 20 | public TemplateNotFoundException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | 24 | public TemplateNotFoundException(Throwable cause) { 25 | super(cause); 26 | } 27 | 28 | public TemplateNotFoundException(String message, Throwable cause, boolean enableSuppression, 29 | boolean writableStackTrace) { 30 | super(message, cause, enableSuppression, writableStackTrace); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/st/malike/elastic/report/engine/generate/GenerateData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package st.malike.elastic.report.engine.generate; 7 | 8 | import java.util.Map; 9 | import st.malike.elastic.report.engine.service.Generator; 10 | 11 | /** 12 | * @author malike_st 13 | */ 14 | public class GenerateData { 15 | 16 | private String query; 17 | private Generator.ReportFormat format; 18 | private Generator.ReturnAs returnAs; 19 | private String templateLocation; 20 | private String fileName; 21 | private String index; 22 | private Map mapData; 23 | 24 | 25 | public String getQuery() { 26 | return query; 27 | } 28 | 29 | public void setQuery(String query) { 30 | this.query = query; 31 | } 32 | 33 | public Generator.ReportFormat getFormat() { 34 | return format; 35 | } 36 | 37 | public void setFormat(Generator.ReportFormat format) { 38 | this.format = format; 39 | } 40 | 41 | public Generator.ReturnAs getReturnAs() { 42 | return returnAs; 43 | } 44 | 45 | public void setReturnAs(Generator.ReturnAs returnAs) { 46 | this.returnAs = returnAs; 47 | } 48 | 49 | public String getTemplateLocation() { 50 | return templateLocation; 51 | } 52 | 53 | public void setTemplateLocation(String templateLocation) { 54 | this.templateLocation = templateLocation; 55 | } 56 | 57 | public String getFileName() { 58 | return fileName; 59 | } 60 | 61 | public void setFileName(String fileName) { 62 | this.fileName = fileName; 63 | } 64 | 65 | public String getIndex() { 66 | return index; 67 | } 68 | 69 | public void setIndex(String index) { 70 | this.index = index; 71 | } 72 | 73 | public Map getMapData() { 74 | return mapData; 75 | } 76 | 77 | public void setMapData(Map mapData) { 78 | this.mapData = mapData; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/st/malike/elastic/report/engine/generate/GenerateResponseListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package st.malike.elastic.report.engine.generate; 7 | 8 | import java.io.File; 9 | import java.security.AccessController; 10 | import java.security.PrivilegedExceptionAction; 11 | import java.util.List; 12 | import org.elasticsearch.ElasticsearchException; 13 | import org.elasticsearch.action.ActionListener; 14 | import org.elasticsearch.action.search.SearchResponse; 15 | import org.elasticsearch.common.xcontent.XContentBuilder; 16 | import org.elasticsearch.rest.BytesRestResponse; 17 | import org.elasticsearch.rest.RestChannel; 18 | import org.elasticsearch.rest.RestRequest; 19 | import org.elasticsearch.rest.RestStatus; 20 | import st.malike.elastic.report.engine.exception.NoDataFoundException; 21 | import st.malike.elastic.report.engine.service.Generator; 22 | import st.malike.elastic.report.engine.service.Generator.JSONResponseMessage; 23 | import st.malike.elastic.report.engine.util.JSONResponse; 24 | import st.malike.elastic.report.engine.util.ReportResponse; 25 | 26 | /** 27 | * @author malike_st 28 | */ 29 | public class GenerateResponseListener implements ActionListener { 30 | 31 | private final GenerateData generateData; 32 | private final RestChannel restChannel; 33 | private final RestRequest restRequest; 34 | 35 | public GenerateResponseListener(GenerateData generateData, RestChannel restChannel, 36 | RestRequest restRequest) { 37 | this.generateData = generateData; 38 | this.restChannel = restChannel; 39 | this.restRequest = restRequest; 40 | } 41 | 42 | @Override 43 | public void onResponse(SearchResponse searchResponse) { 44 | //get data 45 | JSONResponse message = new JSONResponse(); 46 | message.setStatus(false); 47 | message.setCount(0L); 48 | message.setMessage(Generator.JSONResponseMessage.ERROR_GENERATING_REPORT.toString()); 49 | try { 50 | 51 | List dataList = generateData.getFormat().extractData(searchResponse); 52 | 53 | ReportResponse reportFileResponse = AccessController.doPrivileged( 54 | new PrivilegedExceptionAction() { 55 | ReportResponse reportResponse = new ReportResponse(); 56 | 57 | @Override 58 | public ReportResponse run() { 59 | try { 60 | 61 | File reportFile = generateData.getFormat() 62 | .generate(generateData.getMapData(), dataList, 63 | generateData.getTemplateLocation(), 64 | generateData.getFileName()); 65 | reportResponse.setReportFile(reportFile); 66 | reportResponse.setResponse("Generated successfully"); 67 | reportResponse.setSuccess(true); 68 | } catch (Exception e) { 69 | reportResponse.setReportFile(null); 70 | reportResponse.setResponse(e.getLocalizedMessage()); 71 | reportResponse.setSuccess(false); 72 | } 73 | return reportResponse; 74 | } 75 | }); 76 | 77 | if (!reportFileResponse.isSuccess()) { 78 | message.setData("FAILED TO GENERATE : " + reportFileResponse.getResponse()); 79 | message.setMessage(JSONResponseMessage.ERROR_GENERATING_REPORT.toString()); 80 | message.setStatus(false); 81 | message.setCount(0L); 82 | restChannel.sendResponse(new BytesRestResponse(RestStatus.OK, 83 | "application/json", message.toString())); 84 | return; 85 | } 86 | message.setMessage(JSONResponseMessage.SUCCESS.toString()); 87 | message.setStatus(true); 88 | message.setCount(Long.valueOf(dataList.size())); 89 | if (generateData.getReturnAs().equals(Generator.ReturnAs.BASE64)) { 90 | message.setData( 91 | generateData.getFormat() 92 | .objectToBase64String(reportFileResponse.getReportFile(), generateData 93 | .getFormat())); 94 | } else { 95 | message.setData(generateData.getFormat() 96 | .getContents(reportFileResponse.getReportFile(), generateData.getFormat())); 97 | } 98 | message.setMessage(Generator.JSONResponseMessage.SUCCESS.toString()); 99 | XContentBuilder builder = restChannel.newBuilder(); 100 | builder.startObject(); 101 | message.toXContent(builder, restRequest); 102 | builder.endObject(); 103 | restChannel.sendResponse(new BytesRestResponse(RestStatus.OK, builder)); 104 | return; 105 | } catch (NoDataFoundException nde) { 106 | message.setData(nde.getLocalizedMessage()); 107 | message.setMessage(JSONResponseMessage.NO_DATA_EXCEPTION.toString()); 108 | message.setStatus(false); 109 | message.setCount(0L); 110 | restChannel.sendResponse(new BytesRestResponse(RestStatus.OK, 111 | "application/json", message.toString())); 112 | return; 113 | } catch (Exception e) { 114 | message.setData(e.getMessage()); 115 | message.setMessage(JSONResponseMessage.ERROR_GENERATING_REPORT.toString()); 116 | message.setStatus(false); 117 | message.setCount(0L); 118 | restChannel.sendResponse(new BytesRestResponse(RestStatus.OK, 119 | "application/json", message.toString())); 120 | return; 121 | } 122 | } 123 | 124 | @Override 125 | public void onFailure(Exception exception) { 126 | JSONResponse message = new JSONResponse(); 127 | message.setData(exception.getMessage()); 128 | message.setMessage(JSONResponseMessage.ERROR_GENERATING_REPORT.toString()); 129 | message.setStatus(false); 130 | message.setCount(0L); 131 | restChannel.sendResponse(new BytesRestResponse(RestStatus.OK, 132 | "application/json", message.toString())); 133 | throw new ElasticsearchException("FAILED : ", 134 | exception.getMessage()); 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /src/main/java/st/malike/elastic/report/engine/service/GenerateCSVReport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package st.malike.elastic.report.engine.service; 7 | 8 | import com.google.gson.Gson; 9 | import java.io.BufferedWriter; 10 | import java.io.File; 11 | import java.io.FileWriter; 12 | import java.io.IOException; 13 | import java.security.AccessController; 14 | import java.security.PrivilegedExceptionAction; 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | import java.util.Map; 18 | import java.util.Set; 19 | import java.util.TreeSet; 20 | import org.apache.commons.lang.StringUtils; 21 | import st.malike.elastic.report.engine.exception.JasperGenerationException; 22 | import st.malike.elastic.report.engine.exception.ReportFormatUnknownException; 23 | import st.malike.elastic.report.engine.exception.TemplateNotFoundException; 24 | import st.malike.elastic.report.engine.util.ReportResponse; 25 | 26 | /** 27 | * @author malike_st 28 | */ 29 | public class GenerateCSVReport implements GenerateReportService { 30 | 31 | /** 32 | * @param params 33 | * @param data 34 | * @param templateFile 35 | * @param fileName 36 | * @param reportFormat 37 | * @return 38 | * @throws TemplateNotFoundException 39 | * @throws JasperGenerationException 40 | * @throws ReportFormatUnknownException 41 | */ 42 | @Override 43 | @SuppressWarnings("unchecked") 44 | public File generateReport(Map params, List data, String templateFile, 45 | String fileName, Generator.ReportFormat reportFormat) 46 | throws JasperGenerationException { 47 | ReportResponse reportFile = null; 48 | try { 49 | if (reportFormat == null) { 50 | throw new ReportFormatUnknownException("Report format unknown"); 51 | } 52 | String filePath = 53 | System.getProperty("user.dir") + 54 | File.separator + "reports" + 55 | File.separator + fileName + "." + reportFormat 56 | .toString().toLowerCase(); 57 | if (data.isEmpty()) { 58 | //throw exception of it not processed 59 | } 60 | 61 | Set headers = new TreeSet<>(); 62 | Map map = (Map) data.get(0); 63 | headers.addAll(map.keySet()); 64 | 65 | if (!headers.isEmpty()) { 66 | //throw exception of it not processed 67 | } 68 | String output = StringUtils.join(headers.toArray(), ",") + "\n"; 69 | for (Object o : data) { 70 | try { 71 | Map dt = (Map) o; 72 | output = output + getData(headers, dt) + "\n"; 73 | } catch (Exception e) { 74 | } 75 | } 76 | 77 | final String csvOutput; 78 | if (output == null) { 79 | csvOutput = "NO Data"; 80 | } else { 81 | csvOutput = output; 82 | } 83 | 84 | reportFile = AccessController.doPrivileged( 85 | new PrivilegedExceptionAction() { 86 | 87 | @Override 88 | public ReportResponse run() { 89 | ReportResponse reportResponse = new ReportResponse(); 90 | try { 91 | 92 | writeToFile(csvOutput, filePath); 93 | File csvFile = new File(filePath); 94 | reportResponse.setReportFile(csvFile); 95 | reportResponse.setSuccess(true); 96 | reportResponse.setResponse("Generated successfully"); 97 | 98 | } catch (Exception e) { 99 | reportResponse.setReportFile(null); 100 | reportResponse.setSuccess(false); 101 | reportResponse.setResponse("Error generating : " + e.getMessage()); 102 | } 103 | return reportResponse; 104 | } 105 | }); 106 | if (reportFile.isSuccess()) { 107 | return reportFile.getReportFile(); 108 | } else { 109 | throw new JasperGenerationException("Error generating CSV : " 110 | + reportFile.getResponse()); 111 | } 112 | } catch (Exception ex) { 113 | throw new JasperGenerationException("Error generating CSV : " 114 | + ((reportFile != null) ? reportFile.getResponse() : ex.getMessage())); 115 | } 116 | } 117 | 118 | private void writeToFile(String output, String fileName) 119 | throws Exception { 120 | BufferedWriter writer = null; 121 | try { 122 | writer = new BufferedWriter(new FileWriter(fileName)); 123 | writer.write(output); 124 | } catch (Exception e) { 125 | throw e; 126 | } finally { 127 | close(writer); 128 | } 129 | } 130 | 131 | private void close(BufferedWriter writer) throws IOException { 132 | try { 133 | if (writer != null) { 134 | writer.close(); 135 | } 136 | } catch (IOException e) { 137 | throw e; 138 | } 139 | } 140 | 141 | private Object getData(Set headers, Map map) { 142 | List os = new ArrayList<>(); 143 | for (String header : headers) { 144 | Object val = map.get(header) == null ? "" : map.get(header); 145 | if (val instanceof String) { 146 | val = ((String) val).replace(",", ""); 147 | } else if (val instanceof List) { 148 | String listVal = new Gson().toJson(val).replace(",", ";"); 149 | val = "\"" + listVal.replace("\"", "\'") + "\""; 150 | } 151 | os.add(val); 152 | } 153 | return StringUtils.join(os.toArray(), ","); 154 | } 155 | 156 | } 157 | -------------------------------------------------------------------------------- /src/main/java/st/malike/elastic/report/engine/service/GenerateHTMLReport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package st.malike.elastic.report.engine.service; 7 | 8 | import java.io.File; 9 | import java.io.FileInputStream; 10 | import java.io.FileNotFoundException; 11 | import java.io.InputStream; 12 | import java.security.AccessController; 13 | import java.security.PrivilegedActionException; 14 | import java.security.PrivilegedExceptionAction; 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | import java.util.Map; 18 | import net.sf.jasperreports.engine.JRDataSource; 19 | import net.sf.jasperreports.engine.JRException; 20 | import net.sf.jasperreports.engine.JasperCompileManager; 21 | import net.sf.jasperreports.engine.JasperExportManager; 22 | import net.sf.jasperreports.engine.JasperFillManager; 23 | import net.sf.jasperreports.engine.JasperPrint; 24 | import net.sf.jasperreports.engine.JasperReport; 25 | import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; 26 | import net.sf.jasperreports.engine.design.JasperDesign; 27 | import net.sf.jasperreports.engine.util.JRLoader; 28 | import net.sf.jasperreports.engine.xml.JRXmlLoader; 29 | import st.malike.elastic.report.engine.exception.JasperGenerationException; 30 | import st.malike.elastic.report.engine.exception.ReportFormatUnknownException; 31 | import st.malike.elastic.report.engine.exception.TemplateNotFoundException; 32 | import st.malike.elastic.report.engine.util.ReportResponse; 33 | 34 | /** 35 | * @author malike_st 36 | */ 37 | public class GenerateHTMLReport implements GenerateReportService { 38 | 39 | /** 40 | * @param params 41 | * @param data 42 | * @param templateFile 43 | * @param fileName 44 | * @param reportFormat 45 | * @return 46 | * @throws TemplateNotFoundException 47 | * @throws JasperGenerationException 48 | * @throws ReportFormatUnknownException 49 | */ 50 | @Override 51 | @SuppressWarnings("unchecked") 52 | public File generateReport(Map params, List data, String templateFile, String fileName, 53 | Generator.ReportFormat reportFormat) 54 | throws TemplateNotFoundException, JasperGenerationException, 55 | ReportFormatUnknownException, PrivilegedActionException { 56 | try { 57 | if (templateFile == null || templateFile.trim().isEmpty()) { 58 | throw new TemplateNotFoundException("Template file not found"); 59 | } 60 | if (reportFormat == null) { 61 | throw new ReportFormatUnknownException("Report format unknown"); 62 | } 63 | ReportResponse reportFile = null; 64 | reportFile = AccessController.doPrivileged( 65 | new PrivilegedExceptionAction() { 66 | 67 | @Override 68 | public ReportResponse run() { 69 | ReportResponse reportResponse = new ReportResponse(); 70 | String reportFileLocation = 71 | System.getProperty("user.dir") + 72 | File.separator + "reports" + 73 | File.separator + fileName + "." + reportFormat.toString().toLowerCase(); 74 | 75 | String templateFileLocation = System.getProperty("user.dir") + 76 | File.separator + "templates" + 77 | File.separator + templateFile; 78 | try { 79 | 80 | InputStream reportStream = new FileInputStream(new File(templateFileLocation)); 81 | JasperReport jr; 82 | if (templateFile.endsWith("jasper")) { 83 | jr = (JasperReport) JRLoader.loadObject( 84 | new File(templateFileLocation)); 85 | } else if (templateFile.endsWith("jrxml")) { 86 | JasperDesign jd = JRXmlLoader.load(reportStream); 87 | jr = JasperCompileManager.compileReport(jd); 88 | } else { 89 | reportResponse.setReportFile(null); 90 | reportResponse.setSuccess(false); 91 | reportResponse.setResponse("Jasper Report Template file not supported"); 92 | return reportResponse; 93 | } 94 | JasperPrint jp = JasperFillManager.fillReport(jr, params, getDatasource(data)); 95 | JasperExportManager.exportReportToHtmlFile(jp, reportFileLocation); 96 | File htmlFile = new File(reportFileLocation); 97 | reportResponse.setReportFile(htmlFile); 98 | reportResponse.setSuccess(true); 99 | reportResponse.setResponse("Generated successfully"); 100 | return reportResponse; 101 | } catch (RuntimeException e) { 102 | reportResponse.setReportFile(null); 103 | reportResponse.setSuccess(false); 104 | reportResponse.setResponse("Permission : " + e.getMessage()); 105 | } catch (FileNotFoundException e) { 106 | reportResponse.setReportFile(null); 107 | reportResponse.setSuccess(false); 108 | reportResponse.setResponse("File Not Found : " + e.getMessage() 109 | + " [\"" + reportFileLocation + "\"]"); 110 | } catch (JRException e) { 111 | reportResponse.setReportFile(null); 112 | reportResponse.setSuccess(false); 113 | reportResponse.setResponse("Jasper Report Exception : " + e.getMessage()); 114 | } 115 | return reportResponse; 116 | } 117 | }); 118 | if (reportFile.isSuccess()) { 119 | return reportFile.getReportFile(); 120 | } else { 121 | throw new JasperGenerationException("Error generating HTML : " 122 | + reportFile.getResponse()); 123 | } 124 | } catch (Exception e) { 125 | throw e; 126 | } 127 | } 128 | 129 | private JRDataSource getDatasource(List data) { 130 | if (null != data) { 131 | return new JRBeanCollectionDataSource(data); 132 | } 133 | return new JRBeanCollectionDataSource(new ArrayList()); 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /src/main/java/st/malike/elastic/report/engine/service/GeneratePDFReport.java: -------------------------------------------------------------------------------- 1 | package st.malike.elastic.report.engine.service; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.FileNotFoundException; 7 | import java.io.FileOutputStream; 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | import java.security.AccessController; 11 | import java.security.PrivilegedActionException; 12 | import java.security.PrivilegedExceptionAction; 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import java.util.Map; 16 | import net.sf.jasperreports.engine.JRDataSource; 17 | import net.sf.jasperreports.engine.JRException; 18 | import net.sf.jasperreports.engine.JRExporterParameter; 19 | import net.sf.jasperreports.engine.JasperCompileManager; 20 | import net.sf.jasperreports.engine.JasperFillManager; 21 | import net.sf.jasperreports.engine.JasperPrint; 22 | import net.sf.jasperreports.engine.JasperReport; 23 | import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; 24 | import net.sf.jasperreports.engine.design.JasperDesign; 25 | import net.sf.jasperreports.engine.export.JRPdfExporter; 26 | import net.sf.jasperreports.engine.util.JRLoader; 27 | import net.sf.jasperreports.engine.xml.JRXmlLoader; 28 | import org.apache.commons.io.IOUtils; 29 | import st.malike.elastic.report.engine.exception.JasperGenerationException; 30 | import st.malike.elastic.report.engine.exception.ReportFormatUnknownException; 31 | import st.malike.elastic.report.engine.exception.TemplateNotFoundException; 32 | import st.malike.elastic.report.engine.service.Generator.ReportFormat; 33 | import st.malike.elastic.report.engine.util.ReportResponse; 34 | 35 | /** 36 | * @author malike_st 37 | */ 38 | public class GeneratePDFReport implements GenerateReportService { 39 | 40 | /** 41 | * @param params 42 | * @param data 43 | * @param templateFile 44 | * @param fileName 45 | * @param reportFormat 46 | * @return 47 | * @throws TemplateNotFoundException 48 | * @throws JasperGenerationException 49 | * @throws ReportFormatUnknownException 50 | */ 51 | @Override 52 | @SuppressWarnings("unchecked") 53 | public File generateReport(Map params, List data, String templateFile, String fileName, 54 | ReportFormat reportFormat) 55 | throws TemplateNotFoundException, JasperGenerationException, ReportFormatUnknownException, 56 | PrivilegedActionException { 57 | try { 58 | if (templateFile == null || templateFile.trim().isEmpty()) { 59 | throw new TemplateNotFoundException("Template file not found"); 60 | } 61 | if (reportFormat == null) { 62 | throw new ReportFormatUnknownException("Report format unknown"); 63 | } 64 | ReportResponse reportFile = null; 65 | reportFile = AccessController.doPrivileged( 66 | new PrivilegedExceptionAction() { 67 | 68 | @Override 69 | public ReportResponse run() { 70 | ReportResponse reportResponse = new ReportResponse(); 71 | String reportFileLocation = 72 | System.getProperty("user.dir") + 73 | File.separator + "reports" + 74 | File.separator + fileName + "." + reportFormat.toString().toLowerCase(); 75 | 76 | String templateFileLocation = System.getProperty("user.dir") + 77 | File.separator + "templates" + 78 | File.separator + templateFile; 79 | try { 80 | 81 | InputStream reportStream = new FileInputStream(new File(templateFileLocation)); 82 | JasperReport jr; 83 | if (templateFile.endsWith("jasper")) { 84 | jr = (JasperReport) JRLoader.loadObject( 85 | new File(templateFileLocation)); 86 | } else if (templateFile.endsWith("jrxml")) { 87 | JasperDesign jd = JRXmlLoader.load(reportStream); 88 | jr = JasperCompileManager.compileReport(jd); 89 | } else { 90 | reportResponse.setReportFile(null); 91 | reportResponse.setSuccess(false); 92 | reportResponse.setResponse("Jasper Report Template file not supported"); 93 | return reportResponse; 94 | } 95 | JasperPrint jp = JasperFillManager.fillReport(jr, params, getDatasource(data)); 96 | byte[] dataInByte; 97 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 98 | exportPdf(jp, byteArrayOutputStream, params); 99 | if (byteArrayOutputStream.size() == 0) { 100 | return null; 101 | } 102 | byteArrayOutputStream.flush(); 103 | dataInByte = byteArrayOutputStream.toByteArray(); 104 | //write file to temp folder 105 | File reportFile = new File(reportFileLocation); 106 | FileOutputStream outputStream = new FileOutputStream(reportFile); 107 | IOUtils.write(dataInByte, outputStream); 108 | outputStream.flush(); 109 | File htmlFile = new File(reportFileLocation); 110 | reportResponse.setReportFile(htmlFile); 111 | reportResponse.setSuccess(true); 112 | reportResponse.setResponse("Generated successfully"); 113 | return reportResponse; 114 | } catch (RuntimeException e) { 115 | reportResponse.setReportFile(null); 116 | reportResponse.setSuccess(false); 117 | reportResponse.setResponse("Permission : " + e.getMessage()); 118 | } catch (FileNotFoundException e) { 119 | reportResponse.setReportFile(null); 120 | reportResponse.setSuccess(false); 121 | reportResponse.setResponse(e.getMessage()); 122 | } catch (JRException e) { 123 | reportResponse.setReportFile(null); 124 | reportResponse.setSuccess(false); 125 | reportResponse.setResponse(e.getMessage()); 126 | } catch (IOException e) { 127 | reportResponse.setReportFile(null); 128 | reportResponse.setSuccess(false); 129 | reportResponse.setResponse(e.getMessage()); 130 | } 131 | return reportResponse; 132 | } 133 | }); 134 | if (reportFile.isSuccess()) { 135 | return reportFile.getReportFile(); 136 | } else { 137 | throw new JasperGenerationException("Error generating PDF : " 138 | + reportFile.getResponse()); 139 | } 140 | } catch (Exception e) { 141 | throw e; 142 | } 143 | } 144 | 145 | private JRDataSource getDatasource(List data) { 146 | if (data != null) { 147 | return new JRBeanCollectionDataSource(data); 148 | } 149 | return new JRBeanCollectionDataSource(new ArrayList()); 150 | } 151 | 152 | private void exportPdf(JasperPrint jp, ByteArrayOutputStream baos, Map params) { 153 | // Create a JRPdfExporter instance 154 | JRPdfExporter exporter = new JRPdfExporter(); 155 | exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp); 156 | exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos); 157 | try { 158 | exporter.exportReport(); 159 | } catch (JRException e) { 160 | 161 | } 162 | } 163 | 164 | } 165 | -------------------------------------------------------------------------------- /src/main/java/st/malike/elastic/report/engine/service/GenerateReportService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package st.malike.elastic.report.engine.service; 7 | 8 | import java.io.File; 9 | import java.security.PrivilegedActionException; 10 | import java.util.List; 11 | import java.util.Map; 12 | import st.malike.elastic.report.engine.exception.JasperGenerationException; 13 | import st.malike.elastic.report.engine.exception.ReportFormatUnknownException; 14 | import st.malike.elastic.report.engine.exception.TemplateNotFoundException; 15 | 16 | /** 17 | * @author malike_st 18 | */ 19 | public interface GenerateReportService { 20 | 21 | public File generateReport(Map params, List data, String templateFile, 22 | String fileName, Generator.ReportFormat reportFormat) 23 | throws TemplateNotFoundException, JasperGenerationException, ReportFormatUnknownException, PrivilegedActionException; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/st/malike/elastic/report/engine/service/Generator.java: -------------------------------------------------------------------------------- 1 | package st.malike.elastic.report.engine.service; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.nio.charset.StandardCharsets; 6 | import java.nio.file.Files; 7 | import java.nio.file.Paths; 8 | import java.security.AccessController; 9 | import java.security.PrivilegedActionException; 10 | import java.security.PrivilegedExceptionAction; 11 | import java.util.HashMap; 12 | import java.util.LinkedList; 13 | import java.util.List; 14 | import java.util.Map; 15 | import java.util.logging.Level; 16 | import java.util.logging.Logger; 17 | import org.apache.commons.codec.binary.Base64; 18 | import org.elasticsearch.action.search.SearchResponse; 19 | import org.elasticsearch.search.SearchHit; 20 | import org.elasticsearch.search.SearchHits; 21 | import st.malike.elastic.report.engine.exception.NoDataFoundException; 22 | import st.malike.elastic.report.engine.exception.ReportGenerationException; 23 | 24 | /** 25 | * @author malike_st 26 | */ 27 | public class Generator { 28 | 29 | public enum JSONResponseMessage { 30 | 31 | REPORT_FORMAT_UNKNOWN, 32 | ERROR_GENERATING_REPORT, 33 | SUCCESS, 34 | NO_DATA_EXCEPTION, 35 | MISSING_PARAM 36 | } 37 | 38 | public enum ReturnAs { 39 | 40 | BASE64, 41 | PLAIN 42 | } 43 | 44 | public enum ReportFormat { 45 | 46 | /** 47 | * PDF Report 48 | */ 49 | PDF { 50 | @Override 51 | @SuppressWarnings("unchecked") 52 | public File generate(Map dataMap, List dataList, String templateFile, 53 | String fileName) throws Exception { 54 | try { 55 | return new GeneratePDFReport() 56 | .generateReport(dataMap, dataList, templateFile, fileName, PDF); 57 | } catch (Exception ex) { 58 | Logger.getLogger(Generator.class.getName()).log(Level.SEVERE, ex.getMessage(), ex); 59 | throw ex; 60 | } 61 | } 62 | }, 63 | /** 64 | * CSV Report 65 | */ 66 | CSV { 67 | @Override 68 | @SuppressWarnings("unchecked") 69 | public File generate(Map dataMap, List dataList, String templateFile, 70 | String fileName) throws Exception { 71 | if (dataList.isEmpty()) { 72 | return null; 73 | } 74 | try { 75 | return new GenerateCSVReport() 76 | .generateReport(dataMap, dataList, templateFile, fileName, CSV); 77 | } catch (Exception ex) { 78 | Logger.getLogger(Generator.class.getName()).log(Level.SEVERE, ex.getMessage(), ex); 79 | throw ex; 80 | } 81 | } 82 | }, 83 | /** 84 | * HTML Report 85 | */ 86 | HTML { 87 | @Override 88 | @SuppressWarnings("unchecked") 89 | public File generate(Map dataMap, List dataList, String templateFile, 90 | String fileName) throws Exception { 91 | try { 92 | return new GenerateHTMLReport() 93 | .generateReport(dataMap, dataList, templateFile, fileName, HTML); 94 | } catch (Exception ex) { 95 | Logger.getLogger(Generator.class.getName()).log(Level.SEVERE, ex.getMessage(), ex); 96 | throw ex; 97 | } 98 | } 99 | }; 100 | 101 | @SuppressWarnings("unchecked") 102 | public abstract File generate(Map dataMap, List dataList, String templateFile, 103 | String fileName) throws Exception; 104 | 105 | /** 106 | * @param file 107 | * @param reportFormat 108 | * @return 109 | * @throws java.io.IOException 110 | */ 111 | @SuppressWarnings("unchecked") 112 | public Map objectToBase64String(File file, ReportFormat reportFormat) 113 | throws IOException, PrivilegedActionException { 114 | if (file == null) { 115 | return null; 116 | } 117 | Map mapResponse = AccessController.doPrivileged( 118 | new PrivilegedExceptionAction() { 119 | 120 | @Override 121 | public Map run() { 122 | Map data = new HashMap(); 123 | try { 124 | data.put("reportFormat", reportFormat.toString()); 125 | data.put("data", Base64.encodeBase64URLSafeString( 126 | Files.readAllBytes(file.toPath()))); 127 | 128 | } catch (Exception e) { 129 | } 130 | return data; 131 | } 132 | }); 133 | return mapResponse; 134 | } 135 | 136 | /** 137 | * @param response 138 | * @return 139 | */ 140 | @SuppressWarnings("unchecked") 141 | public List extractData(SearchResponse response) 142 | throws NoDataFoundException, ReportGenerationException { 143 | List data = new LinkedList<>(); 144 | SearchHits hits = response.getHits(); 145 | if (response.getShardFailures().length > 0) { 146 | throw new ReportGenerationException("Report failed to get data. Kindly try again."); 147 | } 148 | if (hits.getTotalHits() == 0) { 149 | throw new NoDataFoundException("No data found"); 150 | } 151 | try { 152 | for (SearchHit hit : hits) { 153 | Map sourceMap = hit.getSourceAsMap(); 154 | data.add(sourceMap); 155 | } 156 | } catch (Exception e) { 157 | throw new NoDataFoundException("Error extracting data : " + e.getMessage()); 158 | } 159 | return data; 160 | } 161 | 162 | @SuppressWarnings("unchecked") 163 | public Map getContents(File reportFile, ReportFormat reportFormat) 164 | throws IOException, PrivilegedActionException { 165 | if (reportFile == null) { 166 | return null; 167 | } 168 | if (reportFormat.equals(ReportFormat.PDF)) { 169 | //default to base64 if report type is PDF 170 | return objectToBase64String(reportFile, reportFormat); 171 | } 172 | Map mapResponse = AccessController.doPrivileged( 173 | new PrivilegedExceptionAction() { 174 | 175 | @Override 176 | public Map run() { 177 | Map data = new HashMap(); 178 | try { 179 | 180 | byte[] reportFileEncoded = Files 181 | .readAllBytes(Paths.get(reportFile.getAbsolutePath())); 182 | String report = new String(reportFileEncoded, StandardCharsets.UTF_8); 183 | data.put("reportFormat", reportFormat.toString()); 184 | data.put("data", report); 185 | } catch (Exception e) { 186 | } 187 | return data; 188 | } 189 | }); 190 | return mapResponse; 191 | 192 | } 193 | } 194 | 195 | } 196 | -------------------------------------------------------------------------------- /src/main/java/st/malike/elastic/report/engine/util/JSONResponse.java: -------------------------------------------------------------------------------- 1 | package st.malike.elastic.report.engine.util; 2 | 3 | import java.io.IOException; 4 | import org.elasticsearch.common.xcontent.ToXContent; 5 | import org.elasticsearch.common.xcontent.XContentBuilder; 6 | 7 | /** 8 | * @author malike_st 9 | */ 10 | public class JSONResponse implements ToXContent { 11 | 12 | private String message; 13 | private Boolean status; 14 | private Object data; 15 | private Long count; 16 | 17 | public String getMessage() { 18 | return message; 19 | } 20 | 21 | public void setMessage(String message) { 22 | this.message = message; 23 | } 24 | 25 | public Boolean getStatus() { 26 | return status; 27 | } 28 | 29 | public void setStatus(Boolean status) { 30 | this.status = status; 31 | } 32 | 33 | public Object getData() { 34 | return data; 35 | } 36 | 37 | public void setData(Object data) { 38 | this.data = data; 39 | } 40 | 41 | public Long getCount() { 42 | return count; 43 | } 44 | 45 | public void setCount(Long count) { 46 | this.count = count; 47 | } 48 | 49 | @Override 50 | public XContentBuilder toXContent(XContentBuilder xContentBuilder, Params params) 51 | throws IOException { 52 | return xContentBuilder.field("message", message) 53 | .field("status", status) 54 | .field("count", count) 55 | .field("data", data); 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return "{" + 61 | "\"message\":\"" + (message).replace("\"", "\'") + "\"" + 62 | ",\"status\":" + status + 63 | ",\"data\":\"" + ((data == null) ? "\"" 64 | : ((String) data).replace("\"", "\'") + "\"") + 65 | ",\"count\":" + count + 66 | "}"; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/st/malike/elastic/report/engine/util/ReportResponse.java: -------------------------------------------------------------------------------- 1 | package st.malike.elastic.report.engine.util; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * @autor malike_st 7 | */ 8 | public class ReportResponse { 9 | 10 | private File reportFile; 11 | private String response; 12 | private boolean success; 13 | 14 | public File getReportFile() { 15 | return reportFile; 16 | } 17 | 18 | public void setReportFile(File reportFile) { 19 | this.reportFile = reportFile; 20 | } 21 | 22 | public String getResponse() { 23 | return response; 24 | } 25 | 26 | public void setResponse(String response) { 27 | this.response = response; 28 | } 29 | 30 | public boolean isSuccess() { 31 | return success; 32 | } 33 | 34 | public void setSuccess(boolean success) { 35 | this.success = success; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/resources/plugin-descriptor.properties: -------------------------------------------------------------------------------- 1 | description=${project.description} 2 | version=${project.version} 3 | name=${project.artifactId} 4 | classname=st.malike.elastic.report.engine.ElasticReportPlugin 5 | java.version=1.8 6 | elasticsearch.version=${elasticsearch.version} 7 | 8 | -------------------------------------------------------------------------------- /src/main/resources/plugin-security.policy: -------------------------------------------------------------------------------- 1 | grant { 2 | permission java.lang.RuntimePermission "*"; 3 | permission java.lang.reflect.ReflectPermission "*"; 4 | permission java.io.FilePermission "templates/-", "read,write"; 5 | permission java.io.FilePermission "reports/-", "read,write"; 6 | permission java.io.FilePermission "templates\-", "read,write"; 7 | permission java.io.FilePermission "reports\-", "read,write"; 8 | permission java.io.FilePermission "net/sf/jasperreports/-", "read,write"; 9 | permission java.io.FilePermission "net\sf\jasperreports\-", "read,write"; 10 | permission java.util.PropertyPermission "*", "read, write"; 11 | }; -------------------------------------------------------------------------------- /src/test/java/st/malike/elastic/report/engine/ElasticReportPluginTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package st.malike.elastic.report.engine; 7 | 8 | import static com.jayway.restassured.RestAssured.given; 9 | import static org.junit.Assert.assertEquals; 10 | import static st.malike.elastic.report.engine.ElasticReportPluginTest.CDIndicator.randomCDIndicator; 11 | 12 | import com.google.gson.Gson; 13 | import java.io.IOException; 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | import org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner; 17 | import org.elasticsearch.action.search.SearchResponse; 18 | import org.elasticsearch.common.settings.Settings; 19 | import org.elasticsearch.node.Node; 20 | import org.hamcrest.Matchers; 21 | import org.junit.AfterClass; 22 | import org.junit.Before; 23 | import org.junit.BeforeClass; 24 | import org.junit.Ignore; 25 | import org.junit.Test; 26 | import org.junit.runner.RunWith; 27 | import org.junit.runners.BlockJUnit4ClassRunner; 28 | import st.malike.elastic.report.engine.service.Generator; 29 | 30 | @RunWith(BlockJUnit4ClassRunner.class) 31 | @Ignore 32 | public class ElasticReportPluginTest { 33 | 34 | private static final String CLUSTER_NAME = "REPORTDATA_CLUSTER"; 35 | private static final String CLUSTER_HOST_ADDRESS = "localhost:9201-9210"; 36 | private static final String INDEX = "reportindex"; 37 | private static final int DOC_SIZE = 100; 38 | private static Node node; 39 | private static ElasticsearchClusterRunner runner; 40 | private static String TEMPLATE_NAME = "SampleTemplate.jasper"; 41 | private Map param; 42 | 43 | @BeforeClass 44 | public static void setUp() throws IOException { 45 | 46 | runner = new ElasticsearchClusterRunner(); 47 | 48 | runner.onBuild(new ElasticsearchClusterRunner.Builder() { 49 | @Override 50 | public void build(final int number, final Settings.Builder settingsBuilder) { 51 | settingsBuilder.put("http.cors.allow-origin", "*"); 52 | settingsBuilder.put("http.cors.enabled", true); 53 | settingsBuilder.putArray("discovery.zen.ping.unicast.hosts", CLUSTER_HOST_ADDRESS); 54 | } 55 | }).build(ElasticsearchClusterRunner.newConfigs().clusterName(CLUSTER_NAME).numOfNode(1) 56 | .pluginTypes("st.malike.elastic.report.engine.ElasticReportPlugin")); 57 | 58 | runner.ensureYellow(); 59 | 60 | //setupup dummy data 61 | final String type = "reporttype"; 62 | 63 | // create an index 64 | runner.createIndex(INDEX, (Settings) null); 65 | 66 | // create documents 67 | for (int i = 1; i <= DOC_SIZE; i++) { 68 | runner.insert(INDEX, type, String.valueOf(i), 69 | "{" 70 | + "\"type\":\"" + randomCDIndicator().toString() + "\"," 71 | + "\"description\":\"Transaction " + i + "\"," 72 | + "\"id\":" + i 73 | + "}"); 74 | } 75 | runner.refresh(); 76 | 77 | SearchResponse searchResponse = runner.search(INDEX, type, null, null, 0, 10); 78 | assertEquals(DOC_SIZE, searchResponse.getHits().getTotalHits()); 79 | 80 | node = runner.node(); 81 | } 82 | 83 | @AfterClass 84 | public static void tearDown() throws IOException { 85 | runner.close(); 86 | runner.clean(); 87 | } 88 | 89 | @Before 90 | public void setUpTest() { 91 | 92 | Map dummy = new HashMap(); 93 | dummy.put("fullName", "Malike St"); 94 | dummy.put("email", "st.malike@gmail.com"); 95 | dummy.put("age", "15"); 96 | 97 | Map sort = new HashMap(); 98 | sort.put("id", "DESC"); 99 | 100 | // String queryString = "{\"term\":{\"id\":20}}"; 101 | 102 | // String queryString = "{" 103 | // + " \"match\": {" 104 | // + " \"type\": \"CREDIT\"" 105 | // + " }" 106 | // + "}"; 107 | 108 | String queryString = "{" 109 | + " \"match\": {" 110 | + " \"description\": \"Transaction\"" 111 | + " }" 112 | + "}"; 113 | 114 | param = new HashMap(); 115 | param.put("format", "PDF"); 116 | param.put("fileName", "TEST_REPORT"); 117 | param.put("index", INDEX); 118 | param.put("template", TEMPLATE_NAME); 119 | param.put("mapData", dummy); 120 | param.put("from", 0); 121 | param.put("size", DOC_SIZE); 122 | param.put("query", queryString); 123 | param.put("sort", sort); 124 | } 125 | 126 | @Test 127 | public void generateReportPDF() { 128 | given() 129 | .log().all().contentType("application/json") 130 | .body(new Gson().toJson(param)) 131 | .when() 132 | .post("http://localhost:9201/_generate") 133 | .then() 134 | .statusCode(200) 135 | .body("status", Matchers.is(true)) 136 | .body("message", Matchers.is(Generator.JSONResponseMessage.SUCCESS.toString())); 137 | } 138 | 139 | @Test 140 | public void generateReportHTML() { 141 | 142 | param.put("format", "HTML"); 143 | param.remove("query"); 144 | 145 | given() 146 | .log().all().contentType("application/json") 147 | .body(new Gson().toJson(param)) 148 | .when() 149 | .post("http://localhost:9201/_generate") 150 | .then() 151 | .statusCode(200) 152 | .body("message", Matchers.is(Generator.JSONResponseMessage.SUCCESS.toString())) 153 | .body("status", Matchers.is(true)); 154 | } 155 | 156 | @Test 157 | public void generateReportHTMLReturnAsPLAIN() { 158 | 159 | param.put("format", "HTML"); 160 | param.put("returnAs", Generator.ReturnAs.PLAIN.toString()); 161 | 162 | given() 163 | .log().all().contentType("application/json") 164 | .body(new Gson().toJson(param)) 165 | .when() 166 | .post("http://localhost:9201/_generate") 167 | .then() 168 | .statusCode(200) 169 | .body("status", Matchers.is(true)) 170 | .body("data.data", Matchers.startsWith("(); 45 | map.put("fullName", "Malike St"); 46 | map.put("email", "st.malike@gmail.com"); 47 | 48 | list = new LinkedList<>(); 49 | // create documents 50 | for (int i = 1; i <= 10; i++) { 51 | Map dataMap = new HashMap(); 52 | dataMap.put("id", i); 53 | dataMap.put("description", "Item Number " + i); 54 | dataMap.put("type", "CREDIT"); 55 | list.add(dataMap); 56 | } 57 | 58 | fileName = "RANDOM_REPORT"; 59 | templateFileName = "SampleTemplate.jrxml"; 60 | reportFormat = Generator.ReportFormat.PDF; 61 | 62 | } 63 | 64 | @Test 65 | public void testGeneratePDFReport() throws Exception { 66 | generatePDFReport 67 | .generateReport(map, list, templateFileName, fileName, Generator.ReportFormat.PDF); 68 | File f = new File(System.getProperty("user.dir") + 69 | File.separator + "reports" + 70 | File.separator + fileName + "." 71 | + Generator.ReportFormat.PDF.toString().toLowerCase()); 72 | Assert.assertTrue(f.exists() && !f.isDirectory()); 73 | } 74 | 75 | @Test 76 | public void testGenerateHTMLReport() throws Exception { 77 | generateHTMLReport 78 | .generateReport(map, list, templateFileName, fileName, Generator.ReportFormat.HTML); 79 | File f = new File(System.getProperty("user.dir") + 80 | File.separator + "reports" + 81 | File.separator + fileName + "." 82 | + Generator.ReportFormat.HTML.toString().toLowerCase()); 83 | Assert.assertTrue(f.exists() && !f.isDirectory()); 84 | } 85 | 86 | @Test(expected = TemplateNotFoundException.class) 87 | public void testGeneratePDFReportThrowsTemplateNotFoundException() throws Exception { 88 | generatePDFReport.generateReport(map, list, null, fileName, reportFormat); 89 | } 90 | 91 | @Test(expected = ReportFormatUnknownException.class) 92 | public void testGenerateReportThrowsReportFormatUnknowException() throws Exception { 93 | generatePDFReport.generateReport(map, list, templateFileName, fileName, null); 94 | } 95 | 96 | @Test 97 | public void testGenerateCSVReport() throws Exception { 98 | generateCSVReport 99 | .generateReport(map, list, templateFileName, fileName, Generator.ReportFormat.CSV); 100 | File f = new File(System.getProperty("user.dir") + 101 | File.separator + "reports" + 102 | File.separator + fileName + "." 103 | + Generator.ReportFormat.CSV.toString().toLowerCase()); 104 | Assert.assertTrue(f.exists() && !f.isDirectory()); 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/test/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /templates/SampleTemplate.jasper: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malike/elasticsearch-report-engine/3b9988656c5cc8b7009166a2dc42ab5a96bd6b37/templates/SampleTemplate.jasper -------------------------------------------------------------------------------- /templates/SampleTemplate.jrxml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | <band height="430" splitType="Stretch"> 34 | <elementGroup/> 35 | <staticText> 36 | <reportElement backcolor="#C0C0C0" height="47" mode="Opaque" width="595" x="-20" y="82"/> 37 | <text><![CDATA[]]></text> 38 | </staticText> 39 | <staticText> 40 | <reportElement forecolor="#FFFFFF" height="20" width="218" x="168" y="95"/> 41 | <textElement textAlignment="Center"> 42 | <font size="14"/> 43 | </textElement> 44 | <text><![CDATA[Sample Template]]></text> 45 | </staticText> 46 | <textField> 47 | <reportElement forecolor="#2C6BA4" height="20" width="260" x="0" y="145"/> 48 | <textElement> 49 | <font isBold="true" size="12"/> 50 | </textElement> 51 | <textFieldExpression><![CDATA[$P{fullName}]]></textFieldExpression> 52 | </textField> 53 | <staticText> 54 | <reportElement backcolor="#ADA9A5" height="4" mode="Opaque" width="555" x="0" y="204"/> 55 | <text><![CDATA[]]></text> 56 | </staticText> 57 | <pieChart> 58 | <chart evaluationTime="Report" renderType="svg"> 59 | <reportElement height="153" width="258" x="2" y="220"/> 60 | <chartTitle/> 61 | <chartSubtitle/> 62 | <chartLegend/> 63 | </chart> 64 | <pieDataset> 65 | <keyExpression><![CDATA[$F{type}]]></keyExpression> 66 | <valueExpression><![CDATA[$V{totalSum}]]></valueExpression> 67 | </pieDataset> 68 | <piePlot> 69 | <plot> 70 | <seriesColor color="#F7931D" seriesOrder="0"/> 71 | <seriesColor color="#8BC63E" seriesOrder="1"/> 72 | </plot> 73 | <itemLabel/> 74 | </piePlot> 75 | </pieChart> 76 | <barChart> 77 | <chart evaluationTime="Report" renderType="svg"> 78 | <reportElement height="153" width="277" x="278" y="220"/> 79 | <chartTitle/> 80 | <chartSubtitle/> 81 | <chartLegend/> 82 | </chart> 83 | <categoryDataset> 84 | <categorySeries> 85 | <seriesExpression><![CDATA["Sample"]]></seriesExpression> 86 | <categoryExpression><![CDATA[$F{type}]]></categoryExpression> 87 | <valueExpression><![CDATA[$V{totalSum}]]></valueExpression> 88 | </categorySeries> 89 | </categoryDataset> 90 | <barPlot> 91 | <plot> 92 | <seriesColor color="#F7931D" seriesOrder="0"/> 93 | <seriesColor color="#8BC63E" seriesOrder="1"/> 94 | </plot> 95 | <itemLabel/> 96 | <categoryAxisFormat> 97 | <axisFormat/> 98 | </categoryAxisFormat> 99 | <valueAxisFormat> 100 | <axisFormat/> 101 | </valueAxisFormat> 102 | </barPlot> 103 | </barChart> 104 | </band> 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | --------------------------------------------------------------------------------