diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetVersionServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/DatasetVersionServiceBean.java index 69c1be49b3b..6d007a8b7e2 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DatasetVersionServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetVersionServiceBean.java @@ -703,6 +703,7 @@ public Long getThumbnailByVersionId(Long versionId) { + "AND df.id = o.id " + "AND fm.datasetversion_id = dv.id " + "AND fm.datafile_id = df.id " + + "AND df.restricted = false " + "AND o.previewImageAvailable = true " + "ORDER BY df.id LIMIT 1;").getSingleResult(); } catch (Exception ex) { @@ -727,6 +728,7 @@ public Long getThumbnailByVersionId(Long versionId) { + "AND fm.datasetversion_id = dv.id " + "AND fm.datafile_id = df.id " // + "AND o.previewImageAvailable = false " + + "AND df.restricted = false " + "AND df.contenttype LIKE 'image/%' " + "AND NOT df.contenttype = 'image/fits' " + "AND df.filesize < " + imageThumbnailSizeLimit + " " @@ -759,6 +761,7 @@ public Long getThumbnailByVersionId(Long versionId) { + "AND fm.datasetversion_id = dv.id " + "AND fm.datafile_id = df.id " // + "AND o.previewImageAvailable = false " + + "AND df.restricted = false " + "AND df.contenttype = 'application/pdf' " + "AND df.filesize < " + imageThumbnailSizeLimit + " " + "ORDER BY df.filesize ASC LIMIT 1;").getSingleResult(); diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/PublishDatasetCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/PublishDatasetCommand.java index 79e072b9a2e..5e8edd48814 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/PublishDatasetCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/PublishDatasetCommand.java @@ -177,33 +177,55 @@ public Dataset execute(CommandContext ctxt) throws CommandException { if (dataFile.getFileMetadata() != null && dataFile.getFileMetadata().getDatasetVersion().equals(theDataset.getLatestVersion())) { dataFile.setRestricted(dataFile.getFileMetadata().isRestricted()); } - if (dataFile.isRestricted() && ctxt.mapLayerMetadata().findMetadataByDatafile(dataFile) != null){ - // (We need an AuthenticatedUser in order to produce a WorldMap token!) - String id = getUser().getIdentifier(); - id = id.startsWith("@") ? id.substring(1) : id; - AuthenticatedUser authenticatedUser = ctxt.authentication().getAuthenticatedUser(id); - try { - logger.fine("(1 of 2) PublishDatasetCommand: delete MapLayer From *WorldMap*"); - ctxt.mapLayerMetadata().deleteMapLayerFromWorldMap(dataFile, authenticatedUser); - - // If that was successful, delete the layer on the Dataverse side as well: - //SEK 4/20/2017 - //Command to delete from Dataverse side - logger.fine("(2 of 2) PublishDatasetCommand: Delete MapLayerMetadata From *Dataverse*"); - boolean deleteMapSuccess = ctxt.engine().submit(new DeleteMapLayerMetadataCommand(this.getRequest(), dataFile)); - - // RP - Bit of hack, update the datafile here b/c the reference to the datafile - // is not being passed all the way up/down the chain. - // - dataFile.setPreviewImageAvailable(false); - - } catch (IOException ioex) { - // We are not going to treat it as a fatal condition and bail out, - // but we will send a notification to the user, warning them about - // the layer still being out there, un-deleted: - ctxt.notifications().sendNotification(authenticatedUser, new Timestamp(new Date().getTime()), UserNotification.Type.MAPLAYERDELETEFAILED, dataFile.getFileMetadata().getId()); + + + if (dataFile.isRestricted()) { + // A couple things need to happen if the file has been restricted: + // 1. If there's a map layer associated with this shape file, or + // tabular-with-geo-tag file, all that map layer data (that + // includes most of the actual data in the file!) need to be + // removed from WorldMap and GeoConnect, since anyone can get + // download the data from there; + // 2. If this (image) file has been assigned as the dedicated + // thumbnail for the dataset, we need to remove that assignment, + // now that the file is restricted. + + // Map layer: + + if (ctxt.mapLayerMetadata().findMetadataByDatafile(dataFile) != null) { + // (We need an AuthenticatedUser in order to produce a WorldMap token!) + String id = getUser().getIdentifier(); + id = id.startsWith("@") ? id.substring(1) : id; + AuthenticatedUser authenticatedUser = ctxt.authentication().getAuthenticatedUser(id); + try { + logger.fine("(1 of 2) PublishDatasetCommand: delete MapLayer From *WorldMap*"); + ctxt.mapLayerMetadata().deleteMapLayerFromWorldMap(dataFile, authenticatedUser); + + // If that was successful, delete the layer on the Dataverse side as well: + //SEK 4/20/2017 + //Command to delete from Dataverse side + logger.fine("(2 of 2) PublishDatasetCommand: Delete MapLayerMetadata From *Dataverse*"); + boolean deleteMapSuccess = ctxt.engine().submit(new DeleteMapLayerMetadataCommand(this.getRequest(), dataFile)); + + // RP - Bit of hack, update the datafile here b/c the reference to the datafile + // is not being passed all the way up/down the chain. + // + dataFile.setPreviewImageAvailable(false); + + } catch (IOException ioex) { + // We are not going to treat it as a fatal condition and bail out, + // but we will send a notification to the user, warning them about + // the layer still being out there, un-deleted: + ctxt.notifications().sendNotification(authenticatedUser, new Timestamp(new Date().getTime()), UserNotification.Type.MAPLAYERDELETEFAILED, dataFile.getFileMetadata().getId()); + } + + } + + // Dataset thumbnail assignment: + + if (dataFile.equals(theDataset.getThumbnailFile())) { + theDataset.setThumbnailFile(null); } - } }