private async Task <TreeNodeInfo> getNodeByTreePath(TreePtr tree, TreePath path, DateTime asOfUtc, ICacheParams caching) { var tblCache = s_CacheTableName[tree]; var keyCache = nameof(getNodeByTreePath) + path + asOfUtc.Ticks; var result = await m_Data.Cache.FetchThroughAsync( keyCache, tblCache, caching, async key => { TreeNodeInfo nodeParent = null; TreeNodeInfo node = null; for (var i = -1; i < path.Count; i++) //going from LEFT to RIGHT { var segment = i < 0 ? Constraints.VERY_ROOT_PATH_SEGMENT : path[i]; node = await getNodeByPathSegment(tree, nodeParent == null ? GDID.ZERO : nodeParent.Gdid, segment, asOfUtc, caching).ConfigureAwait(false); if (node == null) { return(null); // deleted } //Config chain inheritance pattern if (nodeParent == null) { node.EffectiveConfig = new ConfigVector(node.LevelConfig.Content);//Copy node.FullPath = Constraints.VERY_ROOT_PATH_SEGMENT; } else { var confHere = node.LevelConfig.Node.NonEmpty(nameof(node.LevelConfig)); var confParent = nodeParent.EffectiveConfig.Node.NonEmpty(nameof(nodeParent.EffectiveConfig)); var confResult = new MemoryConfiguration() { Application = this.App }; confResult.CreateFromNode(confParent); //inherit confResult.Root.OverrideBy(confHere); //override node.EffectiveConfig = new ConfigVector(confResult.Root); node.FullPath = TreePath.Join(nodeParent.FullPath, node.PathSegment); } nodeParent = node; App.Authorize(new TreePermission(TreeAccessLevel.Read, node.FullPathId)); } return(node); }).ConfigureAwait(false); return(result); }
private async Task <TreeNodeInfo> getNodeByGdid(HashSet <GDID> graph, TreePtr tree, GDID gNode, DateTime asOfUtc, ICacheParams caching) { var tblCache = s_CacheTableName[tree]; var keyCache = nameof(getNodeByGdid) + gNode.ToHexString() + asOfUtc.Ticks; var result = await m_Data.Cache.FetchThroughAsync( keyCache, tblCache, caching, async key => { if (!graph.Add(gNode)) { //circular reference var err = new ConfigException("Circular reference in config tree = `{0}`, gnode = `{1}`, asof = `{2}`".Args(tree, gNode, asOfUtc)); WriteLogFromHere(Log.MessageType.CatastrophicError, err.Message, err, pars: new { tree = tree.ToString(), gnode = gNode, asof = asOfUtc }.ToJson()); throw err; } //1 - fetch THIS level - rightmost part of the tree var qry = new Query <TreeNodeInfo>("Tree.GetNodeInfoByGdid") { new Query.Param("tree", tree), new Query.Param("gdid", gNode), new Query.Param("asof", asOfUtc) }; var node = await m_Data.TreeLoadDocAsync(tree, qry); if (node == null) { return(null); } //2 - if IAM ROOT, there is no parent for root node.EffectiveConfig = new ConfigVector(node.LevelConfig.Content);//Copy node.FullPath = Constraints.VERY_ROOT_PATH_SEGMENT; if (node.Gdid == Constraints.G_VERY_ROOT_NODE) { return(node); } //3 - Fetch parent of THIS TreeNodeInfo nodeParent = await getNodeByGdid(graph, tree, node.G_Parent, asOfUtc, caching).ConfigureAwait(false); if (nodeParent == null) { return(null); } //4 - calculate effective config var cfgNode = node.LevelConfig.Node.NonEmpty(nameof(node.LevelConfig)); var cfgParent = nodeParent.EffectiveConfig.Node.NonEmpty(nameof(nodeParent.EffectiveConfig)); var confResult = new MemoryConfiguration() { Application = this.App }; confResult.CreateFromNode(cfgParent); //inherit confResult.Root.OverrideBy(cfgNode); //override node.EffectiveConfig.Node = confResult.Root; node.FullPath = TreePath.Join(nodeParent.FullPath, node.PathSegment); //the security check is done post factum AFTER tree node full path is known return(node); } ).ConfigureAwait(false); if (result == null) { return(null); } App.Authorize(new TreePermission(TreeAccessLevel.Read, result.FullPathId)); return(result); }