changeset 5274:bcfb30b73f06

Merged
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 13 Mar 2013 16:39:35 +0100
parents db196abd16ca (diff) da3101abc9da (current diff)
children 911f62917753
files
diffstat 5 files changed, 34 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/doc/schema/oracle-minfo.sql	Wed Mar 13 12:47:51 2013 +0100
+++ b/flys-backend/doc/schema/oracle-minfo.sql	Wed Mar 13 16:39:35 2013 +0100
@@ -24,7 +24,7 @@
 -- lookup table for bedheight types
 CREATE TABLE bed_height_type (
     id          NUMBER(38,0) NOT NULL,
-    type        VARCHAR(65)  NOT NULL,
+    name        VARCHAR(65)  NOT NULL,
     PRIMARY KEY(id)
 );
 INSERT INTO bed_height_type VALUES (1, 'Querprofil')
--- a/flys-backend/doc/schema/postgresql-minfo.sql	Wed Mar 13 12:47:51 2013 +0100
+++ b/flys-backend/doc/schema/postgresql-minfo.sql	Wed Mar 13 16:39:35 2013 +0100
@@ -24,7 +24,7 @@
 -- lookup table for bedheight types
 CREATE TABLE bed_height_type (
     id          int NOT NULL,
-    type        VARCHAR(64) NOT NULL,
+    name        VARCHAR(64) NOT NULL,
     PRIMARY KEY(id)
 );
 INSERT INTO bed_height_type VALUES (1, 'Querprofil')
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightType.java	Wed Mar 13 12:47:51 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightType.java	Wed Mar 13 16:39:35 2013 +0100
@@ -16,19 +16,22 @@
         Logger.getLogger(ImportBedHeightType.class);
 
     protected String name;
-    protected String description;
 
     protected BedHeightType peer;
 
+    public ImportBedHeightType(BedHeightType peer)  {
+        this.peer = peer;
+        name = peer.getName();
+    }
 
-    public ImportBedHeightType(String name, String description) {
+
+    public ImportBedHeightType(String name) {
         this.name        = name;
-        this.description = description;
     }
 
 
     public void storeDependencies() {
-        BedHeightType type = getPeer();
+        getPeer();
     }
 
 
@@ -37,16 +40,14 @@
             Session session = ImporterSession.getInstance().getDatabaseSession();
 
             Query query = session.createQuery(
-                "from BedHeightType where " +
-                "name=:name and description=:description");
+                "from BedHeightType where name=:name and description=:description");
 
             query.setParameter("name", name);
-            query.setParameter("description", description);
 
             List<BedHeightType> types = query.list();
 
             if (types.isEmpty()) {
-                peer = new BedHeightType(name, description);
+                peer = new BedHeightType(name);
                 session.save(peer);
             }
             else {
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightParser.java	Wed Mar 13 12:47:51 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightParser.java	Wed Mar 13 16:39:35 2013 +0100
@@ -331,15 +331,14 @@
         if (m.matches()) {
             String tmp = m.group(1).replace(";", "");
 
-            String name = BedHeightType.getBedHeightName(tmp);
+            BedHeightType bht = BedHeightType.fetchBedHeightTypeForType(tmp);
 
-            if (name != null) {
-                obj.setType(new ImportBedHeightType(name, tmp));
+            if (bht != null) {
+                obj.setType(new ImportBedHeightType(bht));
                 return true;
             }
-            else {
-                log.warn("Unknown bed height type: '" + tmp + "'");
-            }
+
+            log.warn("Unknown bed height type: '" + tmp + "'");
         }
 
         return false;
--- a/flys-backend/src/main/java/de/intevation/flys/model/BedHeightType.java	Wed Mar 13 12:47:51 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/model/BedHeightType.java	Wed Mar 13 16:39:35 2013 +0100
@@ -2,6 +2,8 @@
 
 import java.io.Serializable;
 
+import java.util.List;
+
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.Table;
@@ -12,6 +14,10 @@
 
 import org.apache.log4j.Logger;
 
+import org.hibernate.Query;
+import org.hibernate.Session;
+
+import de.intevation.flys.backend.SessionHolder;
 
 @Entity
 @Table(name = "bed_height_type")
@@ -22,15 +28,13 @@
 
     private Integer id;
     private String  name;
-    private String  description;
 
 
     public BedHeightType() {
     }
 
-    public BedHeightType(String name, String description) {
-        this.name        = name;
-        this.description = description;
+    public BedHeightType(String name) {
+        this.name = name;
     }
 
     @Id
@@ -59,36 +63,17 @@
         this.name = name;
     }
 
-    @Column(name = "description")
-    public String getDescription() {
-        return description;
-    }
-
-    public void setDescription(String description) {
-        this.description = description;
-    }
-
 
-    public static String getBedHeightName(String description) {
-        if (description.equals("Flächenpeilung")) {
-            return "FP";
-        }
-        else if ("Querprofile".equals(description)) {
-            return "QP";
-        }
-        else if ("Querprofil".equals(description)) {
-            return "QP";
-        }
-        else if ("TIN".equals(description)) {
-            return "TIN";
-        }
-        else if ("Flächen- u. Querprofilpeilungen".equals(description)) {
-            return "FP-QP";
-        }
-        else {
-            log.warn("Unknown bed height type: " + description);
-            return null;
-        }
+    public static BedHeightType fetchBedHeightTypeForType(String type) {
+        Session session = SessionHolder.HOLDER.get();
+        Query query = session.createQuery(
+            "from BedHeightType where type=:type");
+
+        query.setParameter("type", type);
+
+        List<Object> results = query.list();
+
+        return results.isEmpty() ? null : (BedHeightType)results.get(0);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org