changeset 960:92027887775a

DataCage: Added a recommend() method to generate recommendations for a given artifact, outs and extra parameters. flys-artifacts/trunk@2379 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 20 Jul 2011 17:03:00 +0000
parents a2b20ed3d3b4
children 3ba4f5a88c20
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/DataCage.java
diffstat 3 files changed, 82 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Jul 20 16:28:49 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Jul 20 17:03:00 2011 +0000
@@ -1,3 +1,12 @@
+2011-07-20  Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/services/meta/DataCage.java:
+	  Added a recommend() method to generate recommendations for
+	  a given artifact, outs and extra parameters.
+
+	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Added
+	  method to extract all data at once.
+
 2011-07-20  Sascha L. Teichmann <sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/services/meta/FunctionResolver.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Wed Jul 20 16:28:49 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Wed Jul 20 17:03:00 2011 +0000
@@ -407,6 +407,10 @@
         return data != null ? (String) data.getValue() : null;
     }
 
+    public Collection<StateData> getAllData() {
+        return data.values();
+    }
+
 
     public Facet getNativeFacet(Facet facet) {
         String name  = facet.getName();
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/DataCage.java	Wed Jul 20 16:28:49 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/DataCage.java	Wed Jul 20 17:03:00 2011 +0000
@@ -1,18 +1,35 @@
 package de.intevation.flys.artifacts.services.meta;
 
+import java.util.Map;
+import java.util.HashMap;
+
 import java.io.InputStream;
 import java.io.IOException;
 import java.io.File;
 
 import java.io.FileInputStream;
 
+import java.sql.Connection;
+import java.sql.SQLException;
+
 import org.apache.log4j.Logger;
 
 import org.w3c.dom.Document;
 
+import org.hibernate.Session;
+
+import org.hibernate.jdbc.Work;
+
 import de.intevation.artifacts.common.utils.Config;
 import de.intevation.artifacts.common.utils.XMLUtils;
 
+import de.intevation.flys.artifacts.FLYSArtifact;
+
+import de.intevation.flys.backend.SessionHolder;
+
+import de.intevation.artifactdatabase.data.StateData;
+
+
 public class DataCage
 {
     private static Logger log = Logger.getLogger(DataCage.class);
@@ -35,6 +52,58 @@
         return builder;
     }
 
+    public Document recommend(FLYSArtifact artifact, String [] outs) {
+        return recommend(artifact, outs, null);
+    }
+
+    public Document recommend(
+        FLYSArtifact        artifact,
+        String []           outs,
+        Map<String, Object> extraParameters
+    ) {
+        Map<String, Object> parameters = new HashMap<String, Object>();
+
+        if (extraParameters != null) {
+            parameters.putAll(extraParameters);
+        }
+
+        parameters.put("current-state-id", artifact.getCurrentStateId());
+        parameters.put("artifact-outs", outs);
+
+        for (StateData sd: artifact.getAllData()) {
+            Object value = sd.getValue();
+            if (value == null) {
+                continue;
+            }
+            String key = sd.getName().replace('.', '-');
+            parameters.put(key, value);
+        }
+
+        return process(parameters);
+    }
+
+    public Document process(final Map<String, Object> parameters) {
+        final Document result = XMLUtils.newDocument();
+
+        if (builder != null) {
+            log.error("builder not configured properly.");
+            return result;
+        }
+
+        Session session = SessionHolder.HOLDER.get();
+
+        session.doWork(new Work() {
+            @Override
+            public void execute(Connection connection)
+            throws SQLException
+            {
+                builder.build(connection, result, parameters);
+            }
+        });
+
+        return result;
+    }
+
     public static synchronized DataCage getInstance() {
         if (INSTANCE == null) {
             INSTANCE = createDataCage();

http://dive4elements.wald.intevation.org