Skip to content

Commit

Permalink
Feature branch for export version fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bjosel committed Jan 18, 2024
1 parent 1f9e10c commit 14935c6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 21 deletions.
70 changes: 56 additions & 14 deletions src/main/java/edu/harvard/iq/dataverse/FileDownloadServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,16 @@ 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);
}
Expand All @@ -401,9 +411,6 @@ public void downloadCitationXML(FileMetadata fileMetadata, Dataset dataset, bool
} else {
citation= new DataCitation(fileMetadata, direct);
}
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
response.setContentType("text/xml");
String fileNameString;
if (fileMetadata == null || fileMetadata.getLabel() == null) {
// Dataset-level citation:
Expand All @@ -412,14 +419,21 @@ 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) {

}
}

Expand All @@ -429,6 +443,16 @@ public void downloadDatasetCitationRIS(Dataset dataset) {

}

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);
}
Expand All @@ -445,10 +469,6 @@ public void downloadCitationRIS(FileMetadata fileMetadata, Dataset dataset, bool
citation= new DataCitation(fileMetadata, direct);
}

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:
Expand All @@ -457,6 +477,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 @@ -479,6 +507,16 @@ public void downloadDatasetCitationBibtex(Dataset dataset) {

}

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);
}
Expand All @@ -494,12 +532,6 @@ 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();

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

String fileNameString;
if (fileMetadata == null || fileMetadata.getLabel() == null) {
Expand All @@ -509,6 +541,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
8 changes: 4 additions & 4 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 All @@ -49,4 +49,4 @@
</div>
</div>
</div>
</ui:composition>
</ui:composition>
6 changes: 3 additions & 3 deletions src/main/webapp/file.xhtml
Original file line number Diff line number Diff line change
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 14935c6

Please sign in to comment.