Skip to content

Commit

Permalink
Patch to fix export version bug merged.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjosel committed Oct 10, 2023
1 parent 24a807e commit cd6f708
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 29 deletions.
86 changes: 64 additions & 22 deletions src/main/java/edu/harvard/iq/dataverse/FileDownloadServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,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 @@ -358,15 +368,12 @@ public void downloadDirectDatafileCitationXML(FileMetadata fileMetadata) {
}

public void downloadCitationXML(FileMetadata fileMetadata, Dataset dataset, boolean direct) {
DataCitation citation=null;
DataCitation citation=null;
if (dataset != null){
citation = new DataCitation(dataset.getLatestVersion());
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");
String fileNameString;
if (fileMetadata == null || fileMetadata.getLabel() == null) {
// Dataset-level citation:
Expand All @@ -375,14 +382,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 @@ -392,6 +406,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 @@ -401,17 +425,13 @@ public void downloadDirectDatafileCitationRIS(FileMetadata fileMetadata) {
}

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

String fileNameString;
if (fileMetadata == null || fileMetadata.getLabel() == null) {
// Dataset-level citation:
Expand All @@ -420,6 +440,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 @@ -431,7 +459,7 @@ public void downloadCitationRIS(FileMetadata fileMetadata, Dataset dataset, bool

}
}

private String getFileNameFromPid(GlobalId id) {
return id.asString();
}
Expand All @@ -442,6 +470,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 @@ -451,19 +489,13 @@ public void downloadDirectDatafileCitationBibtex(FileMetadata fileMetadata) {
}

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


String fileNameString;
if (fileMetadata == null || fileMetadata.getLabel() == null) {
// Dataset-level citation:
Expand All @@ -472,6 +504,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,17 +33,17 @@
</button>
<ul class="dropdown-menu">
<li>
<a jsf:id="endNoteLink" jsf:action="#{DatasetPage.fileDownloadService.downloadDatasetCitationXML(DatasetPage.dataset)}" >
<a jsf:id="endNoteLink" jsf:action="#{DatasetPage.fileDownloadService.downloadDatasetCitationXML(DatasetPage.workingVersion)}" >
#{bundle['dataset.cite.downloadBtn.xml']}
</a>
</li>
<li>
<a jsf:id="risLink" jsf:actionListener="#{DatasetPage.fileDownloadService.downloadDatasetCitationRIS(DatasetPage.dataset)}">
<a jsf:id="risLink" jsf:actionListener="#{DatasetPage.fileDownloadService.downloadDatasetCitationRIS(DatasetPage.workingVersion)}">
#{bundle['dataset.cite.downloadBtn.ris']}
</a>
</li>
<li>
<a jsf:id="bibLink" jsf:actionListener="#{DatasetPage.fileDownloadService.downloadDatasetCitationBibtex(DatasetPage.dataset)}" target="_blank">
<a jsf:id="bibLink" jsf:actionListener="#{DatasetPage.fileDownloadService.downloadDatasetCitationBibtex(DatasetPage.workingVersion)}" target="_blank">
#{bundle['dataset.cite.downloadBtn.bib']}
</a>
</li>
Expand All @@ -55,4 +55,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 @@ -156,17 +156,17 @@
</button>
<ul class="dropdown-menu">
<li>
<a jsf:id="endNoteLink" jsf:action="#{FilePage.fileDownloadService.downloadDatasetCitationXML(FilePage.fileMetadata.datasetVersion.dataset)}" >
<a jsf:id="endNoteLink" jsf:action="#{FilePage.fileDownloadService.downloadDatasetCitationXML(FilePage.fileMetadata.datasetVersion)}" >
#{bundle['dataset.cite.downloadBtn.xml']}
</a>
</li>
<li>
<a jsf:id="risLink" jsf:actionListener="#{FilePage.fileDownloadService.downloadDatasetCitationRIS(FilePage.fileMetadata.datasetVersion.dataset)}">
<a jsf:id="risLink" jsf:actionListener="#{FilePage.fileDownloadService.downloadDatasetCitationRIS(FilePage.fileMetadata.datasetVersion)}">
#{bundle['dataset.cite.downloadBtn.ris']}
</a>
</li>
<li>
<a jsf:id="bibLink" jsf:actionListener="#{FilePage.fileDownloadService.downloadDatasetCitationBibtex(FilePage.fileMetadata.datasetVersion.dataset)}" target="_blank">
<a jsf:id="bibLink" jsf:actionListener="#{FilePage.fileDownloadService.downloadDatasetCitationBibtex(FilePage.fileMetadata.datasetVersion)}" target="_blank">
#{bundle['dataset.cite.downloadBtn.bib']}
</a>
</li>
Expand Down

0 comments on commit cd6f708

Please sign in to comment.