use of org.jabref.model.FieldChange in project jabref by JabRef.
the class CleanupWorker method cleanup.
public List<FieldChange> cleanup(CleanupPreset preset, BibEntry entry) {
Objects.requireNonNull(preset);
Objects.requireNonNull(entry);
List<CleanupJob> jobs = determineCleanupActions(preset);
List<FieldChange> changes = new ArrayList<>();
for (CleanupJob job : jobs) {
changes.addAll(job.cleanup(entry));
}
return changes;
}
use of org.jabref.model.FieldChange in project jabref by JabRef.
the class FileLinksCleanup method cleanup.
@Override
public List<FieldChange> cleanup(BibEntry entry) {
Optional<String> oldValue = entry.getField(FieldName.FILE);
if (!oldValue.isPresent()) {
return Collections.emptyList();
}
List<LinkedFile> fileList = entry.getFiles();
// Parsing automatically moves a single description to link, so we just need to write the fileList back again
String newValue = FileFieldWriter.getStringRepresentation(fileList);
if (!oldValue.get().equals(newValue)) {
entry.setField(FieldName.FILE, newValue);
FieldChange change = new FieldChange(entry, FieldName.FILE, oldValue.get(), newValue);
return Collections.singletonList(change);
}
return Collections.emptyList();
}
use of org.jabref.model.FieldChange in project jabref by JabRef.
the class ISSNCleanup method cleanup.
@Override
public List<FieldChange> cleanup(BibEntry entry) {
Optional<String> issnString = entry.getField(FieldName.ISSN);
if (!issnString.isPresent()) {
return Collections.emptyList();
}
ISSN issn = new ISSN(issnString.get());
if (issn.isCanBeCleaned()) {
String newValue = issn.getCleanedISSN();
FieldChange change = new FieldChange(entry, FieldName.ISSN, issnString.get(), newValue);
entry.setField(FieldName.ISSN, newValue);
return Collections.singletonList(change);
}
return Collections.emptyList();
}
use of org.jabref.model.FieldChange in project jabref by JabRef.
the class SpecialFieldsUtils method syncSpecialFieldsFromKeywords.
/**
* Updates special field values according to keywords
*/
public static List<FieldChange> syncSpecialFieldsFromKeywords(BibEntry entry, Character keywordDelimiter) {
List<FieldChange> fieldChanges = new ArrayList<>();
if (!entry.hasField(FieldName.KEYWORDS)) {
return fieldChanges;
}
KeywordList keywordList = entry.getKeywords(keywordDelimiter);
for (SpecialField field : SpecialField.values()) {
fieldChanges.addAll(SpecialFieldsUtils.importKeywordsForField(keywordList, field, entry));
}
return fieldChanges;
}
use of org.jabref.model.FieldChange in project jabref by JabRef.
the class SpecialFieldsUtils method importKeywordsForField.
private static List<FieldChange> importKeywordsForField(KeywordList keywordList, SpecialField field, BibEntry entry) {
List<FieldChange> fieldChanges = new ArrayList<>();
KeywordList values = field.getKeyWords();
Optional<Keyword> newValue = Optional.empty();
for (Keyword keyword : values) {
if (keywordList.contains(keyword)) {
newValue = Optional.of(keyword);
break;
}
}
UpdateField.updateNonDisplayableField(entry, field.getFieldName(), newValue.map(Keyword::toString).orElse(null)).ifPresent(fieldChange -> {
fieldChanges.add(fieldChange);
});
return fieldChanges;
}
Aggregations