diff --git a/dspace-api/src/main/java/org/dspace/curate/Curation.java b/dspace-api/src/main/java/org/dspace/curate/Curation.java index 0fcbd6c272..2f578a5cfe 100644 --- a/dspace-api/src/main/java/org/dspace/curate/Curation.java +++ b/dspace-api/src/main/java/org/dspace/curate/Curation.java @@ -190,6 +190,7 @@ public class Curation extends DSpaceRunnable { */ private Curator initCurator() throws FileNotFoundException { Curator curator = new Curator(); + curator.setLogHandler(handler); OutputStream reporterStream; if (null == this.reporter) { reporterStream = new NullOutputStream(); diff --git a/dspace-api/src/main/java/org/dspace/curate/Curator.java b/dspace-api/src/main/java/org/dspace/curate/Curator.java index aa6cb14fda..9e9d05cd46 100644 --- a/dspace-api/src/main/java/org/dspace/curate/Curator.java +++ b/dspace-api/src/main/java/org/dspace/curate/Curator.java @@ -30,6 +30,7 @@ import org.dspace.core.Context; import org.dspace.core.factory.CoreServiceFactory; import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.service.HandleService; +import org.dspace.scripts.handler.DSpaceRunnableHandler; /** * Curator orchestrates and manages the application of a one or more curation @@ -90,6 +91,7 @@ public class Curator { protected CommunityService communityService; protected ItemService itemService; protected HandleService handleService; + protected DSpaceRunnableHandler handler; /** * No-arg constructor @@ -338,7 +340,7 @@ public class Curator { */ public void report(String message) { if (null == reporter) { - log.warn("report called with no Reporter set: {}", message); + logWarning("report called with no Reporter set: {}", message); return; } @@ -435,7 +437,7 @@ public class Curator { // Site-wide Tasks really should have an EPerson performer associated with them, // otherwise they are run as an "anonymous" user with limited access rights. if (ctx.getCurrentUser() == null && !ctx.ignoreAuthorization()) { - log.warn("You are running one or more Site-Wide curation tasks in ANONYMOUS USER mode," + + logWarning("You are running one or more Site-Wide curation tasks in ANONYMOUS USER mode," + " as there is no EPerson 'performer' associated with this task. To associate an EPerson " + "'performer' " + " you should ensure tasks are called via the Curator.curate(Context, ID) method."); @@ -546,7 +548,7 @@ public class Curator { } statusCode = task.perform(dso); String id = (dso.getHandle() != null) ? dso.getHandle() : "workflow item: " + dso.getID(); - log.info(logMessage(id)); + logInfo(logMessage(id)); visit(dso); return !suspend(statusCode); } catch (IOException ioe) { @@ -562,7 +564,7 @@ public class Curator { throw new IOException("Context or identifier is null"); } statusCode = task.perform(c, id); - log.info(logMessage(id)); + logInfo(logMessage(id)); visit(null); return !suspend(statusCode); } catch (IOException ioe) { @@ -604,5 +606,34 @@ public class Curator { } return mb.toString(); } + + protected void logInfo(String id) { + if (handler == null) { + log.info(logMessage(id)); + } else { + handler.logInfo(logMessage(id)); + } + } + + } + + protected void logWarning(String message) { + logWarning(message, null); + } + + protected void logWarning(String message, Object object) { + if (handler == null) { + if (object != null) { + log.warn(message, object); + } else { + log.warn(message); + } + } else { + handler.logWarning(message); + } + } + + public void setLogHandler(DSpaceRunnableHandler handler) { + this.handler = handler; } }