Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function Set-RsRestItemDataSource
Description
-----------
Updates data sources to the specified $dataSources object. This example is only applicable to Paginated Reports.

.LINK
https://docs.microsoft.com/en-us/power-bi/report-server/connect-data-source-apis-pre-oct-2020
#>
Expand Down Expand Up @@ -140,7 +140,7 @@ function Set-RsRestItemDataSource
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$dataSourcesUri = $ReportPortalUri + "api/$RestApiVersion/{0}(Path='{1}')/DataSources"
Expand Down Expand Up @@ -177,33 +177,35 @@ function Set-RsRestItemDataSource
}
elseif ($ds.DataSourceSubType -eq $null)
{
# DataSourceType, ConnectionString and CredentialRetrieval must always be specified!
if ($ds.DataSourceType -eq $null -or
$ds.ConnectionString -eq $null -or
$ds.CredentialRetrieval -eq $null -or
!($ds.CredentialRetrieval -LIKE 'Integrated' -or
$ds.CredentialRetrieval -LIKE 'Store' -or
$ds.CredentialRetrieval -LIKE 'Prompt' -or
$ds.CredentialRetrieval -LIKE 'None'))
{
throw "Invalid data source specified: $ds!"
}
elseif ($ds.DataModelDataSource -ne $null)
{
# since this is an embedded data source for Paginated Report/Shared data set,
# you should not set any value to DataModelDataSource
throw "You cannot specify DataModelDataSource for this datasource: $ds!"
}

if ($ds.CredentialRetrieval -LIKE 'Store' -and $ds.CredentialsInServer -eq $null)
{
# CredentialsInServer must be specified for Store
throw "CredentialsInServer must be specified when CredentialRetrieval is set to Store: $ds!"
}
elseif ($ds.CredentialRetrieval -LIKE 'Prompt' -and $ds.CredentialsByUser -eq $null)
{
# CredentialsByUser must be specified for Prompt
throw "CredentialsByUser must be specified when CredentialRetrieval is set to Prompt: $ds!"
if (!$ds.IsReference) {
# DataSourceType, ConnectionString and CredentialRetrieval must always be specified!
if ($ds.DataSourceType -eq $null -or
$ds.ConnectionString -eq $null -or
$ds.CredentialRetrieval -eq $null -or
!($ds.CredentialRetrieval -LIKE 'Integrated' -or
$ds.CredentialRetrieval -LIKE 'Store' -or
$ds.CredentialRetrieval -LIKE 'Prompt' -or
$ds.CredentialRetrieval -LIKE 'None'))
{
throw "Invalid data source specified: $ds!"
}
elseif ($ds.DataModelDataSource -ne $null)
{
# since this is an embedded data source for Paginated Report/Shared data set,
# you should not set any value to DataModelDataSource
throw "You cannot specify DataModelDataSource for this datasource: $ds!"
}

if ($ds.CredentialRetrieval -LIKE 'Store' -and $ds.CredentialsInServer -eq $null)
{
# CredentialsInServer must be specified for Store
throw "CredentialsInServer must be specified when CredentialRetrieval is set to Store: $ds!"
}
elseif ($ds.CredentialRetrieval -LIKE 'Prompt' -and $ds.CredentialsByUser -eq $null)
{
# CredentialsByUser must be specified for Prompt
throw "CredentialsByUser must be specified when CredentialRetrieval is set to Prompt: $ds!"
}
}
}
else
Expand Down
67 changes: 66 additions & 1 deletion Tests/CatalogItems/Rest/Set-RsRestItemDataSource.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,38 @@ Describe "Set-RsRestItemDataSource" {
$fetchedDataSources = Get-RsRestItemDataSource -ReportPortalUri $reportPortalUri -RsItem $datasourcesReport
$fetchedDataSources[0].CredentialRetrieval | Should Be "None"
}

It "Updates linked datasource" {
# uploading datasourceReport.rdl
Write-RsRestCatalogItem -ReportPortalUri $reportPortalUri -Path "$localPath\linkedDatasources\datasourcesReportLinkedDS.rdl" -RsFolder $rsFolderPath
Write-RsRestCatalogItem -ReportPortalUri $reportPortalUri -Path "$localPath\linkedDatasources\dsMaster.rsds" -RsFolder $rsFolderPath
Write-RsRestCatalogItem -ReportPortalUri $reportPortalUri -Path "$localPath\linkedDatasources\dsModel.rsds" -RsFolder $rsFolderPath
$datasourcesReport = "$rsFolderPath/datasourcesReportLinkedDS"

$datasources = Get-RsRestItemDataSource -ReportPortalUri $reportPortalUri -RsItem $datasourcesReport
$datasources.Count | Should -Be 2
$datasources[0].IsReference | Should -BeTrue
$datasources[1].IsReference | Should -BeTrue
$datasources[0].Id | Should -Be "00000000-0000-0000-0000-000000000000"
$datasources[1].Id | Should -Be "00000000-0000-0000-0000-000000000000"

# now set the second to a valid path
$datasources[0].Path = "$rsFolderPath/DSmaster"
$datasources[1].Path = "$rsFolderPath/DSmodel"

Set-RsRestItemDataSource -ReportPortalUri $reportPortalUri -RsItem $datasourcesReport -RsItemType Report -DataSources $datasources -Verbose

$fetchedDataSources = Get-RsRestItemDataSource -ReportPortalUri $reportPortalUri -RsItem $datasourcesReport
$fetchedDataSources | Should -HaveCount 2
$fetchedDataSources[0].Path | Should -Be "$rsFolderPath/DSmaster"
$fetchedDataSources[1].Path | Should -Be "$rsFolderPath/DSmodel"
$fetchedDataSources[0].Id | Should -Not -Be "00000000-0000-0000-0000-000000000000"
$fetchedDataSources[1].Id | Should -Not -Be "00000000-0000-0000-0000-000000000000"
# remove test items
Remove-RsRestCatalogItem -ReportPortalUri $reportPortalUri -RsItem $datasourcesReport -Confirm:$false
Remove-RsRestCatalogItem -ReportPortalUri $reportPortalUri -RsItem "$rsFolderPath/DSmaster" -Confirm:$false
Remove-RsRestCatalogItem -ReportPortalUri $reportPortalUri -RsItem "$rsFolderPath/DSmodel" -Confirm:$false
}
}

Context "ReportPortalUri parameter - Power BI Reports" {
Expand Down Expand Up @@ -379,9 +411,42 @@ Describe "Set-RsRestItemDataSource" {
$fetchedDataSources = Get-RsRestItemDataSource -WebSession $rsSession -RsItem $datasourcesReport
$fetchedDataSources[0].CredentialRetrieval | Should Be "None"
}

It "Updates linked datasource" {
# uploading datasourceReport.rdl
Write-RsRestCatalogItem -WebSession $rsSession -Path "$localPath\linkedDatasources\datasourcesReportLinkedDS.rdl" -RsFolder $rsFolderPath
Write-RsRestCatalogItem -WebSession $rsSession -Path "$localPath\linkedDatasources\dsMaster.rsds" -RsFolder $rsFolderPath
Write-RsRestCatalogItem -WebSession $rsSession -Path "$localPath\linkedDatasources\dsModel.rsds" -RsFolder $rsFolderPath
$datasourcesReport = "$rsFolderPath/datasourcesReportLinkedDS"

$datasources = Get-RsRestItemDataSource -WebSession $rsSession -RsItem $datasourcesReport
$datasources.Count | Should -Be 2
$datasources[0].IsReference | Should -BeTrue
$datasources[1].IsReference | Should -BeTrue
$datasources[0].Id | Should -Be "00000000-0000-0000-0000-000000000000"
$datasources[1].Id | Should -Be "00000000-0000-0000-0000-000000000000"

# now set the second to a valid path
$datasources[0].Path = "$rsFolderPath/DSmaster"
$datasources[1].Path = "$rsFolderPath/DSmodel"

Set-RsRestItemDataSource -WebSession $rsSession -RsItem $datasourcesReport -RsItemType Report -DataSources $datasources -Verbose

$fetchedDataSources = Get-RsRestItemDataSource -WebSession $rsSession -RsItem $datasourcesReport
$fetchedDataSources | Should -HaveCount 2
$fetchedDataSources[0].Path | Should -Be "$rsFolderPath/DSmaster"
$fetchedDataSources[1].Path | Should -Be "$rsFolderPath/DSmodel"
$fetchedDataSources[0].Id | Should -Not -Be "00000000-0000-0000-0000-000000000000"
$fetchedDataSources[1].Id | Should -Not -Be "00000000-0000-0000-0000-000000000000"

# remove test items
Remove-RsRestCatalogItem -WebSession $rsSession -RsItem $datasourcesReport -Confirm:$false
Remove-RsRestCatalogItem -WebSession $rsSession -RsItem "$rsFolderPath/DSmaster" -Confirm:$false
Remove-RsRestCatalogItem -WebSession $rsSession -RsItem "$rsFolderPath/DSmodel" -Confirm:$false
}
}

Context "ReportPortalUri parameter - Power BI Reports" {
Context "WebSession parameter - Power BI Reports" {
$sqlPowerBIReport = ""

BeforeEach {
Expand Down
13 changes: 7 additions & 6 deletions Tests/CatalogItems/Write-RsFolderContent.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,21 @@ Describe "Write-RsFolderContent" {
Write-RsFolderContent -Path $localReportPath -RsFolder $folderPath -Recurse
It "Should upload a local subFolder with Recurse Parameter" {
$uploadedFolders = (Get-RsFolderContent -RsFolder $folderPath -Recurse ) | Where-Object TypeName -eq 'Folder' | Sort-Object -Property Name -Descending
$uploadedFolders.Count | Should Be 3
$uploadedFolders.Count | Should Be 4
$uploadedFolders[0].Name | Should Be 'testResources2'
$uploadedFolders[1].Name | Should Be 'imagesResources'
$uploadedFolders[2].Name | Should Be 'datasources'
$uploadedFolders[1].Name | Should Be 'linkedDatasources'
$uploadedFolders[2].Name | Should Be 'imagesResources'
$uploadedFolders[3].Name | Should Be 'datasources'
}

It "Should upload a report that is in a folder and a second report that is in a subfolder" {
$uploadedReports = (Get-RsFolderContent -RsFolder $folderPath -Recurse ) | Where-Object TypeName -eq 'Report'
$uploadedReports.Count | Should Be 4
$uploadedReports.Count | Should Be 5
}

It "Should upload a local RsDataSource in Report Server" {
It "Should upload local RsDataSources in Report Server" {
$uploadedDataSource = (Get-RsFolderContent -RsFolder $folderPath -Recurse ) | Where-Object TypeName -eq 'DataSource'
$uploadedDataSource.Name | Should Be 'SutWriteRsFolderContent_DataSource'
$uploadedDataSource | ForEach-Object { $_.Name | Should BeIn 'SutWriteRsFolderContent_DataSource', 'dsMaster','dsModel' }
}

It "Should upload a local DataSet in Report Server" {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="utf-8"?>
<Report MustUnderstand="df" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:df="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition/defaultfontfamily">
<df:DefaultFontFamily>Segoe UI</df:DefaultFontFamily>
<AutoRefresh>0</AutoRefresh>
<DataSources>
<DataSource Name="master">
<DataSourceReference>DSmaster</DataSourceReference>
<rd:SecurityType>None</rd:SecurityType>
<rd:DataSourceID>24e9bb1a-7346-4007-9ff9-5bec2e485891</rd:DataSourceID>
</DataSource>
<DataSource Name="model">
<DataSourceReference>DSinvalid</DataSourceReference>
<rd:SecurityType>None</rd:SecurityType>
<rd:DataSourceID>19977be0-7084-48d9-a184-659be45fb3fd</rd:DataSourceID>
</DataSource>
</DataSources>
<ReportSections>
<ReportSection>
<Body>
<ReportItems>
<Textbox Name="ReportTitle">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value />
<Style>
<FontFamily>Segoe UI Light</FontFamily>
<FontSize>28pt</FontSize>
</Style>
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:WatermarkTextbox>Title</rd:WatermarkTextbox>
<rd:DefaultName>ReportTitle</rd:DefaultName>
<Height>0.5in</Height>
<Width>5.5in</Width>
<Style>
<Border>
<Style>None</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</ReportItems>
<Height>2.25in</Height>
<Style>
<Border>
<Style>None</Style>
</Border>
</Style>
</Body>
<Width>6in</Width>
<Page>
<PageFooter>
<Height>0.45in</Height>
<PrintOnFirstPage>true</PrintOnFirstPage>
<PrintOnLastPage>true</PrintOnLastPage>
<ReportItems>
<Textbox Name="ExecutionTime">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Globals!ExecutionTime</Value>
<Style />
</TextRun>
</TextRuns>
<Style>
<TextAlign>Right</TextAlign>
</Style>
</Paragraph>
</Paragraphs>
<rd:DefaultName>ExecutionTime</rd:DefaultName>
<Top>0.2in</Top>
<Left>4in</Left>
<Height>0.25in</Height>
<Width>2in</Width>
<Style>
<Border>
<Style>None</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</ReportItems>
<Style>
<Border>
<Style>None</Style>
</Border>
</Style>
</PageFooter>
<LeftMargin>1in</LeftMargin>
<RightMargin>1in</RightMargin>
<TopMargin>1in</TopMargin>
<BottomMargin>1in</BottomMargin>
<Style />
</Page>
</ReportSection>
</ReportSections>
<ReportParametersLayout>
<GridLayoutDefinition>
<NumberOfColumns>4</NumberOfColumns>
<NumberOfRows>2</NumberOfRows>
</GridLayoutDefinition>
</ReportParametersLayout>
<rd:ReportUnitType>Inch</rd:ReportUnitType>
<rd:ReportID>68930910-5594-43ac-aed6-c0d26ea291b9</rd:ReportID>
</Report>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<DataSourceDefinition>
<Extension>SQL</Extension>
<ConnectString>Data Source=localhost;Initial Catalog=master</ConnectString>
<UseOriginalConnectString>False</UseOriginalConnectString>
<OriginalConnectStringExpressionBased>False</OriginalConnectStringExpressionBased>
<CredentialRetrieval>Integrated</CredentialRetrieval>
<Enabled>True</Enabled>
</DataSourceDefinition>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<DataSourceDefinition>
<Extension>SQL</Extension>
<ConnectString>Data Source=localhost;Initial Catalog=model</ConnectString>
<UseOriginalConnectString>False</UseOriginalConnectString>
<OriginalConnectStringExpressionBased>False</OriginalConnectStringExpressionBased>
<CredentialRetrieval>Integrated</CredentialRetrieval>
<Enabled>True</Enabled>
</DataSourceDefinition>