This class contains term set members
Esempio n. 1
0
        /// <summary>
        /// Extract term store groups
        /// </summary>
        /// <param name="configVal">Configuration values from excel</param>
        /// <returns>Term sets</returns>
        internal static TermSets FetchGroupTerms(Dictionary <string, string> configVal)
        {
            TermStoreDetails termStoreDetails = new TermStoreDetails();

            termStoreDetails.TermSetName        = ConfigurationManager.AppSettings["PracticeGroupTermSetName"];
            termStoreDetails.CustomPropertyName = ConfigurationManager.AppSettings["CustomPropertyName"];
            termStoreDetails.TermGroup          = ConfigurationManager.AppSettings["PracticeGroupName"];
            TermSets practiceGroupTermSets = null;

            using (ClientContext clientContext = MatterProvisionHelperUtility.GetClientContext(configVal["TenantAdminURL"], configVal))
            {
                TaxonomySession taxanomySession = TaxonomySession.GetTaxonomySession(clientContext);
                clientContext.Load(taxanomySession,
                                   items => items.TermStores.Include(
                                       item => item.Groups,
                                       item => item.Groups.Include(
                                           group => group.Name)));
                clientContext.ExecuteQuery();
                TermGroup termGroup = taxanomySession.TermStores[0].Groups.GetByName(termStoreDetails.TermGroup);
                clientContext.Load(termGroup,
                                   group => group.Name,
                                   group => group.TermSets.Include(
                                       termSet => termSet.Name,
                                       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.Equals(termStoreDetails.TermSetName, StringComparison.OrdinalIgnoreCase))
                    {
                        if (termStoreDetails.TermSetName.Equals(termStoreDetails.TermSetName, StringComparison.OrdinalIgnoreCase))
                        {
                            practiceGroupTermSets = TermStoreOperations.GetPracticeGroupTermSetHierarchy(termSet, termStoreDetails.CustomPropertyName);
                        }
                    }
                }

                return(practiceGroupTermSets);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Method to associate
 /// </summary>
 /// <param name="listval">Value of list</param>
 /// <param name="terms">Termsets object</param>
 /// <param name="matterMetadata">Matter meta data</param>
 /// <param name="count">Integer count</param>
 /// <param name="practiceGroupsList">List of practice groups</param>
 /// <param name="areaOfLawsList">List of area of laws</param>
 /// <param name="subAreaOfLawsList">List of sub area of law</param>
 /// <param name="folders">Folder name</param>
 /// <param name="documentTemplate">Template of document</param>
 /// <param name="flag">Boolean flag</param>
 private static void AssociateTermStoreProperties(List <DataStorage> listval, TermSets terms, MatterMetadata matterMetadata, int count, List <string> practiceGroupsList, List <string> areaOfLawsList, List <string> subAreaOfLawsList, ref string folders, ref string documentTemplate, ref bool flag)
 {
     foreach (PracticeGroupTerm practiceGroup in terms.PGTerms)
     {
         foreach (AreaTerm areaTerm in practiceGroup.AreaTerms)
         {
             foreach (SubareaTerm subAreaTerm in areaTerm.SubareaTerms)
             {
                 if (subAreaOfLawsList.Contains(subAreaTerm.TermName, StringComparer.OrdinalIgnoreCase) && areaOfLawsList.Contains(areaTerm.TermName, StringComparer.OrdinalIgnoreCase) && practiceGroupsList.Contains(practiceGroup.TermName, StringComparer.OrdinalIgnoreCase))
                 {
                     if (Convert.ToBoolean(subAreaTerm.IsNoFolderStructurePresent, CultureInfo.InvariantCulture))
                     {
                         folders = string.IsNullOrWhiteSpace(areaTerm.FolderNames) ? practiceGroup.FolderNames : areaTerm.FolderNames;
                     }
                     else
                     {
                         folders = subAreaTerm.FolderNames;
                     }
                     documentTemplate = subAreaTerm.ContentTypeName + ";" + subAreaTerm.DocumentTemplates;
                     listval[count].DefaultContentType = subAreaTerm.ContentTypeName;
                     // Setting metadata properties for the Matter
                     matterMetadata.PracticeGroupTerm = practiceGroup;
                     matterMetadata.AreaTerm          = areaTerm;
                     matterMetadata.SubareaTerm       = subAreaTerm;
                     if (!string.IsNullOrWhiteSpace(subAreaTerm.DocumentTemplates))
                     {
                         listval[count].DocumentCount = Convert.ToString(subAreaTerm.DocumentTemplates.Split(';').Count(), CultureInfo.InvariantCulture);
                     }
                     else
                     {
                         listval[count].DocumentCount = Constants.ZERO_DOCUMENT_COUNT;
                     }
                     flag = true;
                     break;
                 }
             }
             if (flag)
             {
                 break;
             }
         }
         if (flag)
         {
             break;
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Method to associate 
 /// </summary>
 /// <param name="listval">Value of list</param>
 /// <param name="terms">Termsets object</param>
 /// <param name="matterMetadata">Matter meta data</param>
 /// <param name="count">Integer count</param>
 /// <param name="practiceGroupsList">List of practice groups</param>
 /// <param name="areaOfLawsList">List of area of laws</param>
 /// <param name="subAreaOfLawsList">List of sub area of law</param>
 /// <param name="folders">Folder name</param>
 /// <param name="documentTemplate">Template of document</param>
 /// <param name="flag">Boolean flag</param>
 private static void AssociateTermStoreProperties(List<DataStorage> listval, TermSets terms, MatterMetadata matterMetadata, int count, List<string> practiceGroupsList, List<string> areaOfLawsList, List<string> subAreaOfLawsList, ref string folders, ref string documentTemplate, ref bool flag)
 {
     foreach (PracticeGroupTerm practiceGroup in terms.PGTerms)
     {
         foreach (AreaTerm areaTerm in practiceGroup.AreaTerms)
         {
             foreach (SubareaTerm subAreaTerm in areaTerm.SubareaTerms)
             {
                 if (subAreaOfLawsList.Contains(subAreaTerm.TermName, StringComparer.OrdinalIgnoreCase) && areaOfLawsList.Contains(areaTerm.TermName, StringComparer.OrdinalIgnoreCase) && practiceGroupsList.Contains(practiceGroup.TermName, StringComparer.OrdinalIgnoreCase))
                 {
                     if (Convert.ToBoolean(subAreaTerm.IsNoFolderStructurePresent, CultureInfo.InvariantCulture))
                     {
                         folders = string.IsNullOrWhiteSpace(areaTerm.FolderNames) ? practiceGroup.FolderNames : areaTerm.FolderNames;
                     }
                     else
                     {
                         folders = subAreaTerm.FolderNames;
                     }
                     documentTemplate = subAreaTerm.ContentTypeName + ";" + subAreaTerm.DocumentTemplates;
                     listval[count].DefaultContentType = subAreaTerm.ContentTypeName;
                     // Setting metadata properties for the Matter
                     matterMetadata.PracticeGroupTerm = practiceGroup;
                     matterMetadata.AreaTerm = areaTerm;
                     matterMetadata.SubareaTerm = subAreaTerm;
                     if (!string.IsNullOrWhiteSpace(subAreaTerm.DocumentTemplates))
                     {
                         listval[count].DocumentCount = Convert.ToString(subAreaTerm.DocumentTemplates.Split(';').Count(), CultureInfo.InvariantCulture);
                     }
                     else
                     {
                         listval[count].DocumentCount = Constants.ZERO_DOCUMENT_COUNT;
                     }
                     flag = true;
                     break;
                 }
             }
             if (flag)
             {
                 break;
             }
         }
         if (flag)
         {
             break;
         }
     }
 }
        /// <summary>
        /// Load practice group term set from term store 
        /// </summary>
        /// <param name="termSet">Term set containing term set data</param>
        /// <param name="customPropertyName">Custom property name</param>
        /// <returns>Term sets</returns>
        internal static TermSets GetPracticeGroupTermSetHierarchy(TermSet termSet, string customPropertyName)
        {
            TermSets tempTermSet = new TermSets();
            string practiceGroupCustomPropertyFolderNames = ConfigurationManager.AppSettings["PracticeGroupCustomPropertyFolderNames"];
            string areaCustomPropertyFolderNames = ConfigurationManager.AppSettings["AreaCustomPropertyFolderNames"];
            string subAreaCustomPropertyFolderNames = ConfigurationManager.AppSettings["SubAreaCustomPropertyFolderNames"];
            string subAreaCustomPropertyisNoFolderStructurePresent = ConfigurationManager.AppSettings["SubAreaCustomPropertyisNoFolderStructurePresent"];
            string subAreaOfLawDocumentTemplates = ConfigurationManager.AppSettings["SubAreaOfLawDocumentTemplates"];

            try
            {
                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)
                    {
                        tempTermPG.FolderNames = (customProperty.Key.Equals(practiceGroupCustomPropertyFolderNames, StringComparison.OrdinalIgnoreCase)) ? customProperty.Value : string.Empty;
                    }
                    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)
                        {
                            tempTermArea.FolderNames = (customProperty.Key.Equals(areaCustomPropertyFolderNames, StringComparison.OrdinalIgnoreCase)) ? customProperty.Value : string.Empty;
                        }
                        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(customPropertyName, StringComparison.OrdinalIgnoreCase))
                                {
                                    tempTermSubArea.ContentTypeName = customProperty.Value;
                                }
                                else if (customProperty.Key.Equals(subAreaCustomPropertyFolderNames, StringComparison.OrdinalIgnoreCase))
                                {
                                    tempTermSubArea.FolderNames = customProperty.Value;
                                }
                                else if (customProperty.Key.Equals(subAreaCustomPropertyisNoFolderStructurePresent, StringComparison.OrdinalIgnoreCase))
                                {
                                    tempTermSubArea.IsNoFolderStructurePresent = customProperty.Value;
                                }
                                else if (customProperty.Key.Equals(subAreaOfLawDocumentTemplates, StringComparison.OrdinalIgnoreCase))
                                {
                                    tempTermSubArea.DocumentTemplates = customProperty.Value;
                                }
                            }
                            tempTermArea.SubareaTerms.Add(tempTermSubArea);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                DisplayAndLogError(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
                tempTermSet = null;
            }
            return tempTermSet;
        }
Esempio n. 5
0
        /// <summary>
        /// Load practice group term set from term store
        /// </summary>
        /// <param name="termSet">Term set containing term set data</param>
        /// <param name="customPropertyName">Custom property name</param>
        /// <returns>Term sets</returns>
        internal static TermSets GetPracticeGroupTermSetHierarchy(TermSet termSet, string customPropertyName)
        {
            TermSets tempTermSet = new TermSets();
            string   practiceGroupCustomPropertyFolderNames          = ConfigurationManager.AppSettings["PracticeGroupCustomPropertyFolderNames"];
            string   areaCustomPropertyFolderNames                   = ConfigurationManager.AppSettings["AreaCustomPropertyFolderNames"];
            string   subAreaCustomPropertyFolderNames                = ConfigurationManager.AppSettings["SubAreaCustomPropertyFolderNames"];
            string   subAreaCustomPropertyisNoFolderStructurePresent = ConfigurationManager.AppSettings["SubAreaCustomPropertyisNoFolderStructurePresent"];
            string   subAreaOfLawDocumentTemplates                   = ConfigurationManager.AppSettings["SubAreaOfLawDocumentTemplates"];

            try
            {
                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)
                    {
                        tempTermPG.FolderNames = (customProperty.Key.Equals(practiceGroupCustomPropertyFolderNames, StringComparison.OrdinalIgnoreCase)) ? customProperty.Value : string.Empty;
                    }
                    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)
                        {
                            tempTermArea.FolderNames = customProperty.Key.Equals(areaCustomPropertyFolderNames, StringComparison.OrdinalIgnoreCase) ? customProperty.Value : string.Empty;
                        }
                        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(customPropertyName, StringComparison.OrdinalIgnoreCase))
                                {
                                    tempTermSubArea.ContentTypeName = customProperty.Value;
                                }
                                else if (customProperty.Key.Equals(subAreaCustomPropertyFolderNames, StringComparison.OrdinalIgnoreCase))
                                {
                                    tempTermSubArea.FolderNames = customProperty.Value;
                                }
                                else if (customProperty.Key.Equals(subAreaCustomPropertyisNoFolderStructurePresent, StringComparison.OrdinalIgnoreCase))
                                {
                                    tempTermSubArea.IsNoFolderStructurePresent = customProperty.Value;
                                }
                                else if (customProperty.Key.Equals(subAreaOfLawDocumentTemplates, StringComparison.OrdinalIgnoreCase))
                                {
                                    tempTermSubArea.DocumentTemplates = customProperty.Value;
                                }
                            }
                            tempTermArea.SubareaTerms.Add(tempTermSubArea);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Utility.DisplayAndLogError(Utility.ErrorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
                tempTermSet = null;
            }
            return(tempTermSet);
        }
Esempio n. 6
0
        /// <summary>
        /// Creates sample data based on the information provided
        /// </summary>
        /// <param name="listval">Matter details collection</param>
        /// <param name="clientDetails">Client details collection</param>
        /// <param name="configVal">Config values from Excel</param>
        internal static void CreateData(List <DataStorage> listval, ClientTermSets clientDetails, Dictionary <string, string> configVal)
        {
            try
            {
                int   successMatterNameCount = 0, alreadyExistsMatterCount = 0;
                Regex validateMatterId    = new Regex(ConfigurationManager.AppSettings["SpecialCharacterExpressionMatterId"]),
                      validateMatterTitle = new Regex(ConfigurationManager.AppSettings["SpecialCharacterExpressionMatterTitle"]),
                      validateMatterDesc  = new Regex(ConfigurationManager.AppSettings["SpecialCharacterExpressionMatterDescription"]);
                //Read data from term store
                TermSets terms = TermStoreOperations.FetchGroupTerms(configVal);
                if (null == terms)
                {
                    Utility.DisplayAndLogError(errorFilePath, "Failed to get Group Terms, skipping matter creation.");
                    return;
                }
                else
                {
                    MatterMetadata matterMetadata = new MatterMetadata();
                    //retrieve data from the list
                    for (int count = 0; count < listval.Count; count++)
                    {
                        string clientName = listval[count].ClientName;
                        /* Read from Term store */
                        Client client = clientDetails.ClientTerms.Where(item => item.ClientName.Equals(clientName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                        if (null == client)
                        {
                            Console.WriteLine("Failed to get client Id and/or client Url from term store for '{0}' client.", clientName);
                            Console.WriteLine("-------------------------------------------------------------------------------");
                            continue;
                        }

                        List <string> practiceGroupsList = Utility.ProcessString(listval[count].PracticeGroup).Split(';').ToList();
                        List <string> areaOfLawsList     = Utility.ProcessString(listval[count].AreaOfLaw).Split(';').ToList();
                        List <string> subAreaOfLawsList  = Utility.ProcessString(listval[count].SubAreaOfLaw).Split(';').ToList();

                        string folders          = string.Empty;
                        string documentTemplate = string.Empty;
                        bool   flag             = false;

                        AssociateTermStoreProperties(listval, terms, matterMetadata, count, practiceGroupsList, areaOfLawsList, subAreaOfLawsList, ref folders, ref documentTemplate, ref flag);
                        if (string.IsNullOrWhiteSpace(documentTemplate) || string.IsNullOrWhiteSpace(listval[count].DefaultContentType))
                        {
                            Console.WriteLine("Skipping matter creation as no matching document templates exists in term store corresponding to entry for '{0}' in the configuration Excel", client.ClientName);
                            Console.WriteLine("-------------------------------------------------------------------------------");
                            continue;
                        }

                        string[] contentTypes = documentTemplate.Split(';');
                        Matter   matterObj    = new Matter(listval[count]);
                        Console.WriteLine("Client details fetched");
                        Console.WriteLine("Client name: {0}", clientName);

                        using (ClientContext clientContext = MatterProvisionHelperUtility.GetClientContext(client.ClientUrl, configVal))
                        {
                            CheckMatterCreationStatus(configVal, ref successMatterNameCount, ref alreadyExistsMatterCount, validateMatterId, validateMatterTitle, validateMatterDesc, matterMetadata, clientName, client, folders, contentTypes, matterObj, clientContext);
                        }
                    }  // end of for

                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine(ConfigurationManager.AppSettings["MatterSuccess"], successMatterNameCount, listval.Count);
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine(ConfigurationManager.AppSettings["MatterFound"], alreadyExistsMatterCount);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(ConfigurationManager.AppSettings["MatterFailure"], Convert.ToString((listval.Count - (successMatterNameCount + alreadyExistsMatterCount)), CultureInfo.InvariantCulture), listval.Count);
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
            catch (Exception exception)
            {
                Utility.DisplayAndLogError(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
            }
        }