diff --git a/src/main/java/org/ld4l/bib2lod/.keep b/src/main/java/org/ld4l/bib2lod/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/main/java/org/ld4l/bib2lod/Bib2LodObjectFactory.java b/src/main/java/org/ld4l/bib2lod/Bib2LodObjectFactory.java new file mode 100644 index 000000000..5088f27cf --- /dev/null +++ b/src/main/java/org/ld4l/bib2lod/Bib2LodObjectFactory.java @@ -0,0 +1,36 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package org.ld4l.bib2lod; + +import java.io.FileNotFoundException; +import java.io.IOException; + +import org.apache.commons.cli.ParseException; +import org.ld4l.bib2lod.configuration.DefaultConfiguration; + +/** + * Factory class to instantiate Bib2Lod objects. + * + * Use these methods instead of constructors. The best way to call them is from + * static factory methods on the result classes. + * + * The singleton instance may be replaced for unit tests. + */ +public abstract class Bib2LodObjectFactory { + + // NOTE: private but not final, so it can be changed during unit tests. + private static Bib2LodObjectFactory instance = + new DefaultBib2LodObjectFactory(); + + public static Bib2LodObjectFactory instance() { + return instance; + } + + //public abstract OptionsReader createOptionsReader(String[] args); + + public abstract DefaultConfiguration createConfiguration(String[] args) + throws ClassNotFoundException, FileNotFoundException, IOException, + ParseException; +} + + diff --git a/src/main/java/org/ld4l/bib2lod/DefaultBib2LodObjectFactory.java b/src/main/java/org/ld4l/bib2lod/DefaultBib2LodObjectFactory.java new file mode 100644 index 000000000..f0728f6b9 --- /dev/null +++ b/src/main/java/org/ld4l/bib2lod/DefaultBib2LodObjectFactory.java @@ -0,0 +1,30 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package org.ld4l.bib2lod; + +import java.io.FileNotFoundException; +import java.io.IOException; + +import org.apache.commons.cli.ParseException; +import org.ld4l.bib2lod.configuration.DefaultConfiguration; + +/** + * A simple implementation. + */ +public class DefaultBib2LodObjectFactory extends Bib2LodObjectFactory { + + @Override + public DefaultConfiguration createConfiguration(String[] args) + throws ClassNotFoundException, FileNotFoundException, IOException, + ParseException { + return new DefaultConfiguration(args); + } + +// @Override +// public OptionsReader createOptionsReader(String[] args) { +// return new OptionsReaderImpl(args); +// } + + + +} diff --git a/src/main/java/org/ld4l/bib2lod/configuration/Configuration.java b/src/main/java/org/ld4l/bib2lod/configuration/Configuration.java index ee95dce67..dacb36e86 100644 --- a/src/main/java/org/ld4l/bib2lod/configuration/Configuration.java +++ b/src/main/java/org/ld4l/bib2lod/configuration/Configuration.java @@ -1,277 +1,54 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + package org.ld4l.bib2lod.configuration; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.apache.commons.cli.ParseException; -import org.apache.jena.iri.IRIException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.ld4l.bib2lod.configuration.options.JsonOptionsReader; -import org.ld4l.bib2lod.configuration.options.JsonUtils; +import org.ld4l.bib2lod.Bib2LodObjectFactory; import org.ld4l.bib2lod.conversion.Converter; import org.ld4l.bib2lod.uri.UriMinter; -import com.fasterxml.jackson.databind.JsonNode; - - /** * An object providing program configuration values - * */ -public class Configuration { - - public static class InvalidValueException extends RuntimeException { - private static final long serialVersionUID = 1L; - - protected InvalidValueException(String key) { - super("Value of configuration key '" + key + "' is invalid."); - } - - public InvalidValueException(String key, String msg) { - super("Value of configuration key '" + key + - "' is invalid: " + msg + "."); - } - } - - private static final Logger LOGGER = LogManager.getLogger(); - - private String localNamespace; - private UriMinter uriMinter; - private List input; - - // TODO Convert to list later - // private List converters; - private Converter converter; - - // cleaner, parser, converters - // private Reader reader; - // private Writer writer; - // private ErrorHandler errorHandler; - // private Logger logger; - - protected enum Key { - - CONVERTER("converter"), - INPUT("input"), - INPUT_LOCATION("location"), - LOCAL_NAMESPACE("local_namespace"), - URI_MINTER("uri_minter"); - - final String string; - - Key(String string) { - this.string = string; - } - - public String string() { - return this.string; - } - } +public interface Configuration { /** - * @param args - the commandline arguments - * @throws Exception - * @throws ClassNotFoundException - * @throws IOException - * @throws ParseException - * @throws ReflectiveOperationException + * Factory method */ - public Configuration(String[] args) throws ClassNotFoundException, - FileNotFoundException, IOException, ParseException, - ReflectiveOperationException { - - // Get the configuration values from the commandline values and - // specified config file as a JSON object. - JsonOptionsReader optionsReader = new JsonOptionsReader(args); - JsonNode config = optionsReader.configure(); - - LOGGER.debug(config.toString()); - - setLocalNamespace(config); - - // buildServices(config); - - // buildInputFileList(config); - - // buildConverters(config); - // buildConverter(config); - - // TODO Add same for other config elements... - + static Configuration instance(String[] args) throws ClassNotFoundException, + FileNotFoundException, IOException, ParseException { + return Bib2LodObjectFactory.instance().createConfiguration(args); } - /** * Gets the configured local namespace. * @return localNamespace - the local namespace */ - public String getLocalNamespace() { - return localNamespace; - } - + String getLocalNamespace(); + /** * Gets the configured URI minter * @return uriMinter - the configured UriMinter */ - public UriMinter getUriMinter() { - return uriMinter; - } - + UriMinter getUriMinter(); + /** * Gets the configured list of input files. * @return input - the list of input files */ // TODO Or just return the input string from config file? - public List getInput() { - return input; - } - -// public List getConverters() { -// return converters; -// } - + List getInput(); + /** * Gets the configured converter * @return converter - the converter */ - public Converter getConverter() { - return converter; - } - - /** - * Sets the local namespace - * @param config - */ - protected void setLocalNamespace(JsonNode config) - throws IRIException, InvalidValueException { - - String localNamespace = - JsonUtils.getRequiredJsonStringValue( - config, Key.LOCAL_NAMESPACE.string); - - // Throws an error if the localNamespace is malformed. - org.apache.jena.riot.system.IRIResolver.validateIRI(localNamespace); + // TODO Change to array of converters + Converter getConverter(); - // Require the final slash, otherwise it could be a web page address - if (!localNamespace.endsWith("/")) { - throw new InvalidValueException(Key.LOCAL_NAMESPACE.string, - "Local namespace must end in a forward slash."); - } - - this.localNamespace = localNamespace; - } - - /** - * Builds the services specified in the config file - * @param config - * @throws ClassNotFoundException - * @throws ReflectiveOperationException - */ - protected void buildServices(JsonNode config) - throws ClassNotFoundException, ReflectiveOperationException { - - JsonNode services = config.get("services"); - LOGGER.debug(services.toString()); - - makeUriMinter(JsonUtils.getRequiredJsonStringValue( - services, Key.URI_MINTER.string)); - - // TODO Add same for other services... - - } - - /** - * Builds the UriMinter service - * @param minterClassName - * @throws ClassNotFoundException - * @throws ReflectiveOperationException - */ - protected void makeUriMinter(String minterClassName) - throws ClassNotFoundException, ReflectiveOperationException { - - Class c = Class.forName(minterClassName); - this.uriMinter = (UriMinter) c.getConstructor(String.class) - .newInstance(localNamespace); - } - - /** - * Builds list of input files from the input path - * @param input - * @return - * @return - * @throws FileNotFoundException - */ - // TODO Also pass in file type and make sure we get only the files of this - // type - protected void buildInputFileList(JsonNode config) - throws FileNotFoundException { - - // TODO Throw error if not defined - JsonNode inputNode = config.get(Key.INPUT.string); - String inputPath = JsonUtils.getRequiredJsonStringValue( - inputNode, Key.INPUT_LOCATION.string); -// String inputFormat = getJsonStringValue(inputNode, "format"); -// String fileExtension = getJsonStringValue(inputNode, "extension"); - - this.input = new ArrayList(); - - File path = new File(inputPath); - - if (! path.exists()) { - throw new FileNotFoundException("Input location not found."); - } - - // TODO - Add filter to path.listFiles() so that we get only the - // files with the right extension. See FilenameFilter or FileFilter. - if (path.isDirectory()) { - this.input = Arrays.asList(path.listFiles()); - } else { - this.input.add(path); - } - } - - /** - * Builds the converter specified in the config file - * @param config - * @throws ClassNotFoundException - * @throws InstantiationException - * @throws IllegalAccessException - * @throws IllegalArgumentException - * @throws InvocationTargetException - * @throws NoSuchMethodException - * @throws SecurityException - */ - protected void buildConverter(JsonNode config) - throws ClassNotFoundException, InstantiationException, - IllegalAccessException, IllegalArgumentException, - InvocationTargetException, NoSuchMethodException, - SecurityException { - - // ObjectMapper mapper = new ObjectMapper(); - - // JsonNode converterList = config.get("converters"); - // TODO Should be an array of strings or a string. For now just handle - // an array. - // if string...convert to list - // else - - // TODO Get this to work. Hard-coding as a single converter for now - // TypeReference ref = new TypeReference>() {}; - // converters = mapper.readValue(converterList, ref); - String converter = JsonUtils.getRequiredJsonStringValue( - config, Key.CONVERTER.string); - Class converterClass = Class.forName(converter); - Constructor constructor = - converterClass.getConstructor(this.getClass()); - this.converter = (Converter) constructor.newInstance(this); - } - - } diff --git a/src/main/java/org/ld4l/bib2lod/configuration/DefaultConfiguration.java b/src/main/java/org/ld4l/bib2lod/configuration/DefaultConfiguration.java new file mode 100644 index 000000000..45b34d4fc --- /dev/null +++ b/src/main/java/org/ld4l/bib2lod/configuration/DefaultConfiguration.java @@ -0,0 +1,285 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package org.ld4l.bib2lod.configuration; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.cli.ParseException; +import org.apache.jena.iri.IRIException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.ld4l.bib2lod.conversion.Converter; +import org.ld4l.bib2lod.uri.UriMinter; + +import com.fasterxml.jackson.databind.JsonNode; + + +/** + * A simple implementation. + */ +public class DefaultConfiguration implements Configuration { + + + private static final Logger LOGGER = LogManager.getLogger(); + + private String localNamespace; + private UriMinter uriMinter; + private List input; + + // TODO Convert to list later + // private List converters; + private Converter converter; + + // cleaner, parser, converters + // private Reader reader; + // private Writer writer; + // private ErrorHandler errorHandler; + // private Logger logger; + + /** + * Represents keys in the incoming JSON configuration. + */ + protected enum Key { + + CONVERTER("converter"), + INPUT("input"), + INPUT_LOCATION("location"), + LOCAL_NAMESPACE("local_namespace"), + URI_MINTER("uri_minter"); + + final String string; + + Key(String string) { + this.string = string; + } + + public String string() { + return this.string; + } + } + + /** + * Signals that the content of a configuration value is invalid. Differs + * from empty, null, or invalid types, which are handled by JsonUtils + * exceptions, which are content-neutral. The DefaultConfiguration object + * evaluates the contents of the value. + */ + public static class InvalidValueException extends RuntimeException { + private static final long serialVersionUID = 1L; + + protected InvalidValueException(String key) { + super("Value of configuration key '" + key + "' is invalid."); + } + + public InvalidValueException(String key, String msg) { + super("Value of configuration key '" + key + + "' is invalid: " + msg + "."); + } + } + + + /** + * @param optionsReader - holds the parsed arguments + * @throws Exception + * @throws ClassNotFoundException + * @throws IOException + * @throws ParseException + * @throws ReflectiveOperationException + */ + public DefaultConfiguration(String[] args) + throws ClassNotFoundException, FileNotFoundException, IOException, + ParseException { + + // Get the configuration values from the commandline values and + // specified config file as a JSON object. + //JsonNode config = OptionsReader.instance(args).configure(); + + //LOGGER.debug(config.toString()); + + //setLocalNamespace(config); + + // buildServices(config); + + // buildInputFileList(config); + + // buildConverters(config); + // buildConverter(config); + + // TODO Add same for other config elements... + + } + + /* (non-Javadoc) + * @see org.ld4l.bib2lod.configuration.Configuration#getLocalNamespace() + */ + @Override + public String getLocalNamespace() { + return localNamespace; + } + + /* (non-Javadoc) + * @see org.ld4l.bib2lod.configuration.Configuration#getUriMinter() + */ + @Override + public UriMinter getUriMinter() { + return uriMinter; + } + + /* (non-Javadoc) + * @see org.ld4l.bib2lod.configuration.Configuration#getInput() + */ + // TODO Or just return the input string from config file? + @Override + public List getInput() { + return input; + } + +// public List getConverters() { +// return converters; +// } + + /* (non-Javadoc) + * @see org.ld4l.bib2lod.configuration.Configuration#getConverter() + */ + @Override + public Converter getConverter() { + return converter; + } + + /** + * Sets the local namespace + * @param config + */ + protected void setLocalNamespace(JsonNode config) + throws IRIException, InvalidValueException { + + String localNamespace = JsonUtils.getRequiredJsonStringValue( + config, Key.LOCAL_NAMESPACE.string); + + // Throws an error if the localNamespace is malformed. + org.apache.jena.riot.system.IRIResolver.validateIRI(localNamespace); + + // Require the final slash, otherwise it could be a web page address + if (!localNamespace.endsWith("/")) { + throw new InvalidValueException(Key.LOCAL_NAMESPACE.string, + "Local namespace must end in a forward slash."); + } + + this.localNamespace = localNamespace; + } + +// TODO - these will all go in the factory methods and factory +// /** +// * Builds the services specified in the config file +// * @param config +// * @throws ClassNotFoundException +// * @throws ReflectiveOperationException +// */ +// protected void buildServices(JsonNode config) +// throws ClassNotFoundException, ReflectiveOperationException { +// +// JsonNode services = config.get("services"); +// LOGGER.debug(services.toString()); +// +// makeUriMinter(JsonUtils.getRequiredJsonStringValue( +// services, Key.URI_MINTER.string)); +// +// // TODO Add same for other services... +// +// } +// +// /** +// * Builds the UriMinter service +// * @param minterClassName +// * @throws ClassNotFoundException +// * @throws ReflectiveOperationException +// */ +// protected void makeUriMinter(String minterClassName) +// throws ClassNotFoundException, ReflectiveOperationException { +// +// Class c = Class.forName(minterClassName); +// this.uriMinter = (UriMinter) c.getConstructor(String.class) +// .newInstance(localNamespace); +// } +// +// /** +// * Builds list of input files from the input path +// * @param input +// * @return +// * @return +// * @throws FileNotFoundException +// */ +// // TODO Also pass in file type and make sure we get only the files of this +// // type +// protected void buildInputFileList(JsonNode config) +// throws FileNotFoundException { +// +// // TODO Throw error if not defined +// JsonNode inputNode = config.get(Key.INPUT.string); +// String inputPath = JsonUtils.getRequiredJsonStringValue( +// inputNode, Key.INPUT_LOCATION.string); +//// String inputFormat = getJsonStringValue(inputNode, "format"); +//// String fileExtension = getJsonStringValue(inputNode, "extension"); +// +// this.input = new ArrayList(); +// +// File path = new File(inputPath); +// +// if (! path.exists()) { +// throw new FileNotFoundException("Input location not found."); +// } +// +// // TODO - Add filter to path.listFiles() so that we get only the +// // files with the right extension. See FilenameFilter or FileFilter. +// if (path.isDirectory()) { +// this.input = Arrays.asList(path.listFiles()); +// } else { +// this.input.add(path); +// } +// } +// +// /** +// * Builds the converter specified in the config file +// * @param config +// * @throws ClassNotFoundException +// * @throws InstantiationException +// * @throws IllegalAccessException +// * @throws IllegalArgumentException +// * @throws InvocationTargetException +// * @throws NoSuchMethodException +// * @throws SecurityException +// */ +// protected void buildConverter(JsonNode config) +// throws ClassNotFoundException, InstantiationException, +// IllegalAccessException, IllegalArgumentException, +// InvocationTargetException, NoSuchMethodException, +// SecurityException { +// +// // ObjectMapper mapper = new ObjectMapper(); +// +// // JsonNode converterList = config.get("converters"); +// // TODO Should be an array of strings or a string. For now just handle +// // an array. +// // if string...convert to list +// // else +// +// // TODO Get this to work. Hard-coding as a single converter for now +// // TypeReference ref = new TypeReference>() {}; +// // converters = mapper.readValue(converterList, ref); +// String converter = JsonUtils.getRequiredJsonStringValue( +// config, Key.CONVERTER.string); +// Class converterClass = Class.forName(converter); +// Constructor constructor = +// converterClass.getConstructor(this.getClass()); +// this.converter = (Converter) constructor.newInstance(this); +// } + + +} diff --git a/src/main/java/org/ld4l/bib2lod/configuration/options/JsonOptionsReader.java b/src/main/java/org/ld4l/bib2lod/configuration/JsonOptionsReader.java similarity index 99% rename from src/main/java/org/ld4l/bib2lod/configuration/options/JsonOptionsReader.java rename to src/main/java/org/ld4l/bib2lod/configuration/JsonOptionsReader.java index 2f4887e8b..f5f3bde48 100644 --- a/src/main/java/org/ld4l/bib2lod/configuration/options/JsonOptionsReader.java +++ b/src/main/java/org/ld4l/bib2lod/configuration/JsonOptionsReader.java @@ -1,4 +1,4 @@ -package org.ld4l.bib2lod.configuration.options; +package org.ld4l.bib2lod.configuration; import java.io.FileNotFoundException; import java.io.FileReader; diff --git a/src/main/java/org/ld4l/bib2lod/configuration/options/JsonUtils.java b/src/main/java/org/ld4l/bib2lod/configuration/JsonUtils.java similarity index 74% rename from src/main/java/org/ld4l/bib2lod/configuration/options/JsonUtils.java rename to src/main/java/org/ld4l/bib2lod/configuration/JsonUtils.java index 3262f64d3..c22137e31 100644 --- a/src/main/java/org/ld4l/bib2lod/configuration/options/JsonUtils.java +++ b/src/main/java/org/ld4l/bib2lod/configuration/JsonUtils.java @@ -1,18 +1,29 @@ -package org.ld4l.bib2lod.configuration.options; +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package org.ld4l.bib2lod.configuration; import com.fasterxml.jackson.databind.JsonNode; +/** + * Utility methods for handling JSON objects. + */ public final class JsonUtils { + /** + * Signals that a required key is absent in the JSON object. + */ public static class RequiredKeyMissingException extends RuntimeException { private static final long serialVersionUID = 1L; protected RequiredKeyMissingException(String key) { - super("Configuration is missing required key '" + key + ".'"); + super("DefaultConfiguration is missing required key '" + key + ".'"); } } + /** + * Signals that a required value in the JSON object is null. + */ public static class RequiredValueNullException extends RuntimeException { private static final long serialVersionUID = 1L; @@ -22,6 +33,9 @@ protected RequiredValueNullException(String key) { } } + /** + * Signals that a required value in the JSON object is of the wrong type. + */ public static class InvalidTypeException extends RuntimeException { private static final long serialVersionUID = 1L; @@ -31,6 +45,9 @@ protected InvalidTypeException(String key) { } } + /** + * Signals that a required value in the JSON object is empty. + */ public static class RequiredValueEmptyException extends RuntimeException { private static final long serialVersionUID = 1L; @@ -43,13 +60,10 @@ protected RequiredValueEmptyException(String key) { /** * Utility method to return a required string value in a JsonNode. Throws - * an error if value is null, empty, or an invalid type. + * a RuntimeException if value is null, empty, or of an invalid type. * @param node - the enclosing JsonNode * @param key - the key in the JsonNode - * @return value - the string value if non-null and non-empty - * @throw RequiredKeyMissingException - * @throw RequiredValueNullException - * @throw RequiredValueEmptyException + * @return value - the string value */ public static String getRequiredJsonStringValue(JsonNode node, String key) { @@ -75,14 +89,13 @@ public static String getRequiredJsonStringValue(JsonNode node, String key) { /** * Utility method to return a string value in a JsonNode. Missing, - * null, and empty string values succeed; only non-string values (including - * empty objects and arrays) throw an error. The assumption is that if the - * user has defined a value it is expected to work, and an alert should be - * issued when the value is bad. + * null, and empty string values succeed; non-string values (including + * empty objects and arrays) throw a RuntimeException. The premise is that + * if the user has defined a value it is expected to work, and an alert + * should be issued when the value is bad. * @param node - the JsonNode * @param key - the key in the JsonNode * @return stringValue - the string value - * @throw InvalidTypeException */ public static String getOptionalJsonStringValue(JsonNode node, String key) { diff --git a/src/main/java/org/ld4l/bib2lod/configuration/options/OptionsReader.java b/src/main/java/org/ld4l/bib2lod/configuration/OptionsReader.java similarity index 85% rename from src/main/java/org/ld4l/bib2lod/configuration/options/OptionsReader.java rename to src/main/java/org/ld4l/bib2lod/configuration/OptionsReader.java index 8f449a29c..f8be32bf9 100644 --- a/src/main/java/org/ld4l/bib2lod/configuration/options/OptionsReader.java +++ b/src/main/java/org/ld4l/bib2lod/configuration/OptionsReader.java @@ -1,4 +1,4 @@ -package org.ld4l.bib2lod.configuration.options; +package org.ld4l.bib2lod.configuration; import java.io.IOException; diff --git a/src/main/java/org/ld4l/bib2lod/conversion/BaseConverter.java b/src/main/java/org/ld4l/bib2lod/conversion/BaseConverter.java index 985d13847..7c849b515 100644 --- a/src/main/java/org/ld4l/bib2lod/conversion/BaseConverter.java +++ b/src/main/java/org/ld4l/bib2lod/conversion/BaseConverter.java @@ -2,7 +2,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.ld4l.bib2lod.configuration.Configuration; +import org.ld4l.bib2lod.configuration.DefaultConfiguration; import org.ld4l.bib2lod.uri.UriMinter; public abstract class BaseConverter implements Converter { @@ -14,7 +14,7 @@ public abstract class BaseConverter implements Converter { // NB Is it possible to store the configuration as an instance variable, // which creates cirular references (config points to converter, which // points to config, ...). Is this a problem?? - public BaseConverter(Configuration configuration) { + public BaseConverter(DefaultConfiguration configuration) { this.uriMinter = configuration.getUriMinter(); } diff --git a/src/main/java/org/ld4l/bib2lod/conversion/to_rdf/MarcxmlToRdf.java b/src/main/java/org/ld4l/bib2lod/conversion/to_rdf/MarcxmlToRdf.java index 0aebfeb1a..cd7c2e258 100644 --- a/src/main/java/org/ld4l/bib2lod/conversion/to_rdf/MarcxmlToRdf.java +++ b/src/main/java/org/ld4l/bib2lod/conversion/to_rdf/MarcxmlToRdf.java @@ -11,7 +11,7 @@ import org.apache.jena.rdf.model.ModelFactory; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.ld4l.bib2lod.configuration.Configuration; +import org.ld4l.bib2lod.configuration.DefaultConfiguration; import org.ld4l.bib2lod.conversion.BaseConverter; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -25,7 +25,7 @@ public abstract class MarcxmlToRdf extends BaseConverter { private static final Logger LOGGER = LogManager.getLogger(); - public MarcxmlToRdf(Configuration configuration) { + public MarcxmlToRdf(DefaultConfiguration configuration) { super(configuration); } diff --git a/src/main/java/org/ld4l/bib2lod/conversion/to_rdf/ld4l/MarcxmlToLd4lRdf.java b/src/main/java/org/ld4l/bib2lod/conversion/to_rdf/ld4l/MarcxmlToLd4lRdf.java index 225bb26d6..b7ed08864 100644 --- a/src/main/java/org/ld4l/bib2lod/conversion/to_rdf/ld4l/MarcxmlToLd4lRdf.java +++ b/src/main/java/org/ld4l/bib2lod/conversion/to_rdf/ld4l/MarcxmlToLd4lRdf.java @@ -11,7 +11,7 @@ import org.apache.logging.log4j.Logger; import org.ld4l.bib2lod.clean.Cleaner; import org.ld4l.bib2lod.clean.marcxml.MarcxmlCleaner; -import org.ld4l.bib2lod.configuration.Configuration; +import org.ld4l.bib2lod.configuration.DefaultConfiguration; import org.ld4l.bib2lod.conversion.to_rdf.MarcxmlToRdf; import org.ld4l.bib2lod.conversion.to_rdf.ResourceBuilder; import org.ld4l.bib2lod.util.rdf.RdfUtil; @@ -22,7 +22,7 @@ public class MarcxmlToLd4lRdf extends MarcxmlToRdf { private static final Logger LOGGER = LogManager.getLogger(); - public MarcxmlToLd4lRdf(Configuration configuration) { + public MarcxmlToLd4lRdf(DefaultConfiguration configuration) { super(configuration); } diff --git a/src/main/java/org/ld4l/bib2lod/manager/SimpleManager.java b/src/main/java/org/ld4l/bib2lod/manager/SimpleManager.java index 208c75e91..40199fd90 100644 --- a/src/main/java/org/ld4l/bib2lod/manager/SimpleManager.java +++ b/src/main/java/org/ld4l/bib2lod/manager/SimpleManager.java @@ -1,3 +1,5 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + package org.ld4l.bib2lod.manager; import java.io.File; @@ -6,20 +8,18 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.ld4l.bib2lod.configuration.Configuration; +import org.ld4l.bib2lod.configuration.DefaultConfiguration; /** - * Simple manager orchestrates conversion of a directory of files or a single - * file. - * + * Orchestrates conversion of a directory of files or a single file. */ public final class SimpleManager { private static final Logger LOGGER = LogManager.getLogger(); /** - * Main method: gets a Configuration object and calls conversion method. + * Main method: gets a DefaultConfiguration object and calls conversion method. * @param args - commandline arguments */ public static void main(String[] args) { @@ -27,8 +27,7 @@ public static void main(String[] args) { LOGGER.info("START CONVERSION."); try { - // TODO Use dependency injection here with factory or factory methods - Configuration configuration = new Configuration(args); + // DefaultConfiguration configuration = DefaultConfiguration.instance(args); // convertFiles(configuration); LOGGER.info("END CONVERSION."); } catch (Exception e) { @@ -41,10 +40,9 @@ public static void main(String[] args) { /** * Converts a list of input files. - * @param configuration - the Configuration object - * @throws IOException + * @param configuration - the DefaultConfiguration object */ - private static void convertFiles(Configuration configuration) { + private static void convertFiles(DefaultConfiguration configuration) { List inputFiles = configuration.getInput(); diff --git a/src/test/java/org/ld4l/bib2lod/configuration/options/JsonUtilsTest.java b/src/test/java/org/ld4l/bib2lod/configuration/options/JsonUtilsTest.java index 6037608c7..470bea680 100644 --- a/src/test/java/org/ld4l/bib2lod/configuration/options/JsonUtilsTest.java +++ b/src/test/java/org/ld4l/bib2lod/configuration/options/JsonUtilsTest.java @@ -4,10 +4,11 @@ import org.junit.Before; import org.junit.Test; -import org.ld4l.bib2lod.configuration.options.JsonUtils.InvalidTypeException; -import org.ld4l.bib2lod.configuration.options.JsonUtils.RequiredKeyMissingException; -import org.ld4l.bib2lod.configuration.options.JsonUtils.RequiredValueEmptyException; -import org.ld4l.bib2lod.configuration.options.JsonUtils.RequiredValueNullException; +import org.ld4l.bib2lod.configuration.JsonUtils; +import org.ld4l.bib2lod.configuration.JsonUtils.InvalidTypeException; +import org.ld4l.bib2lod.configuration.JsonUtils.RequiredKeyMissingException; +import org.ld4l.bib2lod.configuration.JsonUtils.RequiredValueEmptyException; +import org.ld4l.bib2lod.configuration.JsonUtils.RequiredValueNullException; import org.ld4l.bib2lod.testing.AbstractTestClass; import com.fasterxml.jackson.databind.node.ObjectNode;