Good morning everyone
(Summary at the end) I'm trying to pass a list of maps from one class to another using a bean with XML configuration:
<bean id="listParamJob"
class="java.util.ArrayList">
</bean>
Here is where I put the value:
private void crearBoton() {
NativeButton botonSimple = new NativeButton("Guardar Consulta");
botonSimple.setIcon(FontAwesome.CLOUD_UPLOAD);
botonSimple.addClickListener((Button.ClickEvent e) -> {
String consulta = areaConsultas.getValue();
paramsLista = (ArrayList<HashMap<String,String>>) context.getBean("listParamJob");
paramsLista = extraerSelect(consulta);
crearNotificacion("Éxito", "Consulta Guardada", Notification.Type.HUMANIZED_MESSAGE);
});
this.addComponent(botonSimple);
}
areaConsultas is a TextArea below I put the method of extractSelect:
private ArrayList<HashMap<String, String>> extraerSelect(String consultaEntera) {
String[] consultasArray = consultaEntera.split("\n");
String consultasSpliteadas = Arrays.toString(consultasArray);
System.out.println(consultasSpliteadas);
ArrayList<HashMap<String, String>> listaMapas = new ArrayList<>();
HashMap<String, String> mapaConsulta;
int contadorConsulta = 0;
for (String cadenaSacada : consultasArray) {
mapaConsulta = new HashMap<>();
StringTokenizer st = new StringTokenizer(cadenaSacada);
int contador = 0;
while (st.hasMoreElements()) {
String tokenSacado = st.nextElement().toString();
if (contador == 1) {
mapaConsulta.put("sql.consulta", consultasArray[contadorConsulta]);
mapaConsulta.put("sql.select", tokenSacado);
System.out.println(tokenSacado);
break;
}
contador++;
}
contadorConsulta++;
listaMapas.add(mapaConsulta);
}
return listaMapas;
}
and when from another class I try to call this list it gives me that it has nothing.
I already checked with the debug that in the previous classes the Hashmap is added to the list so it is not empty I'll put you where I get the value of the list (which says it's empty):
public void crearJob() {
context = ApplicationContextProvider.getApplicationContext();
listaMapasParams = (ArrayList<HashMap<String, String>>) context.getBean("listParamJob");
boolean exito = true;
Job job = (Job) context.getBean("consultaResultJob");
JobParameters parametros = null;
JobExecution execution = null;
annadirCadenas("Creando Job: " + job.getName());
int contadorMapas = 0;
// -----------------------------------------------------
// Aqui es donde leo listaMapasParams, pero como es de longitud 0 no hace nada
// -----------------------------------------------------
for (HashMap<String, String> mapaSacado : listaMapasParams) {
try {
parametros = crearParametrosJob(mapaSacado, contadorMapas);
} catch (ConsultaNoDefinidaException ex) {
String ERROR = "Error: No Hay Una Consulta Definida";
LOG.warning(ERROR);
annadirCadenas(ERROR);
exito = false;
}
annadirCadenas("Pasando Parámetros Al Job");
if (parametros == null) {
annadirCadenas("No Se pudo Ejecutar El Job Debido A Que No Hay Definida Ninguna Consulta");
} else {
try {
annadirCadenas("Ejecutando Job Con Los Siguientes Parámetros: \n" + parametros.toString());
execution = ((JobLauncher) context.getBean("jobLauncher")).run(job, parametros);
LOG.log(Level.INFO, "Job Estado De Finalizaci\u00f3n : {0}", execution.getStatus());
annadirCadenas("Job Finalizado, Estado: " + execution.getStatus());
} catch (JobExecutionException jee) {
LOG.log(Level.WARNING, "Job: " + job.getName() + " Fall\u00f3 , Raz\u00f3n:{0}", jee.getMessage());
}
}
if ((exito) && (execution != null)) {
crearNotificacion("Éxito", "Job Ejecutado Con Éxito", Notification.Type.HUMANIZED_MESSAGE);
} else {
crearNotificacion("Fallo", "Falló La Ejecución Del Job", Notification.Type.ERROR_MESSAGE);
}
System.out.println("Contador:" + contador);
contador = contador + 1;
System.out.println("Contador Despues:" + contador);
contadorMapas++;
}
contador = 0;
}
I put in the two classes:
@Component
@Scope("step")
In continuation, I explain what the program does:
I use vaadin for the graphical interface, Spring boot and Spring batch, the configuration I did for XML, because I was not clear on how the job was done by annotations
What this program does is through a textArea pick up queries separated by line breaks that later spliteo to pick up the values of the select
Then I pass to the job the whole query plus the fields of the select
Later I put the selected pick fields and splite them again to put them in a map that collects the name of the field to be recovered and the value retrieved from the database and so I can use it in the rowmapper to then put it into a CSV the result of the query
To summarize:
You put queries in a textArea separated by line breaks after a reader reads from the database and a writter writes it in a csv the results of the query
To summarize the problem:
How can I modify a bean so that another class can read it and it is not empty?
Where it is giving empty is in the method to create Job (There is put 1 comment so that it is visualized better):
for (HashMap<String, String> mapaSacado : listaMapasParams) {
Thank you in advance for everyone for reading me