{
// before create a new policy check if an identical policy is already in place
if(!AuthorizeManager.isAnIdenticalPolicyAlreadyInPlace(c, myitem, groupID, actionID, -1)){
// now add the policy
ResourcePolicy rp = ResourcePolicy.create(c);
rp.setResource(myitem);
rp.setAction(actionID);
rp.setGroup(group);
rp.setRpName(name);
rp.setRpDescription(description);
rp.setStartDate(startDate);
rp.setEndDate(endDate);
rp.update();
}
}
}
}
else if (contentType == Constants.BUNDLE)
{
// build list of all items in a collection
// build list of all bundles in those items
while (i.hasNext())
{
Item myitem = i.next();
Bundle[] bundles = myitem.getBundles();
for (int j = 0; j < bundles.length; j++)
{
Bundle bundle = bundles[j]; // t for target
// is this a replace? delete policies first
if (isReplace || clearOnly)
{
AuthorizeManager.removeAllPolicies(c, bundle);
}
if (!clearOnly)
{
// before create a new policy check if an identical policy is already in place
if(!AuthorizeManager.isAnIdenticalPolicyAlreadyInPlace(c, bundle, groupID, actionID, -1)){
// now add the policy
ResourcePolicy rp = ResourcePolicy.create(c);
rp.setResource(bundle);
rp.setAction(actionID);
rp.setGroup(group);
rp.setRpName(name);
rp.setRpDescription(description);
rp.setStartDate(startDate);
rp.setEndDate(endDate);
rp.update();
}
}
}
}
}
else if (contentType == Constants.BITSTREAM)
{
// build list of all bitstreams in a collection
// iterate over items, bundles, get bitstreams
while (i.hasNext())
{
Item myitem = i.next();
System.out.println("Item " + myitem.getID());
Bundle[] bundles = myitem.getBundles();
for (int j = 0; j < bundles.length; j++)
{
System.out.println("Bundle " + bundles[j].getID());
Bitstream[] bitstreams = bundles[j].getBitstreams();
for (int k = 0; k < bitstreams.length; k++)
{
Bitstream bitstream = bitstreams[k]; // t for target
if ( filter == null ||
bitstream.getName().indexOf( filter ) != -1 )
{
// is this a replace? delete policies first
if (isReplace || clearOnly)
{
AuthorizeManager.removeAllPolicies(c, bitstream);
}
if (!clearOnly)
{
// before create a new policy check if an identical policy is already in place
if(!AuthorizeManager.isAnIdenticalPolicyAlreadyInPlace(c, bitstream, groupID, actionID, -1)){
// now add the policy
ResourcePolicy rp = ResourcePolicy.create(c);
rp.setResource(bitstream);
rp.setAction(actionID);
rp.setGroup(group);
rp.setRpName(name);
rp.setRpDescription(description);
rp.setStartDate(startDate);
rp.setEndDate(endDate);
rp.update();
}
}
}
}
}