Skip to content

Commit

Permalink
remove deprecated metadatadictionary (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-mlb authored Oct 10, 2023
1 parent 5e0db47 commit bf98c76
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 993 deletions.
120 changes: 18 additions & 102 deletions src/main/java/emissary/core/BaseDataObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -887,16 +871,8 @@ public void mergeParameters(final Map<? extends String, ? extends Object> m) {
*/
@Override
public void putParameters(final Map<? extends String, ? extends Object> m, final MergePolicy policy) {
// Try remapping
MetadataDictionary dict = null;
try {
dict = MetadataDictionary.lookup();
} catch (NamespaceException ex) {
// Remapping not enabled
}

for (final Map.Entry<? extends String, ? extends Object> 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;
Expand Down Expand Up @@ -932,44 +908,21 @@ public void putParameters(final Map<? extends String, ? extends Object> m, final
@Override
public List<Object> getParameter(final String key) {
// Try remapping
List<Object> 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<Object> v = this.parameters.get(key);
if (CollectionUtils.isEmpty(v)) {
return null;
}
return v;
}

@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<? extends CharSequence> 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);
}

/**
Expand All @@ -983,21 +936,11 @@ public void appendParameter(final String key, final Iterable<? extends CharSeque
*/
@Override
public boolean appendUniqueParameter(final String key, final CharSequence value) {
// Try remapping
MetadataDictionary dict = null;
try {
dict = MetadataDictionary.lookup();
} catch (NamespaceException ex) {
// Remapping not enabled
}

final String n = dict != null ? dict.map(key) : key;

if (this.parameters.containsEntry(n, value)) {
if (this.parameters.containsEntry(key, value)) {
return false;
}

this.parameters.put(n, value);
this.parameters.put(key, value);
return true;
}

Expand Down Expand Up @@ -1058,13 +1001,7 @@ public Set<String> getParameterKeys() {

@Override
public List<Object> 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down
Loading

0 comments on commit bf98c76

Please sign in to comment.