annotate gnv/src/main/java/de/intevation/gnv/action/PreviousArtifactStepAction.java @ 580:377da78ed36b

Display an exception if an error occured while stepping back to a former state (issue183). gnv/trunk@719 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 01 Mar 2010 15:52:24 +0000
parents df78178e1180
children 15ac78a91d1b
rev   line source
394
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.action;
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
396
8330c1dbab34 Cleanup imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 394
diff changeset
3 import de.intevation.gnv.action.sessionmodel.SessionModel;
8330c1dbab34 Cleanup imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 394
diff changeset
4 import de.intevation.gnv.action.sessionmodel.SessionModelFactory;
8330c1dbab34 Cleanup imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 394
diff changeset
5
8330c1dbab34 Cleanup imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 394
diff changeset
6 import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient;
8330c1dbab34 Cleanup imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 394
diff changeset
7 import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory;
8330c1dbab34 Cleanup imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 394
diff changeset
8
580
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
9 import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription;
396
8330c1dbab34 Cleanup imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 394
diff changeset
10 import de.intevation.gnv.artifactdatabase.objects.ArtifactObject;
8330c1dbab34 Cleanup imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 394
diff changeset
11
394
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import javax.servlet.http.HttpServletRequest;
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import javax.servlet.http.HttpServletResponse;
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import org.apache.log4j.Logger;
396
8330c1dbab34 Cleanup imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 394
diff changeset
16
394
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 import org.apache.struts.action.ActionForm;
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 import org.apache.struts.action.ActionForward;
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 import org.apache.struts.action.ActionMapping;
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20
409
df78178e1180 Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 396
diff changeset
21
394
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 /**
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 * @author Ingo Weinzierl <ingo.weinzierl@intevation.de>
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 *
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 */
409
df78178e1180 Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 396
diff changeset
26 public class PreviousArtifactStepAction extends DescribeUIAction {
394
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 public static final String URL_STATE_KEY = "target";
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 private static Logger logger =
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 Logger.getLogger(PreviousArtifactStepAction.class);
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 public PreviousArtifactStepAction() {
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 super();
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 }
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 @Override
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 public ActionForward execute(
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 ActionMapping mapping,
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 ActionForm form,
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 HttpServletRequest request,
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 HttpServletResponse response
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 ) throws Exception {
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 String id = request.getSession().getId();
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49
409
df78178e1180 Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 396
diff changeset
50 SessionModel session = SessionModelFactory.getInstance().getSessionModel(
df78178e1180 Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 396
diff changeset
51 request);
394
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52
580
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
53 ArtifactDescription ad = session.getArtifactDescription();
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
54 if (ad == null) {
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
55 logger.warn("Session timed out.");
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
56 request.setAttribute(
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
57 CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID,
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
58 "SessionTimeout has occured");
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
59 new FetchArtifactFactoriesAction().execute(
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
60 mapping, form, request, response);
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
61
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
62 return super.execute(mapping, form, request, response);
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
63 }
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
64
409
df78178e1180 Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 396
diff changeset
65 // TODO check if target is reachable
394
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66
409
df78178e1180 Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 396
diff changeset
67 ArtifactDatabaseClientFactory f =
df78178e1180 Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 396
diff changeset
68 ArtifactDatabaseClientFactory.getInstance();
df78178e1180 Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 396
diff changeset
69 ArtifactDatabaseClient client =
df78178e1180 Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 396
diff changeset
70 f.getArtifactDatabaseClient(getLocale(request));
394
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71
409
df78178e1180 Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 396
diff changeset
72 ArtifactObject artifactFactory = session.getSelectedArtifactFactory();
df78178e1180 Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 396
diff changeset
73 ArtifactObject currentArtifact = session.getCurrentArtifact();
394
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74
409
df78178e1180 Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 396
diff changeset
75 String target = (String) request.getParameter(URL_STATE_KEY);
df78178e1180 Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 396
diff changeset
76 logger.debug("Step back to previous state: " + target);
df78178e1180 Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 396
diff changeset
77
580
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
78 try {
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
79 client.doAdvance(
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
80 artifactFactory,
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
81 currentArtifact,
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
82 target
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
83 );
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
84 }
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
85 catch (Exception e) {
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
86 logger.error(e, e);
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
87 request.setAttribute(
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
88 CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID,
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
89 e.getMessage());
377da78ed36b Display an exception if an error occured while stepping back to a former state (issue183).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 409
diff changeset
90 }
394
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 return super.execute(mapping, form, request, response);
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 }
14eecfde4607 Render links to step back to previous states into gui. Added controller to advance back to these states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 }
409
df78178e1180 Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 396
diff changeset
95 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org