Mercurial > hg > mpdl-group
comparison 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 |
comparison
equal
deleted
inserted
replaced
22:6a45a982c333 | 23:e845310098ba |
---|---|
1 package de.mpg.mpiwg.berlin.mpdl.cms.scheduler; | |
2 | |
3 import java.util.Date; | |
4 | |
5 import java.util.logging.Logger; | |
6 import org.quartz.Job; | |
7 import org.quartz.JobDataMap; | |
8 import org.quartz.JobDetail; | |
9 import org.quartz.JobExecutionContext; | |
10 import org.quartz.JobExecutionException; | |
11 | |
12 import de.mpg.mpiwg.berlin.mpdl.cms.document.DocumentHandler; | |
13 import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException; | |
14 | |
15 public class CmsDocJob implements Job { | |
16 public static String STATUS_BEGIN = "started"; | |
17 private static Logger LOGGER = Logger.getLogger(CmsDocJob.class.getName()); | |
18 private JobExecutionContext currentExecutedContext; | |
19 | |
20 public void execute(JobExecutionContext context) throws JobExecutionException { | |
21 this.currentExecutedContext = context; | |
22 CmsDocOperation docOperation = getDocOperation(); | |
23 try { | |
24 docOperation.setStatus(STATUS_BEGIN); | |
25 String operationName = docOperation.getName(); | |
26 if (operationName.equals("create")) { | |
27 DocumentHandler docHandler = new DocumentHandler(); | |
28 docHandler.doOperation(docOperation); | |
29 } else if (operationName.equals("delete")) { | |
30 DocumentHandler docHandler = new DocumentHandler(); | |
31 docHandler.doOperation(docOperation); | |
32 } else if (operationName.equals("importDirectory")) { | |
33 DocumentHandler docHandler = new DocumentHandler(); | |
34 docHandler.doOperation(docOperation); | |
35 } | |
36 Date startingTime = docOperation.getStart(); | |
37 String jobInfo = "Document operation " + docOperation.toString() + ": started at: " + startingTime; | |
38 LOGGER.info(jobInfo); | |
39 this.currentExecutedContext = null; | |
40 } catch (Exception e) { | |
41 try { | |
42 // Quartz will automatically unschedule all triggers associated with this job so that it does not run again | |
43 CmsChainScheduler mpdlChainScheduler = CmsChainScheduler.getInstance(); | |
44 mpdlChainScheduler.finishOperation(docOperation); | |
45 String errorMessage = e.getMessage(); | |
46 if (errorMessage == null) { | |
47 Throwable t = e.getCause(); | |
48 if (t == null) { | |
49 errorMessage = e.toString(); | |
50 } else { | |
51 errorMessage = t.getMessage(); | |
52 } | |
53 } | |
54 docOperation.setErrorMessage(errorMessage); | |
55 LOGGER.severe(errorMessage); | |
56 JobExecutionException jobExecutionException = new JobExecutionException(e); | |
57 jobExecutionException.setUnscheduleAllTriggers(true); | |
58 throw jobExecutionException; | |
59 } catch (ApplicationException ex) { | |
60 // nothing | |
61 } | |
62 } | |
63 } | |
64 | |
65 private CmsDocOperation getDocOperation() { | |
66 CmsDocOperation docOperation = null; | |
67 if (currentExecutedContext != null) { | |
68 JobDetail job = currentExecutedContext.getJobDetail(); | |
69 JobDataMap parameters = job.getJobDataMap(); | |
70 docOperation = (CmsDocOperation) parameters.get("operation"); | |
71 } | |
72 return docOperation; | |
73 } | |
74 | |
75 } |