Permalink
Browse files

OAI Restrict to having a public content bitstream

  • Loading branch information...
peterdietz committed Aug 20, 2014
1 parent b125c48 commit 62b3472c4b2f7c70d1b230ca7d5d27cb88f39ea1
@@ -301,6 +301,19 @@ private SolrInputDocument index(Item item) throws SQLException, MetadataBindExce
{
doc.addField("metadata.dc.format.mimetype", f);
}
+
+ Bundle[] contentBundles = item.getBundles(Constants.CONTENT_BUNDLE_NAME);
+ boolean hasPublicBitstream = false;
+ for (Bundle bundle : contentBundles) {
+ Bitstream[] bitstreams = bundle.getBitstreams();
+ for (Bitstream bitstream : bitstreams) {
+ if (AuthorizeManager.authorizeActionBoolean(_context, bitstream, Constants.READ)) {
+ hasPublicBitstream = true;
+ break;
+ }
+ }
+ }
+ doc.addField("item.publicBitstream", hasPublicBitstream);
ByteArrayOutputStream out = new ByteArrayOutputStream();
MarshallingUtils.writeMetadata(out, ItemUtils.retrieveMetadata(item));
@@ -16,6 +16,7 @@
import org.apache.log4j.Logger;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.AuthorizeManager;
+import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.Item;
import org.dspace.core.Constants;
@@ -24,7 +25,7 @@
import org.dspace.xoai.data.DSpaceItem;
/**
- *
+ * BitstreamAccessFilter - To determine if there is a publicly accessible bitstream that is accessible
* @author Lyncode Development Team <dspace@lyncode.com>
*/
public class DSpaceAuthorizationFilter extends DSpaceFilter
@@ -35,6 +36,7 @@
@Override
public DatabaseFilterResult getWhere(Context context)
{
+ log.info("GetWhere");
List<Object> params = new ArrayList<Object>();
return new DatabaseFilterResult("EXISTS (SELECT p.action_id FROM "
+ "resourcepolicy p, " + "bundle2bitstream b, " + "bundle bu, "
@@ -48,20 +50,32 @@ public DatabaseFilterResult getWhere(Context context)
@Override
public boolean isShown(DSpaceItem item)
{
+ log.info("Check if isShown for item: " + item.getIdentifier());
try
{
Context ctx = super.getContext();
String handle = DSpaceItem.parseHandle(item.getIdentifier());
if (handle == null) return false;
Item dsitem = (Item) HandleManager.resolveToObject(ctx, handle);
- AuthorizeManager.authorizeAction(ctx, dsitem, Constants.READ);
- for (Bundle b : dsitem.getBundles())
- AuthorizeManager.authorizeAction(ctx, b, Constants.READ);
- return true;
- }
- catch (AuthorizeException ex)
- {
- log.debug(ex.getMessage());
+
+ if(AuthorizeManager.authorizeActionBoolean(ctx, dsitem, Constants.READ)) {
+ Bundle[] contentBundles = dsitem.getBundles(Constants.CONTENT_BUNDLE_NAME);
+ for (Bundle bundle : contentBundles) {
+ if (AuthorizeManager.authorizeActionBoolean(ctx, bundle, Constants.READ)) {
+ Bitstream[] bitstreams = bundle.getBitstreams();
+ for (Bitstream bitstream : bitstreams) {
+ if (AuthorizeManager.authorizeActionBoolean(ctx, bitstream, Constants.READ)) {
+ log.info("There is an accessible bitstream in: " + dsitem.getHandle());
+ return true;
+ }
+ }
+ }
+ }
+ }
+
+ //If previous loop didn't return true after it found a readable content bitstream, then nothing readable
+ log.info("NO accessible bitstream in: " + dsitem.getHandle());
+ return false;
}
catch (SQLException ex)
{
@@ -77,7 +91,8 @@ public boolean isShown(DSpaceItem item)
@Override
public SolrFilterResult getQuery()
{
- return new SolrFilterResult("item.public:true");
+ log.info("SOLR getQuery");
+ return new SolrFilterResult("item.public:true AND item.publicBitstream:true");
}
}
@@ -15,6 +15,9 @@
<Contexts>
<Context baseurl="request">
+ <!-- Open Access (Downloadable) -->
+ <Filter refid="bitstreamaccessFilter"/>
+
<Format refid="oaidc" />
<Format refid="mets" />
<Format refid="xoai" />
@@ -147,6 +147,7 @@
<!-- Item always present information -->
<field name="item.id" type="int" indexed="true" stored="true" multiValued="false" />
<field name="item.public" type="boolean" indexed="true" stored="true" multiValued="false" />
+ <field name="item.publicBitstream" type="boolean" indexed="true" stored="true" multiValued="false" />
<field name="item.handle" type="string" indexed="true" stored="true" multiValued="false" />
<field name="item.collections" type="string" indexed="true" stored="true" multiValued="true" />
<field name="item.communities" type="string" indexed="true" stored="true" multiValued="true" />

0 comments on commit 62b3472

Please sign in to comment.