LoadAllCatalogDecider.java

package com.sintia.ffl.admin.optique.catalogue.batch.config.loadcatalog;

import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.job.flow.FlowExecutionStatus;
import org.springframework.batch.core.job.flow.JobExecutionDecider;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Indicate if there's still at least 1 catalog file to process
 *
 * @author jumazet
 */
@Component
@Slf4j
public class LoadAllCatalogDecider implements JobExecutionDecider {

	@Override
	public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {

		@SuppressWarnings("unchecked")
		List<String> associationsFiles = (List<String>) stepExecution.getJobExecution()
				.getExecutionContext()
				.get("associationsFiles");

		// if the list is empty, that means that all the catalogs list in the previous
		// step has been processed, so we can stop
		if (associationsFiles == null || associationsFiles.isEmpty()) {
			log.info("Plus aucun fichier à traiter");
			return new FlowExecutionStatus("END");
		} else {
			log.info("Reste un ou plusieurs fichiers à traiter");
			return new FlowExecutionStatus("NEXT");
		}
	}

}