<div dir="ltr">Hi Jon,<div>thanks for the quick reply and the explanation about file/folder/item, things are much clear now. Regarding the approach we are taking, we would like to think in term of "assets", where an asset can be either a file or a folder. Under this approach we will most likely remove the file/folder endpoints and generate a new one called "asset", keeping the REST semantics. So maybe we should start by creating an Asset model with its mongo collection counterpart and then move from there. But I will dig a bit deeper into mongo's options first, just to get a better insight on its capabilities.</div><div><br></div><div>Thanks!</div><div>Andy</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 10, 2017 at 10:49 AM, Jonathan Beezley <span dir="ltr"><<a href="mailto:jonathan.beezley@kitware.com" target="_blank">jonathan.beezley@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Andy,<div><br></div><div>Folders, items, and files are all separate entities. In terms of their tree structure, Girder models look like this:</div><div><br></div><div>* a folder's parent is either a folder, user, or collection</div><div>* an item's parent is a folder</div><div>* a file's parent is an item</div><div><br></div><div>A model can only have one parent, but multiple children. So, folders can contain both other folders and items, but not files. In terms of an abstract file system, there is no equivalent to an "item", it is an additional type that lies between a file and a folder.</div><div><br></div><div>Files don't have metadata associated with them, so you are probably looking to create an endpoint that searches folders and items. It's possible you might be able to construct a single query to do this using a mongo aggregation pipeline, but I'm not certain how. The simplest way would be to do two queries and join them together somehow. The only endpoint that I know of that returns multiple model types is <a href="https://github.com/girder/girder/blob/master/girder/api/v1/resource.py#L68" target="_blank">/resource/search</a>, though I don't know I would recommend doing it that way.</div><div><br></div><div>If I were doing this, I would probably just create two different endpoints for each type. It adds a bit of complexity to the client (two rest requests rather than one), but it is a more idiomatic restful interface.</div><div><br></div><div>Jon</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Mon, Jul 10, 2017 at 9:25 AM, Andrés Fortier <span dir="ltr"><<a href="mailto:andres@ekumenlabs.com" target="_blank">andres@ekumenlabs.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Hi all,<div>I'm working on a plugin to search on Files and Folders by a metadata field (the "type" field). The important parts of the code I have so far are:</div><div><br></div><div><div><font face="monospace, monospace">class ResourceExt(Resource):</font></div><div><font face="monospace, monospace"> @access.public</font></div><div><font face="monospace, monospace"> @describeRoute(...)</font></div><div><font face="monospace, monospace"> def typeSearch(self, params):</font></div><div><font face="monospace, monospace"> self.requireParams(('type'), params)</font></div><div><font face="monospace, monospace"> limit, offset, sort = self.getPagingParameters(param<wbr>s, 'name')</font></div><div><font face="monospace, monospace"> asset_type = params['type']</font></div><div><font face="monospace, monospace"> query = {"meta.type": asset_type}</font></div><div><font face="monospace, monospace"> fields = ['_id', 'name', 'description', 'folderId', 'public', 'access']</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> model = ModelImporter().model('item')</font></div><div><font face="monospace, monospace"> cursor = model.find(query, fields=fields)<br></font></div><div><font face="monospace, monospace"> return list(model.filterResultsByPerm<wbr>ission(</font></div><div><font face="monospace, monospace"> cursor, user=self.getCurrentUser(), level=AccessType.READ,</font></div><div><font face="monospace, monospace"> limit=limit, offset=offset, removeKeys=('public', 'access')))</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">def load(info):</font></div><div><font face="monospace, monospace"> ModelImporter.model('item').en<wbr>sureIndex(['meta.type', {'sparse': True}])</font></div><div><font face="monospace, monospace"> ext = ResourceExt()</font></div><div><font face="monospace, monospace"> info['apiRoot'].resource.route<wbr>('GET', ('type_search',), ext.typeSearch)</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">now this seems to be working ok with files, but fails to return folders, so I think I have a wrong idea of what an item model is. I originally thought that an item was an abstraction of both files and folders, and that querying the item model was the way to query for both of them. I then checked the items mongo collection and it seems there is an item record for each file record, but none for the folder entries. So this brings up a couple of questions:</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">1. What is the relationship between items, files and folders? What are the concrete use cases for items? [1]</font></div><div><font face="arial, helvetica, sans-serif">2. Is there a way to perform metadata-based queries on both files and folders? I know I can do two queries (one on files and one on folders) but then I would have to manually merge them and handle all the limit/offset math, which seems unnecessarily complicated.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">[1] I did check the class comments and I'm a bit confused about those too. E.g. in Item it says "</font><span style="font-family:arial,helvetica,sans-serif">Items are leaves in the data hierarchy. They can contain 0 or more </span><span style="font-family:arial,helvetica,sans-serif">files within them ...", which is confusing as I would expect leaves to be files instead of containing them. Also if items can contain files, doesn't that mean they are (or act as) folders?</span></div><div><span style="font-family:arial,helvetica,sans-serif"><br></span></div><div><span style="font-family:arial,helvetica,sans-serif">Thanks in advance!</span></div><div><span style="font-family:arial,helvetica,sans-serif">Andy</span></div></div>
<br></div></div>______________________________<wbr>_________________<br>
Girder-users mailing list<br>
<a href="mailto:Girder-users@public.kitware.com" target="_blank">Girder-users@public.kitware.co<wbr>m</a><br>
<a href="http://public.kitware.com/mailman/listinfo/girder-users" rel="noreferrer" target="_blank">http://public.kitware.com/mail<wbr>man/listinfo/girder-users</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>