Commit ff3cce3c authored by Sonia Zorba's avatar Sonia Zorba
Browse files

NodeDAO bugfix

parent c2518169
Loading
Loading
Loading
Loading
+24 −9
Original line number Diff line number Diff line
@@ -41,21 +41,24 @@ public class NodeDAO {
        String path = nodeURI.replaceAll("vos://[^/]+", "");
        String parentPath = getParentPath(path);

        String sql = "SELECT path, relative_path from "
        String sql = "SELECT path from "
                + "node n join node_vos_path p on n.node_id = p.node_id "
                + "where p.vos_path = ?";

        List<NodePaths> paths = jdbcTemplate.query(conn -> {
        List<String> ltreeParentPaths = jdbcTemplate.query(conn -> {
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, parentPath);
            return ps;
        }, (row, index) -> {
            return getPathsFromResultSet(row);
            return row.getString("path");
        });

        if (paths.isEmpty()) {
        if (ltreeParentPaths.isEmpty()) {
            throw new IllegalStateException("Unable to find parent node during node creation");
        }
        if (ltreeParentPaths.size() > 1) {
            throw new IllegalStateException("Multiple ltree parent paths found for " + parentPath);
        }

        StringBuilder sb = new StringBuilder();
        sb.append("INSERT INTO node");
@@ -72,7 +75,7 @@ public class NodeDAO {
            ps.setArray(5, fromPropertyToArray(ps, getProperty(myNode, getPropertyURI("groupread"))));
            ps.setArray(6, fromPropertyToArray(ps, getProperty(myNode, getPropertyURI("groupwrite"))));
            ps.setBoolean(7, Boolean.valueOf(getProperty(myNode, getPropertyURI("publicread"))));
            ps.setObject(8, paths.get(0).parentPath, Types.OTHER);
            ps.setObject(8, ltreeParentPaths.get(0), Types.OTHER);
            ps.setObject(9, getDbNodeType(myNode), Types.OTHER);
            return ps;
        });
@@ -81,7 +84,7 @@ public class NodeDAO {

    public Optional<Node> listNode(String path) {

        String sql = "SELECT os.vos_path, n.node_id, type, async_trans, busy_state, owner_id, group_read, group_write, is_public, content_length, created_on, last_modified from node n\n"
        String sql = "SELECT os.vos_path, n.node_id, type, async_trans, busy_state, creator_id, group_read, group_write, is_public, content_length, created_on, last_modified from node n\n"
                + "JOIN node_vos_path os ON n.node_id = os.node_id\n"
                + "WHERE n.path ~ (" + getFirstLevelChildrenSelector(path) + ")::lquery\n"
                + "OR os.vos_path = ? ORDER BY vos_path";
@@ -141,6 +144,9 @@ public class NodeDAO {
        addProperty(getPropertyURI("btime"), rs.getString("created_on"),
                properties);

        addProperty(getPropertyURI("creator"), rs.getString("creator_id"),
                properties);

        addProperty(getPropertyURI("mtime"), rs.getString("last_modified"),
                properties);

@@ -228,13 +234,22 @@ public class NodeDAO {
        return false;
    }

    // Copied from CreateNodeController: to be moved in a common utility class
    private String getParentPath(String path) {
        String[] parsedPath = path.split("/");
        String[] parsedPath = path.split("[/]+");

        if (parsedPath.length < 2 || !parsedPath[0].isEmpty()) {
            throw new IllegalArgumentException();
        }

        StringBuilder sb = new StringBuilder();
        sb.append("/");

        for (int i = 0; i < parsedPath.length - 1; i++) {
            sb.append("/").append(parsedPath[i]);
        for (int i = 1; i < parsedPath.length - 1; i++) {
            sb.append(parsedPath[i]);
            if (i < parsedPath.length - 2) {
                sb.append("/");
            }
        }

        return sb.toString();