Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/test/SinfoProof.java Wed Apr 25 11:58:49 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/test/SinfoProof.java Thu Apr 26 10:46:12 2018 +0200 @@ -9,27 +9,30 @@ package org.dive4elements.river.client.test; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; -import java.net.MalformedURLException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; import java.util.ArrayList; -import java.util.List; +import java.util.HashMap; -import org.apache.log4j.Logger; -import org.apache.log4j.PropertyConfigurator; import org.dive4elements.artifacts.common.ArtifactNamespaceContext; import org.dive4elements.artifacts.common.utils.ClientProtocolUtils; import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException; import org.dive4elements.artifacts.httpclient.http.HttpClient; import org.dive4elements.artifacts.httpclient.http.HttpClientImpl; import org.dive4elements.artifacts.httpclient.http.response.DocumentResponseHandler; -import org.dive4elements.artifacts.httpclient.utils.Configuration; import org.dive4elements.artifacts.httpclient.utils.XMLUtils; +import org.dive4elements.river.client.client.ui.NilDatacageTwinPanelInfo; +import org.dive4elements.river.client.client.ui.RecommandationUtils; import org.dive4elements.river.client.server.AdvanceServiceImpl; import org.dive4elements.river.client.server.ArtifactHelper; import org.dive4elements.river.client.server.CollectionHelper; import org.dive4elements.river.client.server.CreateCollectionServiceImpl; import org.dive4elements.river.client.server.FLYSArtifactCreator; import org.dive4elements.river.client.server.FeedServiceImpl; +import org.dive4elements.river.client.server.LoadArtifactServiceImpl; import org.dive4elements.river.client.server.auth.DefaultUser; import org.dive4elements.river.client.server.auth.User; import org.dive4elements.river.client.server.auth.UserClient; @@ -51,78 +54,12 @@ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class SinfoProof { - /** - * The logging is done via Log4j. To configure the logging - * a file 'log4j.properties' is search in the configuration directory. - */ - public static final String LOG4J_PROPERTIES = "log4j.properties"; - /** - * The path of the configuration directory. - */ - public static final String CONFIG_PATH = System.getProperty("config.dir", "conf"); - - public static final String CONFIG = System.getProperty("config.file", "use_case1.conf"); - - public static final String XPATH_DYNAMIC = "/art:result/art:ui/art:dynamic"; private static final String serverUrl = "http://localhost:8181"; private static final String locale = "de"; - /** - * The logger used in this class. - */ - private static Logger logger; - - static { - configureLogging(); - - logger = Logger.getLogger(SinfoProof.class); - } - - /** - * Trys to load the Log4j configuration from ${config.dir}/log4j.properties. - */ - public static final void configureLogging() { - final File configDir = new File(CONFIG_PATH); - final File propFile = new File(configDir, LOG4J_PROPERTIES); - - if (propFile.isFile() && propFile.canRead()) { - try { - PropertyConfigurator.configure(propFile.toURI().toURL()); - } - catch (final MalformedURLException mue) { - mue.printStackTrace(System.err); - } - } - } - - public static final Configuration readConfiguration() { - final File configDir = new File(CONFIG_PATH); - final File configFile = new File(configDir, CONFIG); - - logger.debug("Configuration file: " + configFile.getAbsolutePath()); - - if (configFile.isFile() && configFile.canRead()) { - try { - final Configuration conf = new Configuration(configFile); - conf.initialize(); - - return conf; - } - catch (final IOException ioe) { - logger.error("Error while reading configuration."); - } - } - - return null; - } - - public SinfoProof() { - // empty constructor - super(); - } public static void main(final String[] args) throws ServerException, IOException { - logger.info("Starting console client."); + // logger.info("Starting console client."); final User user = new DefaultUser("belger", "belger", null, false, new ArrayList<String>(), new ArrayList<String>()); final UserClient userClient = new UserClient(serverUrl); @@ -144,33 +81,58 @@ final Data dataCalcMode = new StringOptionsData("calculation_mode", "calculation_mode", new DataItem[] { minMaxFlowdepth }); final Artifact rangeArtifact = feedAndGo(calcModeArtifact, new Data[] { dataCalcMode }, 0); - /* Select Distance */ + /* Select Range */ // entweder eine bestimmte Range - final Data dataFrom = new StringOptionsData("ld_from", "ld_from", new DataItem[] { new DefaultDataItem("0", "0", "0") }); + final Data dataFrom = new StringOptionsData("ld_from", "ld_from", new DataItem[] { new DefaultDataItem("10", "10", "10") }); final Data dataTo = new StringOptionsData("ld_to", "ld_to", new DataItem[] { new DefaultDataItem("100", "100", "100") }); final Data[] rangeFromToDetermined = new Data[] { dataFrom, dataTo }; // oder die maxRange final DataList list = rangeArtifact.getArtifactDescription().getCurrentData(); final Data[] rangeMax = new Data[] { list.get(0), list.get(1) }; - final Artifact dataChoiceArtifact = feedAndGo(rangeArtifact, rangeMax, 0); + + final Artifact dataChoiceArtifact = feedAndGo(rangeArtifact, rangeFromToDetermined, 0); /* Select Fixpunkte */ - final List<Recommendation> recs = collection.getRecommendations(); - if (recs != null) { + final Recommendation rec1 = new Recommendation("staticwqkms", "additionals-wstv-0-103", "sinfo_flowdepth_waterlevels"); + final Recommendation rec2 = new Recommendation("bedheight", "bedheight-single-36-2015-FP-2015_0-502", "sinfo_flowdepthminmax_heights"); + final Artifact[] artifacts = loadMany(collection, new Recommendation[] { rec1, rec2 }, null); + + // rec1.getDisplayName() TODO: makeDisplayName + final String rec1String = RecommandationUtils.createDataString(artifacts[0].getUuid(), rec1, new NilDatacageTwinPanelInfo("xxxx")); + final String rec2String = RecommandationUtils.createDataString(artifacts[1].getUuid(), rec2, new NilDatacageTwinPanelInfo("xxxx")); + // TODO: check display name + final String combinedIdNeu = rec1String + "#" + rec2String; + + final Data pair = new StringOptionsData("diffids", "diffids", new DataItem[] { new DefaultDataItem(combinedIdNeu, combinedIdNeu, combinedIdNeu) }); + final Artifact exportArtifact = feedAndGo(dataChoiceArtifact, new Data[] { pair }, 0); + + // Describe collection + describeCollection(collection); // wichtig, damit die Facets erzeugt werden + + // /* Export calculation */ + final OutputMode[] modes = exportArtifact.getArtifactDescription().getOutputModes(); + if (modes != null) { + final OutputMode mode = modes[1]; // output.sinfo_flowdepthminmax_export + doGet(mode.getName(), collection.identifier()); } - 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... - final Data pair = new StringOptionsData("Ausgewählte Differenzen", "diffids", new DataItem[] { new DefaultDataItem(null, null, combinedId) }); - final Artifact export = feedAndGo(dataChoiceArtifact, new Data[] { pair }, 0); - final Recommendation r; + } - /* Export calculation */ - final OutputMode[] modes = export.getArtifactDescription().getOutputModes(); - if (modes != null) { + private static Collection describeCollection(final Collection collection) throws ConnectionException { - } + final String uuid = collection.identifier(); + + final Document describe = ClientProtocolUtils.newDescribeCollectionDocument(uuid); + + final HttpClient client = new HttpClientImpl(serverUrl, locale); + + final Document response = (Document) client.doCollectionAction(describe, uuid, new DocumentResponseHandler()); + + final Collection c = CollectionHelper.parseCollection(response); + + return c; } private static Artifact feedAndGo(final Artifact inputArtifact, final Data[] data, final int reachableStateIndex) @@ -263,6 +225,75 @@ throw new ServerException(AdvanceServiceImpl.ERROR_ADVANCE_ARTIFACT); } - // FIXME + public static Artifact[] loadMany(final Collection parent, final Recommendation[] recoms, final String factory) throws ServerException { + + final ArrayList<Artifact> artifacts = new ArrayList<Artifact>(); + final HashMap<Recommendation, Artifact> cloneMap = new HashMap<Recommendation, Artifact>(); + + for (final Recommendation recom : recoms) { + + final Artifact prevClone = cloneMap.get(recom); + if (prevClone != null) { + + artifacts.add(prevClone); + } else { + // Not already cloned. + final String realFactory = factory != null ? factory : recom.getFactory(); + + final Artifact clone = ArtifactHelper.createArtifact(serverUrl, locale, realFactory, recom); + + if (clone != null) { + final Collection c = CollectionHelper.addArtifact(parent, clone, serverUrl, locale); + + if (c != null) { + artifacts.add(clone); + // Remember we cloned a recommendation like this. + cloneMap.put(recom, clone); + } else { + throw new ServerException(LoadArtifactServiceImpl.ERROR_LOAD_ARTIFACT); + } + } + } + } + return artifacts.toArray(new Artifact[artifacts.size()]); + } + + /// ExportServiceImpl + + public static void doGet(final String mode, final String collectionId) { + + try { + + final String name = mode; + final String type = "csv"; + + final String fn = name + "." + type; // TODO: make filename unique + final String enc = "windows-1252";// req.getParameter("encoding"); + + final OutputStream out = new FileOutputStream(new File("D:" + File.separator + fn)); + final Document attr = null; + final Document request = ClientProtocolUtils.newOutCollectionDocument(collectionId, mode, type, attr); + final HttpClient client = new HttpClientImpl(serverUrl, locale); + + if (enc != null) { + final InputStreamReader in = new InputStreamReader(client.collectionOut(request, collectionId, mode), "UTF-8"); + try { + final OutputStreamWriter encOut = new OutputStreamWriter(out, enc); + final char buf[] = new char[4096]; + int c; + while ((c = in.read(buf, 0, buf.length)) >= 0) { + encOut.write(buf, 0, c); + } + encOut.flush(); + encOut.close(); + } finally { + in.close(); + } + } + } + catch (final IOException ioe) { + ioe.printStackTrace(); + } + } + } -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: