From 334c2c94c50be6f4c9eda4aaa5af4b3885b753b9 Mon Sep 17 00:00:00 2001 From: Leonid Andreev Date: Thu, 1 Jun 2017 16:28:51 -0400 Subject: [PATCH 1/2] A small change per Gustavo's review: if a datafile is assigned as the thumbnail for a dataset, but has been restricted since then, the assignment will be removed *when the dataset gets published*. (somewhat similarly to how the map layer for a restricted file gets removed inside PublishDatasetCommand). --- .../edu/harvard/iq/dataverse/DatasetVersionServiceBean.java | 3 +++ .../dataverse/engine/command/impl/PublishDatasetCommand.java | 4 ++++ 2 files changed, 7 insertions(+) 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..771e123835e 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 @@ -205,6 +205,10 @@ public Dataset execute(CommandContext ctxt) throws CommandException { } } + + if (dataFile.isRestricted() && dataFile.equals(theDataset.getThumbnailFile())) { + theDataset.setThumbnailFile(null); + } } theDataset.setFileAccessRequest(theDataset.getLatestVersion().getTermsOfUseAndAccess().isFileAccessRequest()); From df6bf879ed18e6bac97f03f4dbf5c4647eb011d8 Mon Sep 17 00:00:00 2001 From: Leonid Andreev Date: Thu, 1 Jun 2017 17:15:53 -0400 Subject: [PATCH 2/2] (added a comment to PublishDatasetCommand explaining what's being done there, regarding datafiles that are being made restricted). --- .../command/impl/PublishDatasetCommand.java | 78 ++++++++++++------- 1 file changed, 48 insertions(+), 30 deletions(-) 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 771e123835e..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,37 +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() && dataFile.equals(theDataset.getThumbnailFile())) { - theDataset.setThumbnailFile(null); + + 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); + } } }