Skip to content

Commit 94428bb

Browse files
author
Matus Kasak
committed
Removed unused Report and refactor getChecks
1 parent aaabfde commit 94428bb

2 files changed

Lines changed: 25 additions & 232 deletions

File tree

dspace-api/src/main/java/org/dspace/app/healthreport/HealthReport.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@
3232
import org.dspace.content.service.ReportResultService;
3333
import org.dspace.core.Context;
3434
import org.dspace.core.Email;
35+
import org.dspace.core.factory.CoreServiceFactory;
36+
import org.dspace.core.service.PluginService;
3537
import org.dspace.core.I18nUtil;
3638
import org.dspace.eperson.factory.EPersonServiceFactory;
3739
import org.dspace.eperson.service.EPersonService;
3840
import org.dspace.health.Check;
39-
import org.dspace.health.Report;
4041
import org.dspace.health.ReportInfo;
4142
import org.dspace.scripts.DSpaceRunnable;
4243
import org.dspace.services.ConfigurationService;
@@ -60,7 +61,7 @@ public class HealthReport extends DSpaceRunnable<HealthReportScriptConfiguration
6061
/**
6162
* Checks to be performed.
6263
*/
63-
private static final LinkedHashMap<String, Check> checks = Report.checks();
64+
private static final LinkedHashMap<String, Check> checks = getChecks();
6465

6566
/**
6667
* `-h`: Help, show help information.
@@ -171,7 +172,7 @@ public void internalRun() throws Exception {
171172
JSONObject root = new JSONObject();
172173
// Create the array
173174
JSONArray checksArray = new JSONArray();
174-
for (Map.Entry<String, Check> check_entry : Report.checks().entrySet()) {
175+
for (Map.Entry<String, Check> check_entry : checks.entrySet()) {
175176
++position;
176177
if (!specificChecks.isEmpty() && !specificChecks.contains(position)) {
177178
continue;
@@ -330,4 +331,25 @@ public static String getCheckName(int specificCheck) {
330331
}
331332
return null; // should not happen
332333
}
334+
335+
/**
336+
* Create check list from configured healthcheck plugins.
337+
*/
338+
private static LinkedHashMap<String, Check> getChecks() {
339+
LinkedHashMap<String, Check> loadedChecks = new LinkedHashMap<>();
340+
String[] checkNames = DSpaceServicesFactory.getInstance().getConfigurationService()
341+
.getArrayProperty("healthcheck.checks");
342+
PluginService pluginService = CoreServiceFactory.getInstance().getPluginService();
343+
344+
for (String checkName : checkNames) {
345+
Check check = (Check) pluginService.getNamedPlugin(Check.class, checkName);
346+
if (check != null) {
347+
loadedChecks.put(checkName, check);
348+
} else {
349+
log.warn("Could not find implementation for [{}]", checkName);
350+
}
351+
}
352+
353+
return loadedChecks;
354+
}
333355
}

dspace-api/src/main/java/org/dspace/health/Report.java

Lines changed: 0 additions & 229 deletions
This file was deleted.

0 commit comments

Comments
 (0)