<commit_before>package controller.configuration;

import hochberger.utilities.files.checker.FileChecker;
import hochberger.utilities.files.checker.aspects.ExistingFolderFileAspect;
import hochberger.utilities.properties.LoadProperties;
import hochberger.utilities.text.Text;

import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;

public class NuFiConfiguration {

	private final Properties properties;

	private NuFiConfiguration(final Properties properties) {
		super();
		this.properties = properties;
	}

	public static NuFiConfiguration createFrom(final String filePath) throws IOException, InvalidConfigurationException {
		Properties properties = LoadProperties.fromExtern(filePath);
		validateProperties(properties);
		return new NuFiConfiguration(properties);
	}

	private static void validateProperties(final Properties properties) throws InvalidConfigurationException {
		validateEntryExistence(properties);
		validateSourceFolderExistence(properties);
		validateChannelExistence(properties);
	}

	private static void validateEntryExistence(final Properties properties) throws InvalidConfigurationException {
		List<String> missingEntries = new LinkedList<String>();
		for (String key : NuFiConfigurationConstants.MANDATORY_ENTRIES) {
			if (Text.empty().equals(properties.getProperty(key, Text.empty()))) {
				missingEntries.add(key);
			}
		}
		if (!missingEntries.isEmpty()) {
			throw new InvalidConfigurationException(Text.fromIterable(missingEntries, ", "));
		}
	}

	private static void validateSourceFolderExistence(final Properties properties) {
		String filename = properties.getProperty(NuFiConfigurationConstants.SOURCE_FOLDER);
		FileChecker fileChecker = new FileChecker(new File(filename));
		fileChecker.addFileAspect(new ExistingFolderFileAspect());
		// TODO
	}

	private static void validateChannelExistence(final Properties properties) {
		// TODO Auto-generated method stub

	}

	public static class InvalidConfigurationException extends Exception {

		public InvalidConfigurationException(final String missingKeys) {
			super("There are missing keys in the configuration: " + missingKeys);
		}
	}
}<commit_msg>workson #13<commit_after>package controller.configuration;

import hochberger.utilities.files.checker.FileChecker;
import hochberger.utilities.files.checker.aspects.ExistingFolderFileAspect;
import hochberger.utilities.properties.LoadProperties;
import hochberger.utilities.text.Text;

import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;

import controller.NuFiApplication;

public class NuFiConfiguration {

	private final Properties properties;

	private NuFiConfiguration(final Properties properties) {
		super();
		this.properties = properties;
	}

	public static NuFiConfiguration createFrom(final String filePath) throws IOException, ConfigurationException {
		Properties properties = LoadProperties.fromExtern(filePath);
		validateProperties(properties);
		return new NuFiConfiguration(properties);
	}

	private static void validateProperties(final Properties properties) throws ConfigurationException {
		validateEntryExistence(properties);
		validateSourceFolderExistence(properties);
		validateChannelExistence(properties);
	}

	private static void validateEntryExistence(final Properties properties) throws InvalidConfigurationException {
		List<String> missingEntries = new LinkedList<String>();
		for (String key : NuFiConfigurationConstants.MANDATORY_ENTRIES) {
			if (Text.empty().equals(properties.getProperty(key, Text.empty()))) {
				missingEntries.add(key);
			}
		}
		if (!missingEntries.isEmpty()) {
			throw new InvalidConfigurationException(Text.fromIterable(missingEntries, ", "));
		}
		NuFiApplication.getLogger().info("Configuration keys are okay.");
	}

	private static void validateSourceFolderExistence(final Properties properties) throws MissingSourceFolderException {
		String filename = properties.getProperty(NuFiConfigurationConstants.SOURCE_FOLDER);
		FileChecker fileChecker = new FileChecker(new File(filename));
		fileChecker.addFileAspect(new ExistingFolderFileAspect());
		if (!fileChecker.check()) {
			throw new MissingSourceFolderException(Text.fromIterable(fileChecker.getResultDescriptions(), ", "));
		}
		NuFiApplication.getLogger().info("Source folder is okay.");
	}

	private static void validateChannelExistence(final Properties properties) {
		// TODO Auto-generated method stub

	}

	public static class ConfigurationException extends Exception {

		public ConfigurationException(final String message) {
			super(message);
		}
	}

	public static class InvalidConfigurationException extends ConfigurationException {

		private static final long serialVersionUID = 3651037404940742635L;

		public InvalidConfigurationException(final String missingKeys) {
			super("There are missing keys in the configuration: " + missingKeys);
		}
	}

	public static class MissingSourceFolderException extends ConfigurationException {

		private static final long serialVersionUID = 5203928823071388289L;

		public MissingSourceFolderException(final String description) {
			super("Source folder error: " + description);
		}
	}
}
{'fraction_non_alphanumeric': 0.08208246247387421, 'fraction_numerical': 0.007600228006840205, 'mean_word_length': 6.4772727272727275, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1080863', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1324, 'n_words': 316}