changeset 4904:aa67a88314f2 dc-km-filter

[branch: dc-km-filter]: Merge with tip.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 30 Jan 2013 08:26:54 +0100
parents 137ff80f0a01 (current diff) 5ab87837622f (diff)
children 4d1e2a0c283a
files
diffstat 2 files changed, 124 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/doc/conf/datacage.sql	Tue Jan 29 15:05:37 2013 +0100
+++ b/flys-artifacts/doc/conf/datacage.sql	Wed Jan 30 08:26:54 2013 +0100
@@ -85,7 +85,40 @@
              ON o.c_id = ci2.collection_id 
     WHERE  a2.creation = o.oldest_a;
 
+CREATE VIEW master_artifacts_range AS
+    SELECT ma.id                   AS id,
+           ma.gid                  AS gid,
+           ma.state                AS state,
+           ma.creation             AS creation,
+           ma.collection_id        AS collection_id,
+           mam.ld_mode             AS ld_mode,
+           mal.ld_locations        AS ld_locations,
+           maf.ld_from             AS ld_from,
+           mat.ld_to               AS ld_to
+    FROM master_artifacts ma
+        LEFT JOIN (SELECT ad.v           AS ld_mode,
+                          ad.artifact_id AS artifact_id
+                   FROM artifact_data ad
+                   WHERE ad.k = 'ld_mode') mam
+                   ON mam.artifact_id = ma.id
+        LEFT JOIN (SELECT ad.v           AS ld_locations,
+                          ad.artifact_id AS artifact_id
+                   FROM artifact_data ad
+                   WHERE ad.k = 'ld_locations') mal
+                   ON mal.artifact_id = ma.id
+        LEFT JOIN (SELECT ad.v           AS ld_from,
+                          ad.artifact_id AS artifact_id
+                   FROM artifact_data ad
+                   WHERE ad.k = 'ld_from') maf
+                   ON maf.artifact_id = ma.id
+        LEFT JOIN (SELECT ad.v           AS ld_to,
+                          ad.artifact_id AS artifact_id
+                   FROM artifact_data ad
+                   WHERE ad.k = 'ld_to') mat
+                   ON mat.artifact_id = ma.id;
+
 -- DROP VIEW master_artifacts;
+-- DROP VIEW master_artifacts_range;
 -- DROP SEQUENCE USERS_ID_SEQ;
 -- DROP SEQUENCE COLLECTIONS_ID_SEQ;
 -- DROP SEQUENCE ARTIFACTS_ID_SEQ;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java	Tue Jan 29 15:05:37 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java	Wed Jan 30 08:26:54 2013 +0100
@@ -1,5 +1,6 @@
 package de.intevation.flys.artifacts.datacage.templating;
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.Collection;
 import java.util.Map;
@@ -82,6 +83,96 @@
         });
     }
 
+    static {
+        /** Implementation for getting the minimum value of location or distance
+         *  dc:fromValue. */
+        FUNCTIONS.addFunction("fromValue", 3, new XPathFunction() {
+            @Override
+            public Object evaluate(List args) throws XPathFunctionException {
+                Object mode      = args.get(0);
+                Object locations = args.get(1);
+                Object from      = args.get(2);
+
+                if (!(mode instanceof String)){
+                    return -Double.MAX_VALUE;
+                }
+
+                if (mode.equals("locations")) {
+                    if (!(locations instanceof String)) {
+                        return -Double.MAX_VALUE;
+                    }
+                    else {
+                        String loc = ((String)locations).replace(" ", "");
+                        String[] split = loc.split(",");
+                        Arrays.sort(split);
+                        return split[0];
+                    }
+                }
+                else if (mode.equals("distance")) {
+                    if (!(from instanceof String)) {
+                        return -Double.MAX_VALUE;
+                    }
+                    String f = (String)from;
+                    try {
+                        return Double.parseDouble(f);
+                    }
+                    catch(NumberFormatException nfe) {
+                        return -Double.MAX_VALUE;
+                    }
+                }
+                else {
+                    return -Double.MAX_VALUE;
+                }
+            }
+        });
+    }
+
+    static {
+        /** Implementation for getting the maximum value of location or distance
+         *  dc:toValue. */
+        FUNCTIONS.addFunction("toValue", 3, new XPathFunction() {
+            @Override
+            public Object evaluate(List args) throws XPathFunctionException {
+                Object mode      = args.get(0);
+                Object locations = args.get(1);
+                Object to        = args.get(2);
+
+                if (!(mode instanceof String)){
+                    return Double.MAX_VALUE;
+                }
+
+                if (mode.equals("locations")) {
+                    if (!(locations instanceof String)) {
+                        return Double.MAX_VALUE;
+                    }
+                    else {
+                        String loc = ((String)locations).replace(" ", "");
+                        String[] split = loc.split(",");
+                        Arrays.sort(split);
+                        return split[split.length - 1];
+                    }
+                }
+                else if (mode.equals("distance")) {
+                    if (!(to instanceof String)) {
+                        return Double.MAX_VALUE;
+                    }
+                    else {
+                        String t = (String)to;
+                        try {
+                            return Double.parseDouble(t);
+                        }
+                        catch(NumberFormatException nfe) {
+                            return Double.MAX_VALUE;
+                        }
+                    }
+                }
+                else {
+                    return Double.MAX_VALUE;
+                }
+            }
+        });
+    }
+
     /** List of functions. */
     protected List<Entry> functions;
 

http://dive4elements.wald.intevation.org