changeset 970:e456aca4eb7b

meta data service: Adjusted to use the DataCage recommendations. flys-artifacts/trunk@2395 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 22 Jul 2011 10:41:30 +0000
parents 2c8fc60125b9
children d0c9a5f32c30
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MetaDataService.java
diffstat 2 files changed, 109 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Jul 22 09:10:31 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Jul 22 10:41:30 2011 +0000
@@ -1,3 +1,14 @@
+2011-07-21  Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/services/MetaDataService.java:
+	  Adjusted to use the DataCage recommendations. The incomming document
+	  can pass the artifacts UUID by '/art:outs/@value' the outs as a
+	  comma separated list in '/art:outs/@value' and optional a set of
+	  filters comma separated in '/art:filters/@value'.
+
+	  If UUID and OUTS are not given the old service is used. This
+	  should be removed as soon as the client uses the new service.
+
 2011-07-21  Sascha L. Teichmann <sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/services/meta/CompiledStatement.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MetaDataService.java	Fri Jul 22 09:10:31 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MetaDataService.java	Fri Jul 22 10:41:30 2011 +0000
@@ -10,18 +10,24 @@
 import java.util.Map;
 import java.util.HashMap;
 
+import de.intevation.artifacts.Artifact;
 import de.intevation.artifacts.CallMeta;
 import de.intevation.artifacts.GlobalContext;
+import de.intevation.artifacts.ArtifactDatabase;
+import de.intevation.artifacts.ArtifactDatabaseException;
 
 import de.intevation.artifactdatabase.DefaultService;
 
 import de.intevation.artifacts.common.utils.XMLUtils;
+import de.intevation.artifacts.common.utils.StringUtils;
 
 import de.intevation.artifacts.common.ArtifactNamespaceContext;
 
 import de.intevation.flys.artifacts.services.meta.Builder;
 import de.intevation.flys.artifacts.services.meta.DataCage;
 
+import de.intevation.flys.artifacts.FLYSArtifact;
+
 import de.intevation.flys.backend.SessionHolder;
 
 import org.hibernate.Session;
@@ -36,8 +42,13 @@
     // old service. To be removed
     public static final String XPATH_RIVER = "/art:river/text()";
 
-    public static final String XPATH_OUT  = "/art:out/@value";
-    public static final String XPATH_UUID = "/art:uuid/@value";
+    public static final String XPATH_UUID    = "/art:uuid/@value";
+    public static final String XPATH_OUTS    = "/art:outs/@value";
+    public static final String XPATH_FILTERS = "/art:filters/@value";
+
+    /** The global context key of the artifact database */
+    public static final String ARTIFACT_DATA_BASE_KEY =
+        "global.artifact.database";
 
     public MetaDataService() {
     }
@@ -57,13 +68,8 @@
         return parameters;
     }
 
-    @Override
-    public Document process(
-        Document      data,
-        GlobalContext globalContext,
-        CallMeta      callMeta
-    ) {
-        log.debug("MetaDataService.process");
+    /** The old service. To be removed. */
+    protected Document oldService(Document data) {
 
         final Document result = XMLUtils.newDocument();
 
@@ -95,5 +101,88 @@
 
         return result;
     }
+
+    protected Document newService(
+        String        uuid,
+        String        outsString,
+        String        filters,
+        GlobalContext globalContext
+    ) {
+        Document result = XMLUtils.newDocument();
+
+        if (!StringUtils.checkUUID(uuid)) {
+            log.warn("'" + uuid + "' is not a UUID");
+            return result;
+        }
+
+        Object dbObject =
+            (ArtifactDatabase)globalContext.get(ARTIFACT_DATA_BASE_KEY);
+
+        if (!(dbObject instanceof ArtifactDatabase)) {
+            log.error("Cannot find artifact database");
+            return result;
+        }
+
+        ArtifactDatabase db = (ArtifactDatabase)dbObject;
+
+        Artifact artifact;
+
+        try {
+            artifact = db.getRawArtifact(uuid);
+        }
+        catch (ArtifactDatabaseException adbe) {
+            log.warn("fetching artifact failed", adbe);
+            return result;
+        }
+
+        if (!(artifact instanceof FLYSArtifact)) {
+            log.warn("artifact is not a FLYS artifact.");
+            return result;
+        }
+
+        FLYSArtifact flysArtifact = (FLYSArtifact)artifact;
+
+        String [] outs = outsString.split("\\s*,\\s*");
+
+        Map<String, Object> extras;
+        
+        if (filters != null) {
+            extras = new HashMap<String, Object>();
+            for (String filter: filters.split("\\s*,\\*s")) {
+                extras.put(filter, "true");
+            }
+        }
+        else {
+            extras = null;
+        }
+
+        DataCage dc = DataCage.getInstance();
+
+        dc.recommend(flysArtifact, outs, extras, result);
+
+        return result;
+    }
+
+    @Override
+    public Document process(
+        Document      data,
+        GlobalContext globalContext,
+        CallMeta      callMeta
+    ) {
+        log.debug("MetaDataService.process");
+
+        String uuid = XMLUtils.xpathString(
+            data, XPATH_UUID, ArtifactNamespaceContext.INSTANCE);
+
+        String outs = XMLUtils.xpathString(
+            data, XPATH_OUTS, ArtifactNamespaceContext.INSTANCE);
+
+        String filters = XMLUtils.xpathString(
+            data, XPATH_FILTERS, ArtifactNamespaceContext.INSTANCE);
+
+        return uuid != null && outs != null
+            ? newService(uuid, outs, filters, globalContext)
+            : oldService(data);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org