Skip to content

Commit

Permalink
TIKA-4289 -- improve serializability for the metadatafilters (#1868)
Browse files Browse the repository at this point in the history
  • Loading branch information
tballison authored Jul 30, 2024
1 parent 137c0d1 commit e4d774b
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ public void setTargetField(String targetField) {
this.targetField = targetField;
}

public String getRegex() {
return regexString;
}

public String getSourceField() {
return sourceField;
}

public String getTargetField() {
return targetField;
}

@Override
public void initialize(Map<String, Param> params) throws TikaConfigException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.tika.metadata.filter;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -82,4 +83,8 @@ public void setTypes(List<String> types) throws TikaConfigException {
}
this.types.addAll(types);
}

public List<String> getTypes() {
return new ArrayList<>(types);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.tika.metadata.filter;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -65,4 +66,8 @@ public void filter(Metadata metadata) throws TikaException {
public void setMimes(List<String> mimes) {
this.mimes.addAll(mimes);
}

public List<String> getMimes() {
return new ArrayList<>(mimes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,33 @@
*/
package org.apache.tika.metadata.filter;

import java.util.ArrayList;
import java.util.List;

import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;

public class CompositeMetadataFilter extends MetadataFilter {

private final List<MetadataFilter> filters;
//no longer final to allow for no arg initialization during serialization
private List<MetadataFilter> filters;

public CompositeMetadataFilter() {
filters = new ArrayList<>();
}
public CompositeMetadataFilter(List<MetadataFilter> filters) {
this.filters = filters;
}

public void setFilters(List<MetadataFilter> filters) {
this.filters.clear();
this.filters.addAll(filters);
}

public List<MetadataFilter> getFilters() {
return filters;
}

@Override
public void filter(Metadata metadata) throws TikaException {
for (MetadataFilter filter : filters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ public void filter(Metadata metadata) throws TikaException {
public void setDefaultTimeZone(String timeZoneId) {
this.defaultTimeZone = TimeZone.getTimeZone(ZoneId.of(timeZoneId));
}

public String getDefaultTimeZone() {
return this.defaultTimeZone.toZoneId().toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.tika.metadata.filter;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -49,4 +50,8 @@ public void filter(Metadata metadata) throws TikaException {
public void setExclude(List<String> exclude) {
this.excludeSet.addAll(exclude);
}

public List<String> getExclude() {
return new ArrayList<>(excludeSet);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public void setMappings(Map<String, String> mappings) {
}
}

public Map<String, String> getMappins() {
return mappings;
}

@Override
public String toString() {
return "FieldNameMappingFilter{" + "mappings=" + mappings + ", excludeUnmapped=" + excludeUnmapped + '}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public void setGeoPointFieldName(String geoPointFieldName) {
this.geoPointFieldName = geoPointFieldName;
}

public String getGeoPointFieldName() {
return geoPointFieldName;
}

@Override
public void filter(Metadata metadata) throws TikaException {
String lat = metadata.get(TikaCoreProperties.LATITUDE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.tika.metadata.filter;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -43,6 +44,10 @@ public void setInclude(List<String> include) {
includeSet.addAll(include);
}

public List<String> getInclude() {
return new ArrayList<>(includeSet);
}

@Override
public void filter(Metadata metadata) throws TikaException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static void serializeObject(String fieldName, Object obj, Class superClas
.getClass()
.getConstructor();
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("class (" + obj.getClass() + ") doesn't have a no-arg constructor. Respectfully not seralizing.");
throw new IllegalArgumentException("class (" + obj.getClass() + ") doesn't have a no-arg constructor. Respectfully not serializing.");
}
try {
if (fieldName != null) {
Expand Down Expand Up @@ -221,10 +221,6 @@ private static void serializeCollection(String fieldName, Object obj, JsonGenera
}
}

private static void serializeItem(String field, Object obj, Class<?> generalType, JsonGenerator jsonGenerator) {

}

private static void serializePrimitiveAndBoxed(String paramName, Object obj, JsonGenerator jsonGenerator) throws IOException {
Class clazz = obj.getClass();
if (paramName != null) {
Expand Down

0 comments on commit e4d774b

Please sign in to comment.