public IActionResult GetCurrentSiteTitle() { var termStoreViewModel1 = new TermStoreViewModel() { Client = new Client() { Id = "123456", Name = "Disney", Url = "https://microsoft.sharepoint.com/teams/mcuisite" }, TermStoreDetails = new TermStoreDetails() { TermGroup = "Site Collection - microsoft.sharepoint.com-teams-mcuisite", TermSetName = "Clients", CustomPropertyName = "ClientURL" } }; string siteName = string.Empty; spoAuthorization.AccessToken = HttpContext.Request.Headers["Authorization"]; siteName = taxonomyRepository.GetCurrentSiteName(termStoreViewModel1.Client); var success = new { Title = siteName }; return(matterCenterServiceFunctions.ServiceResponse(success, (int)HttpStatusCode.OK)); }
public async void Get_Taxonomy_Hierarchy_For_PracticeGroups() { var termStoreViewModel = new TermStoreViewModel() { Client = new Client() { Id = "123456", Name = "Microsoft", Url = "https://msmatter.sharepoint.com/sites/catalog" }, TermStoreDetails = new TermStoreDetails() { TermGroup = "MatterCenterTerms", TermSetName = "Practice Groups", CustomPropertyName = "FolderNames" } }; using (var client = testServer.CreateClient().AcceptJson()) { var response = await client.PostAsJsonAsync("http://localhost:58775/api/v1/taxonomy/gettaxonomy", termStoreViewModel); var result = response.Content.ReadAsJsonAsync <TermSets>().Result; Assert.NotNull(result); Assert.NotEmpty(result.PGTerms); } }
public async void Internal_Server_Error() { var termStoreViewModel = new TermStoreViewModel() { Client = new Client() { Id = "123456", Name = "Microsoft", Url = "https://microsoft.sharepoint.com/teams/mcuisite1234" }, TermStoreDetails = new TermStoreDetails() { TermGroup = "Site Collection - microsoft.sharepoint.com-teams-mcuisite", TermSetName = "NoClients", CustomPropertyName = "ClientURL" } }; using (var client = testServer.CreateClient().AcceptJson()) { var response = await client.PostAsJsonAsync("http://localhost:58775/api/v1/taxonomy/gettaxonomy", termStoreViewModel); var result = response.Content.ReadAsJsonAsync <ErrorResponse>().Result; Assert.NotNull(result); Assert.Equal("500", result.ErrorCode); } }
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; } }
/// <summary> /// This method will get the taxonomy hierarchy object for the given search criterai and return to the service /// </summary> /// <typeparam name="T"></typeparam> /// <param name="termStoreViewModel">The request object for which the taxonomy has to be retrieved</param> /// <returns>Client TermSet or SPO TermSet</returns> public async Task <TaxonomyResponseVM> GetTaxonomyHierarchyAsync(TermStoreViewModel termStoreViewModel) { return(await Task.FromResult(taxonomy.GetTaxonomyHierarchy(termStoreViewModel.Client, termStoreViewModel.TermStoreDetails))); }