Search in sources :

Example 11 with FieldChange

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;
}
Also used : ArrayList(java.util.ArrayList) FieldChange(org.jabref.model.FieldChange) CleanupJob(org.jabref.model.cleanup.CleanupJob)

Example 12 with FieldChange

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();
}
Also used : LinkedFile(org.jabref.model.entry.LinkedFile) FieldChange(org.jabref.model.FieldChange)

Example 13 with FieldChange

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();
}
Also used : ISSN(org.jabref.model.entry.identifier.ISSN) FieldChange(org.jabref.model.FieldChange)

Example 14 with FieldChange

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;
}
Also used : SpecialField(org.jabref.model.entry.specialfields.SpecialField) ArrayList(java.util.ArrayList) FieldChange(org.jabref.model.FieldChange) KeywordList(org.jabref.model.entry.KeywordList)

Example 15 with FieldChange

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;
}
Also used : Keyword(org.jabref.model.entry.Keyword) ArrayList(java.util.ArrayList) FieldChange(org.jabref.model.FieldChange) KeywordList(org.jabref.model.entry.KeywordList)

Aggregations

FieldChange (org.jabref.model.FieldChange)35 BibEntry (org.jabref.model.entry.BibEntry)17 ArrayList (java.util.ArrayList)13 UndoableFieldChange (org.jabref.gui.undo.UndoableFieldChange)8 NamedCompound (org.jabref.gui.undo.NamedCompound)7 Test (org.junit.Test)7 KeywordList (org.jabref.model.entry.KeywordList)6 LinkedFile (org.jabref.model.entry.LinkedFile)6 IOException (java.io.IOException)3 File (java.io.File)2 Path (java.nio.file.Path)2 Keyword (org.jabref.model.entry.Keyword)2 FieldChangedEvent (org.jabref.model.entry.event.FieldChangedEvent)2 Subscribe (com.google.common.eventbus.Subscribe)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 AbstractUndoableEdit (javax.swing.undo.AbstractUndoableEdit)1 BasePanel (org.jabref.gui.BasePanel)1 CleanupWorker (org.jabref.logic.cleanup.CleanupWorker)1