diff artifacts/src/main/java/org/dive4elements/river/artifacts/D4EArtifact.java @ 6140:60b94dec104b

Add handling of bound artifacts. When an artifact is bound to an out its facets will only be shown in that Out. They will be removed in the blackboard pass and marked as incompatible by the AttributeWriter
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 31 May 2013 15:29:30 +0200
parents af13ceeba52a
children cc7df824d5c4
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/D4EArtifact.java	Fri May 31 15:27:06 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/D4EArtifact.java	Fri May 31 15:29:30 2013 +0200
@@ -86,12 +86,11 @@
     public static final String XPATH_FILTER =
         "/art:action/art:filter/art:out";
 
-    public static final Pattern CONTAINS_OUT =
-        Pattern.compile( "^(.*):OUT=(.+)$");
-
     /** Path to 'ids' (data) in doc that comes from datacage. */
     public static final String XPATH_IDS = "/art:action/art:ids/@value";
 
+    /** Path to 'target_out' (data) in doc that comes from datacage. */
+    public static final String XPATH_TARGET_OUT = "/art:action/art:target_out/@value";
 
     /** The constant string that shows that an operation was successful. */
     public static final String OPERATION_SUCCESSFUL = "SUCCESS";
@@ -120,7 +119,7 @@
      */
     protected Map<String, List<Facet>> filterFacets;
 
-    protected String boundToOut;
+    private String boundToOut;
 
 
     /**
@@ -194,11 +193,7 @@
         CallMeta        callMeta,
         Document        data)
     {
-        boolean debug = log.isDebugEnabled();
-
-        if (debug) {
-            log.debug("Setup this artifact with the uuid: " + identifier);
-        }
+        log.debug("Setup this artifact with the uuid: " + identifier);
 
         super.setup(identifier, factory, context, callMeta, data);
 
@@ -208,9 +203,7 @@
 
         String name = getName();
 
-        if (debug) {
-            log.debug("setup(): Set initial state for artifact '" + name + "'");
-        }
+        log.debug("setup(): Set initial state for artifact '" + name + "'");
 
         if (states == null) {
             log.error("No states found from which an initial "
@@ -241,21 +234,13 @@
     }
 
     protected void extractOut(Document data) {
-        log.debug("extractOut");
-        String ids = XMLUtils.xpathString(data, XPATH_IDS,
+        String targetOut = XMLUtils.xpathString(data, XPATH_TARGET_OUT,
             ArtifactNamespaceContext.INSTANCE);
+        if (targetOut.isEmpty()) {
+            targetOut = null;
+        }
 
-        log.debug("ids: '" + ids + "'");
-        if (ids != null) {
-            Matcher m = CONTAINS_OUT.matcher(ids);
-            if (m.matches()) {
-                boundToOut = m.group(2);
-                log.debug("Bound to out :'" + boundToOut + "'");
-            }
-            else {
-                log.debug("does not match");
-            }
-        }
+        setBoundToOut(targetOut);
     }
 
     /**
@@ -264,17 +249,9 @@
      * @return the id element value of data document.
      */
     public static String getDatacageIDValue(Document data) {
-
         String ids = XMLUtils.xpathString(data, XPATH_IDS,
             ArtifactNamespaceContext.INSTANCE);
 
-        if (ids != null) {
-            Matcher m = CONTAINS_OUT.matcher(ids);
-            if (m.matches()) {
-                ids = m.group(1);
-            }
-        }
-
         return ids;
     }
 
@@ -977,9 +954,18 @@
      * @param facet that defines index and name of facet searched.
      * @return facet instance or null if not found.
      */
-    public Facet getNativeFacet(Facet facet) {
+    public Facet getNativeFacet(Facet facet, String outName) {
         String name  = facet.getName();
         int    index = facet.getIndex();
+        if (getBoundToOut() != null && !getBoundToOut().isEmpty() &&
+                !getBoundToOut().equals(outName)) {
+            log.debug(name + ": not returning facets for " + outName +
+                    " because bound to " + getBoundToOut());
+            return null;
+        }
+        log.debug("Facet: " + facet.getName());
+        log.debug("Bound to out: " + getBoundToOut());
+        log.debug("OutName: " + outName);
 
         for (List<Facet> fs: facets.values()) {
             for (Facet f: fs) {
@@ -1497,6 +1483,9 @@
      * @param facets List of facets to be stored
      */
     protected void addFacets(String id, List<Facet> facets) {
+        for (Facet fac : facets) {
+            fac.setBoundToOut(getBoundToOut());
+        }
         this.facets.put(id, facets);
     }
 
@@ -1509,7 +1498,8 @@
         // Include uuid, type, name
         log.debug(" - Name: " + getName());
         log.debug(" - UUID: " + identifier());
-        log.debug(" - Class: " + this.getClass().getName());
+        log.debug(" - Class: " + getClass().getName());
+        log.debug(" - BoundToOut: " + getBoundToOut());
 
         log.debug("------ DUMP DATA ------");
         Collection<StateData> allData = data.values();
@@ -1545,6 +1535,7 @@
             List<Facet> fs = entry.getValue();
             for (Facet f: fs) {
                 log.debug("  # " + out + " : " + f.getName());
+                log.debug("  # boundToOut : " + f.getBoundToOut());
             }
         }
 
@@ -1618,11 +1609,23 @@
      * @return List of Facets belonging to the state identifier
      */
     protected List<Facet> getFacets(String stateid) {
-        return this.facets.get(stateid);
+        return facets.get(stateid);
     }
 
     public String getBoundToOut() {
         return boundToOut;
     }
+
+    /**
+     * Binds this artifact and all its facet to an out
+     */
+    public void setBoundToOut(String out) {
+        boundToOut = out;
+        for (List<Facet> stateFacets: facets.values()) {
+            for (Facet fac: stateFacets) {
+                fac.setBoundToOut(out);
+            }
+        }
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org