-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
185 additions
and
36 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/main/java/edu/harvard/iq/dataverse/engine/command/impl/DeleteLinkedDatasetCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package edu.harvard.iq.dataverse.engine.command.impl; | ||
|
||
import edu.harvard.iq.dataverse.Dataset; | ||
import edu.harvard.iq.dataverse.DatasetLinkingDataverse; | ||
import edu.harvard.iq.dataverse.authorization.Permission; | ||
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser; | ||
import edu.harvard.iq.dataverse.engine.command.AbstractCommand; | ||
import edu.harvard.iq.dataverse.engine.command.CommandContext; | ||
import edu.harvard.iq.dataverse.engine.command.DataverseRequest; | ||
import edu.harvard.iq.dataverse.engine.command.RequiredPermissions; | ||
import edu.harvard.iq.dataverse.engine.command.exception.CommandException; | ||
import edu.harvard.iq.dataverse.engine.command.exception.PermissionException; | ||
import java.util.Collections; | ||
|
||
/** | ||
* | ||
* @author sarahferry | ||
*/ | ||
|
||
@RequiredPermissions( Permission.EditDataverse ) | ||
public class DeleteLinkedDatasetCommand extends AbstractCommand<Dataset>{ | ||
private final DatasetLinkingDataverse doomed; | ||
private final Dataset editedDs; | ||
|
||
public DeleteLinkedDatasetCommand(DataverseRequest aRequest, Dataset editedDs , DatasetLinkingDataverse doomed) { | ||
super(aRequest, editedDs); | ||
this.editedDs = editedDs; | ||
this.doomed = doomed; | ||
} | ||
|
||
@Override | ||
public Dataset execute(CommandContext ctxt) throws CommandException { | ||
if ((!(getUser() instanceof AuthenticatedUser) || !getUser().isSuperuser())) { | ||
throw new PermissionException("Move Dataset can only be called by superusers.", | ||
this, Collections.singleton(Permission.DeleteDataverse), editedDs); | ||
} | ||
Dataset merged = ctxt.em().merge(editedDs); | ||
DatasetLinkingDataverse doomedAndMerged = ctxt.em().merge(doomed); | ||
ctxt.em().remove(doomedAndMerged); | ||
return merged; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/edu/harvard/iq/dataverse/engine/command/impl/DeleteLinkedDataverseCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package edu.harvard.iq.dataverse.engine.command.impl; | ||
|
||
import edu.harvard.iq.dataverse.Dataverse; | ||
import edu.harvard.iq.dataverse.DataverseLinkingDataverse; | ||
import edu.harvard.iq.dataverse.authorization.Permission; | ||
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser; | ||
import edu.harvard.iq.dataverse.engine.command.AbstractCommand; | ||
import edu.harvard.iq.dataverse.engine.command.CommandContext; | ||
import edu.harvard.iq.dataverse.engine.command.DataverseRequest; | ||
import edu.harvard.iq.dataverse.engine.command.RequiredPermissions; | ||
import edu.harvard.iq.dataverse.engine.command.exception.CommandException; | ||
import edu.harvard.iq.dataverse.engine.command.exception.PermissionException; | ||
import java.util.Collections; | ||
|
||
/** | ||
* | ||
* @author sarahferry | ||
*/ | ||
|
||
@RequiredPermissions( Permission.EditDataverse ) | ||
public class DeleteLinkedDataverseCommand extends AbstractCommand<Dataverse> { | ||
|
||
private final DataverseLinkingDataverse doomed; | ||
private final Dataverse editedDv; | ||
|
||
public DeleteLinkedDataverseCommand(DataverseRequest aRequest, Dataverse editedDv , DataverseLinkingDataverse doomed) { | ||
super(aRequest, editedDv); | ||
this.editedDv = editedDv; | ||
this.doomed = doomed; | ||
} | ||
|
||
@Override | ||
public Dataverse execute(CommandContext ctxt) throws CommandException { | ||
if ((!(getUser() instanceof AuthenticatedUser) || !getUser().isSuperuser())) { | ||
throw new PermissionException("Move Dataset can only be called by superusers.", | ||
this, Collections.singleton(Permission.DeleteDataverse), editedDv); | ||
} | ||
Dataverse merged = ctxt.em().merge(editedDv); | ||
DataverseLinkingDataverse doomedAndMerged = ctxt.em().merge(doomed); | ||
ctxt.em().remove(doomedAndMerged); | ||
return merged; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters