diff --git a/src/main/java/caosdb/server/resource/AbstractCaosDBServerResource.java b/src/main/java/caosdb/server/resource/AbstractCaosDBServerResource.java index c88bbd75a34aea81198b2c9d48702ca6f66a41e0..f389e3d2d8474811312fc6416a2a4943a72393c5 100644 --- a/src/main/java/caosdb/server/resource/AbstractCaosDBServerResource.java +++ b/src/main/java/caosdb/server/resource/AbstractCaosDBServerResource.java @@ -331,6 +331,7 @@ public abstract class AbstractCaosDBServerResource extends ServerResource { this.xslScript = s; } + /** Wrap an element for an "OK" response. */ protected JdomRepresentation ok(Element root) { return ok(new Document(root)); } diff --git a/src/main/java/caosdb/server/resource/InfoResource.java b/src/main/java/caosdb/server/resource/InfoResource.java index 96459212a804d2451c2b978bd858bba954640bca..c2342cc46f7e62fd6a398218b39e804ab9f1767d 100644 --- a/src/main/java/caosdb/server/resource/InfoResource.java +++ b/src/main/java/caosdb/server/resource/InfoResource.java @@ -30,10 +30,15 @@ import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.JDOMException; import org.restlet.representation.Representation; -import org.restlet.resource.Options; +/** This class represents the information retrieved by /Info requests (only GET) to CaosDB. */ public class InfoResource extends AbstractCaosDBServerResource { + /** + * The response to the HTTP GET request is generated here. + * + * @return The response code for OK and the resulting info XML document. + */ @Override protected Representation httpGetInChildClass() throws Exception { final Document doc = new Document(); @@ -45,14 +50,10 @@ public class InfoResource extends AbstractCaosDBServerResource { return ok(doc); } + /** There is no POST request specified for the /Info resource. */ @Override protected Representation httpPostInChildClass(final Representation entity) throws ConnectionException, JDOMException { return null; } - - @Options - public static Representation describeResource() { - return null; - } } diff --git a/src/main/java/caosdb/server/utils/Info.java b/src/main/java/caosdb/server/utils/Info.java index bba346716624f3802aac449b86b2191c7cbcee10..445374a105fbe8fbff1bc95a90fcceba197b09f4 100644 --- a/src/main/java/caosdb/server/utils/Info.java +++ b/src/main/java/caosdb/server/utils/Info.java @@ -95,6 +95,18 @@ public class Info extends AbstractObservable implements Observer, TransactionInt return recordTypesCount; } + /** + * Utility function that takes an array of file objects and returns a linked list containing XML + * representations of all files within each contained directory. All files in the array that are + * directories are recursively traversed. This function is used for files within the drop off box + * only. + * + * @param files An array of file objects. + * @return A linked list containing XML elements. The path attribute of these elements is set to + * the absolute path of the filenames where the path to the drop off box is removed at the + * beginning. + * @fixme Should check if the files are inside the DropOffBox path. + */ private static LinkedList<Element> getFlatList(final File[] files) { try { final LinkedList<Element> ret = new LinkedList<Element>(); @@ -104,7 +116,7 @@ public class Info extends AbstractObservable implements Observer, TransactionInt } else { final Element element = new Element("file"); final String tempPath = - file.getAbsolutePath().substring(dropOffBox.getCanonicalPath().length() + 1); + file.getCanonicalPath().substring(dropOffBox.getCanonicalPath().length() + 1); element.setAttribute("path", tempPath); ret.add(element); } @@ -158,6 +170,22 @@ public class Info extends AbstractObservable implements Observer, TransactionInt return toElement(false); } + /** + * Generates an XML element showing the information for the /Info resource in CaosDB. + * + * @return An XML element containing: + * <ul> + * <li>The number of records + * <li>The number of properties + * <li>The number of record types + * <li>The number of files + * <li>The total file size + * <li>The number of temp files + * <li>The path of the DropOffBox + * <li>A tree of files in the DropOffBox + * </ul> + * TODO: The error format for missing or not readable drop off box has to be specified. + */ public static Element toElement(final boolean tree) throws Exception, SQLException { dropOffBox = new File(FileSystem.getDropOffBox()); final Element info = new Element("Stats"); @@ -173,14 +201,20 @@ public class Info extends AbstractObservable implements Observer, TransactionInt } final Element e = new Element("dropOffBox"); if (dropOffBox.isDirectory()) { - if (tree) { - e.setAttribute("path", dropOffBox.getAbsolutePath()); - e.addContent(getTree(dropOffBox.listFiles())); + if (dropOffBox.canRead()) { + if (tree) { + e.setAttribute("path", dropOffBox.getAbsolutePath()); + e.addContent(getTree(dropOffBox.listFiles())); + } else { + e.setAttribute("path", dropOffBox.getAbsolutePath()); + e.addContent(getFlatList(dropOffBox.listFiles())); + } } else { - e.setAttribute("path", dropOffBox.getAbsolutePath()); - e.addContent(getFlatList(dropOffBox.listFiles())); + // TODO: return a message that the DropOffBox is not readable. } } else { + // TODO: This function should at least return a message that the DropOffBox is disabled or not + // present. } info.addContent(counts); info.addContent(e);