From 654d95f9df5774c2f22367259bf407638a3b4185 Mon Sep 17 00:00:00 2001 From: Nicola Fulvio Calabria <nicola.calabria@inaf.it> Date: Thu, 7 Jan 2021 22:32:12 +0100 Subject: [PATCH] Task #3547 - Complete getNodeFromResultSet method in NodeDAO --- .../oats/vospace/persistence/NodeDAO.java | 54 +++++++++++++++++-- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java b/src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java index a0eb652..f0f60db 100644 --- a/src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java +++ b/src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java @@ -4,11 +4,13 @@ import net.ivoa.xml.vospace.v2.Node; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import javax.sql.DataSource; import net.ivoa.xml.vospace.v2.ContainerNode; import net.ivoa.xml.vospace.v2.DataNode; +import net.ivoa.xml.vospace.v2.Property; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.jdbc.core.JdbcTemplate; @@ -46,7 +48,7 @@ public class NodeDAO { public Optional<Node> listNode(String path) { - String sql = "SELECT os.vos_path, n.node_id, type, async_trans, 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, owner_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"; @@ -60,13 +62,13 @@ public class NodeDAO { return getNodeFromResultSet(row); }); - if(parentAndChildren.isEmpty()) { + if (parentAndChildren.isEmpty()) { return Optional.empty(); } - + // Query returns parent as first node Node node = parentAndChildren.get(0); - + // Fill children if (node instanceof ContainerNode && parentAndChildren.size() > 1) { ContainerNode parent = (ContainerNode) node; @@ -91,11 +93,55 @@ public class NodeDAO { private Node getNodeFromResultSet(ResultSet rs) throws SQLException { Node node = getTypedNode(rs.getString("type")); + + if(node instanceof DataNode) + { + ((DataNode) node).setBusy(rs.getBoolean("is_busy")); + } + node.setUri(getUri(rs.getString("vos_path"))); + List<Property> properties = new ArrayList<>(); + + addProperty(getPropertyURI("length"), rs.getString("content_length"), + properties); + + addProperty(getPropertyURI("btime"), rs.getString("created_on"), + properties); + + addProperty(getPropertyURI("mtime"), rs.getString("last_modified"), + properties); + + addProperty(getPropertyURI("groupread"), rs.getString("group_read"), + properties); + + addProperty(getPropertyURI("groupwrite"), rs.getString("group_write"), + properties); + + addProperty(getPropertyURI("publicread"), rs.getString("is_public"), + properties); + + addProperty("urn:async_trans", rs.getString("async_trans"), + properties); + + node.setProperties(properties); return node; } + private String getPropertyURI(String propertyName) { + return "ivo://ivoa.net/vospace/core#".concat(propertyName); + } + + // If value is null does nothing + private void addProperty(String uri, String value, List<Property> list) { + if (value != null) { + Property prop = new Property(); + prop.setUri(uri); + prop.setValue(value); + list.add(prop); + } + } + private Node getTypedNode(String type) { Node node; switch (type) { -- GitLab