/// <summary> /// Function to return no data row /// </summary> /// <param name="managedProperties">Managed properties information</param> /// <returns>No data row</returns> private SearchResponseVM NoDataRow(List<string> managedProperties) { SearchResponseVM searchResponseVM = new SearchResponseVM(); try { List<Dictionary<string, object>> noDataList = new List<Dictionary<string, object>>(); Dictionary<string, object> noDataObject = new Dictionary<string, object>(); managedProperties.Add(ServiceConstants.PATH_FIELD_NAME); foreach (string managedProperty in managedProperties) { if (!noDataObject.ContainsKey(managedProperty)) { noDataObject.Add(managedProperty, string.Empty); } } noDataList.Add(noDataObject); searchResponseVM.TotalRows = 0; searchResponseVM.SearchResults = noDataList; } catch (Exception exception) { customLogger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable); throw; } //string result = string.Concat(ServiceConstants.OPEN_SQUARE_BRACE, // JsonConvert.SerializeObject(noDataObject), ServiceConstants.CLOSE_SQUARE_BRACE, // ServiceConstants.DOLLAR, ServiceConstants.PIPE, ServiceConstants.DOLLAR, 0); return searchResponseVM; }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="listName"></param> /// <param name="listColumnName"></param> /// <param name="isShowDocument"></param> /// <returns></returns> public SearchResponseVM GetPinnedData(SearchRequestVM searchRequestVM, string listName, string listColumnName, bool isShowDocument) { ////Holds logged-in user alias string userAlias = string.Empty; ////Object to store all the list items retrieved from SharePoint list ListItemCollection listItems; ////Stores the JSON structure with the meta-data of pinned matter/document string userPinnedDetails = string.Empty; SearchResponseVM searchResponse = new SearchResponseVM(); using (clientContext = spoAuthorization.GetClientContext(searchRequestVM.Client.Url)) { try { ////Get logged in user alias Users currentUserDetail = userDetails.GetLoggedInUserDetails(clientContext); userAlias = currentUserDetail.LogOnName; listItems = spList.GetData(clientContext, listName, string.Format(CultureInfo.InvariantCulture, camlQueries.UserPinnedDetailsQuery, searchSettings.PinnedListColumnUserAlias, userAlias, listColumnName)); if (listItems != null && listItems.Count > 0) { ////Since we are maintaining only single list item per user, listItems collection will have only one object; hence accessing first object ////Check if column holds null or empty string. If non empty, pinned matter/document exists if (!string.IsNullOrEmpty(Convert.ToString(listItems[0][listColumnName], CultureInfo.InvariantCulture))) { string userPinnedMatter = Convert.ToString(listItems[0][listColumnName], CultureInfo.InvariantCulture); var sortCol = searchRequestVM.SearchObject.Sort.ByColumn; sortCol = UppercaseFirst(sortCol); if (isShowDocument) { Dictionary<string, DocumentData> userpinnedDocumentCollection = JsonConvert.DeserializeObject<Dictionary<string, DocumentData>>(userPinnedMatter); searchResponse.TotalRows = userpinnedDocumentCollection.Count; if (searchRequestVM.SearchObject.Sort.SortAndFilterPinnedData == false) { searchResponse.DocumentDataList = userpinnedDocumentCollection.Values.Reverse(); } else { string lastModifiedDate = configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentModifiedDate").GetValue<string>("keyName"); string createdDate = configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentCreatedDate").GetValue<string>("keyName"); //searchResponse.DocumentDataList = userpinnedDocumentCollection.Values.Reverse(); IList<DocumentData> filterPinnedDocList = null; filterPinnedDocList = GetPinDocsFilteredResult(searchRequestVM, userpinnedDocumentCollection); filterPinnedDocList = filterPinnedDocList .Select(usr => {usr.DocumentMatterName = WebUtility.HtmlDecode(usr.DocumentMatterName);usr.DocumentPracticeGroup = usr.DocumentPracticeGroup;usr.DocumentName = usr.DocumentName;return usr; }) .ToList(); if (filterPinnedDocList != null) { searchResponse.DocumentDataList = filterPinnedDocList; try { if (searchRequestVM.SearchObject.Sort.Direction == 0 && !string.IsNullOrWhiteSpace(sortCol) && filterPinnedDocList.Count > 1) { var getSortColNullCount = filterPinnedDocList.Select(x => TypeHelper.GetPropertyValue(x, sortCol)).Where(y => y == null); if (getSortColNullCount.Count() == 0) { if (sortCol.ToLower().Trim() == lastModifiedDate.ToLower().Trim() || sortCol.ToLower().Trim() == createdDate.ToLower().Trim()) { searchResponse.DocumentDataList = filterPinnedDocList.OrderBy(x => DateTime.Parse(TypeHelper.GetPropertyValue(x, sortCol).ToString())).ToList(); } else { searchResponse.DocumentDataList = filterPinnedDocList.OrderBy(x => TypeHelper.GetPropertyValue(x, sortCol)).ToList(); } } } else if (searchRequestVM.SearchObject.Sort.Direction == 1 && !string.IsNullOrWhiteSpace(sortCol) && filterPinnedDocList.Count > 1) { var getSortColNullCount = filterPinnedDocList.Select(x => TypeHelper.GetPropertyValue(x, sortCol)).Where(y => y == null); if (getSortColNullCount.Count() == 0) { if (sortCol.ToLower().Trim() == lastModifiedDate.ToLower().Trim() || sortCol.ToLower().Trim() == createdDate.ToLower().Trim()) { searchResponse.DocumentDataList = filterPinnedDocList.OrderByDescending(x => DateTime.Parse(TypeHelper.GetPropertyValue(x, sortCol).ToString())).ToList(); } else { searchResponse.DocumentDataList = filterPinnedDocList.OrderByDescending(x => TypeHelper.GetPropertyValue(x, sortCol)).ToList(); } } } } catch (Exception ex) { string msg = ex.Message; } searchResponse.TotalRows = searchResponse.DocumentDataList.Count; } else { searchResponse.DocumentDataList = new List<DocumentData>(); searchResponse.TotalRows = 0; } } } else { Dictionary<string, MatterData> userpinnedMatterCollection = JsonConvert.DeserializeObject<Dictionary<string, MatterData>>(userPinnedMatter); searchResponse.TotalRows = userpinnedMatterCollection.Count; if (searchRequestVM.SearchObject.Sort.SortAndFilterPinnedData == false) { searchResponse.MatterDataList = userpinnedMatterCollection.Values.Reverse(); } else { string lastModifiedDate = configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForMatter").GetSection("matterModifiedDate").GetValue<string>("keyName"); string createdDate = configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForMatter").GetSection("matterCreatedDate").GetValue<string>("keyName"); // searchResponse.MatterDataList = userpinnedMatterCollection.Values.Reverse(); #region Code for filtering pinned data IList<MatterData> filterPinnedMatterList = null; filterPinnedMatterList = GetPinMattersFilteredResult(searchRequestVM, userpinnedMatterCollection); filterPinnedMatterList = filterPinnedMatterList .Select(usr => { usr.MatterName = WebUtility.HtmlDecode(usr.MatterName); usr.MatterSubAreaOfLaw = WebUtility.HtmlDecode(usr.MatterSubAreaOfLaw); return usr; }) .ToList(); if (filterPinnedMatterList != null) { searchResponse.MatterDataList = filterPinnedMatterList; try { if (searchRequestVM.SearchObject.Sort.Direction == 0 && !string.IsNullOrWhiteSpace(sortCol) && filterPinnedMatterList.Count > 1) { var getSortColNullCount = filterPinnedMatterList.Select(x => TypeHelper.GetPropertyValue(x, sortCol)).Where(y => y == null); if (getSortColNullCount.Count() == 0) { if (sortCol.ToLower().Trim() == lastModifiedDate.ToLower().Trim() || sortCol.ToLower().Trim() == createdDate.ToLower().Trim()) { searchResponse.MatterDataList = filterPinnedMatterList.OrderBy(x => DateTime.Parse(TypeHelper.GetPropertyValue(x, sortCol).ToString())).ToList(); } else { searchResponse.MatterDataList = filterPinnedMatterList.OrderBy(x => TypeHelper.GetPropertyValue(x, sortCol)).ToList(); } } } else if (searchRequestVM.SearchObject.Sort.Direction == 1 && !string.IsNullOrWhiteSpace(sortCol) && filterPinnedMatterList.Count > 1) { var getSortColNullCount = filterPinnedMatterList.Select(x => TypeHelper.GetPropertyValue(x, sortCol)).Where(y => y == null); if (getSortColNullCount.Count() == 0) { if (sortCol.ToLower().Trim() == lastModifiedDate.ToLower().Trim() || sortCol.ToLower().Trim() == createdDate.ToLower().Trim()) { searchResponse.MatterDataList = filterPinnedMatterList.OrderByDescending(x => DateTime.Parse(TypeHelper.GetPropertyValue(x, sortCol).ToString())).ToList(); } else { searchResponse.MatterDataList = filterPinnedMatterList.OrderByDescending(x => TypeHelper.GetPropertyValue(x, sortCol)).ToList(); } } } } catch (Exception ex) { string msg = ex.Message; } searchResponse.TotalRows = searchResponse.MatterDataList.Count; } else { searchResponse.MatterDataList = new List<MatterData>(); searchResponse.TotalRows = 0; } #endregion } } } } else { searchResponse.TotalRows = 0; searchResponse.NoPinnedMessage = ServiceConstants.NO_PINNED_MESSAGE; } return searchResponse; } catch (Exception ex) { customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable); throw; } } }
/// <summary> /// Fires query on SharePoint Search and fills the result data. /// </summary> /// <param name="clientContext">The client context.</param> /// <param name="keywordQuery">The keyword query.</param> /// <param name="searchObject">The search object.</param> /// <param name="isMatterSearch">The flag to determine weather call is from Search Matter or Search Document.</param> /// <param name="managedProperties">List of managed properties</param> /// <returns>It returns a string object, that contains all the results combined with dollar pipe dollar separator.</returns> private SearchResponseVM FillResultData(ClientContext clientContext, KeywordQuery keywordQuery, SearchRequestVM searchRequestVM, Boolean isMatterSearch, List<string> managedProperties) { SearchResponseVM searchResponseVM = new SearchResponseVM(); Boolean isReadOnly; try { var searchObject = searchRequestVM.SearchObject; //var client = searchRequestVM.Client; if (null != searchObject.Sort) { keywordQuery.EnableSorting = true; keywordQuery = GetSortByProperty(keywordQuery, searchObject, isMatterSearch); } if(keywordQuery.QueryText.Length > 4000) { return new SearchResponseVM(); } SearchExecutor searchExecutor = new SearchExecutor(clientContext); ClientResult<ResultTableCollection> resultsTableCollection = searchExecutor.ExecuteQuery(keywordQuery); Users currentLoggedInUser = userDetails.GetLoggedInUserDetails(clientContext); if (null != resultsTableCollection && null != resultsTableCollection.Value && 0 < resultsTableCollection.Value.Count && null != resultsTableCollection.Value[0].ResultRows) { if (isMatterSearch && 0 < resultsTableCollection.Value.Count && null != resultsTableCollection.Value[0].ResultRows && !string.IsNullOrWhiteSpace(currentLoggedInUser.Email)) { foreach (IDictionary<string, object> matterMetadata in resultsTableCollection.Value[0].ResultRows) { isReadOnly = false; if (null != matterMetadata) { // Decode matter properties DecodeMatterProperties(matterMetadata); string readOnlyUsers = Convert.ToString(matterMetadata[searchSettings.ManagedPropertyBlockedUploadUsers], CultureInfo.InvariantCulture); if (!string.IsNullOrWhiteSpace(readOnlyUsers)) { isReadOnly = IsUserReadOnlyForMatter(isReadOnly, currentLoggedInUser.Name, currentLoggedInUser.Email, readOnlyUsers); } matterMetadata.Add(generalSettings.IsReadOnlyUser, isReadOnly); } } } else { /*Keeping the code to clean the author values*/ foreach (IDictionary<string, object> documentMetadata in resultsTableCollection.Value[0].ResultRows) { if (null != documentMetadata) { string authorData = Convert.ToString(documentMetadata[searchSettings.ManagedPropertyAuthor], CultureInfo.InvariantCulture); int ltIndex = authorData.IndexOf(ServiceConstants.OPENING_ANGULAR_BRACKET, StringComparison.Ordinal); int gtIndex = authorData.IndexOf(ServiceConstants.CLOSING_ANGULAR_BRACKET, StringComparison.Ordinal); authorData = (0 <= ltIndex && ltIndex < gtIndex) ? authorData.Remove(ltIndex, (gtIndex - ltIndex) + 1) : authorData; authorData = authorData.Replace(ServiceConstants.ENCODED_DOUBLE_QUOTES, string.Empty); documentMetadata[searchSettings.ManagedPropertyAuthor] = authorData.Trim(); } } } if (resultsTableCollection.Value.Count > 1) { searchResponseVM.TotalRows = resultsTableCollection.Value[0].TotalRows; searchResponseVM.SearchResults = resultsTableCollection.Value[0].ResultRows; } else { if (resultsTableCollection.Value[0].TotalRows == 0) { searchResponseVM = NoDataRow(managedProperties); } else { searchResponseVM.TotalRows = resultsTableCollection.Value[0].TotalRows; searchResponseVM.SearchResults = resultsTableCollection.Value[0].ResultRows; } } } else { searchResponseVM = NoDataRow(managedProperties); } } catch (Exception exception) { customLogger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable); throw; } return searchResponseVM; }