Skip to content

Commit

Permalink
Entry editor shows both journal and journaltitle in the case of BibLa…
Browse files Browse the repository at this point in the history
…TeX mode
  • Loading branch information
koppor committed Dec 12, 2016
1 parent 4aa0da2 commit 7e57775
Show file tree
Hide file tree
Showing 22 changed files with 128 additions and 61 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Adds an integrity check that detects invalid DOIs [#1445](https://github.com/JabRef/jabref/issues/1445)
- We changed the order of the cleanup operations so that the generated file name corresponds to the cleaned-up fields. [1441](https://github.com/JabRef/jabref/issues/1441)
- Replaces manual thread management with cached thread pool
- We enhanced the integrity checks testing for biblatex-only fields to be aware of more fields (e.g., `location`).
- We display both the field name `journaltitle` and `journal` in BibLaTeX mode as `journaltitle` only was causing headaches. [#2209](https://github.com/JabRef/jabref/issues/2209)
- Files can now be moved to subfolders named by a custom format pattern, e.g., based on `entrytype`.
The pattern can be specified in the settings like the filename pattern. [#1092](https://github.com/JabRef/jabref/issues/1092)

Expand Down
16 changes: 3 additions & 13 deletions src/main/java/net/sf/jabref/logic/TypedBibEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Optional;

import net.sf.jabref.model.EntryTypes;
import net.sf.jabref.model.FieldChange;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.database.BibDatabaseContext;
import net.sf.jabref.model.database.BibDatabaseMode;
Expand All @@ -17,6 +16,9 @@
import net.sf.jabref.model.entry.ParsedFileField;
import net.sf.jabref.model.strings.StringUtil;

/**
* Wrapper around a {@link BibEntry} offering methods for {@link BibDatabaseMode} dependend results
*/
public class TypedBibEntry {

private final BibEntry entry;
Expand Down Expand Up @@ -77,16 +79,4 @@ public List<ParsedFileField> getFiles() {
return FileField.parse(oldValue.get());
}

public Optional<FieldChange> setFiles(List<ParsedFileField> files) {

Optional<String> oldValue = entry.getField(FieldName.FILE);
String newValue = FileField.getStringRepresentation(files);

if(oldValue.isPresent() && oldValue.get().equals(newValue)) {
return Optional.empty();
}

entry.setField(FieldName.FILE, newValue);
return Optional.of(new FieldChange(entry, FieldName.FILE, oldValue.orElse(""), newValue));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public List<FieldChange> cleanup(BibEntry entry) {
}

if (changed) {
Optional<FieldChange> change = typedEntry.setFiles(newFileList);
Optional<FieldChange> change = entry.setFiles(newFileList);
if(change.isPresent()) {
return Collections.singletonList(change.get());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public List<FieldChange> cleanup(BibEntry entry) {
}

if (changed) {
Optional<FieldChange> change = typedEntry.setFiles(newFileList);
Optional<FieldChange> change = entry.setFiles(newFileList);
if(change.isPresent()) {
return Collections.singletonList(change.get());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public List<FieldChange> cleanup(BibEntry entry) {
}
}
if (changed) {
Optional<FieldChange> change = typedEntry.setFiles(newFileList);
Optional<FieldChange> change = entry.setFiles(newFileList);
//we put an undo of the field content here
//the file is not being renamed back, which leads to inconsistencies
//if we put a null undo object here, the change by "doMakePathsRelative" would overwrite the field value nevertheless.
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/net/sf/jabref/logic/importer/fetcher/ArXiv.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import net.sf.jabref.logic.TypedBibEntry;
import net.sf.jabref.logic.help.HelpFile;
import net.sf.jabref.logic.importer.FetcherException;
import net.sf.jabref.logic.importer.FulltextFetcher;
Expand All @@ -26,7 +25,6 @@
import net.sf.jabref.logic.importer.util.OAI2Handler;
import net.sf.jabref.logic.util.DOI;
import net.sf.jabref.logic.util.io.XMLUtil;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.BibtexEntryTypes;
import net.sf.jabref.model.entry.FieldName;
Expand Down Expand Up @@ -345,10 +343,9 @@ public BibEntry toBibEntry(Character keywordDelimiter) {
abstractText.ifPresent(abstractContent -> bibEntry.setField(FieldName.ABSTRACT, abstractContent));
getDate().ifPresent(date -> bibEntry.setField(FieldName.DATE, date));
primaryCategory.ifPresent(category -> bibEntry.setField(FieldName.EPRINTCLASS, category));
journalReferenceText.ifPresent(journal -> bibEntry.setField(FieldName.JOURNALTITLE, journal));
getPdfUrl().ifPresent(url -> (new TypedBibEntry(bibEntry, BibDatabaseMode.BIBLATEX))
journalReferenceText.ifPresent(journal -> bibEntry.setField(FieldName.JOURNAL, journal));
getPdfUrl().ifPresent(url -> bibEntry
.setFiles(Collections.singletonList(new ParsedFileField("online", url, "PDF"))));

return bibEntry;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
package net.sf.jabref.logic.integrity;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Collectors;

import net.sf.jabref.logic.integrity.IntegrityCheck.Checker;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.EntryConverter;
import net.sf.jabref.model.entry.FieldName;

public class NoBibtexFieldChecker implements Checker {

/**
* BibLaTeX package documentation (Section 2.1.1):
* The title of the periodical is given in the journaltitle field.
*/
@Override
public List<IntegrityMessage> check(BibEntry entry) {
Optional<String> value = entry.getField(FieldName.JOURNALTITLE);

//BibTeX
if (!value.isPresent()) {
return Collections.emptyList();
}
else {
return Collections.singletonList(
new IntegrityMessage(Localization.lang("BibLaTeX field only"), entry, FieldName.JOURNALTITLE));
}
SortedSet<String> allBibLaTeXOnlyFields = new TreeSet<>();
allBibLaTeXOnlyFields.addAll(EntryConverter.FIELD_ALIASES_LTX_TO_TEX.keySet());

// file is both in bibtex and biblatex
allBibLaTeXOnlyFields.remove(FieldName.FILE);

// this exists in BibLaTeX only (and is no aliassed field)
allBibLaTeXOnlyFields.add(FieldName.JOURNALSUBTITLE);

return entry.getFieldNames().stream()
.filter(name -> allBibLaTeXOnlyFields.contains(name))
.map(name -> new IntegrityMessage(Localization.lang("BibLaTeX field only"), entry, name)).collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static BibEntry convert(MSBibEntry entry) {
}

if (entry.journalName != null) {
fieldValues.put(FieldName.JOURNALTITLE, entry.journalName);
fieldValues.put(FieldName.JOURNAL, entry.journalName);
}
if (entry.month != null) {
Month month = MonthUtil.getMonth(entry.month);
Expand Down
32 changes: 24 additions & 8 deletions src/main/java/net/sf/jabref/model/entry/BibEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,21 +404,24 @@ public Optional<String> getFieldOrAliasLatexFree(String name) {
* <p>
* The following aliases are considered (old bibtex <-> new biblatex) based
* on the BibLatex documentation, chapter 2.2.5:<br>
* address <-> location <br>
* annote <-> annotation <br>
* archiveprefix <-> eprinttype <br>
* journal <-> journaltitle <br>
* key <-> sortkey <br>
* pdf <-> file <br
* primaryclass <-> eprintclass <br>
* school <-> institution <br>
* address <-> location <br>
* annote <-> annotation <br>
* archiveprefix <-> eprinttype <br>
* journal <-> journaltitle <br>
* key <-> sortkey <br>
* pdf <-> file <br
* primaryclass <-> eprintclass <br>
* school <-> institution <br>
* These work bidirectional. <br>
* </p>
*
* <p>
* Special attention is paid to dates: (see the BibLatex documentation,
* chapter 2.3.8)
* The fields 'year' and 'month' are used if the 'date'
* field is empty. Conversely, getFieldOrAlias("year") also tries to
* extract the year from the 'date' field (analogously for 'month').
* </p>
*/
public Optional<String> getFieldOrAlias(String name) {
return genericGetFieldOrAlias(name, this::getField);
Expand Down Expand Up @@ -824,4 +827,17 @@ public Optional<String> getLatexFreeField(String name) {
return Optional.of(latexFreeField);
}
}

public Optional<FieldChange> setFiles(List<ParsedFileField> files) {
Optional<String> oldValue = this.getField(FieldName.FILE);
String newValue = FileField.getStringRepresentation(files);

if (oldValue.isPresent() && oldValue.get().equals(newValue)) {
return Optional.empty();
}

this.setField(FieldName.FILE, newValue);
return Optional.of(new FieldChange(this, FieldName.FILE, oldValue.orElse(""), newValue));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/**
* This class defines entry types for BibLatex support.
* @see http://mirrors.concertpass.com/tex-archive/macros/latex/contrib/biblatex/doc/biblatex.pdf
* @see <a href="http://mirrors.concertpass.com/tex-archive/macros/latex/contrib/biblatex/doc/biblatex.pdf">biblatex documentation</a>
*/
public class BibLatexEntryTypes {

Expand All @@ -19,7 +19,8 @@ public class BibLatexEntryTypes {
FieldName.EPRINT, FieldName.EPRINTCLASS, FieldName.EPRINTTYPE, FieldName.URL, FieldName.URLDATE));

{
addAllRequired(FieldName.AUTHOR, FieldName.TITLE, FieldName.JOURNALTITLE,
addAllRequired(FieldName.AUTHOR, FieldName.TITLE,
FieldName.orFields(FieldName.JOURNAL, FieldName.JOURNALTITLE),
FieldName.orFields(FieldName.YEAR, FieldName.DATE));
addAllOptional(FieldName.TRANSLATOR, FieldName.ANNOTATOR, FieldName.COMMENTATOR, FieldName.SUBTITLE,
FieldName.TITLEADDON, FieldName.EDITOR, FieldName.EDITORA, FieldName.EDITORB, FieldName.EDITORC,
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/net/sf/jabref/model/entry/EntryConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
* Converts Entry models from BibTex to BibLaTex and back.
*/
public class EntryConverter {
// BibTex to BibLatex

// BibTeX to BibLaTeX
public static Map<String, String> FIELD_ALIASES_TEX_TO_LTX;
// BibLatex to BibTex

// BibLaTeX to BibTeX
public static Map<String, String> FIELD_ALIASES_LTX_TO_TEX;

// All aliases
public static Map<String, String> FIELD_ALIASES;

Expand All @@ -36,4 +39,5 @@ public class EntryConverter {
FIELD_ALIASES.putAll(EntryConverter.FIELD_ALIASES_TEX_TO_LTX);
FIELD_ALIASES.putAll(EntryConverter.FIELD_ALIASES_LTX_TO_TEX);
}

}
11 changes: 11 additions & 0 deletions src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,17 @@ public void cleanupLatexMergesTwoLatexMathEnvironments() {
Assert.assertEquals(Optional.of("$\\alpha\\beta$"), entry.getField("title"));
}

@Test
public void convertToBiblatexMovesAddressToLocation() {
CleanupPreset preset = new CleanupPreset(CleanupPreset.CleanupStep.CONVERT_TO_BIBLATEX);
BibEntry entry = new BibEntry();
entry.setField("address", "test");

worker.cleanup(preset, entry);
Assert.assertEquals(Optional.empty(), entry.getField("address"));
Assert.assertEquals(Optional.of("test"), entry.getField("location"));
}

@Test
public void convertToBiblatexMovesJournalToJournalTitle() {
CleanupPreset preset = new CleanupPreset(CleanupPreset.CleanupStep.CONVERT_TO_BIBLATEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void searchEntryByOldId() throws Exception {
expected.setField("eprintclass", "hep-ex");
expected.setField("keywords", "hep-ex");
expected.setField("doi", "10.1140/epjc/s2003-01326-x");
expected.setField("journaltitle", "Eur.Phys.J.C31:17-29,2003");
expected.setField("journal", "Eur.Phys.J.C31:17-29,2003");

assertEquals(Optional.of(expected), finder.performSearchById("hep-ex/0307015"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void testImportEntries() throws IOException, URISyntaxException {
assertEquals(Optional.of("2006"), entry.getField("date"));
assertEquals(Optional.of("Effect of immobilization on catalytic characteristics"),
entry.getField("indextitle"));
assertEquals(Optional.of("#jomch#"), entry.getField("journaltitle"));
assertEquals(Optional.of("#jomch#"), entry.getField("journal"));
assertEquals(Optional.of("13"), entry.getField("number"));
assertEquals(Optional.of("3027-3036"), entry.getField("pages"));
assertEquals(Optional
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package net.sf.jabref.logic.integrity;

import java.util.Collections;

import net.sf.jabref.model.entry.BibEntry;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;


public class NoBibTexFieldCheckerTest {

private NoBibtexFieldChecker checker = new NoBibtexFieldChecker();

@Test
public void addressIsNotRecognizedAsBibLaTeXOnlyField() {
BibEntry entry = new BibEntry();
entry.setField("address", "test");
assertEquals(Collections.emptyList(), checker.check(entry));
}

@Test
public void journalIsNotRecognizedAsBibLaTeXOnlyField() {
BibEntry entry = new BibEntry();
entry.setField("journal", "test");
assertEquals(Collections.emptyList(), checker.check(entry));
}

@Test
public void journaltitleIsRecognizedAsBibLaTeXOnlyField() {
BibEntry entry = new BibEntry();
entry.setField("journaltitle", "test");
assertNotEquals(Collections.emptyList(), checker.check(entry));
}

@Test
public void locationIsRecognizedAsBibLaTeXOnlyField() {
BibEntry entry = new BibEntry();
entry.setField("location", "test");
assertNotEquals(Collections.emptyList(), checker.check(entry));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ @article{Orlowski;2011
publisher = {Oficyna Wydawnicza Politechniki Wrocławskiej},
pages = {99--108},
doi = {10.13140/2.1.3259.2169},
journaltitle = {Information Systems Architecture and Technology: Service Oriented Networked Systems},
journal = {Information Systems Architecture and Technology: Service Oriented Networked Systems},
}

@Comment{jabref-meta: databaseType:biblatex;}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ @article{aksin
title = {Effect of immobilization on catalytic characteristics of
saturated {Pd-N}-heterocyclic carbenes in {Mizoroki-Heck}
reactions},
journaltitle = jomch,
journal = jomch,
date = 2006,
volume = 691,
number = 13,
pages = {3027-3036},
indextitle = {Effect of immobilization on catalytic characteristics},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@book{raey,
author = {5},
journaltitle = {Wirtschaftsinformatik},
journal = {Wirtschaftsinformatik},
keywords = {software development processes; agile software development environments; time-to-market; Extreme Programming; Crystal methods family; Adaptive Software Development},
language = {english},
lccn = {0937-6429},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@book{raey,
issn = {0937-6429},
journaltitle = {Wirtschaftsinformatik},
journal = {Wirtschaftsinformatik},
keywords = {software development processes; agile software development environments; time-to-market; Extreme Programming; Crystal methods family; Adaptive Software Development},
language = {english},
issue = {3},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
% Encoding: UTF-8
@techreport{,
journaltitle = {Wirtschaftsinformatik},
journal = {Wirtschaftsinformatik},
keywords = {software development processes; agile software development environments; time-to-market; Extreme Programming; Crystal methods family; Adaptive Software Development},
language = {english},
mrnumber = {0937-6429},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
% Encoding: UTF-8
@online{,
journaltitle = {Wirtschaftsinformatik},
journal = {Wirtschaftsinformatik},
keywords = {software development processes; agile software development environments; time-to-market; Extreme Programming; Crystal methods family; Adaptive Software Development},
language = {english},
mrnumber = {0937-6429},
Expand Down
Loading

0 comments on commit 7e57775

Please sign in to comment.