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

3759 bibtex improvements #5368

Merged
merged 5 commits into from
Dec 6, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/DataCitation.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,17 @@ public void writeAsBibtexCitation(OutputStream os) throws IOException {
out.write(title);
out.write("},\r\n");
}
if(UNF != null){
out.write("UNF = {");
out.write(UNF);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to use getUNF() and UNF in the same block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, just following the pattern wrt title above. I can change it.

out.write("},\r\n");
}
out.write("year = {");
out.write(year);
out.write("},\r\n");
out.write("version = {");
out.write(version);
out.write("},\r\n");
out.write("doi = {");
out.write(persistentId.getAuthority());
out.write("/");
Expand Down Expand Up @@ -313,9 +321,10 @@ public void writeAsRISCitation(OutputStream os) throws IOException {
if (seriesTitle != null) {
out.write("T3 - " + seriesTitle + "\r\n");
}
/* Removing abstract/description per Request from G. King in #3759
if(description!=null) {
out.write("AB - " + flattenHtml(description) + "\r\n");
}
} */
for (String author : authors) {
out.write("AU - " + author + "\r\n");
}
Expand Down Expand Up @@ -498,12 +507,13 @@ private void createEndNoteXML(XMLStreamWriter xmlw) throws XMLStreamException {

xmlw.writeCharacters(sectionString);
xmlw.writeEndElement(); // section

/* Removing abstract/description per Request from G. King in #3759
xmlw.writeStartElement("abstract");
if(description!=null) {
xmlw.writeCharacters(flattenHtml(description));
}
xmlw.writeEndElement(); // abstract
*/

xmlw.writeStartElement("dates");
xmlw.writeStartElement("year");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,18 @@ public void downloadCitationBibtex(FileMetadata fileMetadata, Dataset dataset, b
} else {
citation= new DataCitation(fileMetadata, direct);
}

//SEK 12/3/2018 changing this to open the json in a new tab.
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
response.setContentType("application/download");
response.setContentType("application/json");

String fileNameString;
if (fileMetadata == null || fileMetadata.getLabel() == null) {
// Dataset-level citation:
fileNameString = "attachment;filename=" + getFileNameDOI(citation.getPersistentId()) + ".bib";
fileNameString = "inline;filename=" + getFileNameDOI(citation.getPersistentId()) + ".bib";
} else {
// Datafile-level citation:
fileNameString = "attachment;filename=" + getFileNameDOI(citation.getPersistentId()) + "-" + FileUtil.getCiteDataFileFilename(citation.getFileTitle(), FileUtil.FileCitationExtension.BIBTEX);
fileNameString = "inline;filename=" + getFileNameDOI(citation.getPersistentId()) + "-" + FileUtil.getCiteDataFileFilename(citation.getFileTitle(), FileUtil.FileCitationExtension.BIBTEX);
}
response.setHeader("Content-Disposition", fileNameString);

Expand Down
110 changes: 60 additions & 50 deletions src/test/java/edu/harvard/iq/dataverse/DataCitationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,99 +69,111 @@ public void testWriteAsBibtexCitation() throws ParseException, IOException {
dataCitation.writeAsBibtexCitation(os);
String out = new String(os.toByteArray(), "UTF-8");
assertEquals(
"@data{LK0D1H_1955,\r\n" +
"author = {First Last},\r\n" +
"publisher = {LibraScholar},\r\n" +
"title = {Dataset Title},\r\n" +
"year = {1955},\r\n" +
"doi = {10.5072/FK2/LK0D1H},\r\n" +
"url = {https://doi.org/10.5072/FK2/LK0D1H}\r\n" +
"}\r\n",
out
"@data{LK0D1H_1955,\r\n"
+ "author = {First Last},\r\n"
+ "publisher = {LibraScholar},\r\n"
+ "title = {Dataset Title},\r\n"
+ "year = {1955},\r\n"
+ "version = {V1},\r\n"
+ "doi = {10.5072/FK2/LK0D1H},\r\n"
+ "url = {https://doi.org/10.5072/FK2/LK0D1H}\r\n"
+ "}\r\n",
out
);
}

/**
* Test that bibtex data export contains a closing bracket
*
* @throws ParseException
*/
@Test
public void testToBibtexString() throws ParseException {
DatasetVersion datasetVersion = createATestDatasetVersion(true, true);
DataCitation dataCitation = new DataCitation(datasetVersion);
assertEquals(
"@data{LK0D1H_1955,\r\n" +
"author = {First Last},\r\n" +
"publisher = {LibraScholar},\r\n" +
"title = {Dataset Title},\r\n" +
"year = {1955},\r\n" +
"doi = {10.5072/FK2/LK0D1H},\r\n" +
"url = {https://doi.org/10.5072/FK2/LK0D1H}\r\n" +
"}\r\n",
dataCitation.toBibtexString()
"@data{LK0D1H_1955,\r\n"
+ "author = {First Last},\r\n"
+ "publisher = {LibraScholar},\r\n"
+ "title = {Dataset Title},\r\n"
+ "year = {1955},\r\n"
+ "version = {V1},\r\n"
+ "doi = {10.5072/FK2/LK0D1H},\r\n"
+ "url = {https://doi.org/10.5072/FK2/LK0D1H}\r\n"
+ "}\r\n",
dataCitation.toBibtexString()
);
}

/**
* Test that bibtex data export contains an empty author if no author is specified
* Test that bibtex data export contains an empty author if no author is
* specified
*
* @throws ParseException
*/
@Test
public void testToBibtexString_withoutAuthor() throws ParseException {
DatasetVersion datasetVersion = createATestDatasetVersion(true, false);
DataCitation dataCitation = new DataCitation(datasetVersion);
assertEquals(
"@data{LK0D1H_1955,\r\n" +
"author = {},\r\n" +
"publisher = {LibraScholar},\r\n" +
"title = {Dataset Title},\r\n" +
"year = {1955},\r\n" +
"doi = {10.5072/FK2/LK0D1H},\r\n" +
"url = {https://doi.org/10.5072/FK2/LK0D1H}\r\n" +
"}\r\n",
dataCitation.toBibtexString()
"@data{LK0D1H_1955,\r\n"
+ "author = {},\r\n"
+ "publisher = {LibraScholar},\r\n"
+ "title = {Dataset Title},\r\n"
+ "year = {1955},\r\n"
+ "version = {V1},\r\n"
+ "doi = {10.5072/FK2/LK0D1H},\r\n"
+ "url = {https://doi.org/10.5072/FK2/LK0D1H}\r\n"
+ "}\r\n",
dataCitation.toBibtexString()
);
}

/**
* Test that bibtex data export contains an empty title if no title is specified
* Test that bibtex data export contains an empty title if no title is
* specified
*
* @throws ParseException
*/
@Test
public void testToBibtexString_withoutTitle() throws ParseException {
DatasetVersion datasetVersion = createATestDatasetVersion(false, true);
DataCitation dataCitation = new DataCitation(datasetVersion);
assertEquals(
"@data{LK0D1H_1955,\r\n" +
"author = {First Last},\r\n" +
"publisher = {LibraScholar},\r\n" +
"title = {},\r\n" +
"year = {1955},\r\n" +
"doi = {10.5072/FK2/LK0D1H},\r\n" +
"url = {https://doi.org/10.5072/FK2/LK0D1H}\r\n" +
"}\r\n",
dataCitation.toBibtexString()
"@data{LK0D1H_1955,\r\n"
+ "author = {First Last},\r\n"
+ "publisher = {LibraScholar},\r\n"
+ "title = {},\r\n"
+ "year = {1955},\r\n"
+ "version = {V1},\r\n"
+ "doi = {10.5072/FK2/LK0D1H},\r\n"
+ "url = {https://doi.org/10.5072/FK2/LK0D1H}\r\n"
+ "}\r\n",
dataCitation.toBibtexString()
);
}

/**
* Test that bibtex data export contains an empty author and title if no author, nor title is specified
* Test that bibtex data export contains an empty author and title if no
* author, nor title is specified
*
* @throws ParseException
*/
@Test
public void testToBibtexString_withoutTitleAndAuthor() throws ParseException {
DatasetVersion datasetVersion = createATestDatasetVersion(false, false);
DataCitation dataCitation = new DataCitation(datasetVersion);
assertEquals(
"@data{LK0D1H_1955,\r\n" +
"author = {},\r\n" +
"publisher = {LibraScholar},\r\n" +
"title = {},\r\n" +
"year = {1955},\r\n" +
"doi = {10.5072/FK2/LK0D1H},\r\n" +
"url = {https://doi.org/10.5072/FK2/LK0D1H}\r\n" +
"}\r\n",
dataCitation.toBibtexString()
"@data{LK0D1H_1955,\r\n"
+ "author = {},\r\n"
+ "publisher = {LibraScholar},\r\n"
+ "title = {},\r\n"
+ "year = {1955},\r\n"
+ "version = {V1},\r\n"
+ "doi = {10.5072/FK2/LK0D1H},\r\n"
+ "url = {https://doi.org/10.5072/FK2/LK0D1H}\r\n"
+ "}\r\n",
dataCitation.toBibtexString()
);
}

Expand Down Expand Up @@ -221,7 +233,6 @@ public void testToEndNoteString_withTitleAndAuthor() throws ParseException {
"</contributors>" +
"<titles><title>Dataset Title</title></titles>" +
"<section>1955-11-05</section>" +
"<abstract />" +
"<dates><year>1955</year></dates>" +
"<edition>V1</edition>" +
"<publisher>LibraScholar</publisher>" +
Expand All @@ -247,7 +258,6 @@ public void testToEndNoteString_withoutTitleAndAuthor() throws ParseException {
"<contributors />" +
"<titles><title></title></titles>" +
"<section>1955-11-05</section>" +
"<abstract />" +
"<dates><year>1955</year></dates>" +
"<edition>V1</edition>" +
"<publisher>LibraScholar</publisher>" +
Expand Down