Skip to content

Commit

Permalink
Merge pull request #3020 from bmckinney/feature/1013-add-bibtex-support
Browse files Browse the repository at this point in the history
Feature/1013 add bibtex support
  • Loading branch information
scolapasta committed Mar 24, 2016
2 parents 7d6b946 + a578786 commit 0c13184
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/main/java/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ dataset.cite.standards.tip=If you use these data, please add this citation to yo
dataset.cite.downloadBtn=Download Citation
dataset.cite.downloadBtn.xml=EndNote XML
dataset.cite.downloadBtn.ris=RIS Format
dataset.cite.downloadBtn.bib=BibTeX Format
dataset.create.authenticatedUsersOnly=Only authenticated users can create datasets.
dataset.deaccession.reason=Deaccession Reason
dataset.beAccessedAt=The dataset can now be accessed at:
Expand Down
1 change: 1 addition & 0 deletions src/main/java/Bundle_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ dataset.cite.whyCite=\u4e3a\u4ec0\u4e48\u8981\u5f15\u7528\uff1f
dataset.cite.downloadBtn=\u4e0b\u8f7d\u5f15\u7528
dataset.cite.downloadBtn.xml=EndNote XML
dataset.cite.downloadBtn.ris=RIS\u683c\u5f0f
dataset.cite.downloadBtn.bib=BibTeX\u683c\u5f0f
dataset.deaccession.reason=Deaccession\u539f\u56e0\uff1a
dataset.beAccessedAt=\u8be5\u6570\u636e\u96c6\u73b0\u5728\u53ef\u4ee5\u5728{0}\u8bbf\u95ee
dataset.noTemplate.label=\u6ca1\u6709\u6a21\u677f - \u6e05\u6670\u7684\u9ed8\u8ba4\u503c
Expand Down
39 changes: 38 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3311,7 +3311,44 @@ public void downloadCitationRIS(FileMetadata fileMetadata) {

}
}


public void downloadDatasetCitationBibtex() {

downloadCitationBibtex(null);

}

public void downloadDatafileCitationBibtex(FileMetadata fileMetadata) {
downloadCitationBibtex(fileMetadata);
}

public void downloadCitationBibtex(FileMetadata fileMetadata) {

String bibFormatDowload = datasetService.createCitationBibtex(workingVersion, fileMetadata);
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
response.setContentType("application/download");

String fileNameString = "";
if (fileMetadata == null || fileMetadata.getLabel() == null) {
// Dataset-level citation:
fileNameString = "attachment;filename=" + getFileNameDOI() + ".bib";
} else {
// Datafile-level citation:
fileNameString = "attachment;filename=" + getFileNameDOI() + "-" + fileMetadata.getLabel().replaceAll("\\.tab$", ".bib");
}
response.setHeader("Content-Disposition", fileNameString);

try {
ServletOutputStream out = response.getOutputStream();
out.write(bibFormatDowload.getBytes());
out.flush();
ctx.responseComplete();
} catch (Exception e) {

}
}

public String getDatasetPublishCustomText(){
String datasetPublishCustomText = settingsService.getValueForKey(SettingsServiceBean.Key.DatasetPublishPopupCustomText);
if( datasetPublishCustomText!= null && !datasetPublishCustomText.isEmpty()){
Expand Down
32 changes: 31 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/DatasetServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public List<Dataset> findAll() {

/**
* For docs, see the equivalent method on the DataverseServiceBean.
* @see DataverseServiceBean#findAllOrSubset(long, long)
* @see DataverseServiceBean#findAllOrSubset(long, long, boolean)
*/
public List<Dataset> findAllOrSubset(long numPartitions, long partitionId, boolean skipIndexed) {
if (numPartitions < 1) {
Expand Down Expand Up @@ -265,6 +265,36 @@ public String createCitationRIS(DatasetVersion version, FileMetadata fileMetadat
return retString;
}

public String createCitationBibtex(DatasetVersion version) {
return createCitationBibtex(version, null);
}

public String createCitationBibtex(DatasetVersion version, FileMetadata fileMetadata) {
String publisher = version.getRootDataverseNameforCitation();
List<DatasetAuthor> authorList = version.getDatasetAuthors();
List<String> authorDisplayList = new ArrayList<>();

for (DatasetAuthor author : authorList) {
authorDisplayList.add(author.getName().getDisplayValue());
}

String retString = "@data{";
retString += version.getDataset().getIdentifier() + "_" + version.getVersionYear() + "," + "\r\n";
retString += "author = {";
retString += String.join("; ", authorDisplayList);
retString += "}," + "\r\n";
retString += "publisher = {" + publisher + "}," + "\r\n";
retString += "title = {" + version.getTitle() + "}," + "\r\n";
retString += "year = {" + version.getVersionYear() + "}," + "\r\n";
retString += "doi = {" + version.getDataset().getAuthority() +
version.getDataset().getDoiSeparator() +
version.getDataset().getIdentifier() + "}," + "\r\n";
retString += "url = {" + version.getDataset().getPersistentURL() + "}" + "\r\n";
retString += "}";

return retString;
}

private XMLOutputFactory xmlOutputFactory = null;

public String createCitationXML(DatasetVersion datasetVersion, FileMetadata fileMetadata) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/api/Access.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ public BundleDownloadInstance datafileBundle(@PathParam("fileId") Long fileId, @

downloadInstance.setFileCitationEndNote(datasetService.createCitationXML(datasetVersion, fileMetadata));
downloadInstance.setFileCitationRIS(datasetService.createCitationRIS(datasetVersion, fileMetadata));

downloadInstance.setFileCitationBibtex(datasetService.createCitationBibtex(datasetVersion, fileMetadata));

ByteArrayOutputStream outStream = null;
outStream = new ByteArrayOutputStream();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

package edu.harvard.iq.dataverse.api;

import java.util.List;

/**
*
* @author Leonid Andreev
Expand All @@ -19,6 +17,7 @@ public class BundleDownloadInstance {
private String fileCitationEndNote = "";
private String fileCitationRIS = "";
private String fileDDIXML = "";
private String fileCitationBibtex = "";

public BundleDownloadInstance() {

Expand Down Expand Up @@ -59,4 +58,13 @@ public String getFileDDIXML() {
public void setFileDDIXML(String fileDDIXML) {
this.fileDDIXML = fileDDIXML;
}

public String getFileCitationBibtex() {
return fileCitationBibtex;
}

public void setFileCitationBibtex(String fileCitationBibtex) {
this.fileCitationBibtex = fileCitationBibtex;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ public void writeTo(BundleDownloadInstance di, Class<?> clazz, Type type, Annota
zout.closeEntry();
}

if (di.getFileCitationBibtex() != null) {
e = new ZipEntry(fileName.replaceAll("\\.tab$","citation-bib.bib"));

zout.putNextEntry(e);
zout.write(di.getFileCitationBibtex().getBytes());
zout.closeEntry();
}

zout.close();
return;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/webapp/dataset.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@
#{bundle['dataset.cite.downloadBtn.ris']}
</a>
</li>
<li>
<a jsf:id="bibLink" jsf:actionListener="#{DatasetPage.downloadDatasetCitationBibtex()}">
#{bundle['dataset.cite.downloadBtn.bib']}
</a>
</li>
</ul>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions src/main/webapp/filesFragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,12 @@
<h:outputText value="#{bundle['dataset.cite.downloadBtn.xml']}" />
</h:commandLink>
</li>
<li>
<h:commandLink id="bibLinkFile" action="#{DatasetPage.downloadDatafileCitationBibtex(fileMetadata)}">
<h:outputText value="#{bundle['dataset.cite.downloadBtn.bib']}" />
</h:commandLink>
</li>

</ul>
</li>
</ul>
Expand Down

0 comments on commit 0c13184

Please sign in to comment.