Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A small change per Gustavo's review: if a datafile is assigned as the… #3878

Merged
merged 2 commits into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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