use of edu.harvard.iq.dataverse.authorization.users.ApiToken in project dataverse by IQSS.
the class FileDownloadServiceBean method explore.
/**
* Launch an "explore" tool which is a type of ExternalTool such as
* TwoRavens or Data Explorer. This method may be invoked directly from the
* xhtml if no popup is required (no terms of use, no guestbook, etc.).
*/
public void explore(GuestbookResponse guestbookResponse, FileMetadata fmd, ExternalTool externalTool) {
ApiToken apiToken = null;
User user = session.getUser();
if (user instanceof AuthenticatedUser) {
AuthenticatedUser authenticatedUser = (AuthenticatedUser) user;
apiToken = authService.findApiTokenByUser(authenticatedUser);
}
DataFile dataFile = null;
if (fmd != null) {
dataFile = fmd.getDataFile();
} else {
if (guestbookResponse != null) {
dataFile = guestbookResponse.getDataFile();
}
}
ExternalToolHandler externalToolHandler = new ExternalToolHandler(externalTool, dataFile, apiToken);
// Back when we only had TwoRavens, the downloadType was always "Explore". Now we persist the name of the tool (i.e. "TwoRavens", "Data Explorer", etc.)
guestbookResponse.setDownloadtype(externalTool.getDisplayName());
String toolUrl = externalToolHandler.getToolUrlWithQueryParams();
logger.fine("Exploring with " + toolUrl);
try {
FacesContext.getCurrentInstance().getExternalContext().redirect(toolUrl);
} catch (IOException ex) {
logger.info("Problem exploring with " + toolUrl + " - " + ex);
}
// This is the old logic from TwoRavens, null checks and all.
if (guestbookResponse != null && guestbookResponse.isWriteResponse() && ((fmd != null && fmd.getDataFile() != null) || guestbookResponse.getDataFile() != null)) {
if (guestbookResponse.getDataFile() == null && fmd != null) {
guestbookResponse.setDataFile(fmd.getDataFile());
}
if (fmd == null || !fmd.getDatasetVersion().isDraft()) {
writeGuestbookResponseRecord(guestbookResponse);
}
}
}
Aggregations