Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix XMP null error #5519

Merged
merged 1 commit into from
Oct 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- After assigning an entry to a group, the item count is now properly colored to reflect the new membership of the entry. [#3112](https://github.com/JabRef/jabref/issues/3112)
- The group panel is now properly updated when switching between libraries (or when closing/opening one). [#3142](https://github.com/JabRef/jabref/issues/3142)
- We fixed an error where the number of matched entries shown in the group pane was not updated correctly. [#4441](https://github.com/JabRef/jabref/issues/4441)
- We fixed a "null" error when writing XMP metadata. [#5449](https://github.com/JabRef/jabref/issues/5449)
- We fixed an issue where empty keywords lead to a strange display of automatic keyword groups. [#5333](https://github.com/JabRef/jabref/issues/5333)
- We fixed an error where the default color of a new group was white instead of dark gray. [#4868](https://github.com/JabRef/jabref/issues/4868)
- We fixed an issue where the first field in the entry editor got the focus while performing a different action (like searching). [#5084](https://github.com/JabRef/jabref/issues/5084)
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/jabref/logic/xmp/DublinCoreExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,11 @@ private void fillCustomField(Field field, String value) {
public void fillDublinCoreSchema() {
// Query privacy filter settings
boolean useXmpPrivacyFilter = xmpPreferences.isUseXMPPrivacyFilter();
// Fields for which not to write XMP data later on:
Set<Field> filters = new TreeSet<>(xmpPreferences.getXmpPrivacyFilter());

Set<Entry<Field, String>> fieldValues = new TreeSet<>(Comparator.comparing(fieldStringEntry -> fieldStringEntry.getKey().getName()));
fieldValues.addAll(bibEntry.getFieldMap().entrySet());
for (Entry<Field, String> field : fieldValues) {
if (useXmpPrivacyFilter && filters.contains(field.getKey())) {
if (useXmpPrivacyFilter && xmpPreferences.getXmpPrivacyFilter().contains(field.getKey())) {
continue;
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/jabref/logic/xmp/XmpPreferences.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package org.jabref.logic.xmp;

import java.util.List;
import java.util.Set;

import org.jabref.model.entry.field.Field;

public class XmpPreferences {

private final boolean useXMPPrivacyFilter;
private final List<Field> xmpPrivacyFilter;
private final Set<Field> xmpPrivacyFilter;
private final Character keywordSeparator;

public XmpPreferences(boolean useXMPPrivacyFilter, List<Field> xmpPrivacyFilter, Character keywordSeparator) {
public XmpPreferences(boolean useXMPPrivacyFilter, Set<Field> xmpPrivacyFilter, Character keywordSeparator) {
this.useXMPPrivacyFilter = useXMPPrivacyFilter;
this.xmpPrivacyFilter = xmpPrivacyFilter;
this.keywordSeparator = keywordSeparator;
Expand All @@ -20,7 +20,7 @@ public boolean isUseXMPPrivacyFilter() {
return useXMPPrivacyFilter;
}

public List<Field> getXmpPrivacyFilter() {
public Set<Field> getXmpPrivacyFilter() {
return xmpPrivacyFilter;
}

Expand Down
32 changes: 14 additions & 18 deletions src/main/java/org/jabref/logic/xmp/XmpUtilWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Predicate;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -249,40 +247,38 @@ private static void writeDocumentInformation(PDDocument document,

// Query privacy filter settings
boolean useXmpPrivacyFilter = xmpPreferences.isUseXMPPrivacyFilter();
// Fields for which not to write XMP data later on:
Set<Field> filters = new TreeSet<>(xmpPreferences.getXmpPrivacyFilter());

// Set all the values including key and entryType
for (Entry<Field, String> field : resolvedEntry.getFieldMap().entrySet()) {
Field fieldName = field.getKey();
String fieldContent = field.getValue();
for (Entry<Field, String> fieldValuePair : resolvedEntry.getFieldMap().entrySet()) {
Field field = fieldValuePair.getKey();
String fieldContent = fieldValuePair.getValue();

if (useXmpPrivacyFilter && filters.contains(fieldName)) {
if (useXmpPrivacyFilter && xmpPreferences.getXmpPrivacyFilter().contains(field)) {
// erase field instead of adding it
if (StandardField.AUTHOR.equals(fieldName)) {
if (StandardField.AUTHOR.equals(field)) {
di.setAuthor(null);
} else if (StandardField.TITLE.equals(fieldName)) {
} else if (StandardField.TITLE.equals(field)) {
di.setTitle(null);
} else if (StandardField.KEYWORDS.equals(fieldName)) {
} else if (StandardField.KEYWORDS.equals(field)) {
di.setKeywords(null);
} else if (StandardField.ABSTRACT.equals(fieldName)) {
} else if (StandardField.ABSTRACT.equals(field)) {
di.setSubject(null);
} else {
di.setCustomMetadataValue("bibtex/" + fieldName, null);
di.setCustomMetadataValue("bibtex/" + field, null);
}
continue;
}

if (StandardField.AUTHOR.equals(fieldName)) {
if (StandardField.AUTHOR.equals(field)) {
di.setAuthor(fieldContent);
} else if (StandardField.TITLE.equals(fieldName)) {
} else if (StandardField.TITLE.equals(field)) {
di.setTitle(fieldContent);
} else if (StandardField.KEYWORDS.equals(fieldName)) {
} else if (StandardField.KEYWORDS.equals(field)) {
di.setKeywords(fieldContent);
} else if (StandardField.ABSTRACT.equals(fieldName)) {
} else if (StandardField.ABSTRACT.equals(field)) {
di.setSubject(fieldContent);
} else {
di.setCustomMetadataValue("bibtex/" + fieldName, fieldContent);
di.setCustomMetadataValue("bibtex/" + field, fieldContent);
}
}
di.setCustomMetadataValue("bibtex/entrytype", resolvedEntry.getType().getDisplayName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ public LayoutFormatterPreferences getLayoutFormatterPreferences(JournalAbbreviat

@Override
public XmpPreferences getXMPPreferences() {
return new XmpPreferences(getBoolean(USE_XMP_PRIVACY_FILTER), getStringList(XMP_PRIVACY_FILTERS).stream().map(FieldFactory::parseField).collect(Collectors.toList()),
return new XmpPreferences(getBoolean(USE_XMP_PRIVACY_FILTER), getStringList(XMP_PRIVACY_FILTERS).stream().map(FieldFactory::parseField).collect(Collectors.toSet()),
getKeywordDelimiter());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void writeMultipleEntriesInDifferentFiles(@TempDir Path testFolder) throw

@Test
public void exportSingleEntryWithPrivacyFilter(@TempDir Path testFolder) throws Exception {
when(xmpPreferences.getXmpPrivacyFilter()).thenReturn(Collections.singletonList(StandardField.AUTHOR));
when(xmpPreferences.getXmpPrivacyFilter()).thenReturn(Collections.singleton(StandardField.AUTHOR));
when(xmpPreferences.isUseXMPPrivacyFilter()).thenReturn(true);

Path file = testFolder.resolve("ThisIsARandomlyNamedFile");
Expand Down