3232 * @author skraffmi
3333 */
3434@ RequiredPermissionsMap ({
35- @ RequiredPermissions (dataverseName = "moved" , value = {Permission .PublishDataset })
36- , @ RequiredPermissions (dataverseName = "destination" , value = {Permission .AddDataset , Permission .PublishDataset })
35+ @ RequiredPermissions (dataverseName = "moved" , value = {Permission .PublishDataset })
36+ , @ RequiredPermissions (dataverseName = "destination" , value = {Permission .AddDataset , Permission .PublishDataset })
3737})
3838public class MoveDatasetCommand extends AbstractVoidCommand {
3939
@@ -42,10 +42,11 @@ public class MoveDatasetCommand extends AbstractVoidCommand {
4242 final Dataset moved ;
4343 final Dataverse destination ;
4444 final Boolean force ;
45- private boolean allowSelfNotification = false ;
45+ final Boolean allowSelfNotification ;
46+ final Dataverse originalOwner ;
4647
4748 public MoveDatasetCommand (DataverseRequest aRequest , Dataset moved , Dataverse destination , Boolean force ) {
48- this ( aRequest , moved , destination , force , Boolean . FALSE );
49+ this ( aRequest , moved , destination , force , null );
4950 }
5051 public MoveDatasetCommand (DataverseRequest aRequest , Dataset moved , Dataverse destination , Boolean force , Boolean allowSelfNotification ) {
5152 super (
@@ -57,6 +58,7 @@ public MoveDatasetCommand(DataverseRequest aRequest, Dataset moved, Dataverse de
5758 this .destination = destination ;
5859 this .force = force ;
5960 this .allowSelfNotification = allowSelfNotification ;
61+ this .originalOwner = moved .getOwner ();
6062 }
6163
6264 @ Override
@@ -75,13 +77,13 @@ public void executeImpl(CommandContext ctxt) throws CommandException {
7577 if (moved .getOwner ().equals (destination )) {
7678 throw new IllegalCommandException (BundleUtil .getStringFromBundle ("dashboard.move.dataset.command.error.targetDataverseSameAsOriginalDataverse" ), this );
7779 }
78-
80+
7981 // if dataset is published make sure that its target is published
80-
82+
8183 if (moved .isReleased () && !destination .isReleased ()){
8284 throw new IllegalCommandException (BundleUtil .getStringFromBundle ("dashboard.move.dataset.command.error.targetDataverseUnpublishedDatasetPublished" , Arrays .asList (destination .getDisplayName ())), this );
8385 }
84-
86+
8587 //if the datasets guestbook is not contained in the new dataverse then remove it
8688 if (moved .getGuestbook () != null ) {
8789 Guestbook gb = moved .getGuestbook ();
@@ -100,15 +102,15 @@ public void executeImpl(CommandContext ctxt) throws CommandException {
100102 }
101103 }
102104 }
103-
105+
104106 // generate list of all possible parent dataverses to check against
105107 List <Dataverse > ownersToCheck = new ArrayList <>();
106108 ownersToCheck .add (destination );
107109 if (destination .getOwners () != null ) {
108110 ownersToCheck .addAll (destination .getOwners ());
109111 }
110-
111- // if the dataset is linked to the new dataverse or any of
112+
113+ // if the dataset is linked to the new dataverse or any of
112114 // its parent dataverses then remove the link
113115 List <DatasetLinkingDataverse > linkingDatasets = new ArrayList <>();
114116 if (moved .getDatasetLinkingDataverses () != null ) {
@@ -127,7 +129,7 @@ public void executeImpl(CommandContext ctxt) throws CommandException {
127129 }
128130 }
129131 }
130-
132+
131133 if (removeGuestbook || removeLinkDs ) {
132134 StringBuilder errorString = new StringBuilder ();
133135 if (removeGuestbook ) {
@@ -138,25 +140,30 @@ public void executeImpl(CommandContext ctxt) throws CommandException {
138140 }
139141 throw new UnforcedCommandException (errorString .toString (), this );
140142 }
141-
143+
142144 // 6575 if dataset is submitted for review and the default contributor
143145 // role includes dataset publish then remove the lock
144-
146+
145147 if (moved .isLockedFor (DatasetLock .Reason .InReview )
146148 && destination .getDefaultContributorRole ().permissions ().contains (Permission .PublishDataset )) {
147149 ctxt .datasets ().removeDatasetLocks (moved , DatasetLock .Reason .InReview );
148150 }
149151
150152 // OK, move
151- Dataverse originalOwner = moved .getOwner ();
152153 moved .setOwner (destination );
153154 ctxt .em ().merge (moved );
154- sendNotification (moved , originalOwner , ctxt );
155155
156156 boolean doNormalSolrDocCleanUp = true ;
157157 ctxt .index ().asyncIndexDataset (moved , doNormalSolrDocCleanUp );
158158
159159 }
160+
161+ @ Override
162+ public boolean onSuccess (CommandContext ctxt , Object r ) {
163+ sendNotification (moved , originalOwner , ctxt );
164+ return true ;
165+ }
166+
160167 /**
161168 * Sends notifications to those able to publish the dataset upon the successful move of a dataset.
162169 * <p>
@@ -181,14 +188,17 @@ protected void sendNotification(Dataset dataset, Dataverse originalOwner, Comman
181188
182189 // 3. Get all users with publish permission on the dataset's original owner (dataverse) and notify them.
183190 Map <String , AuthenticatedUser > recipients = ctxt .permissions ().getDistinctUsersWithPermissionOn (Permission .PublishDataset , originalOwner );
184- // make sure the requestor is in the recipient list in case they don't match the permission
191+ // make sure the requestor is in the recipient list in case they don't match the permission but only if allowSelfNotification is true
185192 if (requestor != null ) {
186- recipients .put (requestor .getIdentifier (), requestor );
193+ if (Boolean .TRUE .equals (allowSelfNotification )) {
194+ recipients .put (requestor .getIdentifier (), requestor );
195+ } else {
196+ recipients .remove (requestor .getIdentifier ());
197+ }
187198 }
188199
189200 recipients .values ()
190201 .stream ()
191- .filter (recipient -> allowSelfNotification || !recipient .equals (requestor ))
192202 .forEach (recipient -> ctxt .notifications ().sendNotification (
193203 recipient ,
194204 Timestamp .from (Instant .now ()),
@@ -200,3 +210,4 @@ protected void sendNotification(Dataset dataset, Dataverse originalOwner, Comman
200210 ));
201211 }
202212}
213+
0 commit comments