@@ -4984,48 +4984,55 @@ function Global:Get-OciAnnotation {
49844984
49854985<#
49864986 .SYNOPSIS
4987- Update annotation definition by id or name
4987+ Update annotation definition by id
49884988 .DESCRIPTION
4989- Request body could include optional name, description, enum values. Enums should contain name and label. Example: <br/>
4990-
4991- <pre>
4992- {
4993- "name": "MyStorageLocation",
4994- "description": "My Storage Location",
4995- "enumValues": [
4996- {
4997- "name": "PT_LISBON",
4998- "label": "Lisbon (Portugal)"
4999- },
5000- {
5001- "name": "US_WALTHAM",
5002- "label": "Waltham (USA)"
5003- },
5004- {
5005- "name": "US_SUNNYVALE",
5006- "label": "Sunnyvale (USA)"
5007- }
5008- ]
5009- }
5010- </pre>
5011-
5012- .PARAMETER id
5013- Id or name of annotation definition to update
4989+ Update annotation definition by id
50144990 .PARAMETER server
50154991 OCI Server to connect to
4992+ .PARAMETER Id
4993+ Annotation ID to be updated
4994+ .PARAMETER name
4995+ Annotation name
4996+ .PARAMETER type
4997+ Annotation type. Must be either DATE, TEXT, FIXED_ENUM, FLEXIBLE_ENUM, BOOLEAN or NUMBER
4998+ .PARAMETER description
4999+ Annotation description
5000+ .PARAMETER enumValues
5001+ List of name, label pairs for enum types (e.g. @(@{name='name',label='label'}) )
5002+
50165003#>
50175004function Global:Update-OciAnnotation {
50185005 [CmdletBinding()]
50195006
50205007 PARAM (
5021- [parameter(Mandatory=$True,
5022- Position=0,
5023- HelpMessage="Id or name of annotation definition to update",
5024- ValueFromPipeline=$True,
5025- ValueFromPipelineByPropertyName=$True)][String[]]$id,
50265008 [parameter(Mandatory=$False,
5009+ Position=0,
5010+ HelpMessage="OnCommand Insight Server.")]$Server=$CurrentOciServer,
5011+ [parameter(Mandatory=$True,
50275012 Position=1,
5028- HelpMessage="OnCommand Insight Server.")]$Server=$CurrentOciServer
5013+ ValueFromPipeline=$True,
5014+ ValueFromPipelineByPropertyName=$True,
5015+ HelpMessage="Annotation name")][String]$Id,
5016+ [parameter(Mandatory=$False,
5017+ Position=2,
5018+ ValueFromPipeline=$True,
5019+ ValueFromPipelineByPropertyName=$True,
5020+ HelpMessage="Annotation name")][String]$Name,
5021+ [parameter(Mandatory=$False,
5022+ Position=3,
5023+ ValueFromPipeline=$True,
5024+ ValueFromPipelineByPropertyName=$True,
5025+ HelpMessage="Annotation type. Must be either DATE, TEXT, FIXED_ENUM, FLEXIBLE_ENUM, BOOLEAN or NUMBER")][ValidateSet("DATE","TEXT","FIXED_ENUM","FLEXIBLE_ENUM","BOOLEAN","NUMBER")][String]$Type,
5026+ [parameter(Mandatory=$False,
5027+ Position=4,
5028+ ValueFromPipeline=$True,
5029+ ValueFromPipelineByPropertyName=$True,
5030+ HelpMessage="Annotation description.")][String]$Description,
5031+ [parameter(Mandatory=$False,
5032+ Position=5,
5033+ ValueFromPipeline=$True,
5034+ ValueFromPipelineByPropertyName=$True,
5035+ HelpMessage="List of name, label pairs for enum types (e.g. @(@{name='name',label='label'}) )")][PSCustomObject[]]$enumValues
50295036 )
50305037
50315038 Begin {
@@ -5036,27 +5043,28 @@ function Global:Update-OciAnnotation {
50365043 }
50375044
50385045 Process {
5039- $id = @($id)
5040- foreach ($id in $id) {
5041- $Uri = $Server.BaseUri + "/rest/v1/assets/annotations/$id"
5046+ $Uri = $Server.BaseUri + "/rest/v1/assets/annotations/$Id"
5047+ $Method = "PATCH"
50425048
5043- $Body = ""
5044-
5045- try {
5046- Write-Verbose "Body: $Body"
5047- $Result = Invoke-RestMethod -WebSession $Server.Session -TimeoutSec $Server.Timeout -Method PATCH -Uri $Uri -Headers $Server.Headers -Body $Body -ContentType 'application/json'
5048- }
5049- catch {
5050- $ResponseBody = ParseExceptionBody -Response $_.Exception.Response
5051- Write-Error "PATCH to $Uri failed with Exception $($_.Exception.Message) `n $responseBody"
5052- }
5049+ if ($type -match "ENUM" -and -not $enumValues) {
5050+ throw "$type specified, but no enumValues provided"
5051+ }
50535052
5054- if (([String]$Result).Trim().startsWith('{') -or ([String]$Result).toString().Trim().startsWith('[')) {
5055- $Result = ParseJsonString -json $Result.Trim()
5056- }
5053+ try {
5054+ $Body = ConvertTo-Json @{name=$name;type=$type;description=$description;enumValues=$enumValues} -Compress -Depth 4
5055+ Write-Verbose "Body: $Body"
5056+ $Result = Invoke-RestMethod -WebSession $Server.Session -TimeoutSec $Server.Timeout -Method $Method -Uri $Uri -Headers $Server.Headers -Body ([System.Text.Encoding]::UTF8.GetBytes($Body)) -ContentType 'application/json'
5057+ }
5058+ catch {
5059+ $ResponseBody = ParseExceptionBody -Response $_.Exception.Response
5060+ Write-Error "POST to $Uri failed with Exception $($_.Exception.Message) `n $responseBody"
5061+ }
50575062
5058- Write-Output $Result
5063+ if (([String]$Result).Trim().startsWith('{') -or ([String]$Result).toString().Trim().startsWith('[')) {
5064+ $Result = ParseJsonString -json $Result.Trim()
50595065 }
5066+
5067+ Write-Output $Result
50605068 }
50615069}
50625070
0 commit comments