Search in sources :

Example 11 with ApiToken

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);
        }
    }
}
Also used : AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) User(edu.harvard.iq.dataverse.authorization.users.User) ApiToken(edu.harvard.iq.dataverse.authorization.users.ApiToken) ExternalToolHandler(edu.harvard.iq.dataverse.externaltools.ExternalToolHandler) IOException(java.io.IOException) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)

Aggregations

ApiToken (edu.harvard.iq.dataverse.authorization.users.ApiToken)11 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)6 DataFile (edu.harvard.iq.dataverse.DataFile)3 ActionLogRecord (edu.harvard.iq.dataverse.actionlogging.ActionLogRecord)3 Timestamp (java.sql.Timestamp)3 Calendar (java.util.Calendar)3 Test (org.junit.Test)3 User (edu.harvard.iq.dataverse.authorization.users.User)2 ExternalToolHandler (edu.harvard.iq.dataverse.externaltools.ExternalToolHandler)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 DataTable (edu.harvard.iq.dataverse.DataTable)1 Dataverse (edu.harvard.iq.dataverse.Dataverse)1 UserRecordIdentifier (edu.harvard.iq.dataverse.authorization.UserRecordIdentifier)1 BuiltinAuthenticationProvider (edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinAuthenticationProvider)1 BuiltinUser (edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUser)1 AbstractOAuth2AuthenticationProvider (edu.harvard.iq.dataverse.authorization.providers.oauth2.AbstractOAuth2AuthenticationProvider)1 ShibAuthenticationProvider (edu.harvard.iq.dataverse.authorization.providers.shib.ShibAuthenticationProvider)1 ConfirmEmailData (edu.harvard.iq.dataverse.confirmemail.ConfirmEmailData)1 ReservedWord (edu.harvard.iq.dataverse.externaltools.ExternalTool.ReservedWord)1 IOException (java.io.IOException)1