1414import java .util .Iterator ;
1515import java .util .List ;
1616
17+ import org .apache .logging .log4j .LogManager ;
18+ import org .apache .logging .log4j .Logger ;
1719import org .dspace .content .Collection ;
1820import org .dspace .content .Community ;
1921import org .dspace .content .DSpaceObject ;
3739 */
3840@ Distributive
3941public class RemoveAIP extends AbstractCurationTask {
42+ private static final Logger log = LogManager .getLogger ();
43+
4044 private String archFmt ;
4145
4246 // Group where all AIPs are stored
@@ -96,26 +100,26 @@ private void remove(Context context, ReplicaManager repMan, DSpaceObject dso) th
96100
97101 // If it is a Collection, also remove all Items from AIP storage
98102 if (dso instanceof Collection ) {
99- Collection coll = (Collection ) dso ;
100- Iterator <Item > iter = itemService .findByCollection (context , coll );
103+ Collection collection = (Collection ) dso ;
104+ Iterator <Item > iter = itemService .findByCollection (context , collection );
101105 while (iter .hasNext ()) {
102106 remove (context , repMan , iter .next ());
103107 }
104108 } else if (dso instanceof Community ) {
105- // else if it's a Community, also remove all sub-communities, collections (and items) from AIP storage
106- Community comm = (Community ) dso ;
107- for (Community subcomm : comm .getSubcommunities ()) {
108- remove (context , repMan , subcomm );
109+ // else if it is a Community, also remove all sub-communities, collections (and items) from AIP storage
110+ Community community = (Community ) dso ;
111+ for (Community subCommunity : community .getSubcommunities ()) {
112+ remove (context , repMan , subCommunity );
109113 }
110- for (Collection coll : comm .getCollections ()) {
114+ for (Collection coll : community .getCollections ()) {
111115 remove (context , repMan , coll );
112116 }
113117 } else if (dso instanceof Site ) {
114- // else if it's a Site object, remove all top-level communities (and everything else) from AIP storage
118+ // else if it is a Site object, remove all top-level communities (and everything else) from AIP storage
115119 List <Community > topCommunities = communityService .findAllTop (context );
116120
117- for (Community subcomm : topCommunities ) {
118- remove (context , repMan , subcomm );
121+ for (Community subCommunity : topCommunities ) {
122+ remove (context , repMan , subCommunity );
119123 }
120124 }
121125 }
@@ -138,10 +142,16 @@ public int perform(Context ctx, String id) throws IOException {
138142 ReplicaManager repMan = ReplicaManager .instance ();
139143
140144 // If the object is still in DSpace, call perform(dso) instead.
141- DSpaceObject dso = dereference (ctx , id );
142- if (dso != null ) {
143- return perform (dso );
145+ DSpaceObject dso ;
146+ try {
147+ dso = dspaceObjectUtils .findDSpaceObject (ctx ,id );
148+ if (dso != null ) {
149+ return perform (dso );
150+ }
151+ } catch (SQLException sqlE ) {
152+ throw new IOException (sqlE .getMessage (), sqlE );
144153 }
154+
145155 // Otherwise, this object was already previously deleted from DSpace.
146156 // So, we'll treat this as a deletion "garbage clean"
147157
@@ -168,7 +178,11 @@ public int perform(Context ctx, String id) throws IOException {
168178 }
169179
170180 // remove local deletion catalog
171- catFile .delete ();
181+ boolean successful = catFile .delete ();
182+ if (!successful ) {
183+ log .warn ("Unable to delete AIP: {}" , catFile );
184+ }
185+
172186 // remove remote deletion catalog
173187 repMan .removeObject (deleteGroupName , catId );
174188
0 commit comments