mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-10 19:43:10 +00:00
[DS-895] Advanced Embargo Project
This commit is contained in:

committed by
Mark Diggory

parent
ffe1d1a9ff
commit
4b9b206d8c
@@ -186,6 +186,9 @@ public class Item extends DSpaceObject
|
||||
TableRow row = DatabaseManager.create(context, "item");
|
||||
Item i = new Item(context, row);
|
||||
|
||||
// set discoverable to true (default)
|
||||
i.setDiscoverable(true);
|
||||
|
||||
// Call update to give the item a last modified date. OK this isn't
|
||||
// amazingly efficient but creates don't happen that often.
|
||||
context.turnOffAuthorisationSystem();
|
||||
@@ -251,6 +254,11 @@ public class Item extends DSpaceObject
|
||||
return itemRow.getIntColumn("item_id");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see org.dspace.content.DSpaceObject#getHandle()
|
||||
*/
|
||||
@@ -287,6 +295,16 @@ public class Item extends DSpaceObject
|
||||
return itemRow.getBooleanColumn("withdrawn");
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out if the item is discoverable
|
||||
*
|
||||
* @return true if the item is discoverable
|
||||
*/
|
||||
public boolean isDiscoverable()
|
||||
{
|
||||
return itemRow.getBooleanColumn("discoverable");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date the item was last modified, or the current date if
|
||||
* last_modified is null
|
||||
@@ -328,6 +346,18 @@ public class Item extends DSpaceObject
|
||||
modified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "discoverable" flag. This is public and only
|
||||
*
|
||||
* @param discoverable
|
||||
* new value for the flag
|
||||
*/
|
||||
public void setDiscoverable(boolean discoverable)
|
||||
{
|
||||
itemRow.setColumn("discoverable", discoverable);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the owning Collection for the item
|
||||
*
|
||||
@@ -1735,6 +1765,12 @@ public class Item extends DSpaceObject
|
||||
itemRow.setColumn("withdrawn", false);
|
||||
}
|
||||
|
||||
if (itemRow.isColumnNull("discoverable"))
|
||||
{
|
||||
itemRow.setColumn("discoverable", false);
|
||||
}
|
||||
|
||||
|
||||
DatabaseManager.update(ourContext, itemRow);
|
||||
|
||||
if (dublinCoreChanged)
|
||||
@@ -1838,9 +1874,8 @@ public class Item extends DSpaceObject
|
||||
|
||||
ourContext.addEvent(new Event(Event.MODIFY, Constants.ITEM, getID(), "WITHDRAW"));
|
||||
|
||||
// and all of our authorization policies
|
||||
// FIXME: not very "multiple-inclusion" friendly
|
||||
AuthorizeManager.removeAllPolicies(ourContext, this);
|
||||
// remove all authorization policies, saving the custom ones
|
||||
AuthorizeManager.removeAllPoliciesByDSOAndTypeNotEqualsTo(ourContext, this, ResourcePolicy.TYPE_CUSTOM);
|
||||
|
||||
// Write log
|
||||
log.info(LogManager.getHeader(ourContext, "withdraw_item", "user="
|
||||
@@ -2188,51 +2223,79 @@ public class Item extends DSpaceObject
|
||||
public void inheritCollectionDefaultPolicies(Collection c)
|
||||
throws java.sql.SQLException, AuthorizeException
|
||||
{
|
||||
List<ResourcePolicy> policies;
|
||||
adjustItemPolicies(c);
|
||||
adjustBundleBitstreamPolicies(c);
|
||||
|
||||
// remove the submit authorization policies
|
||||
// and replace them with the collection's default READ policies
|
||||
policies = AuthorizeManager.getPoliciesActionFilter(ourContext, c,
|
||||
Constants.DEFAULT_ITEM_READ);
|
||||
log.debug(LogManager.getHeader(ourContext, "item_inheritCollectionDefaultPolicies",
|
||||
"item_id=" + getID()));
|
||||
}
|
||||
|
||||
// MUST have default policies
|
||||
if (policies.size() < 1)
|
||||
{
|
||||
throw new java.sql.SQLException("Collection " + c.getID()
|
||||
+ " (" + c.getHandle() + ")"
|
||||
+ " has no default item READ policies");
|
||||
}
|
||||
public void adjustBundleBitstreamPolicies(Collection c) throws SQLException, AuthorizeException {
|
||||
|
||||
// change the action to just READ
|
||||
// just don't call update on the resourcepolicies!!!
|
||||
for (ResourcePolicy rp : policies)
|
||||
{
|
||||
rp.setAction(Constants.READ);
|
||||
}
|
||||
List<ResourcePolicy> defaultCollectionPolicies = AuthorizeManager.getPoliciesActionFilter(ourContext, c, Constants.DEFAULT_BITSTREAM_READ);
|
||||
|
||||
replaceAllItemPolicies(policies);
|
||||
|
||||
policies = AuthorizeManager.getPoliciesActionFilter(ourContext, c,
|
||||
Constants.DEFAULT_BITSTREAM_READ);
|
||||
|
||||
if (policies.size() < 1)
|
||||
{
|
||||
throw new java.sql.SQLException("Collection " + c.getID()
|
||||
if (defaultCollectionPolicies.size() < 1){
|
||||
throw new SQLException("Collection " + c.getID()
|
||||
+ " (" + c.getHandle() + ")"
|
||||
+ " has no default bitstream READ policies");
|
||||
}
|
||||
|
||||
// change the action to just READ
|
||||
// just don't call update on the resourcepolicies!!!
|
||||
for (ResourcePolicy rp : policies)
|
||||
// remove all policies from bundles, add new ones
|
||||
// Remove bundles
|
||||
Bundle[] bunds = getBundles();
|
||||
for (int i = 0; i < bunds.length; i++){
|
||||
Bundle mybundle = bunds[i];
|
||||
|
||||
// if come from InstallItem: remove all submission/workflow policies
|
||||
AuthorizeManager.removeAllPoliciesByDSOAndType(ourContext, mybundle, ResourcePolicy.TYPE_SUBMISSION);
|
||||
AuthorizeManager.removeAllPoliciesByDSOAndType(ourContext, mybundle, ResourcePolicy.TYPE_WORKFLOW);
|
||||
|
||||
List<ResourcePolicy> policiesBundleToAdd = filterPoliciesToAdd(defaultCollectionPolicies, mybundle);
|
||||
AuthorizeManager.addPolicies(ourContext, policiesBundleToAdd, mybundle);
|
||||
|
||||
for(Bitstream bitstream : mybundle.getBitstreams()){
|
||||
// if come from InstallItem: remove all submission/workflow policies
|
||||
AuthorizeManager.removeAllPoliciesByDSOAndType(ourContext, bitstream, ResourcePolicy.TYPE_SUBMISSION);
|
||||
AuthorizeManager.removeAllPoliciesByDSOAndType(ourContext, bitstream, ResourcePolicy.TYPE_WORKFLOW);
|
||||
|
||||
List<ResourcePolicy> policiesBitstreamToAdd = filterPoliciesToAdd(defaultCollectionPolicies, bitstream);
|
||||
AuthorizeManager.addPolicies(ourContext, policiesBitstreamToAdd, bitstream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void adjustItemPolicies(Collection c) throws SQLException, AuthorizeException {
|
||||
// read collection's default READ policies
|
||||
List<ResourcePolicy> defaultCollectionPolicies = AuthorizeManager.getPoliciesActionFilter(ourContext, c, Constants.DEFAULT_ITEM_READ);
|
||||
|
||||
// MUST have default policies
|
||||
if (defaultCollectionPolicies.size() < 1)
|
||||
{
|
||||
rp.setAction(Constants.READ);
|
||||
throw new SQLException("Collection " + c.getID()
|
||||
+ " (" + c.getHandle() + ")"
|
||||
+ " has no default item READ policies");
|
||||
}
|
||||
|
||||
replaceAllBitstreamPolicies(policies);
|
||||
// if come from InstallItem: remove all submission/workflow policies
|
||||
AuthorizeManager.removeAllPoliciesByDSOAndType(ourContext, this, ResourcePolicy.TYPE_SUBMISSION);
|
||||
AuthorizeManager.removeAllPoliciesByDSOAndType(ourContext, this, ResourcePolicy.TYPE_WORKFLOW);
|
||||
|
||||
log.debug(LogManager.getHeader(ourContext, "item_inheritCollectionDefaultPolicies",
|
||||
"item_id=" + getID()));
|
||||
// add default policies only if not already in place
|
||||
List<ResourcePolicy> policiesToAdd = filterPoliciesToAdd(defaultCollectionPolicies, this);
|
||||
AuthorizeManager.addPolicies(ourContext, policiesToAdd, this);
|
||||
}
|
||||
|
||||
private List<ResourcePolicy> filterPoliciesToAdd(List<ResourcePolicy> defaultCollectionPolicies, DSpaceObject dso) throws SQLException {
|
||||
List<ResourcePolicy> policiesToAdd = new ArrayList<ResourcePolicy>();
|
||||
for (ResourcePolicy rp : defaultCollectionPolicies){
|
||||
rp.setAction(Constants.READ);
|
||||
// if an identical policy is already in place don't add it
|
||||
if(!AuthorizeManager.isAnIdenticalPolicyAlreadyInPlace(ourContext, dso, rp)){
|
||||
rp.setRpType(ResourcePolicy.TYPE_INHERITED);
|
||||
policiesToAdd.add(rp);
|
||||
}
|
||||
}
|
||||
return policiesToAdd;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user