[PATCH 1 of 2] local backup

Wald Commits scm-commit at wald.intevation.org
Thu Apr 26 10:47:29 CEST 2018


# HG changeset patch
# User gernotbelger
# Date 1524650329 -7200
# Node ID 679b1442c8865d05c1ebfe134ea5e0a61ff0a6bf
# Parent  4de5bdd027ff492bed7adfa6fb371615dc690540
local backup

diff -r 4de5bdd027ff -r 679b1442c886 gwt-client/src/main/java/org/dive4elements/river/client/test/SinfoProof.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/test/SinfoProof.java	Wed Apr 25 11:58:49 2018 +0200
@@ -0,0 +1,268 @@
+/*
+ * Copyright (c) 2010 by Intevation GmbH
+ *
+ * This program is free software under the LGPL (>=v2.1)
+ * Read the file LGPL.txt coming with the software for details
+ * or visit http://www.gnu.org/licenses/ if it does not exist.
+ */
+
+package org.dive4elements.river.client.test;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.List;
+
+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.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.auth.DefaultUser;
+import org.dive4elements.river.client.server.auth.User;
+import org.dive4elements.river.client.server.auth.UserClient;
+import org.dive4elements.river.client.shared.exceptions.ServerException;
+import org.dive4elements.river.client.shared.model.Artifact;
+import org.dive4elements.river.client.shared.model.Collection;
+import org.dive4elements.river.client.shared.model.Data;
+import org.dive4elements.river.client.shared.model.DataItem;
+import org.dive4elements.river.client.shared.model.DataList;
+import org.dive4elements.river.client.shared.model.DefaultCollection;
+import org.dive4elements.river.client.shared.model.DefaultDataItem;
+import org.dive4elements.river.client.shared.model.OutputMode;
+import org.dive4elements.river.client.shared.model.Recommendation;
+import org.dive4elements.river.client.shared.model.StringOptionsData;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * @author <a href="mailto:ingo.weinzierl at 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.");
+
+        final User user = new DefaultUser("belger", "belger", null, false, new ArrayList<String>(), new ArrayList<String>());
+        final UserClient userClient = new UserClient(serverUrl);
+        final Element userElement = userClient.findUser(user);
+        final String userUuid = userElement.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "uuid");
+
+        /* Init Collection */
+        final Collection collection = createCollection(serverUrl, locale, userUuid);
+        final org.dive4elements.river.client.shared.model.Artifact sinfoArtifact = ArtifactHelper.createArtifact(serverUrl, locale, "sinfo", null);
+        final Collection newColl = CollectionHelper.addArtifact(collection, sinfoArtifact, serverUrl, locale); // wichtig; sorgt für Persistenz
+
+        /* Select River */
+        final Data data = new StringOptionsData("river", "river", new DataItem[] { new DefaultDataItem("Beispielfluss", "Beispielfluss", "Beispielfluss") });
+        final Artifact calcModeArtifact = feedAndGo(sinfoArtifact, new Data[] { data }, 0);
+
+        /* Select CalcMode */
+        final DataList calcModes = calcModeArtifact.getArtifactDescription().getCurrentData(); // AUSWAHL-Möglichkeiten
+        final DataItem minMaxFlowdepth = calcModes.get(0).getItems()[2];
+        final Data dataCalcMode = new StringOptionsData("calculation_mode", "calculation_mode", new DataItem[] { minMaxFlowdepth });
+        final Artifact rangeArtifact = feedAndGo(calcModeArtifact, new Data[] { dataCalcMode }, 0);
+
+        /* Select Distance */
+
+        // entweder eine bestimmte Range
+        final Data dataFrom = new StringOptionsData("ld_from", "ld_from", new DataItem[] { new DefaultDataItem("0", "0", "0") });
+        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);
+
+        /* Select Fixpunkte */
+        final List<Recommendation> recs = collection.getRecommendations();
+        if (recs != null) {
+
+        }
+        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 Artifact feedAndGo(final Artifact inputArtifact, final Data[] data, final int reachableStateIndex)
+            throws ConnectionException, ServerException {
+        final Artifact artifact = feed(serverUrl, locale, inputArtifact, data);
+        return advance(serverUrl, locale, artifact, getReachableStateByIndex(artifact, reachableStateIndex));
+    }
+
+    private static String getReachableStateByIndex(final Artifact artifact, final int index) {
+
+        final String[] states = artifact.getArtifactDescription().getReachableStates();
+        if (states != null) {
+            if (states.length > index) {
+                return states[index];
+            } else {
+                return states[0];
+            }
+        } else {
+            return "";
+        }
+    }
+
+    public static Collection createCollection(final String url, final String locale, final String ownerId) throws ConnectionException {
+        final Document create = ClientProtocolUtils.newCreateCollectionDocument(null);
+        final HttpClient client = new HttpClientImpl(url, locale);
+        final Document doc = (Document) client.createCollection(create, ownerId, new DocumentResponseHandler());
+        final String uuid = XMLUtils.xpathString(doc, CreateCollectionServiceImpl.XPATH_COLLECTION_UUID, ArtifactNamespaceContext.INSTANCE);
+        final String ttlStr = XMLUtils.xpathString(doc, CreateCollectionServiceImpl.XPATH_COLLECTION_TTL, ArtifactNamespaceContext.INSTANCE);
+
+        return new DefaultCollection(uuid, Long.valueOf(ttlStr), uuid);
+    }
+
+    public static Artifact feed(final String url, final String locale, final Artifact artifact, final Data[] data) throws ServerException, ConnectionException {
+        final Document feed = ClientProtocolUtils.newFeedDocument(artifact.getUuid(), artifact.getHash(), createKVP(data));
+
+        final HttpClient client = new HttpClientImpl(url, locale);
+
+        final Document description = (Document) client.feed(new org.dive4elements.artifacts.httpclient.objects.Artifact(artifact.getUuid(), artifact.getHash()),
+                feed, new DocumentResponseHandler());
+
+        final String result = XMLUtils.xpathString(description, FeedServiceImpl.XPATH_RESULT, ArtifactNamespaceContext.INSTANCE);
+
+        if (result == null || !result.equals(FeedServiceImpl.OPERATION_FAILURE)) {
+            return (Artifact) new FLYSArtifactCreator().create(description);
+        } else if (result != null && result.equals(FeedServiceImpl.OPERATION_FAILURE)) {
+            final String msg = XMLUtils.xpathString(description, FeedServiceImpl.XPATH_RESULT_MSG, ArtifactNamespaceContext.INSTANCE);
+            throw new ServerException(msg);
+        }
+
+        throw new ServerException(FeedServiceImpl.ERROR_FEED_DATA);
+    }
+
+    protected static String[][] createKVP(final Data[] data) {
+        if (data != null) {
+            final String[][] kvp = new String[data.length][];
+
+            int i = 0;
+
+            for (final Data d : data) {
+                final DataItem[] items = d.getItems();
+                final String key = d.getLabel();
+                final String value = d.getStringValue();
+
+                kvp[i++] = new String[] { key, value };
+            }
+
+            return kvp;
+        }
+        return null;
+    }
+
+    public static Artifact advance(final String url, final String locale, final Artifact artifact, final String target)
+            throws ConnectionException, ServerException {
+        final Document advance = ClientProtocolUtils.newAdvanceDocument(artifact.getUuid(), artifact.getHash(), target);
+        final HttpClient client = new HttpClientImpl(url, locale);
+
+        final Document description = (Document) client.advance(
+                new org.dive4elements.artifacts.httpclient.objects.Artifact(artifact.getUuid(), artifact.getHash()), advance, new DocumentResponseHandler());
+
+        if (description == null) {
+            throw new ServerException(AdvanceServiceImpl.ERROR_ADVANCE_ARTIFACT);
+        }
+
+        final String result = XMLUtils.xpathString(description, AdvanceServiceImpl.XPATH_RESULT, ArtifactNamespaceContext.INSTANCE);
+
+        if (result == null || !result.equals(AdvanceServiceImpl.OPERATION_FAILURE)) {
+            return (Artifact) new FLYSArtifactCreator().create(description);
+        }
+
+        throw new ServerException(AdvanceServiceImpl.ERROR_ADVANCE_ARTIFACT);
+    }
+
+    // FIXME
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:


More information about the Dive4Elements-commits mailing list