forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add curation tasks to make admin/public communities/collections/items
- Loading branch information
Showing
3 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
dspace-api/src/main/java/org/dspace/ctask/general/MakeAdminOnly.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,58 @@ | ||
package org.dspace.ctask.general; | ||
|
||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
|
||
import org.dspace.authorize.AuthorizeException; | ||
import org.dspace.authorize.factory.AuthorizeServiceFactory; | ||
import org.dspace.authorize.service.ResourcePolicyService; | ||
import org.dspace.content.Bitstream; | ||
import org.dspace.content.Bundle; | ||
import org.dspace.content.DSpaceObject; | ||
import org.dspace.content.Item; | ||
import org.dspace.core.Constants; | ||
import org.dspace.core.Context; | ||
import org.dspace.curate.AbstractCurationTask; | ||
import org.dspace.curate.Curator; | ||
|
||
/** | ||
* Curation taks to make all {@link DSpaceObject}s public with the exception | ||
* {@link Bundle}s and {@link Bitstream}s, that are left unchanged | ||
* | ||
* @author agomez | ||
*/ | ||
public class MakeAdminOnly extends AbstractCurationTask { | ||
|
||
private ResourcePolicyService resourcePolicyService = AuthorizeServiceFactory.getInstance().getResourcePolicyService(); | ||
|
||
protected String result = null; | ||
|
||
protected String taskProperty(String name, String defaultValue) { | ||
return super.taskProperty(name) != null ? super.taskProperty(name) : defaultValue; | ||
} | ||
|
||
@Override | ||
public int perform(DSpaceObject dso) throws IOException { | ||
if (dso instanceof Item) { | ||
if (!((Item) dso).isArchived()) { | ||
result = "Skipping not archived Item: " + dso.getID(); | ||
setResult(result); | ||
report(result); | ||
return Curator.CURATE_SKIP; | ||
} | ||
} | ||
try { | ||
Context context = Curator.curationContext(); | ||
resourcePolicyService.removePolicies(context, dso, Constants.READ); | ||
result = "DSpaceObject has been successfully made private only for Administrators: " + dso.getID(); | ||
setResult(result); | ||
report(result); | ||
return Curator.CURATE_SUCCESS; | ||
} catch (SQLException | AuthorizeException e) { | ||
result = "Unable to change authorization policy for " + dso.getID(); | ||
setResult(result); | ||
report(result); | ||
return Curator.CURATE_ERROR; | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
dspace-api/src/main/java/org/dspace/ctask/general/MakePublic.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,66 @@ | ||
package org.dspace.ctask.general; | ||
|
||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
|
||
import org.dspace.authorize.AuthorizeException; | ||
import org.dspace.authorize.factory.AuthorizeServiceFactory; | ||
import org.dspace.authorize.service.AuthorizeService; | ||
import org.dspace.authorize.service.ResourcePolicyService; | ||
import org.dspace.content.Bitstream; | ||
import org.dspace.content.Bundle; | ||
import org.dspace.content.DSpaceObject; | ||
import org.dspace.content.Item; | ||
import org.dspace.core.Constants; | ||
import org.dspace.core.Context; | ||
import org.dspace.curate.AbstractCurationTask; | ||
import org.dspace.curate.Curator; | ||
import org.dspace.eperson.Group; | ||
import org.dspace.eperson.factory.EPersonServiceFactory; | ||
import org.dspace.eperson.service.GroupService; | ||
|
||
/** | ||
* Curation taks to make all {@link DSpaceObject}s admin-only with the exception | ||
* {@link Bundle}s and {@link Bitstream}s, that are left unchanged | ||
* | ||
* @author agomez | ||
*/ | ||
public class MakePublic extends AbstractCurationTask { | ||
|
||
private ResourcePolicyService resourcePolicyService = AuthorizeServiceFactory.getInstance().getResourcePolicyService(); | ||
private AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService(); | ||
private GroupService groupService = EPersonServiceFactory.getInstance().getGroupService(); | ||
|
||
protected String result = null; | ||
|
||
protected String taskProperty(String name, String defaultValue) { | ||
return super.taskProperty(name) != null ? super.taskProperty(name) : defaultValue; | ||
} | ||
|
||
@Override | ||
public int perform(DSpaceObject dso) throws IOException { | ||
if (dso instanceof Item) { | ||
if (!((Item) dso).isArchived()) { | ||
result = "Skipping not archived Item: " + dso.getID(); | ||
setResult(result); | ||
report(result); | ||
return Curator.CURATE_SKIP; | ||
} | ||
} | ||
try { | ||
Context context = Curator.curationContext(); | ||
Group anonymous = groupService.findByName(context, Group.ANONYMOUS); | ||
resourcePolicyService.removePolicies(context, dso, Constants.READ); | ||
authorizeService.createResourcePolicy(context, dso, anonymous, null, Constants.READ, null); | ||
result = "DSpaceObject has been successfully made public: " + dso.getID(); | ||
setResult(result); | ||
report(result); | ||
return Curator.CURATE_SUCCESS; | ||
} catch (SQLException | AuthorizeException e) { | ||
result = "Unable to change authorization policy for " + dso.getID(); | ||
setResult(result); | ||
report(result); | ||
return Curator.CURATE_ERROR; | ||
} | ||
} | ||
} |
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