Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display lists in alphabetical order, if possible #39

Open
sottolski opened this issue Aug 24, 2020 · 1 comment
Open

Display lists in alphabetical order, if possible #39

sottolski opened this issue Aug 24, 2020 · 1 comment

Comments

@sottolski
Copy link
Contributor

sottolski commented Aug 24, 2020

Currently, the hierarchy is displayed in no particular order, which is not optimal for the end user. I'm not sure if I found all the right places, but following patch seems to work:

diff --git a/src/main/java/com/enterprisepasswordsafe/database/HierarchyNodeDAO.java b/src/main/java/com/enterprisepasswordsafe/database/HierarchyNodeDAO.java
index ce055ed..fa18514 100644
--- a/src/main/java/com/enterprisepasswordsafe/database/HierarchyNodeDAO.java
+++ b/src/main/java/com/enterprisepasswordsafe/database/HierarchyNodeDAO.java
@@ -63,7 +63,7 @@ public final class HierarchyNodeDAO
      */
 
     private static final String GET_NODE_BY_NAME_SQL =
-            "SELECT " + NODE_FIELDS + " FROM hierarchy  WHERE name = ?";
+            "SELECT " + NODE_FIELDS + " FROM hierarchy  WHERE name = ? ORDER BY name";
 
 
     /**
@@ -71,7 +71,7 @@ public final class HierarchyNodeDAO
      */
 
     private static final String GET_ALL_CHILDREN_NODES_SQL =
-            "SELECT node_id, name, parent_id, type FROM hierarchy nodes WHERE parent_id = ? ";
+            "SELECT node_id, name, parent_id, type FROM hierarchy nodes WHERE parent_id = ? ORDER BY name ";
 
     /**
      * The SQL statement to get the nodes representing a specific access controlled object.
@@ -88,7 +88,7 @@ public final class HierarchyNodeDAO
     private static final String GET_VALID_CHILD_OBJECT_IDS_VIA_UAC_SQL =
             "SELECT   h.name FROM hierarchy h, user_access_control uac "
             + " WHERE h.parent_id = ? AND h.type = " + HierarchyNode.OBJECT_NODE + " AND uac.item_id = h.name "
-            + "  AND uac.rkey is not null AND uac.user_id = ? ";
+            + "  AND uac.rkey is not null AND uac.user_id = ? ORDER BY h.name ";
 
     /**
      * The SQL statement to get the valid object node children for a given
@@ -100,7 +100,7 @@ public final class HierarchyNodeDAO
             + "  FROM hierarchy h, group_access_control gac, membership m, groups g "
             + " WHERE h.parent_id = ? AND h.type = "+ HierarchyNode.OBJECT_NODE+ " AND gac.item_id = h.name "
             + "   AND gac.rkey is not null AND m.group_id = gac.group_id AND m.user_id = ? "
-            + "   AND g.group_id = gac.group_id AND g.status = " + Group.STATUS_ENABLED;
+            + "   AND g.group_id = gac.group_id AND g.status = " + Group.STATUS_ENABLED + " ORDER BY h.name";
 
     /**
      * The SQL statement to get the all child object node ids.
@@ -130,7 +130,7 @@ public final class HierarchyNodeDAO
      */
 
     private static final String GET_CHILD_CONTAINER_NODES_SQL =
-            "SELECT " + NODE_FIELDS + "  FROM hierarchy WHERE parent_id = ? AND type=" + HierarchyNode.CONTAINER_NODE;
+            "SELECT " + NODE_FIELDS + "  FROM hierarchy WHERE parent_id = ? AND type=" + HierarchyNode.CONTAINER_NODE + " ORDER BY name";
 
     /**
      * The SQL statement to get the child container nodes of a specific node.
@@ -145,7 +145,7 @@ public final class HierarchyNodeDAO
 
     private static final String GET_USER_CONTAINER_NODE_SQL =
             "SELECT   node_id, name, parent_id, type FROM hierarchy WHERE name = ? "
-            + "   AND type = " + HierarchyNode.USER_CONTAINER_NODE;
+            + "   AND type = " + HierarchyNode.USER_CONTAINER_NODE + " ORDER BY name";
 
     /**
      * The SQL statement to get the child container nodes of a specific node.
@@ -173,7 +173,7 @@ public final class HierarchyNodeDAO
      */
 
     private static final String TEST_NODES_REFERRING_TO_OBJECT_NODE_SQL =
-            "SELECT " + NODE_FIELDS + " FROM hierarchy WHERE name = ? AND type = " + HierarchyNode.OBJECT_NODE;
+            "SELECT " + NODE_FIELDS + " FROM hierarchy WHERE name = ? AND type = " + HierarchyNode.OBJECT_NODE + " ORDER BY name";
 
     /**
      * The SQL to delete a node.

A similar ordering would be nice for the passwords as well.

Well, I'm not really a coder, so I'm not sure if this makes sense. It seems to work, but I also see error messages like

24-Aug-2020 21:41:01.374 SEVERE [http-nio-8080-exec-5] com.enterprisepasswordsafe.database.StoredObjectFetcher.getMultiple Error fetching object.
        java.sql.SQLDataException: No such column: 3
@sottolski
Copy link
Contributor Author

please ignore the exception mentioned above, this is probably due to my old dataset and incomplete migration. The password_data column is always empty, therefore

for(Password password : getMultiple(user, GET_EXPIRY_DETAILS_SQL)) {
            if( password.getExpiry() < expiryWarningDate) {
                return true;
            }
        }

is failing. I probably would nee a routine to migrate the "password" field to "password_data" somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants