Spring Batch multiresourceitemwriter with fileName in footer - java

I am using multiresourceitemwriter and able to generate multiple files with the difference index, passing flatfileitemwriter as deligate but I want add file name and count of the record into the footer.
Not sure how to do that.please suggest a way.

Related

Anylogic import new Excel file for each iteration of a simulation experiment

In my anylogic model my agents receive their parameters from a database table, which is based on an Excel file. In the Excel file, each cell has its own code stored, so each time I open the file, the cell values change.
I would like to have that with each automatic run of my model the Excel file is read in again as the database table (i.e. the parameter values of the agents change).
In the "Parameter Variation Experiment" I entered this code under "after iteration":
String tempString = excelFile_DatabasisLinks.getCellStringValue(1, rowCounter, 1);
ModelDatabase modelDB = getEngine().getModelDatabase();
Database myNewFile = new Database(this, "rohdaten2", tempString);
modelDB.importFromExternalDB(myNewFile.getConnection(), "Rohdaten", "rohdaten", true, false);
rowCounter += 1;
I have the code form this anylogic help page. Using a variable to be able to change the path of the file (i.e. the file) seems to work (anylogic doesn't throw an error).
In the currently used dummy model, the agents receive their parameters at the source.
At the sink, the parameter values are written via collections into another excel (results) file.
I put obvious pattern into my data files, to see if the data changes, but I always receive the same excel file in my results file.
I read that anylogic copies the excel tables to its temporary files to make simulation runs faster. I hoped the code above would be a workaround, but it is not.
I'm grateful for any suggestions how to make this work!
I could not find out what is wrong with the above code or how to get it work.
However, I found a workaround using the "excelFile "-Block.
In the main agent (the agent where all other agents live) in the agent actions in "on startup":
excelFile.readFile();
ensures that the excel file is updated before each run. The parameters are added via
agent.set_<parametername>(excelFile.getCellBooleanValue( sheet number, row number, column number)
"on exit" in the source.
I hope this helps everyone with a similar problem.

Spring Batch - a FlatFileItemWriter with dynamic schema

I am building an application that handles the batch processings with using a SpringBatch. As the ItemReaders can handle a dynamic schemas (e.g. reading a JSON files (JsonItemReader), XML files (StaxEventItemReader), getting a data from the MongoDB (MongoItemReader) and so on) I am wondering, how can I leverage a SpringBatch to use dynamically a FlatFileItemWriter as an last stage in the step and produce a CSV file.
Normally, it requires to get a fixed schema once I initialize a Writer (before I even start writing an objects). As the schema can differ in the JSON Objects, each product in each chunk can potentially have a different headers. Is there any workaround that I can use to include a FlatFileItemWriter as an output if the domain objects have a various schemas that are unknown until the Runtime?
That's the current code for initializing a FlatFileItemWriter but with using a static schema, that needs to be provided before I create a Writer.
FlatFileItemWriter<Row> flatFileItemWriter = new FlatFileItemWriter<>();
Resource resource = new FileSystemResource(path);
flatFileItemWriter.setResource(resource);
CSVLineAggregator lineAggregator = CSVLineAggregator.builder()
.schema(schema)
.delimiter(delimiter)
.quoteCharacter(quoteCharacter)
.escapeCharacter(escapeCharacter)
.build();
flatFileItemWriter.setLineAggregator(lineAggregator);
flatFileItemWriter.setEncoding(encoding);
flatFileItemWriter.setLineSeparator(lineSeparator);
flatFileItemWriter.setShouldDeleteIfEmpty(shouldDeleteIfEmpty);
flatFileItemWriter.setHeaderCallback(new HeaderCallback(schema.getColumnNames(), flatFileItemWriter, lineSeparator));
** The Row it's my domain object that is just a Map's based structure that stores the data in the Cells and Columns, along with the schema that can differ between the rows.
Thanks in advance for any tips!

Read Excel file using Java with Property file

I am trying to read an Excel file using Java.
I did this successfully by using org.apache.poi which is returning all of the data column wise.
But now I want to read the same excel file by column names only which will be given by the user. The twisting part is that I want to accept column names from a property file and only those names, which are in the property file, those column's data should be shown by the program. So any suggestions? How do I do it?
use net.sf.supercsv library for reading EXL file by header/column name

How to read all properties into an array with spring?

I know you can use spring to read a single property, and to read a single property that has a list of values into a list. But what about reading all the properties from a file into a list?
I.E.
EDIT: The property file we are reading is litterally just a list of values, no key, like the updated example below:
Property File
queueName1
quename2
queName3
...etc (the file is like 100 lines long hence why its not a list of values with one property name)
and then be able to do something like
//Imaginary Code
#Value("${GET ALL THE LINES}")
List<String> eachLineOfPropertyFile;
If you would want to do it using Spring alone, then separate each of the value using "," in the property file and make use of spring EL.
Your properties file will be like:
property.values=queueName1,quename2,queName3
And with Spring Value Annotation
#Value("#{'${property.values}'.split(',')}")
List<String> eachLineOfPropertyFile;
Can you not use the following
List<String> list = Files.readAllLines(new File("propertiesFile").toPath(), Charset.defaultCharset() );
PS: This is part of Java 7

How can I get content from Exchange.In:Body object from a ProcessDefinition in Camel

I am integrating data between two systems using Apache Camel. I want the resulting xml to be written to an xml file. I want to base the name of that file on some data which is unknown when the integration chain starts.
When I have done the first enrich step the data necessary is in the Exchange object.
So the question is how can I get data from the exchange.getIn().getBody() method outside of the process chain in order to generate a desirable filename for my output file and as a final step, write the xml to this file? Or is there some other way to accomplish this?
Here is my current Process chain from the routebuilders configuration method:
from("test_main", "jetty:server")
.process(new PiProgramCommonProcessor())
.enrich("piProgrammeEnricher", new PiProgrammeEnricher())
// after this step I have the data available in exchange.in.body
.to(freeMarkerXMLGenerator)
.to(xmlFileDestination)
.end();
best regards
RythmiC
The file component takes the file name from a header (if present). So you can just add a header to your message with the desired file name.
The header should use the key "CamelFileName" which is also defined from Exchange.FILE_NAME.
See more details at: http://camel.apache.org/file2

Categories

Resources