comparison software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/schedule/MpdlDocJob.java @ 0:408254cf2f1d

Erstellung
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Wed, 24 Nov 2010 17:24:23 +0100
parents
children 5df60f24e997
comparison
equal deleted inserted replaced
-1:000000000000 0:408254cf2f1d
1 package de.mpg.mpiwg.berlin.mpdl.schedule;
2
3 import java.util.Date;
4
5 import org.apache.log4j.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.client.DocumentHandler;
13 import de.mpg.mpiwg.berlin.mpdl.escidoc.ESciDocIngestor;
14 import de.mpg.mpiwg.berlin.mpdl.escidoc.ESciDocRestSession;
15 import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException;
16 import de.mpg.mpiwg.berlin.mpdl.xmlrpc.MpdlXmlRpcDocHandler;
17
18 public class MpdlDocJob implements Job {
19 public static String STATUS_BEGIN = "started";
20 private static Logger LOGGER = Logger.getLogger(MpdlDocJob.class); // Logs to EXIST_HOME/webapp/WEB-INF/logs/exist.log
21 private JobExecutionContext currentExecutedContext;
22
23 public void execute(JobExecutionContext context) throws JobExecutionException {
24 this.currentExecutedContext = context;
25 MpdlDocOperation docOperation = getDocOperation();
26 docOperation.setIncludePdf(true); // default is true: handle also Pdf/Html version of the document
27 try {
28 docOperation.setStatus(STATUS_BEGIN);
29 String operationName = docOperation.getName();
30 String cookieId = docOperation.getESciDocCookieId();
31 MpdlXmlRpcDocHandler mpdlXmlRpcDocHandler = MpdlXmlRpcDocHandler.getInstance();
32 ESciDocRestSession eSciDocSession = ESciDocRestSession.getInstance(cookieId);
33 ESciDocIngestor eSciDocIngestor = new ESciDocIngestor(eSciDocSession);
34 if (operationName.equals("create") || operationName.equals("update")) {
35 DocumentHandler docHandler = new DocumentHandler(mpdlXmlRpcDocHandler, eSciDocIngestor);
36 docHandler.doOperation(docOperation);
37 } else if (operationName.equals("delete")) {
38 DocumentHandler docHandler = new DocumentHandler(mpdlXmlRpcDocHandler, eSciDocIngestor);
39 docHandler.doOperation(docOperation);
40 } else if (operationName.equals("updateExist")) {
41 DocumentHandler docHandler = new DocumentHandler(mpdlXmlRpcDocHandler);
42 docHandler.doOperation(docOperation);
43 } else if (operationName.equals("deleteExist")) {
44 DocumentHandler docHandler = new DocumentHandler(mpdlXmlRpcDocHandler);
45 docHandler.doOperation(docOperation);
46 } else if (operationName.equals("importAllDocumentsLocallyExist")) {
47 DocumentHandler docHandler = new DocumentHandler(mpdlXmlRpcDocHandler);
48 docOperation.setIncludePdf(false); // for performance reasons while importing documents: do not generate Pdf/Html-Versions of the document
49 docHandler.doOperation(docOperation);
50 } else if (operationName.equals("generatePdfHtmlDocumentFiles")) {
51 DocumentHandler docHandler = new DocumentHandler(mpdlXmlRpcDocHandler);
52 docOperation.setIncludePdf(true);
53 docHandler.doOperation(docOperation);
54 }
55 Date startingTime = docOperation.getStart();
56 String jobInfo = "MPDL: Document operation " + docOperation.toString() + ": started at: " + startingTime;
57 LOGGER.info(jobInfo);
58 this.currentExecutedContext = null;
59 } catch (Exception e) {
60 try {
61 // Quartz will automatically unschedule all triggers associated with this job so that it does not run again
62 MpdlChainScheduler mpdlChainScheduler = MpdlChainScheduler.getInstance();
63 mpdlChainScheduler.finishOperation(docOperation);
64 String errorMessage = e.getMessage();
65 if (errorMessage == null) {
66 Throwable t = e.getCause();
67 if (t == null) {
68 errorMessage = e.toString();
69 } else {
70 errorMessage = t.getMessage();
71 }
72 }
73 docOperation.setErrorMessage(errorMessage);
74 LOGGER.error(errorMessage, e);
75 JobExecutionException jobExecutionException = new JobExecutionException(e);
76 jobExecutionException.setUnscheduleAllTriggers(true);
77 throw jobExecutionException;
78 } catch (ApplicationException ex) {
79 // nothing
80 }
81 }
82 }
83
84 private MpdlDocOperation getDocOperation() {
85 MpdlDocOperation docOperation = null;
86 if (currentExecutedContext != null) {
87 JobDetail job = currentExecutedContext.getJobDetail();
88 JobDataMap parameters = job.getJobDataMap();
89 docOperation = (MpdlDocOperation) parameters.get("operation");
90 }
91 return docOperation;
92 }
93
94 }