private static async Task <Dictionary <string, TableauGroup> > GetProjectGroups( string projectId, ITableauServiceFactory serviceFactory ) { var groupService = serviceFactory.GetService <TableauGroupService>(); var permissionService = serviceFactory.GetService <TableauPermissionService>(); var projectGroups = new Dictionary <string, TableauGroup>(); // get groups defined in project permissions as well as default permissions for datasources, workbooks var permissions = new List <TableauPermission>(); permissions.Add( await permissionService.GetPermissionsAsync( ResourceType.Project, projectId ).ConfigureAwait(false) ); permissions.Add( await permissionService.GetDefaultPermissionsAsync( projectId, ResourceType.Datasource ).ConfigureAwait(false) ); permissions.Add( await permissionService.GetDefaultPermissionsAsync( projectId, ResourceType.Workbook ).ConfigureAwait(false) ); foreach (var permission in permissions) { if (permission.GranteeCapabilities == null) { continue; } foreach (var granteeCapability in permission.GranteeCapabilities) { if (granteeCapability.GranteeType == GranteeType.Group) { var group = await groupService.GetGroupAsync(granteeCapability.GranteeId).ConfigureAwait(false); projectGroups[granteeCapability.GranteeId] = group; } } } return(projectGroups); }
private static async Task <Dictionary <string, TableauWorkbook> > GetProjectWorkbooksAsync( string projectId, ITableauServiceFactory serviceFactory ) { var workbookService = serviceFactory.GetService <TableauWorkbookService>(); var projectWorkbooks = new Dictionary <string, TableauWorkbook>(); var workbooks = await workbookService.GetWorkbooksAsync().ConfigureAwait(false); return(workbooks.Where(w => w.Project.Id == projectId).ToDictionary(w => w.Id, w => w)); }
private static async Task <Dictionary <string, TableauDatasource> > GetProjectDatasourcesAsync( string projectId, ITableauServiceFactory serviceFactory ) { var datasourceService = serviceFactory.GetService <TableauDatasourceService>(); var projectDatasources = new Dictionary <string, TableauDatasource>(); var datasources = await datasourceService.GetDatasourcesAsync().ConfigureAwait(false); return(datasources.Where(d => d.Project.Id == projectId).ToDictionary(w => w.Id, w => w)); }
private static async Task <Dictionary <string, TableauUser> > GetGroupUsersWithDomain( string groupId, ITableauServiceFactory serviceFactory ) { var groupUsers = new Dictionary <string, TableauUser>(); var userService = serviceFactory.GetService <TableauUserService>(); var users = await userService.GetUsersAsync(groupId).ConfigureAwait(false); foreach (var user in users) { // get all users in group individually so user's domain is included if specified (slandron) groupUsers.Add(user.Id, await userService.GetUserAsync(user.Id).ConfigureAwait(false)); } return(groupUsers); }
public async Task MigrateProjects() { _logger?.Information( String.Format( "Starting migration from {0} to {1} (root project '{2}')", _settingsMonitor.CurrentValue.TableauApiSettingsSource.BaseUrl, _settingsMonitor.CurrentValue.TableauApiSettingsDestination.BaseUrl, _settingsMonitor.CurrentValue.DestinationRootProjectName ) ); if (_settingsMonitor.CurrentValue.DryRun) { _logger?.Warning("Dry run specified, no changes will be made"); } var sourceProjectService = _tableauServiceFactorySource.GetService <TableauProjectService>(); var destProjectService = _tableauServiceFactoryDest.GetService <TableauProjectService>(); var destRootProject = null as TableauProject; if (!String.IsNullOrWhiteSpace(_settingsMonitor.CurrentValue.DestinationRootProjectName)) { destRootProject = await destProjectService.FindProjectAsync( _settingsMonitor.CurrentValue.DestinationRootProjectName ).ConfigureAwait(false); if (destRootProject == null) { _logger?.Debug( "Destination root project '{0}' not found", _settingsMonitor.CurrentValue.DestinationRootProjectName ); } else { _logger?.Debug( "Migrating to destination root project '{0}' ({1})", _settingsMonitor.CurrentValue.DestinationRootProjectName, destRootProject.Id ); } } foreach (var kvp in _settingsMonitor.CurrentValue.ProjectsToMigrate) { var projectToMigrate = kvp.Key; var workbooksToMigrate = kvp.Value.Split( new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries ).Select(s => s.Trim()); _logger?.Information($"Beginning migration of project '{projectToMigrate}'"); var sourceProject = await sourceProjectService.FindProjectAsync( projectToMigrate ).ConfigureAwait(false); if (sourceProject == null) { _logger?.Warning($"Project '{projectToMigrate}' not found in Tableau source, skipping"); continue; } // find project in destination, create if missing var destProject = await destProjectService.FindProjectAsync( projectToMigrate ).ConfigureAwait(false); if (destProject == null) { _logger?.Information($"Project '{projectToMigrate}' not found in Tableau destination, creating"); if (!_settingsMonitor.CurrentValue.DryRun) { destProject = await destProjectService.CreateProjectAsync( sourceProject.Name, sourceProject.Description, destRootProject?.Id ).ConfigureAwait(false); } } else { _logger?.Information($"Project '{projectToMigrate}' found in Tableau destination"); } // create users from source project missing in destination site await MigrateProjectUsersAsync(sourceProject, destProject).ConfigureAwait(false); // create groups from source project missing in destination site await MigrateProjectGroupsAsync(sourceProject, destProject).ConfigureAwait(false); // migrate project permissions await MigrateProjectPermissionsAsync(sourceProject, destProject).ConfigureAwait(false); // migrate project default permissions var resourceTypes = new List <ResourceType>() { ResourceType.Datasource, ResourceType.Workbook }; foreach (var resourceType in resourceTypes) { await MigrateProjectDefaultPermissionsAsync( sourceProject, destProject, resourceType ).ConfigureAwait(false); } await _vizDatasourceService.LoadVizDatasourceReportAsync().ConfigureAwait(false); // migrate project data sources // skip mass migration of datasources, handle as needed on a per-workbook basis //await MigrateProjectDatasourcesAsync(sourceProject, destProject).ConfigureAwait(false); // download project workbooks await DownloadProjectWorkbooksAsync(sourceProject, destProject).ConfigureAwait(false); // migrate project workbooks with embedded datasources await MigrateProjectWorkbooksAsync( sourceProject, destProject, workbooksToMigrate ).ConfigureAwait(false); _logger?.Information($"Completed migration of project {projectToMigrate}"); } // foreach projectToMigrate _logger?.Information("Migration complete"); }
private static async Task <Dictionary <string, TableauUser> > GetProjectUsersWithDomain( string projectId, ITableauServiceFactory serviceFactory ) { var userService = serviceFactory.GetService <TableauUserService>(); var groupService = serviceFactory.GetService <TableauGroupService>(); var permissionService = serviceFactory.GetService <TableauPermissionService>(); var projectUsers = new Dictionary <string, TableauUser>(); // get users defined in project permissions as well as default permissions for datasources, workbooks var permissions = new List <TableauPermission>(); permissions.Add( await permissionService.GetPermissionsAsync( ResourceType.Project, projectId ).ConfigureAwait(false) ); permissions.Add( await permissionService.GetDefaultPermissionsAsync( projectId, ResourceType.Datasource ).ConfigureAwait(false) ); permissions.Add( await permissionService.GetDefaultPermissionsAsync( projectId, ResourceType.Workbook ).ConfigureAwait(false) ); foreach (var permission in permissions) { if (permission.GranteeCapabilities == null) { continue; } foreach (var granteeCapability in permission.GranteeCapabilities) { if (granteeCapability.GranteeType == GranteeType.Group) { // get all users in group individually so user's domain is included if specified (slandron) var members = await userService.GetUsersAsync( granteeCapability.GranteeId ).ConfigureAwait(false); foreach (var member in members) { if (projectUsers.ContainsKey(member.Id)) { continue; } projectUsers.Add( member.Id, await userService.GetUserAsync(member.Id).ConfigureAwait(false) ); } } if (granteeCapability.GranteeType == GranteeType.User && !projectUsers.ContainsKey(granteeCapability.GranteeId)) { projectUsers.Add( granteeCapability.GranteeId, await userService.GetUserAsync(granteeCapability.GranteeId).ConfigureAwait(false) ); } } } return(projectUsers); }