示例#1
0
 /// <summary>
 /// This method will return the taxonomy hierarchy either for the practice group term set or for client term sets
 /// </summary>
 /// <typeparam name="T">The return type from this class</typeparam>
 /// <param name="clientContext">The sharepoint client context</param>
 /// <param name="termStoreDetails">The term store deatils that client has passed to we apiu</param>
 /// <param name="generalSettings">The general settings config values</param>
 /// <param name="taxonomySettings">The taxonomy settings config values</param>
 /// <returns></returns>
 public TaxonomyResponseVM GetTaxonomyHierarchy(Client client, TermStoreDetails termStoreDetails)
 {
     try
     {
         using (clientContext = spoAuthorization.GetClientContext(client.Url))
         {
             TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
             TermStore       termStore;
             clientContext.Load(taxonomySession.TermStores);
             clientContext.ExecuteQuery();
             termStore = taxonomySession.TermStores[0];
             clientContext.Load(
                 termStore,
                 store => store.Name,
                 store => store.Groups.Include(
                     group => group.Name));
             clientContext.ExecuteQuery();
             taxonomyResponseVM = GetTaxonomyHierarchy(termStore, termStoreDetails);
         }
     }
     catch (Exception ex)
     {
         customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
         throw;
     }
     return(taxonomyResponseVM);
 }
示例#2
0
 /// <summary>
 /// Iterates through the taxonomy hierarchy for the specified term set group.
 /// </summary>
 /// <param name="clientContext">Client content for specified site</param>
 /// <param name="termStore">Term Store object</param>
 /// <param name="termStoreDetails">Term Store object containing Term store data</param>
 /// <returns>Fetch Group Terms Status</returns>
 private TaxonomyResponseVM GetTaxonomyHierarchy(TermStore termStore, TermStoreDetails termStoreDetails)
 {
     try {
         if (generalSettings.IsTenantDeployment)
         {
             foreach (TermGroup termGroup in termStore.Groups)
             {
                 if (termGroup.Name == termStoreDetails.TermGroup)
                 {
                     taxonomyResponseVM = FetchGroupTerms(termGroup, termStoreDetails);
                     break;
                 }
             }
         }
         else
         {
             TermGroup termGroup = termStore.GetSiteCollectionGroup(clientContext.Site, false);
             taxonomyResponseVM = FetchGroupTerms(termGroup, termStoreDetails);
         }
     }
     catch (Exception ex)
     {
         customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
         throw;
     }
     return(taxonomyResponseVM);
 }
示例#3
0
        /// <summary>
        /// Gets the taxonomy hierarchy.
        /// </summary>
        /// <param name="clientContext">Client object containing Client data</param>
        /// <param name="termStoreDetails">Term Store object containing Term store data</param>
        /// <returns>Fetch Group Terms Status</returns>
        internal static string GetTaxonomyHierarchy(ClientContext clientContext, TermStoreDetails termStoreDetails)
        {
            string returnFlag = ConstantStrings.FALSE;

            try
            {
                TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
                TermStore       termStore;
                clientContext.Load(taxonomySession.TermStores);
                clientContext.ExecuteQuery();
                termStore = taxonomySession.TermStores[0];
                clientContext.Load(
                    termStore,
                    store => store.Name,
                    store => store.Groups.Include(
                        group => group.Name));
                clientContext.ExecuteQuery();
                returnFlag = GetReturnFlag(clientContext, termStore, termStoreDetails);
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
            }

            return(returnFlag);
        }
示例#4
0
        /// <summary>
        /// Fetches the term store data for the term group specified
        /// </summary>
        /// <param name="clientContext">Client Context</param>
        /// <param name="termGroup">Term Group from the Term store</param>
        /// <param name="termStoreDetails">Details of the Term Group</param>
        /// <param name="returnFlagStatus">hierarchy of the Term Group</param>
        /// <returns>Hierarchy of the Term Group</returns>
        private TaxonomyResponseVM FetchGroupTerms(TermGroup termGroup,
                                                   TermStoreDetails termStoreDetails)
        {
            try
            {
                //As a first step, load Practice Group Term set and anf its child terms only and not its child child terms
                clientContext.Load(
                    termGroup,
                    group => group.Name,
                    group => group.TermSets.Include(
                        termSet => termSet.Name,
                        termSet => termSet.Id,
                        termSet => termSet.Terms.Include(
                            term => term.Name,
                            term => term.Id,
                            term => term.TermsCount,
                            term => term.CustomProperties
                            )));

                clientContext.ExecuteQuery();

                //This loop of the term set will get all the client termset and practice group term sets
                foreach (TermSet termSet in termGroup.TermSets)
                {
                    if (termSet.Name == termStoreDetails.TermSetName)
                    {
                        //This condition is if the UI is requesting practice group terms
                        if (termStoreDetails.TermSetName == taxonomySettings.PracticeGroupTermSetName)
                        {
                            taxonomyResponseVM.TermSets = GetManagedTermSetHierarchy(clientContext, termSet, termStoreDetails);
                        }
                        //This condition is if the UI is requesting client terms and the clients are defined as term set and not terms
                        else if (termStoreDetails.TermSetName == taxonomySettings.ClientTermSetName)
                        {
                            taxonomyResponseVM.ClientTermSets = GetClientTermSetHierarchy(clientContext, termSet, termStoreDetails);
                        }
                    }
                }

                //if (termStoreDetails.TermSetName == taxonomySettings.ClientTermSetName &&
                //            taxonomySettings.ClientTermPath != ServiceConstants.CLIENT_TERM_PATH)
                //{
                //    //This condition is if the UI is requesting client terms and the clients are defined as terms and not term sets
                //    foreach (TermSet termSet in termGroup.TermSets)
                //    {
                //        if (termSet.Name == taxonomySettings.ClientTermPath)
                //        {
                //            taxonomyResponseVM.ClientTermSets = GetClientTermSetHierarchy(clientContext, termSet, termStoreDetails);
                //        }
                //    }
                //}
            }
            catch (Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
            return(taxonomyResponseVM);
        }
示例#5
0
        /// <summary>
        /// Gets the taxonomy hierarchy for client term set.
        /// </summary>
        /// <param name="termSet">Term set object holding Client terms</param>
        /// <param name="termStoreDetails">Term Store object containing Term store data</param>
        /// <returns>Serialized Object of Client Term Set</returns>
        internal static string GetClientTermSetHierarchy(TermSet termSet, TermStoreDetails termStoreDetails)
        {
            string result = string.Empty;

            try
            {
                ClientTermSets tempClientTermSet = new ClientTermSets();
                tempClientTermSet.Name = termSet.Name;
                /////Retrieve the Terms - level 1
                tempClientTermSet.ClientTerms = new List <Client>();
                TermCollection termColl = termSet.Terms;
                foreach (Term term in termColl)
                {
                    Client tempTermPG = new Client();
                    tempTermPG.Name = term.Name;
                    if (term.CustomProperties.Count > 0)
                    {
                        tempTermPG.Url = string.Empty;
                        tempTermPG.Id  = string.Empty;
                        foreach (KeyValuePair <string, string> customProperty in term.CustomProperties)
                        {
                            if (customProperty.Key.Equals(termStoreDetails.CustomPropertyName, StringComparison.Ordinal))
                            {
                                tempTermPG.Url = customProperty.Value;
                            }

                            if (customProperty.Key.Equals(ServiceConstantStrings.ClientCustomPropertiesId, StringComparison.Ordinal))
                            {
                                tempTermPG.Id = customProperty.Value;
                            }
                        }
                    }

                    tempClientTermSet.ClientTerms.Add(tempTermPG);
                }
                /////Serialize the Term set (Practice Group) object to get all terms under it
                result = JsonConvert.SerializeObject(tempClientTermSet);
            }
            catch (Exception exception)
            {
                result = Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
            }
            return(result);
        }
示例#6
0
        /// <summary>
        /// This method will get all client term properties such as ID and URL
        /// </summary>
        /// <param name="termColl">The taxonomy client terms</param>
        /// <param name="termStoreDetails">The term store details which the UI has sent to the clients</param>
        /// <param name="clientTermSet">The ClientTermSets object to which all the client terms are added</param>
        /// <returns></returns>
        private ClientTermSets GetClientTermProperties(TermCollection termColl, TermStoreDetails termStoreDetails, ClientTermSets clientTermSet)
        {
            try
            {
                foreach (Term term in termColl)
                {
                    Client tempTermPG = new Client();
                    tempTermPG.Name = term.Name;
                    if (term.CustomProperties.Count > 0)
                    {
                        tempTermPG.Url = string.Empty;
                        tempTermPG.Id  = string.Empty;
                        foreach (KeyValuePair <string, string> customProperty in term.CustomProperties)
                        {
                            if (customProperty.Key.Equals(termStoreDetails.CustomPropertyName, StringComparison.Ordinal))
                            {
                                tempTermPG.Url = customProperty.Value;
                            }

                            if (customProperty.Key.Equals(taxonomySettings.ClientCustomPropertiesId, StringComparison.Ordinal))
                            {
                                tempTermPG.Id = customProperty.Value;
                            }
                        }
                    }
                    if (!string.IsNullOrWhiteSpace(tempTermPG.Id) && !string.IsNullOrWhiteSpace(tempTermPG.Url))
                    {
                        clientTermSet.ClientTerms.Add(tempTermPG);
                    }
                }
                return(clientTermSet);
            }
            catch (Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
        }
示例#7
0
        /// <summary>
        /// This method will be called if the clients are defined as term set and not as terms
        /// </summary>
        /// <param name="termSet">Term set object holding Client terms</param>
        /// <param name="termStoreDetails">Term Store object containing Term store data</param>
        /// <returns>Serialized Object of Client Term Set</returns>
        private ClientTermSets GetClientTermSetHierarchy(ClientContext clientContext, TermSet termSet, TermStoreDetails termStoreDetails)
        {
            ClientTermSets tempClientTermSet = new ClientTermSets();

            try
            {
                tempClientTermSet.Name = taxonomySettings.ClientTermSetName;
                /////Retrieve the Terms - level 1
                tempClientTermSet.ClientTerms = new List <Client>();
                TermCollection termColl = null;
                termColl = termSet.Terms;
                return(GetClientTermProperties(termColl, termStoreDetails, tempClientTermSet));
            }
            catch (Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name,
                                      MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
        }
示例#8
0
        /// <summary>
        /// This method will update the taxonomy hierarchy object with custom properties that needs to be send to client. This is a recursive function
        /// and it will loop until a term does not have any child terms
        /// </summary>
        /// <param name="termCollection">The Term Collection object to which terms will be added</param>
        /// <param name="termStoreDetails">The term store details which the client has sent</param>
        /// <param name="parentTerm">The parent term from where the custom properties are read and assign to its child terms</param>
        /// <returns></returns>
        private void GetChildTermsWithCustomProperties(TermCollection termCollection,
                                                       TermStoreDetails termStoreDetails, Term parentTerm, JsonWriter jw, string siteColumnName, int termLevelHierarchyPosition)
        {
            try
            {
                //var subAreaTerms = new List<SubareaTerm>();
                foreach (Term term in termCollection)
                {
                    if (term.Name != taxonomySettings.ClientTermSetName)
                    {
                        jw.WriteStartObject();
                        jw.WritePropertyName("termName");
                        jw.WriteValue(term.Name);
                        jw.WritePropertyName("id");
                        jw.WriteValue(Convert.ToString(term.Id, CultureInfo.InvariantCulture));
                        jw.WritePropertyName("parentTermName");
                        jw.WriteValue(parentTerm.Name);
                        jw.WritePropertyName("siteColumnName");
                        jw.WriteValue(siteColumnName);
                        IDictionary <string, string> childCustomProperties  = term.CustomProperties;
                        IDictionary <string, string> parentCustomProperties = parentTerm.CustomProperties;
                        foreach (KeyValuePair <string, string> parentProperty in parentTerm.CustomProperties)
                        {
                            //if the key is present in the parent and not in the child, add that key value to the child custom properties
                            if (!childCustomProperties.Keys.Contains(parentProperty.Key))
                            {
                                if (parentProperty.Key.Equals(termStoreDetails.CustomPropertyName, StringComparison.Ordinal))
                                {
                                    childCustomProperties.Add(parentProperty.Key, parentProperty.Value);
                                }
                                else if (parentProperty.Key.Equals(taxonomySettings.SubAreaOfLawDocumentTemplates, StringComparison.Ordinal))
                                {
                                    childCustomProperties.Add(parentProperty.Key, parentProperty.Value);
                                }
                                else if (parentProperty.Key.Equals(taxonomySettings.MatterProvisionExtraPropertiesContentType, StringComparison.Ordinal))
                                {
                                    childCustomProperties.Add(parentProperty.Key, parentProperty.Value);
                                }
                                else
                                {
                                    childCustomProperties.Add(parentProperty.Key, parentProperty.Value);
                                }
                            }

                            //If the key is present in both and parent and child and if child value is empty and the parent value is not empty,
                            //update the child value with the parent value for the same key
                            if (childCustomProperties.Keys.Contains(parentProperty.Key) && childCustomProperties[parentProperty.Key] == string.Empty)
                            {
                                childCustomProperties[parentProperty.Key] = parentProperty.Value;
                            }
                        }

                        //Add the custom properties to the subAreaTerms list collection
                        foreach (KeyValuePair <string, string> customProperty in childCustomProperties)
                        {
                            if (customProperty.Key.Equals(taxonomySettings.MatterProvisionExtraPropertiesContentType, StringComparison.Ordinal))
                            {
                                jw.WritePropertyName("MatterProvisionExtraPropertiesContentType");
                                jw.WriteValue(customProperty.Value);
                            }

                            if (customProperty.Key.Equals(termStoreDetails.CustomPropertyName, StringComparison.Ordinal))
                            {
                                jw.WritePropertyName("documentTemplates");
                                jw.WriteValue(customProperty.Value);
                            }
                            else if (customProperty.Key.Equals(taxonomySettings.SubAreaCustomPropertyFolderNames, StringComparison.Ordinal))
                            {
                                jw.WritePropertyName("folderNames");
                                jw.WriteValue(customProperty.Value);
                            }
                            else if (customProperty.Key.Equals(taxonomySettings.SubAreaCustomPropertyisNoFolderStructurePresent, StringComparison.Ordinal))
                            {
                                jw.WritePropertyName("isNoFolderStructurePresent");
                                if (generalSettings.IsBackwardCompatible)
                                {
                                    if (customProperty.Value.ToLower() == ServiceConstants.IS_FOLDER_STRUCTURE_PRESENT_FALSE.ToLower())
                                    {
                                        jw.WriteValue(ServiceConstants.IS_FOLDER_STRUCTURE_PRESENT_TRUE);
                                    }
                                    else if (customProperty.Value.ToLower() == ServiceConstants.IS_FOLDER_STRUCTURE_PRESENT_TRUE.ToLower())
                                    {
                                        jw.WriteValue(ServiceConstants.IS_FOLDER_STRUCTURE_PRESENT_FALSE);
                                    }
                                }
                                else
                                {
                                    jw.WriteValue(customProperty.Value);
                                }
                            }
                            else if (customProperty.Key.Equals(taxonomySettings.SubAreaOfLawDocumentTemplates, StringComparison.Ordinal))
                            {
                                jw.WritePropertyName("documentTemplateNames");
                                jw.WriteValue(customProperty.Value);
                            }
                        }
                        //Increment the level
                        level = level + 1;
                        //Check if we need to get more terms.
                        if (level <= taxonomySettings.Levels)
                        {
                            if (term.TermsCount > 0)
                            {
                                if (level == 4)
                                {
                                    jw.WritePropertyName(taxonomySettings.Level4Name);
                                }
                                //The app will support upto five level of hierarchy
                                if (level == 5)
                                {
                                    jw.WritePropertyName(taxonomySettings.Level5Name);
                                }
                                jw.WriteStartArray();
                                TermCollection termCollLevel4 = term.LoadTerms(clientContext);
                                siteColumnName = configuration.GetSection("ContentTypes").GetSection("ManagedColumns")["ColumnName" + level];
                                //Recursive function which will call it self until a given term does not have any child terms
                                GetChildTermsWithCustomProperties(termCollLevel4, termStoreDetails, term, jw, siteColumnName, termLevelHierarchyPosition);
                                jw.WriteEndArray();
                            }
                        }
                        jw.WriteEndObject();
                    }
                }
            }
            catch (Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
        }
示例#9
0
        /// <summary>
        /// Gets the managed term set hierarchy with generic code using JSONWriter
        /// </summary>
        /// <param name="termSet">Term set object holding Practice Group terms</param>
        /// <param name="termStoreDetails">Term Store object containing Term store data</param>
        /// <returns>Serialized Object of Term Set</returns>
        private string GetManagedTermSetHierarchy(ClientContext clientContext, TermSet termSet, TermStoreDetails termStoreDetails)
        {
            level = 3;
            StringBuilder sb = new StringBuilder();
            JsonWriter    jw = new JsonTextWriter(new StringWriter(sb));

            jw.Formatting = Formatting.Indented;
            jw.WriteStartObject();
            jw.WritePropertyName("name");
            jw.WriteValue(termSet.Name);
            jw.WritePropertyName("levels");
            jw.WriteValue(taxonomySettings.Levels);
            jw.WritePropertyName(taxonomySettings.Level1Name);
            jw.WriteStartArray();
            TermCollection termColl = termSet.Terms;

            foreach (Term term in termColl)
            {
                jw.WriteStartObject();
                //Create level1 terms - Practice Groups
                jw.WritePropertyName("termName");
                jw.WriteValue(term.Name);
                jw.WritePropertyName("id");
                jw.WriteValue(Convert.ToString(term.Id, CultureInfo.InvariantCulture));
                jw.WritePropertyName("parentTermName");
                jw.WriteValue(termSet.Name);
                jw.WritePropertyName("siteColumnName");
                jw.WriteValue(configuration.GetSection("ContentTypes").GetSection("ManagedColumns")["ColumnName1"]);
                foreach (KeyValuePair <string, string> customProperty in term.CustomProperties)
                {
                    if (customProperty.Key.Equals(taxonomySettings.PracticeGroupCustomPropertyFolderNames, StringComparison.Ordinal))
                    {
                        jw.WritePropertyName("folderNames");
                        jw.WriteValue(customProperty.Value);
                    }
                }
                //Create level 2 terms - Area Of Law
                jw.WritePropertyName(taxonomySettings.Level2Name);
                if (term.TermsCount > 0)
                {
                    jw.WriteStartArray();
                    TermCollection termCollLevel2 = term.LoadTerms(clientContext);
                    foreach (Term termLevel2 in termCollLevel2)
                    {
                        if (termLevel2.Name != taxonomySettings.ClientTermSetName)
                        {
                            jw.WriteStartObject();
                            jw.WritePropertyName("termName");
                            jw.WriteValue(termLevel2.Name);
                            jw.WritePropertyName("id");
                            jw.WriteValue(Convert.ToString(termLevel2.Id, CultureInfo.InvariantCulture));
                            jw.WritePropertyName("parentTermName");
                            jw.WriteValue(term.Name);
                            jw.WritePropertyName("siteColumnName");
                            jw.WriteValue(configuration.GetSection("ContentTypes").GetSection("ManagedColumns")["ColumnName2"]);
                            foreach (KeyValuePair <string, string> customProperty in term.CustomProperties)
                            {
                                if (customProperty.Key.Equals(taxonomySettings.PracticeGroupCustomPropertyFolderNames, StringComparison.Ordinal))
                                {
                                    jw.WritePropertyName("folderNames");
                                    jw.WriteValue(customProperty.Value);
                                }
                            }
                            //If the number of levels that are configured are more than 2, try to get the
                            //3rd level hierarchy
                            if (taxonomySettings.Levels > 2)
                            {
                                //Create level 3 terms - Sub Area Of LAW
                                if (termLevel2.TermsCount > 0)
                                {
                                    jw.WritePropertyName(taxonomySettings.Level3Name);
                                    jw.WriteStartArray();
                                    TermCollection termCollLevel3             = termLevel2.LoadTerms(clientContext);
                                    string         siteColumnName             = configuration.GetSection("ContentTypes").GetSection("ManagedColumns")["ColumnName3"];
                                    int            termLevelHierarchyPosition = 0;
                                    GetChildTermsWithCustomProperties(termCollLevel3, termStoreDetails, termLevel2, jw,
                                                                      siteColumnName, termLevelHierarchyPosition);
                                    jw.WriteEndArray();
                                }
                                jw.WriteEndObject();
                            }
                        }
                    }
                    jw.WriteEndArray();
                }
                jw.WriteEndObject();
            }
            jw.WriteEndArray();
            jw.WriteEndObject();
            return(sb.ToString());
        }
示例#10
0
        /// <summary>
        /// Fetches the term store data for the term group specified
        /// </summary>
        /// <param name="clientContext">Client Context</param>
        /// <param name="termGroup">Term Group from the Term store</param>
        /// <param name="termStoreDetails">Details of the Term Group</param>
        /// <param name="returnFlagStatus">hierarchy of the Term Group</param>
        /// <returns>Hierarchy of the Term Group</returns>
        internal static string FetchGroupTerms(ClientContext clientContext, TermGroup termGroup, TermStoreDetails termStoreDetails, string returnFlagStatus)
        {
            clientContext.Load(
                termGroup,
                group => group.Name,
                group => group.TermSets.Include(
                    termSet => termSet.Name,
                    termSet => termSet.Id,
                    termSet => termSet.Terms.Include(
                        term => term.Name,
                        term => term.Id,
                        term => term.CustomProperties,
                        term => term.Terms.Include(
                            termArea => termArea.Name,
                            termArea => termArea.Id,
                            termArea => termArea.CustomProperties,
                            termArea => termArea.Terms.Include(
                                termSubArea => termSubArea.Name,
                                termSubArea => termSubArea.Id,
                                termSubArea => termSubArea.CustomProperties)))));

            clientContext.ExecuteQuery();
            foreach (TermSet termSet in termGroup.TermSets)
            {
                if (termSet.Name == termStoreDetails.TermSetName)
                {
                    if (termStoreDetails.TermSetName == ServiceConstantStrings.PracticeGroupTermSetName)
                    {
                        returnFlagStatus = GetPracticeGroupTermSetHierarchy(termSet, termStoreDetails);
                    }
                    else if (termStoreDetails.TermSetName == ServiceConstantStrings.ClientTermSetName)
                    {
                        returnFlagStatus = GetClientTermSetHierarchy(termSet, termStoreDetails);
                    }
                }
            }

            return(returnFlagStatus);
        }
示例#11
0
        /// <summary>
        /// Gets the practice group term set hierarchy.
        /// </summary>
        /// <param name="termSet">Term set object holding Practice Group terms</param>
        /// <param name="termStoreDetails">Term Store object containing Term store data</param>
        /// <returns>Serialized Object of Term Set</returns>
        internal static string GetPracticeGroupTermSetHierarchy(TermSet termSet, TermStoreDetails termStoreDetails)
        {
            string result = string.Empty;

            try
            {
                TermSets tempTermSet = new TermSets();
                tempTermSet.Name = termSet.Name;
                ////Retrieve the Terms - level 1
                tempTermSet.PGTerms = new List <PracticeGroupTerm>();
                TermCollection termColl = termSet.Terms;
                foreach (Term term in termColl)
                {
                    PracticeGroupTerm tempTermPG = new PracticeGroupTerm();
                    tempTermPG.TermName       = term.Name;
                    tempTermPG.Id             = Convert.ToString(term.Id, CultureInfo.InvariantCulture);
                    tempTermPG.ParentTermName = termSet.Name;
                    /////Retrieve the custom property for Terms at level 1
                    foreach (KeyValuePair <string, string> customProperty in term.CustomProperties)
                    {
                        if (customProperty.Key.Equals(ServiceConstantStrings.PracticeGroupCustomPropertyFolderNames, StringComparison.Ordinal))
                        {
                            tempTermPG.FolderNames = customProperty.Value;
                        }
                    }

                    tempTermSet.PGTerms.Add(tempTermPG);
                    ///// Retrieve the Terms - level 2
                    tempTermPG.AreaTerms = new List <AreaTerm>();
                    TermCollection termCollArea = term.Terms;
                    foreach (Term termArea in termCollArea)
                    {
                        AreaTerm tempTermArea = new AreaTerm();
                        tempTermArea.TermName       = termArea.Name;
                        tempTermArea.Id             = Convert.ToString(termArea.Id, CultureInfo.InvariantCulture);
                        tempTermArea.ParentTermName = term.Name;
                        /////Retrieve the custom property for Terms at level 2
                        foreach (KeyValuePair <string, string> customProperty in termArea.CustomProperties)
                        {
                            if (customProperty.Key.Equals(ServiceConstantStrings.AreaCustomPropertyFolderNames, StringComparison.Ordinal))
                            {
                                tempTermArea.FolderNames = customProperty.Value;
                            }
                        }

                        tempTermPG.AreaTerms.Add(tempTermArea);
                        /////Retrieve the Terms - level 3
                        tempTermArea.SubareaTerms = new List <SubareaTerm>();
                        TermCollection termCollSubArea = termArea.Terms;
                        foreach (Term termSubArea in termCollSubArea)
                        {
                            SubareaTerm tempTermSubArea = new SubareaTerm();
                            tempTermSubArea.TermName       = termSubArea.Name;
                            tempTermSubArea.Id             = Convert.ToString(termSubArea.Id, CultureInfo.InvariantCulture);
                            tempTermSubArea.ParentTermName = termArea.Name;
                            /////Retrieve the custom property for Terms at level 3

                            tempTermSubArea.DocumentTemplates = string.Empty;
                            foreach (KeyValuePair <string, string> customProperty in termSubArea.CustomProperties)
                            {
                                if (customProperty.Key.Equals(termStoreDetails.CustomPropertyName, StringComparison.Ordinal))
                                {
                                    tempTermSubArea.DocumentTemplates = customProperty.Value;
                                }
                                else if (customProperty.Key.Equals(ServiceConstantStrings.SubAreaCustomPropertyFolderNames, StringComparison.Ordinal))
                                {
                                    tempTermSubArea.FolderNames = customProperty.Value;
                                }
                                else if (customProperty.Key.Equals(ServiceConstantStrings.SubAreaCustomPropertyisNoFolderStructurePresent, StringComparison.Ordinal))
                                {
                                    tempTermSubArea.IsNoFolderStructurePresent = customProperty.Value;
                                }
                                else if (customProperty.Key.Equals(ServiceConstantStrings.SubAreaOfLawDocumentTemplates, StringComparison.Ordinal))
                                {
                                    tempTermSubArea.DocumentTemplateNames = customProperty.Value;
                                }
                            }

                            tempTermArea.SubareaTerms.Add(tempTermSubArea);
                        }
                    }
                }
                /////Serialize the Term set (Practice Group) object to get all terms under it and return it
                result = JsonConvert.SerializeObject(tempTermSet);
            }
            catch (Exception exception)
            {
                result = Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
            }
            return(result);
        }
示例#12
0
        /// <summary>
        /// Iterates through the taxonomy hierarchy for the specified term set group.
        /// </summary>
        /// <param name="clientContext">Client content for specified site</param>
        /// <param name="termStore">Term Store object</param>
        /// <param name="termStoreDetails">Term Store object containing Term store data</param>
        /// <returns>Fetch Group Terms Status</returns>
        internal static string GetReturnFlag(ClientContext clientContext, TermStore termStore, TermStoreDetails termStoreDetails)
        {
            string returnFlagStatus = ConstantStrings.FALSE;

            if (ServiceConstantStrings.IsTenantDeployment)
            {
                foreach (TermGroup termGroup in termStore.Groups)
                {
                    if (termGroup.Name == termStoreDetails.TermGroup)
                    {
                        returnFlagStatus = FetchGroupTerms(clientContext, termGroup, termStoreDetails, returnFlagStatus);
                    }
                }
            }
            else
            {
                TermGroup termGroup = termStore.GetSiteCollectionGroup(clientContext.Site, false);
                returnFlagStatus = FetchGroupTerms(clientContext, termGroup, termStoreDetails, returnFlagStatus);
            }

            // Returns the taxonomy hierarchy for the specified term set group
            return(returnFlagStatus);
        }