[PATCH] Introduced helper for finding the user name for a given artifact

Wald Commits scm-commit at wald.intevation.org
Fri Feb 9 13:26:28 CET 2018


# HG changeset patch
# User gernotbelger
# Date 1518179179 -3600
# Node ID 68f01f10624e32d6051003854409a1ce6dd862e7
# Parent  e781b847fdca562185fc23e5444b25dfbb50dfc1
Introduced helper for finding the user name for a given artifact

diff -r e781b847fdca -r 68f01f10624e artifact-database/src/main/java/org/dive4elements/artifactdatabase/ArtifactDatabaseImpl.java
--- a/artifact-database/src/main/java/org/dive4elements/artifactdatabase/ArtifactDatabaseImpl.java	Mon Feb 22 17:25:21 2016 +0100
+++ b/artifact-database/src/main/java/org/dive4elements/artifactdatabase/ArtifactDatabaseImpl.java	Fri Feb 09 13:26:19 2018 +0100
@@ -1979,5 +1979,10 @@
             }
         });
     }
+    
+    @Override
+    public String findArtifactUser(final String artifactIdentifier) {
+        return backend.findUserName(artifactIdentifier);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r e781b847fdca -r 68f01f10624e artifact-database/src/main/java/org/dive4elements/artifactdatabase/Backend.java
--- a/artifact-database/src/main/java/org/dive4elements/artifactdatabase/Backend.java	Mon Feb 22 17:25:21 2016 +0100
+++ b/artifact-database/src/main/java/org/dive4elements/artifactdatabase/Backend.java	Fri Feb 09 13:26:19 2018 +0100
@@ -133,6 +133,7 @@
     public String SQL_COLLECTIONS_TOUCH_BY_ID;
     public String SQL_COLLECTION_ITEMS_LIST_GID;
     public String SQL_ALL_ARTIFACTS;
+    public String SQL_FIND_USER_BY_ARTIFACT;
 
     /** The singleton.*/
     protected static Backend instance;
@@ -361,6 +362,7 @@
         SQL_COLLECTIONS_TOUCH_BY_ID = sql.get("collections.touch.by.id");
         SQL_COLLECTION_ITEMS_LIST_GID = sql.get("collection.items.list.gid");
         SQL_ALL_ARTIFACTS = sql.get("all.artifacts");
+        SQL_FIND_USER_BY_ARTIFACT = sql.get("find.user.by.artifact");        
     }
 
     public void addListener(BackendListener listener) {
@@ -1030,6 +1032,43 @@
 
         return exec.runRead() ? user[0] : null;
     }
+    
+    /** Find the owner of a given artifact */
+    public String findUserName(final String artifactGid) {
+
+        final String[] returnValue = new String[1];
+
+        final SQLExecutor.Instance exec = this.sqlExecutor.new Instance() {
+
+            @Override
+            public boolean doIt() throws SQLException {
+
+                prepareStatement(Backend.this.SQL_FIND_USER_BY_ARTIFACT);
+                this.stmnt.setString(1, artifactGid);
+
+                this.result = this.stmnt.executeQuery();
+
+                // final HashMap<String, LazyBackendUser> users = new HashMap<String, LazyBackendUser>();
+
+                while (this.result.next()) {
+                    // final String userIdentifier = this.result.getString(1);
+                    final String userName = this.result.getString(2);
+
+                    // We only need the name at the moment, else we could do this: User user = new LazyBackendUser(
+                    // userIdentifier, userFactory, Backend.this, context);
+                    returnValue[0] = userName;
+                    return true;
+                }
+
+                return true;
+            }
+        };
+
+        if (exec.runRead())
+            return returnValue[0];
+
+        return null;
+    }    
 
     public User [] getUsers(
         final UserFactory factory,
diff -r e781b847fdca -r 68f01f10624e artifact-database/src/main/resources/sql/org-h2-driver.properties
--- a/artifact-database/src/main/resources/sql/org-h2-driver.properties	Mon Feb 22 17:25:21 2016 +0100
+++ b/artifact-database/src/main/resources/sql/org-h2-driver.properties	Fri Feb 09 13:26:19 2018 +0100
@@ -196,3 +196,10 @@
                 INNER JOIN collection_items ci ON c.id = ci.collection_id \
                 INNER JOIN artifacts a         ON a.id = ci.artifact_id \
         ORDER BY u_gid, c_gid
+
+find.user.by.artifact = \
+	SELECT users.id, users.name FROM users, collections, collection_items, artifacts \
+	WHERE users.id = collections.owner_id AND \
+		  collections.id = collection_items.collection_id AND \
+		  collection_items.artifact_id = artifacts.id AND \
+		  artifacts.gid = ?::uuid
diff -r e781b847fdca -r 68f01f10624e artifact-database/src/main/resources/sql/org-postgresql-driver.properties
--- a/artifact-database/src/main/resources/sql/org-postgresql-driver.properties	Mon Feb 22 17:25:21 2016 +0100
+++ b/artifact-database/src/main/resources/sql/org-postgresql-driver.properties	Fri Feb 09 13:26:19 2018 +0100
@@ -185,3 +185,10 @@
                 INNER JOIN collection_items ci ON c.id = ci.collection_id \
                 INNER JOIN artifacts a         ON a.id = ci.artifact_id \
         ORDER BY u_gid, c_gid
+
+find.user.by.artifact = \
+	SELECT users.id, users.name FROM users, collections, collection_items, artifacts \
+	WHERE users.id = collections.owner_id AND \
+		  collections.id = collection_items.collection_id AND \
+		  collection_items.artifact_id = artifacts.id AND \
+		  artifacts.gid = ?::uuid
diff -r e781b847fdca -r 68f01f10624e artifacts/src/main/java/org/dive4elements/artifacts/ArtifactDatabase.java
--- a/artifacts/src/main/java/org/dive4elements/artifacts/ArtifactDatabase.java	Mon Feb 22 17:25:21 2016 +0100
+++ b/artifacts/src/main/java/org/dive4elements/artifacts/ArtifactDatabase.java	Fri Feb 09 13:26:19 2018 +0100
@@ -290,9 +290,11 @@
             String   artifactId,
             Date     artifactCreated,
             Artifact artifact);
-    };
+    }
 
     public void loadAllArtifacts(ArtifactLoadedCallback callback)
         throws ArtifactDatabaseException;
+
+    String findArtifactUser(String artifactIdentifier);
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :


More information about the Dive4Elements-commits mailing list