Java - Get data from JRMapCollectionDataSource - java

I'm new into the forum.
I want to take this opportunity to thank everyone for the support you have given me many time.
My problem is the following:
I'm trying to get data from a JRMapCollectionDataSource from a java class.
Let me explain better...
I want to test the resulting PDF file from a batch operation.
I can access to the first level fields of the report (made with iReport), but not with the datasource of the internal TABLE represented into the PDF and populated with a JRMapCollectionDatasource.
My question is:
HOW can i access to a JRMapCollectionDatasource from java???
Thanks to all

Related

generate PDF calling information from database in javaFX

Good day to all. I am currently building a program that covers the review of product warranty applications. I'm doing it in javaFX using Netbeans. The program has the following scenes:
a screen where the information of each guarantee request is entered. all the information is stored in a table in a database. The interaction between the program and the database is done, in effect, through JDBC.
a screen where you can see a table that shows all the requests that have been saved. if a row is selected, a button that carries the third scene all the data of the request that was selected is enabled.
a screen where all the data of the tests that are made to the selected guarantee application are entered. The results are also stored in another table in the database.
After the application is evaluated, a warranty review report must be generated. Currently this format is generated in pdf from excel. What I want to do is that from the data results of the tests stored in the database I can dynamically generate the pdf formats from the program in javaFX. Is there a plugin to write these documents automatically? I'm good at writing texts in LaTEX, so if there is a way to generate the latex format from the program and call the necessary information from the database, it would be perfect. Thanks in advance for the help. Any indication or idea is welcome.
It seems like you have two core requirements:
Fetch data from the database suitable for reporting
Generate the report(s) in PDF from JavaFX but can fall back to LaTEX
What you really need seems like a PDF library for Java. I can suggest iText and Docmosis as good options (please note I work for Docmosis) - both are commercial for commercial products so you would have to buy.
Assuming you are using one of these libraries, the process for each report is:
execute the query to fetch the appropriate data for the report
manipulate the data if required to make the reporting stage simple
generate the report
Using iText you would write the query, the manipulation code and then the code to layout the report including the data.
Using Docmosis you would write the query, possibly some manipulation code (Docmosis can also work directly with your ResultSet) and the code to execute the report. The layout is designed in the template (Word or Libre Office Writer).
When you mention writing "these documents automatically" I assume you mean creating the PDF file format, which iText and Docmosis can do. If you mean creating the report layout itself, then you always need to design/write something to make the report do what you require.
I hope that helps.
Thank you very much for your response Paul! I had found something related to the libraries you mentioned, and indeed something like what I'm looking for. I notice that you are more in the subject. then, you do not know bookstore, preferably free, that gives me the possibility of doing the following (pseudo code):
take the row from the database
Save the information of that row in the attributes of a created class.
create text1: "the guarantee with reference" + object.attribute1 + "was not approved in view of the physical revision test indicated that" + object.attribute2 + "
create text2: "..."
...
create the text n: "..."
take text 1 and place it in the header of the pdf document
Take text 2, put it in bold and place it in the subtitle
Generate a table and fill it with the content of text 3, 4 ...
compile all information as a pdf, (word file, xls or others if possible)
I am clear that with the libraries that you recommend you can easily make items from
1 to 8, but I do not know if it is possible to enter the texts within a template created, so that the library accommodates all the texts in the respective zones of the template file. I imagine that this can easily be done with Latex, since everything is written in plain text.
I found a library called Java LaTeX Report (JLR) that allows me to do what I want. This information may be useful to someone. Thank you again for your answer Paul, if you consider the libraries that you mention do the job more easily than JLR please let me know!

Saving data to file or database

I'm starting to work on a new Java desktop app that should help me and my colleagues learn vocabulary. It will contain around 700 words, some texts (that point to the words contained in them) and maybe some images (not sure about that part yet). The data will never change and I want the program to be able to run offline.
The question is: Should I use database, text file or serialize the data into file? Or perhaps if there is any other option I don't know about? If you could explain your choice in detail I would be glad.
If the data never changes and is only 700 words it would probably be easiest to use a file.
If your data was a bit more complex and had many fields and was being constantly updated, a database would be more preferable but a csv file could still be used.
Since you want to access this data offline and data never changes, I think the best option would be to just use text file, which will be more efficient in terms of access and speed.
Keep all the data in memory as Serializable Java objects, and store them serialized when your application is not running. Evaluate airomem - really nice solution that would perfectly work for you.

Update objects written to a text files in java

Writing Java objects or a List into a text file is ok. But I want to know how I can update or rewrite a object which was written previously without writing objects again. For example, let s assume there is a java.util.List has a set of Objects. and then that list is written to a text file. Then later that file will be read again and get all objects from list and then change one object's value at run time by a java application. Then I don't need to write entire list back to the text file. Instead only the updated object in the list is required to be rewritten or updated in the text file without rewriting the whole list again. Any suggestion, or helpful source with sample codes please.
Take a look at RandomAccessFile. This will let you seek to the place in the file you want, and only update the part that you want to update.
Also take a look at this question on stackoverflow.
Without some fairly complex logic, you won't usually be able to update an object without rewriting the entire file. For example, if one of the objects on your list contains a string "shortstring", and you need to update it with string "muchmuchlongerstring", there will be no space in the file for the longer string without rewriting all the following content in the file.
If you want to persist large object trees to a file and still have the ability to update them, your code will be less buggy and life will be simplified by using one of the many file-based DBs out there, like:
SQLite (see Java and SQLite)
Derby
H2 (disk-based tables)

Java: How can I assemble/create a single instance for classification using a Weka generated model?

I've been searching for an answer to this for a while to no avail.
First a bit of background: I'm trying to create an AI for robocode using Weka.
I'm first logging the required data from a manual robot to an ARFF file, this is working as it should.
This data is then processed this using Weka and a model created, I'm then saving this file.
I can successfully import the model and classify a dataset that has been imported from another arff file and use the results.
What I want to do now is every time the game status changes is assemble an instance and classify it, to decide for example which way to move etc. using my previously saved model.
I've tried to look it up on the wiki: http://weka.wikispaces.com/Programmatic+Use
and this ibm tutorial: http://www.ibm.com/developerworks/opensource/library/os-weka3/ to name a couple, I've also been looking through the APIs but that hasn't given me much to go on.
Much of what I've tried is deprecated, for example creating a prototype with the attributes and fast vectors then creating an empty dataset. Then creating a new instance with the required values using somthing like inst.setvalue(attrib, value) and adding it to the dataset.
Also what about the class index, or the attribute I'm predicting, in the instance does it have to be null or set to missing or something, as surley I won't know that value as I'm trying to predict it?
So are there any ideas how I can go about this?
any help is greatly appreciated,
Thank you muchly.
Managed to find the answer a while ago.
For anyone else having trouble with this basically what you have to do is in the Weka manual included with every download, (its a pdf).
Page 202 onwards in the manual - Section 16.3 "Creating datasets in memory".
Follow the steps there and it works perfectly.

Best way to handle large amounts of static text, images when creating pdf using iText

We are going to use iText to create a large report. There will be a lot of static text and images that will be the same for every report. We will then insert dynamic data from a database into the report. The static data and the dynamic data will be mixed together when the report is finished. What is the best way to handle the static data. We are going to use a java servlet in a web application for the creation of the report. We want the report to be sent to the web page immediately, so performance is critical.
These are some of the ideas I had. Not sure if any of these are good ideas.
1.) Create a PDF with the static content then insert the dynamic data. If I go this way how would I know where to insert the dynamic data? Is it possible to bookmark place to insert data?
2.) Get the static data from a database. This seems like it would be difficult trying to design a database with static content that would have to consider things like pages, paragraphs, headings, images. I would also think that this would not be great for performance if the website gets hit hard.
3.) Cache the static content in the servlet context. This would seem to help performance but would still have the same design issues as the database.
I would love some opinions on the best way to store large amounts of static text when creatig a PDF using iText.
Thanks for your help
Doug
I am not sure if the best way to do it, but this worked well for me in a similar situation, I created a template file that I read into code, and in the template I had hash tagged variable holders that I used to find a location and replace with dynamic text from whatever source. For example:
Hello #CUSTOMER_NAME#, Thank you for the purchase of #RECENT_PURCHASES# on
#RECEIPT_DATE#, for a total value of #RECEIPT_TOTAL#. ...
Like I said, it probably isn't ideal, but it really well for my needs.

Categories