use of org.jabref.model.FieldChange in project jabref by JabRef.
the class CleanupWorkerTest method cleanupDoesNothingByDefault.
@Test
public void cleanupDoesNothingByDefault() throws IOException {
BibEntry entry = new BibEntry();
entry.setCiteKey("Toot");
entry.setField("pdf", "aPdfFile");
entry.setField("some", "1st");
entry.setField("doi", "http://dx.doi.org/10.1016/0001-8708(80)90035-3");
entry.setField("month", "01");
entry.setField("pages", "1-2");
entry.setField("date", "01/1999");
entry.setField("pdf", "aPdfFile");
entry.setField("ps", "aPsFile");
entry.setField("file", "link::");
entry.setField("journal", "test");
entry.setField("title", "<b>hallo</b> units 1 A case AlGaAs and latex $\\alpha$$\\beta$");
entry.setField("abstract", "Réflexions");
File tempFile = bibFolder.newFile();
LinkedFile fileField = new LinkedFile("", tempFile.getAbsolutePath(), "");
entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));
List<FieldChange> changes = worker.cleanup(emptyPreset, entry);
Assert.assertEquals(Collections.emptyList(), changes);
}
use of org.jabref.model.FieldChange in project jabref by JabRef.
the class CleanupWorkerTest method cleanupDoiReturnsChangeWhenDoiInURLField.
@Test
public void cleanupDoiReturnsChangeWhenDoiInURLField() {
CleanupPreset preset = new CleanupPreset(CleanupPreset.CleanupStep.CLEAN_UP_DOI);
BibEntry entry = new BibEntry();
entry.setField("url", "http://dx.doi.org/10.1016/0001-8708(80)90035-3");
List<FieldChange> changes = worker.cleanup(preset, entry);
List<FieldChange> changeList = new ArrayList<>();
changeList.add(new FieldChange(entry, "doi", null, "10.1016/0001-8708(80)90035-3"));
changeList.add(new FieldChange(entry, "url", "http://dx.doi.org/10.1016/0001-8708(80)90035-3", null));
Assert.assertEquals(changeList, changes);
}
use of org.jabref.model.FieldChange in project jabref by JabRef.
the class CleanupWorkerTest method cleanupDoiReturnsChanges.
@Test
public void cleanupDoiReturnsChanges() {
CleanupPreset preset = new CleanupPreset(CleanupPreset.CleanupStep.CLEAN_UP_DOI);
BibEntry entry = new BibEntry();
entry.setField("doi", "http://dx.doi.org/10.1016/0001-8708(80)90035-3");
List<FieldChange> changes = worker.cleanup(preset, entry);
FieldChange expectedChange = new FieldChange(entry, "doi", "http://dx.doi.org/10.1016/0001-8708(80)90035-3", "10.1016/0001-8708(80)90035-3");
Assert.assertEquals(Collections.singletonList(expectedChange), changes);
}
use of org.jabref.model.FieldChange in project jabref by JabRef.
the class SpecialFieldDatabaseChangeListener method listen.
@Subscribe
public void listen(EntryAddedEvent event) {
if (!Globals.prefs.isKeywordSyncEnabled()) {
return;
}
final BibEntry entry = event.getBibEntry();
// NamedCompount code similar to SpecialFieldUpdateListener
NamedCompound nc = new NamedCompound(Localization.lang("Synchronized special fields based on keywords"));
List<FieldChange> changes = SpecialFieldsUtils.syncSpecialFieldsFromKeywords(entry, Globals.prefs.getKeywordDelimiter());
for (FieldChange change : changes) {
nc.addEdit(new UndoableFieldChange(change));
}
// Don't insert the compound into the undoManager,
// it would be added before the component which undoes the insertion of the entry and creates heavy problems
// (which prohibits the undo the deleting multiple entries)
}
use of org.jabref.model.FieldChange in project jabref by JabRef.
the class DoiCleanup method cleanup.
@Override
public List<FieldChange> cleanup(BibEntry entry) {
List<FieldChange> changes = new ArrayList<>();
// First check if the Doi Field is empty
if (entry.hasField(FieldName.DOI)) {
String doiFieldValue = entry.getField(FieldName.DOI).orElse(null);
Optional<DOI> doi = DOI.parse(doiFieldValue);
if (doi.isPresent()) {
String newValue = doi.get().getDOI();
if (!doiFieldValue.equals(newValue)) {
entry.setField(FieldName.DOI, newValue);
FieldChange change = new FieldChange(entry, FieldName.DOI, doiFieldValue, newValue);
changes.add(change);
}
// Doi field seems to contain Doi -> cleanup note, url, ee field
for (String field : FIELDS) {
entry.getField(field).flatMap(DOI::parse).ifPresent(unused -> removeFieldValue(entry, field, changes));
}
}
} else {
// As the Doi field is empty we now check if note, url, or ee field contains a Doi
for (String field : FIELDS) {
Optional<DOI> doi = entry.getField(field).flatMap(DOI::parse);
if (doi.isPresent()) {
// update Doi
String oldValue = entry.getField(FieldName.DOI).orElse(null);
String newValue = doi.get().getDOI();
entry.setField(FieldName.DOI, newValue);
FieldChange change = new FieldChange(entry, FieldName.DOI, oldValue, newValue);
changes.add(change);
removeFieldValue(entry, field, changes);
}
}
}
return changes;
}
Aggregations