comparison flys-client/src/main/java/de/intevation/flys/client/server/StepForwardServiceImpl.java @ 215:e02f50a3ad59

Improved the exception handling of artifact / collection specific operations. Warning dialog are displayed after such an exception. flys-client/trunk@1657 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 08 Apr 2011 08:51:28 +0000
parents 88c530c25968
children 924da6695800
comparison
equal deleted inserted replaced
214:29c6d9573ae7 215:e02f50a3ad59
9 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; 9 import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
10 import de.intevation.artifacts.httpclient.http.HttpClient; 10 import de.intevation.artifacts.httpclient.http.HttpClient;
11 import de.intevation.artifacts.httpclient.http.HttpClientImpl; 11 import de.intevation.artifacts.httpclient.http.HttpClientImpl;
12 import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; 12 import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler;
13 13
14 import de.intevation.flys.client.shared.exceptions.ServerException;
14 import de.intevation.flys.client.shared.model.Artifact; 15 import de.intevation.flys.client.shared.model.Artifact;
15 import de.intevation.flys.client.shared.model.ArtifactDescription; 16 import de.intevation.flys.client.shared.model.ArtifactDescription;
16 import de.intevation.flys.client.shared.model.Data; 17 import de.intevation.flys.client.shared.model.Data;
17 import de.intevation.flys.client.shared.model.DataItem; 18 import de.intevation.flys.client.shared.model.DataItem;
18 import de.intevation.flys.client.client.services.StepForwardService; 19 import de.intevation.flys.client.client.services.StepForwardService;
26 */ 27 */
27 public class StepForwardServiceImpl 28 public class StepForwardServiceImpl
28 extends AdvanceServiceImpl 29 extends AdvanceServiceImpl
29 implements StepForwardService 30 implements StepForwardService
30 { 31 {
31 /** XPath that points to the result text of a feed or advance operation.*/ 32 /** XPath that points to the result type of a feed or advance operation.*/
32 public static final String XPATH_RESULT = "/art:result/text()"; 33 public static final String XPATH_RESULT = "/art:result/@art:type";
33 34
34 /** A constant that marks errors.*/ 35 /** A constant that marks errors.*/
35 public static final String OPERATION_FAILURE = "FAILED"; 36 public static final String OPERATION_FAILURE = "FAILURE";
37
38 /** The error message key that is thrown if an error occured while feeding
39 * new data.*/
40 public static final String ERROR_FEED_DATA = "error_feed_data";
36 41
37 42
38 /** 43 /**
39 * This method wraps the artifact operations FEED and ADVANCE. FEED is 44 * This method wraps the artifact operations FEED and ADVANCE. FEED is
40 * always triggerd, ADVANCE only, if there is at least one reachable state. 45 * always triggerd, ADVANCE only, if there is at least one reachable state.
43 * @param artifact The artifact that needs to be fed. 48 * @param artifact The artifact that needs to be fed.
44 * @param data An array of Data objects that contain the information that 49 * @param data An array of Data objects that contain the information that
45 * 50 *
46 * @return the modified artifact. 51 * @return the modified artifact.
47 */ 52 */
48 public Artifact go(String serverUrl, Artifact artifact, Data[] data) { 53 public Artifact go(String serverUrl, Artifact artifact, Data[] data)
54 throws ServerException
55 {
49 Artifact afterFeed = feed(serverUrl, artifact, data); 56 Artifact afterFeed = feed(serverUrl, artifact, data);
50 57
51 if (afterFeed == null) { 58 if (afterFeed == null) {
52 System.err.println("StepForwardService.feed() - FAILED"); 59 System.err.println("StepForwardService.feed() - FAILED");
53 // XXX Better handling here! 60 throw new ServerException(ERROR_FEED_DATA);
54 return null;
55 } 61 }
56 62
57 ArtifactDescription desc = afterFeed.getArtifactDescription(); 63 ArtifactDescription desc = afterFeed.getArtifactDescription();
58 String[] reachable = desc.getReachableStates(); 64 String[] reachable = desc.getReachableStates();
59 65
76 * @param data An array of Data objects that contain the information that 82 * @param data An array of Data objects that contain the information that
77 * are used for the FEED operation. 83 * are used for the FEED operation.
78 * 84 *
79 * @return a new artifact parsed from the description of FEED. 85 * @return a new artifact parsed from the description of FEED.
80 */ 86 */
81 protected Artifact feed(String serverUrl, Artifact artifact, Data[] data) { 87 protected Artifact feed(String serverUrl, Artifact artifact, Data[] data)
88 throws ServerException
89 {
82 Document feed = ClientProtocolUtils.newFeedDocument( 90 Document feed = ClientProtocolUtils.newFeedDocument(
83 artifact.getUuid(), 91 artifact.getUuid(),
84 artifact.getHash(), 92 artifact.getHash(),
85 createKVP(data)); 93 createKVP(data));
86 94
94 feed, 102 feed,
95 new DocumentResponseHandler()); 103 new DocumentResponseHandler());
96 104
97 if (description == null) { 105 if (description == null) {
98 System.err.println("StepForwardService.feed() - FAILED"); 106 System.err.println("StepForwardService.feed() - FAILED");
99 return artifact; 107 throw new ServerException(ERROR_FEED_DATA);
100 } 108 }
101 109
102 String result = XMLUtils.xpathString( 110 String result = XMLUtils.xpathString(
103 description, 111 description,
104 XPATH_RESULT, 112 XPATH_RESULT,
106 114
107 if (result == null || !result.equals(OPERATION_FAILURE)) { 115 if (result == null || !result.equals(OPERATION_FAILURE)) {
108 System.out.println("StepForwardService.feed() - SUCCESS"); 116 System.out.println("StepForwardService.feed() - SUCCESS");
109 return (Artifact) new FLYSArtifactCreator().create(description); 117 return (Artifact) new FLYSArtifactCreator().create(description);
110 } 118 }
119 else if (result != null && result.equals(OPERATION_FAILURE)) {
120 throw new ServerException(ERROR_FEED_DATA);
121 }
111 } 122 }
112 catch (ConnectionException ce) { 123 catch (ConnectionException ce) {
113 System.err.println(ce.getLocalizedMessage()); 124 System.err.println(ce.getLocalizedMessage());
114 } 125 }
115 126
116 System.err.println("StepForwardService.feed() - FAILED"); 127 System.err.println("StepForwardService.feed() - FAILED");
117 128 throw new ServerException(ERROR_FEED_DATA);
118 return artifact;
119 } 129 }
120 130
121 131
122 /** 132 /**
123 * This method creates an array of key/value pairs from an array of Data 133 * This method creates an array of key/value pairs from an array of Data

http://dive4elements.wald.intevation.org