Skip to content

Commit

Permalink
Merge pull request #3878 from IQSS/3852-final-touches-to-regression-f…
Browse files Browse the repository at this point in the history
…ixes

A small change per Gustavo's review: if a datafile is assigned as the…
  • Loading branch information
kcondon authored Jun 2, 2017
2 parents a9c5354 + df6bf87 commit 914e4ea
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 + " "
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
}

Expand Down

0 comments on commit 914e4ea

Please sign in to comment.