Project

General

Profile

« Previous | Next » 

Revision 4951

Added by daigle over 15 years ago

Add scheduler and workflow schedule functionality

View differences:

src/edu/ucsb/nceas/shared/AccessException.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: An Exception thrown when an error occurs because an 
4
 *             AccessionNumber was invalid or used incorrectly
5
 *  Copyright: 2008 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Michael Daigle
8
 *
9
 *   '$Author: daigle $'
10
 *     '$Date: 2008-07-06 21:25:34 -0700 (Sun, 06 Jul 2008) $'
11
 * '$Revision: 4080 $'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27

  
28
package edu.ucsb.nceas.shared;
29

  
30
/**
31
 * Exception thrown when an error occurs in a configuration administrative
32
 * class
33
 */
34
public class AccessException extends Exception {
35
	
36
	private static final long serialVersionUID = -8436697355629175917L;
37

  
38
	/**
39
	 * Create a new AccessException.
40
	 *
41
	 * @param message The error or warning message.
42
	 */
43
	public AccessException(String message) {
44
		super(message);
45
	}
46
}
0 47

  
src/edu/ucsb/nceas/shared/BaseAccess.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that manages database access 
4
 *             information.
5
 *  Copyright: 2009 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Michael Daigle
8
 * 
9
 *   '$Author: daigle $'
10
 *     '$Date: 2009-03-23 13:56:56 -0800 (Mon, 23 Mar 2009) $'
11
 * '$Revision: 4854 $'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27

  
28
package edu.ucsb.nceas.shared;
29

  
30
import java.sql.PreparedStatement;
31
import java.sql.ResultSet;
32
import java.sql.SQLException;
33

  
34
import edu.ucsb.nceas.metacat.DBConnection;
35
import edu.ucsb.nceas.metacat.DBConnectionPool;
36

  
37
public class BaseAccess {
38
	
39
	protected DBConnection conn = null;
40
    protected int serialNumber = -1;
41
    protected PreparedStatement pstmt = null;
42
    protected ResultSet rs = null;
43
	
44
    protected BaseAccess(String methodName) throws AccessException {
45
        //check out DBConnection
46
    	try {
47
    		conn = DBConnectionPool.
48
                	getDBConnection("methodName");
49
    		serialNumber = conn.getCheckOutSerialNumber();
50
    	} catch (SQLException sqle) {
51
    		throw new AccessException("Could not get connection from DB connection pool: " 
52
    				+ sqle.getMessage());
53
    	}
54
    }
55
    
56
    protected ResultSet select(PreparedStatement pstmt) throws AccessException {
57
    	try {
58
    		pstmt.execute();
59
        	rs = pstmt.getResultSet();
60
    	} catch (SQLException sqle) {
61
    		throw new AccessException("Could not perform select: " + pstmt.toString()
62
    				+ sqle.getMessage());
63
    	}
64
    	
65
    	return rs;
66
    }
67
}
src/edu/ucsb/nceas/shared/BaseDAO.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that holds the data from the scheduled_task 
4
 *             table in the database. 
5
 *  Copyright: 2009 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Michael Daigle
8
 * 
9
 *   '$Author: daigle $'
10
 *     '$Date: 2009-03-23 13:56:56 -0800 (Mon, 23 Mar 2009) $'
11
 * '$Revision: 4854 $'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27
package edu.ucsb.nceas.shared;
28

  
29
import java.sql.Timestamp;
30

  
31
public class BaseDAO {
32
	
33
	private Long _id;
34
	private Timestamp _createTime;
35
	private Timestamp _modTime;
36
	private String _status;
37
	
38
	public Long getId() {
39
		return _id;
40
	}
41
	
42
	public void setId(Long id) {
43
		_id = id;
44
	}
45
	
46
	public Timestamp getCreateTime() {
47
		return _createTime;
48
	}
49
	
50
	public void setCreateTime(Timestamp createTime) {
51
		_createTime = createTime;
52
	}
53
	
54
	public Timestamp getModTime() {
55
		return _modTime;
56
	}
57
	
58
	public void setModTime(Timestamp modTime) {
59
		_modTime = modTime;
60
	}
61
	
62
	public String getStatus() {
63
		return _status;
64
	}
65
	
66
	public void setStatus(String status) {
67
		_status = status;
68
	}
69
	
70
}
src/edu/ucsb/nceas/metacat/workflow/WorkflowEngineClient.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that implements system utility methods 
4
 *  Copyright: 2008 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Michael Daigle
7
 * 
8
 *   '$Author: daigle $'
9
 *     '$Date: 2009-03-23 13:56:56 -0800 (Mon, 23 Mar 2009) $'
10
 * '$Revision: 4854 $'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26

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

  
29
import java.util.Hashtable;
30

  
31
import org.apache.log4j.Logger;
32

  
33
public class WorkflowEngineClient implements WorkflowClientInterface {
34

  
35
	private static Logger logMetacat = Logger.getLogger(WorkflowEngineClient.class);
36
	
37
	public void execute(String workflowName, Hashtable<String, String> additionalParams) {
38
		// do execution stuff here
39
	}
40
	
41
	public String getStatus(String workflowId) {
42
		String statusXML = "";
43
		
44
		// do status stuff here
45
		
46
		return statusXML;
47
	}
48

  
49
 }
0 50

  
src/edu/ucsb/nceas/metacat/workflow/WorkflowJob.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: a single workflow job that is schedulable 
4
 *  Copyright: 2009 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Michael Daigle
7
 *
8
 *   '$Author: daigle $'
9
 *     '$Date: 2008-07-06 21:25:34 -0700 (Sun, 06 Jul 2008) $'
10
 * '$Revision: 4080 $'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26
package edu.ucsb.nceas.metacat.workflow;
27

  
28
import org.quartz.JobExecutionContext;
29
import org.quartz.JobExecutionException;
30

  
31
import edu.ucsb.nceas.metacat.scheduler.ScheduledJobInterface;
32

  
33
public class WorkflowJob implements ScheduledJobInterface {
34
	
35
	public void execute(JobExecutionContext context) throws JobExecutionException {
36
	}
37
	
38
	public void interrupt() {
39
	}
40
}
src/edu/ucsb/nceas/metacat/workflow/WorkflowClientInterface.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that loads eml-access.xml file containing ACL 
4
 *             for a metadata document into relational DB
5
 *  Copyright: 2000 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Jivka Bojilova
8
 *
9
 *   '$Author: daigle $'
10
 *     '$Date: 2009-03-25 14:04:06 -0800 (Wed, 25 Mar 2009) $'
11
 * '$Revision: 4863 $'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27

  
28
package edu.ucsb.nceas.metacat.workflow;
29

  
30
import java.util.Hashtable;
31

  
32
/**
33
 * This interface will handle the access control for different documents:
34
 * the package-orented, single eml2 document and other single file
35
 */
36
public interface WorkflowClientInterface
37
{
38

  
39
	public void execute(String workflowName, Hashtable<String, String> additionalParams);
40
	
41
	public String getStatus(String workflowId); 
42
 
43
}
0 44

  
src/edu/ucsb/nceas/metacat/util/SystemUtil.java
26 26

  
27 27
package edu.ucsb.nceas.metacat.util;
28 28

  
29
import java.io.IOException;
30 29
import java.util.Vector;
31 30
import java.util.regex.Matcher;
32 31
import java.util.regex.Pattern;
......
316 315
	 * 
317 316
	 * @return a string holding the backup location.  Null if none could be found.
318 317
	 */
319
	public static String getStoredBackupDir() throws UtilException {
318
	public static String getStoredBackupDir() throws MetacatUtilException {
320 319
		String applicationContext = null;
321 320
		try {
322 321
			applicationContext = ServiceService.getRealApplicationContext();
......
342 341
		return null;
343 342
	}
344 343
	
345
	public static void writeStoredBackupFile(String backupPath) throws UtilException {
344
	public static void writeStoredBackupFile(String backupPath) throws MetacatUtilException {
346 345
		String applicationContext = null;
347 346
		try {
348 347
			applicationContext = ServiceService.getRealApplicationContext();
......
364 363
			
365 364
		} catch (UtilException ue) {
366 365
			logMetacat.warn("Utility error writing backup file: " + ue.getMessage());
367
		} catch (IOException ioe) {
368
			logMetacat.warn("I/O error finding backup location: " + ioe.getMessage());
369 366
		} catch (ServiceException se) {
370 367
			logMetacat.warn("Service error getting real application context: " + se.getMessage());
371 368
		} 
......
399 396
	 *    
400 397
	 * @return a string holding the backup directory path
401 398
	 */
402
	public static String discoverExternalDir() throws UtilException {
399
	public static String discoverExternalDir() throws MetacatUtilException {
403 400
		String applicationContext = null; 
404 401
		
405 402
		try {
......
464 461
				return userHomeMetacatDir;
465 462
			}
466 463

  
467
		} catch (IOException ioe) {
468
			logMetacat.warn("I/O proplem finding backup location: " + ioe.getMessage());
469 464
		} catch (ServiceException se) {
470 465
			logMetacat.warn("Could not get real application context: " + se.getMessage());
466
		} catch (UtilException ue) {
467
			logMetacat.warn("Could not create directory: " + ue.getMessage());
471 468
		} catch (PropertyNotFoundException pnfe) {
472 469
			logMetacat.warn("Could not get default backup base dir property: "
473 470
					+ pnfe.getMessage());
......
497 494
			
498 495
				FileUtil.createDirectory(storedBackupLocDir);
499 496
				FileUtil.writeFile(storedBackupLocFile, externalDir);
500
			} catch (IOException ioe) {
501
				logMetacat.error("I/O error while trying to write stored backup directory: "
502
							+ storedBackupLocFile + " : " + ioe.getMessage());
503 497
			} catch (ServiceException se) {
504 498
				logMetacat.error("Could not get real application directory while trying to write "
505 499
							+ "stored backup directory: "+ storedBackupLocFile + " : " + se.getMessage());
src/edu/ucsb/nceas/metacat/util/RequestUtil.java
312 312
	public static void setUserId(HttpServletRequest request, String userId) {
313 313
		request.getSession().setAttribute("userId", userId);
314 314
	}
315
	
316

  
315 317
}
src/edu/ucsb/nceas/metacat/util/ErrorUtil.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that implements administrative methods 
4
 *  Copyright: 2008 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Michael Daigle
7
 * 
8
 *   '$Author: daigle $'
9
 *     '$Date: 2008-08-22 16:26:10 -0700 (Fri, 22 Aug 2008) $'
10
 * '$Revision: 4299 $'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26

  
27
package edu.ucsb.nceas.metacat.util;
28

  
29
import java.io.IOException;
30
import java.io.PrintWriter;
31
import java.util.Hashtable;
32

  
33
import javax.servlet.http.HttpServletResponse;
34

  
35
import org.apache.log4j.Logger;
36

  
37
public class ErrorUtil {
38
	
39
	private static Logger logMetacat = Logger.getLogger(RequestUtil.class);
40
	
41
	// 101XXX - general errors
42
	public static Long GENERAL_UTILITY_ERROR = new Long(101001);	
43
	public static Long METACAT_UTILITY_ERROR = new Long(101002);
44
	// 104XXX - property errors
45
	public static Long PROPERTY_NOT_FOUND = new Long(104001);	
46
	// 105XXX - permission errors
47
	public static Long NO_READ_PERMISSION = new Long(105001);
48
	
49
	// errorCodes is a lookup table for generic messages for each code.  It
50
	// is better to use the sendError() versions that accept an explicit 
51
	// error message;
52
	static Hashtable<Long, String> errorCodes = new Hashtable<Long, String>();
53
	static {
54
		errorCodes.put(GENERAL_UTILITY_ERROR, "General utility error");
55
		errorCodes.put(METACAT_UTILITY_ERROR, "Metacat utility error");
56
		errorCodes.put(PROPERTY_NOT_FOUND, "Property not found");
57
		errorCodes.put(NO_READ_PERMISSION, "Read permission denied for user");
58
	}
59
	
60
	/**
61
	 * private constructor - all methods are static so there is no
62
     * no need to instantiate.
63
	 */
64
	private ErrorUtil() {}
65
	
66
	public static void sendError(HttpServletResponse response, Long errorCode, String errorMessage) 
67
		throws ErrorSendingErrorException {
68
		
69
		PrintWriter out = null;
70
		try {
71
			out = response.getWriter();			
72
			response.setContentType("text/xml");
73
		
74
			out.println("<?xml version=\"1.0\"?>");
75
			out.println("<error>");
76
			out.println("<code>" + errorCode + "</code>");
77
			out.println("<message>" + errorMessage + "</message>");
78
			out.println("</error>");
79
		
80
		} catch (IOException ioe) {
81
			throw new ErrorSendingErrorException("I/O error when returning error: " 
82
					+ errorCode + " : " + errorMessage);
83
		} finally {
84
			if (out != null) {
85
				out.close();
86
			}
87
		}
88
	}
89
	
90
	public static void sendError(HttpServletResponse response, Long errorCode) 
91
		throws ErrorSendingErrorException {
92
		
93
		PrintWriter out = null;
94
		try {
95
			out = response.getWriter();	
96
			response.setContentType("text/xml");
97
		
98
			out.println("<?xml version=\"1.0\"?>");
99
			out.println("<error>");
100
			out.println("<code>" + errorCode + "</code>");
101
			out.println("<message>" + errorCodes.get(errorCode) + "</message>");
102
			out.println("</error>");
103
		
104
		} catch (IOException ioe) {
105
			throw new ErrorSendingErrorException("I/O error when returning error: " 
106
					+ errorCode);
107
		} finally {
108
			if (out != null) {
109
				out.close();
110
			}
111
		} out.close();
112
	}
113
	
114
	public static void sendError(HttpServletResponse response, PrintWriter out,
115
			Long errorCode, String errorMessage) throws ErrorSendingErrorException {
116

  
117
		response.setContentType("text/xml");
118

  
119
		out.println("<?xml version=\"1.0\"?>");
120
		out.println("<error>");
121
		out.println("<code>" + errorCode + "</code>");
122
		out.println("<message>" + errorMessage + "</message>");
123
		out.println("</error>");
124
	}
125

  
126
	public static void sendError(HttpServletResponse response, PrintWriter out,
127
			Long errorCode) throws ErrorSendingErrorException {
128

  
129
		response.setContentType("text/xml");
130

  
131
		out.println("<?xml version=\"1.0\"?>");
132
		out.println("<error>");
133
		out.println("<code>" + errorCode + "</code>");
134
		out.println("<message>" + errorCodes.get(errorCode) + "</message>");
135
		out.println("</error>");
136
	}
137
}
0 138

  
src/edu/ucsb/nceas/metacat/util/ErrorSendingErrorException.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: An Exception thrown when an error occurs because an 
4
 *             AccessionNumber was invalid or used incorrectly
5
 *  Copyright: 2008 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Michael Daigle
8
 *
9
 *   '$Author: daigle $'
10
 *     '$Date: 2009-03-23 13:56:56 -0800 (Mon, 23 Mar 2009) $'
11
 * '$Revision: 4854 $'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27

  
28
package edu.ucsb.nceas.metacat.util;
29
/**
30
 * Exception thrown when an error occurs in a utility method
31
 */
32
public class ErrorSendingErrorException extends Exception {
33

  
34
	private static final long serialVersionUID = 2470535012803585651L;
35

  
36
	/**
37
	 * Create a new AdminException.
38
	 *
39
	 * @param message The error or warning message.
40
	 */
41
	public ErrorSendingErrorException(String message) {
42
		super(message);
43
	}
44
}
0 45

  
src/edu/ucsb/nceas/metacat/util/ResponseUtil.java
26 26

  
27 27
package edu.ucsb.nceas.metacat.util;
28 28

  
29
import java.io.FileInputStream;
30
import java.io.FileNotFoundException;
29 31
import java.io.IOException;
32
import java.io.InputStream;
33
import java.io.OutputStream;
30 34

  
31 35
import javax.servlet.http.HttpServletRequest;
32 36
import javax.servlet.http.HttpServletResponse;
33 37

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

  
40
import edu.ucsb.nceas.utilities.FileUtil;
41

  
36 42
public class ResponseUtil {
37 43
	
38 44
	private static Logger logMetacat = Logger.getLogger(ResponseUtil.class);
39 45
	
46
	private static int DEFAULT_BUFFER_SIZE = 4 * 1024; // 4K buffer
47
	
40 48
	/**
41 49
	 * private constructor - all methods are static so there is no
42 50
     * no need to instantiate.
......
52 60
	 *            the context-relative URL to which the request is forwarded
53 61
	 */
54 62
	public static void redirectResponse(HttpServletRequest request,
55
			HttpServletResponse response, String destination)
56
			throws IOException {
57
		logMetacat.debug("Redirecting response to " + request.getContextPath() + destination);
58
		response.sendRedirect(request.getContextPath() + destination);
63
			HttpServletResponse response, String destination) throws MetacatUtilException {
64
		try {
65
			logMetacat.debug("Redirecting response to " + request.getContextPath() + destination);
66
			response.sendRedirect(request.getContextPath() + destination);
67
		} catch (IOException ioe) {
68
			throw new MetacatUtilException("I/O error when redirecting response to: " + destination);
69
		}
59 70
	}
71
	
72
	public static void writeFileToOutput(HttpServletResponse response, String fileDir, String fileName)
73
		throws MetacatUtilException {
74
		
75
		writeFileToOutput(response, fileDir, fileName, DEFAULT_BUFFER_SIZE);
76
	}
77
	
78
	public static void writeFileToOutput(HttpServletResponse response, String fileDir, String fileName, int bufferSize)
79
			throws MetacatUtilException {
80
		String filePath = "";
81
		try {
82
			filePath = fileDir + FileUtil.getFS() + fileName;
83
			
84
			int lastFileSep = fileName.lastIndexOf(FileUtil.getFS());
85
			String shortFileName = fileName.substring(lastFileSep + 1, fileName.length());
86
			response.setHeader("Content-Disposition", "attachment; filename=\"" + shortFileName + "\"");
87
			
88
			InputStream inputStream = new FileInputStream(filePath);
89
			OutputStream outputStream = response.getOutputStream();
90
			
91
			byte[] byteBuffer = new byte[bufferSize]; 
92

  
93
			int b = 0;
94
			while ((b = inputStream.read(byteBuffer)) != -1) {
95
				outputStream.write(byteBuffer, 0, b);
96
			}	
97
			
98
		} catch (FileNotFoundException fnfe) {
99
			throw new MetacatUtilException("Error finding file: " + filePath 
100
					+ " when writing to output");
101
		} catch (IOException ioe) {
102
			throw new MetacatUtilException("I/O Error when writing: " + filePath 
103
					+ "  to output");
104
		}
105
	}
60 106
}
src/edu/ucsb/nceas/metacat/scheduler/ScheduledJobDAO.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that holds the data from the scheduled_task 
4
 *             table in the database. 
5
 *  Copyright: 2009 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Michael Daigle
8
 * 
9
 *   '$Author: daigle $'
10
 *     '$Date: 2009-03-23 13:56:56 -0800 (Mon, 23 Mar 2009) $'
11
 * '$Revision: 4854 $'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27

  
28
package edu.ucsb.nceas.metacat.scheduler;
29

  
30
import java.sql.Timestamp;
31

  
32
import edu.ucsb.nceas.shared.BaseDAO;
33

  
34
public class ScheduledJobDAO extends BaseDAO {
35
	
36
	
37
	public static String SECONDLY = "secondly";
38
	public static String MINUTELY = "minutely";
39
	public static String HOURLY = "hourly";
40
	public static String DAILY = "daily";
41
	public static String WEEKLY = "weekly";
42

  
43
	private String _name;
44
	private String _triggerName;
45
	private String _groupName;
46
	private String _className;
47
	private Timestamp _startTime;
48
	private int _interval;
49
	
50
	public String getName() {
51
		return _name;
52
	}
53
	
54
	public void setName(String name) {
55
		_name = name;
56
	}
57
	
58
	public String getTriggerName() {
59
		return _triggerName;
60
	}
61
	
62
	public void setTriggerName(String triggerName) {
63
		_triggerName = triggerName;
64
	}
65
	
66
	public String getGroupName() {
67
		return _groupName;
68
	}
69
	
70
	public void setGroupName(String groupName) {
71
		_groupName = groupName;
72
	}
73
	
74
	public String getClassName() {
75
		return _className;
76
	}
77
	
78
	public void setClassName(String className) {
79
		_className = className;
80
	}
81
	
82
	public Timestamp getStartTime() {
83
		return _startTime;
84
	}
85
	
86
	public void setStartTime(Timestamp startTime) {
87
		_startTime = startTime;
88
	}
89
	
90
	public int getInterval() {
91
		return _interval;
92
	}
93
	
94
	public void setInterval(int interval) {
95
		_interval = interval;
96
	}
97
}
src/edu/ucsb/nceas/metacat/scheduler/SchedulerService.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that handles scheduling tasks 
4
 *  Copyright: 2009 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Michael Daigle
7
 * 
8
 *   '$Author: daigle $'
9
 *     '$Date: 2009-03-25 13:41:15 -0800 (Wed, 25 Mar 2009) $'
10
 * '$Revision: 4861 $'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26

  
27
package edu.ucsb.nceas.metacat.scheduler;
28

  
29
import java.text.DateFormat;
30
import java.text.ParseException;
31
import java.util.Arrays;
32
import java.util.Calendar;
33
import java.util.Date;
34
import java.util.Enumeration;
35
import java.util.Hashtable;
36
import java.util.Vector;
37

  
38
import javax.servlet.http.HttpServletRequest;
39
import javax.servlet.http.HttpServletResponse;
40

  
41
import org.apache.log4j.Logger;
42

  
43
import org.quartz.Job;
44
import org.quartz.JobDetail;
45
import org.quartz.Scheduler;
46
import org.quartz.SchedulerException;
47
import org.quartz.SchedulerFactory;
48
import org.quartz.Trigger;
49
import org.quartz.TriggerUtils;
50

  
51
import edu.ucsb.nceas.metacat.service.BaseService;
52
import edu.ucsb.nceas.metacat.service.ServiceException;
53
import edu.ucsb.nceas.shared.AccessException;
54

  
55
public class SchedulerService extends BaseService {
56
	
57
	private static SchedulerService schedulerService = null;
58
	
59
	private static Logger logMetacat = Logger.getLogger(SchedulerService.class);
60
	
61
	private static Scheduler sched = null;
62
	
63
	static Hashtable<String, String> jobClassNames = new Hashtable<String, String>();
64
	static {
65
		jobClassNames.put("workflow", "edu.ucsb.nceas.metacat.workflow.WorkflowJob");
66
	}
67

  
68
	/**
69
	 * private constructor since this is a singleton
70
	 */
71
	private SchedulerService() throws ServiceException {}
72
	
73
	/**
74
	 * Get the single instance of SchedulerService.
75
	 * 
76
	 * @return the single instance of SchedulerService
77
	 */
78
	public static SchedulerService getInstance() throws ServiceException {
79
		if (schedulerService == null) {
80
			schedulerService = new SchedulerService();
81
		}
82
		return schedulerService;
83
	}
84
	
85
	public boolean refreshable() {
86
		return true;
87
	}
88
	
89
	protected void doRefresh() throws ServiceException {
90
		stop();
91
	}
92

  
93
	protected void start() throws ServiceException {
94
		try {
95
			SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();
96
			
97
			sched = schedFact.getScheduler();
98
			// read jobs from db here.
99
			// then add jobs to sched.
100
			sched.start();
101
		} catch (SchedulerException se) {
102
			throw new ServiceException("Could not start scheduler: " + se.getMessage());
103
		}		
104
	}
105
	
106
	protected void stop() throws ServiceException {
107
		try {
108
			sched.shutdown(true);
109
			sched = null;
110
		} catch (SchedulerException se) {
111
			throw new ServiceException("Could not shut down scheduler: " + se.getMessage());
112
		}		
113
	}
114
	
115
	protected Vector<String> getStatus() throws ServiceException {
116
		return new Vector<String>();
117
	}
118
	
119
	public String scheduleHandler(Hashtable<String, String[]> params,
120
            HttpServletRequest request, HttpServletResponse response,
121
            String username, String[] groups) throws ServiceException {
122
        
123
		String returnString = "";
124
        String[] categories = params.get("category");
125
        if (categories == null || categories.length == 0) {
126
        	throw new ServiceException("SchedulerService.scheduleHandler - Category field " 
127
        			+ "must be populated in scheduler parameters");
128
        }
129
        
130
        String category = categories[0];
131
        
132
        if (category.equals("schedule")) {
133
    		Calendar startCal = null;
134
            Hashtable<String, String> jobParams = new Hashtable<String, String>();
135
        	
136
    		String jobTypes[] = params.get("type");
137
            if (jobTypes == null || jobTypes.length == 0) {
138
            	throw new ServiceException("SchedulerService.scheduleJob - Type field must be populated " 
139
            			+ "in scheduler parameters when scheduling job.");
140
            }
141
    		
142
            String delays[] = params.get("delay");
143
    		String startTimes[] = params.get("starttime");       
144
            try {
145
    			if (delays != null && delays.length > 0) {
146
    				startCal = getStartDateFromDelay(delays[0]);
147
    			} else if (startTimes != null && startTimes.length > 0) {
148
    				Date startDate = DateFormat.getInstance().parse(startTimes[0]);
149
    				startCal = Calendar.getInstance();
150
    				startCal.setTime(startDate);
151
    			} else {
152
    				throw new ServiceException("SchedulerService.scheduleJob -  Either delay or starttime  " 
153
    						+ "field must be populated in scheduler parameters when scheduling job.");
154
    			}
155
    		} catch (ParseException pe) {
156
    			throw new ServiceException("SchedulerService.scheduleJob - Could not parse start time " 
157
    					+ startTimes[0] + " : " + pe.getMessage());
158
    		}
159
            
160
            String intervals[] = params.get("interval"); 
161
            if (intervals == null || intervals.length == 0) {
162
            	throw new ServiceException("SchedulerService.scheduleJob - Interval field must be populated " 
163
            			+ "in scheduler parameters when scheduling job.");
164
            } 
165
            String interval = intervals[0];
166
            
167
            Enumeration<String> paramNames = params.keys();
168
            while (paramNames.hasMoreElements()) {
169
            	String paramName = paramNames.nextElement();
170
            	if (paramName.startsWith("jobparam_")) {
171
            		jobParams.put(paramName.substring(8), params.get(paramName)[0]);
172
            	}
173
            }
174
                   
175
            String jobType = jobTypes[0];
176
            String jobName = jobType + Calendar.getInstance().getTimeInMillis();
177
        	
178
        	returnString = scheduleJob(jobName, startCal, interval, jobType, jobParams);
179
        } else if (category.equals("unschedule")) {
180
        	String jobNames[] = params.get("jobName");
181
        	if (jobNames == null || jobNames.length == 0) {
182
        		throw new ServiceException("SchedulerService.scheduleJob - Job ID field must be populated " 
183
            			+ "in scheduler parameters when unscheduling job.");
184
        	}
185
        	        	
186
        	unscheduleJob(jobNames[0]);
187
        } else if (category.equals("delete")) {
188
//        	deleteJob(params);
189
        }
190
        
191
        return returnString;
192
	}
193
	
194
	public String scheduleJob(String jobName, Calendar startCal, String interval,
195
			String jobType, Hashtable<String, String> jobParams) throws ServiceException {
196

  
197
        Class<Job> jobClass = null;
198
       
199
        String className = jobClassNames.get(jobType);
200
        if (className == null) {
201
        	throw new ServiceException("SchedulerService.scheduleJob - Type: " + jobType 
202
        			+ " is not registered as a valid job type");
203
        }
204
        
205
        logMetacat.info("Scheduling job -- name: " + jobName + ", class: " + className 
206
        		+ ", start time: " + startCal.toString() + ", interval: " + interval);
207
       	 
208
        try {        	
209
        	jobClass = (Class<Job>)Class.forName(jobType + "Job");     	
210
        } catch (ClassNotFoundException cnfe) {
211
        	throw new ServiceException("SchedulerService.scheduleJob - Could not find class with name: " 
212
        			+ jobType + "Job");
213
        }    
214
        
215
		char intervalUnit = interval.trim().charAt(interval.length());
216
		String intervalStrValue = interval.trim().substring(0, interval.length() - 1);
217
		int intervalValue;
218
		try {
219
			intervalValue = Integer.parseInt(intervalStrValue);
220
		} catch (NumberFormatException nfe) {
221
			throw new ServiceException("SchedulerService.scheduleJob - Could not parse interval value " 
222
					+ "into an integer: " + intervalStrValue);
223
		}
224
		
225
		switch (intervalUnit) {
226
		case 's':
227
		case 'S':
228
			scheduleSecondlyJob(jobName, jobClass, startCal, intervalValue, jobType);
229
			break;
230
		case 'm':
231
		case 'M':
232
			scheduleMinutelyJob(jobName, jobClass, startCal, intervalValue, jobType);
233
			break;
234
		case 'h':
235
		case 'H':
236
			scheduleHourlyJob(jobName, jobClass, startCal, intervalValue, jobType);
237
			break;
238
		case 'd':
239
		case 'D':
240
			scheduleDailyJob(jobName, jobClass, startCal, intervalValue, jobType);
241
			break;
242
		default:
243
			throw new ServiceException("SchedulerService.scheduleJob - Could not interpret interval unit: " 
244
					+ intervalUnit + ". Unit must be s, m, h or d");	
245
		}	
246
		
247
		try {
248
			ScheduledJobAccess jobAccess = new ScheduledJobAccess();
249
			jobAccess.createJob(jobName, jobClass, startCal, intervalValue, jobParams);
250
		} catch (AccessException ae) {
251
			try {
252
				deleteJob(jobName);
253
			} catch (ServiceException se) {
254
				// Not much we can do here but log this
255
				logMetacat.error("An access exception was thrown when writing job: " + jobName 
256
						+ "to the db, and another exception was thrown when trying to remove the " 
257
						+ "job from the scheduler.  The db and scheduler may be out of sync");
258
			}
259
			throw new ServiceException("SchedulerService.scheduleJob - Error accessing db: " 
260
					+ ae.getMessage());
261
		}
262
		
263
		return jobName;
264
	}
265
	
266
	public void unscheduleJob(String jobName) throws ServiceException {
267
		try {
268
			ScheduledJobAccess jobAccess = new ScheduledJobAccess();
269
			ScheduledJobDAO jobDAO = jobAccess.getJobByName(jobName);
270

  
271
			sched.unscheduleJob(jobDAO.getName(), jobDAO.getGroupName());
272

  
273
			jobDAO.setStatus(ScheduledJobInterface.STATE_UNSHCEDULED);
274
			jobAccess.updateJobStatus(jobDAO);
275
		} catch (SchedulerException se) {
276
			throw new ServiceException("SchedulerService.unscheduleJob - Could not create "
277
							+ "scheduled job because of service issue: " + se.getMessage());
278
		} catch (AccessException ae) {
279
			throw new ServiceException("SchedulerService.unscheduleJob - Could not create "
280
							+ "scheduled job because of db access issue: " + ae.getMessage());
281
		}
282
	}
283
	
284
	public void deleteJob(String jobName) throws ServiceException {
285
		String groupName = "";
286
		
287
		try {
288
			ScheduledJobAccess jobAccess = new ScheduledJobAccess();
289
			ScheduledJobDAO jobDAO = jobAccess.getJobByName(jobName);
290
			groupName = jobDAO.getGroupName();
291
			
292
			sched.deleteJob(jobName, groupName);
293
		} catch (SchedulerException se) {
294
			throw new ServiceException("SchedulerService.deleteJob - Could not delete job: " 
295
					+ jobName + " for group: " + groupName + " : " + se.getMessage());
296
		} catch (AccessException ae) {
297
			throw new ServiceException("SchedulerService.deleteJob - Could not delete "
298
					+ "scheduled job because of db access issue: " + ae.getMessage());
299
}
300
	}
301
	
302
	public Vector<String> getJobInfo(String groupName) throws ServiceException {
303
		Vector<String> returnVector = new Vector<String>();
304
		
305
		try {
306
			if (groupName.equalsIgnoreCase("All")) {
307
				String[] groupNames = sched.getJobGroupNames();
308
				for (int i = 0; i < groupNames.length; i++) {
309
					returnVector.addAll(Arrays.asList(sched.getJobNames(groupNames[i])));
310
				}
311
			} else {
312
				returnVector.addAll(Arrays.asList(sched.getJobNames(groupName)));
313
			}
314
		} catch (SchedulerException se) {
315
			throw new ServiceException("SchedulerService.getJobNames - Could not get job names for group: " 
316
					+ groupName + " : " + se.getMessage());
317
		}
318

  
319
		return returnVector;
320
	}
321
	
322
	private void scheduleSecondlyJob(String name, Class<Job> jobClass, Calendar startTime, int interval, String jobGroup) throws ServiceException {
323
		JobDetail jobDetail = new JobDetail(name, jobGroup, jobClass);
324

  
325
		Trigger trigger = TriggerUtils.makeSecondlyTrigger(interval);
326
		trigger.setName(name);
327
		trigger.setStartTime(startTime.getTime());
328

  
329
		try {
330
			sched.scheduleJob(jobDetail, trigger);
331
		} catch (SchedulerException se) {
332
			throw new ServiceException("SchedulerService.scheduleSecondlyJob - Could not create " 
333
					+ "scheduler: " + se.getMessage());
334
		}
335
	}
336
	
337
	private void scheduleMinutelyJob(String name, Class<Job> jobClass, Calendar startTime, int interval, String jobGroup) throws ServiceException {
338
		JobDetail jobDetail = new JobDetail(name, jobGroup, jobClass);
339

  
340
		Trigger trigger = TriggerUtils.makeMinutelyTrigger(interval);
341
		trigger.setName(name);
342
		trigger.setStartTime(startTime.getTime());
343

  
344
		try {
345
			sched.scheduleJob(jobDetail, trigger);
346
		} catch (SchedulerException se) {
347
			throw new ServiceException("SchedulerService.scheduleMinutelyJob - Could not create " 
348
					+ "scheduler: " + se.getMessage());
349
		}
350
	}
351
	
352
	private void scheduleHourlyJob(String name, Class<Job> jobClass, Calendar startTime, int interval, String jobGroup) throws ServiceException {
353
		JobDetail jobDetail = new JobDetail(name, jobGroup, jobClass);
354

  
355
		Trigger trigger = TriggerUtils.makeHourlyTrigger(interval);
356
		trigger.setName(name);
357
		trigger.setStartTime(startTime.getTime());
358

  
359
		try {
360
			sched.scheduleJob(jobDetail, trigger);
361
		} catch (SchedulerException se) {
362
			throw new ServiceException("SchedulerService.scheduleHourlyJob - Could not create " 
363
					+  "scheduler: " + se.getMessage());
364
		}
365
	}
366
	
367
	private void scheduleDailyJob(String name, Class<Job> jobClass, Calendar startTime, int interval, String jobGroup) throws ServiceException {
368

  
369
		JobDetail jobDetail = new JobDetail(name, jobGroup, jobClass);
370

  
371
		Trigger trigger = TriggerUtils.makeHourlyTrigger(interval * 24);
372
		trigger.setName(name);
373
		trigger.setStartTime(startTime.getTime());
374

  
375
		try {
376
			sched.scheduleJob(jobDetail, trigger);
377
		} catch (SchedulerException se) {
378
			throw new ServiceException("SchedulerService.scheduleHourlyJob - Could not create " 
379
					+ "scheduler: " + se.getMessage());
380
		}
381
	}
382
	
383

  
384
	
385
	private Calendar getStartDateFromDelay(String delay) throws ServiceException {
386
		Calendar cal = Calendar.getInstance();
387
	
388
		char delayUnit = delay.trim().charAt(delay.length());
389
		String delayStrValue = delay.trim().substring(0, delay.length() - 1);
390
		int delayValue;
391
		try {
392
			delayValue = Integer.parseInt(delayStrValue);
393
		} catch (NumberFormatException nfe) {
394
			throw new ServiceException("SchedulerService.getStartDateFromDelay - Could not " 
395
					+ "parse delay value into an integer: " + delayStrValue);
396
		}
397
		
398
		switch (delayUnit) {
399
		case 's':
400
		case 'S':
401
			cal.add(Calendar.SECOND, delayValue);
402
			break;
403
		case 'm':
404
		case 'M':
405
			cal.add(Calendar.MINUTE, delayValue);
406
			break;
407
		case 'h':
408
		case 'H':
409
			cal.add(Calendar.HOUR, delayValue);
410
			break;
411
		case 'd':
412
		case 'D':
413
			cal.add(Calendar.DAY_OF_YEAR, delayValue);
414
			break;
415
		default:
416
			throw new ServiceException("SchedulerService.getStartDateFromDelay - Could not " 
417
					+ "interpret delay unit: " + delayUnit + ". Unit must be s, m, h or d");	
418
		}
419
		
420
		return cal;
421
	}
422
	
423

  
424

  
425
	
426
	
427
	
428
}
0 429

  
src/edu/ucsb/nceas/metacat/scheduler/ScheduledJobParamsAccess.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that manages database access of scheduled task 
4
 *             information.
5
 *  Copyright: 2009 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Michael Daigle
8
 * 
9
 *   '$Author: daigle $'
10
 *     '$Date: 2009-03-23 13:56:56 -0800 (Mon, 23 Mar 2009) $'
11
 * '$Revision: 4854 $'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27

  
28
package edu.ucsb.nceas.metacat.scheduler;
29

  
30
import java.sql.PreparedStatement;
31
import java.sql.SQLException;
32
import java.util.Enumeration;
33
import java.util.Hashtable;
34

  
35
import org.apache.log4j.Logger;
36

  
37
import edu.ucsb.nceas.shared.AccessException;
38
import edu.ucsb.nceas.shared.BaseAccess;
39

  
40
public class ScheduledJobParamsAccess extends BaseAccess {
41
	
42
	private Logger logMetacat = Logger.getLogger(ScheduledJobParamsAccess.class);
43
	
44
	public ScheduledJobParamsAccess() throws AccessException {
45
		super("ScheduledJobParamsAccess");
46
	}
47
	
48
	protected void createJobParams(Long jobId, Hashtable<String, String> jobParams) throws AccessException {
49
		Enumeration<String> paramKeys = jobParams.keys();
50
		
51
		while(paramKeys.hasMoreElements()) {
52
			String paramKey = paramKeys.nextElement();
53
			
54
			ScheduledJobParamsDAO jobParamsDAO = new ScheduledJobParamsDAO();
55
			jobParamsDAO.setStatus(ScheduledJobInterface.STATE_SCHEDULED);
56
			jobParamsDAO.setJobId(jobId);
57
			jobParamsDAO.setKey(paramKey);
58
			jobParamsDAO.setValue(jobParams.get(paramKey));
59
			
60
			try {
61
				String sql = 
62
					"INSERT INTO scheduled_job_params (date_created, date_updated, status, job_id, key, value) " 
63
					+ "VALUES(now(), now(), ?, ?, ?, ?)";		
64
				PreparedStatement pstmt = conn.prepareStatement(sql);
65
			
66
				pstmt.setString(1, jobParamsDAO.getStatus());
67
				pstmt.setLong(2, jobParamsDAO.getJobId());
68
				pstmt.setString(3, jobParamsDAO.getKey());
69
				pstmt.setString(4, jobParamsDAO.getValue());
70
				
71
				logMetacat.info("SQL createJobParams - " + sql);
72
				logMetacat.info("SQL params:  [" + jobParamsDAO.getStatus() + ","
73
						+ jobParamsDAO.getJobId() + ","
74
						+ jobParamsDAO.getKey() + ","
75
						+ jobParamsDAO.getValue().toString() + "]");
76
				pstmt.execute();
77
				
78
			} catch (SQLException sqle) {
79
				// Just throw the exception.  The ScheduledJobAccess class should handle cleanup.
80
				throw new AccessException("ScheduledJobParamsAccess.createJobParams - SQL error when creating scheduled job parameter : "    
81
					 + sqle.getMessage());
82
			}
83
		}
84
	}
85
	
86
	protected void deleteJobParams(Long jobId) throws AccessException {
87
		try {
88
			String sql = "UPDATE scheduled_job_params SET status = ? WHERE jobId = ?";		
89
			pstmt.setString(1, ScheduledJobInterface.STATE_DELETED);
90
			pstmt.setLong(1, jobId);
91
			
92
			logMetacat.info("SQL deleteJobParams - " + sql);
93

  
94
			pstmt.execute();
95
		} catch (SQLException sqle) {
96
			throw new AccessException("ScheduledJobParamsAccess.deleteJobParams - SQL error " 
97
					+ "when deleting scheduled job params for job" + jobId  + " : "  + sqle.getMessage());
98
		}	
99
		
100
	}	
101
}
src/edu/ucsb/nceas/metacat/scheduler/ScheduledJobParamsDAO.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that holds the data from the scheduled_task 
4
 *             table in the database. 
5
 *  Copyright: 2009 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Michael Daigle
8
 * 
9
 *   '$Author: daigle $'
10
 *     '$Date: 2009-03-23 13:56:56 -0800 (Mon, 23 Mar 2009) $'
11
 * '$Revision: 4854 $'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27

  
28
package edu.ucsb.nceas.metacat.scheduler;
29

  
30
import edu.ucsb.nceas.shared.BaseDAO;
31

  
32
public class ScheduledJobParamsDAO extends BaseDAO {
33

  
34
	private Long _jobId;
35
	private String _key;
36
	private String _value;
37
	
38
	public Long getJobId() {
39
		return _jobId;
40
	}
41
	
42
	public void setJobId(Long jobId) {
43
		_jobId = jobId;
44
	}
45
	
46
	public String getKey() {
47
		return _key;
48
	}
49
	
50
	public void setKey(String key) {
51
		_key = key;
52
	}
53
	
54
	public String getValue() {
55
		return _value;
56
	}
57
	
58
	public void setValue(String value) {
59
		_value = value;
60
	}
61
}
src/edu/ucsb/nceas/metacat/scheduler/ScheduledJobInterface.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that runs a single scheduled report task 
4
 *  Copyright: 2009 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Michael Daigle
7
 * 
8
 *   '$Author: daigle $'
9
 *     '$Date: 2009-03-23 13:56:56 -0800 (Mon, 23 Mar 2009) $'
10
 * '$Revision: 4854 $'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26

  
27
package edu.ucsb.nceas.metacat.scheduler;
28

  
29
import org.quartz.InterruptableJob;
30

  
31
public interface ScheduledJobInterface extends InterruptableJob {
32
	
33
	public static String STATE_SCHEDULED = "scheduled";
34
	public static String STATE_EXECUTING = "executing";
35
	public static String STATE_UNSHCEDULED = "unscheduled";	
36
	public static String STATE_DELETED = "deleted";
37
	
38
}
0 39

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff