Search in sources :

Example 1 with ExternalToolHandler

use of edu.harvard.iq.dataverse.externaltools.ExternalToolHandler in project dataverse by IQSS.

the class ConfigureFragmentBean method getConfigurePopupToolHandler.

public ExternalToolHandler getConfigurePopupToolHandler() {
    if (fileId == null) {
        // on first UI load, method is called before fileId is set. There may be a better way to handle this
        return null;
    }
    if (toolHandler != null) {
        return toolHandler;
    }
    datafileService.find(fileId);
    ApiToken apiToken = new ApiToken();
    User user = session.getUser();
    if (user instanceof AuthenticatedUser) {
        apiToken = authService.findApiTokenByUser((AuthenticatedUser) user);
    }
    toolHandler = new ExternalToolHandler(tool, datafileService.find(fileId), apiToken);
    return toolHandler;
}
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) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)

Example 2 with ExternalToolHandler

use of edu.harvard.iq.dataverse.externaltools.ExternalToolHandler 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)2 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)2 User (edu.harvard.iq.dataverse.authorization.users.User)2 ExternalToolHandler (edu.harvard.iq.dataverse.externaltools.ExternalToolHandler)2 IOException (java.io.IOException)1