public ActionResult ShowLaunchpad(string id) { string output = "Could not process your request"; if (string.IsNullOrEmpty(Identity.TableauAuthTicket)) { ViewBag.Error = output; return View(); } string tableauLaunchpadUrl = System.Configuration.ConfigurationManager.AppSettings["tableauServerUrl"]; if (string.IsNullOrEmpty(tableauLaunchpadUrl)) { //show the could not process request response ViewBag.Error = output; return View(); } _logMessage.AppendFormat("User {0} requested {1} tableau view. Checking if user has view access", Identity.UserName, id); try { GenericAjaxResponse<List<Core.DTO.TableauViewInfo>> apiResponse = _restClient.GetUsersViews(Identity.UserName, Identity.IsInternalUser ? "Internal" : "External"); if (!apiResponse.Success || apiResponse.Data == null || apiResponse.Data.Count <= 0) { //show the could not process request response ViewBag.Error = output; return View(); } Core.DTO.TableauViewInfo viewToDisplay = apiResponse.Data.FirstOrDefault(vw => vw.ViewId.Equals(id, StringComparison.OrdinalIgnoreCase)); if (viewToDisplay == null) { ViewBag.Error = output; return View(); } //construct tableau embed url string tableauEmbedUrl = string.Format("{0}/trusted/{1}/{2}", tableauLaunchpadUrl, Identity.TableauAuthTicket, viewToDisplay.ViewUrl); _logMessage.AppendFormat("Tableau embed url {0}.", tableauEmbedUrl); ViewBag.TableauUri = tableauEmbedUrl; } catch (WebException ex) { if (ex.Response != null) { using (var stream = ex.Response.GetResponseStream()) using (var reader = new StreamReader(stream)) { string error = reader.ReadToEnd(); _logger.Error("An Error occurred during tableu report pull , Error detail " + error + ".", ex); } } } catch (Exception ex) { _logMessage.AppendFormat("Error message {0} while loading view", ex.Message); ViewBag.Error = output; } _logger.Info(_logMessage.ToString()); return View(); }
public ActionResult Home() { ReportViewModel reportVM = new ReportViewModel(); try { _logMessage.Append("Getting reports list using sap token Customer Controller Home Method."); ViewBag.IsInternalUser = Identity.IsInternalUser; if (Identity != null && !string.IsNullOrEmpty(Identity.SapToken)) { reportVM.Category = _restClient.GetReportList(Identity.SapToken); _logMessage.Append("Identity and Sap token are present. Sap Token passed is " + Identity.SapToken + "."); } else { _logMessage.Append("Identity or Sap Token is missing"); } if (Identity != null) { //get all tableau views GenericAjaxResponse <List <AHP.Core.DTO.TableauViewInfo> > apiResponse = _restClient.GetUsersViews(Identity.UserName, Identity.IsInternalUser ? "INTERNAL" : "EXTERNAL"); if (apiResponse.Success && apiResponse.Data != null) { List <Web.ViewModel.TableauWorkbookViewModel> uiResponse = apiResponse.Data.Select(dto => new Web.ViewModel.TableauWorkbookViewModel() { Description = dto.Description, ShortDescription = dto.Description.Substring(0, Math.Min(136, dto.Description.Length)), Disabled = dto.Disabled, IsDashboard = dto.IsDashboard, ShortName = dto.ViewName.Substring(0, Math.Min(51, dto.ViewName.Length)), ViewId = dto.ViewId, ViewName = dto.ViewName, ViewUrl = dto.ViewUrl }).ToList(); ViewBag.TableauViews = uiResponse. Where(vw => vw.IsDashboard.Equals("N", StringComparison.OrdinalIgnoreCase) && vw.Disabled.Equals("N", StringComparison.OrdinalIgnoreCase)). ToList(); ViewBag.TableauDashboards = uiResponse.Where(vw => vw.IsDashboard.Equals("Y", StringComparison.OrdinalIgnoreCase) && vw.Disabled.Equals("N", StringComparison.OrdinalIgnoreCase)).ToList(); } } } catch (Exception ex) { _logMessage.Append("An error occurred getting reports. Exception information " + ex.Message); Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error(ex)); } _logger.Info(_logMessage.ToString()); return(View(reportVM)); }