<commit_before>package ch.elexis.core.ui.importer.div.importers.multifile.strategy;

import java.io.File;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.elexis.core.importer.div.importers.multifile.strategy.BasicFileImportStrategyFactory;
import ch.elexis.core.importer.div.importers.multifile.strategy.DefaultHL7ImportStrategy;
import ch.elexis.core.importer.div.importers.multifile.strategy.IFileImportStrategy;
import ch.elexis.core.importer.div.importers.multifile.strategy.IFileImportStrategyFactory;
import ch.rgw.io.FileTool;

/**
 * Contains strategies for HL7Files ({@link DefaultHL7ImportStrategy}) and their matching PDFFiles (
 * {@link DefaultPDFImportStrategy})<br>
 * Matching of HL7File to PDF takes place via the filename (need to be identical apart from file
 * suffix).
 * 
 * @author lucia
 * 		
 */
public class DefaultImportStrategyFactory extends BasicFileImportStrategyFactory {
	private static final Logger log = LoggerFactory.getLogger(DefaultImportStrategyFactory.class);
	
	private boolean moveAfterImport;
	
	@Override
	public Map<File, IFileImportStrategy> createImportStrategyMap(File hl7File){
		Map<File, IFileImportStrategy> ret = super.createImportStrategyMap(hl7File);
		
		List<File> matchingFiles = getMatchingFiles(hl7File);
		// no matching files for this hl7 file
		if (matchingFiles.isEmpty())
			return ret;
			
		DefaultPDFImportStrategy pdfImportStrategy = new DefaultPDFImportStrategy();
		for (File mFile : matchingFiles) {
			String type = FileTool.getExtension(mFile.getName()).toLowerCase();
			if ("pdf".equals(type)) {
				log.debug("... adding [" + mFile.getName() + "] with DefaultPDFImportStrategy");
				ret.put(mFile, pdfImportStrategy);
			}
		}
		ret.values().forEach(strategy -> strategy.setMoveAfterImport(moveAfterImport));
		return ret;
	}
	
	/**
	 * Specify if imported files should be moved to archiv and error directory inside the import
	 * directory. Default is false.<commit_msg>[6571] fixed move after import for hl7 file without pdf<commit_after>package ch.elexis.core.ui.importer.div.importers.multifile.strategy;

import java.io.File;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.elexis.core.importer.div.importers.multifile.strategy.BasicFileImportStrategyFactory;
import ch.elexis.core.importer.div.importers.multifile.strategy.DefaultHL7ImportStrategy;
import ch.elexis.core.importer.div.importers.multifile.strategy.IFileImportStrategy;
import ch.elexis.core.importer.div.importers.multifile.strategy.IFileImportStrategyFactory;
import ch.rgw.io.FileTool;

/**
 * Contains strategies for HL7Files ({@link DefaultHL7ImportStrategy}) and their matching PDFFiles (
 * {@link DefaultPDFImportStrategy})<br>
 * Matching of HL7File to PDF takes place via the filename (need to be identical apart from file
 * suffix).
 * 
 * @author lucia
 * 		
 */
public class DefaultImportStrategyFactory extends BasicFileImportStrategyFactory {
	private static final Logger log = LoggerFactory.getLogger(DefaultImportStrategyFactory.class);
	
	private boolean moveAfterImport;
	
	@Override
	public Map<File, IFileImportStrategy> createImportStrategyMap(File hl7File){
		Map<File, IFileImportStrategy> ret = super.createImportStrategyMap(hl7File);
		
		List<File> matchingFiles = getMatchingFiles(hl7File);
		// matching files for this hl7 file, probably pdf
		if (!matchingFiles.isEmpty()) {
			DefaultPDFImportStrategy pdfImportStrategy = new DefaultPDFImportStrategy();
			for (File mFile : matchingFiles) {
				String type = FileTool.getExtension(mFile.getName()).toLowerCase();
				if ("pdf".equals(type)) {
					log.debug("... adding [" + mFile.getName() + "] with DefaultPDFImportStrategy");
					ret.put(mFile, pdfImportStrategy);
				}
			}
		}
			
		ret.values().forEach(strategy -> strategy.setMoveAfterImport(moveAfterImport));
		return ret;
	}
	
	/**
	 * Specify if imported files should be moved to archiv and error directory inside the import
	 * directory. Default is false.
{'fraction_non_alphanumeric': 0.10164095028165565, 'fraction_numerical': 0.00612294881214793, 'mean_word_length': 5.1878787878787875, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '24259', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1215, 'n_words': 277}