Mercurial > hg > mpdl-group
diff software/mpdl-services/mpiwg-mpdl-cms/src/de/mpg/mpiwg/berlin/mpdl/cms/scheduler/CmsDocJob.java @ 23:e845310098ba
diverse Korrekturen
author | Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 27 Nov 2012 12:35:19 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/software/mpdl-services/mpiwg-mpdl-cms/src/de/mpg/mpiwg/berlin/mpdl/cms/scheduler/CmsDocJob.java Tue Nov 27 12:35:19 2012 +0100 @@ -0,0 +1,75 @@ +package de.mpg.mpiwg.berlin.mpdl.cms.scheduler; + +import java.util.Date; + +import java.util.logging.Logger; +import org.quartz.Job; +import org.quartz.JobDataMap; +import org.quartz.JobDetail; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +import de.mpg.mpiwg.berlin.mpdl.cms.document.DocumentHandler; +import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException; + +public class CmsDocJob implements Job { + public static String STATUS_BEGIN = "started"; + private static Logger LOGGER = Logger.getLogger(CmsDocJob.class.getName()); + private JobExecutionContext currentExecutedContext; + + public void execute(JobExecutionContext context) throws JobExecutionException { + this.currentExecutedContext = context; + CmsDocOperation docOperation = getDocOperation(); + try { + docOperation.setStatus(STATUS_BEGIN); + String operationName = docOperation.getName(); + if (operationName.equals("create")) { + DocumentHandler docHandler = new DocumentHandler(); + docHandler.doOperation(docOperation); + } else if (operationName.equals("delete")) { + DocumentHandler docHandler = new DocumentHandler(); + docHandler.doOperation(docOperation); + } else if (operationName.equals("importDirectory")) { + DocumentHandler docHandler = new DocumentHandler(); + docHandler.doOperation(docOperation); + } + Date startingTime = docOperation.getStart(); + String jobInfo = "Document operation " + docOperation.toString() + ": started at: " + startingTime; + LOGGER.info(jobInfo); + this.currentExecutedContext = null; + } catch (Exception e) { + try { + // Quartz will automatically unschedule all triggers associated with this job so that it does not run again + CmsChainScheduler mpdlChainScheduler = CmsChainScheduler.getInstance(); + mpdlChainScheduler.finishOperation(docOperation); + String errorMessage = e.getMessage(); + if (errorMessage == null) { + Throwable t = e.getCause(); + if (t == null) { + errorMessage = e.toString(); + } else { + errorMessage = t.getMessage(); + } + } + docOperation.setErrorMessage(errorMessage); + LOGGER.severe(errorMessage); + JobExecutionException jobExecutionException = new JobExecutionException(e); + jobExecutionException.setUnscheduleAllTriggers(true); + throw jobExecutionException; + } catch (ApplicationException ex) { + // nothing + } + } + } + + private CmsDocOperation getDocOperation() { + CmsDocOperation docOperation = null; + if (currentExecutedContext != null) { + JobDetail job = currentExecutedContext.getJobDetail(); + JobDataMap parameters = job.getJobDataMap(); + docOperation = (CmsDocOperation) parameters.get("operation"); + } + return docOperation; + } + +}