@@ -105,6 +105,10 @@ public class ItemUpdate {
105105
106106 private static final String EMBARGO_FIELD_RIGHTS_ACCESS = "dc.rights.access" ;
107107 private static final String EMBARGO_FIELD_DATE_END = "dc.date.embargoend" ;
108+ private static final String EMBARGOED_ACCESS = "embargoedAccess" ;
109+ private static final String STANDARD_EMBARGO_POLICY_NAME = "Standard Embargo" ;
110+ // Must fit resourcepolicy.rpname length (varchar(30))
111+ private static final String SPECIAL_CASE_EMBARGO_POLICY_NAME = "Special Case Embargo" ;
108112
109113 static {
110114 filterAliases .put ("ORIGINAL" , "org.dspace.app.itemupdate.OriginalBitstreamFilter" );
@@ -398,6 +402,25 @@ public static void main(String[] argv) {
398402 * @param isTest test flag
399403 * @throws Exception if error
400404 */
405+ protected void processArchive (Context context , String sourceDirPath , String itemField ,
406+ String metadataIndexName , boolean alterProvenance , boolean isTest )
407+ throws Exception {
408+ processArchive (context , sourceDirPath , itemField , metadataIndexName , alterProvenance , isTest , false );
409+ }
410+
411+ /**
412+ * process an archive
413+ *
414+ * @param context DSpace Context
415+ * @param sourceDirPath source path
416+ * @param itemField item field
417+ * @param metadataIndexName index name
418+ * @param alterProvenance whether to alter provenance
419+ * @param isTest test flag
420+ * @param syncEmbargoPolicies if true, synchronize bitstream embargo resource policies with the embargo metadata
421+ * (dc.rights.access, dc.date.embargoend) after the SAF update is applied
422+ * @throws Exception if error
423+ */
401424 protected void processArchive (Context context , String sourceDirPath , String itemField ,
402425 String metadataIndexName , boolean alterProvenance , boolean isTest ,
403426 boolean syncEmbargoPolicies )
@@ -617,10 +640,13 @@ protected void syncEmbargoPolicies(Context context, Item item) throws SQLExcepti
617640 clearExistingSafEmbargoPolicies (context , item );
618641
619642 List <MetadataValue > embargoEndDates = itemService .getMetadata (item , "dc" , "date" , "embargoend" , Item .ANY );
643+ if (embargoEndDates .size () > 1 ) {
644+ ItemUpdate .pr ("WARNING: Multiple dc.date.embargoend values found. Using first value only." );
645+ }
620646 if (embargoEndDates .isEmpty ()) {
621647 List <MetadataValue > accessRights = itemService .getMetadata (item , "dc" , "rights" , "access" , Item .ANY );
622648 for (MetadataValue accessRight : accessRights ) {
623- if ("embargoedAccess" .equals (accessRight .getValue ())) {
649+ if (EMBARGOED_ACCESS .equals (accessRight .getValue ())) {
624650 ItemUpdate .pr ("WARNING: Item has dc.rights.access=embargoedAccess but no dc.date.embargoend. "
625651 + "Cannot set embargo without end date." );
626652 break ;
@@ -635,42 +661,35 @@ protected void syncEmbargoPolicies(Context context, Item item) throws SQLExcepti
635661 return ;
636662 }
637663
638- Date accessStartDate ;
639- try {
640- DCDate embargoEndDate = new DCDate (embargoEndDateStr );
641- Date endDate = embargoEndDate .toDate ();
642- if (endDate == null ) {
643- ItemUpdate .pr ("ERROR: Invalid embargo end date format: " + embargoEndDateStr );
644- return ;
645- }
646-
647- if (endDate .before (new Date ())) {
648- ItemUpdate .pr ("WARNING: Embargo end date is in the past: " + embargoEndDateStr
649- + ". Embargo will not be applied." );
650- return ;
651- }
664+ DCDate embargoEndDate = new DCDate (embargoEndDateStr );
665+ Date endDate = embargoEndDate .toDate ();
666+ if (endDate == null ) {
667+ ItemUpdate .pr ("ERROR: Invalid embargo end date format: " + embargoEndDateStr );
668+ return ;
669+ }
652670
653- Calendar cal = Calendar .getInstance ();
654- cal .setTime (endDate );
655- cal .add (Calendar .DAY_OF_MONTH , 1 );
656- accessStartDate = cal .getTime ();
657- } catch (Exception e ) {
658- ItemUpdate .pr ("ERROR: Failed to parse embargo end date: " + embargoEndDateStr
659- + ". Error: " + e .getMessage ());
671+ if (endDate .before (new Date ())) {
672+ ItemUpdate .pr ("WARNING: Embargo end date is in the past: " + embargoEndDateStr
673+ + ". Embargo will not be applied." );
660674 return ;
661675 }
662676
677+ Calendar cal = Calendar .getInstance ();
678+ cal .setTime (endDate );
679+ cal .add (Calendar .DAY_OF_MONTH , 1 );
680+ Date accessStartDate = cal .getTime ();
681+
663682 List <MetadataValue > accessRights = itemService .getMetadata (item , "dc" , "rights" , "access" , Item .ANY );
664683 boolean hasEmbargoedAccess = false ;
665684 for (MetadataValue accessRight : accessRights ) {
666- if ("embargoedAccess" .equals (accessRight .getValue ())) {
685+ if (EMBARGOED_ACCESS .equals (accessRight .getValue ())) {
667686 hasEmbargoedAccess = true ;
668687 break ;
669688 }
670689 }
671690
672- String policyReason = hasEmbargoedAccess ? "Standard Embargo"
673- : "Special Case Embargo - No access rights metadata" ;
691+ String policyReason = hasEmbargoedAccess ? STANDARD_EMBARGO_POLICY_NAME
692+ : SPECIAL_CASE_EMBARGO_POLICY_NAME ;
674693 applyEmbargoToItemBitstreams (context , item , accessStartDate , policyReason );
675694 }
676695
@@ -680,16 +699,16 @@ protected void clearExistingSafEmbargoPolicies(Context context, Item item) throw
680699 return ;
681700 }
682701
683- List <Bundle > originalBundles = item .getBundles ("ORIGINAL" );
702+ List <Bundle > originalBundles = item .getBundles (Constants . CONTENT_BUNDLE_NAME );
684703 for (Bundle bundle : originalBundles ) {
685704 for (Bitstream bitstream : bundle .getBitstreams ()) {
686705 List <ResourcePolicy > readPolicies = resourcePolicyService .find (context , bitstream , Constants .READ );
687706 for (ResourcePolicy policy : readPolicies ) {
688707 if (policy .getGroup () != null
689708 && anonymousGroup .equals (policy .getGroup ())
690709 && policy .getStartDate () != null
691- && ("Standard Embargo" .equals (policy .getRpName ())
692- || "Special Case Embargo - No access rights metadata" .equals (policy .getRpName ()))) {
710+ && (STANDARD_EMBARGO_POLICY_NAME .equals (policy .getRpName ())
711+ || SPECIAL_CASE_EMBARGO_POLICY_NAME .equals (policy .getRpName ()))) {
693712 resourcePolicyService .delete (context , policy );
694713 }
695714 }
@@ -704,7 +723,7 @@ protected void applyEmbargoToItemBitstreams(Context context, Item item, Date sta
704723 return ;
705724 }
706725
707- List <Bundle > originalBundles = item .getBundles ("ORIGINAL" );
726+ List <Bundle > originalBundles = item .getBundles (Constants . CONTENT_BUNDLE_NAME );
708727 for (Bundle bundle : originalBundles ) {
709728 for (Bitstream bitstream : bundle .getBitstreams ()) {
710729 removeImmediateAnonymousReadPolicies (context , bitstream , anonymousGroup );
0 commit comments