/// <summary> /// Get a factor tree node by the specified factor id. /// </summary> /// <param name="userContext"> /// Information about the user that makes this method call. /// </param> /// <param name="factorId">The specified factor id.</param> /// <returns>A factor tree node related to the specified factor id.</returns> public override IFactorTreeNode GetFactorTree(IUserContext userContext, int factorId) { IFactorTreeNode factorTreeNode = null; FactorTreeNodeList factorTrees = null; Dictionary <int, IFactorTreeNode> factorTreeNodes = new Dictionary <int, IFactorTreeNode>(); IFactorTreeSearchCriteria searchCriteria; searchCriteria = new FactorTreeSearchCriteria(); searchCriteria.FactorIds = new List <Int32>(); searchCriteria.FactorIds.Add(factorId); Boolean getOnlyPublicFactors = !IsUserAuthorizedToReadNonPublicFactors(userContext); // Get cached factor trees factorTrees = GetFactorTrees(userContext.Locale, getOnlyPublicFactors); factorTreeNode = GetFactorTreeNode(userContext.Locale, factorId, getOnlyPublicFactors); if (factorTrees.IsNull()) { // Get factor trees based on user role and rights (get public factors or all factors) factorTrees = base.GetFactorTrees(userContext); // Store factor trees in cache SetFactorTrees(factorTrees, userContext.Locale, getOnlyPublicFactors); foreach (IFactorTreeNode node in factorTrees) { if (!factorTreeNodes.ContainsKey(node.Id)) { factorTreeNodes.Add(node.Id, node); } AddFactorTreeChildren(factorTreeNodes, node.Children); } // Store factor tree nodes in cache SetFactorTreeNodes(factorTreeNodes, userContext.Locale, getOnlyPublicFactors); } if (factorTrees.IsNotNull()) { foreach (var factorTree in factorTrees) { if (factorTree.Id == factorId) { factorTreeNode = factorTree; break; } } } if (factorTreeNode.IsNull() && factorTreeNodes.IsNotNull()) { foreach (var factorTree in factorTreeNodes) { if (factorTree.Key == factorId) { factorTreeNode = factorTree.Value; break; } } } return(factorTreeNode); }