Skip to content

Commit

Permalink
Merge pull request #9705 from okaradeniz/8952_citation_version_fix
Browse files Browse the repository at this point in the history
Prevent "DRAFT" from appearing in citation file downloaded from a published dataset
  • Loading branch information
jp-tosca authored Apr 11, 2024
2 parents 382ccbb + 7992738 commit a0d7cd2
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 59 deletions.
114 changes: 64 additions & 50 deletions src/main/java/edu/harvard/iq/dataverse/FileDownloadServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,28 +382,26 @@ public void explore(GuestbookResponse guestbookResponse, FileMetadata fmd, Exter
}
}

public void downloadDatasetCitationXML(Dataset dataset) {
downloadCitationXML(null, dataset, false);
public void downloadDatasetCitationXML(DatasetVersion version) {
// DatasetVersion-level citation:
DataCitation citation=null;
citation = new DataCitation(version);
String fileNameString;
fileNameString = "attachment;filename=" + getFileNameFromPid(citation.getPersistentId()) + ".xml";
downloadXML(citation, fileNameString);
}

public void downloadDatafileCitationXML(FileMetadata fileMetadata) {
downloadCitationXML(fileMetadata, null, false);
downloadCitationXML(fileMetadata, false);
}

public void downloadDirectDatafileCitationXML(FileMetadata fileMetadata) {
downloadCitationXML(fileMetadata, null, true);
downloadCitationXML(fileMetadata, true);
}

public void downloadCitationXML(FileMetadata fileMetadata, Dataset dataset, boolean direct) {
DataCitation citation=null;
if (dataset != null){
citation = new DataCitation(dataset.getLatestVersion());
} else {
citation= new DataCitation(fileMetadata, direct);
}
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
response.setContentType("text/xml");
public void downloadCitationXML(FileMetadata fileMetadata, boolean direct) {
DataCitation citation=null;
citation= new DataCitation(fileMetadata, direct);
String fileNameString;
if (fileMetadata == null || fileMetadata.getLabel() == null) {
// Dataset-level citation:
Expand All @@ -412,43 +410,46 @@ public void downloadCitationXML(FileMetadata fileMetadata, Dataset dataset, bool
// Datafile-level citation:
fileNameString = "attachment;filename=" + getFileNameFromPid(citation.getPersistentId()) + "-" + FileUtil.getCiteDataFileFilename(citation.getFileTitle(), FileUtil.FileCitationExtension.ENDNOTE);
}
downloadXML(citation, fileNameString);
}

public void downloadXML(DataCitation citation, String fileNameString) {
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
response.setContentType("text/xml");
response.setHeader("Content-Disposition", fileNameString);

try {
ServletOutputStream out = response.getOutputStream();
citation.writeAsEndNoteCitation(out);
out.flush();
ctx.responseComplete();
} catch (IOException e) {

}
}

public void downloadDatasetCitationRIS(Dataset dataset) {

downloadCitationRIS(null, dataset, false);
public void downloadDatasetCitationRIS(DatasetVersion version) {
// DatasetVersion-level citation:
DataCitation citation=null;
citation = new DataCitation(version);

String fileNameString;
fileNameString = "attachment;filename=" + getFileNameFromPid(citation.getPersistentId()) + ".ris";
downloadRIS(citation, fileNameString);
}

public void downloadDatafileCitationRIS(FileMetadata fileMetadata) {
downloadCitationRIS(fileMetadata, null, false);
downloadCitationRIS(fileMetadata, false);
}

public void downloadDirectDatafileCitationRIS(FileMetadata fileMetadata) {
downloadCitationRIS(fileMetadata, null, true);
downloadCitationRIS(fileMetadata, true);
}

public void downloadCitationRIS(FileMetadata fileMetadata, Dataset dataset, boolean direct) {
DataCitation citation=null;
if (dataset != null){
citation = new DataCitation(dataset.getLatestVersion());
} else {
citation= new DataCitation(fileMetadata, direct);
}

FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
response.setContentType("application/download");

public void downloadCitationRIS(FileMetadata fileMetadata, boolean direct) {
DataCitation citation=null;
citation= new DataCitation(fileMetadata, direct);

String fileNameString;
if (fileMetadata == null || fileMetadata.getLabel() == null) {
// Dataset-level citation:
Expand All @@ -457,6 +458,14 @@ public void downloadCitationRIS(FileMetadata fileMetadata, Dataset dataset, bool
// Datafile-level citation:
fileNameString = "attachment;filename=" + getFileNameFromPid(citation.getPersistentId()) + "-" + FileUtil.getCiteDataFileFilename(citation.getFileTitle(), FileUtil.FileCitationExtension.RIS);
}
downloadRIS(citation, fileNameString);
}

public void downloadRIS(DataCitation citation, String fileNameString) {
//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.setHeader("Content-Disposition", fileNameString);

try {
Expand All @@ -468,38 +477,33 @@ public void downloadCitationRIS(FileMetadata fileMetadata, Dataset dataset, bool

}
}

private String getFileNameFromPid(GlobalId id) {
return id.asString();
}

public void downloadDatasetCitationBibtex(Dataset dataset) {

downloadCitationBibtex(null, dataset, false);
public void downloadDatasetCitationBibtex(DatasetVersion version) {
// DatasetVersion-level citation:
DataCitation citation=null;
citation = new DataCitation(version);

String fileNameString;
fileNameString = "inline;filename=" + getFileNameFromPid(citation.getPersistentId()) + ".bib";
downloadBibtex(citation, fileNameString);
}

public void downloadDatafileCitationBibtex(FileMetadata fileMetadata) {
downloadCitationBibtex(fileMetadata, null, false);
downloadCitationBibtex(fileMetadata, false);
}

public void downloadDirectDatafileCitationBibtex(FileMetadata fileMetadata) {
downloadCitationBibtex(fileMetadata, null, true);
downloadCitationBibtex(fileMetadata, true);
}

public void downloadCitationBibtex(FileMetadata fileMetadata, Dataset dataset, boolean direct) {
DataCitation citation=null;
if (dataset != null){
citation = new DataCitation(dataset.getLatestVersion());
} 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();

//Fix for 6029 FireFox was failing to parse it when content type was set to json
response.setContentType("text/plain");
public void downloadCitationBibtex(FileMetadata fileMetadata, boolean direct) {
DataCitation citation=null;
citation= new DataCitation(fileMetadata, direct);

String fileNameString;
if (fileMetadata == null || fileMetadata.getLabel() == null) {
Expand All @@ -509,6 +513,16 @@ public void downloadCitationBibtex(FileMetadata fileMetadata, Dataset dataset, b
// Datafile-level citation:
fileNameString = "inline;filename=" + getFileNameFromPid(citation.getPersistentId()) + "-" + FileUtil.getCiteDataFileFilename(citation.getFileTitle(), FileUtil.FileCitationExtension.BIBTEX);
}
downloadBibtex(citation, fileNameString);
}

public void downloadBibtex(DataCitation citation, String fileNameString) {
//SEK 12/3/2018 changing this to open the json in a new tab.
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();

//Fix for 6029 FireFox was failing to parse it when content type was set to json
response.setContentType("text/plain");
response.setHeader("Content-Disposition", fileNameString);

try {
Expand Down
6 changes: 3 additions & 3 deletions src/main/webapp/dataset-citation.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
</button>
<ul class="dropdown-menu">
<li>
<h:commandLink id="endNoteLink" value="#{bundle['dataset.cite.downloadBtn.xml']}" action="#{DatasetPage.fileDownloadService.downloadDatasetCitationXML(DatasetPage.dataset)}"/>
<h:commandLink id="endNoteLink" value="#{bundle['dataset.cite.downloadBtn.xml']}" action="#{DatasetPage.fileDownloadService.downloadDatasetCitationXML(DatasetPage.workingVersion)}"/>
</li>
<li>
<h:commandLink id="risLink" value="#{bundle['dataset.cite.downloadBtn.ris']}" action="#{DatasetPage.fileDownloadService.downloadDatasetCitationRIS(DatasetPage.dataset)}"/>
<h:commandLink id="risLink" value="#{bundle['dataset.cite.downloadBtn.ris']}" action="#{DatasetPage.fileDownloadService.downloadDatasetCitationRIS(DatasetPage.workingVersion)}"/>
</li>
<li>
<h:commandLink id="bibLink" value="#{bundle['dataset.cite.downloadBtn.bib']}" action="#{DatasetPage.fileDownloadService.downloadDatasetCitationBibtex(DatasetPage.dataset)}" target="_blank"/>
<h:commandLink id="bibLink" value="#{bundle['dataset.cite.downloadBtn.bib']}" action="#{DatasetPage.fileDownloadService.downloadDatasetCitationBibtex(DatasetPage.workingVersion)}" target="_blank"/>
</li>
</ul>
</div>
Expand Down
12 changes: 6 additions & 6 deletions src/main/webapp/file.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,19 @@
<li>
<h:commandLink
id="endNoteLink-2" value="#{bundle['dataset.cite.downloadBtn.xml']}"
action="#{FilePage.fileDownloadService.downloadCitationXML(FilePage.fileMetadata, null, FilePage.fileMetadata.dataFile.isIdentifierRegistered())}"
action="#{FilePage.fileDownloadService.downloadCitationXML(FilePage.fileMetadata, FilePage.fileMetadata.dataFile.isIdentifierRegistered())}"
/>
</li>
<li>
<h:commandLink
id="risLink-2" value="#{bundle['dataset.cite.downloadBtn.ris']}"
action="#{FilePage.fileDownloadService.downloadCitationRIS(FilePage.fileMetadata, null, FilePage.fileMetadata.dataFile.isIdentifierRegistered())}"
action="#{FilePage.fileDownloadService.downloadCitationRIS(FilePage.fileMetadata, FilePage.fileMetadata.dataFile.isIdentifierRegistered())}"
/>
</li>
<li>
<h:commandLink
id="bibLink-2" value="#{bundle['dataset.cite.downloadBtn.bib']}" target="_blank"
action="#{FilePage.fileDownloadService.downloadCitationBibtex(FilePage.fileMetadata, null, FilePage.fileMetadata.dataFile.isIdentifierRegistered())}"
action="#{FilePage.fileDownloadService.downloadCitationBibtex(FilePage.fileMetadata, FilePage.fileMetadata.dataFile.isIdentifierRegistered())}"
/>
</li>
</ul>
Expand Down Expand Up @@ -161,19 +161,19 @@
<li>
<h:commandLink
id="endNoteLink" value="#{bundle['dataset.cite.downloadBtn.xml']}"
action="#{FilePage.fileDownloadService.downloadDatasetCitationXML(FilePage.fileMetadata.datasetVersion.dataset)}"
action="#{FilePage.fileDownloadService.downloadDatasetCitationXML(FilePage.fileMetadata.datasetVersion)}"
/>
</li>
<li>
<h:commandLink
id="risLink" value="#{bundle['dataset.cite.downloadBtn.ris']}"
action="#{FilePage.fileDownloadService.downloadDatasetCitationRIS(FilePage.fileMetadata.datasetVersion.dataset)}"
action="#{FilePage.fileDownloadService.downloadDatasetCitationRIS(FilePage.fileMetadata.datasetVersion)}"
/>
</li>
<li>
<h:commandLink
id="bibLink" value="#{bundle['dataset.cite.downloadBtn.bib']}" target="_blank"
action="#{FilePage.fileDownloadService.downloadDatasetCitationBibtex(FilePage.fileMetadata.datasetVersion.dataset)}"
action="#{FilePage.fileDownloadService.downloadDatasetCitationBibtex(FilePage.fileMetadata.datasetVersion)}"
/>
</li>
</ul>
Expand Down

0 comments on commit a0d7cd2

Please sign in to comment.