Skip to content

Commit 03edc51

Browse files
authored
Skip adding descriptive values when they are blank (#1357)
1 parent c76113b commit 03edc51

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

indexing-solr/src/main/java/edu/unc/lib/boxc/indexing/solr/filter/SetDescriptiveMetadataFilter.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.List;
2828
import java.util.Properties;
2929

30+
import org.apache.commons.lang3.StringUtils;
3031
import org.apache.jena.rdf.model.Property;
3132
import org.apache.jena.rdf.model.Resource;
3233
import org.apache.jena.rdf.model.Statement;
@@ -246,11 +247,11 @@ private void extractSubjects(Element mods, IndexDocumentBean idb) {
246247
String subjectName = subjectEl.getName();
247248

248249
if (subjectName.equals("name")) {
249-
subjects.add(formatName(subjectEl));
250+
addIfNotBlank(subjects, formatName(subjectEl));
250251
}
251252

252253
if (subjectEl.getChildren().isEmpty() && subjectName.equals("topic")) {
253-
subjects.add(subjectEl.getValue());
254+
addIfNotBlank(subjects, subjectEl.getValue());
254255
}
255256
}
256257
}
@@ -376,15 +377,19 @@ private void extractGenre(Element mods, IndexDocumentBean idb) {
376377
this.addValuesToList(idb.getGenre(), mods.getChildren("genre", JDOMNamespaceUtil.MODS_V3_NS));
377378
}
378379

380+
private void addIfNotBlank(List<String> values, String newValue) {
381+
if (StringUtils.isBlank(newValue)) {
382+
return;
383+
}
384+
values.add(newValue);
385+
}
386+
379387
private void addValuesToList(List<String> values, List<Element> elements) {
380388
if (elements == null) {
381389
return;
382390
}
383391
for (Element elementObj: elements) {
384-
String value = elementObj.getValue();
385-
if (value != null) {
386-
values.add(value.trim());
387-
}
392+
addIfNotBlank(values, elementObj.getValue());
388393
}
389394
}
390395

0 commit comments

Comments
 (0)