@@ -53,6 +53,7 @@ public class DatashareItemDataset {
5353 private static final String DATASHARE_SCHEMA = "ds" ;
5454 private static final String TOMBSTONE_ELEMENT = "withdrawn" ;
5555 private static final String TOMBSTONE_SHOW_QUALIFIER = "showtombstone" ;
56+ private static final String DC_DATE_EMBARGO = "dc.date.embargo" ;
5657
5758 // Static variables
5859 private static String dir = null ;
@@ -341,12 +342,27 @@ public static String getShowTombstone(Item item) {
341342 public static boolean hasEmbargo (Context context , Item item ) {
342343 boolean hasEmbargo = true ;
343344 ItemService itemService = ContentServiceFactory .getInstance ().getItemService ();
344- ConfigurationService configurationService = DSpaceServicesFactory .getInstance ().getConfigurationService ();
345345
346- List <MetadataValue > embargoList = itemService .getMetadataByMetadataString (item ,
347- configurationService .getProperty ("embargo.field.lift" ));
346+ // List<MetadataValue> embargoList = itemService.getMetadataByMetadataString(item,
347+ // configurationService.getProperty("embargo.field.lift"));
348+ List <MetadataValue > embargoList = itemService .getMetadataByMetadataString (item , DC_DATE_EMBARGO );
348349 if (embargoList == null || embargoList .size () == 0 ) {
349350 hasEmbargo = false ;
351+ } else {
352+ // Check if embargo date is in the past
353+ try {
354+ String embargoDateStr = embargoList .get (0 ).getValue ();
355+ log .info ("embargoDateStr: " + embargoDateStr );
356+
357+ Date embargoDate = parseDate (embargoDateStr );
358+ Date now = new Date ();
359+ log .info ("embargoDate: " + embargoDate + ", now: " + now );
360+ if (embargoDate != null && embargoDate .after (now )) {
361+ hasEmbargo = false ;
362+ }
363+ } catch (Exception ex ) {
364+ log .error ("Problem parsing embargo date: " + ex .getMessage ());
365+ }
350366 }
351367
352368 log .info (item .getID () + " hasEmbargo: " + hasEmbargo );
@@ -384,6 +400,30 @@ private static boolean isTombstoned(Context context, Item item) {
384400 log .info ("isTombstoned(): " + show );
385401 return show ;
386402 }
403+
404+ /**
405+ * Parse a date string in ISO format yyyy-MM-dd and return a Date
406+ * representing the start of that day in the system default timezone.
407+ * Returns null when the input is null, empty or not in the expected format.
408+ *
409+ * @param dateStr date string expected in yyyy-MM-dd
410+ * @return parsed Date or null
411+ */
412+ public static Date parseDate (String dateStr ) {
413+ if (dateStr == null || dateStr .trim ().isEmpty ()) {
414+ return null ;
415+ }
416+ try {
417+ // Use Java 8 date time API to parse date
418+ java .time .LocalDate ld = java .time .LocalDate .parse (dateStr ,
419+ java .time .format .DateTimeFormatter .ISO_LOCAL_DATE );
420+ java .time .ZonedDateTime zdt = ld .atStartOfDay (java .time .ZoneId .systemDefault ());
421+ return Date .from (zdt .toInstant ());
422+ } catch (java .time .format .DateTimeParseException ex ) {
423+ log .error ("Problem parsing date: " + ex .getMessage ());
424+ return null ;
425+ }
426+ }
387427
388428 /**
389429 * Create dataset zip file in a seperate thread.
0 commit comments