mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
OAI: add support to extract embargo from bitstreams and expose it in OAI metadata
This commit is contained in:
@@ -11,6 +11,8 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.xml.xoai.Element;
|
||||
@@ -21,6 +23,9 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.util.factory.UtilServiceFactory;
|
||||
import org.dspace.app.util.service.MetadataExposureService;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.Bundle;
|
||||
import org.dspace.content.Item;
|
||||
@@ -34,6 +39,9 @@ import org.dspace.content.service.RelationshipService;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.Utils;
|
||||
import org.dspace.eperson.Group;
|
||||
import org.dspace.eperson.factory.EPersonServiceFactory;
|
||||
import org.dspace.eperson.service.GroupService;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
import org.dspace.xoai.data.DSpaceItem;
|
||||
@@ -57,6 +65,9 @@ public class ItemUtils {
|
||||
private static final BitstreamService bitstreamService
|
||||
= ContentServiceFactory.getInstance().getBitstreamService();
|
||||
|
||||
private static final AuthorizeService authorizeService =
|
||||
AuthorizeServiceFactory.getInstance().getAuthorizeService();
|
||||
|
||||
private static final ConfigurationService configurationService
|
||||
= DSpaceServicesFactory.getInstance().getConfigurationService();
|
||||
/**
|
||||
@@ -136,6 +147,9 @@ public class ItemUtils {
|
||||
if (description != null) {
|
||||
bitstream.getField().add(createValue("description", description));
|
||||
}
|
||||
// Add bitstream embargo information (READ policy present, for Anonymous group with a start date)
|
||||
addEmbargoField(context, bit, bitstream);
|
||||
|
||||
bitstream.getField().add(createValue("format", bit.getFormat(context).getMIMEType()));
|
||||
bitstream.getField().add(createValue("size", "" + bit.getSizeBytes()));
|
||||
bitstream.getField().add(createValue("url", url));
|
||||
@@ -148,6 +162,24 @@ public class ItemUtils {
|
||||
return bundles;
|
||||
}
|
||||
|
||||
private static void addEmbargoField(Context context, Bitstream bit, Element bitstream) throws SQLException {
|
||||
GroupService groupService = EPersonServiceFactory.getInstance().getGroupService();
|
||||
Group anonymousGroup = groupService.findByName(context, Group.ANONYMOUS);
|
||||
List<ResourcePolicy> policies = authorizeService.findPoliciesByDSOAndType(context, bit, ResourcePolicy.TYPE_CUSTOM);
|
||||
|
||||
for (ResourcePolicy policy : policies) {
|
||||
if (policy.getGroup() == anonymousGroup && policy.getAction() == Constants.READ) {
|
||||
Date startDate = policies.get(0).getStartDate();
|
||||
|
||||
if (startDate != null && startDate.after(new Date())) {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
bitstream.getField().add(
|
||||
createValue("embargo", formatter.format(startDate)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Element createLicenseElement(Context context, Item item)
|
||||
throws SQLException, AuthorizeException, IOException {
|
||||
Element license = create("license");
|
||||
|
@@ -123,6 +123,11 @@
|
||||
<xsl:for-each select="doc:element[@name='bitstreams']/doc:element">
|
||||
<dc:identifier xsi:type="dcterms:URI"><xsl:value-of select="doc:field[@name='url']/text()" /></dc:identifier>
|
||||
<uketdterms:checksum xsi:type="uketdterms:MD5"><xsl:value-of select="doc:field[@name='checksum']/text()" /></uketdterms:checksum>
|
||||
<!-- Add embargo information -->
|
||||
<xsl:if test="ancestor::*/doc:field[@name='name']/text() = 'ORIGINAL'
|
||||
and doc:field[@name='embargo']/text()">
|
||||
<uketdterms:embargodate><xsl:value-of select="doc:field[@name='embargo']/text()" /></uketdterms:embargodate>
|
||||
</xsl:if>
|
||||
</xsl:for-each>
|
||||
</xsl:if>
|
||||
|
||||
|
Reference in New Issue
Block a user