diff --git a/src/main/java/emissary/core/BaseDataObject.java b/src/main/java/emissary/core/BaseDataObject.java index c05249edf2..af3de4c28a 100755 --- a/src/main/java/emissary/core/BaseDataObject.java +++ b/src/main/java/emissary/core/BaseDataObject.java @@ -8,6 +8,7 @@ import emissary.util.PayloadUtil; import com.google.common.collect.LinkedListMultimap; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; import org.slf4j.Logger; @@ -805,14 +806,7 @@ public void clearParameters() { @Override public boolean hasParameter(final String key) { - // Try remapping - try { - final MetadataDictionary dict = MetadataDictionary.lookup(); - return this.parameters.containsKey(dict.map(key)); - } catch (NamespaceException ex) { - // Remapping not enabled - return this.parameters.containsKey(key); - } + return this.parameters.containsKey(key); } @Override @@ -829,22 +823,12 @@ public void setParameter(final String key, final Object val) { @Override public void putParameter(final String key, final Object val) { - // Try remapping - MetadataDictionary dict = null; - try { - dict = MetadataDictionary.lookup(); - } catch (NamespaceException ex) { - // Remapping not enabled - } - - final String n = dict != null ? dict.map(key) : key; - - this.parameters.removeAll(n); + this.parameters.removeAll(key); if (val instanceof Iterable) { - this.parameters.putAll(n, (Iterable) val); + this.parameters.putAll(key, (Iterable) val); } else { - this.parameters.put(n, val); + this.parameters.put(key, val); } } @@ -887,16 +871,8 @@ public void mergeParameters(final Map m) { */ @Override public void putParameters(final Map m, final MergePolicy policy) { - // Try remapping - MetadataDictionary dict = null; - try { - dict = MetadataDictionary.lookup(); - } catch (NamespaceException ex) { - // Remapping not enabled - } - for (final Map.Entry entry : m.entrySet()) { - final String name = dict != null ? dict.map(entry.getKey()) : entry.getKey(); + final String name = entry.getKey(); if ((policy == MergePolicy.KEEP_EXISTING) && this.parameters.containsKey(name)) { continue; @@ -932,15 +908,8 @@ public void putParameters(final Map m, final @Override public List getParameter(final String key) { // Try remapping - List v = null; - try { - final MetadataDictionary dict = MetadataDictionary.lookup(); - v = this.parameters.get(dict.map(key)); - } catch (NamespaceException ex) { - // Remapping not enabled - v = this.parameters.get(key); - } - if ((v == null) || v.isEmpty()) { + List v = this.parameters.get(key); + if (CollectionUtils.isEmpty(v)) { return null; } return v; @@ -948,28 +917,12 @@ public List getParameter(final String key) { @Override public void appendParameter(final String key, final CharSequence value) { - // Try remapping - try { - final MetadataDictionary dict = MetadataDictionary.lookup(); - this.parameters.put(dict.map(key), value); - } catch (NamespaceException ex) { - // Remapping not enabled - this.parameters.put(key, value); - } + this.parameters.put(key, value); } @Override public void appendParameter(final String key, final Iterable values) { - // Try remapping - String pkey = key; - try { - final MetadataDictionary dict = MetadataDictionary.lookup(); - pkey = dict.map(key); - } catch (NamespaceException ex) { - // Remapping not enabled - } - - this.parameters.putAll(pkey, values); + this.parameters.putAll(key, values); } /** @@ -983,21 +936,11 @@ public void appendParameter(final String key, final Iterable getParameterKeys() { @Override public List deleteParameter(final String key) { - try { - final MetadataDictionary dict = MetadataDictionary.lookup(); - return this.parameters.removeAll(dict.map(key)); - } catch (NamespaceException ex) { - // Renaming not enabled - return this.parameters.removeAll(key); - } + return this.parameters.removeAll(key); } @Override @@ -1222,12 +1159,7 @@ public int getNumAlternateViews() { */ @Override public byte[] getAlternateView(final String s) { - try { - final MetadataDictionary dict = MetadataDictionary.lookup(); - return this.multipartAlternative.get(dict.map(s)); - } catch (NamespaceException ex) { - return this.multipartAlternative.get(s); - } + return this.multipartAlternative.get(s); } @Override @@ -1269,37 +1201,21 @@ public ByteBuffer getAlternateViewBuffer(final String s) { */ @Override public void addAlternateView(final String name, @Nullable final byte[] data) { - String mappedName = name; - try { - final MetadataDictionary dict = MetadataDictionary.lookup(); - mappedName = dict.map(name); - } catch (NamespaceException ex) { - // ignore - } - if (data == null) { - this.multipartAlternative.remove(mappedName); + this.multipartAlternative.remove(name); } else { - this.multipartAlternative.put(mappedName, data); + this.multipartAlternative.put(name, data); } } @Override public void addAlternateView(final String name, @Nullable final byte[] data, final int offset, final int length) { - String mappedName = name; - try { - final MetadataDictionary dict = MetadataDictionary.lookup(); - mappedName = dict.map(name); - } catch (NamespaceException ex) { - // ignore - } - if (data == null || length <= 0) { - this.multipartAlternative.remove(mappedName); + this.multipartAlternative.remove(name); } else { final byte[] mpa = new byte[length]; System.arraycopy(data, offset, mpa, 0, length); - this.multipartAlternative.put(mappedName, mpa); + this.multipartAlternative.put(name, mpa); } } diff --git a/src/main/java/emissary/core/MetadataDictionary.java b/src/main/java/emissary/core/MetadataDictionary.java deleted file mode 100644 index a547fd034a..0000000000 --- a/src/main/java/emissary/core/MetadataDictionary.java +++ /dev/null @@ -1,312 +0,0 @@ -package emissary.core; - -import emissary.config.ConfigUtil; -import emissary.config.Configurator; - -import org.apache.commons.collections4.map.LRUMap; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import javax.annotation.Nullable; - -/** - * This class provides metadata renaming and remapping based on values in its configuration file. There are a set of - * exact match rename values, and a set of regex that can be applied to get the new name. Provision is made to store one - * of these dictionaries in the global Namespace and retrieve it if desired, but this class is NOT a singleton. - * - * For performance reasons, a second exact match map is kept for things that matched due to a regex. This map is size - * limited and is handled as an LRU. - * - * THe regex list and the name map are not synchronized. Once the class is configured they do not change. If your - * implementation allows them to change, then you should carefully consider synchronization issues. - */ -@Deprecated -public class MetadataDictionary { - /** - * The default name by which we register into the namespace - */ - public static final String DEFAULT_NAMESPACE_NAME = "MetadataDictionary"; - - /** - * Our logger - */ - protected final Logger logger = LoggerFactory.getLogger(MetadataDictionary.class); - - /** - * The name used by this pool - */ - protected String namespaceName = DEFAULT_NAMESPACE_NAME; - - /** - * The map of exact match renames - */ - protected Map nameMap; - - /** - * The map of regex to run when requested - */ - protected Map regexMap; - - /** - * The regex match cache lru - */ - protected Map regexCache; - - /** - * Create one and register with the default name - */ - public MetadataDictionary() { - reconfigure(null); - } - - /** - * Create one and register with the specified name - * - * @param ns the namespace name - */ - public MetadataDictionary(final String ns) { - this.namespaceName = ns; - reconfigure(null); - } - - /** - * Create one and register with the specified name using the config stream - * - * @param ns the namespace name - * @param conf the config stream to use - */ - public MetadataDictionary(final String ns, final Configurator conf) { - this.namespaceName = ns; - reconfigure(conf); - } - - /** - * Setup from configuration file or stream Items used here are - *
    - *
  • RENAME_* - read into a map for exact match renaming
  • - *
  • REGEX - regex patterns that can drive renaming
  • - *
  • CACHE_SIZE - size for LRU regex cache
  • - *
- * - * @param confArg the config stream to use or null for default - */ - @SuppressWarnings("unchecked") - protected void reconfigure(@Nullable final Configurator confArg) { - try { - final Configurator conf; - if (confArg == null) { - conf = ConfigUtil.getConfigInfo(MetadataDictionary.class); - } else { - conf = confArg; - } - - this.nameMap = conf.findStringMatchMap("RENAME_", Configurator.PRESERVE_CASE); - - final int cacheSize = conf.findIntEntry("CACHE_SIZE", 500); - this.regexCache = new ConcurrentHashMap(new LRUMap(cacheSize)); - this.logger.debug("LRU cache configured with size {}", cacheSize); - - final Map list = conf.findStringMatchMap("REGEX_", Configurator.PRESERVE_CASE); - - this.regexMap = new HashMap(); - - for (final Map.Entry entry : list.entrySet()) { - try { - this.regexMap.put(Pattern.compile(entry.getKey()), entry.getValue()); - } catch (Exception pex) { - this.logger.warn("Pattern '{}' could not compile", entry.getKey(), pex); - } - } - } catch (IOException ex) { - this.logger.warn("Cannot read config file", ex); - } finally { - if (this.nameMap == null) { - this.nameMap = Collections.emptyMap(); - } - - if (this.regexMap == null) { - this.regexMap = Collections.emptyMap(); - } - - if (this.regexCache == null) { - this.regexCache = new LRUMap(500); - } - } - } - - /** - * Bind this object into the namespace - */ - protected void bind() { - Namespace.bind(this.namespaceName, this); - } - - /** - * Get the namespace name for this dictionary - */ - public String getDictionaryName() { - return this.namespaceName; - } - - /** - * Unbind this object - */ - protected void unbind() { - Namespace.unbind(this.namespaceName); - } - - /** - * Factory method to initialize and bind a new default named dictionary - */ - public static MetadataDictionary initialize() { - return initialize(DEFAULT_NAMESPACE_NAME); - } - - /** - * Factory method to initialize and bind a new dictionary - * - * @param ns the namespace anem - */ - public static MetadataDictionary initialize(final String ns) { - final MetadataDictionary m = new MetadataDictionary(ns); - m.bind(); - return m; - } - - /** - * Factory method to initialize and bind a new dictionary using a config object - * - * @param ns the namespace anem - * @param conf the config stream to use - */ - public static MetadataDictionary initialize(final String ns, final Configurator conf) { - final MetadataDictionary m = new MetadataDictionary(ns, conf); - m.bind(); - return m; - } - - /** - * Get the dictionary object from the namespace using the default name - */ - public static MetadataDictionary lookup() throws NamespaceException { - return (MetadataDictionary) Namespace.lookup(DEFAULT_NAMESPACE_NAME); - } - - /** - * Get the dictionary object from the namespace using the specified name - * - * @param ns the namespace name - */ - public static MetadataDictionary lookup(final String ns) throws NamespaceException { - return (MetadataDictionary) Namespace.lookup(ns); - } - - /** - * Nice string for namespace printouts - */ - @Override - public String toString() { - return ("Metadata Dictionary names/regexes " + this.nameMap.size() + "/" + this.regexMap.size()); - } - - /** - * Find a new name for the specified metadata element just using exact matches from the nameMap - * - * @param m the metadata element name - * @return the new name or at least the original name of no remapping - */ - public String rename(final String m) { - final String r = this.nameMap.get(m); - if (r == null) { - return m; - } - return r; - } - - /** - * Return a regex renaming of the metadata element name - * - * @param m the metadata element name - * @return the new name as supplied by the first matching regexp or the original name if nothing matches - */ - public String regex(final String m) { - if (m == null) { - return null; - } - String r = this.regexCache.get(m); - if (r != null) { - this.logger.trace("Found cache match for {} --> {}", m, r); - return r; - } - - for (final Pattern p : this.regexMap.keySet()) { - try { - final Matcher matcher = p.matcher(m); - if (matcher.matches()) { - final String repl = this.regexMap.get(p); - if (repl != null) { - r = matcher.replaceAll(repl); - this.logger.trace("Found regex match for {} --> {}", m, r); - this.regexCache.put(m, r); - return r; - } - this.logger.debug("Matching pattern {} has no replacement string", p.pattern()); - } - } catch (Exception pex) { - this.logger.debug("Pattern matching or replacement problem", pex); - } - - // Cache misses too so we don't have to try every keySet again - this.regexCache.put(m, m); - - } - return m; - } - - /** - * Remap a metadata element - */ - public String map(final CharSequence cs) { - if (cs instanceof String) { - return map((String) cs); - } else { - return map(cs.toString()); - } - } - - /** - * Remap a metadata element or return the original name - * - * @param m the metadata element name - * @return the new name if there is one, or the old name if not - */ - public String map(final String m) { - // We don't call rename(s) here because we want - // to check the null return rather than have to - // do a string compare to see if a mapping was done - String r = this.nameMap.get(m); - if (r == null) { - r = regex(m); - } - if (r == null) { - r = m; - } - return r; - } - - public void shutdown() { - logger.info("Initiating metadata dictionary shutdown..."); - this.nameMap.clear(); - this.regexCache.clear(); - this.regexMap.clear(); - Namespace.unbind(namespaceName); - logger.info("Metadata dictionary shutdown."); - } -} diff --git a/src/main/java/emissary/spi/MetadataDictionaryInitializationProvider.java b/src/main/java/emissary/spi/MetadataDictionaryInitializationProvider.java deleted file mode 100644 index adc60a39be..0000000000 --- a/src/main/java/emissary/spi/MetadataDictionaryInitializationProvider.java +++ /dev/null @@ -1,26 +0,0 @@ -package emissary.spi; - -import emissary.core.MetadataDictionary; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Deprecated -public class MetadataDictionaryInitializationProvider implements InitializationProvider { - protected static Logger logger = LoggerFactory.getLogger(MetadataDictionaryInitializationProvider.class); - - @Override - public void initialize() { - // / Initialize the metadata dictionary - MetadataDictionary.initialize(); - } - - @Override - public void shutdown() { - try { - MetadataDictionary.lookup().shutdown(); - } catch (Exception e) { - logger.warn("no metadata dictionary available"); - } - } -} diff --git a/src/main/java/emissary/util/MetadataDictionaryUtil.java b/src/main/java/emissary/util/MetadataDictionaryUtil.java deleted file mode 100755 index 6d94aa4bdb..0000000000 --- a/src/main/java/emissary/util/MetadataDictionaryUtil.java +++ /dev/null @@ -1,136 +0,0 @@ -package emissary.util; - -import emissary.core.MetadataDictionary; -import emissary.core.NamespaceException; - -import com.google.common.collect.TreeMultimap; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Collection; -import java.util.Map; -import java.util.Map.Entry; -import java.util.TreeMap; - -/** - * This class takes an alternate view byte stream and changes the metadata labels to be consistent with the - * MetadataDictionary - */ -@Deprecated -public class MetadataDictionaryUtil { - // The metadata dictionary to use - MetadataDictionary dict = null; - - // Service prefix to apply to all keys - String servicePrefix = null; - - // Our friendly logger - private Logger logger = LoggerFactory.getLogger(MetadataDictionaryUtil.class); - - // The charset of the data - private String charset = StandardCharsets.UTF_8.name(); - - // separator for key and value - private static final char SEP = ' '; - - public MetadataDictionaryUtil(final String servicePrefix) throws NamespaceException { - this.dict = MetadataDictionary.lookup(); - this.servicePrefix = servicePrefix; - } - - public MetadataDictionaryUtil(final MetadataDictionary dict, final String servicePrefix) { - this.dict = dict; - this.servicePrefix = servicePrefix; - } - - public void setCharset(final String cs) { - this.charset = cs; - } - - /** - * Get the view, map the first token on each line. The view should be structured as "key value" where the first space on - * the line separates the key from the rest. - * - * @param input the bytes of the view to be mapped - * @return a byte[] containing transformed/alphabetized keys with their value pairs - */ - public byte[] map(final byte[] input) throws IOException { - try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { - final Map> kv = convertLinesToMap(input, output); - return convertMapToByteArray(kv, output); - } - } - - /** - * Converts a map of key/values into a byte array. Each key/value will be output on a separate line in alphabetical - * order by key in map. - * - * @param metadata the Map of metadata to convert - * @return a byte[] of key/values on individual lines in alphabetical order - * @throws IOException If there is some I/O problem. - */ - public static byte[] convertMapToByteArray(final Map> metadata) throws IOException { - try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { - return convertMapToByteArray(metadata, output); - } - } - - /** - * Converts a map of key/values into a byte array. Each key/value will be output on a separate line in alphabetical - * order by key in map. - * - * @param kv the Map of metadata to convert - * @param output a ByteArrayOutputStream to write the key/value pairs to - * @return a byte[] of key/values on individual lines in alphabetical order - * @throws IOException If there is some I/O problem. - */ - public static byte[] convertMapToByteArray(final Map> kv, final ByteArrayOutputStream output) throws IOException { - // Output the mapped tokens in the revised alphabetical order - for (final Entry> entry : kv.entrySet()) { - final String key = entry.getKey(); - - for (final String v : entry.getValue()) { - output.write(key.getBytes()); - output.write(SEP); - output.write(v.getBytes()); - output.write('\n'); - } - } - - return output.toByteArray(); - } - - /** - * Read each line of input, tokenize them into key/value pairs, perform a lookup/transformation of the keys via the - * MetadataDictionary where applicable, and return the results as a map. - * - * @param input the bytes to convert - * @param output a ByteArrayOutputStream to write failed parse attempts to - * @return a Map containing each line converted to a key/value pair and sorted alphabetically by key - * @throws IOException If there is some I/O problem. - */ - public Map> convertLinesToMap(final byte[] input, final ByteArrayOutputStream output) throws IOException { - final TreeMultimap kv = TreeMultimap.create(); - final LineTokenizer ltok = new LineTokenizer(input, this.charset); - - // Look at each line for a key value and run it through the dictionary - while (ltok.hasMoreTokens()) { - final String line = ltok.nextToken(); - final int pos = line.indexOf(SEP); - if (pos == -1) { - output.write(line.getBytes()); - output.write('\n'); - this.logger.debug("Found no key/value pair on line " + line); - } else { - final String key = line.substring(0, pos); - final String value = line.substring(pos + 1); - final String nkey = this.dict.map(this.servicePrefix + key); - kv.put(nkey, value.trim()); - } - } - return new TreeMap<>(kv.asMap()); - } -} diff --git a/src/main/resources/META-INF/services/emissary.spi.InitializationProvider b/src/main/resources/META-INF/services/emissary.spi.InitializationProvider index f2a79237d3..43f3840efa 100644 --- a/src/main/resources/META-INF/services/emissary.spi.InitializationProvider +++ b/src/main/resources/META-INF/services/emissary.spi.InitializationProvider @@ -1,3 +1,2 @@ emissary.spi.JavaCharSetInitializationProvider -emissary.spi.MetadataDictionaryInitializationProvider emissary.spi.ClassLocationVerificationProvider diff --git a/src/main/resources/emissary/core/MetadataDictionary.cfg b/src/main/resources/emissary/core/MetadataDictionary.cfg deleted file mode 100644 index a3ba35d348..0000000000 --- a/src/main/resources/emissary/core/MetadataDictionary.cfg +++ /dev/null @@ -1,57 +0,0 @@ -# Configure the LRU pattern cache size -CACHE_SIZE = 100 - -# Configure the names that are to be remapped -# LHS is the incoming name, RHS is the new name -# RENAME_foo = bar - -# Configure Regexs that are used to do renameing -# LHS is the regex, RHS is the replacement -#"REGEX_abc_(foo|bar)_def" = "$1" - -# ImageMetadataPlace -RENAME_ImageMetadataPlace>Artist = "DocumentAuthor" -RENAME_ImageMetadataPlace>Artist = "DocumentAuthor" -RENAME_ImageMetadataPlace>CanonImageType = "ImageType" -RENAME_ImageMetadataPlace>CanonFirmwareVersion = "CameraFirmwareVersion" -"RENAME_ImageMetadataPlace>Caption/Abstract" = "ImageTitle" -RENAME_ImageMetadataPlace>DateTimeOriginal = "ImageCreateDateTime" -RENAME_ImageMetadataPlace>DR4CameraModel = "CameraModel" -RENAME_ImageMetadataPlace>ImageCreateDate = "ImageCreateDateTime" -"RENAME_ImageMetadataPlace>MinoltaImageSize" = "ImageSize" -RENAME_ImageMetadataPlace>FirmwareVersion = "CameraFirmwareVersion" -RENAME_ImageMetadataPlace>Make = "CameraMake" -RENAME_ImageMetadataPlace>Model = "CameraModel" -RENAME_ImageMetadataPlace>LensModel = "CameraLensModel" -RENAME_ImageMetadataPlace>Software = "ImageApplication" -RENAME_ImageMetadataPlace>CreatorTool = "ImageApplication" -"REGEX_(?i)ImageMetadataPlace>Image([-a-z0-9_]+)" = "Image$1" -"REGEX_(?i)ImageMetadataPlace>Image([-a-z0-9_]+)[/ ]([-a-z0-9_]+)" = "Image$1$2" -"REGEX_(?i)ImageMetadataPlace>Image([-a-z0-9_]+)[/ ]([-a-z0-9_]+)[/ ]([-a-z0-9_]+)" = "Image$1$2$3" -"REGEX_(?i)ImageMetadataPlace>(?!Image)([-a-z0-9_]+)" = "Image$1" -"REGEX_(?i)ImageMetadataPlace>(?!Image)([-a-z0-9_]+)[/ ]([-a-z0-9_]+)" = "Image$1$2" -"REGEX_(?i)ImageMetadataPlace>(?!Image)([-a-z0-9_]+)[/ ]([-a-z0-9_]+)[/ ]([-a-z0-9_]+)" = "Image$1$2$3" -"REGEX_(?i)ImageMetadataPlace>(?!Image)([-a-z0-9_]+)[/ ]([-a-z0-9_]+)[/ ]([-a-z0-9_]+)-([-a-z0-9_]+)-([-a-z0-9_]+)" = "Image$1$2$3-$4-$5" - -# ImageMetadataJavaPlace -"RENAME_ImageMetadataJavaPlace>Image Description" = "ImageDescription" -"RENAME_ImageMetadataJavaPlace>Image Height" = "ImageHeight" -"RENAME_ImageMetadataJavaPlace>Image Width" = "ImageWidth" -"RENAME_ImageMetadataJavaPlace>Jpeg Comment" = "ImageComment" -"RENAME_ImageMetadataJavaPlace>Date/Time" = "ImageCreateDateTime" -RENAME_ImageMetadataJavaPlace>ImageCreateDate = "ImageCreateDateTime" -RENAME_ImageMetadataJavaPlace>Software = "ImageApplication" -"RENAME_ImageMetadataJavaPlace>Caption/Abstract" = "ImageTitle" -RENAME_ImageMetadataJavaPlace>Make = "CameraMake" -RENAME_ImageMetadataJavaPlace>Model = "CameraModel" -"RENAME_ImageMetadataJavaPlace>Firmware Version" = "CameraFirmwareVersion" -"RENAME_ImageMetadataJavaPlace>Supplemental Category(s)" = "ImageCategories" -"RENAME_ImageMetadataJavaPlace>Makernote Unknown 2" = "ImageFocalPlaneDiagonal" -"RENAME_ImageMetadataJavaPlace>Makernote Unknown 3" = "ImageLensDistortionParams" -"RENAME_ImageMetadataJavaPlace>Unknown tag (0xa420)" = "ImageUniqueID" -"REGEX_ImageMetadataJavaPlace>Unknown tag \\((0x....)\\)" = "ImageUnknownTag$1" -"REGEX_(?i)ImageMetadataJavaPlace>([-a-z0-9]+)" = "Image$1" -"REGEX_(?i)ImageMetadataJavaPlace>([-a-z0-9]+)[/ ]([-a-z0-9]+)" = "Image$1$2" -"REGEX_(?i)ImageMetadataJavaPlace>([-a-z0-9]+)[/ ]([-a-z0-9]+)[/ ]([-a-z0-9]+)" = "Image$1$2$3" -"REGEX_(?i)ImageMetadataJavaPlace>([-a-z0-9]+)[/ ]([-a-z0-9]+)[/ ]([-a-z0-9]+)[/ ]([-a-z0-9]+)" = "Image$1$2$3$4" -REGEX_ImageMetadataJavaPlace>xmp(?:[a-zA-Z0-9]*):([a-zA-Z0-9]+) = "XMP$1" diff --git a/src/test/java/emissary/core/BaseDataObjectTest.java b/src/test/java/emissary/core/BaseDataObjectTest.java index c7aa8c029b..0faa1964e8 100755 --- a/src/test/java/emissary/core/BaseDataObjectTest.java +++ b/src/test/java/emissary/core/BaseDataObjectTest.java @@ -1,7 +1,5 @@ package emissary.core; -import emissary.config.ConfigUtil; -import emissary.config.Configurator; import emissary.core.channels.FillChannelFactory; import emissary.core.channels.InMemoryChannelFactory; import emissary.core.channels.SeekableByteChannelFactory; @@ -22,7 +20,6 @@ import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mockito; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.lang.reflect.Field; import java.nio.ByteBuffer; @@ -681,38 +678,6 @@ void testBeforeStart() { assertFalse(this.b.beforeStart(), "Not before start with sprout key on list"); } - @Test - void testAltViewRemapping() { - try { - final byte[] configData = ("RENAME_PROPERTIES = \"FLUBBER\"\n" + "RENAME_FOO =\"BAR\"\n").getBytes(); - - final ByteArrayInputStream str = new ByteArrayInputStream(configData); - final Configurator conf = ConfigUtil.getConfigInfo(str); - MetadataDictionary.initialize(MetadataDictionary.DEFAULT_NAMESPACE_NAME, conf); - this.b.addAlternateView("PROPERTIES", configData); - this.b.addAlternateView("FOO", configData, 20, 10); - assertNotNull(this.b.getAlternateView("PROPERTIES"), "Remapped alt view retrieved by original name"); - assertNotNull(this.b.getAlternateView("FLUBBER"), "Remapped alt view retrieved by new name"); - assertNotNull(this.b.getAlternateView("FOO"), "Remapped alt view slice retrieved by original name"); - assertNotNull(this.b.getAlternateView("BAR"), "Remapped alt view slice retrieved by new name"); - final Set avnames = this.b.getAlternateViewNames(); - assertTrue(avnames.contains("FLUBBER"), "Alt view names contains remapped name"); - assertTrue(avnames.contains("BAR"), "Alt view slice names contains remapped name"); - - // Delete by orig name - this.b.addAlternateView("FOO", null, 20, 10); - assertEquals(1, this.b.getAlternateViewNames().size(), "View removed by orig name"); - // Delete by mapped name - this.b.addAlternateView("FLUBBER", null); - assertEquals(0, this.b.getAlternateViewNames().size(), "View removed by orig name"); - } catch (Exception ex) { - fail("Could not configure test", ex); - } finally { - // Clean up - Namespace.unbind(MetadataDictionary.DEFAULT_NAMESPACE_NAME); - } - } - @Test void testParametersMapSignature() { final Map map = new HashMap<>(); diff --git a/src/test/java/emissary/core/BaseDataWithRemappingTest.java b/src/test/java/emissary/core/BaseDataWithRemappingTest.java deleted file mode 100755 index 36b9867e00..0000000000 --- a/src/test/java/emissary/core/BaseDataWithRemappingTest.java +++ /dev/null @@ -1,125 +0,0 @@ -package emissary.core; - -import emissary.test.core.junit5.UnitTest; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -class BaseDataWithRemappingTest extends UnitTest { - private BaseDataObject b = null; - private static MetadataDictionary md = null; - - @BeforeAll - public static void beforeClass() { - // this runs before UnitTest has a chance to setup, so do that first - UnitTest.setupSystemProperties(); - - md = new RemappingMetadataDictionary(); - Namespace.bind(md.getDictionaryName(), md); - } - - @AfterAll - public static void afterClass() { - Namespace.unbind(md.getDictionaryName()); - } - - @Override - @BeforeEach - public void setUp() throws Exception { - b = new BaseDataObject("This is a test".getBytes(), "filename.txt"); - b.pushCurrentForm("ONE"); - b.pushCurrentForm("TWO"); - b.pushCurrentForm("THREE"); - } - - @Override - @AfterEach - public void tearDown() throws Exception { - super.tearDown(); - b = null; - } - - @Test - void testAltViews() { - b.addAlternateView("TESTVIEW1", "alternate view".getBytes()); - b.addAlternateView("TESTVIEW2", "alternate view".getBytes()); - b.addAlternateView("TESTVIEW3", "alternate view".getBytes()); - - b.addAlternateView("TESTVIEW2", null); - assertNull(b.getAlternateView("TESTVIEW2"), "Null view after removal"); - assertNull(b.getAlternateViewBuffer("TESTVIEW2"), "Empty byte buffer after removal"); - - // Also null with remapped name - assertNull(b.getAlternateView("testview2"), "Null view by mapped name after removal"); - assertNull(b.getAlternateViewBuffer("testview2"), "Empty byte buffer by mapped name after removal"); - } - - @Test - void testSetOfAltViewNames() { - b.addAlternateView("TESTVIEW1", "alternate view".getBytes()); - b.addAlternateView("TESTVIEW2", "alternate view".getBytes()); - b.addAlternateView("TESTVIEW3", "alternate view".getBytes()); - Set vnames = b.getAlternateViewNames(); - assertEquals(3, vnames.size(), "Count of view names"); - assertTrue(vnames.contains("testview1"), "Altview names should have been remapped"); - assertTrue(vnames.contains("testview2"), "Altview names should have been remapped"); - assertTrue(vnames.contains("testview3"), "Altview names should have been remapped"); - } - - @Test - void testMapOfAltViews() { - b.addAlternateView("TESTVIEW1", "alternate view".getBytes()); - b.addAlternateView("TESTVIEW2", "alternate view".getBytes()); - b.addAlternateView("TESTVIEW3", "alternate view".getBytes()); - Map v = b.getAlternateViews(); - assertEquals(3, v.size(), "Count of views"); - Set vnames = v.keySet(); - assertTrue(vnames.contains("testview1"), "Altview names should have been remapped"); - assertTrue(vnames.contains("testview2"), "Altview names should have been remapped"); - assertTrue(vnames.contains("testview3"), "Altview names should have been remapped"); - } - - @Test - void testParameters() { - b.putParameter("ME", "YOU"); - assertEquals("YOU", b.getStringParameter("ME"), "Gotten parameter"); - Map map = new HashMap<>(); - map.put("ONE", "uno"); - map.put("TWO", "dos"); - map.put("THREE", "tres"); - b.putParameters(map); - assertEquals("uno", b.getStringParameter("ONE"), "Map put parameter gotten"); - assertEquals("dos", b.getStringParameter("TWO"), "Map put parameter gotten"); - assertEquals("tres", b.getStringParameter("THREE"), "Map put parameter gotten"); - assertEquals("YOU", b.getStringParameter("ME"), "Gotten parameter"); - - // Deletes - b.deleteParameter("THREE"); - assertNull(b.getParameter("THREE"), "Deleted param is gone"); - - // Overwrite - b.putParameter("ME", "THEM"); - assertEquals("THEM", b.getStringParameter("ME"), "Gotten parameter"); - - // Clear - b.clearParameters(); - assertNull(b.getParameter("THREE"), "Deleted param is gone"); - assertNull(b.getParameter("ME"), "Deleted param is gone"); - Map m = b.getParameters(); - assertNotNull(m, "Clear paramters leave empty map"); - assertEquals(0, m.size(), "Clear parameters leaves empty map"); - } - -} diff --git a/src/test/java/emissary/core/MetadataDictionaryTest.java b/src/test/java/emissary/core/MetadataDictionaryTest.java deleted file mode 100644 index a9501e579e..0000000000 --- a/src/test/java/emissary/core/MetadataDictionaryTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package emissary.core; - -import emissary.config.ConfigUtil; -import emissary.config.Configurator; -import emissary.test.core.junit5.UnitTest; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.fail; - -public class MetadataDictionaryTest extends UnitTest { - private static final String TEST_NAMESPACE = "test_namespace"; - - private MetadataDictionary getDict(boolean bind) { - MetadataDictionary m = null; - try { - Configurator conf = ConfigUtil.getConfigInfo(this.getClass()); - assertNotNull(conf, "Could not find config for MetadataDictionaryTest"); - if (bind) { - m = MetadataDictionary.initialize(TEST_NAMESPACE, conf); - } else { - m = new MetadataDictionary(TEST_NAMESPACE, conf); - } - } catch (Exception ex) { - fail("Exception configuring dictionary", ex); - } - assertNotNull(m, "Metadata Dictionary must be created"); - return m; - } - - private MetadataDictionary getDict() { - return getDict(false); - } - - private void clearNamespace() { - emissary.core.Namespace.unbind(TEST_NAMESPACE); - } - - @Test - void testRename() { - MetadataDictionary d = getDict(); - assertEquals("bar", d.rename("foo"), "Renaming for found value"); - } - - @Test - void testNonRename() { - MetadataDictionary d = getDict(); - assertEquals("baz", d.rename("baz"), "Original name for not-found value"); - } - - @Test - void testRegexRename() { - MetadataDictionary d = getDict(); - assertEquals("^bar^", d.regex("abc_bar_def"), "Rename by regex match"); - } - - @Test - void testRegexNonRename() { - MetadataDictionary d = getDict(); - assertEquals("shazam", d.regex("shazam"), "Original name when no regex match"); - } - - @Test - void testFullMapRename() { - MetadataDictionary d = getDict(); - assertEquals("NothingHappens", d.map("xyzzy"), "Rename on exact match via map"); - } - - @Test - void testFullMapRegex() { - MetadataDictionary d = getDict(); - assertEquals("NothingHappensCaseInsensitively", d.map("xyZZy"), "Rename on regex match via map"); - } - - @Test - void testFullMapNoMatch() { - MetadataDictionary d = getDict(); - assertEquals("Hello", d.map("Hello"), "NO match via map gives original name"); - } - - - @Test - void testNamespace() { - try { - MetadataDictionary d1 = getDict(true); - MetadataDictionary d2 = MetadataDictionary.lookup(TEST_NAMESPACE); - assertEquals(d1, d2, "INitialize must bind by default lookup name"); - } catch (Exception ex) { - fail("Exception doing namespace lookup", ex); - } finally { - clearNamespace(); - } - } - - @Test - void testNullRegex() { - MetadataDictionary dict = getDict(true); - try { - assertNull(dict.regex(null), "regex() should return null if we pass it a null value."); - } catch (NullPointerException ex) { - fail("An exception was thrown instead of handling a null value gracefully", ex); - } - } - -} diff --git a/src/test/java/emissary/core/RemappingMetadataDictionary.java b/src/test/java/emissary/core/RemappingMetadataDictionary.java deleted file mode 100644 index b8fce2cba7..0000000000 --- a/src/test/java/emissary/core/RemappingMetadataDictionary.java +++ /dev/null @@ -1,11 +0,0 @@ -package emissary.core; - -public class RemappingMetadataDictionary extends MetadataDictionary { - @Override - public String map(final String s) { - if ("FOO".equals(s)) { - return "BAR"; - } - return s.toLowerCase(); - } -} diff --git a/src/test/java/emissary/util/MetadataDictionaryUtilTest.java b/src/test/java/emissary/util/MetadataDictionaryUtilTest.java deleted file mode 100644 index 1a1e7d412a..0000000000 --- a/src/test/java/emissary/util/MetadataDictionaryUtilTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package emissary.util; - -import emissary.config.ConfigUtil; -import emissary.config.Configurator; -import emissary.core.MetadataDictionary; -import emissary.core.MetadataDictionaryTest; -import emissary.test.core.junit5.UnitTest; - -import com.google.common.collect.TreeMultimap; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Collection; -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - -class MetadataDictionaryUtilTest extends UnitTest { - - MetadataDictionary dict; - private String lines; - private MetadataDictionaryUtil md; - - @BeforeEach - public void setup() throws IOException { - final Configurator conf = ConfigUtil.getConfigInfo(MetadataDictionaryTest.class); - this.dict = new MetadataDictionary("test", conf); - this.lines = "key val1\nxyzzy val2\nanother val3\n"; - this.md = new MetadataDictionaryUtil(this.dict, ""); - } - - @Test - void keysCanMapToMultipleVals() { - try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { - final Map> map = this.md.convertLinesToMap(this.lines.getBytes(), output); - - assertEquals(2, map.size()); - assertEquals(2, map.get("NothingHappens").size()); - assertTrue(map.get("NothingHappens").contains("val2")); - assertTrue(map.get("NothingHappens").contains("val3")); - - assertEquals(1, map.get("key").size()); - assertTrue(map.get("key").contains("val1")); - } catch (IOException e) { - fail("Exception occurred while converting lines to map", e); - } - } - - @Test - void mapConvertsToByteArray() throws IOException { - final TreeMultimap kv = TreeMultimap.create(); - kv.put("abc", "val1"); - kv.put("zzz", "val2"); - kv.put("xyzzy", "val3"); - kv.put("another", "val4"); - - final byte[] mapped = MetadataDictionaryUtil.convertMapToByteArray(kv.asMap()); - assertEquals("abc val1\nanother val4\nxyzzy val3\nzzz val2\n", new String(mapped)); - - final byte[] mappedAgain = this.md.map(mapped); - assertEquals("NothingHappens val3\nNothingHappens val4\nabc val1\nzzz val2\n", new String(mappedAgain)); - } -} diff --git a/src/test/resources/emissary/core/MetadataDictionaryTest.cfg b/src/test/resources/emissary/core/MetadataDictionaryTest.cfg deleted file mode 100644 index 81ec29866e..0000000000 --- a/src/test/resources/emissary/core/MetadataDictionaryTest.cfg +++ /dev/null @@ -1,13 +0,0 @@ -# Configure the LRU pattern cache size -CACHE_SIZE = 100 - -# Configure the names that are to be remapped -# LHS is the incoming name, RHS is the new name -RENAME_foo = bar -RENAME_xyzzy = "NothingHappens" -RENAME_another = "NothingHappens" - -# Configure Regexs that are used to do renameing -# LHS is the regex, RHS is the replacement -"REGEX_abc_(foo|bar)_def" = "^$1^" -"REGEX_(?i)XYZZY" = "NothingHappensCaseInsensitively"