Skip to content

Commit 80758a7

Browse files
authored
Merge pull request DSpace#10412 from minurmin/checker-clarifications
Clarify checker and checker-emailer -related command line options, messages and report formatting
2 parents 81dd876 + 2aa77e8 commit 80758a7

File tree

5 files changed

+70
-44
lines changed

5 files changed

+70
-44
lines changed

dspace-api/src/main/java/org/dspace/app/checker/ChecksumChecker.java

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ public static void main(String[] args) throws SQLException {
9797
options.addOption("h", "help", false, "Help");
9898
options.addOption("d", "duration", true, "Checking duration");
9999
options.addOption("c", "count", true, "Check count");
100-
options.addOption("a", "handle", true, "Specify a handle to check");
100+
options.addOption("i", "handle", true, "Specify a handle to check");
101101
options.addOption("v", "verbose", false, "Report all processing");
102102

103103
Option option;
104104

105105
option = Option.builder("b")
106106
.longOpt("bitstream-ids")
107107
.hasArgs()
108-
.desc("Space separated list of bitstream ids")
108+
.desc("Space separated list of bitstream UUIDs")
109109
.build();
110110
options.addOption(option);
111111

@@ -131,6 +131,17 @@ public static void main(String[] args) throws SQLException {
131131
try {
132132
context = new Context();
133133

134+
int mutuallyExclusiveOpts = 0;
135+
for (char c : new char[]{'l', 'L', 'd', 'b', 'i','c'}) {
136+
if (line.hasOption(c)) {
137+
mutuallyExclusiveOpts++;
138+
}
139+
}
140+
if (mutuallyExclusiveOpts > 1) {
141+
System.err.println("Please use only one option of -l, -L, -d, -b, -i, or -c");
142+
LOG.error("Please use only one option of -l, -L, -d, -b, -i, or -c");
143+
System.exit(1);
144+
}
134145

135146
// Prune stage
136147
if (line.hasOption('p')) {
@@ -168,20 +179,22 @@ public static void main(String[] args) throws SQLException {
168179
bitstreams.add(bitstreamService.find(context, UUID.fromString(ids[i])));
169180
} catch (NumberFormatException nfe) {
170181
System.err.println("The following argument: " + ids[i]
171-
+ " is not an integer");
182+
+ " is not an UUID");
172183
System.exit(0);
173184
}
174185
}
175186
dispatcher = new IteratorDispatcher(bitstreams.iterator());
176-
} else if (line.hasOption('a')) {
177-
dispatcher = new HandleDispatcher(context, line.getOptionValue('a'));
187+
} else if (line.hasOption('i')) {
188+
dispatcher = new HandleDispatcher(context, line.getOptionValue('i'));
178189
} else if (line.hasOption('d')) {
179190
// run checker process for specified duration
180191
try {
181192
dispatcher = new LimitedDurationDispatcher(
182193
new SimpleDispatcher(context, processStart, true), Instant.ofEpochMilli(
183194
Instant.now().toEpochMilli() + Utils.parseDuration(line.getOptionValue('d'))));
184195
} catch (Exception e) {
196+
System.err.println("Couldn't parse " + line.getOptionValue('d')
197+
+ " as a duration");
185198
LOG.fatal("Couldn't parse " + line.getOptionValue('d')
186199
+ " as a duration: ", e);
187200
System.exit(0);
@@ -225,18 +238,24 @@ public static void main(String[] args) throws SQLException {
225238
private static void printHelp(Options options) {
226239
HelpFormatter myhelp = new HelpFormatter();
227240

228-
myhelp.printHelp("Checksum Checker\n", options);
229-
System.out.println("\nSpecify a duration for checker process, using s(seconds),"
230-
+ "m(minutes), or h(hours): ChecksumChecker -d 30s"
231-
+ " OR ChecksumChecker -d 30m"
232-
+ " OR ChecksumChecker -d 2h");
233-
System.out.println("\nSpecify bitstream IDs: ChecksumChecker -b 13 15 17 20");
234-
System.out.println("\nLoop once through all bitstreams: "
235-
+ "ChecksumChecker -l");
236-
System.out.println("\nLoop continuously through all bitstreams: ChecksumChecker -L");
237-
System.out.println("\nCheck a defined number of bitstreams: ChecksumChecker -c 10");
238-
System.out.println("\nReport all processing (verbose)(default reports only errors): ChecksumChecker -v");
239-
System.out.println("\nDefault (no arguments) is equivalent to '-c 1'");
241+
myhelp.printHelp("checker\n", options);
242+
System.out.println("\nChecksum Checker usage examples:");
243+
System.out.println("\nThe following options are mutually exclusive:");
244+
System.out.println(" - Specify a duration for checker process, using s(seconds),"
245+
+ "m(minutes), or h(hours): checker -d 30s"
246+
+ " OR checker -d 30m"
247+
+ " OR checker -d 2h");
248+
System.out.println(" - Specify bitstream UUIDs: checker -b 550e8400-e29b-41d4-a716-446655440000"
249+
+ " f3f2e850-b5d4-11ef-ac7e-96584d5248b2");
250+
System.out.println(" - Specify handle: checker -i 12345/100");
251+
System.out.println(" - Loop once through all bitstreams: "
252+
+ "checker -l");
253+
System.out.println(" - Loop continuously through all bitstreams: checker -L");
254+
System.out.println(" - Check a defined number of bitstreams: checker -c 10");
255+
System.out.println("\nThe following options can be used in combination with others above:");
256+
System.out.println(" - Report all processing to checker.log (by default logs only errors): checker -v");
257+
System.out.println(" - Prune old results from the database: checker -p");
258+
System.out.println("\nDefault (no arguments) is equivalent to 'checker -c 1'\n");
240259
System.exit(0);
241260
}
242261

dspace-api/src/main/java/org/dspace/checker/DailyReportEmailer.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public void sendReport(File attachment, int numberOfBitstreams)
7575
email.setContent("Checker Report", "report is attached ...");
7676
email.addAttachment(attachment, "checksum_checker_report.txt");
7777
email.addRecipient(configurationService.getProperty("mail.admin"));
78+
log.info("Sending checker report email to " + configurationService.getProperty("mail.admin"));
7879
email.send();
7980
}
8081
}
@@ -109,18 +110,19 @@ public static void main(String[] args) {
109110
Options options = new Options();
110111

111112
options.addOption("h", "help", false, "Help");
112-
options.addOption("d", "Deleted", false,
113-
"Send E-mail report for all bitstreams set as deleted for today");
114-
options.addOption("m", "Missing", false,
115-
"Send E-mail report for all bitstreams not found in assetstore for today");
116-
options.addOption("c", "Changed", false,
117-
"Send E-mail report for all bitstreams where checksum has been changed for today");
118-
options.addOption("a", "All", false,
119-
"Send all E-mail reports");
120-
options.addOption("u", "Unchecked", false,
121-
"Send the Unchecked bitstream report");
122-
options.addOption("n", "Not Processed", false,
123-
"Send E-mail report for all bitstreams set to longer be processed for today");
113+
options.addOption("d", "deleted", false,
114+
"Send email report for all bitstreams set as deleted for today");
115+
options.addOption("m", "missing", false,
116+
"Send email report for all bitstreams not found in assetstore for today");
117+
options.addOption("c", "changed", false,
118+
"Send email report for all bitstreams where checksum has been changed for today");
119+
options.addOption("a", "all", false,
120+
"Send all email reports (used by default)");
121+
options.addOption("u", "unchecked", false,
122+
"Send the unchecked (i.e. recently added) bitstream email report");
123+
options.addOption("n", "not-processed", false,
124+
"Send email report for all bitstreams set to no longer be processed for today (includes"
125+
+ " bitstreams marked as deleted or not found)");
124126

125127
try {
126128
line = parser.parse(options, args);
@@ -133,13 +135,15 @@ public static void main(String[] args) {
133135
if (line.hasOption('h')) {
134136
HelpFormatter myhelp = new HelpFormatter();
135137

136-
myhelp.printHelp("Checksum Reporter\n", options);
137-
System.out.println("\nSend Deleted bitstream email report: DailyReportEmailer -d");
138-
System.out.println("\nSend Missing bitstreams email report: DailyReportEmailer -m");
139-
System.out.println("\nSend Checksum Changed email report: DailyReportEmailer -c");
140-
System.out.println("\nSend bitstream not to be processed email report: DailyReportEmailer -n");
141-
System.out.println("\nSend Un-checked bitstream report: DailyReportEmailer -u");
142-
System.out.println("\nSend All email reports: DailyReportEmailer");
138+
myhelp.printHelp("checker-emailer\n", options);
139+
System.out.println("\nChecksum Checker Reporter usage examples:\n");
140+
System.out.println(" - Send all email reports: checker-emailer -a");
141+
System.out.println(" - Send deleted bitstream email report: checker-emailer -d");
142+
System.out.println(" - Send missing bitstreams email report: checker-emailer -m");
143+
System.out.println(" - Send checksum changed email report: checker-emailer -c");
144+
System.out.println(" - Send bitstream not to be processed email report: checker-emailer -n");
145+
System.out.println(" - Send unchecked bitstream email report: checker-emailer -u");
146+
System.out.println("\nDefault (no arguments) is equivalent to 'checker-emailer -a'\n");
143147
System.exit(0);
144148
}
145149

@@ -186,7 +190,9 @@ public static void main(String[] args) {
186190
writer.write("\n--------------------------------- Report Spacer ---------------------------\n\n");
187191
numBitstreams += reporter.getBitstreamNotFoundReport(context, yesterday, tomorrow, writer);
188192
writer.write("\n--------------------------------- Report Spacer ---------------------------\n\n");
189-
numBitstreams += reporter.getNotToBeProcessedReport(context, yesterday, tomorrow, writer);
193+
// not to be processed report includes deleted and not found bitstreams so it is not necessary to
194+
// include the sum in the counter
195+
reporter.getNotToBeProcessedReport(context, yesterday, tomorrow, writer);
190196
writer.write("\n--------------------------------- Report Spacer ---------------------------\n\n");
191197
numBitstreams += reporter.getUncheckedBitstreamsReport(context, writer);
192198
writer.write("\n--------------------------------- End Report ---------------------------\n\n");

dspace-api/src/main/java/org/dspace/checker/SimpleReporterServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public int getDeletedBitstreamReport(Context context, Instant startDate, Instant
7272

7373
osw.write("\n");
7474
osw.write(msg("deleted-bitstream-intro"));
75+
osw.write(" ");
7576
osw.write(applyDateFormatShort(startDate));
7677
osw.write(" ");
7778
osw.write(msg("date-range-to"));
@@ -113,7 +114,6 @@ public int getChangedChecksumReport(Context context, Instant startDate, Instant
113114
osw.write("\n");
114115
osw.write(msg("checksum-did-not-match"));
115116
osw.write(" ");
116-
osw.write("\n");
117117
osw.write(applyDateFormatShort(startDate));
118118
osw.write(" ");
119119
osw.write(msg("date-range-to"));

dspace-api/src/main/java/org/dspace/checker/service/SimpleReporterService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public int getBitstreamNotFoundReport(Context context, Instant startDate, Instan
7272

7373
/**
7474
* The bitstreams that were set to not be processed report for the specified
75-
* date range.
75+
* date range. This includes bitstreams that are marked as deleted and bitstreams
76+
* that are not found from the assetstore.
7677
*
7778
* @param context context
7879
* @param startDate the start date range.

dspace-api/src/main/resources/Messages.properties

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,20 @@ org.dspace.checker.ResultsLogger.store-number
7070
org.dspace.checker.ResultsLogger.to-be-processed = To be processed
7171
org.dspace.checker.ResultsLogger.user-format-description = User format description
7272
org.dspace.checker.SimpleReporterImpl.bitstream-id = Bitstream Id
73-
org.dspace.checker.SimpleReporterImpl.bitstream-not-found-report = The following is a BITSTREAM NOT FOUND report for
74-
org.dspace.checker.SimpleReporterImpl.bitstream-will-no-longer-be-processed = The following is a BITSTREAM WILL NO LONGER BE PROCESSED report for
73+
org.dspace.checker.SimpleReporterImpl.bitstream-not-found-report = The following is a BITSTREAM NOT FOUND report from
74+
org.dspace.checker.SimpleReporterImpl.bitstream-will-no-longer-be-processed = The following is a BITSTREAM WILL NO LONGER BE PROCESSED report from
7575
org.dspace.checker.SimpleReporterImpl.check-id = Check Id
7676
org.dspace.checker.SimpleReporterImpl.checksum = Checksum
7777
org.dspace.checker.SimpleReporterImpl.checksum-algorithm = Checksum Algorithm
7878
org.dspace.checker.SimpleReporterImpl.checksum-calculated = Checksum Calculated
79-
org.dspace.checker.SimpleReporterImpl.checksum-did-not-match = The following is a CHECKSUM DID NOT MATCH report for
79+
org.dspace.checker.SimpleReporterImpl.checksum-did-not-match = The following is a CHECKSUM DID NOT MATCH report from
8080
org.dspace.checker.SimpleReporterImpl.checksum-expected = Checksum Expected
8181
org.dspace.checker.SimpleReporterImpl.date-range-to = to
8282
org.dspace.checker.SimpleReporterImpl.deleted = Deleted
83-
org.dspace.checker.SimpleReporterImpl.deleted-bitstream-intro = The following is a BITSTREAM SET DELETED report for
83+
org.dspace.checker.SimpleReporterImpl.deleted-bitstream-intro = The following is a BITSTREAM SET DELETED report from
8484
org.dspace.checker.SimpleReporterImpl.description = Description
8585
org.dspace.checker.SimpleReporterImpl.format-id = Format Id
86-
org.dspace.checker.SimpleReporterImpl.howto-add-unchecked-bitstreams = To add these bitstreams to be checked run the checksum checker with the -u option
86+
org.dspace.checker.SimpleReporterImpl.howto-add-unchecked-bitstreams = To add these bitstreams to be checked run the checksum checker again
8787
org.dspace.checker.SimpleReporterImpl.internal-id = Internal Id
8888
org.dspace.checker.SimpleReporterImpl.name = Name
8989
org.dspace.checker.SimpleReporterImpl.no-bitstreams-changed = There were no bitstreams found with changed checksums

0 commit comments

Comments
 (0)