diff flys-backend/src/main/java/de/intevation/flys/importer/ImportAnnotation.java @ 763:8076f6a689d0

First part of flys/issue18 flys-backend/trunk@2124 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 15 Jun 2011 09:22:00 +0000
parents 3170fe2e7661
children
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportAnnotation.java	Tue Jun 14 17:30:09 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportAnnotation.java	Wed Jun 15 09:22:00 2011 +0000
@@ -1,6 +1,7 @@
 package de.intevation.flys.importer;
 
 import de.intevation.flys.model.Annotation;
+import de.intevation.flys.model.AnnotationType;
 import de.intevation.flys.model.Range;
 import de.intevation.flys.model.Position;
 import de.intevation.flys.model.Attribute;
@@ -15,10 +16,11 @@
 public class ImportAnnotation
 implements   Comparable<ImportAnnotation>
 {
-    protected ImportAttribute attribute;
-    protected ImportPosition  position;
-    protected ImportRange     range;
-    protected ImportEdge      edge;
+    protected ImportAttribute      attribute;
+    protected ImportPosition       position;
+    protected ImportRange          range;
+    protected ImportEdge           edge;
+    protected ImportAnnotationType type;
 
     protected Annotation      peer;
 
@@ -26,15 +28,17 @@
     }
 
     public ImportAnnotation(
-        ImportAttribute attribute,
-        ImportPosition  position,
-        ImportRange     range,
-        ImportEdge      edge
+        ImportAttribute      attribute,
+        ImportPosition       position,
+        ImportRange          range,
+        ImportEdge           edge,
+        ImportAnnotationType type
     ) {
         this.attribute = attribute;
         this.position  = position;
         this.range     = range;
         this.edge      = edge;
+        this.type      = type;
     }
 
     public int compareTo(ImportAnnotation other) {
@@ -55,7 +59,15 @@
         if (edge != null && other.edge == null) return +1;
         if (edge == null && other.edge == null) return 0;
 
-        return edge.compareTo(other.edge);
+        if ((d = edge.compareTo(other.edge)) != 0) {
+            return d;
+        }
+
+        if (type == null && other.type != null) return -1;
+        if (type != null && other.type == null) return +1;
+        if (type == null && other.type == null) return 0;
+
+        return type.compareTo(other.type);
     }
 
     public ImportAttribute getAttribute() {
@@ -82,26 +94,46 @@
         this.range = range;
     }
 
+    public ImportEdge getEdge() {
+        return edge;
+    }
+
+    public void setEdge(ImportEdge edge) {
+        this.edge = edge;
+    }
+
+    public ImportAnnotationType getType() {
+        return type;
+    }
+
+    public void setType(ImportAnnotationType type) {
+        this.type = type;
+    }
+
     public Annotation getPeer(River river) {
         if (peer == null) {
-            Range     r = range.getPeer(river);
-            Attribute a = attribute.getPeer();
-            Position  p = position.getPeer();
-            Edge      e = edge != null ? edge.getPeer() : null;
+            Range          r = range.getPeer(river);
+            Attribute      a = attribute.getPeer();
+            Position       p = position.getPeer();
+            Edge           e = edge != null ? edge.getPeer() : null;
+            AnnotationType t = type != null ? type.getPeer() : null;
+
             Session session = ImporterSession.getInstance().getDatabaseSession();
             Query query = session.createQuery(
                 "from Annotation where "    +
                 "range=:range and "         +
                 "attribute=:attribute and " +
                 "position=:position and "   +
-                "edge=:edge");
+                "edge=:edge and "           +
+                "type=:type");
             query.setParameter("range",     r);
             query.setParameter("attribute", a);
             query.setParameter("position",  p);
             query.setParameter("edge",      e);
+            query.setParameter("type",      t);
             List<Annotation> annotations = query.list();
             if (annotations.isEmpty()) {
-                peer = new Annotation(r, a, p, e);
+                peer = new Annotation(r, a, p, e, t);
                 session.save(peer);
             }
             else {

http://dive4elements.wald.intevation.org