Search in sources :

Example 1 with StorageIO

use of edu.harvard.iq.dataverse.dataaccess.StorageIO in project dataverse by IQSS.

the class Access method dsCardImage.

// Note:
// the Dataverse page is no longer using this method.
@Path("dsCardImage/{versionId}")
@GET
@Produces({ "image/png" })
public InputStream dsCardImage(@PathParam("versionId") Long versionId, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response) /*throws NotFoundException, ServiceUnavailableException, PermissionDeniedException, AuthorizationRequiredException*/
{
    DatasetVersion datasetVersion = versionService.find(versionId);
    if (datasetVersion == null) {
        logger.warning("Preview: Version service could not locate a DatasetVersion object for id " + versionId + "!");
        return null;
    }
    // String imageThumbFileName = null;
    StorageIO thumbnailDataAccess = null;
    if (datasetVersion.getDataset() != null) {
        DataFile logoDataFile = datasetVersion.getDataset().getThumbnailFile();
        if (logoDataFile != null) {
            try {
                StorageIO<DataFile> dataAccess = logoDataFile.getStorageIO();
                if (dataAccess != null) {
                    // && dataAccess.isLocalFile()) {
                    dataAccess.open();
                    thumbnailDataAccess = ImageThumbConverter.getImageThumbnailAsInputStream(dataAccess, 48);
                }
            } catch (IOException ioEx) {
                thumbnailDataAccess = null;
            }
        }
        if (thumbnailDataAccess != null && thumbnailDataAccess.getInputStream() != null) {
            return thumbnailDataAccess.getInputStream();
        }
    }
    return null;
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) StorageIO(edu.harvard.iq.dataverse.dataaccess.StorageIO) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

DataFile (edu.harvard.iq.dataverse.DataFile)1 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)1 StorageIO (edu.harvard.iq.dataverse.dataaccess.StorageIO)1 IOException (java.io.IOException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1