1111import java .io .IOException ;
1212import java .io .InputStream ;
1313import java .sql .SQLException ;
14+ import java .text .SimpleDateFormat ;
15+ import java .util .Date ;
1416import java .util .List ;
1517
1618import com .lyncode .xoai .dataprovider .xml .xoai .Element ;
2123import org .dspace .app .util .factory .UtilServiceFactory ;
2224import org .dspace .app .util .service .MetadataExposureService ;
2325import org .dspace .authorize .AuthorizeException ;
26+ import org .dspace .authorize .ResourcePolicy ;
27+ import org .dspace .authorize .factory .AuthorizeServiceFactory ;
28+ import org .dspace .authorize .service .AuthorizeService ;
2429import org .dspace .content .Bitstream ;
2530import org .dspace .content .Bundle ;
2631import org .dspace .content .Item ;
3439import org .dspace .core .Constants ;
3540import org .dspace .core .Context ;
3641import org .dspace .core .Utils ;
42+ import org .dspace .eperson .Group ;
43+ import org .dspace .eperson .factory .EPersonServiceFactory ;
44+ import org .dspace .eperson .service .GroupService ;
3745import org .dspace .services .ConfigurationService ;
3846import org .dspace .services .factory .DSpaceServicesFactory ;
3947import 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" );
0 commit comments