Skip to content

Commit 0982f65

Browse files
committed
improved logging; lint fixes; corrected typos
1 parent 7718a33 commit 0982f65

12 files changed

Lines changed: 87 additions & 64 deletions

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

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

6867
private ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
@@ -175,10 +174,9 @@ public void consume(Context ctx, Event event) throws Exception {
175174
case MODIFY_METADATA: // MODIFY_METADATA = just modify an object's metadata
176175
// If subject of event is null, this means the object was likely deleted
177176
if (event.getSubject(ctx) == null) {
178-
log.warn(event.getEventTypeAsString() + " event, could not get object for "
179-
+ event.getSubjectTypeAsString() + " id="
180-
+ String.valueOf(event.getSubjectID())
181-
+ ", perhaps it has been deleted.");
177+
log.warn("{} event, could not get object for {} id={}, perhaps it has been deleted.",
178+
event.getEventTypeAsString(), event.getSubjectTypeAsString(),
179+
String.valueOf(event.getSubjectID()));
182180
break;
183181
}
184182

@@ -243,7 +241,7 @@ public void end(Context ctx) throws Exception {
243241
taskPMap.clear();
244242
}
245243

246-
// if there any uncommitted deletions, record them now
244+
// if there are any uncommitted deletions, record them now
247245
if (delObjId != null) {
248246
if (delTasks != null) {
249247
entrySet.add(new TaskQueueEntry(name, stamp, delTasks, delObjId));
@@ -362,7 +360,7 @@ private void processDelete(Context context) throws IOException {
362360
String catID = repMan.deletionCatalogId(delObjId, null);
363361
File packDir = repMan.stage(context, deleteGroupName, catID);
364362
File archive = packer.pack(packDir);
365-
// System.out.println("delcat about to transfer");
363+
// System.out.println("deleted catalog about to transfer");
366364
repMan.transferObject(deleteGroupName, archive);
367365
}
368366
} catch (AuthorizeException | SQLException e) {
@@ -394,7 +392,7 @@ private boolean loadIdFilter(String filterName) {
394392
}
395393
return true;
396394
} catch (IOException ioE) {
397-
// log.error("Unable to read filter file '" + filterName + "'");
395+
// log.error("Unable to read filter file '{}'", filterName);
398396
idFilter = null;
399397
} finally {
400398
if (reader != null) {

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.util.Iterator;
1515
import java.util.List;
1616

17+
import org.apache.logging.log4j.LogManager;
18+
import org.apache.logging.log4j.Logger;
1719
import org.dspace.authorize.AuthorizeException;
1820
import org.dspace.content.Collection;
1921
import org.dspace.content.Community;
@@ -51,6 +53,8 @@
5153
*/
5254
@Suspendable(invoked = Curator.Invoked.INTERACTIVE)
5355
public class CompareWithAIP extends AbstractCurationTask {
56+
private final Logger log = LogManager.getLogger();
57+
5458
private String archFmt;
5559
private int status = Curator.CURATE_UNSET;
5660
private String result = null;
@@ -88,7 +92,10 @@ public int perform(DSpaceObject dso) throws IOException {
8892
File archive = packer.pack(packDir);
8993
String chkSum = Utils.checksum(archive, "MD5");
9094
// remove local archive file -- it's no longer needed
91-
archive.delete();
95+
//boolean successful = archive.delete();
96+
//if (!successful) {
97+
// log.warn("Failed to delete archive {}", archive.getAbsolutePath());
98+
//}
9299

93100
// compare with replica
94101
String repChkSum = repMan.objectAttribute(storeGroupName, objId, "checksum");
@@ -133,25 +140,25 @@ private void auditExtent(Context context, ReplicaManager repMan, DSpaceObject ds
133140

134141
// If container is a Collection, make sure all Items have AIPs in remote storage
135142
if (Constants.COLLECTION == type) {
136-
Collection coll = (Collection)dso;
137-
Iterator<Item> iter = itemService.findByCollection(context, coll);
143+
Collection collection = (Collection)dso;
144+
Iterator<Item> iter = itemService.findByCollection(context, collection);
138145
while (iter.hasNext()) {
139146
checkReplica(context, repMan, iter.next());
140147
}
141148
} else if (Constants.COMMUNITY == type) {
142-
// If Community, make sure all Sub-Communities/Collections have AIPs in remote storage
143-
Community comm = (Community)dso;
144-
for (Community subcomm : comm.getSubcommunities()) {
145-
checkReplica(context, repMan, subcomm);
149+
// If it is a Community, make sure all Sub-Communities/Collections have AIPs in remote storage
150+
Community community = (Community)dso;
151+
for (Community subCommunity : community.getSubcommunities()) {
152+
checkReplica(context, repMan, subCommunity);
146153
}
147-
for (Collection coll : comm.getCollections()) {
148-
checkReplica(context, repMan, coll);
154+
for (Collection collection : community.getCollections()) {
155+
checkReplica(context, repMan, collection);
149156
}
150157
} else if (Constants.SITE == type) {
151-
// If Site, check to see all Top-Level Communities have an AIP in remote storage
152-
List<Community> topComm = communityService.findAllTop(context);
153-
for (Community comm : topComm) {
154-
checkReplica(context, repMan, comm);
158+
// If it is a Site, check to see all Top-Level Communities have an AIP in remote storage
159+
List<Community> topCommunities = communityService.findAllTop(context);
160+
for (Community topCommunity : topCommunities) {
161+
checkReplica(context, repMan, topCommunity);
155162
}
156163
}
157164
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public int perform(DSpaceObject dso) throws IOException {
6363
}
6464
}
6565

66-
6766
/**
6867
* Perform the 'Fetch AIP' task
6968
* @param ctx DSpace Context

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
* @author Tim Donohue
4242
*/
4343
public class FilteredFileTaskQueue extends FileTaskQueue {
44-
private static Logger log = LogManager.getLogger();
45-
4644
/**
4745
* Returns the set of UNIQUE task entries from the named queue. Any duplicate
4846
* task entries in the queue are ignored. The operation locks

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
* @author richardrodgers
8383
*/
8484
public class METSReplicateConsumer implements Consumer {
85-
8685
private Logger log = LogManager.getLogger();
8786

8887
private ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
@@ -255,10 +254,9 @@ public void consume(Context ctx, Event event) throws Exception {
255254
case MODIFY_METADATA: // MODIFY_METADATA = just modify an object's metadata
256255
// If subject of event is null, this means the object was likely deleted
257256
if (event.getSubject(ctx) == null) {
258-
log.warn(event.getEventTypeAsString() + " event, could not get object for "
259-
+ event.getSubjectTypeAsString() + " id="
260-
+ String.valueOf(event.getSubjectID())
261-
+ ", perhaps it has been deleted.");
257+
log.warn("{} event, could not get object for {} id={}, perhaps it has been deleted.",
258+
event.getEventTypeAsString(), event.getSubjectTypeAsString(),
259+
String.valueOf(event.getSubjectID()));
262260
break;
263261
}
264262

@@ -329,7 +327,7 @@ public void end(Context ctx) throws Exception {
329327
taskPMap.clear();
330328
}
331329

332-
// if there any uncommitted deletions, record them now
330+
// if there are any uncommitted deletions, record them now
333331
if (delObjId != null) {
334332
if (delTasks != null) {
335333
entrySet.add(new TaskQueueEntry(name, stamp, delTasks, delObjId));
@@ -566,7 +564,7 @@ private void parseTasks(String propName) {
566564
}
567565
} else {
568566
// Otherwise (if the task ends in "+p"),
569-
// it should be added to the list of tasks to perform immediately
567+
// it should be added to the list of tasks to perform immediately
570568
String sTask = task.substring(0, task.lastIndexOf("+p"));
571569
if ("add".equals(propName)) {
572570
if (addPTasks == null) {

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ public int perform(Context ctx, String id) throws IOException {
9393
// remove the deletion catalog (as the object is now restored)
9494
repMan.removeObject(deleteGroupName, catId);
9595
// remove from local cache as well
96-
catArchive.delete();
96+
boolean successful = catArchive.delete();
97+
if (!successful) {
98+
log.warn("Unable to delete object: {}", catArchive);
99+
}
97100
}
98101

99102
result = getSuccessMsg(id, pkgParams);
@@ -146,12 +149,15 @@ private void restoreObject(Context context, ReplicaManager repMan, File archive,
146149

147150
// Remove the locally cached archive file - it is no longer needed.
148151
if (archive.exists()) {
149-
archive.delete();
152+
boolean successful = archive.delete();
153+
if (!successful) {
154+
log.warn("Unable to delete archived file: {}", archive);
155+
}
150156
}
151157

152158
// check if recursiveMode is enabled (restore/replace multiple objects)
153159
if (pkgParams.recursiveModeEnabled()) {
154-
// See if this package refered to child packages,
160+
// See if this package referred to child packages,
155161
// if so, we want to also replace those child objects
156162
List<String> childPkgRefs = packer.getChildPackageRefs();
157163
if (childPkgRefs != null && !childPkgRefs.isEmpty()) {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@
3737
*/
3838
@Distributive
3939
public class MoveToTrashSingleAIP extends AbstractCurationTask {
40+
private static Logger log = LogManager.getLogger();
41+
4042
// Source and destination group where AIP will be moved to
4143
private String srcGroupName;
4244
private String destGroupName;
43-
4445
private String archFmt;
4546

46-
private static Logger log = LogManager.getLogger();
47-
4847
@Override
4948
public void init(Curator curator, String taskId) throws IOException {
5049
super.init(curator, taskId);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.io.IOException;
1313
import java.sql.SQLException;
1414

15+
import org.apache.logging.log4j.LogManager;
16+
import org.apache.logging.log4j.Logger;
1517
import org.dspace.authorize.AuthorizeException;
1618
import org.dspace.content.DSpaceObject;
1719
import org.dspace.core.Context;
@@ -42,12 +44,15 @@
4244
*/
4345
@Suspendable(invoked = Curator.Invoked.INTERACTIVE)
4446
public class TransmitAIP extends AbstractCurationTask {
47+
private static final Logger log = LogManager.getLogger();
48+
4549
// Group where all AIPs will be stored
4650
private String storeGroupName;
4751

4852
@Override
4953
public void init(Curator curator, String taskId) throws IOException {
5054
super.init(curator, taskId);
55+
log.info("Init TransmitAIP");
5156
storeGroupName = configurationService.getProperty("replicate.group.aip.name");
5257
}
5358

src/main/java/org/dspace/ctask/replicate/checkm/TransmitManifest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ public int perform(DSpaceObject dso) throws IOException {
102102
manFile = siteManifest(context, repMan, (Site)dso);
103103
}
104104

105-
repMan.transferObject(manifestGroupName, manFile);
105+
if (manFile != null) {
106+
repMan.transferObject(manifestGroupName, manFile);
107+
}
106108
} catch (SQLException sqlE) {
107109
throw new IOException(sqlE);
108110
}
@@ -219,7 +221,7 @@ private File collectionManifest(Context context, ReplicaManager repMan, Collecti
219221
// Manifests stored as text files
220222
String filename = repMan.storageId(context, coll.getHandle(), MANIFEST_EXTENSION);
221223

222-
log.debug("Creating manifest for: " + coll.getHandle());
224+
log.debug("Creating manifest for collection: {}", coll.getHandle());
223225

224226
//Create Collection manifest
225227
File manFile = repMan.stage(context, manifestGroupName, filename);
@@ -241,7 +243,7 @@ private File collectionManifest(Context context, ReplicaManager repMan, Collecti
241243
}
242244

243245
writer.close();
244-
report("Created manifest for: " + coll.getHandle());
246+
report("Created manifest for collection: " + coll.getHandle());
245247
return manFile;
246248
}
247249

@@ -258,7 +260,7 @@ private File collectionManifest(Context context, ReplicaManager repMan, Collecti
258260
private File itemManifest(Context context, ReplicaManager repMan, Item item) throws IOException, SQLException {
259261
String filename = repMan.storageId(context, item.getHandle(), MANIFEST_EXTENSION);
260262

261-
log.debug("Creating manifest for: " + item.getHandle());
263+
log.debug("Creating manifest for item: {}", item.getHandle());
262264

263265
//Create Item manifest
264266
File manFile = repMan.stage(context, manifestGroupName, filename);
@@ -319,7 +321,7 @@ private File itemManifest(Context context, ReplicaManager repMan, Item item) thr
319321
}
320322

321323
writer.close();
322-
report("Created manifest for: " + item.getHandle());
324+
report("Created manifest for item: " + item.getHandle());
323325
return manFile;
324326
}
325327

src/main/java/org/dspace/ctask/replicate/store/LocalObjectStore.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99

1010
import java.io.File;
1111
import java.io.IOException;
12+
import java.nio.file.Files;
13+
import java.nio.file.Path;
1214

15+
import org.apache.logging.log4j.LogManager;
16+
import org.apache.logging.log4j.Logger;
1317
import org.dspace.ctask.replicate.ObjectStore;
1418
import org.dspace.curate.Utils;
1519
import org.dspace.services.ConfigurationService;
@@ -30,7 +34,9 @@
3034
* @author richardrodgers
3135
*/
3236
public class LocalObjectStore implements ObjectStore {
33-
private ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
37+
private final Logger log = LogManager.getLogger(LocalObjectStore.class);
38+
39+
private final ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
3440

3541
// where replicas are kept
3642
protected String storeDir = null;
@@ -43,9 +49,13 @@ public LocalObjectStore() {
4349
public void init() throws IOException {
4450
storeDir = configurationService.getProperty("replicate.store.dir");
4551

46-
File storeFile = new File(storeDir);
47-
if (! storeFile.exists()) {
48-
storeFile.mkdirs();
52+
Path storePath = Path.of(storeDir);
53+
try {
54+
Files.createDirectories(storePath);
55+
log.info("Successfully created replicate store directory: {}", storePath);
56+
} catch (IOException e) {
57+
log.warn("Failed to create replicate.store.dir: {}", e.getMessage());
58+
throw e;
4959
}
5060
}
5161

@@ -76,7 +86,10 @@ public long removeObject(String group, String id) {
7686
File remFile = new File(storeDir + File.separator + group, id);
7787
if (remFile.exists()) {
7888
size = remFile.length();
79-
remFile.delete();
89+
boolean successful = remFile.delete();
90+
if (!successful) {
91+
log.warn("Cannot delete object: '{}'.", remFile);
92+
}
8093
}
8194
return size;
8295
}

0 commit comments

Comments
 (0)