get<T extends IResource> static method
AsyncReply<T?>
get<T extends IResource>(
- String path, [
- Map<
String, dynamic> ? attributes = null, - IResource? parent = null,
- IPermissionsManager? manager = null,
Implementation
static AsyncReply<T?> get<T extends IResource>(String path,
[Map<String, dynamic>? attributes = null,
IResource? parent = null,
IPermissionsManager? manager = null]) {
var rt = AsyncReply<T?>();
// Should we create a new store ?
if (_urlRegex.hasMatch(path)) {
var url = _urlRegex.allMatches(path).first;
if (protocols.containsKey(url[1])) {
var handler = protocols[url[1]] as AsyncReply<IStore> Function(
String, Map<String, dynamic>?);
var getFromStore = () {
handler(url[2] as String, attributes)
..then((store) {
if ((url[3] as String).length > 0 && url[3] != "")
store.get(url[3] as String)
..then((r) {
rt.trigger(r as T);
})
..error((e) => rt.triggerError(e));
else
rt.trigger(store as T);
})
..error((e) {
rt.triggerError(e);
//Warehouse.remove(store);
});
};
if (!_warehouseIsOpen)
open()
..then((v) {
if (v)
getFromStore();
else
rt.trigger(null);
});
else
getFromStore();
return rt;
}
}
query(path).then((rs) {
if (rs != null && rs.length > 0)
rt.trigger(rs[0] as T);
else
rt.trigger(null);
});
return rt;
/*
var p = path.split('/');
IResource res;
for(IStore d in _stores)
if (p[0] == d.instance.name)
{
var i = 1;
res = d;
while(p.length > i)
{
var si = i;
for (IResource r in res.instance.children)
if (r.instance.name == p[i])
{
i++;
res = r;
break;
}
if (si == i)
// not found, ask the store
return d.get(path.substring(p[0].length + 1));
}
return new AsyncReply<IResource>.ready(res);
}
// Should we create a new store ?
if (path.contains("://"))
{
var url = path.split("://");
var hostname = url[1].split('/')[0];
var pathname = url[1].split('/').skip(1).join("/");
var rt = new AsyncReply<IResource>();
if (protocols.containsKey(url[0]))
{
var handler = protocols[url[0]];
var store = handler();
put(store, url[0] + "://" + hostname, null, parent, null, 0, manager, attributes);
store.trigger(ResourceTrigger.Open).then<dynamic>((x){
if (pathname.length > 0 && pathname != "")
store.get(pathname).then<dynamic>((r) => rt.trigger(r)
).error((e) =>
rt.triggerError(e)
);
else
rt.trigger(store);
}).error((e) {
rt.triggerError(e);
Warehouse.remove(store);
});
}
return rt;
}
return new AsyncReply<IResource>.ready(null);
*/
}