3232import org .dspace .content .service .ReportResultService ;
3333import org .dspace .core .Context ;
3434import org .dspace .core .Email ;
35+ import org .dspace .core .factory .CoreServiceFactory ;
36+ import org .dspace .core .service .PluginService ;
3537import org .dspace .core .I18nUtil ;
3638import org .dspace .eperson .factory .EPersonServiceFactory ;
3739import org .dspace .eperson .service .EPersonService ;
3840import org .dspace .health .Check ;
39- import org .dspace .health .Report ;
4041import org .dspace .health .ReportInfo ;
4142import org .dspace .scripts .DSpaceRunnable ;
4243import 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}
0 commit comments