Skip to content

Commit db81d75

Browse files
committed
OAI: add support to extract embargo from bitstreams and expose it in OAI metadata
1 parent a533704 commit db81d75

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

dspace-oai/src/main/java/org/dspace/xoai/util/ItemUtils.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import java.io.IOException;
1212
import java.io.InputStream;
1313
import java.sql.SQLException;
14+
import java.text.SimpleDateFormat;
15+
import java.util.Date;
1416
import java.util.List;
1517

1618
import com.lyncode.xoai.dataprovider.xml.xoai.Element;
@@ -21,6 +23,9 @@
2123
import org.dspace.app.util.factory.UtilServiceFactory;
2224
import org.dspace.app.util.service.MetadataExposureService;
2325
import org.dspace.authorize.AuthorizeException;
26+
import org.dspace.authorize.ResourcePolicy;
27+
import org.dspace.authorize.factory.AuthorizeServiceFactory;
28+
import org.dspace.authorize.service.AuthorizeService;
2429
import org.dspace.content.Bitstream;
2530
import org.dspace.content.Bundle;
2631
import org.dspace.content.Item;
@@ -34,6 +39,9 @@
3439
import org.dspace.core.Constants;
3540
import org.dspace.core.Context;
3641
import org.dspace.core.Utils;
42+
import org.dspace.eperson.Group;
43+
import org.dspace.eperson.factory.EPersonServiceFactory;
44+
import org.dspace.eperson.service.GroupService;
3745
import org.dspace.services.ConfigurationService;
3846
import org.dspace.services.factory.DSpaceServicesFactory;
3947
import org.dspace.xoai.data.DSpaceItem;
@@ -57,6 +65,9 @@ public class ItemUtils {
5765
private static final BitstreamService bitstreamService
5866
= ContentServiceFactory.getInstance().getBitstreamService();
5967

68+
private static final AuthorizeService authorizeService =
69+
AuthorizeServiceFactory.getInstance().getAuthorizeService();
70+
6071
private static final ConfigurationService configurationService
6172
= DSpaceServicesFactory.getInstance().getConfigurationService();
6273
/**
@@ -136,6 +147,9 @@ private static Element createBundlesElement(Context context, Item item) throws S
136147
if (description != null) {
137148
bitstream.getField().add(createValue("description", description));
138149
}
150+
// Add bitstream embargo information (READ policy present, for Anonymous group with a start date)
151+
addEmbargoField(context, bit, bitstream);
152+
139153
bitstream.getField().add(createValue("format", bit.getFormat(context).getMIMEType()));
140154
bitstream.getField().add(createValue("size", "" + bit.getSizeBytes()));
141155
bitstream.getField().add(createValue("url", url));
@@ -148,6 +162,24 @@ private static Element createBundlesElement(Context context, Item item) throws S
148162
return bundles;
149163
}
150164

165+
private static void addEmbargoField(Context context, Bitstream bit, Element bitstream) throws SQLException {
166+
GroupService groupService = EPersonServiceFactory.getInstance().getGroupService();
167+
Group anonymousGroup = groupService.findByName(context, Group.ANONYMOUS);
168+
List<ResourcePolicy> policies = authorizeService.findPoliciesByDSOAndType(context, bit, ResourcePolicy.TYPE_CUSTOM);
169+
170+
for (ResourcePolicy policy : policies) {
171+
if (policy.getGroup() == anonymousGroup && policy.getAction() == Constants.READ) {
172+
Date startDate = policies.get(0).getStartDate();
173+
174+
if (startDate != null && startDate.after(new Date())) {
175+
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
176+
bitstream.getField().add(
177+
createValue("embargo", formatter.format(startDate)));
178+
}
179+
}
180+
}
181+
}
182+
151183
private static Element createLicenseElement(Context context, Item item)
152184
throws SQLException, AuthorizeException, IOException {
153185
Element license = create("license");

dspace/config/crosswalks/oai/metadataFormats/uketd_dc.xsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@
123123
<xsl:for-each select="doc:element[@name='bitstreams']/doc:element">
124124
<dc:identifier xsi:type="dcterms:URI"><xsl:value-of select="doc:field[@name='url']/text()" /></dc:identifier>
125125
<uketdterms:checksum xsi:type="uketdterms:MD5"><xsl:value-of select="doc:field[@name='checksum']/text()" /></uketdterms:checksum>
126+
<!-- Add embargo information -->
127+
<xsl:if test="ancestor::*/doc:field[@name='name']/text() = 'ORIGINAL'
128+
and doc:field[@name='embargo']/text()">
129+
<uketdterms:embargodate><xsl:value-of select="doc:field[@name='embargo']/text()" /></uketdterms:embargodate>
130+
</xsl:if>
126131
</xsl:for-each>
127132
</xsl:if>
128133

0 commit comments

Comments
 (0)