diff --git a/src/main/java/it/inaf/oats/vospace/datamodel/NodeUtils.java b/src/main/java/it/inaf/oats/vospace/datamodel/NodeUtils.java index ddbe29908cf933a0dcfb774b9442b5737dff393d..4190ae2fdf60249f1d89aec0e4f9b9bf93b5be81 100644 --- a/src/main/java/it/inaf/oats/vospace/datamodel/NodeUtils.java +++ b/src/main/java/it/inaf/oats/vospace/datamodel/NodeUtils.java @@ -9,6 +9,9 @@ import java.util.Arrays; import java.util.List; import java.util.regex.Pattern; import java.util.stream.Collectors; +import net.ivoa.xml.vospace.v2.ContainerNode; +import net.ivoa.xml.vospace.v2.DataNode; +import net.ivoa.xml.vospace.v2.StructuredDataNode; public class NodeUtils { @@ -163,5 +166,62 @@ public class NodeUtils { return true; } + + + + + public static String getDbNodeType(Node node) { + if (node instanceof ContainerNode) { + return "container"; + } else if (node instanceof DataNode) { + return "data"; + } + throw new UnsupportedOperationException("Unable to retrieve database node type for class " + node.getClass().getCanonicalName()); + } + + + public static String getNodeName(String path) { + String[] parsedPath = path.split("/"); + + return parsedPath[parsedPath.length - 1]; + } + + + public static String getNodeName(Node myNode) { + String uri = myNode.getUri(); + return getNodeName(uri); + } + + + public static boolean getIsBusy(Node myNode) { + + if (myNode instanceof DataNode) { + + DataNode dataNode = (DataNode) myNode; + return dataNode.isBusy(); + } + + return false; + } + + + public static Node getTypedNode(String type) { + Node node; + switch (type) { + case "container": + node = new ContainerNode(); + break; + case "data": + node = new DataNode(); + break; + case "structured": + node = new StructuredDataNode(); + break; + default: + throw new UnsupportedOperationException("Node type " + type + " not supported yet"); + } + return node; + } + }