Skip to content

Commit

Permalink
1. Significant improvements to Subscriptions data inventory.
Browse files Browse the repository at this point in the history
2. Downloading Views inventory
  • Loading branch information
unknown authored and unknown committed May 9, 2017
1 parent fdf8464 commit ce6ff92
Show file tree
Hide file tree
Showing 9 changed files with 1,109 additions and 275 deletions.
164 changes: 142 additions & 22 deletions TabRESTMigrate/FilesLogging/CustomerSiteInventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CustomerSiteInventory : CsvDataGenerator
const string ContentConnectionUserName = "connection-user-name";
const string ContentProjectId = "project-id";
const string ContentWorkbookId = "workbook-id";
const string ContentViewCount = "view-count";
const string ContentWorkbookName = "workbook-name";
const string ContentViewId = "view-id";
const string ContentProjectName = "project-name";
Expand All @@ -30,7 +31,8 @@ class CustomerSiteInventory : CsvDataGenerator
const string ContentOwnerName = "owner-name";
const string ContentTags = "tags";
const string ContentSubscriptionId = "subscription-id";
const string ContentSubscriptionName = "subscription-name";
const string ContentScheduleId = "schedule-id";
const string ContentScheduleName = "schedule-name";
const string ContentSubscriptionType = "subscription-type";
const string WorkbookShowTabs = "workbook-show-tabs";
const string SiteRole = "user-role";
Expand All @@ -41,6 +43,16 @@ class CustomerSiteInventory : CsvDataGenerator
/// </summary>
private readonly KeyedLookup<SiteUser> _siteUserMapping;

/// <summary>
/// Efficent store for looking up views by ID
/// </summary>
private readonly KeyedLookup<SiteView> _siteViewMapping;

/// <summary>
/// Efficent store for looking up workbooks by ID
/// </summary>
private readonly KeyedLookup<SiteWorkbook> _siteWorkbookMapping;

/// <summary>
/// Status log data
/// </summary>
Expand All @@ -58,6 +70,7 @@ public CustomerSiteInventory(
IEnumerable<SiteProject> projects,
IEnumerable<SiteDatasource> dataSources,
IEnumerable<SiteWorkbook> workbooks,
IEnumerable<SiteView> views,
IEnumerable<SiteUser> users,
IEnumerable<SiteGroup> groups,
IEnumerable<SiteSubscription> subscriptions,
Expand All @@ -77,11 +90,24 @@ public CustomerSiteInventory(
_siteUserMapping = new KeyedLookup<SiteUser>(users);
}

//Want to be able to map views to workbooks (e.g. in subscriptions)
if(views != null)
{
_siteViewMapping = new KeyedLookup<SiteView>(views);
}

//Want to be able to map workbooks to workbook names (e.g. in subscriptions)
if (workbooks != null)
{
_siteWorkbookMapping = new KeyedLookup<SiteWorkbook>(workbooks);
}

AddProjectsData(projects);
AddDatasourcesData(dataSources);
AddWorkbooksData(workbooks);
AddUsersData(users);
AddGroupsData(groups);
AddViewsData(views);
AddSubscriptionsData(subscriptions);
}

Expand Down Expand Up @@ -127,11 +153,33 @@ private string helper_AttemptUserNameLookup_inner(string userId)
}


/// <summary>
/// If we have cached views, look them up
/// </summary>
/// <param name="viewId"></param>
/// <returns></returns>
private SiteView helper_AttemptViewLookup(string viewId)
{
if (_siteViewMapping == null) return null;
return _siteViewMapping.FindItem(viewId);
}

/// <summary>
/// If we have cached workbooks, look them up
/// </summary>
/// <param name="viewId"></param>
/// <returns></returns>
private SiteWorkbook helper_AttemptWorkbookLookup(string workbookId)
{
if (_siteWorkbookMapping == null) return null;
return _siteWorkbookMapping.FindItem(workbookId);
}

/// <summary>
/// Add CSV for all the data sources
/// </summary>
/// <param name="dataSources"></param>
private void AddDatasourcesData(IEnumerable<SiteDatasource> dataSources)
private void AddDatasourcesData(IEnumerable<SiteDatasource> dataSources)
{
//No data sources? Do nothing.
if (dataSources == null) return;
Expand Down Expand Up @@ -301,6 +349,42 @@ private void AddProjectsData(IEnumerable<SiteProject> projects)
}
}

/// <summary>
/// Add CSV rows for all the views data
/// </summary>
/// <param name="views"></param>
private void AddViewsData(IEnumerable<SiteView> views)
{
//No data to add? do nothing.
if (views == null) return;

//Add each project as a row in the CSV file we will generate
foreach (var thisView in views)
{
this.AddKeyValuePairs(
new string[] {
ContentType //1
,ContentId //2
,ContentName //3
,ContentUrl //4
,ContentOwnerId //5
,ContentWorkbookId //6
,ContentViewCount //7
,DeveloperNotes //8
},
new string[] {
"view" //1
,thisView.Id //2
,thisView.Name //3
,thisView.ContentUrl //4
,thisView.OwnerId //5
,thisView.WorkbookId //6
,thisView.TotalViewCount.ToString() //7 UNDONE: Could expland CSV generation to be integers and strings, rather than make this a string
,thisView.DeveloperNotes //8
});
}
}

/// <summary>
/// Add CSV rows for all the subscriptions data
/// </summary>
Expand All @@ -313,13 +397,21 @@ private void AddSubscriptionsData(IEnumerable<SiteSubscription> subscriptions)
//Add each subscription as a row in the CSV file we will generate
foreach (var thisSubscription in subscriptions)
{

string contentUrl = "";
string thisSubscriptionViewId = "";
string thisSubscriptionWorkbookId = "";

if(thisSubscription.ContentType == "View")
{

//UNDONE: We could TRY to look up the Workbook ID, if we have set of VIEWS
thisSubscriptionViewId = thisSubscription.ContentId;
//If we have view information, then look up the workbook id
var thisView = helper_AttemptViewLookup(thisSubscription.ContentId);
if(thisView != null)
{
thisSubscriptionWorkbookId = thisView.WorkbookId;
contentUrl = thisView.ContentUrl;
}
}
else if(thisSubscription.ContentType == "Workbook")
{
Expand All @@ -330,32 +422,60 @@ private void AddSubscriptionsData(IEnumerable<SiteSubscription> subscriptions)
this.StatusLog.AddError("Unknown subscription type: " + thisSubscription.ContentType);
}

//If we have workbook information, look up the workbook and get its name
string thisWorkbookName = "";
string thisWorkbookProjectId = "";
if(!string.IsNullOrWhiteSpace(thisSubscriptionWorkbookId))
{
var thisWorkbook = helper_AttemptWorkbookLookup(thisSubscriptionWorkbookId);
if(thisWorkbook != null)
{
thisWorkbookName = thisWorkbook.Name;
thisWorkbookProjectId = thisWorkbook.ProjectId;

//If the subscription is for a Workbook, and we have that workbook then grab the content URL
if (thisSubscription.ContentType == "Workbook")
{
contentUrl = thisWorkbook.ContentUrl;
}
}
}


this.AddKeyValuePairs(
new string[] {
ContentType //1
,ContentId //2
,ContentDescription //3
,ContentOwnerId //4
,ContentOwnerName //5
,ContentSubscriptionId //6
,ContentSubscriptionName //7
,ContentSubscriptionType //8
,ContentWorkbookId //9
,ContentViewId //10
,DeveloperNotes //11
,ContentSubscriptionId //3
,ContentDescription //4
,ContentOwnerId //5
,ContentOwnerName //6
,ContentScheduleId //7
,ContentScheduleName //8
,ContentSubscriptionType //9
,ContentWorkbookId //10
,ContentViewId //11
,ContentWorkbookName //12
,ContentProjectId //13
,ContentUrl //14
,DeveloperNotes //15
},
new string[] {
"subscription" //1
,thisSubscription.Id //2
,thisSubscription.Subject //3
,thisSubscription.UserId //4
,thisSubscription.UserName //5
,thisSubscription.ScheduleId //6
,thisSubscription.ScheduleName //7
,thisSubscription.ContentType //8
,thisSubscriptionWorkbookId //9
,thisSubscriptionViewId //10
,thisSubscription.DeveloperNotes //11
,thisSubscription.Id //3
,thisSubscription.Subject //4
,thisSubscription.UserId //5
,thisSubscription.UserName //6
,thisSubscription.ScheduleId //7
,thisSubscription.ScheduleName //8
,thisSubscription.ContentType //9
,thisSubscriptionWorkbookId //10
,thisSubscriptionViewId //11
,thisWorkbookName //12
,thisWorkbookProjectId //13
,contentUrl //14
,thisSubscription.DeveloperNotes //15
});
}
}
Expand Down
18 changes: 18 additions & 0 deletions TabRESTMigrate/RESTHelpers/TableauServerUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public ServerVersion ServerVersion
private readonly string _urlListDatasourcesTemplate;
private readonly string _urlListProjectsTemplate;
private readonly string _urlListSubscriptionsTemplate;
private readonly string _urlListViewsTemplate;
private readonly string _urlListGroupsTemplate;
private readonly string _urlListUsersTemplate;
private readonly string _urlListUsersInGroupTemplate;
Expand Down Expand Up @@ -93,6 +94,7 @@ public TableauServerUrls(string protocol, string serverName, string siteUrlSegme
this._urlListDatasourcesTemplate = serverNameWithProtocol + "/api/2.3/sites/{{iwsSiteId}}/datasources?pageSize={{iwsPageSize}}&pageNumber={{iwsPageNumber}}";
this._urlListProjectsTemplate = serverNameWithProtocol + "/api/2.3/sites/{{iwsSiteId}}/projects?pageSize={{iwsPageSize}}&pageNumber={{iwsPageNumber}}";
this._urlListSubscriptionsTemplate = serverNameWithProtocol + "/api/2.3/sites/{{iwsSiteId}}/subscriptions?pageSize={{iwsPageSize}}&pageNumber={{iwsPageNumber}}";
this._urlListViewsTemplate = serverNameWithProtocol + "/api/2.3/sites/{{iwsSiteId}}/views?includeUsageStatistics=true&pageSize={{iwsPageSize}}&pageNumber={{iwsPageNumber}}";
this._urlListGroupsTemplate = serverNameWithProtocol + "/api/2.3/sites/{{iwsSiteId}}/groups?pageSize={{iwsPageSize}}&pageNumber={{iwsPageNumber}}";
this._urlListUsersTemplate = serverNameWithProtocol + "/api/2.3/sites/{{iwsSiteId}}/users?pageSize={{iwsPageSize}}&pageNumber={{iwsPageNumber}}";
this._urlListUsersInGroupTemplate = serverNameWithProtocol + "/api/2.3/sites/{{iwsSiteId}}/groups/{{iwsGroupId}}/users?pageSize={{iwsPageSize}}&pageNumber={{iwsPageNumber}}";
Expand Down Expand Up @@ -432,6 +434,22 @@ public string Url_SubscriptionsList(TableauServerSignIn session, int pageSize, i
return workingText;
}

/// <summary>
/// URL for the Subscriptions list
/// </summary>
/// <param name="siteUrlSegment"></param>
/// <returns></returns>
public string Url_ViewsList(TableauServerSignIn session, int pageSize, int pageNumber = 1)
{
string workingText = _urlListViewsTemplate;
workingText = workingText.Replace("{{iwsSiteId}}", session.SiteId);
workingText = workingText.Replace("{{iwsPageSize}}", pageSize.ToString());
workingText = workingText.Replace("{{iwsPageNumber}}", pageNumber.ToString());
ValidateTemplateReplaceComplete(workingText);

return workingText;
}

/// <summary>
/// URL for the Groups list
/// </summary>
Expand Down
Loading

0 comments on commit ce6ff92

Please sign in to comment.