# HG changeset patch
# User gernotbelger
# Date 1524741153 -7200
# Node ID 7f3818ec6eb68843a9230054831fe6342f3b65a0
# Parent 274ddafb719b8063a8f30530826bd09825c196d1
work on proof 2
diff -r 274ddafb719b -r 7f3818ec6eb6 gwt-client/src/main/java/org/dive4elements/river/client/test/ProofMain.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/test/ProofMain.java Thu Apr 26 13:12:33 2018 +0200
@@ -0,0 +1,32 @@
+/*
+ * 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.IOException;
+
+import org.dive4elements.artifacts.httpclient.http.HttpClient;
+import org.dive4elements.artifacts.httpclient.http.HttpClientImpl;
+import org.dive4elements.river.client.shared.exceptions.ServerException;
+
+/**
+ * @author Ingo Weinzierl
+ */
+public class ProofMain {
+
+ private static final String serverUrl = "http://localhost:8181";
+ private static final String locale = "de";
+ private static final HttpClient client = new HttpClientImpl(serverUrl, locale);
+
+ public static void main(final String[] args) throws ServerException, IOException {
+ // logger.info("Starting console client.");
+ final SinfoProof proof = new SinfoProof("belger", "belger", "sinfo");
+ proof.runTest();
+ }
+
+}
diff -r 274ddafb719b -r 7f3818ec6eb6 gwt-client/src/main/java/org/dive4elements/river/client/test/SinfoProof.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/test/SinfoProof.java Thu Apr 26 10:46:12 2018 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,299 +0,0 @@
-/*
- * 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.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-
-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.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;
-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 Ingo Weinzierl
- */
-public class SinfoProof {
-
- private static final String serverUrl = "http://localhost:8181";
- private static final String locale = "de";
-
- 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(), new ArrayList());
- 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 Range */
-
- // entweder eine bestimmte Range
- 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, rangeFromToDetermined, 0);
-
- /* Select Fixpunkte */
- 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());
- }
- }
-
- 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)
- 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);
- }
-
- public static Artifact[] loadMany(final Collection parent, final Recommendation[] recoms, final String factory) throws ServerException {
-
- final ArrayList artifacts = new ArrayList();
- final HashMap cloneMap = new HashMap();
-
- 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();
- }
- }
-
-}
diff -r 274ddafb719b -r 7f3818ec6eb6 gwt-client/src/main/java/org/dive4elements/river/client/test/SuperProof.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/test/SuperProof.java Thu Apr 26 13:12:33 2018 +0200
@@ -0,0 +1,310 @@
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ * Björnsen Beratende Ingenieure GmbH
+ * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+package org.dive4elements.river.client.test;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+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.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.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;
+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.DefaultCollection;
+import org.dive4elements.river.client.shared.model.Recommendation;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * @author Domenico Nardi Tironi
+ *
+ */
+public abstract class SuperProof {
+
+ private final String serverUrl = "http://localhost:8181";
+ private final String locale = "de";
+ private final HttpClient client;
+
+ private final String username;
+ private final String password;
+ private final String infotype;
+ private final String userUuid;
+ private Collection collection;
+ private Artifact artifact;
+
+ public SuperProof(final String username, final String password, final String infotype) {
+ this.username = username;
+ this.password = password;
+ this.infotype = infotype;
+
+ // init
+ this.client = new HttpClientImpl(this.serverUrl, this.locale);
+ this.userUuid = makeUserUuid();
+ this.collection = getCollection();
+ this.artifact = getArtifact();
+ }
+
+ private String makeUserUuid() {
+ final User user = new DefaultUser(this.username, this.password, null, false, new ArrayList(), new ArrayList());
+ final UserClient userClient = new UserClient(this.serverUrl);
+ Element userElement;
+ try {
+ userElement = userClient.findUser(user);
+ return userElement.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "uuid");
+ }
+ catch (final ConnectionException e) {
+ e.printStackTrace();
+ }
+ return "";
+ }
+
+ protected final Artifact getArtifact() {
+
+ /* Init Collection */
+ if (this.artifact == null)
+ try {
+
+ this.artifact = ArtifactHelper.createArtifact(this.serverUrl, this.locale, this.infotype, null);
+ setCollection(CollectionHelper.addArtifact(getCollection(), this.artifact, this.serverUrl, this.locale)); // wichtig; sorgt für Persistenz
+ }
+ catch (final ServerException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return this.artifact;
+ }
+
+ private Collection getCollection() {
+
+ if (this.collection == null) {
+ try {
+ // lazy-Loading
+ final Document create = ClientProtocolUtils.newCreateCollectionDocument(null);
+ final Document doc = (Document) this.client.createCollection(create, this.userUuid, 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);
+ this.collection = new DefaultCollection(uuid, Long.valueOf(ttlStr), uuid);
+ }
+ catch (final ConnectionException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ return this.collection;
+ }
+
+ private void setCollection(final Collection collection) {
+ this.collection = collection;
+ }
+
+ private void setArtifact(final Artifact artifact) {
+ this.artifact = artifact;
+ }
+
+ // TODO: MAKE THIS CLASS ABSTRACT AND OVERRIDE runTest in children
+ public abstract void runTest();
+
+ protected final void describeCollection() {
+ try {
+ final String uuid = getCollection().identifier();
+ final Document describe = ClientProtocolUtils.newDescribeCollectionDocument(uuid);
+ final Document response = (Document) this.client.doCollectionAction(describe, uuid, new DocumentResponseHandler());
+ final Collection c = CollectionHelper.parseCollection(response);
+ setCollection(c);
+ }
+ catch (final ConnectionException e) {
+ e.printStackTrace();
+ }
+ }
+
+ protected final void feedAndGo(final Data[] data, final int reachableStateIndex) {
+ try {
+ feed(data);
+ advance(getReachableStateByIndex(getArtifact(), reachableStateIndex)); // reachablestate könnte auch String sein... TODO: feedAndgo(data,string)
+ // bauen
+ }
+ catch (final ConnectionException e) {
+ e.printStackTrace();
+ }
+ catch (final ServerException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private 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 "";
+ }
+ }
+
+ private void feed(final Data[] data) throws ServerException, ConnectionException {
+ final Document feed = ClientProtocolUtils.newFeedDocument(getArtifact().getUuid(), getArtifact().getHash(), createKVP(data));
+
+ final Document description = (Document) this.client.feed(
+ new org.dive4elements.artifacts.httpclient.objects.Artifact(getArtifact().getUuid(), getArtifact().getHash()), feed,
+ new DocumentResponseHandler());
+
+ final String result = XMLUtils.xpathString(description, FeedServiceImpl.XPATH_RESULT, ArtifactNamespaceContext.INSTANCE);
+
+ if (result == null || !result.equals(FeedServiceImpl.OPERATION_FAILURE)) {
+ setArtifact((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);
+ }
+
+ private 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;
+ }
+
+ private void advance(final String target) throws ConnectionException, ServerException {
+ final Document advance = ClientProtocolUtils.newAdvanceDocument(getArtifact().getUuid(), getArtifact().getHash(), target);
+ // final HttpClient client = new HttpClientImpl(url, locale);
+
+ final Document description = (Document) this.client.advance(
+ new org.dive4elements.artifacts.httpclient.objects.Artifact(getArtifact().getUuid(), getArtifact().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)) {
+ setArtifact((Artifact) new FLYSArtifactCreator().create(description));
+ }
+
+ // throw new ServerException(AdvanceServiceImpl.ERROR_ADVANCE_ARTIFACT);
+ }
+
+ protected final Artifact[] loadMany(final Recommendation[] recoms, final String factory) {
+ try {
+ final ArrayList artifacts = new ArrayList();
+ final HashMap cloneMap = new HashMap();
+
+ 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(this.serverUrl, this.locale, realFactory, recom);
+
+ if (clone != null) {
+ final Collection c = CollectionHelper.addArtifact(getCollection(), clone, this.serverUrl, this.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()]);
+ }
+ catch (final ServerException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /// ExportServiceImpl
+ public void doGet(final String mode) {
+ 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(getCollection().identifier(), mode, type, attr);
+ // final HttpClient client = new HttpClientImpl(serverUrl, locale);
+
+ if (enc != null) {
+ final InputStreamReader in = new InputStreamReader(this.client.collectionOut(request, getCollection().identifier(), 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();
+ }
+ }
+
+}