Project

General

Profile

« Previous | Next » 

Revision 5027

Added by daigle over 14 years ago

Change MetaCatVersion to MetacatVersion

View differences:

WorkflowScheduler.java
27 27
package edu.ucsb.nceas.metacat.workflow;
28 28

  
29 29
import java.io.IOException;
30
import java.io.PrintWriter;
30 31
import java.util.Calendar;
31 32
import java.util.Hashtable;
32 33
import java.util.HashMap;
33 34

  
34 35
import javax.servlet.http.HttpServletRequest;
35 36
import javax.servlet.http.HttpServletResponse;
36
import javax.servlet.ServletException;
37 37

  
38 38
import org.apache.log4j.Logger;
39 39

  
40
import edu.ucsb.nceas.metacat.MetaCatServlet;
41 40
import edu.ucsb.nceas.metacat.scheduler.BaseScheduler;
42 41
import edu.ucsb.nceas.metacat.scheduler.ScheduledJobAccess;
43 42
import edu.ucsb.nceas.metacat.scheduler.ScheduledJobDAO;
44
import edu.ucsb.nceas.metacat.scheduler.ScheduledJobParamDAO;
45 43
import edu.ucsb.nceas.metacat.scheduler.SchedulerService;
46 44
import edu.ucsb.nceas.metacat.scheduler.MetacatSchedulerException;
47 45
import edu.ucsb.nceas.metacat.shared.AccessException;
48 46
import edu.ucsb.nceas.metacat.shared.ServiceException;
49 47
import edu.ucsb.nceas.metacat.util.ErrorSendingErrorException;
50 48
import edu.ucsb.nceas.metacat.util.ResponseUtil;
51
import edu.ucsb.nceas.metacat.util.RequestUtil;
52 49
import edu.ucsb.nceas.utilities.DateUtil;
53 50
import edu.ucsb.nceas.utilities.UtilException;
54 51

  
......
56 53
 * @author daigle
57 54
 *
58 55
 */
59
/**
60
 * @author daigle
61
 *
62
 */
63 56
public class WorkflowScheduler extends BaseScheduler {
64 57
	
65 58
	private static WorkflowScheduler workflowScheduler = null;
......
177 170
			// Schedule the job
178 171
			String xmlResult = schedulerService.scheduleJob(jobName, startCal, endCal, intervalValue, intervalUnit,
179 172
					WORKFLOW_JOB_CLASS, WORKFLOW_JOB_GROUP, jobParams, username, groups);
180

  
181
			// if there is a forwardto param on the request, then send the user to the page
182
			// referenced in that param, otherwise, just send the xml back.
183
			String forwardtos[] = params.get("forwardto");
184
			String forwardto = null;
185
			if (forwardtos != null && forwardtos.length > 0) {
186
				forwardto = forwardtos[0];
187
			}
188 173
			
189
			if (forwardto != null) {
190
				String qformats[] = params.get("qformat");
191
				String qformat = null;
192
				if (qformats != null && qformats.length > 0) {
193
					qformat = qformats[0];
194
				}
195
				
196
				String destination = "/style/skins/" + qformat + "/" + forwardto
197
					+ "?workflowid=" + jobParams.get("workflowid") 
198
					+ "&karid=" + jobParams.get("karid");			
199
				RequestUtil.forwardRequest(request, response, destination);
200
			} else {
201
				ResponseUtil.sendSuccessXML(response, xmlResult);
202
			}
174
			ResponseUtil.sendSuccessXML(response, xmlResult);
203 175
			
204 176
		} catch (UtilException ue) {
205
			throw new MetacatSchedulerException("WorkflowScheduler.scheduleJob - Utility issue when scheduling job: " + ue.getMessage());
177
			throw new MetacatSchedulerException("WorkflowScheduler.scheduleJob - " 
178
					+ "Utility issue when scheduling job: " + ue.getMessage());
206 179
		} catch (ServiceException se) {
207
			throw new MetacatSchedulerException("WorkflowScheduler.scheduleJob - Service issue when scheduling job", se);
208
		} catch (IOException ioe) {
209
			throw new MetacatSchedulerException("WorkflowScheduler.scheduleJob - I/O issue when scheduling job: " + ioe.getMessage());
210
		} catch (ServletException se) {
211
			throw new MetacatSchedulerException("WorkflowScheduler.scheduleJob - Servlet issue when scheduling job: " + se.getMessage());
180
			throw new MetacatSchedulerException("WorkflowScheduler.scheduleJob - " 
181
					+ "Service issue when scheduling job", se);
212 182
		} catch (ErrorSendingErrorException esee) {
213
			throw new MetacatSchedulerException("WorkflowScheduler.scheduleJob - Issue sending error when scheduling job: " + esee.getMessage());			
183
			throw new MetacatSchedulerException("WorkflowScheduler.scheduleJob - " 
184
					+ "Issue sending error when scheduling job: " + esee.getMessage());			
214 185
		}
215 186
	}
216 187
	
......
244 215
			SchedulerService schedulerService = SchedulerService.getInstance();
245 216
			String xmlResult = schedulerService.unScheduleJob(jobName, username, groups);
246 217
			
247
			
248
			String forwardtos[] = params.get("forwardto");
249
			String forwardto = null;
250
			if (forwardtos != null && forwardtos.length > 0) {
251
				forwardto = forwardtos[0];
252
			}
253
			
254
			// if there is a forwardto param on the request, then send the user to the page
255
			// referenced in that param, otherwise, just send the xml back.
256
			if (forwardto != null) {
257
				String qformats[] = params.get("qformat");
258
				String qformat = null;
259
				if (qformats != null && qformats.length > 0) {
260
					qformat = qformats[0];
261
				}
262
				
263
				ScheduledJobAccess jobAccess = new ScheduledJobAccess();
264
				ScheduledJobDAO jobDAO = jobAccess.getJobByName(jobName);
265
				
266
				// we need to include the workflow id in the forward url
267
				ScheduledJobParamDAO workflowIdJobParamDAO = jobDAO.getJobParam("workflowid");
268
				if (workflowIdJobParamDAO == null) {
269
					throw new MetacatSchedulerException("WorkflowScheduler.unScheduleJob - could not find workflow " 
270
							+ "id when unscheduling job: " + jobName);
271
				}	
272
				
273
				// we need to include the workflow id in the forward url
274
				ScheduledJobParamDAO karJobParamDAO = jobDAO.getJobParam("karid");
275
				if (karJobParamDAO == null) {
276
					throw new MetacatSchedulerException("WorkflowScheduler.unScheduleJob - could not find kar " 
277
							+ "id when unscheduling job: " + jobName);
278
				}
279
				
280
				// we need to include the workflow id in the url
281
				ScheduledJobParamDAO workflowNameJobParamDAO = jobDAO.getJobParam("workflowname");
282
				if (workflowNameJobParamDAO == null) {
283
					throw new MetacatSchedulerException("WorkflowScheduler.unScheduleJob - could not find workflow " 
284
							+ "name when unscheduling job: " + jobName);
285
				}
286
				
287
				String destination = "/style/skins/" + qformat + "/" + forwardto
288
					+ "?workflowid=" + workflowIdJobParamDAO.getValue() 
289
					+ "&karid=" + karJobParamDAO.getValue()
290
					+ "&workflowname=" + workflowNameJobParamDAO.getValue();
291
				
292
				RequestUtil.forwardRequest(request, response, destination.toString());
293
			} else {
294
				ResponseUtil.sendSuccessXML(response, xmlResult);
295
			}
296 218
			ResponseUtil.sendSuccessXML(response, xmlResult);
219

  
297 220
		} catch (ServiceException se) {
298
			throw new MetacatSchedulerException(
299
					"WorkflowScheduler.unScheduleJob - Service issue unscheduling job",
300
					se);
221
			throw new MetacatSchedulerException("WorkflowScheduler.unScheduleJob - " 
222
					+ "Service issue unscheduling job", se);
301 223
		} catch (Exception e) {
302
			throw new MetacatSchedulerException(
303
					"WorkflowScheduler.unScheduleJob - Generic issue unscheduling job: "
304
							+ e.getMessage());
224
			throw new MetacatSchedulerException("WorkflowScheduler.unScheduleJob - " 
225
					+ "Generic issue unscheduling job: " + e.getMessage());
305 226
		}
306 227
	}
307 228
	
......
339 260
			SchedulerService schedulerService = SchedulerService.getInstance();
340 261
			String result = schedulerService.rescheduleJob(jobDAO, username, groups);
341 262

  
342
			// if there is a forwardto param on the request, then send the user to the page
343
			// referenced in that param, otherwise, just send the xml back.
344
			String forwardtos[] = params.get("forwardto");
345
			String forwardto = null;
346
			if (forwardtos != null && forwardtos.length > 0) {
347
				forwardto = forwardtos[0];
348
			}
263
			ResponseUtil.sendSuccessXML(response, result);
349 264
			
350
			if (forwardto != null) {
351
				String qformats[] = params.get("qformat");
352
				String qformat = null;
353
				if (qformats != null && qformats.length > 0) {
354
					qformat = qformats[0];
355
				}
356
				
357
				// we need to include the workflow id in the url
358
				ScheduledJobParamDAO workflowIdJobParamDAO = jobDAO.getAllJobParams().get("workflowid");
359
				if (workflowIdJobParamDAO == null) {
360
					throw new MetacatSchedulerException("WorkflowScheduler.reScheduleJob - could not find workflow " 
361
							+ "id when deleting job: " + jobName);
362
					
363
				}
364
				
365
				// we need to include the workflow id in the url
366
				ScheduledJobParamDAO karJobParamDAO = jobDAO.getJobParam("karid");
367
				if (karJobParamDAO == null) {
368
					throw new MetacatSchedulerException("WorkflowScheduler.reScheduleJob - could not find kar " 
369
							+ "id when deleting job: " + jobName);
370
				}
371
				
372
				// we need to include the workflow id in the url
373
				ScheduledJobParamDAO workflowNameJobParamDAO = jobDAO.getJobParam("workflowname");
374
				if (workflowNameJobParamDAO == null) {
375
					throw new MetacatSchedulerException("WorkflowScheduler.reScheduleJob - could not find workflow " 
376
							+ "name when deleting job: " + jobName);
377
				}
378
				
379
				String destination = "/style/skins/" + qformat + "/" + forwardto
380
					+ "?workflowid=" + workflowIdJobParamDAO.getValue()	
381
					+ "&karid=" + karJobParamDAO.getValue()
382
					+ "&workflowname=" + workflowNameJobParamDAO.getValue();
383
				
384
				RequestUtil.forwardRequest(request, response, destination);
385
			} else {
386
				ResponseUtil.sendSuccessXML(response, result);
387
			}
388
			
389 265
		} catch (AccessException ae) {
390
			throw new MetacatSchedulerException("WorkflowScheduler.scheduleJob - DB access issue when scheduling job  : ", ae);
266
			throw new MetacatSchedulerException("WorkflowScheduler.reScheduleJob - " 
267
					+ "DB access issue when scheduling job  : ", ae);
391 268
		} catch (ServiceException se) {
392
			throw new MetacatSchedulerException("WorkflowScheduler.scheduleJob - Service issue scheduling job", se);
393
		} catch (IOException ioe) {
394
			throw new MetacatSchedulerException("WorkflowScheduler.scheduleJob - I/O issue scheduling job: " + ioe.getMessage());
395
		} catch (ServletException se) {
396
			throw new MetacatSchedulerException("WorkflowScheduler.scheduleJob - Servlet issue scheduling job: " + se.getMessage());
269
			throw new MetacatSchedulerException("WorkflowScheduler.reScheduleJob - " 
270
					+ "Service issue scheduling job", se);
397 271
		} catch (ErrorSendingErrorException esee) {
398
			throw new MetacatSchedulerException("WorkflowScheduler.scheduleJob - Issue sending erro when scheduling job: " + esee.getMessage());			
272
			throw new MetacatSchedulerException("WorkflowScheduler.reScheduleJob - " 
273
					+ "Issue sending erro when scheduling job: " + esee.getMessage());			
399 274
		}
400 275
	}
401 276
	
......
405 280
	public void deleteJob(HttpServletRequest request, HttpServletResponse response, 
406 281
			Hashtable<String, String[]> params, String username, String[] groups) throws MetacatSchedulerException {
407 282
		 try {
408
		// workflow job id must exist
409
		String jobNames[] = params.get("workflowjobid");	
410
		if (jobNames == null || jobNames.length == 0) {
411
			throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - workflowjobid field must be populated "
412
					+ "in scheduler parameters when deleting job.");
413
		}			
414
		String jobName = jobNames[0];
283
			// workflow job id must exist
284
			String jobNames[] = params.get("workflowjobid");
285
			if (jobNames == null || jobNames.length == 0) {
286
				throw new MetacatSchedulerException(
287
						"WorkflowScheduler.deleteJob - workflowname field must be populated "
288
								+ "in scheduler parameters when deleting job.");
289
			}
290
			String jobName = jobNames[0];
415 291

  
416
		ScheduledJobAccess jobAccess = new ScheduledJobAccess();
417
		ScheduledJobDAO jobDAO = jobAccess.getJobByName(jobName);
418
		
419
		// delete the job
420
		SchedulerService schedulerService = SchedulerService.getInstance();
421
		String result = schedulerService.deleteJob(jobDAO, username, groups);
422
		
423
		// if there is a forwardto param on the request, then send the user to the page
424
		// referenced in that param, otherwise, just send the xml back.
425
		String forwardtos[] = params.get("forwardto");
426
		String forwardto = null;
427
		if (forwardtos != null && forwardtos.length > 0) {
428
			forwardto = forwardtos[0];
429
		}
430
		
431
		if (forwardto != null) {
432
			String qformats[] = params.get("qformat");
433
			String qformat = null;
434
			if (qformats != null && qformats.length > 0) {
435
				qformat = qformats[0];
436
			}
437
			
438
			// we need to include the workflow id in the url
439
			ScheduledJobParamDAO workflowIdJobParamDAO = jobDAO.getAllJobParams().get("workflowid");
440
			if (workflowIdJobParamDAO == null) {
441
				throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - could not find workflow " 
442
						+ "id when deleting job: " + jobName);
443
				
444
			}
445
			
446
			// we need to include the workflow id in the url
447
			ScheduledJobParamDAO karJobParamDAO = jobDAO.getJobParam("karid");
448
			if (karJobParamDAO == null) {
449
				throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - could not find kar " 
450
						+ "id when deleting job: " + jobName);
451
			}
452
			
453
			// we need to include the workflow id in the url
454
			ScheduledJobParamDAO workflowNameJobParamDAO = jobDAO.getJobParam("workflowname");
455
			if (workflowNameJobParamDAO == null) {
456
				throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - could not find workflow " 
457
						+ "name when deleting job: " + jobName);
458
			}
459
			
460
			String destination = "/style/skins/" + qformat + "/" + forwardto
461
				+ "?workflowid=" + workflowIdJobParamDAO.getValue()	
462
				+ "&karid=" + karJobParamDAO.getValue()
463
				+ "&workflowname=" + workflowNameJobParamDAO.getValue();
464
			
465
			RequestUtil.forwardRequest(request, response, destination);
466
		} else {
292
			ScheduledJobAccess jobAccess = new ScheduledJobAccess();
293
			ScheduledJobDAO jobDAO = jobAccess.getJobByName(jobName);
294

  
295
			// delete the job
296
			SchedulerService schedulerService = SchedulerService.getInstance();
297
			String result = schedulerService.deleteJob(jobDAO, username, groups);
298

  
467 299
			ResponseUtil.sendSuccessXML(response, result);
468
		}
469
		
300

  
470 301
		} catch (AccessException ae) {
471
				throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - DB access issue when deleting job  : ", ae);
302
			throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - "
303
					+ "DB access issue when deleting job  : ", ae);
472 304
		} catch (ServiceException se) {
473
			throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - Service issue deleting job", se);
474
		} catch (IOException ioe) {
475
			throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - I/O issue deleting job: " + ioe.getMessage());
476
		} catch (ServletException se) {
477
			throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - Servlet issue deleting job: " + se.getMessage());
305
			throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - "
306
					+ "Service issue deleting job", se);
478 307
		} catch (ErrorSendingErrorException esee) {
479
			throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - Issue sending erro when deleting job: " + esee.getMessage());			
308
			throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - "
309
					+ "Issue sending erro when deleting job: " + esee.getMessage());
480 310
		}
481 311
	}
482 312
	
......
497 327
	public void getJobs(HttpServletRequest request, HttpServletResponse response, 
498 328
			Hashtable<String, String[]> params, String username, String[] groups) throws MetacatSchedulerException {
499 329
		
500
		String workFlowId = null;
501
		String qformat = "";
330
		String workflowId = null;
502 331
		
503
		String workFlowIds[] = params.get("workflowid");
504
		if (workFlowIds != null && workFlowIds.length != 0) {
505
			workFlowId = workFlowIds[0];
332
		String workflowIds[] = params.get("workflowid");
333
		if (workflowIds != null && workflowIds.length != 0) {
334
			workflowId = workflowIds[0];
506 335
		}
507 336
		
508
        if (params.containsKey("qformat")) {
509
            qformat = params.get("qformat")[0];
510
        }
511
		
337
        PrintWriter out = null;
512 338
		try {
513 339
			// get the job info in xml format
514
			String xmlResult = SchedulerService.getInstance().getJobsInfoXML(WORKFLOW_JOB_GROUP, "workflowid", workFlowId);
515
			logMetacat.debug("WorkflowScheduler.getJobs - xmlResult: " + xmlResult);
516
			
517
			if (qformat == null || qformat.equals(MetaCatServlet.XMLFORMAT)) {
518
				ResponseUtil.send(response, xmlResult);
519
			} else {				
520
				ResponseUtil.transformAndSendXML(response, xmlResult, "-//NCEAS//scheduledWorkflowResultset//EN", 
521
					"-//W3C//HTML//EN", qformat, params);
340
			out = response.getWriter();
341
			SchedulerService.getInstance().getJobsInfoXML(WORKFLOW_JOB_GROUP,
342
					"workflowid", workflowId, out);
343
		} catch (ServiceException se) {
344
			throw new MetacatSchedulerException("WorkflowScheduler.getJobs - " 
345
					+ "Service error when transforming XML for workflow id: " 
346
					+ workflowId + " : " + se.getMessage());
347
		} catch (IOException ioe) {
348
			throw new MetacatSchedulerException("WorkflowScheduler.getJobs - " 
349
					+ "I/O error when transforming XML for workflow id: " 
350
					+ workflowId + " : " + ioe.getMessage());
351
		} finally {
352
			if (out != null) {
353
				out.close();
522 354
			}
523
		} catch (ServiceException se) {
524
			throw new MetacatSchedulerException("WorkflowScheduler.getJobs - Service issue getting jobs", se);
525
		} catch (Exception e) {
526
			throw new MetacatSchedulerException("WorkflowScheduler.getJobs - Generic issue getting jobs: " 
527
					+ e.getMessage());
528
		}		
529
	}	
355
		}
356
	}
530 357
}

Also available in: Unified diff