Skip to content

Commit 102c01e

Browse files
authored
Updates for compatibility with DSpace 9.3 (DSpace#90)
* fixed instances of Date that should be LocalDate * added new unsupported methods * updated logging library from dspace-api to exclude * set variables to final where applicable * added logging * added null check for collection
1 parent 13aa1e9 commit 102c01e

25 files changed

Lines changed: 144 additions & 124 deletions

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@
331331
<artifactId>jaxb-api</artifactId>
332332
</exclusion>
333333
<exclusion>
334-
<groupId>log4j</groupId>
335-
<artifactId>log4j</artifactId>
334+
<groupId>org.apache.logging.log4j</groupId>
335+
<artifactId>log4j-core</artifactId>
336336
</exclusion>
337337
<exclusion>
338338
<groupId>org.glassfish.jaxb</groupId>

src/main/java/org/dspace/ctask/replicate/AbstractPackagerTask.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
* @see org.dspace.content.packager.PackageIngester
2626
*/
2727
public abstract class AbstractPackagerTask extends AbstractCurationTask {
28+
private static final Logger log = LogManager.getLogger();
29+
2830
// Name of recursive mode option configurable in curation task configuration file
2931
private final String recursiveMode = "recursiveMode";
3032

@@ -34,8 +36,6 @@ public abstract class AbstractPackagerTask extends AbstractCurationTask {
3436
// Name of useCollectionTemplate option configurable in curation task configuration file
3537
private final String useCollectionTemplate = "useCollectionTemplate";
3638

37-
private static Logger log = LogManager.getLogger();
38-
3939
/**
4040
* Loads pre-configured PackageParameters settings from a given Module
4141
* configuration file (specified by 'moduleName').
@@ -47,7 +47,7 @@ public abstract class AbstractPackagerTask extends AbstractCurationTask {
4747
* <p>
4848
* Valid 'options' include all packager options supported by the
4949
* Packager class, e.g. AIP packagers minimally support these options:
50-
* https://wiki.lyrasis.org/display/DSDOC6x/AIP+Backup+and+Restore#AIPBackupandRestore-AdditionalPackagerOptions
50+
* https://wiki.lyrasis.org/display/DSDOC9x/AIP+Backup+and+Restore#AIPBackupandRestore-AdditionalPackagerOptions
5151
* <p>
5252
* Please note that different Packager classes will support different options.
5353
* You should determine which options are valid for your Packager class
@@ -100,7 +100,7 @@ protected PackageParameters loadPackagerParameters(String moduleName) {
100100
pkgParams.addProperty(option, value);
101101
}
102102

103-
log.debug("Set package parameter property <" + option + "> to value <" + value + ">");
103+
log.debug("Set package parameter property <{}> to value <{}>", option, value);
104104
}
105105
}
106106

src/main/java/org/dspace/ctask/replicate/BagItReplaceWithAIP.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,16 @@
4040
*/
4141
@Mutative
4242
public class BagItReplaceWithAIP extends AbstractCurationTask {
43+
private final CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
44+
private final CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
45+
private final ItemService itemService = ContentServiceFactory.getInstance().getItemService();
46+
private final SiteService siteService = ContentServiceFactory.getInstance().getSiteService();
4347

4448
private String archFmt;
4549

4650
// Group where all AIPs are stored
4751
private String storeGroupName;
4852

49-
private CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
50-
private CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
51-
private ItemService itemService = ContentServiceFactory.getInstance().getItemService();
52-
private SiteService siteService = ContentServiceFactory.getInstance().getSiteService();
53-
5453
@Override
5554
public void init(Curator curator, String taskId) throws IOException {
5655
super.init(curator, taskId);

src/main/java/org/dspace/ctask/replicate/BagItReplicateConsumer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@
6262
* @author richardrodgers
6363
*/
6464
public class BagItReplicateConsumer implements Consumer {
65-
private Logger log = LogManager.getLogger();
65+
private final Logger log = LogManager.getLogger();
6666

67-
private ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
68-
private PluginService pluginService = CoreServiceFactory.getInstance().getPluginService();
69-
private CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
70-
private CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
71-
private ItemService itemService = ContentServiceFactory.getInstance().getItemService();
67+
private final ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
68+
private final PluginService pluginService = CoreServiceFactory.getInstance().getPluginService();
69+
private final CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
70+
private final CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
71+
private final ItemService itemService = ContentServiceFactory.getInstance().getItemService();
7272

7373
private ReplicaManager repMan = null;
7474
private TaskQueue taskQueue = null;

src/main/java/org/dspace/ctask/replicate/BagItRestoreFromAIP.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@
5757
@Distributive
5858
@Mutative
5959
public class BagItRestoreFromAIP extends AbstractCurationTask {
60+
private static final Logger log = LogManager.getLogger();
61+
62+
private final EmbargoService embargoService = EmbargoServiceFactory.getInstance().getEmbargoService();
63+
private final WorkspaceItemService workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService();
64+
private final InstallItemService installItemService = ContentServiceFactory.getInstance().getInstallItemService();
65+
private final CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
6066

61-
private static Logger log = LogManager.getLogger();
6267
private String archFmt;
6368

6469
// Group where all AIPs are stored
@@ -67,11 +72,6 @@ public class BagItRestoreFromAIP extends AbstractCurationTask {
6772
// Group where object deletion catalog/records are stored
6873
private String deleteGroupName;
6974

70-
private EmbargoService embargoService = EmbargoServiceFactory.getInstance().getEmbargoService();
71-
private WorkspaceItemService workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService();
72-
private InstallItemService installItemService = ContentServiceFactory.getInstance().getInstallItemService();
73-
private CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
74-
7575
@Override
7676
public void init(Curator curator, String taskId) throws IOException {
7777
super.init(curator, taskId);
@@ -224,10 +224,10 @@ private void recoverItem(Context ctx, File archive, String objId, Properties pro
224224
packer.unpack(archive);
225225
// Install item
226226
Item item = installItemService.restoreItem(ctx, wi, objId);
227-
String colls = props.getProperty(OTHER_IDS);
228-
if (colls != null) {
227+
String collections = props.getProperty(OTHER_IDS);
228+
if (collections != null) {
229229
// reset linked collections
230-
for (String link : colls.split(",")) {
230+
for (String link : collections.split(",")) {
231231
Collection linkC = (Collection) handleService.resolveToObject(ctx, link);
232232
collectionService.addItem(ctx, linkC, item);
233233
}
@@ -251,17 +251,21 @@ private void recoverItem(Context ctx, File archive, String objId, Properties pro
251251
* @throws IOException if IO error
252252
*/
253253
private void recoverCollection(Context ctx, File archive, String collId, String commId) throws IOException {
254-
Collection coll = null;
255254
try {
256255
if (commId != null) {
257-
Community pcomm = (Community) handleService.resolveToObject(ctx, commId);
258-
coll = collectionService.create(ctx, pcomm, collId);
256+
Community parentCommunity = (Community) handleService.resolveToObject(ctx, commId);
257+
Collection collection = collectionService.create(ctx, parentCommunity, collId);
258+
259+
if (collection != null) {
260+
// update with AIP data
261+
Packer packer = PackerFactory.instance(ctx, collection);
262+
packer.unpack(archive);
263+
} else {
264+
log.error("Unable to restore collection {} because it could not be found.", collId);
265+
}
259266
} else {
260-
log.error("Collection '" + collId + "' lacks parent community");
267+
log.error("Collection '{}' lacks parent community", collId);
261268
}
262-
// update with AIP data
263-
Packer packer = PackerFactory.instance(ctx, coll);
264-
packer.unpack(archive);
265269
} catch (AuthorizeException | SQLException authE) {
266270
throw new IOException(authE);
267271
}
@@ -277,16 +281,17 @@ private void recoverCollection(Context ctx, File archive, String collId, String
277281
*/
278282
private void recoverCommunity(Context ctx, File archive, String commId, String parentId) throws IOException {
279283
// if not top-level, have parent create it
280-
Community comm = null;
284+
Community community = null;
281285
try {
282286
if (parentId != null) {
283-
Community pcomm = (Community) handleService.resolveToObject(ctx, parentId);
284-
comm = communityService.createSubcommunity(ctx, pcomm, commId);
287+
Community parentCommunity = (Community) handleService.resolveToObject(ctx, parentId);
288+
community = communityService.createSubcommunity(ctx, parentCommunity, commId);
285289
} else {
286-
comm = communityService.create(null, ctx, commId);
290+
community = communityService.create(null, ctx, commId);
287291
}
292+
288293
// update with AIP data
289-
Packer packer = PackerFactory.instance(ctx, comm);
294+
Packer packer = PackerFactory.instance(ctx, community);
290295
packer.unpack(archive);
291296
} catch (AuthorizeException | SQLException authE) {
292297
throw new IOException(authE);

src/main/java/org/dspace/ctask/replicate/METSReplicateConsumer.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@
8282
* @author richardrodgers
8383
*/
8484
public class METSReplicateConsumer implements Consumer {
85-
private Logger log = LogManager.getLogger();
86-
87-
private ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
88-
private PluginService pluginService = CoreServiceFactory.getInstance().getPluginService();
89-
private SiteService siteService = ContentServiceFactory.getInstance().getSiteService();
90-
private CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
91-
private CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
92-
private ItemService itemService = ContentServiceFactory.getInstance().getItemService();
85+
private final Logger log = LogManager.getLogger();
86+
87+
private final ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
88+
private final PluginService pluginService = CoreServiceFactory.getInstance().getPluginService();
89+
private final SiteService siteService = ContentServiceFactory.getInstance().getSiteService();
90+
private final CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
91+
private final CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
92+
private final ItemService itemService = ContentServiceFactory.getInstance().getItemService();
9393

9494
private ReplicaManager repMan = null;
9595
private TaskQueue taskQueue = null;

src/main/java/org/dspace/ctask/replicate/METSRestoreFromAIP.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
@Distributive
3434
@Mutative
3535
public class METSRestoreFromAIP extends AbstractPackagerTask {
36-
private Logger log = LogManager.getLogger();
36+
private final Logger log = LogManager.getLogger();
3737

3838
private String archFmt;
3939

src/main/java/org/dspace/ctask/replicate/MoveToTrashSingleAIP.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
/**
2323
* MoveToTrashSingleAIP task moves a single AIP from one group (folder) in external
24-
* storage to another group (folder). Currently it always moves content
24+
* storage to another group (folder). Currently, it always moves content
2525
* from the 'group.aip.name' store to the 'group.delete.name' store, essentially
2626
* moving the content into a "trash" folder.
2727
* <P>
@@ -37,8 +37,6 @@
3737
*/
3838
@Distributive
3939
public class MoveToTrashSingleAIP extends AbstractCurationTask {
40-
private static Logger log = LogManager.getLogger();
41-
4240
// Source and destination group where AIP will be moved to
4341
private String srcGroupName;
4442
private String destGroupName;

src/main/java/org/dspace/ctask/replicate/RemoveAIP.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
public class RemoveAIP extends AbstractCurationTask {
4242
private static final Logger log = LogManager.getLogger();
4343

44+
private final CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
45+
private final ItemService itemService = ContentServiceFactory.getInstance().getItemService();
46+
4447
private String archFmt;
4548

4649
// Group where all AIPs are stored
@@ -49,9 +52,6 @@ public class RemoveAIP extends AbstractCurationTask {
4952
// Group where object deletion catalog/records are stored
5053
private String deleteGroupName;
5154

52-
private CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
53-
private ItemService itemService = ContentServiceFactory.getInstance().getItemService();
54-
5555
@Override
5656
public void init(Curator curator, String taskId) throws IOException {
5757
super.init(curator, taskId);

src/main/java/org/dspace/ctask/replicate/ReplicaManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
* @author richardrodgers
4141
*/
4242
public class ReplicaManager {
43-
private ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
44-
private PluginService pluginService = CoreServiceFactory.getInstance().getPluginService();
45-
private HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
43+
private final ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
44+
private final PluginService pluginService = CoreServiceFactory.getInstance().getPluginService();
45+
private final HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
4646

47-
private Logger log = LogManager.getLogger();
47+
private final Logger log = LogManager.getLogger();
4848
// singleton instance
4949
private static ReplicaManager instance = null;
5050
// the replica provider

0 commit comments

Comments
 (0)