Search in sources :

Example 11 with MakeDataCountEntry

use of edu.harvard.iq.dataverse.makedatacount.MakeDataCountLoggingServiceBean.MakeDataCountEntry in project dataverse by IQSS.

the class FileDownloadServiceBean method writeGuestbookResponseRecord.

public void writeGuestbookResponseRecord(GuestbookResponse guestbookResponse) {
    try {
        CreateGuestbookResponseCommand cmd = new CreateGuestbookResponseCommand(dvRequestService.getDataverseRequest(), guestbookResponse, guestbookResponse.getDataset());
        commandEngine.submit(cmd);
        DatasetVersion version = guestbookResponse.getDatasetVersion();
        // Sometimes guestbookResponse doesn't have a version, so we grab the released version
        if (null == version) {
            version = guestbookResponse.getDataset().getReleasedVersion();
        }
        MakeDataCountEntry entry = new MakeDataCountEntry(FacesContext.getCurrentInstance(), dvRequestService, version, guestbookResponse.getDataFile());
        // As the api download url is not available at this point we construct it manually
        entry.setTargetUrl("/api/access/datafile/" + guestbookResponse.getDataFile().getId());
        entry.setRequestUrl("/api/access/datafile/" + guestbookResponse.getDataFile().getId());
        mdcLogService.logEntry(entry);
    } catch (CommandException e) {
        // if an error occurs here then download won't happen no need for response recs...
        logger.warning("Exception writing GuestbookResponse for file: " + guestbookResponse.getDataFile().getId() + " : " + e.getLocalizedMessage());
    }
}
Also used : CreateGuestbookResponseCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateGuestbookResponseCommand) MakeDataCountEntry(edu.harvard.iq.dataverse.makedatacount.MakeDataCountLoggingServiceBean.MakeDataCountEntry) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException)

Example 12 with MakeDataCountEntry

use of edu.harvard.iq.dataverse.makedatacount.MakeDataCountLoggingServiceBean.MakeDataCountEntry in project dataverse by IQSS.

the class FilePage method init.

public String init() {
    if (fileId != null || persistentId != null) {
        // ---------------------------------------
        if (fileId != null) {
            file = datafileService.find(fileId);
        } else if (persistentId != null) {
            file = datafileService.findByGlobalId(persistentId);
            if (file != null) {
                fileId = file.getId();
            }
        }
        if (file == null || fileId == null) {
            return permissionsWrapper.notFound();
        }
        // Is the Dataset harvested?
        if (file.getOwner().isHarvested()) {
            // if so, we'll simply forward to the remote URL for the original
            // source of this harvested dataset:
            String originalSourceURL = file.getOwner().getRemoteArchiveURL();
            if (originalSourceURL != null && !originalSourceURL.equals("")) {
                logger.fine("redirecting to " + originalSourceURL);
                try {
                    FacesContext.getCurrentInstance().getExternalContext().redirect(originalSourceURL);
                } catch (IOException ioex) {
                    // must be a bad URL...
                    // we don't need to do anything special here - we'll redirect
                    // to the local 404 page, below.
                    logger.warning("failed to issue a redirect to " + originalSourceURL);
                }
            }
            return permissionsWrapper.notFound();
        }
        RetrieveDatasetVersionResponse retrieveDatasetVersionResponse;
        Long getDatasetVersionID = null;
        if (datasetVersionId == null) {
            retrieveDatasetVersionResponse = datasetVersionService.selectRequestedVersion(file.getOwner().getVersions(), version);
            getDatasetVersionID = retrieveDatasetVersionResponse.getDatasetVersion().getId();
        } else {
            getDatasetVersionID = datasetVersionId;
        }
        fileMetadata = datafileService.findFileMetadataByDatasetVersionIdAndDataFileId(getDatasetVersionID, fileId);
        if (fileMetadata == null) {
            logger.fine("fileMetadata is null! Checking finding most recent version file was in.");
            fileMetadata = datafileService.findMostRecentVersionFileIsIn(file);
            if (fileMetadata == null) {
                return permissionsWrapper.notFound();
            }
        }
        // If this DatasetVersion is unpublished and permission is doesn't have permissions:
        // > Go to the Login page
        // 
        // Check permisisons
        Boolean authorized = (fileMetadata.getDatasetVersion().isReleased()) || (!fileMetadata.getDatasetVersion().isReleased() && this.canViewUnpublishedDataset());
        if (!authorized) {
            return permissionsWrapper.notAuthorized();
        }
        // termsOfAccess = fileMetadata.getDatasetVersion().getTermsOfUseAndAccess().getTermsOfAccess();
        // fileAccessRequest = fileMetadata.getDatasetVersion().getTermsOfUseAndAccess().isFileAccessRequest();
        this.guestbookResponse = this.guestbookResponseService.initGuestbookResponseForFragment(fileMetadata, session);
        if (fileMetadata.getDatasetVersion().isPublished()) {
            MakeDataCountEntry entry = new MakeDataCountEntry(FacesContext.getCurrentInstance(), dvRequestService, fileMetadata.getDatasetVersion());
            mdcLogService.logEntry(entry);
        }
        // Find external tools based on their type, the file content type, and whether
        // ingest has created a derived file for that type
        // Currently, tabular data files are the only type of derived file created, so
        // isTabularData() works - true for tabular types where a .tab file has been
        // created and false for other mimetypes
        String contentType = file.getContentType();
        // For tabular data, indicate successful ingest by returning a contentType for the derived .tab file
        if (file.isTabularData()) {
            contentType = DataFileServiceBean.MIME_TYPE_TSV_ALT;
        }
        configureTools = externalToolService.findFileToolsByTypeAndContentType(ExternalTool.Type.CONFIGURE, contentType);
        exploreTools = externalToolService.findFileToolsByTypeAndContentType(ExternalTool.Type.EXPLORE, contentType);
        Collections.sort(exploreTools, CompareExternalToolName);
        toolsWithPreviews = sortExternalTools();
        if (!toolsWithPreviews.isEmpty()) {
            setSelectedTool(toolsWithPreviews.get(0));
        }
    } else {
        return permissionsWrapper.notFound();
    }
    return null;
}
Also used : MakeDataCountEntry(edu.harvard.iq.dataverse.makedatacount.MakeDataCountLoggingServiceBean.MakeDataCountEntry) RetrieveDatasetVersionResponse(edu.harvard.iq.dataverse.DatasetVersionServiceBean.RetrieveDatasetVersionResponse) IOException(java.io.IOException)

Aggregations

MakeDataCountEntry (edu.harvard.iq.dataverse.makedatacount.MakeDataCountLoggingServiceBean.MakeDataCountEntry)12 IOException (java.io.IOException)6 DataFile (edu.harvard.iq.dataverse.DataFile)5 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)5 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)4 BadRequestException (javax.ws.rs.BadRequestException)4 NotFoundException (javax.ws.rs.NotFoundException)4 GuestbookResponse (edu.harvard.iq.dataverse.GuestbookResponse)3 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)3 MakeDataCountLoggingServiceBean (edu.harvard.iq.dataverse.makedatacount.MakeDataCountLoggingServiceBean)3 URISyntaxException (java.net.URISyntaxException)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 RedirectionException (javax.ws.rs.RedirectionException)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 GuestUser (edu.harvard.iq.dataverse.authorization.users.GuestUser)2 User (edu.harvard.iq.dataverse.authorization.users.User)2 CreateGuestbookResponseCommand (edu.harvard.iq.dataverse.engine.command.impl.CreateGuestbookResponseCommand)2 GetLatestAccessibleDatasetVersionCommand (edu.harvard.iq.dataverse.engine.command.impl.GetLatestAccessibleDatasetVersionCommand)2 FileNotFoundException (java.io.FileNotFoundException)2