@@ -0,0 +1,1896 @@
+package nz.ac.lconz.irr.curate.task;%0A%0Aimport org.dspace.authorize.AuthorizeException;%0Aimport org.dspace.authorize.AuthorizeManager;%0Aimport org.dspace.authorize.ResourcePolicy;%0Aimport org.dspace.content.Collection;%0Aimport org.dspace.content.Community;%0Aimport org.dspace.content.DSpaceObject;%0Aimport org.dspace.core.Constants;%0Aimport org.dspace.core.Context;%0Aimport org.dspace.curate.AbstractCurationTask;%0Aimport org.dspace.curate.Curator;%0A%0Aimport java.io.IOException;%0Aimport java.sql.SQLException;%0Aimport java.util.List;%0A%0A/**%0A * @author Andrea Schweer schweer@waikato.ac.nz for the LCoNZ Institutional Research Repositories%0A */%0Apublic class CopyCommunityPoliciesToCollections extends AbstractCurationTask %7B%0A%09@Override%0A%09public int perform(DSpaceObject dso) throws IOException %7B%0A%09%09if (dso == null %7C%7C dso.getType() != Constants.COMMUNITY) %7B%0A%09%09%09String message = %22This curation task must be run on a community%22;%0A%09%09%09report(message);%0A%09%09%09setResult(message);%0A%09%09%09return Curator.CURATE_SKIP;%0A%09%09%7D%0A%09%09Community community = (Community) dso;%0A%09%09Context context = null;%0A%09%09try %7B%0A%09%09%09context = new Context();%0A%09%09%09Collection%5B%5D collections = community.getCollections();%0A%0A%09%09%09for (Collection collection : collections) %7B%0A%09%09%09%09AuthorizeManager.inheritPolicies(context, community, collection);%0A%09%09%09%7D%0A%0A%09%09%09context.commit();%0A%09%09%09context = null;%0A%0A%09%09%09String message = String.format(%22%25d child collections inherited the policies of the community%5C%22%25d%5C%22%22, collections.length, community.getName());%0A%09%09%09report(message);%0A%09%09%09setResult(message);%0A%0A%09%09%09return Curator.CURATE_SUCCESS;%0A%09%09%7D catch (SQLException e) %7B%0A%09%09%09String message = e.getMessage();%0A%09%09%09report(message);%0A%09%09%09setResult(message);%0A%09%09%09return Curator.CURATE_ERROR;%0A%09%09%7D catch (AuthorizeException e) %7B%0A%09%09%09String message = e.getMessage();%0A%09%09%09report(message);%0A%09%09%09setResult(message);%0A%09%09%09return Curator.CURATE_ERROR;%0A%09%09%7D finally %7B%0A%09%09%09if (context != null) %7B%0A%09%09%09%09context.abort();%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%7D%0A

New curation task: collections inherit policies