[Dive4elements-commits] [PATCH] [branch: dc-km-filter]: Merge with tip

Wald Commits scm-commit at wald.intevation.org
Wed Jan 30 08:20:39 CET 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1359530814 -3600
# Branch dc-km-filter
# Node ID aa67a88314f227196f024f167bd5f7d08b044ec4
# Parent  137ff80f0a014fc9ad5a8b6d1576ce027b6cf3ef
# Parent  5ab87837622fcc36d77c97dda074b5bb92b2d2c8
[branch: dc-km-filter]: Merge with tip.

diff -r 137ff80f0a01 -r aa67a88314f2 flys-artifacts/doc/conf/datacage.sql
--- 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;
diff -r 137ff80f0a01 -r aa67a88314f2 flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java
--- 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;
 


More information about the Dive4elements-commits mailing list