예제 #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>
        /// Constructor to inject required dependencies
        /// </summary>
        /// <param name="generalSettings"></param>
        /// <param name="taxonomySettings"></param>
        /// <param name="logTables"></param>
        /// <param name="spoAuthorization"></param>
        /// <param name="customLogger"></param>
        public Taxonomy(IOptions <GeneralSettings> generalSettings,
                        IOptions <TaxonomySettings> taxonomySettings,
                        IOptions <ContentTypesConfig> contentTypeSettings,
                        IOptions <LogTables> logTables,
                        ISPOAuthorization spoAuthorization, ICustomLogger customLogger,
                        IConfigurationRoot configuration)
        {
            this.generalSettings     = generalSettings.Value;
            this.taxonomySettings    = taxonomySettings.Value;
            this.contentTypeSettings = contentTypeSettings.Value;
            this.logTables           = logTables.Value;
            this.spoAuthorization    = spoAuthorization;
            taxonomyResponseVM       = new TaxonomyResponseVM();
            this.customLogger        = customLogger;

            this.configuration = configuration;
        }
        public async Task <IActionResult> GetTaxonomy([FromBody] TermStoreViewModel termStoreViewModel)
        {
            try
            {
                #region Error Checking

                var matterInformation = new MatterInformationVM()
                {
                    Client = new Client()
                    {
                        Url = termStoreViewModel.Client.Url
                    }
                };
                var genericResponseVM = validationFunctions.IsMatterValid(matterInformation, 0, null);
                if (genericResponseVM != null)
                {
                    genericResponseVM.Description = $"Error occurred while getting the taxonomy data";
                    return(matterCenterServiceFunctions.ServiceResponse(genericResponseVM, (int)HttpStatusCode.BadRequest));
                }
                #endregion

                string cacheValue = string.Empty;
                string key        = string.Empty;
                var    details    = termStoreViewModel.TermStoreDetails;
                if (details.TermSetName == taxonomySettings.PracticeGroupTermSetName)
                {
                    key = ServiceConstants.CACHE_MATTER_TYPE;
                }
                else if (details.TermSetName == taxonomySettings.ClientTermSetName)
                {
                    key = ServiceConstants.CACHE_CLIENTS;
                }

                ServiceUtility.RedisCacheHostName = generalSettings.RedisCacheHostName;
                cacheValue = ServiceUtility.GetDataFromAzureRedisCache(key);
                cacheValue = "";
                TaxonomyResponseVM taxonomyRepositoryVM = null;
                if (String.IsNullOrEmpty(cacheValue))
                {
                    taxonomyRepositoryVM = await taxonomyRepository.GetTaxonomyHierarchyAsync(termStoreViewModel);

                    if (termStoreViewModel.TermStoreDetails.TermSetName == taxonomySettings.PracticeGroupTermSetName && taxonomyRepositoryVM.TermSets != null)
                    {
                        ServiceUtility.SetDataIntoAzureRedisCache <string>(key, taxonomyRepositoryVM.TermSets);
                        return(matterCenterServiceFunctions.ServiceResponse(taxonomyRepositoryVM.TermSets, (int)HttpStatusCode.OK));
                    }
                    if (termStoreViewModel.TermStoreDetails.TermSetName == taxonomySettings.ClientTermSetName && taxonomyRepositoryVM.ClientTermSets != null)
                    {
                        ServiceUtility.SetDataIntoAzureRedisCache <ClientTermSets>(key, taxonomyRepositoryVM.ClientTermSets);
                        return(matterCenterServiceFunctions.ServiceResponse(taxonomyRepositoryVM.ClientTermSets, (int)HttpStatusCode.OK));
                    }
                }
                else
                {
                    if (termStoreViewModel.TermStoreDetails.TermSetName == taxonomySettings.PracticeGroupTermSetName)
                    {
                        var pgTermSets = JsonConvert.DeserializeObject <string>(cacheValue);
                        if (pgTermSets == null)
                        {
                            genericResponseVM = new GenericResponseVM()
                            {
                                Value       = errorSettings.MessageNoResult,
                                Code        = "404",
                                Description = "No data is present for the given passed input"
                            };
                            return(matterCenterServiceFunctions.ServiceResponse(genericResponseVM, (int)HttpStatusCode.NotFound));
                        }
                        return(matterCenterServiceFunctions.ServiceResponse(pgTermSets, (int)HttpStatusCode.OK));
                    }
                    if (termStoreViewModel.TermStoreDetails.TermSetName == taxonomySettings.ClientTermSetName)
                    {
                        var clientTermSets = JsonConvert.DeserializeObject <ClientTermSets>(cacheValue);
                        if (clientTermSets == null)
                        {
                            genericResponseVM = new GenericResponseVM()
                            {
                                Value       = errorSettings.MessageNoResult,
                                Code        = HttpStatusCode.NotFound.ToString(),
                                Description = "No data is present for the given passed input"
                            };
                            return(matterCenterServiceFunctions.ServiceResponse(genericResponseVM, (int)HttpStatusCode.NotFound));
                        }
                        return(matterCenterServiceFunctions.ServiceResponse(clientTermSets, (int)HttpStatusCode.OK));
                    }
                }
                //If all the above condition fails, return validation error object
                genericResponseVM = new GenericResponseVM()
                {
                    Value       = errorSettings.MessageNoResult,
                    Code        = HttpStatusCode.NotFound.ToString(),
                    Description = "No data is present for the given passed input"
                };
                return(matterCenterServiceFunctions.ServiceResponse(genericResponseVM, (int)HttpStatusCode.BadRequest));
            }
            catch (Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                var errorResponse = customLogger.GenerateErrorResponse(ex);
                return(matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.InternalServerError));
            }
        }
        /// <summary>
        /// Gets the hierarchy of terms along with the specific custom properties of each term from term store.
        /// </summary>
        /// <param name="client">Client object containing Client data</param>
        /// <param name="details">Term Store object containing Term store data</param>
        /// <returns>Returns JSON object to the client</returns>
        ///
        public async Task <IActionResult> GetTaxonomy([FromBody] TermStoreViewModel termStoreViewModel)
        {
            try
            {
                spoAuthorization.AccessToken = HttpContext.Request.Headers["Authorization"];
                #region Error Checking
                ErrorResponse errorResponse = null;
                //if the token is not valid, immediately return no authorization error to the user
                if (errorResponse != null && !errorResponse.IsTokenValid)
                {
                    return(matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.Unauthorized));
                }

                ValidationHelperFunctions.ErrorSettings = errorSettings;
                errorResponse = ValidationHelperFunctions.TaxonomyValidation(termStoreViewModel.Client);
                if (errorResponse != null && !String.IsNullOrWhiteSpace(errorResponse.Message))
                {
                    return(matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest));
                }
                #endregion

                string cacheValue = string.Empty;
                string key        = string.Empty;
                var    details    = termStoreViewModel.TermStoreDetails;
                if (details.TermSetName == taxonomySettings.PracticeGroupTermSetName)
                {
                    key = ServiceConstants.CACHE_MATTER_TYPE;
                }
                else if (details.TermSetName == taxonomySettings.ClientTermSetName)
                {
                    key = ServiceConstants.CACHE_CLIENTS;
                }

                ServiceUtility.GeneralSettings = generalSettings;
                //cacheValue = ServiceUtility.GetDataFromAzureRedisCache(key);
                TaxonomyResponseVM taxonomyRepositoryVM = null;
                if (String.IsNullOrEmpty(cacheValue))
                {
                    taxonomyRepositoryVM = await taxonomyRepository.GetTaxonomyHierarchyAsync(termStoreViewModel);

                    if (termStoreViewModel.TermStoreDetails.TermSetName == taxonomySettings.PracticeGroupTermSetName && taxonomyRepositoryVM.TermSets != null)
                    {
                        ServiceUtility.SetDataIntoAzureRedisCache <TermSets>(key, taxonomyRepositoryVM.TermSets);
                        return(matterCenterServiceFunctions.ServiceResponse(taxonomyRepositoryVM.TermSets, (int)HttpStatusCode.OK));
                    }
                    if (termStoreViewModel.TermStoreDetails.TermSetName == taxonomySettings.ClientTermSetName && taxonomyRepositoryVM.ClientTermSets != null)
                    {
                        ServiceUtility.SetDataIntoAzureRedisCache <ClientTermSets>(key, taxonomyRepositoryVM.ClientTermSets);
                        return(matterCenterServiceFunctions.ServiceResponse(taxonomyRepositoryVM.ClientTermSets, (int)HttpStatusCode.OK));
                    }
                }
                else
                {
                    if (termStoreViewModel.TermStoreDetails.TermSetName == taxonomySettings.PracticeGroupTermSetName)
                    {
                        var pgTermSets = JsonConvert.DeserializeObject <TermSets>(cacheValue);
                        if (pgTermSets == null)
                        {
                            errorResponse = new ErrorResponse()
                            {
                                Message     = errorSettings.MessageNoResult,
                                ErrorCode   = "404",
                                Description = "No data is present for the given passed input"
                            };
                            return(matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.NotFound));
                        }
                        return(matterCenterServiceFunctions.ServiceResponse(pgTermSets, (int)HttpStatusCode.OK));
                    }
                    if (termStoreViewModel.TermStoreDetails.TermSetName == taxonomySettings.ClientTermSetName)
                    {
                        var clientTermSets = JsonConvert.DeserializeObject <ClientTermSets>(cacheValue);
                        if (clientTermSets == null)
                        {
                            errorResponse = new ErrorResponse()
                            {
                                Message     = errorSettings.MessageNoResult,
                                ErrorCode   = "404",
                                Description = "No data is present for the given passed input"
                            };
                            return(matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.NotFound));
                        }
                        return(matterCenterServiceFunctions.ServiceResponse(clientTermSets, (int)HttpStatusCode.OK));
                    }
                }
                //If all the above condition fails, return validation error object
                errorResponse = new ErrorResponse()
                {
                    Message     = errorSettings.MessageNoResult,
                    ErrorCode   = "404",
                    Description = "No data is present for the given passed input"
                };
                return(matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.NotFound));
            }
            catch (Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
        }