01: /*
02: * Created on Feb 27, 2004
03: *
04: * To change the template for this generated file go to
05: * Window - Preferences - Java - Code Generation - Code and Comments
06: */
07: package org.vfny.geoserver.action.validation;
08:
09: import org.apache.struts.action.ActionError;
10: import org.apache.struts.action.ActionErrors;
11: import org.apache.struts.action.ActionForm;
12: import org.apache.struts.action.ActionForward;
13: import org.apache.struts.action.ActionMapping;
14: import org.vfny.geoserver.action.ConfigAction;
15: import org.vfny.geoserver.config.validation.TestSuiteConfig;
16: import org.vfny.geoserver.config.validation.ValidationConfig;
17: import org.vfny.geoserver.global.UserContainer;
18: import java.util.HashMap;
19: import java.util.Map;
20: import javax.servlet.ServletContext;
21: import javax.servlet.http.HttpServletRequest;
22: import javax.servlet.http.HttpServletResponse;
23:
24: /**
25: * ValidationTestDoIt purpose.
26: * <p>
27: * Description of ValidationTestDoIt ...
28: * </p>
29: *
30: * @author dzwiers, Refractions Research, Inc.
31: * @author $Author: sploreg $ (last modification)
32: * @version $Id: ValidationTestDoIt.java 6177 2007-02-19 10:11:27Z aaime $
33: */
34: public class ValidationTestDoIt extends ConfigAction {
35: public ActionForward execute(ActionMapping mapping,
36: ActionForm incomingForm, UserContainer user,
37: HttpServletRequest request, HttpServletResponse response) {
38: boolean stopThread = false;
39: String parameter = mapping.getParameter();
40:
41: if ((parameter != null) && parameter.equals("stop")) {
42: stopThread = true;
43: }
44:
45: //Checks to see if previous Validation has even finished executing yet.
46: Thread oldThread = (Thread) request.getSession().getAttribute(
47: ValidationRunnable.KEY);
48:
49: if ((oldThread != null) && oldThread.isAlive()) {
50: //OldThread has not finished execution; Shouldn't start a new one.
51: //Alternatively, we could wait.
52: if (stopThread == true) {
53: oldThread.stop(); //This is decprecated, but is there another way to stop a Runnable?
54: }
55: } else {
56: ServletContext context = this .getServlet()
57: .getServletContext();
58: ValidationConfig validationConfig = (ValidationConfig) context
59: .getAttribute(ValidationConfig.CONFIG_KEY);
60: TestSuiteConfig suiteConfig = (TestSuiteConfig) request
61: .getSession().getAttribute(
62: TestSuiteConfig.CURRENTLY_SELECTED_KEY);
63: Map plugins = new HashMap();
64: Map testSuites = new HashMap();
65: validationConfig.toDTO(plugins, testSuites); // return by ref.
66:
67: TestValidationResults results = new TestValidationResults();
68:
69: try {
70: ValidationRunnable testThread = new ValidationRunnable(
71: request);
72: testThread.setup(results, getDataConfig().toRepository(
73: context), plugins, testSuites);
74:
75: Thread thread = new Thread(testThread);
76: thread.start();
77:
78: request.getSession().setAttribute(
79: ValidationRunnable.KEY, thread);
80: } catch (Exception erp) {
81: ActionErrors errors = new ActionErrors();
82: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
83: "error.cannotRunValidation", erp));
84: saveErrors(request, errors);
85: }
86: }
87:
88: return mapping.findForward("config.validation.displayResults");
89: }
90: }
|