<commit_before>package com.ohadr.spring_batch_dynamic_composite.item;

import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.support.CompositeItemProcessor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.util.StringUtils;
import com.ohadr.spring_batch_dynamic_composite.core.BatchBeanTypeEnum;
import com.ohadr.spring_batch_dynamic_composite.core.CompositeBatchBeanEntity;
import com.ohadr.spring_batch_dynamic_composite.core.CompositeBatchBeanManager;

public class DynamicCompositeItemProcessor<I, O> 
	extends CompositeItemProcessor<I, O> 
	implements StepExecutionListener, ApplicationContextAware
{
	protected String taskName;

	@Autowired
	protected CompositeBatchBeanManager compositeBatchBeanManager;

	// if false, filter result is false if any filter is defined
	protected Boolean acceptEmptyFiltersList = false;

	private ApplicationContext applicationContext;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
	{
		this.applicationContext = applicationContext;
	}

	@Override
	public void afterPropertiesSet() throws Exception 
	{
//		Assert.notNull(delegates, "The 'delegates' may not be null");
//		Assert.notEmpty(delegates, "The 'delegates' may not be empty");
	}

	@Override
	public ExitStatus afterStep(StepExecution stepExecution)
	{
		return stepExecution != null ? stepExecution.getExitStatus() : null;
	}

	protected void getProcessorsList() throws Exception
	{
		List<ItemProcessor<I, O>> delegates = new ArrayList<ItemProcessor<I, O>>();

		BatchBeanTypeEnum batchBeanType = BatchBeanTypeEnum.PROCESSOR;
		List<CompositeBatchBeanEntity> processorsList = compositeBatchBeanManager.getBatchBeanList(taskName, batchBeanType);
		if (processorsList.isEmpty() && !acceptEmptyFiltersList)
		{
//TODO			Log.debug("No filters found for Item . Item will not be accepted . filterName: " + this.getClass().getSimpleName() + " , item:" + item.getItemKey());

			throw new Exception();	//TODO better exception
		}

		for (CompositeBatchBeanEntity compositeProcessorEntity : processorsList)
		{
			// load generic filter by name
			ItemProcessor<I, O> processor = applicationContext.getBean(compositeProcessorEntity.getName(), ItemProcessor.class);
			delegates.add( processor );
		}

		setDelegates(delegates);
//TODO add relevant log		Log.trace("Item have been accepted. " + item);
		
	}

	@Override
	public void beforeStep(StepExecution stepExecution)
	{
		if (StringUtils.isEmpty(taskName))
		{
			String message = getClass().getSimpleName() + " beforeStep: taskName is null or empty.";
	//		Log.error(message);
			throw new RuntimeException(message);
		}
		
		//get processors list from DB
		try
		{
			getProcessorsList();
		}
		catch (Exception e)
		{
			throw new RuntimeException("no processors were found");
		}
	}
}<commit_msg>making the dynamic-composite-processor to work<commit_after>package com.ohadr.spring_batch_dynamic_composite.item;

import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.support.CompositeItemProcessor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.util.StringUtils;
import com.ohadr.spring_batch_dynamic_composite.core.BatchBeanTypeEnum;
import com.ohadr.spring_batch_dynamic_composite.core.CompositeBatchBeanEntity;
import com.ohadr.spring_batch_dynamic_composite.core.CompositeBatchBeanManager;

public class DynamicCompositeItemProcessor<I, O> 
	extends CompositeItemProcessor<I, O> 
	implements StepExecutionListener, ApplicationContextAware
{
	private static Logger log = Logger.getLogger(DynamicCompositeItemProcessor.class);

	protected String taskName;

	@Autowired
	protected CompositeBatchBeanManager compositeBatchBeanManager;

	// if false, filter result is false if any filter is defined
	protected Boolean acceptEmptyFiltersList = false;

	private ApplicationContext applicationContext;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
	{
		this.applicationContext = applicationContext;
	}

	//hide super's implementation
	@Override
	public void afterPropertiesSet() throws Exception 
	{
	}

	@Override
	public ExitStatus afterStep(StepExecution stepExecution)
	{
		return stepExecution != null ? stepExecution.getExitStatus() : null;
	}

	protected void getProcessorsList()
	{
		List<ItemProcessor<I, O>> delegates = new ArrayList<ItemProcessor<I, O>>();

		BatchBeanTypeEnum batchBeanType = BatchBeanTypeEnum.PROCESSOR;
		List<CompositeBatchBeanEntity> processorsList = compositeBatchBeanManager.getBatchBeanList(taskName, batchBeanType);
		if (processorsList.isEmpty() && !acceptEmptyFiltersList)
		{
			log.error("No processors were found for taskName=" + taskName + " and batchBeanType=" + batchBeanType);

			throw new RuntimeException("no processors were found");
		}

		for (CompositeBatchBeanEntity compositeProcessorEntity : processorsList)
		{
			// load generic filter by name
			ItemProcessor<I, O> processor = applicationContext.getBean(compositeProcessorEntity.getName(), ItemProcessor.class);
			delegates.add( processor );
		}

		setDelegates(delegates);
		log.debug("processors list: " + delegates);		
	}

	@Override
	public void beforeStep(StepExecution stepExecution)
	{
		taskName = stepExecution.getJobExecution().getJobInstance().getJobName();
		
		if (StringUtils.isEmpty(taskName))
		{
			String message = getClass().getSimpleName() + " beforeStep: taskName is null or empty.";
	//		Log.error(message);
			throw new RuntimeException(message);
		}
		
		//get processors list from DB
		getProcessorsList();
	}
}
{'fraction_non_alphanumeric': 0.08896797153024912, 'fraction_numerical': 0.00015472690700912888, 'mean_word_length': 5.988108108108108, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '22651', 'n_tokens_mistral': 1884, 'n_tokens_neox': 1772, 'n_words': 399}