Private/ConvertTo-Page.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function ConvertTo-Page {
    <#
    .SYNOPSIS
    Extracted the conversion to private function in order to have a single place to
    select the properties to use when casting to custom object type
    #>

    [CmdletBinding()]
    [OutputType( [ConfluencePS.Page] )]
    param (
        # object to convert
        [Parameter( Position = 0, ValueFromPipeline = $true )]
        $InputObject
    )

    Process {
        foreach ($object in $InputObject) {
            Write-Verbose "[$($MyInvocation.MyCommand.Name)] Converting Object to Page"
            ($object | Select-Object `
                id,
                status,
                title,
                @{Name = "space"; Expression = {
                        if ($_.space) {
                            ConvertTo-Space $_.space
                        }
                        else {$null}
                    }
                },
                @{Name = "version"; Expression = {
                        if ($_.version) {
                            ConvertTo-Version $_.version
                        }
                        else {$null}
                    }
                },
                @{Name = "body"; Expression = {$_.body.storage.value}},
                @{Name = "ancestors"; Expression = {
                        if ($_.ancestors) {
                            ConvertTo-PageAncestor $_.ancestors
                        }
                        else {$null}
                    }
                },
                @{Name = "URL"; Expression = {
                        if ($_._links.webui) {
                            "{0}{1}" -f $_._links.base, $_._links.webui
                        }
                        else {$null}
                    }
                },
                @{Name = "ShortURL"; Expression = {
                        if ($_._links.tinyui) {
                            "{0}{1}" -f $_._links.base, $_._links.tinyui
                        }
                        else {$null}
                    }
                }
            ) -as [ConfluencePS.Page]
        }
    }
}