Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/test/SinfoProof.java @ 9027:274ddafb719b
S-Info-Proof-Init
Testing
author | gernotbelger |
---|---|
date | Thu, 26 Apr 2018 10:46:12 +0200 |
parents | 679b1442c886 |
children |
comparison
equal
deleted
inserted
replaced
9026:679b1442c886 | 9027:274ddafb719b |
---|---|
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.client.test; | 9 package org.dive4elements.river.client.test; |
10 | 10 |
11 import java.io.File; | 11 import java.io.File; |
12 import java.io.FileOutputStream; | |
12 import java.io.IOException; | 13 import java.io.IOException; |
13 import java.net.MalformedURLException; | 14 import java.io.InputStreamReader; |
15 import java.io.OutputStream; | |
16 import java.io.OutputStreamWriter; | |
14 import java.util.ArrayList; | 17 import java.util.ArrayList; |
15 import java.util.List; | 18 import java.util.HashMap; |
16 | 19 |
17 import org.apache.log4j.Logger; | |
18 import org.apache.log4j.PropertyConfigurator; | |
19 import org.dive4elements.artifacts.common.ArtifactNamespaceContext; | 20 import org.dive4elements.artifacts.common.ArtifactNamespaceContext; |
20 import org.dive4elements.artifacts.common.utils.ClientProtocolUtils; | 21 import org.dive4elements.artifacts.common.utils.ClientProtocolUtils; |
21 import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException; | 22 import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException; |
22 import org.dive4elements.artifacts.httpclient.http.HttpClient; | 23 import org.dive4elements.artifacts.httpclient.http.HttpClient; |
23 import org.dive4elements.artifacts.httpclient.http.HttpClientImpl; | 24 import org.dive4elements.artifacts.httpclient.http.HttpClientImpl; |
24 import org.dive4elements.artifacts.httpclient.http.response.DocumentResponseHandler; | 25 import org.dive4elements.artifacts.httpclient.http.response.DocumentResponseHandler; |
25 import org.dive4elements.artifacts.httpclient.utils.Configuration; | |
26 import org.dive4elements.artifacts.httpclient.utils.XMLUtils; | 26 import org.dive4elements.artifacts.httpclient.utils.XMLUtils; |
27 import org.dive4elements.river.client.client.ui.NilDatacageTwinPanelInfo; | |
28 import org.dive4elements.river.client.client.ui.RecommandationUtils; | |
27 import org.dive4elements.river.client.server.AdvanceServiceImpl; | 29 import org.dive4elements.river.client.server.AdvanceServiceImpl; |
28 import org.dive4elements.river.client.server.ArtifactHelper; | 30 import org.dive4elements.river.client.server.ArtifactHelper; |
29 import org.dive4elements.river.client.server.CollectionHelper; | 31 import org.dive4elements.river.client.server.CollectionHelper; |
30 import org.dive4elements.river.client.server.CreateCollectionServiceImpl; | 32 import org.dive4elements.river.client.server.CreateCollectionServiceImpl; |
31 import org.dive4elements.river.client.server.FLYSArtifactCreator; | 33 import org.dive4elements.river.client.server.FLYSArtifactCreator; |
32 import org.dive4elements.river.client.server.FeedServiceImpl; | 34 import org.dive4elements.river.client.server.FeedServiceImpl; |
35 import org.dive4elements.river.client.server.LoadArtifactServiceImpl; | |
33 import org.dive4elements.river.client.server.auth.DefaultUser; | 36 import org.dive4elements.river.client.server.auth.DefaultUser; |
34 import org.dive4elements.river.client.server.auth.User; | 37 import org.dive4elements.river.client.server.auth.User; |
35 import org.dive4elements.river.client.server.auth.UserClient; | 38 import org.dive4elements.river.client.server.auth.UserClient; |
36 import org.dive4elements.river.client.shared.exceptions.ServerException; | 39 import org.dive4elements.river.client.shared.exceptions.ServerException; |
37 import org.dive4elements.river.client.shared.model.Artifact; | 40 import org.dive4elements.river.client.shared.model.Artifact; |
49 | 52 |
50 /** | 53 /** |
51 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 54 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
52 */ | 55 */ |
53 public class SinfoProof { | 56 public class SinfoProof { |
54 /** | 57 |
55 * The logging is done via Log4j. To configure the logging | |
56 * a file 'log4j.properties' is search in the configuration directory. | |
57 */ | |
58 public static final String LOG4J_PROPERTIES = "log4j.properties"; | |
59 | |
60 /** | |
61 * The path of the configuration directory. | |
62 */ | |
63 public static final String CONFIG_PATH = System.getProperty("config.dir", "conf"); | |
64 | |
65 public static final String CONFIG = System.getProperty("config.file", "use_case1.conf"); | |
66 | |
67 public static final String XPATH_DYNAMIC = "/art:result/art:ui/art:dynamic"; | |
68 private static final String serverUrl = "http://localhost:8181"; | 58 private static final String serverUrl = "http://localhost:8181"; |
69 private static final String locale = "de"; | 59 private static final String locale = "de"; |
70 /** | |
71 * The logger used in this class. | |
72 */ | |
73 private static Logger logger; | |
74 | |
75 static { | |
76 configureLogging(); | |
77 | |
78 logger = Logger.getLogger(SinfoProof.class); | |
79 } | |
80 | |
81 /** | |
82 * Trys to load the Log4j configuration from ${config.dir}/log4j.properties. | |
83 */ | |
84 public static final void configureLogging() { | |
85 final File configDir = new File(CONFIG_PATH); | |
86 final File propFile = new File(configDir, LOG4J_PROPERTIES); | |
87 | |
88 if (propFile.isFile() && propFile.canRead()) { | |
89 try { | |
90 PropertyConfigurator.configure(propFile.toURI().toURL()); | |
91 } | |
92 catch (final MalformedURLException mue) { | |
93 mue.printStackTrace(System.err); | |
94 } | |
95 } | |
96 } | |
97 | |
98 public static final Configuration readConfiguration() { | |
99 final File configDir = new File(CONFIG_PATH); | |
100 final File configFile = new File(configDir, CONFIG); | |
101 | |
102 logger.debug("Configuration file: " + configFile.getAbsolutePath()); | |
103 | |
104 if (configFile.isFile() && configFile.canRead()) { | |
105 try { | |
106 final Configuration conf = new Configuration(configFile); | |
107 conf.initialize(); | |
108 | |
109 return conf; | |
110 } | |
111 catch (final IOException ioe) { | |
112 logger.error("Error while reading configuration."); | |
113 } | |
114 } | |
115 | |
116 return null; | |
117 } | |
118 | |
119 public SinfoProof() { | |
120 // empty constructor | |
121 super(); | |
122 } | |
123 | 60 |
124 public static void main(final String[] args) throws ServerException, IOException { | 61 public static void main(final String[] args) throws ServerException, IOException { |
125 logger.info("Starting console client."); | 62 // logger.info("Starting console client."); |
126 | 63 |
127 final User user = new DefaultUser("belger", "belger", null, false, new ArrayList<String>(), new ArrayList<String>()); | 64 final User user = new DefaultUser("belger", "belger", null, false, new ArrayList<String>(), new ArrayList<String>()); |
128 final UserClient userClient = new UserClient(serverUrl); | 65 final UserClient userClient = new UserClient(serverUrl); |
129 final Element userElement = userClient.findUser(user); | 66 final Element userElement = userClient.findUser(user); |
130 final String userUuid = userElement.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "uuid"); | 67 final String userUuid = userElement.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "uuid"); |
142 final DataList calcModes = calcModeArtifact.getArtifactDescription().getCurrentData(); // AUSWAHL-Möglichkeiten | 79 final DataList calcModes = calcModeArtifact.getArtifactDescription().getCurrentData(); // AUSWAHL-Möglichkeiten |
143 final DataItem minMaxFlowdepth = calcModes.get(0).getItems()[2]; | 80 final DataItem minMaxFlowdepth = calcModes.get(0).getItems()[2]; |
144 final Data dataCalcMode = new StringOptionsData("calculation_mode", "calculation_mode", new DataItem[] { minMaxFlowdepth }); | 81 final Data dataCalcMode = new StringOptionsData("calculation_mode", "calculation_mode", new DataItem[] { minMaxFlowdepth }); |
145 final Artifact rangeArtifact = feedAndGo(calcModeArtifact, new Data[] { dataCalcMode }, 0); | 82 final Artifact rangeArtifact = feedAndGo(calcModeArtifact, new Data[] { dataCalcMode }, 0); |
146 | 83 |
147 /* Select Distance */ | 84 /* Select Range */ |
148 | 85 |
149 // entweder eine bestimmte Range | 86 // entweder eine bestimmte Range |
150 final Data dataFrom = new StringOptionsData("ld_from", "ld_from", new DataItem[] { new DefaultDataItem("0", "0", "0") }); | 87 final Data dataFrom = new StringOptionsData("ld_from", "ld_from", new DataItem[] { new DefaultDataItem("10", "10", "10") }); |
151 final Data dataTo = new StringOptionsData("ld_to", "ld_to", new DataItem[] { new DefaultDataItem("100", "100", "100") }); | 88 final Data dataTo = new StringOptionsData("ld_to", "ld_to", new DataItem[] { new DefaultDataItem("100", "100", "100") }); |
152 final Data[] rangeFromToDetermined = new Data[] { dataFrom, dataTo }; | 89 final Data[] rangeFromToDetermined = new Data[] { dataFrom, dataTo }; |
153 | 90 |
154 // oder die maxRange | 91 // oder die maxRange |
155 final DataList list = rangeArtifact.getArtifactDescription().getCurrentData(); | 92 final DataList list = rangeArtifact.getArtifactDescription().getCurrentData(); |
156 final Data[] rangeMax = new Data[] { list.get(0), list.get(1) }; | 93 final Data[] rangeMax = new Data[] { list.get(0), list.get(1) }; |
157 final Artifact dataChoiceArtifact = feedAndGo(rangeArtifact, rangeMax, 0); | 94 |
95 final Artifact dataChoiceArtifact = feedAndGo(rangeArtifact, rangeFromToDetermined, 0); | |
158 | 96 |
159 /* Select Fixpunkte */ | 97 /* Select Fixpunkte */ |
160 final List<Recommendation> recs = collection.getRecommendations(); | 98 final Recommendation rec1 = new Recommendation("staticwqkms", "additionals-wstv-0-103", "sinfo_flowdepth_waterlevels"); |
161 if (recs != null) { | 99 final Recommendation rec2 = new Recommendation("bedheight", "bedheight-single-36-2015-FP-2015_0-502", "sinfo_flowdepthminmax_heights"); |
162 | 100 |
163 } | 101 final Artifact[] artifacts = loadMany(collection, new Recommendation[] { rec1, rec2 }, null); |
164 final String combinedId = "[c23bcc26-2282-47b7-b262-5a328a372926;staticwqkms;0;ELBE_W-MNQ1890-2006_Fixierungsdaten_150-280.csv]#[d2e2e1da-81cd-40e6-8857-dddc22252c29;bedheight;0;FP-2015_0-502]"; // SCHWACHSTELLE... | 102 |
165 final Data pair = new StringOptionsData("Ausgewählte Differenzen", "diffids", new DataItem[] { new DefaultDataItem(null, null, combinedId) }); | 103 // rec1.getDisplayName() TODO: makeDisplayName |
166 final Artifact export = feedAndGo(dataChoiceArtifact, new Data[] { pair }, 0); | 104 final String rec1String = RecommandationUtils.createDataString(artifacts[0].getUuid(), rec1, new NilDatacageTwinPanelInfo("xxxx")); |
167 final Recommendation r; | 105 final String rec2String = RecommandationUtils.createDataString(artifacts[1].getUuid(), rec2, new NilDatacageTwinPanelInfo("xxxx")); |
168 | 106 // TODO: check display name |
169 /* Export calculation */ | 107 final String combinedIdNeu = rec1String + "#" + rec2String; |
170 final OutputMode[] modes = export.getArtifactDescription().getOutputModes(); | 108 |
109 final Data pair = new StringOptionsData("diffids", "diffids", new DataItem[] { new DefaultDataItem(combinedIdNeu, combinedIdNeu, combinedIdNeu) }); | |
110 final Artifact exportArtifact = feedAndGo(dataChoiceArtifact, new Data[] { pair }, 0); | |
111 | |
112 // Describe collection | |
113 describeCollection(collection); // wichtig, damit die Facets erzeugt werden | |
114 | |
115 // /* Export calculation */ | |
116 final OutputMode[] modes = exportArtifact.getArtifactDescription().getOutputModes(); | |
171 if (modes != null) { | 117 if (modes != null) { |
172 | 118 final OutputMode mode = modes[1]; // output.sinfo_flowdepthminmax_export |
173 } | 119 doGet(mode.getName(), collection.identifier()); |
120 } | |
121 } | |
122 | |
123 private static Collection describeCollection(final Collection collection) throws ConnectionException { | |
124 | |
125 final String uuid = collection.identifier(); | |
126 | |
127 final Document describe = ClientProtocolUtils.newDescribeCollectionDocument(uuid); | |
128 | |
129 final HttpClient client = new HttpClientImpl(serverUrl, locale); | |
130 | |
131 final Document response = (Document) client.doCollectionAction(describe, uuid, new DocumentResponseHandler()); | |
132 | |
133 final Collection c = CollectionHelper.parseCollection(response); | |
134 | |
135 return c; | |
174 } | 136 } |
175 | 137 |
176 private static Artifact feedAndGo(final Artifact inputArtifact, final Data[] data, final int reachableStateIndex) | 138 private static Artifact feedAndGo(final Artifact inputArtifact, final Data[] data, final int reachableStateIndex) |
177 throws ConnectionException, ServerException { | 139 throws ConnectionException, ServerException { |
178 final Artifact artifact = feed(serverUrl, locale, inputArtifact, data); | 140 final Artifact artifact = feed(serverUrl, locale, inputArtifact, data); |
261 } | 223 } |
262 | 224 |
263 throw new ServerException(AdvanceServiceImpl.ERROR_ADVANCE_ARTIFACT); | 225 throw new ServerException(AdvanceServiceImpl.ERROR_ADVANCE_ARTIFACT); |
264 } | 226 } |
265 | 227 |
266 // FIXME | 228 public static Artifact[] loadMany(final Collection parent, final Recommendation[] recoms, final String factory) throws ServerException { |
229 | |
230 final ArrayList<Artifact> artifacts = new ArrayList<Artifact>(); | |
231 final HashMap<Recommendation, Artifact> cloneMap = new HashMap<Recommendation, Artifact>(); | |
232 | |
233 for (final Recommendation recom : recoms) { | |
234 | |
235 final Artifact prevClone = cloneMap.get(recom); | |
236 if (prevClone != null) { | |
237 | |
238 artifacts.add(prevClone); | |
239 } else { | |
240 // Not already cloned. | |
241 final String realFactory = factory != null ? factory : recom.getFactory(); | |
242 | |
243 final Artifact clone = ArtifactHelper.createArtifact(serverUrl, locale, realFactory, recom); | |
244 | |
245 if (clone != null) { | |
246 final Collection c = CollectionHelper.addArtifact(parent, clone, serverUrl, locale); | |
247 | |
248 if (c != null) { | |
249 artifacts.add(clone); | |
250 // Remember we cloned a recommendation like this. | |
251 cloneMap.put(recom, clone); | |
252 } else { | |
253 throw new ServerException(LoadArtifactServiceImpl.ERROR_LOAD_ARTIFACT); | |
254 } | |
255 } | |
256 } | |
257 } | |
258 return artifacts.toArray(new Artifact[artifacts.size()]); | |
259 } | |
260 | |
261 /// ExportServiceImpl | |
262 | |
263 public static void doGet(final String mode, final String collectionId) { | |
264 | |
265 try { | |
266 | |
267 final String name = mode; | |
268 final String type = "csv"; | |
269 | |
270 final String fn = name + "." + type; // TODO: make filename unique | |
271 final String enc = "windows-1252";// req.getParameter("encoding"); | |
272 | |
273 final OutputStream out = new FileOutputStream(new File("D:" + File.separator + fn)); | |
274 final Document attr = null; | |
275 final Document request = ClientProtocolUtils.newOutCollectionDocument(collectionId, mode, type, attr); | |
276 final HttpClient client = new HttpClientImpl(serverUrl, locale); | |
277 | |
278 if (enc != null) { | |
279 final InputStreamReader in = new InputStreamReader(client.collectionOut(request, collectionId, mode), "UTF-8"); | |
280 try { | |
281 final OutputStreamWriter encOut = new OutputStreamWriter(out, enc); | |
282 final char buf[] = new char[4096]; | |
283 int c; | |
284 while ((c = in.read(buf, 0, buf.length)) >= 0) { | |
285 encOut.write(buf, 0, c); | |
286 } | |
287 encOut.flush(); | |
288 encOut.close(); | |
289 } finally { | |
290 in.close(); | |
291 } | |
292 } | |
293 } | |
294 catch (final IOException ioe) { | |
295 ioe.printStackTrace(); | |
296 } | |
297 } | |
298 | |
267 } | 299 } |
268 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |