[JAVA] Customize the output with Wagby's CSV download function

Motivation

I wanted to edit the contents of the output CSV while using the standard CSV download function.

Since it was not on the support page, I will describe what I checked.

Wagby version

8.2.0

Thing you want to do

--I don't want to output the CSV header line. --I want to modify (format) the contents of each output column.

Avoid outputting CSV header lines

First stage

It seems that it is not recommended to do it on the application created by Wagby. If you can process it separately using an ETL tool, that may be easier.

When performing on an application created with Wagby

It is necessary to create a class that inherits Java that is automatically generated and change the contents of the CSV output method.

Class to inherit: Download model name ProcessBean

DownloadTestProcessBean.java


public Object outputAllData(DbDownloadProcessor out, Map paramMap, boolean getallmodelitem) {
    ...
    // Output header line
    Collection<String> targetitems =
        (Collection<String>) getParameter("targetitems");
    String[] _data = ((jp.jasminesoft.wagby.app.test.TestPCSVHelper)p.appctx.getBean("TestPCSVHelper")).toCsvDataHeader(null, colMap, (ActionParameter)p, getallmodelitem, targetitems);
    out.write(_data);
    ...
}

You can create a CSV without a header by creating a method that overrides the above method and deletes the header output process described.

This process may change when the Wagby version is upgraded, so it is better to check if the inheritance source process has changed when the version is upgraded.

Modify (format) the contents of each output column

Since it is not introduced on the support page, it seems that it is not a standard custom point, but there is javascript called at the timing of reading and outputting each line, and it is possible to edit the contents there.

javascript name: model name + Helper_beforeShowInDownload.js

TestHelper_beforeShowInDownload.js


/**
 *Methods called from Java
 */
function process() {
    //The contents of the store model can be rewritten
    test.id = "hoge";
}

At this time, not only the column output to CSV but also the store model stores all one record of the model.

Recommended Posts

Customize the output with Wagby's CSV download function
csv file output with opencsv
CSV output with Apache Commons CSV
[Ruby on Rails] CSV output function
Implement CSV download function in Rails
[Tutorial] Download Eclipse → Run the application with Java (Pleiades)
I tried to read and output CSV with Outsystems
Spring with Kotorin --3. Omitting curly braces from the function
Try running the Embulk command with your Lambda function