diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/AddIshBackgroundTask.Tests.ps1 b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/AddIshBackgroundTask.Tests.ps1
new file mode 100644
index 00000000..2e8f4203
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/AddIshBackgroundTask.Tests.ps1
@@ -0,0 +1,172 @@
+BeforeAll {
+ $cmdletName = "Add-IshBackgroundTask"
+ Write-Host ("`r`nLoading ISHRemote.PesterSetup.ps1 over BeforeAll-block for MyCommand[" + $cmdletName + "]...")
+ . (Join-Path (Split-Path -Parent $PSCommandPath) "\..\..\ISHRemote.PesterSetup.ps1")
+
+ Write-Host ("Running "+$cmdletName+" Test Data and Variables initialization")
+}
+
+Describe "Add-IshBackgroundTask" -Tags "Create" {
+ BeforeAll {
+ $ishFolderTestRootOriginal = Get-IshFolder -IShSession $ishSession -FolderPath $folderTestRootPath
+ $folderIdTestRootOriginal = $ishFolderTestRootOriginal.IshFolderRef
+ $folderTypeTestRootOriginal = $ishFolderTestRootOriginal.IshFolderType
+ $ownedByTestRootOriginal = $ishFolderTestRootOriginal.fusergroup_none_element
+ $readAccessTestRootOriginal = $ishFolderTestRootOriginal.readaccess_none_element
+
+ Write-Debug("folderIdTestRootOriginal[" + $ishFolderTestRootOriginal.IshFolderRef + "] folderTypeTestRootOriginal[" + $folderTypeTestRootOriginal + "]")
+ $global:ishBackgroundTaskCmdlet = Add-IshFolder -IShSession $ishSession -ParentFolderId $folderIdTestRootOriginal -FolderType $folderTypeTestRootOriginal -FolderName $cmdletName -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+ $ishFolderTopic = Add-IshFolder -IshSession $ishSession -ParentFolderId($global:ishBackgroundTaskCmdlet.IshFolderRef) -FolderType ISHModule -FolderName "Topic" -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Topic $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+
+ $ishObjectTopic1_1 = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -LogicalId "ISHREMOTE-LOGICALID-TOPIC-FORADDBT1" -Version '1' -Lng $ishLng -Metadata $ishTopicMetadata -Edt "EDTXML" -FileContent $ditaTopicFileContent
+ $ishObjectTopic1_2 = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -LogicalId "ISHREMOTE-LOGICALID-TOPIC-FORADDBT1" -Version '2' -Lng $ishLng -Metadata $ishTopicMetadata -Edt "EDTXML" -FileContent $ditaTopicFileContent
+ $ishObjectTopic1_3 = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -LogicalId "ISHREMOTE-LOGICALID-TOPIC-FORADDBT1" -Version '3' -Lng $ishLng -Metadata $ishTopicMetadata -Edt "EDTXML" -FileContent $ditaTopicFileContent
+
+ $ishObjectTopic2_1 = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -LogicalId "ISHREMOTE-LOGICALID-TOPIC-FORADDBT2" -Version '1' -Lng $ishLng -Metadata $ishTopicMetadata -Edt "EDTXML" -FileContent $ditaTopicFileContent
+ $ishObjectTopic2_2 = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -LogicalId "ISHREMOTE-LOGICALID-TOPIC-FORADDBT2" -Version '2' -Lng $ishLng -Metadata $ishTopicMetadata -Edt "EDTXML" -FileContent $ditaTopicFileContent
+ $ishObjectTopic2_3 = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -LogicalId "ISHREMOTE-LOGICALID-TOPIC-FORADDBT2" -Version '3' -Lng $ishLng -Metadata $ishTopicMetadata -Edt "EDTXML" -FileContent $ditaTopicFileContent
+
+ $ishObjectTopic3_1 = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -LogicalId "ISHREMOTE-LOGICALID-TOPIC-FORADDBT3" -Version '1' -Lng $ishLng -Metadata $ishTopicMetadata -Edt "EDTXML" -FileContent $ditaTopicFileContent
+ $ishObjectTopic3_2 = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -LogicalId "ISHREMOTE-LOGICALID-TOPIC-FORADDBT3" -Version '2' -Lng $ishLng -Metadata $ishTopicMetadata -Edt "EDTXML" -FileContent $ditaTopicFileContent
+ $ishObjectTopic3_3 = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -LogicalId "ISHREMOTE-LOGICALID-TOPIC-FORADDBT3" -Version '3' -Lng $ishLng -Metadata $ishTopicMetadata -Edt "EDTXML" -FileContent $ditaTopicFileContent
+ $ishObjectTopic3_4 = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -LogicalId "ISHREMOTE-LOGICALID-TOPIC-FORADDBT3" -Version '4' -Lng $ishLng -Metadata $ishTopicMetadata -Edt "EDTXML" -FileContent $ditaTopicFileContent
+
+ $ishObjects = $ishFolderTopic | Get-IshFolderContent -IshSession $ishSession -VersionFilter ""
+ $createdLngRefs = $ishObjects | select -ExpandProperty LngRef
+ }
+ Context "Add-IshBackgroundTask IshObjectsGroup Parameter IshObject with implicit IshSession since 14SP4/14.0.4" {
+ if (([Version]$ishSession.ServerVersion).Major -ge 15 -or (([Version]$ishSession.ServerVersion).Major -ge 14 -and ([Version]$ishSession.ServerVersion).Revision -ge 4)) {
+ It "Parameter IshObject invalid" {
+ { Add-IshBackgroundTask -EventType $ishEventTypeToPurge -IshObject "INVALIDISHOBJECT" } | Should -Throw
+ }
+ It "Parameter EventType null" {
+ { Add-IshBackgroundTask -EventType $null -IshObject $ishObjects } | Should -Throw
+ }
+ It "Pipeline IshObject Single" {
+ $ishBackgroundTaskIshObjectsParameter = Add-IshBackgroundTask -EventType $ishEventTypeToPurge -IshObject $ishObjectTopic1_1
+ $ishObjectTopic1_1.Count | Should -BeExactly 1
+ $ishBackgroundTaskIshObjectsParameter.Count | Should -BeExactly 1
+ $ishBackgroundTaskIshObjectsParameter.GetType() | Should -BeExactly Trisoft.ISHRemote.Objects.Public.IshBackgroundTask
+ $ishBackgroundTaskIshObjectsParameter.EventType | Should -BeExactly $ishEventTypeToPurge
+ $ishBackgroundTaskIshObjectsParameter.userid | Should -BeExactly $ishSession.UserName
+ }
+ It "Pipeline IshObject Multiple" {
+ $ishBackgroundTaskIshObjectsParameter = Add-IshBackgroundTask -EventType $ishEventTypeToPurge -IshObject $ishObjects
+ $ishBackgroundTaskIshObjectsParameter.Count | Should -BeExactly 1
+ $ishBackgroundTaskIshObjectsParameter.GetType() | Should -BeExactly Trisoft.ISHRemote.Objects.Public.IshBackgroundTask
+ $ishBackgroundTaskIshObjectsParameter.EventType | Should -BeExactly $ishEventTypeToPurge
+ $ishBackgroundTaskIshObjectsParameter.userid | Should -BeExactly $ishSession.UserName
+ }
+ }
+ }
+
+ Context "Add-IshBackgroundTask IshObjectsGroup Pipeline IshObject since 14SP4/14.0.4" {
+ BeforeAll {
+ if (([Version]$ishSession.ServerVersion).Major -ge 15 -or (([Version]$ishSession.ServerVersion).Major -ge 14 -and ([Version]$ishSession.ServerVersion).Revision -ge 4)) {
+ $ishBackgroundTaskIshObjectsPipeline = $ishObjects | Add-IshBackgroundTask -IshSession $ishSession -EventType $ishEventTypeToPurge
+ }
+ $savedMetadataBatchSize = $ishSession.MetadataBatchSize
+ }
+ It "Add-IshBackgroundTask returns IshBackgroundTask object" {
+ if (([Version]$ishSession.ServerVersion).Major -ge 15 -or (([Version]$ishSession.ServerVersion).Major -ge 14 -and ([Version]$ishSession.ServerVersion).Revision -ge 4)) {
+ $ishObjects.Count | Should -BeExactly 10
+ $ishBackgroundTaskIshObjectsPipeline.Count | Should -BeExactly 1
+ $ishBackgroundTaskIshObjectsPipeline.GetType().Name | Should -BeExactly "IshBackgroundTask"
+ $ishBackgroundTaskIshObjectsPipeline.EventType | Should -BeExactly $ishEventTypeToPurge
+ $ishBackgroundTaskIshObjectsPipeline.userid | Should -BeExactly $ishSession.UserName
+ }
+ }
+ It "Pipeline IshObject Single" {
+ if (([Version]$ishSession.ServerVersion).Major -ge 15 -or (([Version]$ishSession.ServerVersion).Major -ge 14 -and ([Version]$ishSession.ServerVersion).Revision -ge 4)) {
+ $ishBackgroundTaskIshObjectsPipeline = $ishObjectTopic1_1 | Add-IshBackgroundTask -IshSession $ishSession -EventType $ishEventTypeToPurge
+ $ishObjectTopic1_1.Count | Should -BeExactly 1
+ $ishBackgroundTaskIshObjectsPipeline.Count | Should -BeExactly 1
+ $ishBackgroundTaskIshObjectsPipeline.GetType().Name | Should -BeExactly "IshBackgroundTask"
+ $ishBackgroundTaskIshObjectsPipeline.EventType | Should -BeExactly $ishEventTypeToPurge
+ $ishBackgroundTaskIshObjectsPipeline.userid | Should -BeExactly $ishSession.UserName
+ }
+ }
+ It "Pipeline IshObject MetadataBatchSize[2] with LogicalId grouping" {
+ if (([Version]$ishSession.ServerVersion).Major -ge 15 -or (([Version]$ishSession.ServerVersion).Major -ge 14 -and ([Version]$ishSession.ServerVersion).Revision -ge 4)) {
+ $ishSession.MetadataBatchSize = 2
+ $ishBackgroundTasks = $ishObjects | Add-IshBackgroundTask -IshSession $ishSession -EventType $ishEventTypeToPurge
+ $ishBackgroundTasks.Count | Should -BeExactly 3
+ }
+ }
+ It "Pipeline IshObject MetadataBatchSize[4] with LogicalId grouping" {
+ if (([Version]$ishSession.ServerVersion).Major -ge 15 -or (([Version]$ishSession.ServerVersion).Major -ge 14 -and ([Version]$ishSession.ServerVersion).Revision -ge 4)) {
+ $ishSession.MetadataBatchSize = 4
+ $ishBackgroundTasks = $ishObjects | Add-IshBackgroundTask -IshSession $ishSession -EventType $ishEventTypeToPurge
+ $ishBackgroundTasks.Count | Should -BeExactly 3
+ }
+ }
+ It "Pipeline IshObject MetadataBatchSize[6] with LogicalId grouping" {
+ if (([Version]$ishSession.ServerVersion).Major -ge 15 -or (([Version]$ishSession.ServerVersion).Major -ge 14 -and ([Version]$ishSession.ServerVersion).Revision -ge 4)) {
+ $ishSession.MetadataBatchSize = 6
+ $ishBackgroundTasks = $ishObjects | Add-IshBackgroundTask -IshSession $ishSession -EventType $ishEventTypeToPurge
+ $ishBackgroundTasks.Count | Should -BeExactly 2
+ }
+ }
+ It "Pipeline IshObject MetadataBatchSize[10] with LogicalId grouping" {
+ if (([Version]$ishSession.ServerVersion).Major -ge 15 -or (([Version]$ishSession.ServerVersion).Major -ge 14 -and ([Version]$ishSession.ServerVersion).Revision -ge 4)) {
+ $ishSession.MetadataBatchSize = 10
+ $ishBackgroundTasks = $ishObjects | Add-IshBackgroundTask -IshSession $ishSession -EventType $ishEventTypeToPurge
+ $ishBackgroundTasks.Count | Should -BeExactly 1
+ }
+ }
+ AfterAll {
+ $ishSession.MetadataBatchSize = $savedMetadataBatchSize
+ }
+ }
+
+ Context "Add-IshBackgroundTask ParameterGroup" {
+ BeforeAll {
+ # If you get the below error, it means you configured default purge operation $ishEventTypetoPurge (defaults to PUSHTRANSLATIONS in ISHRemote.PesterSetup.ps1) away
+ # FaultException`1: [-105001] The parameter eventType with value "PUSHTRANSLATIONS" is invalid. Make sure a handler with the eventType is configured in the Background Task Configuration XML [105001;InvalidParameter]
+ $rawData = "Text"
+ $eventDescription = "Created by Powershell and ISHRemote"
+ $ishBackgroundTaskParameters = Add-IshBackgroundTask -EventType $ishEventTypeToPurge -EventDescription $eventDescription -RawInputData $rawData
+ }
+ It "Add-IshBackgroundTask returns IshBackgroundTask object" {
+ $ishBackgroundTaskParameters.Count | Should -BeExactly 1
+ $ishBackgroundTaskParameters.GetType().Name | Should -BeExactly "IshBackgroundTask"
+ $ishBackgroundTaskParameters.EventType | Should -BeExactly $ishEventTypeToPurge
+ $ishBackgroundTaskParameters.userid | Should -BeExactly $ishSession.UserName
+ }
+ It "Parameter EventDescription null" {
+ { Add-IshBackgroundTask -EventType $ishEventTypeToPurge -EventDescription $null -RawInputData $rawData } | Should -Throw
+ }
+ It "Parameter EventType null" {
+ { Add-IshBackgroundTask -EventType $null -EventDescription $eventDescription -RawInputData $rawData } | Should -Throw
+ }
+ It "Parameter RawInputData null" {
+ { Add-IshBackgroundTask -EventType $ishEventTypeToPurge -EventDescription $eventDescription -RawInputData $null } | Should -Throw
+ }
+ It "Parameter StartAfter Tommorrow" {
+ $dateTomorrow = (Get-Date).AddDays(1)
+ $ishBackgroundTaskStartsAfter = Add-IshBackgroundTask -EventType $ishEventTypeToPurge -EventDescription ($eventDescription + " StartAfter") -RawInputData $rawData -StartAfter $dateTomorrow
+ $ishBackgroundTaskStartsAfter.Count | Should -BeExactly 1
+ ($ishBackgroundTaskStartsAfter.executeafterdate -eq $ishBackgroundTaskStartsAfter.creationdate) | Should -Be $false
+ $ishBackgroundTaskStartsAfter.GetType().Name | Should -BeExactly "IshBackgroundTask"
+ $ishBackgroundTaskStartsAfter.EventType | Should -BeExactly $ishEventTypeToPurge
+ $ishBackgroundTaskStartsAfter.userid | Should -BeExactly $ishSession.UserName
+ # Verify returned submitted IshBackgroundTask.StartsAfter date matches provided tomorrow StartsAfter
+ $retrievedExecuteAfter = New-Object DateTime
+ $conversionResult = [DateTime]::TryParseExact($ishBackgroundTaskStartsAfter.executeafterdate, "yyyy-MM-ddTHH:mm:ss", [System.Globalization.CultureInfo]::InvariantCulture, [System.Globalization.DateTimeStyles]::None, [ref]$retrievedExecuteAfter)
+ $conversionResult | Should -BeExactly $true
+ $retrievedExecuteAfter.ToString("dd/MM/yyyy") | Should -BeExactly $dateTomorrow.ToString("dd/MM/yyyy")
+ }
+ }
+}
+
+AfterAll {
+ Write-Host ("Running "+$cmdletName+" Test Data and Variables cleanup")
+ $folderCmdletRootPath = (Join-Path $folderTestRootPath $cmdletName)
+ try { Get-IshFolder -IshSession $ishSession -FolderPath $folderCmdletRootPath -Recurse | Get-IshFolderContent -IshSession $ishSession -VersionFilter "" | Remove-IshDocumentObj -IshSession $ishSession -Force } catch { }
+ try { Remove-IshFolder -IshSession $ishSession -FolderPath $folderCmdletRootPath -Recurse } catch { }
+}
+
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/AddIshBackgroundTask.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/AddIshBackgroundTask.cs
new file mode 100644
index 00000000..2bca892d
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/AddIshBackgroundTask.cs
@@ -0,0 +1,294 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Management.Automation;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+using Trisoft.ISHRemote.Exceptions;
+using Trisoft.ISHRemote.HelperClasses;
+using System.Linq;
+using Trisoft.ISHRemote.BackgroundTask25ServiceReference;
+using Trisoft.ISHRemote.EventMonitor25ServiceReference;
+using System.Text;
+
+namespace Trisoft.ISHRemote.Cmdlets.BackgroundTask
+{
+ ///
+ /// The Add-IshBackgroundTask cmdlet add fire-and-forget asynchronous processing events to the CMS generic queuing system.
+ /// Add-IshBackgroundTask ParameterGroup variation uses BackgroundTask25.CreateBackgroundTask(WithStartAfter) that allows you to submit generic messages. Note that this requires a generic BackgroundTask service message handler.
+ /// Add-IshBackgroundTask IshObjectsGroup requires content object(s) which are transformed as message inputdata and passed to DocumentObj25.RaiseEventByIshLngRefs. This function will server-side validate the incoming objects and trigger an internal BackgroundTask25.CreateBackgroundTask.
+ ///
+ ///
+ ///
+ /// New-IshSession -WsBaseUrl "https://example.com/ISHWS/" -PSCredential "Admin"
+ /// $ishBackgroundTask = Get-IshFolderContent -FolderPath "General\MyFolder\Topics" -VersionFilter Latest -LanguagesFilter en |
+ /// Add-IshBackgroundTask -EventType "SMARTTAG"
+ ///
+ /// Add BackgroundTask with event type "SMARTTAG" for the objects located under the "General\MyFolder\Topics" path
+ ///
+ ///
+ ///
+ /// New-IshSession -WsBaseUrl "https://example.com/ISHWS/" -PSCredential "Admin"
+ /// $ishBackgroundTask = Get-IshFolder -FolderPath "General\Myfolder" -FolderTypeFilter @("ISHModule", "ISHMasterDoc", "ISHLibrary") -Recurse |
+ /// Get-IshFolderContent -VersionFilter Latest -LanguagesFilter en |
+ /// Add-IshBackgroundTask -EventType "SMARTTAG"
+ ///
+ /// Add BackgroundTask with event type "SMARTTAG" for the latest-version en(glish) content objects of type topic, map and topic library; located under the "General\MyFolder" path. Trigger a legacy correction event of SMARTTAG across many folders. Note that Get-IshFolder gives you a progress bar for follow-up. Note that it is possible to configure the BackgroundTask-handler with a variation of the SMARTTAG event to do more-or-less fields for automatic concept suggestions.
+ ///
+ ///
+ ///
+ /// New-IshSession -WsBaseUrl "https://example.com/ISHWS/" -PSCredential "Admin"
+ /// $rawData = "<data><export-document-type>ISHPublication</export-document-type><export-document-level>lng</export-document-level><export-ishlngref>549482</export-ishlngref><creationdate>20210303070257182</creationdate></data>"
+ /// $ishBackgroundTask = Add-IshBackgroundTask -EventType "PUBLISH" -EventDescription "Custom publish event description" -RawInputData $rawData
+ ///
+ /// Add background task with the event type "PUBLISH" and provided event description and publish input raw data. Note: example code only, for publish operations usage of Publish-IshPublicationOutput cmdlet is preferred.
+ ///
+ ///
+ ///
+ /// New-IshSession -WsBaseUrl "https://example.com/ISHWS/" -PSCredential "Admin"
+ /// $rawData = "<data><export-document-type>ISHPublication</export-document-type><export-document-level>lng</export-document-level><export-ishlngref>549482</export-ishlngref><creationdate>20210303070257182</creationdate></data>"
+ /// $date = (Get-Date).AddDays(1)
+ /// $ishBackgroundTask = Add-IshBackgroundTask -EventType "PUBLISH" -EventDescription "Custom publish event description" -RawInputData $rawData -StartAfter $date
+ ///
+ /// Add background task with the event type "PUBLISH" and provided event description and publish input raw data.
+ /// Provided StartAfter parameter with tomorrow's date indicates that background task should not be executed before this date. Note: example code only, for publish operations usage of Publish-IshPublicationOutput cmdlet is preferred.
+ ///
+ [Cmdlet(VerbsCommon.Add, "IshBackgroundTask", SupportsShouldProcess = false)]
+ [OutputType(typeof(IshBackgroundTask))]
+ public sealed class AddIshBackgroundTask : BackgroundTaskCmdlet
+ {
+ ///
+ /// The IshSession variable holds the authentication and contract information. This object can be initialized using the New-IshSession cmdlet.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [ValidateNotNullOrEmpty]
+ public IshSession IshSession { get; set; }
+
+ ///
+ /// Type of the event (e.g. SMARTTAG). Needs a match CMS BackgroundTask service handler entry.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [ValidateNotNullOrEmpty]
+ public string EventType { get; set; }
+
+ ///
+ /// The input data for the background task.
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [ValidateNotNullOrEmpty]
+ public string RawInputData { get; set; }
+
+ ///
+ /// Description of the event
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [ValidateNotNullOrEmpty]
+ public string EventDescription { get; set; }
+
+ ///
+ /// Date time indicating that the background task should not be picked up and executed before it.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ public DateTime? StartAfter { get; set; }
+
+ ///
+ /// The s that will be used for background task creation.
+ ///
+ [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = "IshObjectsGroup")]
+ [AllowEmptyCollection]
+ public IshObject[] IshObject { get; set; }
+
+ #region Private fields
+ private readonly List _retrievedIshObjects = new List();
+ private readonly DateTime _modifiedSince = DateTime.Today.AddDays(-1);
+ private readonly BackgroundTask25ServiceReference.eUserFilter _userFilter = EnumConverter.ToUserFilter(Enumerations.UserFilter.Current);
+ private readonly int _startEventMaxProgress = 100;
+ #endregion
+
+ protected override void BeginProcessing()
+ {
+ if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); }
+ if (IshSession == null) { throw new ArgumentException(ISHRemoteSessionStateIshSessionException); }
+ WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession}");
+
+ switch (ParameterSetName)
+ {
+ case "ParameterGroup":
+ if ((IshSession.ServerIshVersion.MajorVersion < 13) || ((IshSession.ServerIshVersion.MajorVersion == 13) && (IshSession.ServerIshVersion.RevisionVersion < 2)))
+ {
+ throw new PlatformNotSupportedException($"Add-IshBackgroundTask with the current parameter set requires server-side BackgroundTask API which is only available starting from 13SP2/13.0.2 and up. ServerIshVersion[{IshSession.ServerVersion}]");
+ }
+ break;
+ case "IshObjectsGroup":
+ if ((IshSession.ServerIshVersion.MajorVersion < 14) || ((IshSession.ServerIshVersion.MajorVersion == 14) && (IshSession.ServerIshVersion.RevisionVersion < 4)))
+ {
+ throw new PlatformNotSupportedException($"Add-IshBackgroundTask with the current parameter set requires server-side DocumentObj API which is only available starting from 14SP4/14.0.4 and up. ServerIshVersion[{IshSession.ServerVersion}]");
+ }
+ break;
+ }
+ base.BeginProcessing();
+ }
+
+ ///
+ /// Process the cmdlet.
+ ///
+ protected override void ProcessRecord()
+ {
+ try
+ {
+ if (IshObject != null)
+ {
+ foreach (IshObject ishObject in IshObject)
+ {
+ _retrievedIshObjects.Add(ishObject);
+ }
+ }
+ }
+ catch (TrisoftAutomationException trisoftAutomationException)
+ {
+ ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
+ }
+ catch (Exception exception)
+ {
+ ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
+ }
+ }
+
+ ///
+ /// Process the Add-IshBackgroundTask command-let.
+ ///
+ ///
+ ///
+ /// Writes to the pipeline.
+ protected override void EndProcessing()
+ {
+ try
+ {
+ IshFields metadataFilter = new IshFields();
+ IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, new IshFields(), Enumerations.ActionMode.Find);
+ var startEventResponse = new StartEventResponse();
+ var progressIds = new List();
+ if (ParameterSetName == "IshObjectsGroup")
+ {
+ var ishObjectsDividedInBatches = DevideListInBatchesByLogicalId(_retrievedIshObjects, IshSession.MetadataBatchSize);
+
+ int currentIshObjectsCount = 0;
+ foreach (var ishObjectsGroup in ishObjectsDividedInBatches)
+ {
+ // Create BackgroundTask
+ var lngCardIds = ishObjectsGroup.Select(ishObject => Convert.ToInt64(ishObject.ObjectRef[Enumerations.ReferenceType.Lng])).ToList();
+ var response = IshSession.DocumentObj25.RaiseEventByIshLngRefs(new DocumentObj25ServiceReference.RaiseEventByIshLngRefsRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ palLngRefs = lngCardIds.ToArray(),
+ psEventType = EventType
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ progressIds.Add(response.plOutProgressId);
+ currentIshObjectsCount += ishObjectsGroup.Count;
+ WriteDebug($"RaiseEventByIshLngRefs.length[{lngCardIds.Count}] {currentIshObjectsCount}/{_retrievedIshObjects.Count}");
+ }
+ }
+
+ if (ParameterSetName == "ParameterGroup")
+ {
+ // Start event
+ var responseStartEvent = IshSession.EventMonitor25.StartEvent(new StartEventRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psDescription = EventDescription,
+ psEventType = EventType,
+ piMaximumProgress = _startEventMaxProgress
+ });
+ IshSession.AuthenticationContext = responseStartEvent.psAuthContext;
+ }
+
+ if (ParameterSetName == "ParameterGroup" && StartAfter.HasValue)
+ {
+ // Create BackgroundTask
+ var responseStartAfterEvent = IshSession.BackgroundTask25.CreateBackgroundTaskWithStartAfter(new CreateBackgroundTaskWithStartAfterRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psEventType = EventType,
+ psHashId = "",
+ pbInputData = Encoding.Unicode.GetBytes(RawInputData),
+ pdStartAfter = StartAfter.Value
+ });
+ IshSession.AuthenticationContext = responseStartAfterEvent.psAuthContext;
+ progressIds.Add(responseStartAfterEvent.plOutProgressId);
+ }
+
+ if (ParameterSetName == "ParameterGroup" && !StartAfter.HasValue)
+ {
+ // Create BackgroundTask
+ var responseCreate = IshSession.BackgroundTask25.CreateBackgroundTask(new CreateBackgroundTaskRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psEventType = EventType,
+ psHashId = "",
+ pbInputData = Encoding.Unicode.GetBytes(RawInputData),
+ });
+ IshSession.AuthenticationContext = responseCreate.psAuthContext;
+ progressIds.Add(responseCreate.plOutProgressId);
+ }
+
+ // Find and return IshBackgroundTask object
+ if (progressIds.Count > 1)
+ {
+ var progressIdsAsString = string.Join(IshSession.Separator, progressIds.ToArray());
+ metadataFilter.AddField(new IshMetadataFilterField(FieldElements.BackgroundTaskProgressId,
+ Enumerations.Level.Task, Enumerations.FilterOperator.In, progressIdsAsString,
+ Enumerations.ValueType.Element));
+ }
+ else
+ {
+ metadataFilter.AddField(new IshMetadataFilterField(FieldElements.BackgroundTaskProgressId,
+ Enumerations.Level.Task, Enumerations.FilterOperator.In, progressIds.First().ToString(),
+ Enumerations.ValueType.Element));
+ }
+
+ WriteDebug($"Finding BackgroundTask UserFilter[{_userFilter}] MetadataFilter.length[{metadataFilter.ToXml().Length}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}]");
+ var responseFind = IshSession.BackgroundTask25.Find(new FindRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ pdModifiedSince = _modifiedSince,
+ peUserFilter = _userFilter,
+ psXMLMetadataFilter = metadataFilter.ToXml(),
+ psXMLRequestedMetadata = requestedMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = responseFind.psAuthContext;
+ var xmlIshBackgroundTasks = responseFind.psOutXMLTaskList;
+ List returnIshBackgroundTasks = new IshBackgroundTasks(xmlIshBackgroundTasks).BackgroundTasks;
+
+ WriteVerbose("returned object count[" + returnIshBackgroundTasks.Count + "]");
+ WriteObject(IshSession, ISHType, returnIshBackgroundTasks.ConvertAll(x => (IshBaseObject)x), true);
+ }
+ catch (TrisoftAutomationException trisoftAutomationException)
+ {
+ ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
+ }
+ catch (Exception exception)
+ {
+ ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
+ }
+ }
+ }
+}
+
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/BackgroundTaskCmdlet.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/BackgroundTaskCmdlet.cs
new file mode 100644
index 00000000..e400017d
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/BackgroundTaskCmdlet.cs
@@ -0,0 +1,34 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Management.Automation;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+using Trisoft.ISHRemote.Exceptions;
+using System.Collections.Generic;
+
+namespace Trisoft.ISHRemote.Cmdlets.BackgroundTask
+{
+ public abstract class BackgroundTaskCmdlet : TrisoftCmdlet
+ {
+ public Enumerations.ISHType[] ISHType
+ {
+ get { return new Enumerations.ISHType[] { Enumerations.ISHType.ISHBackgroundTask }; }
+ }
+ }
+}
+
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/GetIshBackgroundTask.Tests.ps1 b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/GetIshBackgroundTask.Tests.ps1
new file mode 100644
index 00000000..9e542a3b
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/GetIshBackgroundTask.Tests.ps1
@@ -0,0 +1,208 @@
+BeforeAll {
+ $cmdletName = "Get-IshBackgroundTask"
+ Write-Host ("`r`nLoading ISHRemote.PesterSetup.ps1 over BeforeAll-block for MyCommand[" + $cmdletName + "]...")
+ . (Join-Path (Split-Path -Parent $PSCommandPath) "\..\..\ISHRemote.PesterSetup.ps1")
+
+ Write-Host ("Running "+$cmdletName+" Test Data and Variables initialization")
+}
+
+Describe "Get-IshBackgroundTask" -Tags "Create" {
+ BeforeAll {
+ $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Name "FNAME" |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Name "FDOCUMENTTYPE" |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Name "READ-ACCESS" -ValueType Element |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Name "FUSERGROUP" -ValueType Element
+ $ishFolderTestRootOriginal = Get-IshFolder -IShSession $ishSession -FolderPath $folderTestRootPath -RequestedMetadata $requestedMetadata
+ $folderIdTestRootOriginal = $ishFolderTestRootOriginal.IshFolderRef
+ $folderTypeTestRootOriginal = $ishFolderTestRootOriginal.IshFolderType
+ Write-Debug ("folderIdTestRootOriginal[" + $folderIdTestRootOriginal + "] folderTypeTestRootOriginal[" + $folderTypeTestRootOriginal + "]")
+ $ownedByTestRootOriginal = Get-IshMetadataField -IshSession $ishSession -Name "FUSERGROUP" -ValueType Element -IshField $ishFolderTestRootOriginal.IshField
+ $readAccessTestRootOriginal = (Get-IshMetadataField -IshSession $ishSession -Name "READ-ACCESS" -ValueType Element -IshField $ishFolderTestRootOriginal.IshField).Split($ishSession.Separator)
+
+ $global:ishFolderCmdlet = Add-IshFolder -IShSession $ishSession -ParentFolderId $folderIdTestRootOriginal -FolderType $folderTypeTestRootOriginal -FolderName $cmdletName -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+ $ishFolderTopic = Add-IshFolder -IshSession $ishSession -ParentFolderId ($global:ishFolderCmdlet.IshFolderRef) -FolderType ISHModule -FolderName "Topic" -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Topic $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObject = Add-IshDocumentObj -IshSession $ishSession -FolderId $ishFolderTopic.IshFolderRef -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Set-IshDocumentObj -IshSession $ishSession -Metadata (Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusReleased)
+
+
+ $allTaskMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name CREATIONDATE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name CURRENTATTEMPT |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name EVENTTYPE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name EXECUTEAFTERDATE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name HASHID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name INPUTDATAID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name LEASEDBY |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name LEASEDON |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name MODIFICATIONDATE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name OUTPUTDATAID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name PROGRESSID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name STATUS -ValueType Value |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name STATUS -ValueType Element |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name TASKID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name TRACKINGID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name USERID -ValueType Element
+ $allHistMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name ENDDATE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name ERROR |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name ERRORNUMBER |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name EXITCODE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name HISTORYID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name HOSTNAME |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name OUTPUT |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name STARTDATE
+ $allMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name CREATIONDATE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name CURRENTATTEMPT |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name EVENTTYPE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name EXECUTEAFTERDATE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name HASHID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name INPUTDATAID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name LEASEDBY |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name LEASEDON |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name MODIFICATIONDATE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name OUTPUTDATAID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name PROGRESSID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name STATUS -ValueType Value |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name STATUS -ValueType Element |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name TASKID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name TRACKINGID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name USERID -ValueType Element |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name ENDDATE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name ERROR |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name ERRORNUMBER |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name EXITCODE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name HISTORYID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name HOSTNAME |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name OUTPUT |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name STARTDATE
+ }
+ Context "Get-IshBackgroundTask" {
+ BeforeAll {
+ $metadata = Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name TASKID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name HISTORYID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name EVENTTYPE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name PROGRESSID
+ $ishBackgroundTask = (Get-IshBackgroundTask -IshSession $ishSession -UserFilter All -RequestedMetadata $metadata)[0]
+ }
+ It "GetType().Name" {
+ $ishBackgroundTask.GetType().Name | Should -BeExactly "IshBackgroundTask"
+ }
+ It "ishObject.IshField" {
+ $ishBackgroundTask.IshField | Should -Not -BeNullOrEmpty
+ }
+ It "ishObject.IshRef" {
+ $ishBackgroundTask.IshRef | Should -Not -BeNullOrEmpty
+ }
+ # Double check following 2 ReferenceType enum usage
+ It "ishBackgroundTask.TaskRef" {
+ $ishBackgroundTask.TaskRef | Should -Not -BeNullOrEmpty
+ }
+ #It "ishBackgroundTask.HistoryRef" {
+ # $ishBackgroundTask.HistoryRef | Should -Not -BeNullOrEmpty
+ #}
+ It "ishBackgroundTask ConvertTo-Json" {
+ (ConvertTo-Json $ishBackgroundTask).Length -gt 2 | Should -Be $true
+ }
+ It "Parameter IshSession/ModifiedSince/UserFilter invalid" {
+ { Get-IshBackgroundTask -IShSession "INVALIDISHSESSION" -ModifiedSince "INVALIDDATE" -UserFilter "INVALIDUSERFILTER" } | Should -Throw
+ }
+ It "Parameter RequestedMetadata/MetadataFile invalid" {
+ { Get-IshBackgroundTask -IShSession $ishSession -RequestedMetadata "INVALIDMETADATA" -MetadataFilter "INVALIDFILTER" } | Should -Throw
+ }
+ It "Parameter IshSession/UserFilter/MetadataFilter are optional" {
+ $ishBackgroundTask = (Get-IshBackgroundTask -ModifiedSince ((Get-Date).AddSeconds(-10)) -RequestedMetadata $allTaskMetadata)[0]
+ ($ishBackgroundTask | Get-IshMetadataField -IshSession $ishSession -Level Task -Name USERID -ValueType Element).StartsWith('VUSER') | Should -Be $true
+ ($ishBackgroundTask | Get-IshMetadataField -IshSession $ishSession -Level Task -Name STATUS -ValueType Element).StartsWith('VBACKGROUNDTASK') | Should -Be $true
+ }
+ It "Option IshSession.DefaultRequestedMetadata" {
+ $oldDefaultRequestedMetadata = $ishSession.DefaultRequestedMetadata
+ $ishSession.DefaultRequestedMetadata = "Descriptive"
+ $ishBackgroundTask = (Get-IshBackgroundTask -IShSession $ishSession)[0]
+ (($ishBackgroundTask.IshField.Count -eq 1) -or ($ishBackgroundTask.IshField.Count -eq 2)) | Should -Be $true # Either BackgroundTask has run and you get taskid/historyid, or it didn't and you only get taskid
+ $ishSession.DefaultRequestedMetadata = "Basic"
+ $ishBackgroundTask = (Get-IshBackgroundTask -IShSession $ishSession)[0]
+ $ishBackgroundTask.status.Length -ge 1 | Should -Be $true
+ $ishBackgroundTask.status_task_element.StartsWith('VBACKGROUNDTASKSTATUS') | Should -Be $true
+ (($ishBackgroundTask.IshField.Count -eq 13) -or ($ishBackgroundTask.IshField.Count -eq 19)) | Should -Be $true
+ $ishSession.DefaultRequestedMetadata = "All"
+ $ishBackgroundTask = (Get-IshBackgroundTask -IShSession $ishSession)[0]
+ (($ishBackgroundTask.IshField.Count -eq 18) -or ($ishBackgroundTask.IshField.Count -eq 26)) | Should -Be $true
+ $ishSession.DefaultRequestedMetadata = $oldDefaultRequestedMetadata
+ }
+ It "Parameter ModifiedSince is now" {
+ (Get-IshBackgroundTask -IshSession $ishSession -ModifiedSince ((Get-Date).AddMinutes(1)) -UserFilter All).Count | Should -Be 0
+ }
+ It "Parameter RequestedMetadata only all of Task level" {
+ $ishBackgroundTask = (Get-IshBackgroundTask -IshSession $ishSession -ModifiedSince ((Get-Date).AddSeconds(-10)) -UserFilter All -RequestedMetadata $allTaskMetadata)[0]
+ $ishBackgroundTask.TaskRef -gt 0 | Should -Be $true
+ $ishBackgroundTask.IshField.Count -ge 16 | Should -Be $true
+ }
+ It "Parameter RequestedMetadata only all of History level" {
+ $ishBackgroundTask = (Get-IshBackgroundTask -IshSession $ishSession -ModifiedSince ((Get-Date).AddMinutes(-1)) -UserFilter All -RequestedMetadata $allHistMetadata)[0]
+ $ishBackgroundTask.TaskRef -gt 0 | Should -Be $true
+ #$ishBackgroundTask.HistoryRef -gt 0 | Should -Be $true
+ $ishBackgroundTask.IshField.Count -ge 1 | Should -Be $true # At least 1 entries returned if BackgroundTask service is not running, otherwise more
+ }
+ It "Parameter RequestedMetadata PipelineObjectPreference=PSObjectNoteProperty" {
+ $ishSession.PipelineObjectPreference | Should -Be "PSObjectNoteProperty"
+ $ishBackgroundTask = (Get-IshBackgroundTask -IshSession $ishSession -ModifiedSince ((Get-Date).AddMinutes(-1)) -UserFilter All -RequestedMetadata $allMetadata)[0]
+ $ishBackgroundTask.GetType().Name | Should -BeExactly "IshBackgroundTask" # and not PSObject
+ [bool]($ishBackgroundTask.PSobject.Properties.name -match "status_task_element") | Should -Be $true
+ [bool]($ishBackgroundTask.PSobject.Properties.name -match "userid_task_element") | Should -Be $true
+ [bool]($ishBackgroundTask.PSobject.Properties.name -match "modificationdate") | Should -Be $true
+ $ishBackgroundTask.modificationdate -like "*/*" | Should -Be $false # It should be sortable date format: yyyy-MM-ddTHH:mm:ss
+ }
+ It "Parameter RequestedMetadata PipelineObjectPreference=Off" {
+ $pipelineObjectPreference = $ishSession.PipelineObjectPreference
+ $ishSession.PipelineObjectPreference = "Off"
+ $ishBackgroundTask = (Get-IshBackgroundTask -IshSession $ishSession -ModifiedSince ((Get-Date).AddMinutes(-1)) -UserFilter All -RequestedMetadata $allMetadata)[0]
+ $ishBackgroundTask.GetType().Name | Should -BeExactly "IshBackgroundTask"
+ [bool]($ishBackgroundTask.PSobject.Properties.name -match "status_task_element") | Should -Be $false
+ [bool]($ishBackgroundTask.PSobject.Properties.name -match "userid_task_element") | Should -Be $false
+ [bool]($ishBackgroundTask.PSobject.Properties.name -match "modificationdate") | Should -Be $false
+ $ishSession.PipelineObjectPreference = $pipelineObjectPreference
+ }
+ It "Parameter MetadataFilter Filter to exactly one" {
+ $ishBackgroundTask = (Get-IshBackgroundTask -IshSession $ishSession -ModifiedSince ((Get-Date).AddMinutes(-1)) -UserFilter All -RequestedMetadata $allTaskMetadata)[0]
+ $filterMetadata = Set-IshMetadataFilterField -IshSession $ishSession -Level Task -Name USERID -ValueType Element -Value ($ishBackgroundTask | Get-IshMetadataField -IshSession $ishSession -Level Task -Name USERID -ValueType Element) |
+ Set-IshMetadataFilterField -IshSession $ishSession -Level Task -Name TASKID -ValueType Element -Value ($ishBackgroundTask | Get-IshMetadataField -IshSession $ishSession -Level Task -Name TASKID)
+ $ishBackgroundTaskArray = Get-IshBackgroundTask -IshSession $ishSession -MetadataFilter $filterMetadata
+ #Write-Host ("ishBackgroundTask.IshRef["+ $ishBackgroundTask.IshRef + "] ishBackgroundTaskArray.IshRef["+ $ishBackgroundTask.IshRef + "]")
+ $ishBackgroundTaskArray.Count -ge 1 | Should -Be $true # earlier on, also filter on HISTORYID, but that is not always filled in, even with the windows service off
+ }
+ It "Parameter IshBackgroundTask invalid" {
+ { Get-IshBackgroundTask -IshSession $ishSession -IshBackgroundTask "INVALIDISHBACKGROUNDTASK" } | Should -Throw
+ }
+ It "Parameter IshBackgroundTask Single" {
+ $ishBackgroundTask = (Get-IshBackgroundTask -IshSession $ishSession -ModifiedSince ((Get-Date).AddMinutes(-1)) -UserFilter Current)[0]
+ $taskId = $ishBackgroundTask | Get-IshMetadataField -IshSession $ishSession -Level Task -Name TASKID
+ $ishBackgroundTaskArray = Get-IshBackgroundTask -IshSession $ishSession -IshBackgroundTask $ishBackgroundTask
+ $ishBackgroundTaskArray.Count -ge 1 | Should -Be $true
+ $ishBackgroundTaskArray.IshRef | Should -Be $taskId
+ }
+ <# TODO [Could] It "Parameter IshBackgroundTask Multiple" {
+ }
+ #>
+ It "Pipeline IshBackgroundTask Single" {
+ $ishBackgroundTask = (Get-IshBackgroundTask -IshSession $ishSession -ModifiedSince ((Get-Date).AddMinutes(-1)) -UserFilter Current)[0]
+ $taskId = $ishBackgroundTask | Get-IshMetadataField -IshSession $ishSession -Level Task -Name TASKID
+ $ishBackgroundTaskArray = $ishBackgroundTask | Get-IshBackgroundTask -IshSession $ishSession
+ $ishBackgroundTaskArray.Count -ge 1 | Should -Be $true
+ $ishBackgroundTaskArray.IshRef | Should -Be $taskId
+ }
+ <# TODO [Could] It "Pipeline IshBackgroundTask Multiple" {
+ }
+ #>
+ }
+ #>
+}
+
+
+AfterAll {
+ Write-Host ("Running "+$cmdletName+" Test Data and Variables cleanup")
+ $folderCmdletRootPath = (Join-Path $folderTestRootPath $cmdletName)
+ try { Get-IshFolder -IshSession $ishSession -FolderPath $folderCmdletRootPath -Recurse | Get-IshFolderContent -IshSession $ishSession | Remove-IshDocumentObj -IshSession $ishSession -Force } catch { }
+ try { Remove-IshFolder -IshSession $ishSession -FolderPath $folderCmdletRootPath -Recurse } catch { }
+}
+
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/GetIshBackgroundTask.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/GetIshBackgroundTask.cs
new file mode 100644
index 00000000..6f8bfb85
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/GetIshBackgroundTask.cs
@@ -0,0 +1,248 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Management.Automation;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+using Trisoft.ISHRemote.Exceptions;
+using Trisoft.ISHRemote.HelperClasses;
+using System.Linq;
+
+namespace Trisoft.ISHRemote.Cmdlets.BackgroundTask
+{
+ ///
+ /// Gets BackgroundTask entries with filtering options.
+ /// Uses BackgroundTask25 API to retrieve backgroundtasks showing their status, lease, etc from the virtual queue.
+ /// This table oriented API maps straight through to database column names regarding ishfield usage.
+ ///
+ ///
+ ///
+ /// New-IshSession -WsBaseUrl "https://example.com/ISHWS/" -PSCredential "Admin"
+ /// Get-IshBackgroundTask
+ ///
+ /// New-IshSession will submit into SessionState, so it can be reused by this cmdlet. Returns the full denormalized task/history entries limited to only Basic fields, for All users and the last 24 hours.
+ ///
+ ///
+ ///
+ /// $allMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name CREATIONDATE |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name CURRENTATTEMPT |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name EVENTTYPE |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name EXECUTEAFTERDATE |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name HASHID |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name INPUTDATAID |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name LEASEDBY |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name LEASEDON |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name MODIFICATIONDATE |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name OUTPUTDATAID |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name PROGRESSID |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name STATUS -ValueType Value |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name STATUS -ValueType Element |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name TASKID |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name TRACKINGID |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name USERID -ValueType All |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name ENDDATE |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name ERROR |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name ERRORNUMBER |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name EXITCODE |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name HISTORYID |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name HOSTNAME |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name OUTPUT |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Level History -Name STARTDATE
+ /// Get-IshBackgroundTask -IshSession $ishSession -RequestedMetadata $allMetadata
+ ///
+ /// Returns the full denormalized task/history entries limited to All users and the last 24 hours.
+ ///
+ ///
+ ///
+ /// Get-IshBackgroundTask -IshSession $ishSession -ModifiedSince ((Get-Date).AddSeconds(-10)) -UserFilter Current
+ ///
+ /// Returns the full denormalized task/history entries limited to only Basic fields, the current user and limited to 10 seconds ago of activity.
+ ///
+ ///
+ ///
+ /// $filterMetadata = Set-IshMetadataFilterField -IshSession $ishSession -Level Task -Name EVENTTYPE -FilterOperator In -Value "CREATETRANSLATIONS, CREATETRANSLATIONFROMLIST" |
+ /// Set-IshMetadataFilterField -IshSession $ishSession -Level Task -Name TASKID -Value $taskId
+ /// Get-IshBackgroundTask -IshSession $ishSession -MetadataFilter $filterMetadata
+ ///
+ /// Returns the full denormalized task/history entries limited to only Basic fields, for All users and the last 24 hours.
+ ///
+ ///
+ ///
+ /// $metadata = Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name STATUS
+ /// Get-IshBackgroundTask -IshSession $ishSession -RequestedMetadata $metadata | Group-Object -Property status
+ ///
+ /// Returns the group-by count by status, for All users and the last 24 hours.
+ ///
+ [Cmdlet(VerbsCommon.Get, "IshBackgroundTask", SupportsShouldProcess = false)]
+ [OutputType(typeof(IshBackgroundTask))]
+ public sealed class GetIshBackgroundTask : BackgroundTaskCmdlet
+ {
+
+ ///
+ /// The IshSession variable holds the authentication and contract information. This object can be initialized using the New-IshSession cmdlet.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshBackgroundTasksGroup")]
+ [ValidateNotNullOrEmpty]
+ public IshSession IshSession { get; set; }
+
+ ///
+ /// Enumeration indicating if only events of the current user or all events must be retrieved
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [ValidateNotNullOrEmpty]
+ public Enumerations.UserFilter UserFilter
+ {
+ private get { return Enumerations.UserFilter.All; } // required otherwise XmlDoc2CmdletDoc crashes with 'System.ArgumentException: Property Get method was not found.'
+ set { _userFilter = EnumConverter.ToUserFilter(value); }
+ }
+
+ ///
+ /// A date limiting the events that will be retrieved based on the last modification date of the events
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [ValidateNotNullOrEmpty]
+ public DateTime ModifiedSince
+ {
+ get { return _modifiedSince; }
+ set { _modifiedSince = value; }
+ }
+
+ ///
+ /// Filter on metadata to limit the objects on which metadata has to be returned
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshBackgroundTasksGroup")]
+ [ValidateNotNullOrEmpty]
+ public IshField[] MetadataFilter { get; set; }
+
+ ///
+ /// XML structure indicating which metadata has to be retrieved.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshBackgroundTasksGroup")]
+ [ValidateNotNullOrEmpty]
+ public IshField[] RequestedMetadata { get; set; }
+
+ ///
+ /// The s that need to be handled.
+ ///
+ [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = "IshBackgroundTasksGroup")]
+ public IshBackgroundTask[] IshBackgroundTask { get; set; }
+
+
+
+ #region Private fields
+ private DateTime _modifiedSince = DateTime.Today.AddDays(-1);
+ //private BackgroundTask25ServiceReference.B _progressStatusFilter = BackgroundTask25ServiceReference.ProgressStatusFilter.All;
+ private BackgroundTask25ServiceReference.eUserFilter _userFilter = BackgroundTask25ServiceReference.eUserFilter.All;
+ private readonly List _retrievedIshBackgroundTask = new List();
+ #endregion
+
+ protected override void BeginProcessing()
+ {
+ if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); }
+ if (IshSession == null) { throw new ArgumentException(ISHRemoteSessionStateIshSessionException); }
+ WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession}");
+
+ if ((IshSession.ServerIshVersion.MajorVersion < 13) || ((IshSession.ServerIshVersion.MajorVersion == 13) && (IshSession.ServerIshVersion.RevisionVersion < 2)))
+ {
+ throw new PlatformNotSupportedException($"Get-IshBackgroundTask requires server-side BackgroundTask API which only available starting from 13SP2/13.0.2 and up. ServerIshVersion[{IshSession.ServerVersion}]");
+ }
+ base.BeginProcessing();
+ }
+
+ ///
+ /// Process the cmdlet.
+ ///
+ protected override void ProcessRecord()
+ {
+ try
+ {
+ if (IshBackgroundTask != null)
+ {
+ foreach(IshBackgroundTask ishBackgroundTask in IshBackgroundTask)
+ {
+ _retrievedIshBackgroundTask.Add(ishBackgroundTask);
+ }
+ }
+ }
+ catch (TrisoftAutomationException trisoftAutomationException)
+ {
+ ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
+ }
+ catch (Exception exception)
+ {
+ ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
+ }
+ }
+
+ ///
+ /// Process the cmdlet.
+ ///
+ ///
+ ///
+ /// Writes to the pipeline.
+ protected override void EndProcessing()
+ {
+ try
+ {
+ IshFields metadataFilter = new IshFields(MetadataFilter);
+ IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, new IshFields(RequestedMetadata), Enumerations.ActionMode.Find);
+ string xmlIshBackgroundTasks;
+ if (_retrievedIshBackgroundTask.Count != 0)
+ {
+ var backgroundTaskIds = _retrievedIshBackgroundTask.Select(ishBackgroundTask => Convert.ToInt64(ishBackgroundTask.TaskRef)).ToList();
+ if (backgroundTaskIds.Count != 0)
+ {
+ var backgroundTaskIdsAsString = string.Join(", ", backgroundTaskIds.ToArray());
+ metadataFilter.AddOrUpdateField(new IshMetadataFilterField("TASKID", Enumerations.Level.Task, Enumerations.FilterOperator.In, backgroundTaskIdsAsString, Enumerations.ValueType.Value), Enumerations.ActionMode.Find);
+ }
+ }
+ WriteDebug($"Finding UserFilter[{_userFilter}] MetadataFilter.length[{metadataFilter.ToXml().Length}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}]");
+ var responseFind = IshSession.BackgroundTask25.Find(new BackgroundTask25ServiceReference.FindRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ pdModifiedSince = ModifiedSince,
+ peUserFilter = _userFilter,
+ psXMLMetadataFilter = metadataFilter.ToXml(),
+ psXMLRequestedMetadata = requestedMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = responseFind.psAuthContext;
+ xmlIshBackgroundTasks = responseFind.psOutXMLTaskList;
+ List returnIshBackgroundTasks = new IshBackgroundTasks(xmlIshBackgroundTasks).BackgroundTasks;
+
+ WriteVerbose("returned object count[" + returnIshBackgroundTasks.Count + "]");
+ WriteObject(IshSession, ISHType, returnIshBackgroundTasks.ConvertAll(x => (IshBaseObject)x), true);
+ }
+ catch (TrisoftAutomationException trisoftAutomationException)
+ {
+ ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
+ }
+ catch (Exception exception)
+ {
+ ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
+ }
+ finally
+ {
+ base.EndProcessing();
+ }
+ }
+ }
+}
+
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/AddIshDocumentObj.Tests.ps1 b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/AddIshDocumentObj.Tests.ps1
new file mode 100644
index 00000000..5f99286c
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/AddIshDocumentObj.Tests.ps1
@@ -0,0 +1,199 @@
+BeforeAll {
+ $cmdletName = "Add-IshDocumentObj"
+ Write-Host ("`r`nLoading ISHRemote.PesterSetup.ps1 over BeforeAll-block for MyCommand[" + $cmdletName + "]...")
+ . (Join-Path (Split-Path -Parent $PSCommandPath) "\..\..\ISHRemote.PesterSetup.ps1")
+
+ Write-Host ("Running "+$cmdletName+" Test Data and Variables initialization")
+}
+
+Describe "Add-IshDocumentObj" -Tags "Create" {
+ BeforeAll {
+ $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Name "FNAME" |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Name "FDOCUMENTTYPE" |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Name "READ-ACCESS" -ValueType Element |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Name "FUSERGROUP" -ValueType Element
+ $ishFolderTestRootOriginal = Get-IshFolder -IShSession $ishSession -FolderPath $folderTestRootPath -RequestedMetadata $requestedMetadata
+ $folderIdTestRootOriginal = $ishFolderTestRootOriginal.IshFolderRef
+ $folderTypeTestRootOriginal = $ishFolderTestRootOriginal.IshFolderType
+ Write-Debug ("folderIdTestRootOriginal[" + $folderIdTestRootOriginal + "] folderTypeTestRootOriginal[" + $folderTypeTestRootOriginal + "]")
+ $ownedByTestRootOriginal = Get-IshMetadataField -IshSession $ishSession -Name "FUSERGROUP" -ValueType Element -IshField $ishFolderTestRootOriginal.IshField
+ $readAccessTestRootOriginal = (Get-IshMetadataField -IshSession $ishSession -Name "READ-ACCESS" -ValueType Element -IshField $ishFolderTestRootOriginal.IshField).Split($ishSession.Separator)
+
+ $global:ishFolderCmdlet = Add-IshFolder -IShSession $ishSession -ParentFolderId $folderIdTestRootOriginal -FolderType $folderTypeTestRootOriginal -FolderName $cmdletName -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+ $ishFolderTopic = Add-IshFolder -IshSession $ishSession -ParentFolderId ($global:ishFolderCmdlet.IshFolderRef) -FolderType ISHModule -FolderName "Topic" -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+ $ishFolderMap = Add-IshFolder -IshSession $ishSession -ParentFolderId ($global:ishFolderCmdlet.IshFolderRef) -FolderType ISHMasterDoc -FolderName "Map" -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+ $ishFolderLib = Add-IshFolder -IshSession $ishSession -ParentFolderId ($global:ishFolderCmdlet.IshFolderRef) -FolderType ISHLibrary -FolderName "Library" -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+ $ishFolderImage = Add-IshFolder -IshSession $ishSession -ParentFolderId ($global:ishFolderCmdlet.IshFolderRef) -FolderType ISHIllustration -FolderName "Image" -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+ $ishFolderOther = Add-IshFolder -IshSession $ishSession -ParentFolderId ($global:ishFolderCmdlet.IshFolderRef) -FolderType ISHTemplate -FolderName "Other" -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+
+ $tempFilePath = (New-TemporaryFile).FullName
+ }
+ Context "Add-IshDocumentObj returns IshObject object (Topic)" {
+ BeforeAll {
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Topic $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObject = Add-IshDocumentObj -IshSession $ishSession -FolderId $ishFolderTopic.IshFolderRef -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent
+ }
+ It "GetType().Name" {
+ $ishObject.GetType().Name | Should -BeExactly "IshDocumentObj"
+ }
+ It "ishObject.IshData" {
+ { $ishObject.IshData } | Should -Not -Throw
+ }
+ It "ishObject.IshField" {
+ $ishObject.IshField | Should -Not -BeNullOrEmpty
+ }
+ It "ishObject.IshRef" {
+ $ishObject.IshRef | Should -Not -BeNullOrEmpty
+ }
+ It "ishObject.IshType" {
+ $ishObject.IshType | Should -Not -BeNullOrEmpty
+ }
+ # Double check following 3 ReferenceType enum usage
+ It "ishObject.ObjectRef" {
+ $ishObject.ObjectRef | Should -Not -BeNullOrEmpty
+ }
+ It "ishObject.VersionRef" {
+ $ishObject.VersionRef | Should -Not -BeNullOrEmpty
+ }
+ It "ishObject.LngRef" {
+ $ishObject.LngRef | Should -Not -BeNullOrEmpty
+ }
+ It "ishObject ConvertTo-Json" {
+ (ConvertTo-Json $ishObject).Length -gt 2 | Should -Be $true
+ }
+ It "Option IshSession.DefaultRequestedMetadata" {
+ $ishSession.DefaultRequestedMetadata | Should -Be "Basic"
+ #logical
+ $ishObject.ftitle_logical_value.Length -ge 1 | Should -Be $true
+ #version
+ $ishObject.version_version_value.Length -ge 1 | Should -Be $true
+ #language
+ $ishObject.fstatus.Length -ge 1 | Should -Be $true
+ $ishObject.fstatus_lng_element.StartsWith('VSTATUS') | Should -Be $true
+ $ishObject.doclanguage.Length -ge 1 | Should -Be $true # Field names like DOC-LANGUAGE get stripped of the hyphen, otherwise you get $ishObject.'doc-language' and now you get the more readable $ishObject.doclanguage
+ $ishObject.doclanguage_lng_element.StartsWith('VLANGUAGE') | Should -Be $true
+ }
+ }
+ Context "Add-IshDocumentObj ParameterGroupFileContent" {
+ It "Parameter IshSession/Lng/FileContent invalid" {
+ { Add-IshDocumentObj -IShSession "INVALIDISHSESSION" -Lng "INVALIDLANGUAGE" -FileContent "INVALIDFILECONTENT" } | Should -Throw
+ }
+ It "Parameter Lng/FileContent invalid" {
+ { Add-IshDocumentObj -IShSession $ishSession -Lng "INVALIDLANGUAGE" -FileContent "INVALIDFILECONTENT" } | Should -Throw
+ }
+ It "Parameter FileContent invalid" {
+ { Add-IshDocumentObj -IShSession $ishSession -Lng $ishLng -FileContent "INVALIDFILECONTENT" } | Should -Throw
+ }
+ It "All Parameters (Topic)" {
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "All Parameters Topic $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObject = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -LogicalId "MYOWNGENERATEDLOGICALIDTOPIC" -Version '2' -Lng $ishLng -Metadata $ishTopicMetadata -Edt "EDTXML" -FileContent $ditaTopicFileContent
+ $ishObject.LngRef -gt 0 | Should -Be $true
+ }
+ It "All Parameters (Map)" {
+ $ishMapMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "All Parameters Map $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObject = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderMap -IshType ISHMasterDoc -LogicalId "MYOWNGENERATEDLOGICALIDMAP" -Version '3' -Lng $ishLng -Metadata $ishMapMetadata -Edt "EDTXML" -FileContent $ditaMapFileContent
+ $ishObject.LngRef -gt 0 | Should -Be $true
+ }
+ It "All Parameters (Lib)" {
+ $ishLibMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "All Parameters Lib $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObject = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderLib -IshType ISHLibrary -LogicalId "MYOWNGENERATEDLOGICALIDLIB" -Version '4' -Lng $ishLng -Metadata $ishLibMetadata -Edt "EDTXML" -FileContent $ditaTopicFileContent
+ $ishObject.LngRef -gt 0 | Should -Be $true
+ }
+ }
+ Context "Add-IshDocumentObj ParameterGroupFilePath" {
+ It "Parameter IshSession/Lng/FilePath invalid" {
+ { Add-IshDocumentObj -IShSession "INVALIDISHSESSION" -Lng "INVALIDLANGUAGE" -FilePath "INVALIDFILEPATH" } | Should -Throw
+ }
+ It "All Parameters (Image like EDTJPEG)" {
+ $ishImageMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "All Parameters Image $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $tempFilePath = (New-TemporaryFile).FullName
+ Add-Type -AssemblyName "System.Drawing"
+ $bmp = New-Object -TypeName System.Drawing.Bitmap(100,100)
+ for ($i = 0; $i -lt 100; $i++)
+ {
+ for ($j = 0; $j -lt 100; $j++)
+ {
+ $bmp.SetPixel($i, $j, 'Red')
+ }
+ }
+ $bmp.Save($tempFilePath, [System.Drawing.Imaging.ImageFormat]::Jpeg)
+ $ishObject = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderImage -IshType ISHIllustration -LogicalId "MYOWNGENERATEDLOGICALIDIMAGE" -Version '5' -Lng $ishLng -Resolution $ishResolution -Metadata $ishImageMetadata -Edt "EDTJPEG" -FilePath $tempFilePath
+ $ishObject.LngRef -gt 0 | Should -Be $true
+ }
+ It "All Parameters (Other like EDT-TEXT)" {
+ $ishOtherMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "All Parameters Other $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ Get-Process | Out-File $tempFilePath
+ $ishObject = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderOther -IshType ISHTemplate -LogicalId "MYOWNGENERATEDLOGICALIDOTHER" -Version '6' -Lng $ishLng -Metadata $ishOtherMetadata -Edt "EDT-TEXT" -FilePath $tempFilePath
+ $ishObject.LngRef -gt 0 | Should -Be $true
+ }
+ }
+ Context "Add-IshDocumentObj IshObjectsGroup" {
+ BeforeAll {
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Topic $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ }
+ It "Parameter IshObject invalid" {
+ { Add-IshDocumentObj -IshSession $ishSession -IshFolder "INVALIDISHFOLDER" -IshObject "INVALIDISHOBJECT" } | Should -Throw
+ }
+ It "Parameter IshObject Single with implicit IshSession" {
+ # Create an object, Delete it, Recreate it using parameter IshObject as if the incoming object came from another repository
+ $ishObject = Add-IshDocumentObj -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Get-IshDocumentObjData
+ Remove-IshDocumentObj -IshSession $ishSession -IshObject $ishObject
+ $ishObjectArray = Add-IshDocumentObj -IshFolder $ishFolderTopic -IshObject $ishObject
+ $ishObjectArray.Count | Should -Be 1
+ }
+ It "Parameter IshObject Multiple with implicit IshSession" {
+ # Create an object, Delete it, Recreate it using parameter IshObject as if the incoming object came from another repository
+ $ishObjectA = Add-IshDocumentObj -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Get-IshDocumentObjData
+ Remove-IshDocumentObj -IshSession $ishSession -IshObject $ishObjectA
+ $ishObjectB = Add-IshDocumentObj -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Get-IshDocumentObjData
+ Remove-IshDocumentObj -IshObject $ishObjectB
+ $ishObjectArray = Add-IshDocumentObj -IshFolder $ishFolderTopic -IshObject @($ishObjectA,$ishObjectB)
+ $ishObjectArray.Count | Should -Be 2
+ }
+ It "Pipeline IshObject Single" {
+ # Create an object, Delete it, Recreate it using parameter IshObject as if the incoming object came from another repository
+ $ishObjectC = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Get-IshDocumentObjData -IshSession $ishSession
+ Remove-IshDocumentObj -IshSession $ishSession -IshObject $ishObjectC
+ $ishObjectArray = $ishObjectC | Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic
+ $ishObjectArray.Count | Should -Be 1
+ }
+ It "Pipeline IshObject Multiple" {
+ # Create an object, Delete it, Recreate it using parameter IshObject as if the incoming object came from another repository
+ $ishObjectD = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Get-IshDocumentObjData -IshSession $ishSession
+ $ishObjectE = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Get-IshDocumentObjData -IshSession $ishSession
+ $ishObjects = @($ishObjectD,$ishObjectE)
+ $ishObjects | Remove-IshDocumentObj -IshSession $ishSession
+ $ishObjectArray = $ishObjects | Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic
+ $ishObjects.Count -eq $ishObjectArray.Count | Should -Be $true
+ }
+ }
+}
+
+AfterAll {
+ Write-Host ("Running "+$cmdletName+" Test Data and Variables cleanup")
+ $folderCmdletRootPath = (Join-Path $folderTestRootPath $cmdletName)
+ try { Get-IshFolder -IshSession $ishSession -FolderPath $folderCmdletRootPath -Recurse | Get-IshFolderContent -IshSession $ishSession | Remove-IshDocumentObj -IshSession $ishSession -Force } catch { }
+ try { Remove-IshFolder -IshSession $ishSession -FolderPath $folderCmdletRootPath -Recurse } catch { }
+ try { Remove-Item $tempFilePath -Force } catch { }
+}
+
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/AddIshDocumentObj.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/AddIshDocumentObj.cs
new file mode 100644
index 00000000..62332fce
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/AddIshDocumentObj.cs
@@ -0,0 +1,418 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Management.Automation;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+using Trisoft.ISHRemote.Exceptions;
+using Trisoft.ISHRemote.HelperClasses;
+using System.Xml.Linq;
+using System.IO;
+using System.Text;
+using System.Xml;
+
+namespace Trisoft.ISHRemote.Cmdlets.DocumentObj
+{
+ ///
+ /// The Add-IshDocumentObj cmdlet adds the new document object(s) (which include illustrations) that are passed through the pipeline or determined via provided parameters This commandlet allows to create all types of objects (Illustrations, Maps, etc. ), except for publication (outputs).
+ /// For publication (outputs) you need to use Add-IshPublicationOutput.
+ /// The Add-IshDocumentObj cmdlet adds the new document object(s) (which include illustrations) that are passed through the pipeline or determined via provided parameters This commandlet allows to create all types of objects (Illustrations, Maps, etc. ), except for publication (outputs).
+ /// For publication (outputs) you need to use Add-IshPublicationOutput.
+ ///
+ ///
+ ///
+ /// $ishSession = New-IshSession -WsBaseUrl "https://example.com/InfoShareWS/" -PSCredential Admin
+ /// Write-Host "`r`nCreate a logical, version, language level"
+ /// $ditaFileContent = @"
+ /// <? xml version="1.0" ?>
+ /// <!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
+ /// <topic><title>Enter the title of your topic here.<? ish-replace-title?></title><shortdesc>Enter a short description of your topic here(optional).</shortdesc><body><p>This is the start of your topic.</p></body></topic>
+ /// "@
+ /// $ishMetadataFields = Set-IshMetadataField -Name "FTITLE" -Level "Logical" -Value "Example ISHModule" |
+ /// Set-IshMetadataField -Name "FCHANGES" -Level "Version" -Value "Changes text field" |
+ /// Set-IshMetadataField -Name "FSTATUS" -Level "Lng" -Value "Draft" |
+ /// Set-IshMetadataField -Name "FAUTHOR" -Level "Lng" -Value "admin"
+ /// # add object
+ /// $ishObject = Add-IshDocumentObj `
+ /// -FolderId "0" `
+ /// -IshType "ISHModule" `
+ /// -Lng "en" `
+ /// -Metadata $ishMetadataFields `
+ /// -Edt "EDTXML" `
+ /// -FileContent $ditaFileContent
+ /// $ishObject.ObjectRef| Format-Table
+ ///
+ /// New-IshSession will submit into SessionState, so it can be reused by this cmdlet. Add Module without providing LogicalId, Version and using FileContent parameter
+ ///
+ ///
+ ///
+ /// $ishSession = New-IshSession -WsBaseUrl "https://example.com/InfoShareWS/" -IshUserName "" -IshUserPassword ""
+ /// Write-Host "`r`nCreate a logical, version, language level"
+ /// $timestamp = get-date -Format "yyyyMMddHHmmss"
+ /// $logicalId = "MYGUID-$timestamp"
+ /// $ditaFilePath = "c:\temp\Task.dita" # Template which is used to create a language level
+ /// $ishMetadataFields = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value "Example ISHModule" `
+ /// | Set-IshMetadataField -IshSession $ishSession -Name "FCHANGES" -Level "Version" -Value "Changes text field" `
+ /// | Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level "Lng" -Value "Draft" `
+ /// | Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level "Lng" -Value "admin"
+ /// # add object
+ /// $ishObject = Add-IshDocumentObj -IshSession $ishSession `
+ /// -FolderId "0" ` #use valid FolderId
+ /// -LogicalId $logicalId `
+ /// -IshType "ISHModule" `
+ /// -Version "1" `
+ /// -Lng "en" `
+ /// -Metadata $ishMetadataFields `
+ /// -Edt "EDTXML" `
+ /// -FilePath $ditaFilePath
+ /// $ishObject.ObjectRef| Format-Table
+ ///
+ /// Add Module with providing LogicalId and Version
+ ///
+ ///
+ ///
+ /// $ishSession = New-IshSession -WsBaseUrl "https://example.com/InfoShareWS/" -IshUserName "" -IshUserPassword ""
+ /// Write-Host "`r`nCreate a logical, version, language level"
+ /// $ditaFilePath = "c:\temp\Task.dita" # Template which is used to create a language level
+ /// $ishMetadataFields = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value "Example ISHModule" `
+ /// | Set-IshMetadataField -IshSession $ishSession -Name "FCHANGES" -Level "Version" -Value "Changes text field" `
+ /// | Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level "Lng" -Value "Draft" `
+ /// | Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level "Lng" -Value "admin"
+ /// # add object
+ /// $ishObject = Add-IshDocumentObj -IshSession $ishSession `
+ /// -FolderId "0" ` #use valid FolderId
+ /// -IshType "ISHModule" `
+ /// -Lng "en" `
+ /// -Metadata $ishMetadataFields `
+ /// -Edt "EDTXML" `
+ /// -FilePath $ditaFilePath
+ /// $ishObject.ObjectRef| Format-Table
+ ///
+ /// Add Module without providing LogicalId and Version
+ ///
+ [Cmdlet(VerbsCommon.Add, "IshDocumentObj", SupportsShouldProcess = true)]
+ [OutputType(typeof(IshDocumentObj))]
+ public sealed class AddIshDocumentObj : DocumentObjCmdlet
+ {
+
+ ///
+ /// The IshSession variable holds the authentication and contract information. This object can be initialized using the New-IshSession cmdlet.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [ValidateNotNullOrEmpty]
+ public IshSession IshSession { get; set; }
+
+ ///
+ /// The FolderId of the DocumentObj.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [ValidateNotNullOrEmpty]
+ public long FolderId
+ {
+ get { return _folderId; }
+ set { _folderId = value; }
+ }
+
+ ///
+ /// The FolderId of the DocumentObj by IshFolder object
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [ValidateNotNull]
+ public IshFolder IshFolder
+ {
+ private get { return null; } // required otherwise XmlDoc2CmdletDoc crashes with 'System.ArgumentException: Property Get method was not found.'
+ set { _folderId = value.IshFolderRef; }
+ }
+
+ ///
+ /// The .
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [ValidateNotNullOrEmpty]
+ public Enumerations.ISHType IshType
+ {
+ //TODO: [Should] Derive IshType from incoming IshFolder
+ get { return _ishType; }
+ set { _ishType = value; }
+ }
+
+ ///
+ /// The LogicalId of the DocumentObj.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [ValidateNotNullOrEmpty]
+ public string LogicalId
+ {
+ get { return _logicalId; }
+ set { _logicalId = value; }
+ }
+
+ ///
+ /// The Version of the DocumentObj.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [ValidateNotNullOrEmpty]
+ public string Version
+ {
+ get { return _version; }
+ set { _version = value; }
+ }
+
+ ///
+ /// The Language of the DocumentObj.
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [ValidateNotNull]
+ public string Lng { get; set; }
+
+ ///
+ /// The Resolution of the DocumentObj.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [ValidateNotNull]
+ public string Resolution { get; set; }
+
+ ///
+ /// The metadata of the DocumentObj.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [ValidateNotNull]
+ public IshField[] Metadata { get; set; }
+
+ ///
+ /// The unique identifier of the Electronic Document Type for the content (e.g. EDTPDF, EDTXML, EDTHTML,...) of the new object.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [ValidateNotNullOrEmpty]
+ public string Edt
+ {
+ get { return _edt; }
+ set { _edt = value; }
+ }
+
+ ///
+ /// The path to the file containing data for the DocumentObj
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [ValidateNotNullOrEmpty]
+ public string FilePath { get; set; }
+
+ ///
+ /// String with XML content of the DocumentObj
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [ValidateNotNullOrEmpty]
+ public string FileContent { get; set; }
+
+ ///
+ /// The s that need to be added.
+ ///
+ [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = "IshObjectsGroup")]
+ [AllowEmptyCollection]
+ public IshObject[] IshObject { get; set; }
+
+
+ #region Private fields
+ ///
+ /// Private fields to store the provide a default for non-mandatory parameters
+ ///
+ private Enumerations.ISHType _ishType = Enumerations.ISHType.ISHNone;
+ ///
+ /// Logical Id will be defaulted to typical GUID-XYZ in uppercase
+ ///
+ private string _logicalId = ("GUID-" + Guid.NewGuid()).ToUpper();
+ ///
+ /// Version will be defaulted to NEW, meaning that a first or next version will be created for existing objects
+ ///
+ private string _version = "NEW";
+ ///
+ /// EDT will be defaulted to EDTXML. Needs to match up with FileContent or FilePath content.
+ ///
+ private string _edt = "EDTXML";
+ ///
+ /// Holds the folder card id, specified by incoming parameter (long,IShObject)
+ ///
+ private long _folderId = -1;
+ ///
+ /// Holds IshData object initialized either by EDT and FilePath or EDT and FileContent
+ ///
+ private IshData _ishData;
+ #endregion
+
+ protected override void BeginProcessing()
+ {
+ if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); }
+ if (IshSession == null) { throw new ArgumentException(ISHRemoteSessionStateIshSessionException); }
+ WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession}");
+ base.BeginProcessing();
+ }
+
+ ///
+ /// Process the Add-IshDocumentObj commandlet.
+ ///
+ ///
+ ///
+ /// Writes an array to the pipeline.
+ protected override void ProcessRecord()
+ {
+ try
+ {
+ // 1. Validating the input
+ WriteDebug("Validating");
+
+ // Parameters to retrieve added document
+ List returnIshObjects = new List();
+
+ WriteDebug("Adding");
+
+ if (IshObject != null)
+ {
+ int current = 0;
+ foreach (IshObject ishObject in IshObject)
+ {
+ WriteDebug($"lngRef[{ishObject.ObjectRef[Enumerations.ReferenceType.Lng]}] {++current}/{IshObject.Length}");
+
+ // 2b. Add using IshObject pipeline
+ // Initialize from the object
+ string logicalId = ishObject.IshRef;
+ string ishObjectVersion = ishObject.IshFields.GetFieldValue("VERSION", Enumerations.Level.Version, Enumerations.ValueType.Value);
+ //TODO: [Should] Respect LanguageApplicability, which means take the first entry from the ishfield DOC-LANGUAGE value
+ string ishObjectLanguage = ishObject.IshFields.GetFieldValue("DOC-LANGUAGE", Enumerations.Level.Lng, Enumerations.ValueType.Value);
+ string ishObjectResolution = ishObject.IshFields.GetFieldValue("FRESOLUTION", Enumerations.Level.Lng, Enumerations.ValueType.Value);
+ var metadata = IshSession.IshTypeFieldSetup.ToIshMetadataFields(ISHType, ishObject.IshFields, Enumerations.ActionMode.Create);
+
+ // Add
+ WriteDebug($"LogicalId[{logicalId}] Version[{ishObjectVersion}] Lng[{ishObjectLanguage}] Resolution[{ishObjectResolution}] Metadata.length[{metadata.ToXml().Length}] dataSize[{ishObject.IshData.Size()}]");
+ DocumentObj25ServiceReference.CreateResponse responseCreate = null;
+ if (ShouldProcess(logicalId + "=" + ishObjectVersion + "=" + ishObjectLanguage + "=" + ishObjectResolution))
+ {
+ responseCreate = IshSession.DocumentObj25.Create(new DocumentObj25ServiceReference.CreateRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ plFolderRef= _folderId,
+ psIshType = ishObject.IshType.ToString(),
+ psLogicalId = logicalId,
+ psVersion = ishObjectVersion,
+ psLanguage = ishObjectLanguage,
+ psResolution = ishObjectResolution,
+ psXMLMetadata = metadata.ToXml(),
+ psEdt = ishObject.IshData.Edt,
+ pbData = ishObject.IshData.ByteArray
+ });
+ }
+
+ IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, metadata, Enumerations.ActionMode.Read);
+ var responseGet = IshSession.DocumentObj25.GetMetaData(new DocumentObj25ServiceReference.GetMetaDataRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psLogicalId = responseCreate.psLogicalId,
+ psVersion = responseCreate.psVersion,
+ psLanguage = ishObjectLanguage,
+ psResolution = ishObjectResolution,
+ psXMLRequestedMetaData = requestedMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = responseGet.psAuthContext;
+ string xmlIshObjects = responseGet.psOutXMLObjList;
+ IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects);
+ returnIshObjects.AddRange(retrievedObjects.Objects);
+ }
+ }
+ // 2a. LogicalId is provided
+ else
+ {
+ string resolution = Resolution ?? "";
+ if ((FileContent != null) && (FilePath == null))
+ {
+ if (!_edt.Equals("EDTXML", StringComparison.Ordinal))
+ {
+ throw new NotImplementedException("FileContent parameter is only supported with Edt='EDTXML'");
+ }
+
+ var doc = XDocument.Parse(FileContent, LoadOptions.PreserveWhitespace);
+ var ms = new MemoryStream();
+ doc.Save(ms, SaveOptions.DisableFormatting);
+ _ishData = new IshData(_edt, ms.ToArray());
+ }
+ if ((FileContent == null) && (FilePath != null))
+ {
+ _ishData = new IshData(_edt, FilePath);
+ }
+
+ var metadata = IshSession.IshTypeFieldSetup.ToIshMetadataFields(ISHType, new IshFields(Metadata), Enumerations.ActionMode.Create);
+ WriteDebug($"LogicalId[{LogicalId}] Version[{Version}] Lng[{Lng}] Resolution[{resolution}] Metadata.length[{metadata.ToXml().Length}] byteArray[{_ishData.Size()}]");
+ if (ShouldProcess(LogicalId + "=" + Version + "=" + Lng + "=" + resolution))
+ {
+ var responseCreate = IshSession.DocumentObj25.Create(new DocumentObj25ServiceReference.CreateRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ plFolderRef = _folderId,
+ psIshType = IshType.ToString(),
+ psLogicalId = LogicalId,
+ psVersion = Version,
+ psLanguage = Lng,
+ psResolution = resolution,
+ psXMLMetadata = metadata.ToXml(),
+ psEdt = _ishData.Edt,
+ pbData = _ishData.ByteArray
+ });
+ IshSession.AuthenticationContext = responseCreate.psAuthContext;
+ IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, metadata, Enumerations.ActionMode.Read);
+ var response = IshSession.DocumentObj25.GetMetaData(new DocumentObj25ServiceReference.GetMetaDataRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psLogicalId = responseCreate.psLogicalId,
+ psVersion = responseCreate.psVersion,
+ psLanguage = Lng,
+ psResolution = resolution,
+ psXMLRequestedMetaData = requestedMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = responseCreate.psAuthContext;
+ string xmlIshObjects = response.psOutXMLObjList;
+ IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects);
+ returnIshObjects.AddRange(retrievedObjects.Objects);
+ }
+ }
+
+ WriteVerbose("returned object count[" + returnIshObjects.Count + "]");
+ WriteObject(IshSession, ISHType, returnIshObjects.ConvertAll(x => (IshBaseObject)x), true);
+ }
+ catch (TrisoftAutomationException trisoftAutomationException)
+ {
+ ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
+ }
+ catch (Exception exception)
+ {
+ ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
+ }
+ }
+ }
+}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/DocumentObjCmdlet.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/DocumentObjCmdlet.cs
new file mode 100644
index 00000000..0e00a8b9
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/DocumentObjCmdlet.cs
@@ -0,0 +1,33 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Management.Automation;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+using Trisoft.ISHRemote.Exceptions;
+using System.Collections.Generic;
+
+namespace Trisoft.ISHRemote.Cmdlets.DocumentObj
+{
+ public abstract class DocumentObjCmdlet : TrisoftCmdlet
+ {
+ public Enumerations.ISHType[] ISHType
+ {
+ get { return new Enumerations.ISHType[] { Enumerations.ISHType.ISHIllustration, Enumerations.ISHType.ISHLibrary, Enumerations.ISHType.ISHMasterDoc, Enumerations.ISHType.ISHModule, Enumerations.ISHType.ISHTemplate }; }
+ }
+ }
+}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/GetIshDocumentObj.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/GetIshDocumentObj.cs
new file mode 100644
index 00000000..96a3fc86
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/GetIshDocumentObj.cs
@@ -0,0 +1,295 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Management.Automation;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+using Trisoft.ISHRemote.Exceptions;
+using Trisoft.ISHRemote.HelperClasses;
+using System.Linq;
+
+namespace Trisoft.ISHRemote.Cmdlets.DocumentObj
+{
+ ///
+ /// Retrieves the metadata and optionally blob of document objects
+ /// Gets IshObject entries through logical id filtering or language card ids, optionally providing the blob.
+ /// Uses DocumentObj25 API to retrieve ishobjects.
+ /// The Get-IshDocumentObj cmdlet retrieves metadata of the document objects that are passed through the pipeline or determined via provided parameters. This commandlet allows to retrieve all types of objects(Illustrations, Maps, etc. ), except for publication(outputs). For publication(outputs) you need to use Get-IshPublicationOutput.
+ ///
+ ///
+ ///
+ /// $ishSession = New-IshSession -WsBaseUrl "https://example.com/InfoShareWS/" -PSCredential Admin
+ /// Get-IshDocumentObj -LogicalId ISHPUBLILLUSTRATIONMISSING
+ ///
+ /// New-IshSession will submit into SessionState, so it can be reused by this cmdlet. Returns all versions/language of object identified through LogicalId Get-IshDocumentObj -LogicalId ISHPUBLILLUSTRATIONMISSING (typically also GUIDs).
+ ///
+ [Cmdlet(VerbsCommon.Get, "IshDocumentObj", SupportsShouldProcess = false)]
+ [OutputType(typeof(IshDocumentObj))]
+ public sealed class GetIshDocumentObj : DocumentObjCmdlet
+ {
+ ///
+ /// The IshSession variable holds the authentication and contract information. This object can be initialized using the New-IshSession cmdlet.
+ ///
+ [Parameter(Mandatory =false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory =false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [ValidateNotNullOrEmpty]
+ public IshSession IshSession { get; set; }
+
+ ///
+ /// The logical identifiers of the document objects for which to retrieve the metadata
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup"), ValidateNotNullOrEmpty]
+ public string[] LogicalId { get; set; }
+
+ ///
+ /// The metadata filter with the filter fields to limit the amount of objects returned. Default is no filtering.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [ValidateNotNullOrEmpty]
+ public IshField[] MetadataFilter { get; set; }
+
+ ///
+ /// The metadata fields to retrieve
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [ValidateNotNullOrEmpty]
+ public IshField[] RequestedMetadata { get; set; }
+
+ ///
+ /// The status filter to limit the amount of objects returned. Default is no filtering.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [ValidateNotNullOrEmpty]
+ public Enumerations.StatusFilter StatusFilter
+ {
+ get { return _statusFilter; }
+ set { _statusFilter = value; }
+ }
+
+ ///
+ /// Switch patameter that specifies if the return objects should hold the blob (ishdata) sections, potentially conditionally published if IshFeature was passed
+ ///
+ [Parameter(Mandatory = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ParameterSetName = "IshObjectsGroup")]
+ public SwitchParameter IncludeData
+ {
+ get { return _includeData; }
+ set { _includeData = value; }
+ }
+
+ ///
+ /// The condition context to use for conditional filtering. If no context is provided, the elements containing ishcondition attributes will always remain in the data content. You can use the Set-IshFeature cmdlet to create a condition context.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ public IshFeature[] IshFeature { get; set; }
+
+ ///
+ /// Array with the objects for which to retrieve the metadata. This array can be passed through the pipeline or explicitly passed via the parameter.
+ ///
+ [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = "IshObjectsGroup")]
+ [AllowEmptyCollection]
+ public IshObject[] IshObject { get; set; }
+
+
+
+
+
+ #region Private fields
+
+ ///
+ /// Private field to store the IshType and provide a default for non-mandatory parameters
+ ///
+ private Enumerations.StatusFilter _statusFilter = Enumerations.StatusFilter.ISHNoStatusFilter;
+
+ ///
+ /// Switch patameter that specifies if the return objects should hold the blob (ishdata) sections, potentially conditionally published if IshFeature was passed
+ ///
+ private bool _includeData = false;
+ #endregion
+
+ protected override void BeginProcessing()
+ {
+ if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); }
+ if (IshSession == null) { throw new ArgumentException(ISHRemoteSessionStateIshSessionException); }
+ WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession}");
+ base.BeginProcessing();
+ }
+
+ ///
+ /// Process the Get-IshDocumentObj commandlet.
+ ///
+ ///
+ ///
+ /// Writes an array to the pipeline.
+ protected override void ProcessRecord()
+ {
+ try
+ {
+ // 1. Validating the input
+ WriteDebug("Validating");
+
+ List returnIshObjects = new List();
+
+ if (IshObject != null && IshObject.Length == 0)
+ {
+ // Do nothing
+ WriteVerbose("IshObject is empty, so nothing to retrieve");
+ }
+ else
+ {
+ WriteDebug("Retrieving");
+ IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, new IshFields(RequestedMetadata), Enumerations.ActionMode.Read);
+
+ if (IshObject != null)
+ {
+ // 2a. Retrieve using LngCardIds
+ IshObjects ishObjects = new IshObjects(IshObject);
+ var lngCardIds =
+ ishObjects.Objects.Select(
+ ishObject => Convert.ToInt64(ishObject.ObjectRef[Enumerations.ReferenceType.Lng])).ToList();
+ if (!_includeData)
+ {
+ //RetrieveMetadata
+ WriteDebug("Retrieving CardIds.length[{lngCardIds.Count}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] 0/{lngCardIds.Count}");
+ // Devides the list of language card ids in different lists that all have maximally MetadataBatchSize elements
+ List> devidedlngCardIdsList = DevideListInBatches(lngCardIds, IshSession.MetadataBatchSize);
+ int currentLngCardIdCount = 0;
+ foreach (List lngCardIdBatch in devidedlngCardIdsList)
+ {
+ // Process language card ids in batches
+ var response = IshSession.DocumentObj25.RetrieveMetadataByIshLngRefs(new DocumentObj25ServiceReference.RetrieveMetadataByIshLngRefsRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ palLngRefs = lngCardIdBatch.ToArray(),
+ psXMLRequestedMetadata = requestedMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ string xmlIshObjects = response.psOutXMLObjList;
+ IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects);
+ returnIshObjects.AddRange(retrievedObjects.Objects);
+ currentLngCardIdCount += lngCardIdBatch.Count;
+ WriteDebug($"Retrieving CardIds.length[{lngCardIdBatch.Count}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] including data {currentLngCardIdCount}/{lngCardIds.Count}");
+ }
+ }
+ else
+ {
+ //RetrieveObjects
+ WriteDebug($"Retrieving CardIds.length[{lngCardIds.Count}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] including data 0/{lngCardIds.Count}");
+ IshFeatures productDefinitionFeatures = new IshFeatures(IshFeature);
+ // Devides the list of language card ids in different lists that all have maximally BlobBatchSize elements
+ List> devidedlngCardIdsList = DevideListInBatches(lngCardIds, IshSession.BlobBatchSize);
+ int currentLngCardIdCount = 0;
+ foreach (List lngCardIdBatch in devidedlngCardIdsList)
+ {
+ // Process language card ids in batches
+ var response = IshSession.DocumentObj25.RetrieveObjectsByIshLngRefs(new DocumentObj25ServiceReference.RetrieveObjectsByIshLngRefsRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ palLngRefs = lngCardIdBatch.ToArray(),
+ psXmlProductDefinition = productDefinitionFeatures.ToXml(),
+ psXMLRequestedMetadata = requestedMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ string xmlIshObjects = response.psOutXMLObjList;
+ IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects);
+ returnIshObjects.AddRange(retrievedObjects.Objects);
+ currentLngCardIdCount += lngCardIdBatch.Count;
+ WriteDebug($"Retrieving CardIds.length[{lngCardIdBatch.Count}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] including data {currentLngCardIdCount}/{lngCardIds.Count}");
+ }
+ }
+ }
+ else
+ {
+ // 2b. Retrieve using LogicalId
+ IshFields metadataFilter = new IshFields(MetadataFilter);
+ var statusFilter = EnumConverter.ToStatusFilter(StatusFilter);
+ if (!_includeData)
+ {
+ //RetrieveMetadata
+ WriteDebug($"Retrieving LogicalId.length[{LogicalId.Length}] StatusFilter[{statusFilter}] MetadataFilter.length[{metadataFilter.ToXml().Length}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] 0/{LogicalId.Length}");
+ // Devides the list of language card ids in different lists that all have maximally MetadataBatchSize elements
+ List> devidedlogicalIdsList = DevideListInBatches(LogicalId.ToList(), IshSession.MetadataBatchSize);
+ int currentLogicalIdCount = 0;
+ foreach (List logicalIdBatch in devidedlogicalIdsList)
+ {
+ // Process language card ids in batches
+ var response = IshSession.DocumentObj25.RetrieveMetadata(new DocumentObj25ServiceReference.RetrieveMetadataRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ pasLogicalIds = logicalIdBatch.ToArray(),
+ peStatusFilter = statusFilter,
+ psXMLMetadataFilter = metadataFilter.ToXml(),
+ psXMLRequestedMetadata = requestedMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ string xmlIshObjects = response.psOutXMLObjList;
+ IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects);
+ returnIshObjects.AddRange(retrievedObjects.Objects);
+ currentLogicalIdCount += logicalIdBatch.Count;
+ WriteDebug($"Retrieving LogicalId.length[{logicalIdBatch.Count}] StatusFilter[{statusFilter}] MetadataFilter.length[{metadataFilter.ToXml().Length}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] {currentLogicalIdCount}/{LogicalId.Length}");
+ }
+ }
+ else
+ {
+ //RetrieveObjects
+ WriteDebug($"Retrieving LogicalId.length[{LogicalId.Length}] StatusFilter[{statusFilter}] MetadataFilter.length[{metadataFilter.ToXml().Length}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] 0/{LogicalId.Length}");
+ IshFeatures productDefinitionFeatures = new IshFeatures(IshFeature);
+ // Devides the list of language card ids in different lists that all have maximally BlobBatchSize elements
+ List> devidedlogicalIdsList = DevideListInBatches(LogicalId.ToList(), IshSession.BlobBatchSize);
+ int currentLogicalIdCount = 0;
+ foreach (List logicalIdBatch in devidedlogicalIdsList)
+ {
+ // Process language card ids in batches
+ var response = IshSession.DocumentObj25.RetrieveObjects(new DocumentObj25ServiceReference.RetrieveObjectsRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ pasLogicalIds = logicalIdBatch.ToArray(),
+ peStatusFilter = statusFilter,
+ psXMLMetadataFilter = metadataFilter.ToXml(),
+ psXmlProductDefinition = productDefinitionFeatures.ToXml(),
+ psXMLRequestedMetadata = requestedMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ string xmlIshObjects = response.psOutXMLObjList;
+ IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects);
+ returnIshObjects.AddRange(retrievedObjects.Objects);
+ currentLogicalIdCount += logicalIdBatch.Count;
+ WriteDebug($"Retrieving LogicalId.length[{logicalIdBatch.Count}] StatusFilter[{statusFilter}] MetadataFilter.length[{metadataFilter.ToXml().Length}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] {currentLogicalIdCount}/{LogicalId.Length}");
+ }
+ }
+ }
+ }
+
+ WriteVerbose("returned object count[" + returnIshObjects.Count + "]");
+ WriteObject(IshSession, ISHType, returnIshObjects.ConvertAll(x => (IshBaseObject)x), true);
+ }
+ catch (TrisoftAutomationException trisoftAutomationException)
+ {
+ ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
+ }
+ catch (Exception exception)
+ {
+ ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
+ }
+ }
+ }
+}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/GetIshDocumentObjData.Tests.ps1 b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/GetIshDocumentObjData.Tests.ps1
new file mode 100644
index 00000000..fecae104
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/GetIshDocumentObjData.Tests.ps1
@@ -0,0 +1,89 @@
+BeforeAll {
+ $cmdletName = "Get-IshDocumentObjData"
+ Write-Host ("`r`nLoading ISHRemote.PesterSetup.ps1 over BeforeAll-block for MyCommand[" + $cmdletName + "]...")
+ . (Join-Path (Split-Path -Parent $PSCommandPath) "\..\..\ISHRemote.PesterSetup.ps1")
+
+ Write-Host ("Running "+$cmdletName+" Test Data and Variables initialization")
+ $tempFolder = [System.IO.Path]::GetTempPath()
+}
+
+Describe "Get-IshDocumentObjData" -Tags "Read" {
+ BeforeAll {
+ $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Name "FNAME" |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Name "FDOCUMENTTYPE" |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Name "READ-ACCESS" -ValueType Element |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Name "FUSERGROUP" -ValueType Element
+ $ishFolderTestRootOriginal = Get-IshFolder -IShSession $ishSession -FolderPath $folderTestRootPath -RequestedMetadata $requestedMetadata
+ $folderIdTestRootOriginal = $ishFolderTestRootOriginal.IshFolderRef
+ $folderTypeTestRootOriginal = $ishFolderTestRootOriginal.IshFolderType
+ Write-Debug ("folderIdTestRootOriginal[" + $folderIdTestRootOriginal + "] folderTypeTestRootOriginal[" + $folderTypeTestRootOriginal + "]")
+ $ownedByTestRootOriginal = Get-IshMetadataField -IshSession $ishSession -Name "FUSERGROUP" -ValueType Element -IshField $ishFolderTestRootOriginal.IshField
+ $readAccessTestRootOriginal = (Get-IshMetadataField -IshSession $ishSession -Name "READ-ACCESS" -ValueType Element -IshField $ishFolderTestRootOriginal.IshField).Split($ishSession.Separator)
+
+ $global:ishFolderCmdlet = Add-IshFolder -IShSession $ishSession -ParentFolderId $folderIdTestRootOriginal -FolderType $folderTypeTestRootOriginal -FolderName $cmdletName -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+ $ishFolderTopic = Add-IshFolder -IshSession $ishSession -ParentFolderId ($global:ishFolderCmdlet.IshFolderRef) -FolderType ISHModule -FolderName "Topic" -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+ $ishFolderLib = Add-IshFolder -IshSession $ishSession -ParentFolderId ($global:ishFolderCmdlet.IshFolderRef) -FolderType ISHLibrary -FolderName "Library" -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Topic $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObjectTopicA = Add-IshDocumentObj -IshSession $ishSession -FolderId $ishFolderTopic.IshFolderRef -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent
+ $ishObjectLibraryA = Add-IshDocumentObj -IshSession $ishSession -FolderId $ishFolderLib.IshFolderRef -IshType ISHLibrary -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent
+ }
+ Context "Get-IshDocumentObjData FolderPathGroup" {
+ It "Parameter IshSession/IshObject invalid" {
+ { Get-IshDocumentObjData -IShSession "INVALIDISHSESSION" -IshObject "INVALIDISHOBJECT" } | Should -Throw
+ }
+ It "FileInfo.Name contains 4 = signs" {
+ $fileInfo = Get-IshDocumentObjData -IshSession $ishSession -IshObject $ishObjectTopicA -FolderPath (Join-Path $tempFolder $cmdletName)
+ $fileInfo.GetType().Name | Should -BeExactly "FileInfo"
+ $fileInfo.Name -like "*=*=*=*=*.*" | Should -Be $true
+ }
+ It "Parameter IshFeature matching features (so everything equals source file)" {
+ $ishFeatures = Set-IshFeature -Name "ISHRemoteStringCond" -Value "StringOne" |
+ Set-IshFeature -Name "ISHRemoteVersionCond" -Value "12.0.1"
+ $fileInfo = Get-IshDocumentObjData -IshSession $ishSession -IshObject $ishObjectTopicA -FolderPath (Join-Path $tempFolder $cmdletName) -IshFeature $ishFeatures
+ $fileContent = Get-Content $fileInfo -Raw
+ Write-Debug ("fileContent.Length[" + $fileContent.Length + "] fileContent.GetType()[" + $fileContent.GetType() + "] fileContent[" +$fileContent+"]")
+ ($fileContent -like "*ISHRemoteStringCond*") | Should -Be $true
+ }
+ It "Parameter IshFeature not matching features (so everything filtered away)" {
+ $ishFeatures = Set-IshFeature -Name "INVALIDFEATURE" -Value "INVALIDVALUE"
+ $fileInfo = Get-IshDocumentObjData -IshSession $ishSession -IshObject $ishObjectTopicA -FolderPath (Join-Path $tempFolder $cmdletName) -IshFeature $ishFeatures
+ $fileContent = Get-Content $fileInfo -Raw
+ Write-Debug ("fileContent.Length[" + $fileContent.Length + "] fileContent.GetType()[" + $fileContent.GetType() + "] fileContent[" +$fileContent+"]")
+ $fileContent -notlike "*ISHRemoteStringCond*" | Should -Be $true
+ }
+ }
+ Context "Get-IshDocumentObjData IshObjectGroup" {
+ It "GetType().Name" {
+ $ishobjects = Get-IshDocumentObjData -IshSession $ishSession -IshObject @($ishObjectTopicA,$ishObjectLibraryA)
+ $ishobjects.GetType().Name | Should -BeExactly "Object[]"
+ }
+ It "Parameter IshObject Single with implicit IshSession" {
+ $ishobjects = Get-IshDocumentObjData -IshObject $ishObjectTopicA
+ $ishobjects.Count | Should -Be 1
+ }
+ It "Parameter IshObject Multiple with implicit IshSession" {
+ $ishobjects = Get-IshDocumentObjData -IshObject @($ishObjectTopicA,$ishObjectLibraryA)
+ $ishobjects.Count | Should -Be 2
+ }
+ It "Pipeline IshObject Single" {
+ $ishobjects = $ishObjectTopicA | Get-IshDocumentObjData -IshSession $ishSession
+ $ishobjects.Count | Should -Be 1
+ }
+ It "Pipeline IshObject Multiple" {
+ $ishobjects = @($ishObjectTopicA,$ishObjectLibraryA) | Get-IshDocumentObjData -IshSession $ishSession
+ $ishobjects.Count | Should -Be 2
+ }
+ }
+}
+
+AfterAll {
+ Write-Host ("Running "+$cmdletName+" Test Data and Variables cleanup")
+ $folderCmdletRootPath = (Join-Path $folderTestRootPath $cmdletName)
+ try { Get-IshFolder -IshSession $ishSession -FolderPath $folderCmdletRootPath -Recurse | Get-IshFolderContent -IshSession $ishSession | Remove-IshDocumentObj -IshSession $ishSession -Force } catch { }
+ try { Remove-IshFolder -IshSession $ishSession -FolderPath $folderCmdletRootPath -Recurse } catch { }
+ try { Remove-Item (Join-Path $tempFolder $cmdletName) -Recurse -Force } catch { }
+}
+
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/GetIshDocumentObjData.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/GetIshDocumentObjData.cs
new file mode 100644
index 00000000..4578f568
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/GetIshDocumentObjData.cs
@@ -0,0 +1,187 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Management.Automation;
+using System.Xml;
+using Trisoft.ISHRemote.Exceptions;
+using Trisoft.ISHRemote.HelperClasses;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+
+namespace Trisoft.ISHRemote.Cmdlets.DocumentObj
+{
+ ///
+ /// The Get-IshDocumentObjData cmdlet retrieves the data/blob of the document objects that are passed through the pipeline or determined via provided parameters and saves them to the given Windows folder. This commandlet allows to retrieve all types of objects (Illustrations, Maps, etc. ), except for publication (outputs).
+ /// For publication (outputs) you need to use Get-IshPublicationOutputData.
+ /// The Get-IshDocumentObjData cmdlet retrieves the data/blob of the document objects that are passed through the pipeline or determined via provided parameters and saves them to the given Windows folder. This commandlet allows to retrieve all types of objects (Illustrations, Maps, etc. ), except for publication (outputs).
+ /// For publication (outputs) you need to use Get-IshPublicationOutputData.
+ ///
+ ///
+ ///
+ /// $ishSession = New-IshSession -WsBaseUrl "https://example.com/InfoShareWS/" -IshUserName "username" -IshUserPassword "userpassword"
+ /// $ishMetadataFilterFields = Set-IshMetadataFilterField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -FilterOperator "Like" -Value "%topic%" |
+ /// Set-IshMetadataFilterField -IshSession $ishSession -Name "FAUTHOR" -Level "Lng" -FilterOperator "Equal" -Value "admin" |
+ /// Set-IshMetadataFilterField -IshSession $ishSession -Name "FSTATUS" -Level "Lng" -FilterOperator "Equal" -Value "To be translated"
+ /// $ishRequestedFields = Set-IshRequestedMetadataField -IshSession $ishSession -Name "FTITLE" -Level "logical" |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Name "VERSION" -Level "version" |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Name "DOC-LANGUAGE" -Level "lng"
+ /// $fileList = Find-IshDocumentObj -IshSession $ishSession -MetadataFilter $ishMetadataFilterFields `
+ /// -IshTypeFilter "ISHModule" `
+ /// -RequestedMetadata $ishRequestedFields |
+ /// Get-IshDocumentObjData $ishSession `
+ /// -FolderPath "c:\temp\export"
+ ///
+ /// New-IshSession will submit into SessionState, so it can be reused by this cmdlet. Download modules to a temp location
+ ///
+ [Cmdlet(VerbsCommon.Get, "IshDocumentObjData", SupportsShouldProcess = false)]
+ [OutputType(typeof(IshObject), typeof(FileInfo))]
+ public sealed class GetIshDocumentObjData : DocumentObjCmdlet
+ {
+ ///
+ /// The IshSession variable holds the authentication and contract information. This object can be initialized using the New-IshSession cmdlet.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false)]
+ [ValidateNotNullOrEmpty]
+ public IshSession IshSession { get; set; }
+
+ ///
+ /// Array with the objects for which to retrieve the data. This array can be passed through the pipeline or explicitly passed via the parameter.
+ ///
+ [Parameter(Mandatory = true, ValueFromPipeline = true)]
+ [AllowEmptyCollection]
+ public IshObject[] IshObject { get; set; }
+
+ ///
+ /// Folder on the Windows filesystem where to store the retrieved data files
+ ///
+ [Parameter(Mandatory = false, ValueFromPipeline = false)]
+ public string FolderPath { get; set; }
+
+ ///
+ /// The condition context to use for conditional filtering. If no context is provided, the elements containing ishcondition attributes will always remain in the data content. You can use the Set-IshFeature cmdlet to create a condition context.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false)]
+ public IshFeature[] IshFeature { get; set; }
+
+ protected override void BeginProcessing()
+ {
+ if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); }
+ if (IshSession == null) { throw new ArgumentException(ISHRemoteSessionStateIshSessionException); }
+ WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession}");
+ base.BeginProcessing();
+ }
+
+ ///
+ /// Process the Get-IshDocumentObjData commandlet.
+ ///
+ ///
+ ///
+ /// Writes an array to the pipeline.
+ protected override void ProcessRecord()
+ {
+ try
+ {
+ List fileInfo = new List();
+
+ if (IshObject != null && IshObject.Length == 0)
+ {
+ WriteVerbose("IshObject is empty, so nothing to retrieve");
+ }
+ else
+ {
+ WriteDebug("Retrieving");
+
+ IshFeatures productDefinitionFeatures = new IshFeatures(IshFeature);
+ int current = 0;
+
+ var ishObjects = new IshObjects(IshObject).Objects;
+ foreach (IshObject ishObject in ishObjects)
+ {
+ // Get language ref
+ long lngRef = Convert.ToInt64(ishObject.ObjectRef[Enumerations.ReferenceType.Lng]);
+ long[] lngRefsArray = new long[1] { lngRef };
+
+ var response = IshSession.DocumentObj25.RetrieveObjectsByIshLngRefs(new DocumentObj25ServiceReference.RetrieveObjectsByIshLngRefsRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ palLngRefs = lngRefsArray,
+ psXmlProductDefinition = productDefinitionFeatures.ToXml(),
+ psXMLRequestedMetadata = ""
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ using (var stringReader = new StringReader(response.psOutXMLObjList))
+ {
+ byte[] bytearray = null;
+ string edt = "";
+ string fileExtension = "";
+
+ using (XmlTextReader xmlTextReader = new XmlTextReader(stringReader))
+ {
+ while (xmlTextReader.Read())
+ {
+ if (xmlTextReader.NodeType == XmlNodeType.Element && xmlTextReader.Name == "ishdata")
+ {
+ edt = xmlTextReader.GetAttribute("edt");
+ fileExtension = xmlTextReader.GetAttribute("fileextension");
+ }
+
+ if (xmlTextReader.NodeType == XmlNodeType.CDATA)
+ {
+ bytearray = System.Convert.FromBase64String(xmlTextReader.Value);
+ }
+ }
+ }
+ IshData ishData = new IshData(edt, fileExtension, bytearray);
+
+ if (FolderPath != null)
+ {
+ string tempLocation = Directory.CreateDirectory(FolderPath).FullName;
+ WriteDebug($"Writing lngRef[{lngRef}] to [{tempLocation}] {++current}/{ishObjects.Length}");
+ //Create the file.
+ string tempFilePath = FileNameHelper.GetDefaultObjectFileName(tempLocation, ishObject, ishData.FileExtension);
+ using (FileStream fs = File.Create(tempFilePath))
+ {
+ fs.Write(ishData.ByteArray, 0, ishData.Size());
+ }
+ // Append file info list
+ fileInfo.Add(new FileInfo(tempFilePath));
+ WriteObject(fileInfo, true);
+ }
+ else
+ {
+ WriteDebug($"Enriching ishObject[{ishObject.ObjectRef[Enumerations.ReferenceType.Lng]}] with IshData {++current}/{IshObject.Length}");
+ ishObject.IshData = ishData;
+ WriteObject(ishObject, true);
+ }
+ }
+ }
+ WriteVerbose("returned file count[" + current + "]");
+ }
+ }
+ catch (TrisoftAutomationException trisoftAutomationException)
+ {
+ ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
+ }
+ catch (Exception exception)
+ {
+ ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
+ }
+ }
+ }
+}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/RemoveIshDocumentObj.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/RemoveIshDocumentObj.cs
new file mode 100644
index 00000000..195bc3b6
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/RemoveIshDocumentObj.cs
@@ -0,0 +1,261 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.Linq;
+using System.Management.Automation;
+using Trisoft.ISHRemote.DocumentObj25ServiceReference;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+using Trisoft.ISHRemote.Exceptions;
+
+namespace Trisoft.ISHRemote.Cmdlets.DocumentObj
+{
+ ///
+ /// The Remove-IshDocumentObj cmdlet removes the document objects that are passed through the pipeline or determined via provided parameters This commandlet allows to remove all types of objects (Illustrations, Maps, etc. ), except for publication (outputs).
+ /// For publication (outputs) you need to use Remove-IshPublicationOutput.
+ /// The Remove-IshDocumentObj cmdlet removes the document objects that are passed through the pipeline or determined via provided parameters This commandlet allows to remove all types of objects (Illustrations, Maps, etc. ), except for publication (outputs).
+ /// For publication (outputs) you need to use Remove-IshPublicationOutput.
+ ///
+ ///
+ ///
+ /// $ishSession = New-IshSession -WsBaseUrl "https://example.com/InfoShareWS/" -PSCredential Admin
+ /// Get-IshFolder -FolderPath $folderCmdletRootPath -Recurse |
+ /// Get-IshFolderContent |
+ /// Remove-IshDocumentObj -Force
+ ///
+ /// New-IshSession will submit into SessionState, so it can be reused by this cmdlet. Removes all content objects from the listed folder and its subfolders.
+ ///
+ [Cmdlet(VerbsCommon.Remove, "IshDocumentObj", SupportsShouldProcess = true)]
+ public sealed class RemoveIshDocumentObj : DocumentObjCmdlet
+ {
+
+ ///
+ /// The IshSession variable holds the authentication and contract information. This object can be initialized using the New-IshSession cmdlet.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [ValidateNotNullOrEmpty]
+ public IshSession IshSession { get; set; }
+
+ ///
+ /// The logical identifier of the document object
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup"), ValidateNotNullOrEmpty]
+ public string LogicalId { get; set; }
+
+ ///
+ /// The version of the document object
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup"), ValidateNotNullOrEmpty]
+ public string Version { get; set; }
+
+ ///
+ /// The language of the document object
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup"), ValidateNotNullOrEmpty]
+ public string Lng { get; set; }
+
+ ///
+ /// The resolution of the document object
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup"), ValidateNotNullOrEmpty]
+ public string Resolution { get; set; }
+
+ ///
+ /// The required current metadata of the document object. This parameter can be used to avoid that users override changes done by other users. The cmdlet will check whether the fields provided in this parameter still have the same values in the repository:
+ /// If the metadata is still the same, the document object is removed.
+ /// If the metadata is not the same anymore, an error is given and the document object is not removed.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [ValidateNotNullOrEmpty]
+ public IshField[] RequiredCurrentMetadata { get; set; }
+
+ ///
+ /// Array with the objects to remove. This array can be passed through the pipeline or explicitly passed via the parameter.
+ ///
+ /// TODO [Should] Promote parameter IshObject to IshObject[] processing
+ [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = "IshObjectsGroup")]
+ public IshObject IshObject { get; set; }
+
+ ///
+ /// When the Force switch is set, after deleting the language object, the version object and logical object will be deleted if they don't have any language objects anymore
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [ValidateNotNullOrEmpty]
+ public SwitchParameter Force { get; set; }
+
+ protected override void BeginProcessing()
+ {
+ if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); }
+ if (IshSession == null) { throw new ArgumentException(ISHRemoteSessionStateIshSessionException); }
+ WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession}");
+ base.BeginProcessing();
+ }
+
+ ///
+ /// Process the Remove-IshDocumentObj commandlet.
+ ///
+ ///
+ ///
+ protected override void ProcessRecord()
+ {
+
+ try
+ {
+ // 1. Validating the input
+ WriteDebug("Validating");
+
+ var logicalIdsVersionsCollection = new NameValueCollection();
+ WriteDebug("Removing");
+
+ IshFields requiredCurrentMetadata = new IshFields(RequiredCurrentMetadata);
+
+ if (IshObject != null)
+ {
+ long lngRef = Convert.ToInt64(IshObject.ObjectRef[Enumerations.ReferenceType.Lng]);
+ WriteDebug($"Removing lngCardId[{lngRef}]");
+ if (ShouldProcess(Convert.ToString(lngRef)))
+ {
+ var response = IshSession.DocumentObj25.DeleteByIshLngRef(new DeleteByIshLngRefRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ plLngRef = lngRef,
+ psXMLRequiredCurrentMetadata = requiredCurrentMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ }
+ logicalIdsVersionsCollection.Add(IshObject.IshRef, IshObject.IshFields.GetFieldValue("VERSION", Enumerations.Level.Version, Enumerations.ValueType.Value));
+ }
+ else
+ {
+ string resolution = Resolution ?? "";
+ string lng = Lng ?? "";
+ if (lng.Length > 0)
+ {
+ // only delete when you have a lanuage, lower the version delete (so empty lng) is handled
+ WriteDebug($"Removing LogicalId[{LogicalId}] Version[{Version}] Lng[{lng}] Resolution[{resolution}]");
+ if (ShouldProcess(LogicalId + "=" + Version + "=" + lng + "=" + resolution))
+ {
+ var response = IshSession.DocumentObj25.Delete(new DeleteRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psLogicalId = LogicalId,
+ psVersion = Version,
+ psLanguage = lng,
+ psResolution = resolution,
+ psXMLRequiredCurrentMetadata = requiredCurrentMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ }
+ }
+ logicalIdsVersionsCollection.Add(LogicalId, Version);
+ }
+
+ if (Force.IsPresent && logicalIdsVersionsCollection.Count > 0)
+ {
+ var response = IshSession.DocumentObj25.RetrieveMetadata(new RetrieveMetadataRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ pasLogicalIds = logicalIdsVersionsCollection.AllKeys.ToArray(),
+ peStatusFilter = eISHStatusgroup.ISHNoStatusFilter,
+ psXMLMetadataFilter = "",
+ psXMLRequestedMetadata = ""
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ string xmlIshObjects = response.psOutXMLObjList;
+ List retrievedObjects = new List();
+ retrievedObjects.AddRange(new IshObjects(xmlIshObjects).Objects);
+
+ // Delete versions which do not have any language card anymore
+ foreach (string logicalId in logicalIdsVersionsCollection.AllKeys)
+ {
+ var versions = logicalIdsVersionsCollection.GetValues(logicalId).Distinct();
+ foreach (var version in versions)
+ {
+ bool versionWithLanguagesFound = false;
+ foreach (var retrievedObject in retrievedObjects)
+ {
+ if (retrievedObject.IshRef == logicalId && retrievedObject.IshFields.GetFieldValue("VERSION", Enumerations.Level.Version, Enumerations.ValueType.Value) == version)
+ {
+ versionWithLanguagesFound = true;
+ }
+ }
+ if (!versionWithLanguagesFound)
+ {
+ if (ShouldProcess(LogicalId + "=" + version + "=" + "="))
+ {
+ var responseDelete = IshSession.DocumentObj25.Delete(new DeleteRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psLogicalId = logicalId,
+ psVersion = version,
+ psLanguage = "",
+ psResolution = "",
+ psXMLRequiredCurrentMetadata = ""
+ });
+ IshSession.AuthenticationContext = responseDelete.psAuthContext;
+ }
+ }
+ }
+ }
+
+ // Delete logical cards which do not have any languages anymore
+ foreach (string logicalId in logicalIdsVersionsCollection.AllKeys)
+ {
+ bool logicalIdFound = false;
+ foreach (var retrievedObject in retrievedObjects)
+ {
+ if (retrievedObject.IshRef == logicalId)
+ {
+ logicalIdFound = true;
+ }
+ }
+ if (!logicalIdFound)
+ {
+ if (ShouldProcess(LogicalId + "=" + "=" + "="))
+ {
+ var responseDelete = IshSession.DocumentObj25.Delete(new DeleteRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psLogicalId = logicalId,
+ psVersion = "",
+ psLanguage = "",
+ psResolution = "",
+ psXMLRequiredCurrentMetadata = ""
+ });
+ IshSession.AuthenticationContext = responseDelete.psAuthContext;
+ }
+ }
+ }
+ }
+ WriteVerbose("returned object count[0]");
+ }
+ catch (TrisoftAutomationException trisoftAutomationException)
+ {
+ ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
+ }
+ catch (Exception exception)
+ {
+ ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
+ }
+ }
+ }
+}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/SetIshDocumentObj.Tests.ps1 b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/SetIshDocumentObj.Tests.ps1
new file mode 100644
index 00000000..b098e202
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/SetIshDocumentObj.Tests.ps1
@@ -0,0 +1,802 @@
+BeforeAll {
+ $cmdletName = "Set-IshDocumentObj"
+ Write-Host ("`r`nLoading ISHRemote.PesterSetup.ps1 over BeforeAll-block for MyCommand[" + $cmdletName + "]...")
+ . (Join-Path (Split-Path -Parent $PSCommandPath) "\..\..\ISHRemote.PesterSetup.ps1")
+
+ Write-Host ("Running "+$cmdletName+" Test Data and Variables initialization")
+ $tempFolder = [System.IO.Path]::GetTempPath()
+ #
+ # Script-file scope auxiliary function
+ #
+ function script:CreateSquareImageBySideSize([int]$size)
+ {
+ Add-Type -AssemblyName "System.Drawing"
+ $bmp = New-Object -TypeName System.Drawing.Bitmap($size, $size)
+ for ($i = 0; $i -lt $size; $i++)
+ {
+ for ($j = 0; $j -lt $size; $j++)
+ {
+ $bmp.SetPixel($i, $j, 'Red')
+ }
+ }
+
+ return $bmp
+ }
+}
+
+Describe "Set-IshDocumentObj" -Tags "Create" {
+ BeforeAll {
+ $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Name "FNAME" |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Name "FDOCUMENTTYPE" |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Name "READ-ACCESS" -ValueType Element |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Name "FUSERGROUP" -ValueType Element
+ $ishFolderTestRootOriginal = Get-IshFolder -IShSession $ishSession -FolderPath $folderTestRootPath -RequestedMetadata $requestedMetadata
+ $folderIdTestRootOriginal = $ishFolderTestRootOriginal.IshFolderRef
+ $folderTypeTestRootOriginal = $ishFolderTestRootOriginal.IshFolderType
+ Write-Debug ("folderIdTestRootOriginal[" + $folderIdTestRootOriginal + "] folderTypeTestRootOriginal[" + $folderTypeTestRootOriginal + "]")
+ $ownedByTestRootOriginal = Get-IshMetadataField -IshSession $ishSession -Name "FUSERGROUP" -ValueType Element -IshField $ishFolderTestRootOriginal.IshField
+ $readAccessTestRootOriginal = (Get-IshMetadataField -IshSession $ishSession -Name "READ-ACCESS" -ValueType Element -IshField $ishFolderTestRootOriginal.IshField).Split($ishSession.Separator)
+
+ $global:ishFolderCmdlet = Add-IshFolder -IShSession $ishSession -ParentFolderId $folderIdTestRootOriginal -FolderType ISHNone -FolderName $cmdletName -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+ $ishFolderTopic = Add-IshFolder -IshSession $ishSession -ParentFolderId ($global:ishFolderCmdlet.IshFolderRef) -FolderType ISHModule -FolderName "Topic" -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+ $ishFolderMap = Add-IshFolder -IshSession $ishSession -ParentFolderId ($global:ishFolderCmdlet.IshFolderRef) -FolderType ISHMasterDoc -FolderName "Map" -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+ $ishFolderLib = Add-IshFolder -IshSession $ishSession -ParentFolderId ($global:ishFolderCmdlet.IshFolderRef) -FolderType ISHLibrary -FolderName "Library" -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+ $ishFolderImage = Add-IshFolder -IshSession $ishSession -ParentFolderId ($global:ishFolderCmdlet.IshFolderRef) -FolderType ISHIllustration -FolderName "Image" -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+ $ishFolderOther = Add-IshFolder -IshSession $ishSession -ParentFolderId ($global:ishFolderCmdlet.IshFolderRef) -FolderType ISHTemplate -FolderName "Other" -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+
+ # Create files with two images: 100*100 and 200*200
+ $tempFilePathImage100x100 = (New-TemporaryFile).FullName
+ $bmp = CreateSquareImageBySideSize -size 100
+ $bmp.Save($tempFilePathImage100x100, [System.Drawing.Imaging.ImageFormat]::Jpeg)
+ $tempFilePathImage200x200 = (New-TemporaryFile).FullName
+ $bmp = CreateSquareImageBySideSize -size 200
+ $bmp.Save($tempFilePathImage200x200, [System.Drawing.Imaging.ImageFormat]::Jpeg)
+ }
+ Context "Set-IshDocumentObj returns IshObject object (Topic)" {
+ BeforeAll {
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Topic $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession `
+ -FolderId $ishFolderTopic.IshFolderRef `
+ -IshType ISHModule `
+ -Lng $ishLng `
+ -Metadata $ishTopicMetadata `
+ -FileContent $ditaTopicFileContent
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value "Updated topic title $timestamp"
+ $ishObject = Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -Metadata $ishMetadataFieldsSet
+ }
+ It "GetType().Name" {
+ $ishObject.GetType().Name | Should -BeExactly "IshDocumentObj"
+ }
+ It "ishObject.IshData" {
+ { $ishObject.IshData } | Should -Not -Throw
+ }
+ It "ishObject.IshField" {
+ $ishObject.IshField | Should -Not -BeNullOrEmpty
+ }
+ It "ishObject.IshRef" {
+ $ishObject.IshRef | Should -Not -BeNullOrEmpty
+ }
+ It "ishObject.IshType" {
+ $ishObject.IshType | Should -Not -BeNullOrEmpty
+ }
+ It "ishObject.ObjectRef" {
+ $ishObject.ObjectRef | Should -Not -BeNullOrEmpty
+ }
+ It "ishObject.VersionRef" {
+ $ishObject.VersionRef | Should -Not -BeNullOrEmpty
+ }
+ It "ishObject.LngRef" {
+ $ishObject.LngRef | Should -Not -BeNullOrEmpty
+ }
+ It "ishObject ConvertTo-Json" {
+ (ConvertTo-Json $ishObject).Length -gt 2 | Should -Be $true
+ }
+ It "Option IshSession.DefaultRequestedMetadata" {
+ $ishSession.DefaultRequestedMetadata | Should -Be "Basic"
+ #logical
+ $ishObject.ftitle_logical_value.Length -ge 1 | Should -Be $true
+ #version
+ $ishObject.version_version_value.Length -ge 1 | Should -Be $true
+ #language
+ $ishObject.fstatus.Length -ge 1 | Should -Be $true
+ $ishObject.fstatus_lng_element.StartsWith('VSTATUS') | Should -Be $true
+ $ishObject.doclanguage.Length -ge 1 | Should -Be $true # Field names like DOC-LANGUAGE get stripped of the hyphen, otherwise you get $ishObject.'doc-language' and now you get the more readable $ishObject.doclanguage
+ $ishObject.doclanguage_lng_element.StartsWith('VLANGUAGE') | Should -Be $true
+ }
+ }
+ Context "Set-IshDocumentObj ParameterGroupMetadata" {
+ It "Mandatory parameter: LogicalId" {
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value "updated title"
+ {Set-IshDocumentObj -IshSession $ishSession `
+ -Version "1" `
+ -Lng "en" `
+ -Metadata $ishMetadataFieldsSet} | Should -Throw
+ }
+ It "Mandatory parameter: Version" {
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Topic $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession -FolderId $ishFolderTopic.IshFolderRef -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent
+
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value "updated title"
+ {Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Lng "en" `
+ -Metadata $ishMetadataFieldsSet} | Should -Throw
+ }
+ It "Mandatory parameter: Lng" {
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Topic $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession -FolderId $ishFolderTopic.IshFolderRef -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent
+
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value "updated title"
+ {Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Metadata $ishMetadataFieldsSet} | Should -Throw
+ }
+ It "Topic - metadata update" {
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Topic $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession -FolderId $ishFolderTopic.IshFolderRef -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent
+
+ $updatedTitle = $ishObjectToUpdate.ftitle_logical_value + "...updated"
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+ $ishObject = Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -Metadata $ishMetadataFieldsSet
+ $ishObject.ftitle_logical_value | Should -Be $updatedTitle
+ }
+ It "Topic - metadata update with RequiredCurrentMetadata accepted" {
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Topic $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession -FolderId $ishFolderTopic.IshFolderRef -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent
+
+ $updatedTitle = $ishObjectToUpdate.ftitle_logical_value + "...updated"
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+ $ishRequiredCurrentMetadata = Set-IshRequiredCurrentMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObject = Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -Metadata $ishMetadataFieldsSet `
+ -RequiredCurrentMetadata $ishRequiredCurrentMetadata
+ $ishObject.ftitle_logical_value | Should -Be $updatedTitle
+ }
+ It "Topic - metadata update with RequiredCurrentMetadata rejected" {
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Topic $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession -FolderId $ishFolderTopic.IshFolderRef -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent
+
+ $updatedTitle = $ishObjectToUpdate.ftitle_logical_value + "...updated"
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+ $ishRequiredCurrentMetadata = Set-IshRequiredCurrentMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusReleased
+ $exception = { Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -Metadata $ishMetadataFieldsSet `
+ -RequiredCurrentMetadata $ishRequiredCurrentMetadata } | Should -Throw -PassThru
+ "The supplied expected metadata"
+ # 14.0.4 message is: [-106011] The supplied expected metadata value "Released" does not match the current database value "In progress" so we rolled back your operation. To make the operation work you should make sure your value matches the latest database value. [f:158 fe:FSTATUS ft:LOV] [106011;InvalidCurrentMetadata]
+ $exception -like "*106011*" | Should -Be $true
+ $exception -like "*InvalidCurrentMetadata*" | Should -Be $true
+ }
+ It "Image - metadata update without Resolution" {
+ $ishImageMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Image $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession `
+ -IshFolder $ishFolderImage `
+ -IshType ISHIllustration `
+ -Version '3' `
+ -Lng $ishLng `
+ -Resolution $ishResolution `
+ -Metadata $ishImageMetadata `
+ -Edt "EDTJPEG" `
+ -FilePath $tempFilePathImage100x100
+
+ $updatedTitle = $ishObjectToUpdate.ftitle_logical_value + "...updated"
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+ $ishObject = Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -Metadata $ishMetadataFieldsSet
+ $ishObject.ftitle_logical_value | Should -Be $updatedTitle
+ }
+ It "Image - metadata update with Resolution" {
+ $ishImageMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Image $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession `
+ -IshFolder $ishFolderImage `
+ -IshType ISHIllustration `
+ -Version '3' `
+ -Lng $ishLng `
+ -Resolution $ishResolution `
+ -Metadata $ishImageMetadata `
+ -Edt "EDTJPEG" `
+ -FilePath $tempFilePathImage100x100
+
+ $updatedTitle = $ishObjectToUpdate.ftitle_logical_value + "...updated"
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+ $ishObject = Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -Resolution $ishResolution `
+ -Metadata $ishMetadataFieldsSet
+ $ishObject.ftitle_logical_value | Should -Be $updatedTitle
+ }
+ It "Image - metadata update with non-matching Resolution" {
+ $ishImageMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Image $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession `
+ -IshFolder $ishFolderImage `
+ -IshType ISHIllustration `
+ -Version '3' `
+ -Lng $ishLng `
+ -Resolution $ishResolution `
+ -Metadata $ishImageMetadata `
+ -Edt "EDTJPEG" `
+ -FilePath $tempFilePathImage100x100
+
+ $updatedTitle = $ishObjectToUpdate.ftitle_logical_value + "...updated"
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+ $exception = { Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -Resolution "VRESHIGH" `
+ -Metadata $ishMetadataFieldsSet } | Should -Throw -PassThru
+ # 14.0.4 message is: [-102] The object GUID-862BD02A-422D-4E42-8626-725A12CF6D3A=3=en=High does not exist. [co:"GUID-862BD02A-422D-4E42-8626-725A12CF6D3A=3=en=High"] [102;ObjectNotFound]
+ $exception -like "*102*" | Should -Be $true
+ $exception -like "*ObjectNotFound*" | Should -Be $true
+ }
+ }
+ Context "Set-IshDocumentObj ParameterGroupFileContent" {
+ BeforeAll {
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Set All Parameters Topic $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -Version '1' -Lng $ishLng -Metadata $ishTopicMetadata -Edt "EDTXML" -FileContent $ditaTopicFileContent
+ }
+ It "Parameter EDT explicitly EDTJPEG" {
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value "Updated title"
+ $exception = { Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -Metadata $ishMetadataFieldsSet `
+ -Edt "EDTJPEG" `
+ -FileContent "INVALIDFILECONTENT" } | Should -Throw -PassThru
+ # ISHRemote message is: FileContent parameter is only supported with EDT[EDTXML], not EDT[EDTJPEG].
+ $exception -like "*FileContent*" | Should -Be $true
+ $exception -like "*EDTXML*" | Should -Be $true
+ }
+ It "Parameter FileContent has invalid xml content" {
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value "Updated title"
+ {Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -Metadata $ishMetadataFieldsSet `
+ -FileContent "INVALIDFILECONTENT"} |
+ Should -Throw "Data at the root level is invalid. Line 1, position 1."
+ }
+ It "Provide both FileContent and FilePath" {
+ $tempFilePath = (New-TemporaryFile).FullName
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value "Updated title"
+ $exception = { Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -Metadata $ishMetadataFieldsSet `
+ -FileContent $ditaTopicFileContent `
+ -FilePath $tempFilePath } | Should -Throw -PassThru
+ $exception -like "*Parameter set cannot be resolved using the specified named parameters.*" | Should -Be $true
+ }
+ It "Topic - update blob only" {
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Set All Parameters Topic $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession `
+ -IshFolder $ishFolderTopic `
+ -IshType ISHModule `
+ -Version '1' `
+ -Lng $ishLng `
+ -Metadata $ishTopicMetadata `
+ -Edt "EDTXML" `
+ -FileContent $ditaTopicFileContent
+ $fileInfo = $ishObjectToUpdate | Get-IshDocumentObjData -IshSession $ishSession -FolderPath (Join-Path $tempFolder $cmdletName)
+ [string]$ishObjectToUpdateContent = Get-Content -Path $fileInfo
+
+ $updatedTitle = $ishObjectToUpdate.ftitle_logical_value + "...updated"
+ $updatedContent = $ishObjectToUpdateContent.Replace("(optional)", "(optional-updated)")
+ $ishObject = Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -FileContent $updatedContent
+ $fileInfo = $ishObject | Get-IshDocumentObjData -IshSession $ishSession -FolderPath (Join-Path $tempFolder $cmdletName)
+ [string]$ishObjectContent = Get-Content -Path $fileInfo
+ $ishObjectContent -eq $updatedContent | Should -Be $true
+ }
+ It "Topic - update blob and metadata" {
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Set All Parameters Topic $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession `
+ -IshFolder $ishFolderTopic `
+ -IshType ISHModule `
+ -Version '1' `
+ -Lng $ishLng `
+ -Metadata $ishTopicMetadata `
+ -Edt "EDTXML" `
+ -FileContent $ditaTopicFileContent
+ $fileInfo = $ishObjectToUpdate | Get-IshDocumentObjData -IshSession $ishSession -FolderPath (Join-Path $tempFolder $cmdletName)
+ [string]$ishObjectToUpdateContent = Get-Content -Path $fileInfo
+
+ $updatedTitle = $ishObjectToUpdate.ftitle_logical_value + "...updated"
+ $updatedContent = $ishObjectToUpdateContent.Replace("(optional)", "(optional-updated)")
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+ $ishObject = Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Metadata $ishMetadataFieldsSet `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -FileContent $updatedContent
+ $fileInfo = $ishObject | Get-IshDocumentObjData -IshSession $ishSession -FolderPath (Join-Path $tempFolder $cmdletName)
+ [string]$ishObjectContent = Get-Content -Path $fileInfo
+
+ $ishObject.ftitle_logical_value | Should -Be $updatedTitle
+ $ishObjectContent -eq $updatedContent | Should -Be $true
+ }
+ It "Topic - update (RequiredCurrentMetadata accepted)" {
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Topic update with RequiredCurrentMetadata accepted $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession `
+ -IshFolder $ishFolderTopic `
+ -IshType ISHModule `
+ -Version '1' `
+ -Lng $ishLng `
+ -Metadata $ishTopicMetadata `
+ -Edt "EDTXML" `
+ -FileContent $ditaTopicFileContent
+ $fileInfo = $ishObjectToUpdate | Get-IshDocumentObjData -IshSession $ishSession -FolderPath (Join-Path $tempFolder $cmdletName)
+ [string]$ishObjectToUpdateContent = Get-Content -Path $fileInfo
+
+ $updatedTitle = $ishObjectToUpdate.ftitle_logical_value + "...updated"
+ $updatedContent = $ishObjectToUpdateContent.Replace("(optional)", "(optional-updated)")
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+ $ishRequiredCurrentMetadata = Set-IshRequiredCurrentMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObject = Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -Metadata $ishMetadataFieldsSet `
+ -RequiredCurrentMetadata $ishRequiredCurrentMetadata `
+ -FileContent $updatedContent
+ $fileInfo = $ishObject | Get-IshDocumentObjData -IshSession $ishSession -FolderPath (Join-Path $tempFolder $cmdletName)
+ [string]$ishObjectContent = Get-Content -Path $fileInfo
+
+ $ishObject.ftitle_logical_value | Should -Be $updatedTitle
+ $ishObjectContent -eq $updatedContent | Should -Be $true
+ }
+ It "Topic - update (RequiredCurrentMetadata rejected)" {
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Topic update with RequiredCurrentMetadata rejected $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession `
+ -IshFolder $ishFolderTopic `
+ -IshType ISHModule `
+ -Version '1' `
+ -Lng $ishLng `
+ -Metadata $ishTopicMetadata `
+ -Edt "EDTXML" `
+ -FileContent $ditaTopicFileContent
+ $fileInfo = $ishObjectToUpdate | Get-IshDocumentObjData -IshSession $ishSession -FolderPath (Join-Path $tempFolder $cmdletName)
+ [string]$ishObjectToUpdateContent = Get-Content -Path $fileInfo
+
+ $updatedTitle = $ishObjectToUpdate.ftitle_logical_value + "...updated"
+ $updatedContent = $ishObjectToUpdateContent.Replace("(optional)", "(optional-updated)")
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+ $ishRequiredCurrentMetadata = Set-IshRequiredCurrentMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusReleased
+ $exception = { Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -Metadata $ishMetadataFieldsSet `
+ -RequiredCurrentMetadata $ishRequiredCurrentMetadata `
+ -FileContent $updatedContent } | Should -Throw -PassThru
+ # 14.0.4 message is: [-106011] The supplied expected metadata value "Released" does not match the current database value "In progress" so we rolled back your operation. To make the operation work you should make sure your value matches the latest database value. [f:158 fe:FSTATUS ft:LOV] [106011;InvalidCurrentMetadata]
+ $exception -like "*106011*" | Should -Be $true
+ $exception -like "*InvalidCurrentMetadata*" | Should -Be $true
+ }
+ It "Map - update blob and metadata" {
+ $ishMapMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Map update $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession `
+ -IshFolder $ishFolderMap `
+ -IshType ISHMasterDoc `
+ -Version '3' `
+ -Lng $ishLng `
+ -Metadata $ishMapMetadata `
+ -Edt "EDTXML" `
+ -FileContent $ditaMapFileContent
+ $fileInfo = $ishObjectToUpdate | Get-IshDocumentObjData -IshSession $ishSession -FolderPath (Join-Path $tempFolder $cmdletName)
+ [string]$ishObjectToUpdateContent = Get-Content -Path $fileInfo
+
+ $updatedTitle = $ishObjectToUpdate.ftitle_logical_value + "...updated"
+ $updatedContent = $ishObjectToUpdateContent.Replace("your map", "my map")
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+ $ishObject = Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Metadata $ishMetadataFieldsSet `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -FileContent $updatedContent
+ $fileInfo = $ishObject | Get-IshDocumentObjData -IshSession $ishSession -FolderPath (Join-Path $tempFolder $cmdletName)
+ [string]$ishObjectContent = Get-Content -Path $fileInfo
+
+ $ishObject.ftitle_logical_value | Should -Be $updatedTitle
+ $ishObjectContent -eq $updatedContent | Should -Be $true
+
+ }
+ It "Lib - update blob and metadata" {
+ $ishLibMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Lib update $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession `
+ -IshFolder $ishFolderLib `
+ -IshType ISHLibrary `
+ -Version '4' `
+ -Lng $ishLng `
+ -Metadata $ishLibMetadata `
+ -Edt "EDTXML" `
+ -FileContent $ditaTopicFileContent
+ $fileInfo = $ishObjectToUpdate | Get-IshDocumentObjData -IshSession $ishSession -FolderPath (Join-Path $tempFolder $cmdletName)
+ [string]$ishObjectToUpdateContent = Get-Content -Path $fileInfo
+
+ $updatedTitle = $ishObjectToUpdate.ftitle_logical_value + "...updated"
+ $updatedContent = $ishObjectToUpdateContent.Replace("(optional)", "(optional-updated)")
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+ $ishObject = Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Metadata $ishMetadataFieldsSet `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -FileContent $updatedContent
+ $fileInfo = $ishObject | Get-IshDocumentObjData -IshSession $ishSession -FolderPath (Join-Path $tempFolder $cmdletName)
+ [string]$ishObjectContent = Get-Content -Path $fileInfo
+
+ $ishObject.ftitle_logical_value | Should -Be $updatedTitle
+ $ishObjectContent -eq $updatedContent | Should -Be $true
+ }
+ }
+ Context "Set-IshDocumentObj ParameterGroupFilePath" {
+ It "Image - update blob only (providing EDT)" {
+ $ishImageMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Mandatory parameters Image $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession `
+ -IshFolder $ishFolderImage `
+ -IshType ISHIllustration `
+ -Version '3' `
+ -Lng $ishLng `
+ -Resolution $ishResolution `
+ -Metadata $ishImageMetadata `
+ -Edt "EDTJPEG" `
+ -FilePath $tempFilePathImage100x100
+
+ $fileInfoToUpdate = Get-Item -Path $tempFilePathImage100x100
+ $ishObject = Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -Edt "EDTJPEG" `
+ -FilePath $tempFilePathImage200x200
+
+ $fileInfo = $ishObject | Get-IshDocumentObjData -IshSession $ishSession -FolderPath (Join-Path $tempFolder $cmdletName)
+ $fileInfoToUpdate.Length -lt $fileInfo.Length | Should -Be $true
+ }
+ It "Image - update metadata and blob (providing EDT)" {
+ $ishImageMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Mandatory parameters Image $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession `
+ -IshFolder $ishFolderImage `
+ -IshType ISHIllustration `
+ -Version '3' `
+ -Lng $ishLng `
+ -Resolution $ishResolution `
+ -Metadata $ishImageMetadata `
+ -Edt "EDTJPEG" `
+ -FilePath $tempFilePathImage100x100
+
+ $fileInfoToUpdate = Get-Item -Path $tempFilePathImage100x100
+ $updatedTitle = $ishObjectToUpdate.ftitle_logical_value + "...updated"
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+
+ $ishObject = Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -Metadata $ishMetadataFieldsSet `
+ -Edt "EDTJPEG" `
+ -FilePath $tempFilePathImage200x200
+
+ $fileInfo = $ishObject | Get-IshDocumentObjData -IshSession $ishSession -FolderPath (Join-Path $tempFolder $cmdletName)
+
+ $ishObject.ftitle_logical_value | Should -Be $updatedTitle
+ $fileInfoToUpdate.Length -lt $fileInfo.Length | Should -Be $true
+ }
+ It "Image - update metadata and blob providing EDT, RequiredCurrentMetadata accepted" {
+ $ishImageMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Mandatory parameters Image with RequiredCurrentMetadata $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession `
+ -IshFolder $ishFolderImage `
+ -IshType ISHIllustration `
+ -Version '3' `
+ -Lng $ishLng `
+ -Resolution $ishResolution `
+ -Metadata $ishImageMetadata `
+ -Edt "EDTJPEG" `
+ -FilePath $tempFilePathImage100x100
+
+ $fileInfoToUpdate = Get-Item -Path $tempFilePathImage100x100
+ $updatedTitle = $ishObjectToUpdate.ftitle_logical_value + "...updated"
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+
+ $ishRequiredCurrentMetadata = Set-IshRequiredCurrentMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObject = Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -Metadata $ishMetadataFieldsSet `
+ -Edt "EDTJPEG" `
+ -RequiredCurrentMetadata $ishRequiredCurrentMetadata `
+ -FilePath $tempFilePathImage200x200
+
+ $fileInfo = $ishObject | Get-IshDocumentObjData -IshSession $ishSession -FolderPath (Join-Path $tempFolder $cmdletName)
+
+ $ishObject.ftitle_logical_value | Should -Be $updatedTitle
+ $fileInfoToUpdate.Length -lt $fileInfo.Length | Should -Be $true
+ }
+ It "Topic - update metadata and blob, RequiredCurrentMetadata rejected" {
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Topic update with RequiredCurrentMetadata rejected $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession `
+ -IshFolder $ishFolderTopic `
+ -IshType ISHModule `
+ -Version '1' `
+ -Lng $ishLng `
+ -Metadata $ishTopicMetadata `
+ -Edt "EDTXML" `
+ -FileContent $ditaTopicFileContent
+ $fileInfo = $ishObjectToUpdate | Get-IshDocumentObjData -IshSession $ishSession -FolderPath (Join-Path $tempFolder $cmdletName)
+ [string]$ishObjectToUpdateContent = Get-Content -Path $fileInfo
+
+ $updatedTitle = $ishObjectToUpdate.ftitle_logical_value + "...updated"
+ $updatedContent = $ishObjectToUpdateContent.Replace("(optional)", "(optional-updated)")
+ $tempFilePathUpdated = (New-TemporaryFile).FullName
+ $updatedContent | Out-File -Encoding Unicode -FilePath $tempFilePathUpdated -Force
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+ $ishRequiredCurrentMetadata = Set-IshRequiredCurrentMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusReleased
+ $exception = { Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -Metadata $ishMetadataFieldsSet `
+ -RequiredCurrentMetadata $ishRequiredCurrentMetadata `
+ -FilePath $tempFilePathUpdated } | Should -Throw -PassThru
+ # 14.0.4 message is: [-106011] The supplied expected metadata value "Released" does not match the current database value "In progress" so we rolled back your operation. To make the operation work you should make sure your value matches the latest database value. [f:158 fe:FSTATUS ft:LOV] [106011;InvalidCurrentMetadata]
+ # 14.0.4 message with pretranslation enabled is: [-106021] The target xml file handler "PreTranslation" returned the following error: "There is no Unicode byte order mark. Cannot switch to Unicode." [106021;TargetXmlFileHandlerExecutionFailure]
+ # 14.0.4 message is: There is no Unicode byte order mark. Cannot switch to Unicode.
+ $exception -like "*106011*" | Should -Be $true
+ $exception -like "*InvalidCurrentMetadata*" | Should -Be $true
+ }
+ It "Update Other like EDT-TEXT" {
+ $ishOtherMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Update Other like EDT-TEXT $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $tempFilePath = (New-TemporaryFile).FullName
+ ("Update other " * 100) | Out-File $tempFilePath
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderOther -IshType ISHTemplate -Version '6' -Lng $ishLng -Metadata $ishOtherMetadata -Edt "EDT-TEXT" -FilePath $tempFilePath
+ $fileInfoToUpdate = $ishObjectToUpdate | Get-IshDocumentObjData -IshSession $ishSession -FolderPath (Join-Path $tempFolder $cmdletName)
+
+ $updatedTitle = $ishObjectToUpdate.ftitle_logical_value + "...updated"
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+ ("Update other " * 200) | Out-File $tempFilePath -Force
+ $ishObject = Set-IshDocumentObj -IshSession $ishSession `
+ -LogicalId $ishObjectToUpdate.IshRef `
+ -Version $ishObjectToUpdate.version_version_value `
+ -Lng $ishObjectToUpdate.doclanguage `
+ -Metadata $ishMetadataFieldsSet `
+ -Edt "EDT-TEXT" `
+ -FilePath $tempFilePath
+ $fileInfo = $ishObject | Get-IshDocumentObjData -IshSession $ishSession -FolderPath (Join-Path $tempFolder $cmdletName)
+
+ $ishObject.ftitle_logical_value | Should -Be $updatedTitle
+ $fileInfoToUpdate.Length -lt $fileInfo.Length | Should -Be $true
+ }
+ }
+ Context "Set-IshDocumentObj IshObjectsGroup" {
+ BeforeAll {
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Topic $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ }
+ It "Parameter/pipe IshObject is empty" {
+ {Set-IshDocumentObj -IshSession $ishSession -IshObject @()} | Should -Not -Throw
+ {@() | Set-IshDocumentObj -IshSession $ishSession} | Should -Not -Throw
+ }
+ It "Parameter IshObject invalid" {
+ { Set-IshDocumentObj -IshSession $ishSession -IshObject "INVALIDISHOBJECT" } |
+ Should -Throw "Cannot bind parameter 'IshObject'. Cannot convert the ""INVALIDISHOBJECT"" value of type ""System.String"" to type ""Trisoft.ISHRemote.Objects.Public.IshObject""."
+ }
+ It "Provide as parameter/pipe deleted object" {
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent
+ Remove-IshDocumentObj -IshSession $ishSession -IshObject $ishObjectToUpdate -Force
+ $exception = { $ishObjectSet = Set-IshDocumentObj -IshSession $ishSession -IshObject $ishObjectToUpdate } | Should -Throw -PassThru
+ # 14.0.4 message is: [-102] The object GUID-862BD02A-422D-4E42-8626-725A12CF6D3A=3=en=High does not exist. [co:"GUID-862BD02A-422D-4E42-8626-725A12CF6D3A=3=en=High"] [102;ObjectNotFound]
+ $exception -like "*102*" | Should -Be $true
+ $exception -like "*ObjectNotFound*" | Should -Be $true
+ $exception = { $ishObjectSet = $ishObjectToUpdate | Set-IshDocumentObj -IshSession $ishSession } | Should -Throw -PassThru
+ # 14.0.4 message is: [-102] The object GUID-862BD02A-422D-4E42-8626-725A12CF6D3A=3=en=High does not exist. [co:"GUID-862BD02A-422D-4E42-8626-725A12CF6D3A=3=en=High"] [102;ObjectNotFound]
+ $exception -like "*102*" | Should -Be $true
+ $exception -like "*ObjectNotFound*" | Should -Be $true
+ }
+ It "Set metadata, provide multiple objects to IshObject" {
+ $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Name "ED" -Level Lng
+ $ishObjectA = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+ $ishObjectB = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+
+ $updatedTitle = $ishObjectA.ftitle_logical_value + "...updated"
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+ $ishObjectArray = Set-IshDocumentObj -IshSession $ishSession -IshObject @($ishObjectA, $ishObjectB) -Metadata $ishMetadataFieldsSet
+ $ishObjectAUpdated = $ishObjectA | Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+ $ishObjectBUpdated = $ishObjectB | Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+
+ $ishObjectArray.Count | Should -Be 2
+ $ishObjectA.ed -eq $ishObjectAUpdated.ed | Should -Be $true
+ $ishObjectB.ed -eq $ishObjectBUpdated.ed | Should -Be $true
+ $ishObjectArray[0].ftitle_logical_value | Should -Be $updatedTitle
+ $ishObjectArray[1].ftitle_logical_value | Should -Be $updatedTitle
+ }
+ It "Resubmit blob, provide multiple objects to IshObject" {
+ $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Name "ED" -Level Lng
+ $ishObjectA = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata -IncludeData
+ $ishObjectB = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata -IncludeData
+
+ $ishObjectArray = Set-IshDocumentObj -IshSession $ishSession -IshObject @($ishObjectA, $ishObjectB)
+ $ishObjectAUpdated = $ishObjectA | Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+ $ishObjectBUpdated = $ishObjectB | Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+
+ $ishObjectArray.Count | Should -Be 2
+ $ishObjectA.ed -ne $ishObjectAUpdated.ed | Should -Be $true
+ $ishObjectB.ed -ne $ishObjectBUpdated.ed | Should -Be $true
+ }
+ It "Resubmit blob, provide multiple objects via pipeline" {
+ $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Name "ED" -Level Lng
+ $ishObjectA = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+ $ishObjectB = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+ $ishObjectAB = @($ishObjectA, $ishObjectB) | Get-IshDocumentObj -IshSession $ishSession -IncludeData
+
+ $ishObjectArray = $ishObjectAB | Set-IshDocumentObj -IshSession $ishSession
+ $ishObjectAUpdated = $ishObjectA | Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+ $ishObjectBUpdated = $ishObjectB | Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+
+ $ishObjectArray.Count | Should -Be 2
+ $ishObjectA.ed -ne $ishObjectAUpdated.ed | Should -Be $true
+ $ishObjectB.ed -ne $ishObjectBUpdated.ed | Should -Be $true
+ }
+ It "Resubmit blob, provide multiple objects via pipeline with RequiredCurrentMetadata accepted" {
+ $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Name "ED" -Level Lng
+ $ishObjectA = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+ $ishObjectB = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+ $ishObjectAB = @($ishObjectA, $ishObjectB) | Get-IshDocumentObj -IshSession $ishSession -IncludeData
+
+ $ishRequiredCurrentMetadata = Set-IshRequiredCurrentMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ $ishObjectArray = $ishObjectAB | Set-IshDocumentObj -IshSession $ishSession -RequiredCurrentMetadata $ishRequiredCurrentMetadata
+ $ishObjectAUpdated = $ishObjectA | Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+ $ishObjectBUpdated = $ishObjectB | Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+
+ $ishObjectArray.Count | Should -Be 2
+ $ishObjectA.ed -ne $ishObjectAUpdated.ed | Should -Be $true
+ $ishObjectB.ed -ne $ishObjectBUpdated.ed | Should -Be $true
+ }
+ It "Resubmit blob, provide multiple objects via pipeline with RequiredCurrentMetadata rejected" {
+ $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Name "ED" -Level Lng
+ $ishObjectA = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent
+ $ishObjectB = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent
+ $ishObjectAB = @($ishObjectA, $ishObjectB) | Get-IshDocumentObj -IshSession $ishSession -IncludeData
+
+ $ishRequiredCurrentMetadata = Set-IshRequiredCurrentMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusReleased
+ $exception = { $ishObjectAB | Set-IshDocumentObj -IshSession $ishSession -RequiredCurrentMetadata $ishRequiredCurrentMetadata } | Should -Throw -PassThru
+ # 14.0.4 message is: [-106011] The supplied expected metadata value "Released" does not match the current database value "In progress" so we rolled back your operation. To make the operation work you should make sure your value matches the latest database value. [f:158 fe:FSTATUS ft:LOV] [106011;InvalidCurrentMetadata]
+ $exception -like "*106011*" | Should -Be $true
+ $exception -like "*InvalidCurrentMetadata*" | Should -Be $true
+ }
+ It "Resubmit blob and set Metadata, provide multiple objects via pipeline" {
+ $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Name "ED" -Level Lng
+ $ishObjectA = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+ $ishObjectB = Add-IshDocumentObj -IshSession $ishSession -IshFolder $ishFolderTopic -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+ $ishObjectAB = @($ishObjectA, $ishObjectB) | Get-IshDocumentObj -IshSession $ishSession -IncludeData
+
+ $updatedTitle = $ishObjectA.ftitle_logical_value + "...updated"
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+ $ishObjectArray = $ishObjectAB | Set-IshDocumentObj -IshSession $ishSession -Metadata $ishMetadataFieldsSet
+ $ishObjectAUpdated = $ishObjectA | Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+ $ishObjectBUpdated = $ishObjectB | Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+
+ $ishObjectArray.Count | Should -Be 2
+ $ishObjectA.ed -ne $ishObjectAUpdated.ed | Should -Be $true
+ $ishObjectB.ed -ne $ishObjectBUpdated.ed | Should -Be $true
+ $ishObjectArray[0].ftitle_logical_value | Should -Be $updatedTitle
+ $ishObjectArray[1].ftitle_logical_value | Should -Be $updatedTitle
+ }
+ It "Resubmit blob and set Metadata, provide single object via pipeline" {
+ $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Name "ED" -Level Lng
+ $ishObjectToUpdate = Add-IshDocumentObj -IshSession $ishSession `
+ -IshFolder $ishFolderTopic `
+ -IshType ISHModule `
+ -Lng $ishLng `
+ -Metadata $ishTopicMetadata `
+ -FileContent $ditaTopicFileContent |
+ Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata -IncludeData
+
+ $updatedTitle = $ishObjectToUpdate.ftitle_logical_value + "...updated"
+ $ishMetadataFieldsSet = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level "Logical" -Value $updatedTitle
+ $ishObject = $ishObjectToUpdate |
+ Set-IshDocumentObj -IshSession $ishSession -Metadata $ishMetadataFieldsSet |
+ Get-IshDocumentObj -IshSession $ishSession -RequestedMetadata $requestedMetadata
+
+ $ishObjectToUpdate.ed -ne $ishObject.ed | Should -Be $true
+ $ishObject.ftitle_logical_value | Should -Be $updatedTitle
+ }
+ }
+}
+
+AfterAll {
+ Write-Host ("Running "+$cmdletName+" Test Data and Variables cleanup")
+ $folderCmdletRootPath = (Join-Path $folderTestRootPath $cmdletName)
+ try { Get-IshFolder -IshSession $ishSession -FolderPath $folderCmdletRootPath -Recurse | Get-IshFolderContent -IshSession $ishSession | Remove-IshDocumentObj -IshSession $ishSession -Force } catch { }
+ try { Remove-IshFolder -IshSession $ishSession -FolderPath $folderCmdletRootPath -Recurse } catch { }
+ try { Remove-Item $tempFilePath -Force } catch { }
+}
+
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/SetIshDocumentObj.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/SetIshDocumentObj.cs
new file mode 100644
index 00000000..b7a520dc
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/SetIshDocumentObj.cs
@@ -0,0 +1,414 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Management.Automation;
+using Trisoft.ISHRemote.DocumentObj25ServiceReference;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+using Trisoft.ISHRemote.Exceptions;
+using System.Xml.Linq;
+using System.IO;
+
+namespace Trisoft.ISHRemote.Cmdlets.DocumentObj
+{
+ ///
+ /// The Set-IshDocumentObj cmdlet updates the document objects that are passed through the pipeline or determined via provided parameters This commandlet allows to update all types of objects (Illustrations, Maps, etc. ), except for publication (outputs).
+ /// For publication (outputs) you need to use Set-IshPublicationOutput.
+ /// The Set-IshDocumentObj cmdlet updates the document objects that are passed through the pipeline or determined via provided parameters This commandlet allows to update all types of objects (Illustrations, Maps, etc. ), except for publication (outputs).
+ /// For publication (outputs) you need to use Set-IshPublicationOutput.
+ ///
+ ///
+ ///
+ ///$ishSession = New-IshSession -WsBaseUrl "https://example.com/ISHWS/" -PSCredential Admin
+ ///Get-IshDocumentObj -IshSession $ishSession -LogicalId ISHPUBLMODULECOMBINELANGUAGES |
+ ///Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level "Lng" -ValueType "Element" -Value "VSTATUSTOBEREVIEWED" |
+ ///Set-IshDocumentObj -IshSession $ishSession |
+ ///Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level "Lng" -ValueType "Element" -Value "VSTATUSRELEASED" |
+ ///Set-IshDocumentObj -IshSession $ishSession
+ ///
+ /// For all versions and languages retrieved, push them to status 'To Be Reviewed' and immediately to 'Release'. Note that also Find-IshDocumentObj or Get-IshFolderContent are ways to get to content objects.
+ ///
+ ///
+ ///
+ ///New-IshSession -WsBaseUrl "https://example.com/ISHWS/" -IshUserName "Username" -IshUserPassword "Password"
+ ///$ishFolderTopic = Add-IshFolder -ParentFolderId (Get-IshFolder -BaseFolder Data).IshFolderRef -FolderType ISHModule -FolderName "TopicFolder"
+ ///$ishTopicMetadata = Set-IshMetadataField -Name "FTITLE" -Level Logical -Value "My test Topic" |
+ /// Set-IshMetadataField -Name "FAUTHOR" -Level Lng -ValueType Value -Value "Username" |
+ /// Set-IshMetadataField -Name "FSTATUS" -Level Lng -ValueType Element -Value "VSTATUSDRAFT"
+ ///$ditaTopicFileContent = @"
+ ///<?xml version="1.0" ?>
+ ///<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
+ ///<topic><title>Enter the title of your topic here.</title><body><p>This is the start of your topic</p></body></topic>
+ ///"@
+ ///$ishObject = Add-IshDocumentObj -FolderId $ishFolderTopic.IshFolderRef -IshType ISHModule -Lng "en" -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent
+ ///$ishObject = $ishObject | Set-IshDocumentObj -Metadata(Set-IshMetadataField -Name "FTITLE" -Level Lng -Value "Updated topic title")
+ ///
+ /// Create a topic in a folder and then overwrite its metadata (FTITLE) using piped IshObject to the Set-IshDocumentObj cmdlet. New-IshSession will submit into SessionState, so it can be reused by all cmdlets.
+ ///
+ ///
+ ///
+ ///New-IshSession -WsBaseUrl "https://example.com/ISHWS/" -IshUserName "Username" -IshUserPassword "Password"
+ ///$ishFolderTopic = Add-IshFolder -ParentFolderId(Get-IshFolder -BaseFolder Data).IshFolderRef -FolderType ISHModule -FolderName "TopicFolder"
+ ///$ishTopicMetadata = Set-IshMetadataField -Name "FTITLE" -Level Logical -Value "My test Topic" |
+ /// Set-IshMetadataField -Name "FAUTHOR" -Level Lng -ValueType Value -Value "Username" |
+ /// Set-IshMetadataField -Name "FSTATUS" -Level Lng -ValueType Element -Value "VSTATUSDRAFT"
+ ///$ditaTopicFileContent = @"
+ ///<?xml version="1.0" ?>
+ ///<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
+ ///<topic><title>Enter the title of your topic here.</title><body><p>This is the start of your topic</p></body></topic>
+ ///"@
+ /// $ditaTopicFileContentUpdated = @"
+ ///<? xml version="1.0" ?>
+ ///<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
+ ///<topic><title>Enter the title of your topic here.</title><body><p>This is the start of your topic(updated)</p></body></topic>
+ ///"@
+ ///$ishObject = Add-IshDocumentObj -FolderId $ishFolderTopic.IshFolderRef -IshType ISHModule -Lng "en" -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent
+ ///$ishObject = Set-IshDocumentObj -LogicalId $ishObject.IshRef `
+ /// -Version $ishObject.version_version_value `
+ /// -Lng $ishObject.doclanguage `
+ /// -FileContent $ditaTopicFileContentUpdated `
+ /// -Metadata(Set-IshMetadataField -Name "FTITLE" -Level Logical -Value "Updated topic title and content")
+ ///
+ /// Create a topic in a folder and then overwrite its metadata (FTITLE) and blob by providing parameters and FileContent value to the Set-IshDocumentObj cmdlet. New-IshSession will submit into SessionState, so it can be reused by all cmdlets.
+ ///
+ ///
+ ///
+ ///New-IshSession -WsBaseUrl "https://example.com/ISHWS/" -IshUserName "Username" -IshUserPassword "Password"
+ ///$ishFolderTopic = Add-IshFolder -ParentFolderId(Get-IshFolder -BaseFolder Data).IshFolderRef -FolderType ISHModule -FolderName "TopicFolder"
+ ///$ishTopicMetadata = Set-IshMetadataField -Name "FTITLE" -Level Logical -Value "My test Topic" |
+ /// Set-IshMetadataField -Name "FAUTHOR" -Level Lng -ValueType Value -Value "Username" |
+ /// Set-IshMetadataField -Name "FSTATUS" -Level Lng -ValueType Element -Value "VSTATUSDRAFT"
+ ///$ditaTopicFileContent = @"
+ ///<?xml version="1.0" ?>
+ ///<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
+ ///<topic><title>Enter the title of your topic here.</title><body><p>This is the start of your topic</p></body></topic>
+ ///"@
+ ///$ishObject = Add-IshDocumentObj -FolderId $ishFolderTopic.IshFolderRef -IshType ISHModule -Lng "en" -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent
+ ///$tempFilePath = (New-TemporaryFile).FullName
+ ///$ditaTopicFileContent.Replace("your topic", "my topic") | Out-File -FilePath $tempFilePath
+ ///$ishObject = Set-IshDocumentObj -LogicalId $ishObject.IshRef `
+ /// -Version $ishObject.version_version_value `
+ /// -Lng $ishObject.doclanguage `
+ /// -FilePath $tempFilePath `
+ /// -Metadata(Set-IshMetadataField -Name "FTITLE" -Level Logical -Value "Updated topic title and content using file path")
+ ///
+ /// Create a topic in a folder and then overwrite its metadata (FTITLE) and blob by providing parameters and FilePath value to the Set-IshDocumentObj cmdlet. New-IshSession will submit into SessionState, so it can be reused by all cmdlets.
+ ///
+ [Cmdlet(VerbsCommon.Set, "IshDocumentObj", SupportsShouldProcess = true)]
+ [OutputType(typeof(IshDocumentObj))]
+ public sealed class SetIshDocumentObj : DocumentObjCmdlet
+ {
+ ///
+ /// The IshSession variable holds the authentication and contract information. This object can be initialized using the New-IshSession cmdlet.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupMetadata")]
+ [ValidateNotNullOrEmpty]
+ public IshSession IshSession { get; set; }
+
+ ///
+ /// The logical identifier of the object to update
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupMetadata")]
+ [ValidateNotNullOrEmpty]
+ public string LogicalId { get; set; }
+
+ ///
+ /// The version of the object to update
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupMetadata")]
+ [ValidateNotNullOrEmpty]
+ public string Version { get; set; }
+
+ ///
+ /// The language of the object to update
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupMetadata")]
+ [ValidateNotNullOrEmpty]
+ public string Lng { get; set; }
+
+ ///
+ /// The resolution of the object to update
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupMetadata")]
+ [ValidateNotNullOrEmpty]
+ public string Resolution { get; set; }
+
+ ///
+ /// The metadata to set for the document object
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupMetadata")]
+ [ValidateNotNull]
+ public IshField[] Metadata { get; set; }
+
+ ///
+ /// The required current metadata of the document object. This parameter can be used to avoid that users override changes done by other users. The cmdlet will check whether the fields provided in this parameter still have the same values in the repository:
+ /// If the metadata is still the same, the metadata will be set.
+ /// If the metadata is not the same anymore, an error is given and the metadata will not be set.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupMetadata")]
+ [ValidateNotNullOrEmpty]
+ public IshField[] RequiredCurrentMetadata { get; set; }
+
+ ///
+ /// The unique identifier of the Electronic Document Type of the output (e.g. EDTPDF, EDTXML, EDTHTML,...)
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent")]
+ [ValidateNotNullOrEmpty]
+ public string Edt
+ {
+ get { return _edt; }
+ set { _edt = value; }
+ }
+
+ ///
+ /// The location of the file on the filesystem containing new content (xml, jpg, etc.) for the object
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFilePath"), ValidateNotNullOrEmpty]
+ public string FilePath { get; set; }
+
+ ///
+ /// String with XML content of the DocumentObj
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroupFileContent"), ValidateNotNullOrEmpty]
+ public string FileContent { get; set; }
+
+ ///
+ /// Array with the objects for which to update the metadata. This array can be passed through the pipeline or explicitly passed via the parameter.
+ ///
+ [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = "IshObjectsGroup")]
+ [AllowEmptyCollection]
+ public IshObject[] IshObject { get; set; }
+
+ #region Private fields
+ ///
+ /// EDT will be defaulted to EDTXML. Needs to match up with FileContent or FilePath content.
+ ///
+ private string _edt = "EDTXML";
+ #endregion
+
+ protected override void BeginProcessing()
+ {
+ if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); }
+ if (IshSession == null) { throw new ArgumentException(ISHRemoteSessionStateIshSessionException); }
+ WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession}");
+ base.BeginProcessing();
+ }
+
+ ///
+ /// Process the Set-IshDocumentObj cmdlet.
+ ///
+ ///
+ ///
+ /// Writes an array to the pipeline.
+ protected override void ProcessRecord()
+ {
+ try
+ {
+ // 1. Validating the input
+ WriteDebug("Validating");
+ if (IshObject != null && IshObject.Length == 0)
+ {
+ // Do nothing
+ WriteVerbose("IshObject is empty, so nothing to update");
+ return;
+ }
+
+ // 2. Doing the update
+ WriteDebug("Updating");
+ List returnedObjects = new List();
+ IshFields requiredCurrentMetadata = new IshFields(RequiredCurrentMetadata);
+
+ if (ParameterSetName == "IshObjectsGroup")
+ {
+ int current = 0;
+ IshObject[] ishObjects = IshObject;
+ List lngCardIds = new List();
+
+ foreach (IshObject ishObject in ishObjects)
+ {
+ // Get language ref
+ long lngRef = Convert.ToInt64(ishObject.ObjectRef[Enumerations.ReferenceType.Lng]);
+ // Use incoming Metadata for update operation, or re-submit metadata of incoming IshObjects
+ var metadata = (Metadata != null) ?
+ IshSession.IshTypeFieldSetup.ToIshMetadataFields(ISHType, new IshFields(Metadata), Enumerations.ActionMode.Update) :
+ IshSession.IshTypeFieldSetup.ToIshMetadataFields(ISHType, ishObject.IshFields, Enumerations.ActionMode.Update);
+ if (ishObject.IshData != null)
+ {
+ WriteDebug($"lngRef[{lngRef}] Metadata.length[{metadata.ToXml().Length}] dataSize[{ishObject.IshData.Size()}] {++current}/{ishObjects.Length}");
+ if (ShouldProcess(Convert.ToString(lngRef)))
+ {
+ var response = IshSession.DocumentObj25.UpdateByIshLngRef(new UpdateByIshLngRefRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ plLngRef = lngRef,
+ psXMLMetadata = metadata.ToXml(),
+ psXMLRequiredCurrentMetadata = requiredCurrentMetadata.ToXml(),
+ psEdt = ishObject.IshData.Edt,
+ pbData = ishObject.IshData.ByteArray
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ }
+ }
+ else
+ {
+ WriteDebug($"lngRef[{lngRef}] Metadata.length[{metadata.ToXml().Length}] dataSize[0] {++current}/{ishObjects.Length}");
+ if (ShouldProcess(Convert.ToString(lngRef)))
+ {
+ var response = IshSession.DocumentObj25.SetMetadataByIshLngRef(new SetMetadataByIshLngRefRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ plLngRef = lngRef,
+ psXMLMetadata = metadata.ToXml(),
+ psXMLRequiredCurrentMetadata = requiredCurrentMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ }
+ }
+ lngCardIds.Add(lngRef);
+ }
+
+ var returnFields = IshObject[0].IshFields ?? new IshFields();
+ IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, returnFields, Enumerations.ActionMode.Read);
+ var responseRetrieve = IshSession.DocumentObj25.RetrieveMetadataByIshLngRefs(new RetrieveMetadataByIshLngRefsRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ palLngRefs = lngCardIds.ToArray(),
+ psXMLRequestedMetadata = requestedMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = responseRetrieve.psAuthContext;
+ string xmlIshObjects = responseRetrieve.psOutXMLObjList;
+ IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects);
+ returnedObjects.AddRange(retrievedObjects.Objects);
+ }
+ else
+ {
+ // ParameterGroups FilePath, FileContent, Metadata
+ string resolution = Resolution ?? "";
+ IshData ishData = null;
+ var metadata = IshSession.IshTypeFieldSetup.ToIshMetadataFields(ISHType, new IshFields(Metadata), Enumerations.ActionMode.Update);
+ string version = "-1";
+
+ if (ParameterSetName == "ParameterGroupFilePath")
+ {
+ ishData = new IshData(_edt, FilePath);
+ }
+
+ if (ParameterSetName == "ParameterGroupFileContent")
+ {
+ if (!_edt.Equals("EDTXML", StringComparison.Ordinal))
+ {
+ throw new NotImplementedException($"FileContent parameter is only supported with EDT[EDTXML], not EDT[{_edt}].");
+ }
+
+ var doc = XDocument.Parse(FileContent, LoadOptions.PreserveWhitespace);
+ var ms = new MemoryStream();
+ doc.Save(ms, SaveOptions.DisableFormatting);
+ ishData = new IshData(_edt, ms.ToArray());
+ }
+
+ if (ParameterSetName == "ParameterGroupMetadata")
+ {
+ WriteDebug($"Id[{LogicalId}] Version[{Version}] Lng[{Lng}] Resolution[{resolution}] Metadata.length[{metadata.ToXml().Length}] dataSize[0]");
+ if (ShouldProcess(LogicalId + "=" + Version + "=" + Lng + "=" + resolution))
+ {
+ var responseSet = IshSession.DocumentObj25.SetMetadata(new SetMetadataRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psLogicalId = LogicalId,
+ psVersion = Version,
+ psLanguage = Lng,
+ psResolution = resolution,
+ psXMLMetadata = metadata.ToXml(),
+ psXMLRequiredCurrentMetadata = requiredCurrentMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = responseSet.psAuthContext;
+ version = responseSet.psVersion;
+ }
+ }
+ else
+ {
+ WriteDebug($"Id[{LogicalId}] Version[{Version}] Lng[{Lng}] Resolution[{resolution}] Metadata.length[{metadata.ToXml().Length}] dataSize[{ishData.Size()}]");
+ if (ShouldProcess(LogicalId + "=" + Version + "=" + Lng + "=" + resolution))
+ {
+ var responseUpdate = IshSession.DocumentObj25.Update(new UpdateRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psLogicalId = LogicalId,
+ psVersion = Version,
+ psLanguage = Lng,
+ psResolution = resolution,
+ psXMLMetadata = metadata.ToXml(),
+ psXMLRequiredCurrentMetadata = requiredCurrentMetadata.ToXml(),
+ psEdt = ishData.Edt,
+ pbData = ishData.ByteArray
+ });
+ IshSession.AuthenticationContext = responseUpdate.psAuthContext;
+ version = responseUpdate.psVersion;
+ }
+ }
+
+ // Get the updated object
+ IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, metadata, Enumerations.ActionMode.Read);
+ var responseGet = IshSession.DocumentObj25.GetMetaData(new GetMetaDataRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psLogicalId = LogicalId,
+ psVersion = version,
+ psLanguage = Lng,
+ psResolution = resolution,
+ psXMLRequestedMetaData = requestedMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = responseGet.psAuthContext;
+ string xmlIshObjects = responseGet.psOutXMLObjList;
+ IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects);
+ returnedObjects.AddRange(retrievedObjects.Objects);
+ }
+
+ // 3. Write it
+ WriteVerbose("returned object count[" + returnedObjects.Count + "]");
+ WriteObject(IshSession, ISHType, returnedObjects.ConvertAll(x => (IshBaseObject)x), true);
+ }
+ catch (TrisoftAutomationException trisoftAutomationException)
+ {
+ ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
+ }
+ catch (Exception exception)
+ {
+ ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
+ }
+ }
+ }
+}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/EventMonitor/EventCmdlet.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/EventMonitor/EventCmdlet.cs
new file mode 100644
index 00000000..e1280080
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/EventMonitor/EventCmdlet.cs
@@ -0,0 +1,34 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Management.Automation;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+using Trisoft.ISHRemote.Exceptions;
+using System.Collections.Generic;
+
+namespace Trisoft.ISHRemote.Cmdlets.EventMonitor
+{
+ public abstract class EventCmdlet : TrisoftCmdlet
+ {
+ public Enumerations.ISHType[] ISHType
+ {
+ get { return new Enumerations.ISHType[] { Enumerations.ISHType.ISHEvent }; }
+ }
+ }
+}
+
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/EventMonitor/GetIshEvent.Tests.ps1 b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/EventMonitor/GetIshEvent.Tests.ps1
new file mode 100644
index 00000000..a090125d
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/EventMonitor/GetIshEvent.Tests.ps1
@@ -0,0 +1,214 @@
+BeforeAll {
+ $cmdletName = "Get-IshEvent"
+ Write-Host ("`r`nLoading ISHRemote.PesterSetup.ps1 over BeforeAll-block for MyCommand[" + $cmdletName + "]...")
+ . (Join-Path (Split-Path -Parent $PSCommandPath) "\..\..\ISHRemote.PesterSetup.ps1")
+
+ Write-Host ("Running "+$cmdletName+" Test Data and Variables initialization")
+}
+
+Describe "Get-IshEvent" -Tags "Create" {
+ BeforeAll {
+ $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Name "FNAME" |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Name "FDOCUMENTTYPE" |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Name "READ-ACCESS" -ValueType Element |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Name "FUSERGROUP" -ValueType Element
+ $ishFolderTestRootOriginal = Get-IshFolder -IShSession $ishSession -FolderPath $folderTestRootPath -RequestedMetadata $requestedMetadata
+ $folderIdTestRootOriginal = $ishFolderTestRootOriginal.IshFolderRef
+ $folderTypeTestRootOriginal = $ishFolderTestRootOriginal.IshFolderType
+ Write-Debug ("folderIdTestRootOriginal[" + $folderIdTestRootOriginal + "] folderTypeTestRootOriginal[" + $folderTypeTestRootOriginal + "]")
+ $ownedByTestRootOriginal = Get-IshMetadataField -IshSession $ishSession -Name "FUSERGROUP" -ValueType Element -IshField $ishFolderTestRootOriginal.IshField
+ $readAccessTestRootOriginal = (Get-IshMetadataField -IshSession $ishSession -Name "READ-ACCESS" -ValueType Element -IshField $ishFolderTestRootOriginal.IshField).Split($ishSession.Separator)
+
+ $global:ishFolderCmdlet = Add-IshFolder -IShSession $ishSession -ParentFolderId $folderIdTestRootOriginal -FolderType $folderTypeTestRootOriginal -FolderName $cmdletName -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+ $ishFolderTopic = Add-IshFolder -IshSession $ishSession -ParentFolderId ($global:ishFolderCmdlet.IshFolderRef) -FolderType ISHModule -FolderName "Topic" -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal
+ $ishTopicMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Topic $timestamp" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FAUTHOR" -Level Lng -ValueType Element -Value $ishUserAuthor |
+ Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusDraft
+ # Forcing a status transition to release, triggers Translation Management which means a BackgroundTask and EventMonitor entry
+ $ishObject = Add-IshDocumentObj -IshSession $ishSession -FolderId $ishFolderTopic.IshFolderRef -IshType ISHModule -Lng $ishLng -Metadata $ishTopicMetadata -FileContent $ditaTopicFileContent |
+ Set-IshDocumentObj -IshSession $ishSession -Metadata (Set-IshMetadataField -IshSession $ishSession -Name "FSTATUS" -Level Lng -ValueType Element -Value $ishStatusReleased)
+ $allProgressMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name PROGRESSID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name EVENTID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name CREATIONDATE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name MODIFICATIONDATE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name EVENTTYPE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name DESCRIPTION |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name STATUS -ValueType Value |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name STATUS -ValueType Element |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name USERID -ValueType Value |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name USERID -ValueType Element |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name PARENTPROGRESSID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name MAXIMUMPROGRESS |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name CURRENTPROGRESS
+ $allDetailMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name DETAILID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name PROGRESSID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name CREATIONDATE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name HOSTNAME |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name ACTION |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name DESCRIPTION |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name STATUS -ValueType Value |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name STATUS -ValueType Element |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name EVENTLEVEL -ValueType Value |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name EVENTLEVEL -ValueType Element |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name PROCESSID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name THREADID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name EVENTDATATYPE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name EVENTDATASIZE
+ $allMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name PROGRESSID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name EVENTID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name CREATIONDATE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name MODIFICATIONDATE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name EVENTTYPE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name DESCRIPTION |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name STATUS -ValueType Value |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name STATUS -ValueType Element |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name USERID -ValueType Value |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name USERID -ValueType Element |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name PARENTPROGRESSID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name MAXIMUMPROGRESS |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name CURRENTPROGRESS |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name DETAILID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name PROGRESSID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name CREATIONDATE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name HOSTNAME |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name ACTION |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name DESCRIPTION |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name STATUS -ValueType Value |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name STATUS -ValueType Element |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name EVENTLEVEL -ValueType Value |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name EVENTLEVEL -ValueType Element |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name PROCESSID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name THREADID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name EVENTDATATYPE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Detail -Name EVENTDATASIZE
+ }
+ Context "Get-IshEvent" {
+ BeforeAll {
+ $metadata = Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name PROGRESSID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name EVENTID |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name EVENTTYPE |
+ Set-IshRequestedMetadataField -IshSession $ishSession -Level Progress -Name STATUS
+ $ishEvent = (Get-IshEvent -IshSession $ishSession -UserFilter All -RequestedMetadata $metadata)[0]
+ }
+ It "GetType().Name" {
+ $ishEvent.GetType().Name | Should -BeExactly "IshEvent"
+ }
+ It "ishObject.IshField" {
+ $ishEvent.IshField | Should -Not -BeNullOrEmpty
+ }
+ It "ishObject.IshRef" {
+ $ishEvent.IshRef | Should -Not -BeNullOrEmpty
+ }
+ # Double check following 2 ReferenceType enum usage
+ It "ishEvent.ProgressRef" {
+ $ishEvent.ProgressRef | Should -Not -BeNullOrEmpty
+ }
+ #It "ishEvent.DetailRef" { # Requires BackgroundTask to be running to get detail entries
+ # $ishEvent.DetailRef | Should -Not -BeNullOrEmpty
+ #}
+ It "ishEvent ConvertTo-Json" {
+ (ConvertTo-Json $ishEvent).Length -gt 2 | Should -Be $true
+ }
+ It "Parameter IshSession/ModifiedSince/UserFilter invalid" {
+ { Get-IshEvent -IShSession "INVALIDISHSESSION" -ModifiedSince "INVALIDDATE" -UserFilter "INVALIDUSERFILTER" } | Should -Throw
+ }
+ It "Parameter RequestedMetadata/MetadataFile invalid" {
+ { Get-IshEvent -IShSession $ishSession -RequestedMetadata "INVALIDMETADATA" -MetadataFilter "INVALIDFILTER" } | Should -Throw
+ }
+ It "Parameter IshSession/UserFilter/MetadataFilter are optional" {
+ $ishEvent = (Get-IshEvent -ModifiedSince ((Get-Date).AddSeconds(-10)) -RequestedMetadata $allProgressMetadata)[0]
+ ($ishEvent | Get-IshMetadataField -IshSession $ishSession -Level Progress -Name EVENTID -ValueType Value).Length -gt 0 | Should -Be $true
+ #($ishEvent | Get-IshMetadataField -IshSession $ishSession -Level Progress -Name USERID -ValueType Element).StartsWith('VUSER') | Should -Be $false # unexpected but ValueType Element is not returned by the API call
+ }
+ It "Option IshSession.DefaultRequestedMetadata" {
+ $oldDefaultRequestedMetadata = $ishSession.DefaultRequestedMetadata
+ $ishSession.DefaultRequestedMetadata = "Descriptive"
+ $ishEvent = (Get-IshEvent -IShSession $ishSession)[0]
+ $ishEvent.IshField.Count | Should -Be 2
+ $ishSession.DefaultRequestedMetadata = "Basic"
+ $ishEvent = (Get-IshEvent -IShSession $ishSession)[0]
+ $ishEvent.status.Length -gt 0 | Should -Be $true
+ $ishEvent.IshField.Count | Should -Be 9
+ $ishSession.DefaultRequestedMetadata = "All"
+ $ishEvent = (Get-IshEvent -IShSession $ishSession)[0]
+ $ishEvent.IshField.Count | Should -Be 10
+ $ishSession.DefaultRequestedMetadata = $oldDefaultRequestedMetadata
+ }
+ It "Parameter ModifiedSince is now" {
+ (Get-IshEvent -IshSession $ishSession -ModifiedSince ((Get-Date).AddMinutes(1)) -UserFilter All).Count | Should -Be 0
+ }
+ It "Parameter RequestedMetadata only all of Progress level" {
+ $ishEvent = (Get-IshEvent -IshSession $ishSession -ModifiedSince ((Get-Date).AddSeconds(-10)) -UserFilter All -RequestedMetadata $allProgressMetadata)[0]
+ $ishEvent.ProgressRef -gt 0 | Should -Be $true
+ #$ishEvent.DetailRef -gt 0 | Should -Be $true
+ $ishEvent.IshField.Count | Should -Be 10
+ }
+ It "Parameter RequestedMetadata only all of Detail level" {
+ $ishEvent = (Get-IshEvent -IshSession $ishSession -ModifiedSince ((Get-Date).AddMinutes(-1)) -UserFilter All -RequestedMetadata $allDetailMetadata)[0]
+ $ishEvent.ProgressRef -gt 0 | Should -Be $true
+ $ishEvent.DetailRef -gt 0 | Should -Be $true
+ $ishEvent.IshField.Count -ge 20 | Should -Be $true # Perhaps expected 10 Progress level fields, but Get-IshEvent currently always retrieves details as well
+ }
+ It "Parameter RequestedMetadata PipelineObjectPreference=PSObjectNoteProperty" {
+ $ishSession.PipelineObjectPreference | Should -Be "PSObjectNoteProperty"
+ $ishEvent = (Get-IshEvent -IshSession $ishSession -ModifiedSince ((Get-Date).AddMinutes(-1)) -UserFilter All -RequestedMetadata $allMetadata)[0]
+ $ishEvent.GetType().Name | Should -BeExactly "IshEvent" # and not PSObject
+ [bool]($ishEvent.PSobject.Properties.name -match "status") | Should -Be $true
+ [bool]($ishEvent.PSobject.Properties.name -match "userid") | Should -Be $true
+ [bool]($ishEvent.PSobject.Properties.name -match "modificationdate") | Should -Be $true
+ [bool]($ishEvent.PSobject.Properties.name -match "status_detail_value") | Should -Be $true
+ $ishEvent.modificationdate -like "*/*" | Should -Be $false # It should be sortable date format: yyyy-MM-ddTHH:mm:ss
+ }
+ It "Parameter RequestedMetadata PipelineObjectPreference=Off" {
+ $pipelineObjectPreference = $ishSession.PipelineObjectPreference
+ $ishSession.PipelineObjectPreference = "Off"
+ $ishEvent = (Get-IshEvent -IshSession $ishSession -ModifiedSince ((Get-Date).AddMinutes(-1)) -UserFilter All -RequestedMetadata $allMetadata)[0]
+ $ishEvent.GetType().Name | Should -BeExactly "IshEvent"
+ [bool]($ishEvent.PSobject.Properties.name -match "status") | Should -Be $false
+ [bool]($ishEvent.PSobject.Properties.name -match "userid") | Should -Be $false
+ [bool]($ishEvent.PSobject.Properties.name -match "modificationdate") | Should -Be $false
+ [bool]($ishEvent.PSobject.Properties.name -match "status_detail_value") | Should -Be $false
+ $ishSession.PipelineObjectPreference = $pipelineObjectPreference
+ }
+ It "Parameter MetadataFilter" {
+ $ishEvent = (Get-IshEvent -IshSession $ishSession -ModifiedSince ((Get-Date).AddMinutes(-1)) -UserFilter All -RequestedMetadata $allMetadata)[0]
+ $filterMetadata = Set-IshMetadataFilterField -IshSession $ishSession -Level Progress -Name EVENTID -Value ($ishEvent | Get-IshMetadataField -IshSession $ishSession -Level Progress -Name EVENTID)
+ # | Set-IshMetadataFilterField -IshSession $ishSession -Level Progress -Name USERID -Value ($ishEvent | Get-IshMetadataField -IshSession $ishSession -Level Progress -Name USERID) # Seems just like higher that USERID by valuetype retrieval and filtering are not working
+ $ishEventArray = Get-IshEvent -IshSession $ishSession -MetadataFilter $filterMetadata
+ #Write-Host ("ishEvent.IshRef["+ $ishEvent.IshRef + "] ishEventArray.IshRef["+ $ishEvent.IshRef + "]")
+ $ishEventArray.Count -ge 1 | Should -Be $true
+ }
+ It "Parameter IshEvent invalid" {
+ { Get-IshEvent -IshSession $ishSession -IshEvent "INVALIDISHEVENT" } | Should -Throw
+ }
+ It "Parameter IshEvent Single" {
+ $ishEvent = (Get-IshEvent -IshSession $ishSession -ModifiedSince ((Get-Date).AddMinutes(-1)) -UserFilter Current)[0]
+ $eventId = $ishEvent | Get-IshMetadataField -IshSession $ishSession -Level Progress -Name EVENTID
+ $ishEventArray = Get-IshEvent -IshSession $ishSession -IshEvent $ishEvent
+ $ishEventArray.Count -ge 1 | Should -Be $true
+ $ishEventArray.IshRef | Should -Be $eventId
+ }
+ <# TODO [Could] It "Parameter IshEvent Multiple" {
+ }
+ #>
+ It "Pipeline IshEvent Single" {
+ $ishEvent = (Get-IshEvent -IshSession $ishSession -ModifiedSince ((Get-Date).AddMinutes(-1)) -UserFilter Current)[0]
+ $eventId = $ishEvent | Get-IshMetadataField -IshSession $ishSession -Level Progress -Name EVENTID
+ $ishEventArray = $ishEvent | Get-IshEvent -IshSession $ishSession
+ $ishEventArray.Count -ge 1 | Should -Be $true
+ $ishEventArray.IshRef | Should -Be $eventId
+ }
+ <# TODO [Could] It "Pipeline IshEvent Multiple" {
+ }
+ #>
+ }
+ #>
+}
+
+AfterAll {
+ Write-Host ("Running "+$cmdletName+" Test Data and Variables cleanup")
+ $folderCmdletRootPath = (Join-Path $folderTestRootPath $cmdletName)
+ try { Get-IshFolder -IshSession $ishSession -FolderPath $folderCmdletRootPath -Recurse | Get-IshFolderContent -IshSession $ishSession | Remove-IshDocumentObj -IshSession $ishSession -Force } catch { }
+ try { Remove-IshFolder -IshSession $ishSession -FolderPath $folderCmdletRootPath -Recurse } catch { }
+}
+
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/EventMonitor/GetIshEvent.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/EventMonitor/GetIshEvent.cs
new file mode 100644
index 00000000..a1b35e40
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/EventMonitor/GetIshEvent.cs
@@ -0,0 +1,277 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Management.Automation;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+using Trisoft.ISHRemote.Exceptions;
+using Trisoft.ISHRemote.HelperClasses;
+using System.Linq;
+
+namespace Trisoft.ISHRemote.Cmdlets.EventMonitor
+{
+ ///
+ /// Gets EventMonitor entries with filtering options.
+ /// Uses EventMonitor25 API to retrieve ishevents showing progress of background task events from the centralized log system.
+ /// This table oriented API maps straight through to database column names regarding ishfield usage.
+ ///
+ ///
+ ///
+ /// $ishSession = New-IshSession -WsBaseUrl "https://example.com/ISHWS/" -PSCredential "Admin"
+ /// $requestedMetadata = Set-IshRequestedMetadataField -Name "EVENTID" -Level "Progress" |
+ /// Set-IshRequestedMetadataField -Name "EVENTTYPE" -Level "Progress"
+ /// Get-IshEvent -EventTypes @("EXPORTFORPUBLICATION","SYNCHRONIZETOLIVECONTENT") -RequestedMetadata $requestedMetadata
+ ///
+ /// New-IshSession will submit into SessionState, so it can be reused by this cmdlet. Gets all top-level (progress) ishevents filtered to publish and synchronize events.
+ ///
+ ///
+ ///
+ /// $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Name "EVENTID" -Level "Progress" |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Name "EVENTTYPE" -Level "Progress" |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Name "EVENTDATATYPE" -Level "Detail"
+ /// $metadataFilter = Set-IshMetadataFilterField -IshSession $ishSession -Name "EVENTDATATYPE" -Level "Detail" -FilterOperator "NotEqual" -Value "10"
+ /// Get-IshEvent -IshSession $ishSession -EventTypes @("EXPORTFORPUBLICATION","SYNCHRONIZETOLIVECONTENT") -RequestedMetadata $requestedMetadata -MetadataFilter $metadataFilter
+ ///
+ /// Gets up to detail ishevents filtered to publish and synchronize events and the eventdatatype should differ from 10.
+ ///
+ ///
+ ///
+ /// $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Name "EVENTID" -Level "Progress" |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Name "EVENTTYPE" -Level "Progress" |
+ /// Set-IshRequestedMetadataField -IshSession $ishSession -Name "EVENTDATATYPE" -Level "Detail"
+ /// $metadataFilter = Set-IshMetadataFilterField -IshSession $ishSession -Name "ACTION" -Level "Detail" -FilterOperator In -Value "Request started, Start execution, Execution completed"
+ /// Get-IshEvent -IshSession $ishSession -EventTypes @("EXPORTFORPUBLICATION") -RequestedMetadata $requestedMetadata -MetadataFilter $metadataFilter
+ ///
+ /// Gets up to detail ishevents filtered to publish events and filters to only have the queue event, processing started and processing ended. This allows calculation of lead times and through put.
+ ///
+ [Cmdlet(VerbsCommon.Get, "IshEvent", SupportsShouldProcess = false)]
+ [OutputType(typeof(IshEvent))]
+ public sealed class GetIshEvent : EventCmdlet
+ {
+
+ ///
+ /// The IshSession variable holds the authentication and contract information. This object can be initialized using the New-IshSession cmdlet.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshEventsGroup")]
+ [ValidateNotNullOrEmpty]
+ public IshSession IshSession { get; set; }
+
+ ///
+ /// String array containing the event types to retrieve (e.g. EXPORTFORPUBLICATION, PUSHTRANSLATIONS,...)
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup"), ValidateNotNullOrEmpty]
+ public string[] EventTypes { get; set; }
+
+
+ ///
+ /// The enumeration indicating which overall status the event must have (e.g. All, Success, Failed,...)
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [ValidateNotNullOrEmpty]
+ public Enumerations.ProgressStatusFilter ProgressStatusFilter
+ {
+ private get { return Enumerations.ProgressStatusFilter.All; } // required otherwise XmlDoc2CmdletDoc crashes with 'System.ArgumentException: Property Get method was not found.'
+ set { _progressStatusFilter = EnumConverter.ToProgressStatusFilter(value); }
+ }
+
+ ///
+ /// A date limiting the events that will be retrieved based on the last modification date of the events
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [ValidateNotNullOrEmpty]
+ public DateTime ModifiedSince
+ {
+ get { return _modifiedSince; }
+ set { _modifiedSince = value; }
+ }
+
+ ///
+ /// Enumeration indicating if only events of the current user or all events must be retrieved
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [ValidateNotNullOrEmpty]
+ public Enumerations.UserFilter UserFilter
+ {
+ private get { return Enumerations.UserFilter.All; } // required otherwise XmlDoc2CmdletDoc crashes with 'System.ArgumentException: Property Get method was not found.'
+ set { _userFilter = EnumConverter.ToUserFilter(value); }
+ }
+
+ ///
+ /// Filter on metadata to limit the objects on which metadata has to be returned
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshEventsGroup")]
+ [ValidateNotNullOrEmpty]
+ public IshField[] MetadataFilter { get; set; }
+
+ ///
+ /// XML structure indicating which metadata has to be retrieved.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshEventsGroup")]
+ [ValidateNotNullOrEmpty]
+ public IshField[] RequestedMetadata { get; set; }
+
+
+ ///
+ /// Possible values for the level of an event detail.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshEventsGroup")]
+ [ValidateNotNullOrEmpty]
+ public Enumerations.EventLevel EventLevel
+ {
+ private get { return Enumerations.EventLevel.Exception; } // required otherwise XmlDoc2CmdletDoc crashes with 'System.ArgumentException: Property Get method was not found.'
+ set { _eventLevel = EnumConverter.ToEventLevelFilter(value); }
+ }
+
+ ///
+ /// The s that need to be handled.
+ ///
+ [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = "IshEventsGroup")]
+ public IshEvent[] IshEvent { get; set; }
+
+
+
+ #region Private fields
+ private DateTime _modifiedSince = DateTime.Today.AddDays(-1);
+ private EventMonitor25ServiceReference.eProgressStatusFilter _progressStatusFilter = EventMonitor25ServiceReference.eProgressStatusFilter.All;
+ private EventMonitor25ServiceReference.eUserFilter _userFilter = EventMonitor25ServiceReference.eUserFilter.All;
+ private EventMonitor25ServiceReference.eEventLevel _eventLevel = EventMonitor25ServiceReference.eEventLevel.Information;
+ private List _retrievedIshEvents = new List();
+ #endregion
+
+ protected override void BeginProcessing()
+ {
+ if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); }
+ if (IshSession == null) { throw new ArgumentException(ISHRemoteSessionStateIshSessionException); }
+ WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession}");
+ base.BeginProcessing();
+ }
+
+
+ ///
+ /// Process the cmdlet.
+ ///
+ protected override void ProcessRecord()
+ {
+ try
+ {
+ if (IshEvent != null)
+ {
+ foreach(IshEvent ishEvent in IshEvent)
+ {
+ _retrievedIshEvents.Add(ishEvent);
+ }
+ }
+ }
+ catch (TrisoftAutomationException trisoftAutomationException)
+ {
+ ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
+ }
+ catch (Exception exception)
+ {
+ ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
+ }
+ }
+
+ ///
+ /// Process the cmdlet.
+ ///
+ ///
+ ///
+ /// Writes to the pipeline.
+ protected override void EndProcessing()
+ {
+ try
+ {
+ IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, new IshFields(RequestedMetadata), Enumerations.ActionMode.Find);
+ string xmlIshEvents;
+ if (_retrievedIshEvents.Count == 0)
+ {
+ WriteVerbose("Retrieving overview");
+ var progressLevelRequestedMetadata = requestedMetadata.ToRequestedFields(Enumerations.Level.Progress);
+ WriteDebug($"Retrieving ProgressStatusFilter[{_progressStatusFilter}] UserFilter[{_userFilter}] RequestedMetadata.length[{progressLevelRequestedMetadata.ToXml().Length}]");
+ var response = IshSession.EventMonitor25.RetrieveEventOverview(new EventMonitor25ServiceReference.RetrieveEventOverviewRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ pasEventTypes = EventTypes,
+ peStatusFilter = _progressStatusFilter,
+ pdModifiedSince = ModifiedSince,
+ peUserFilter = _userFilter,
+ psXMLRequestedEventData = progressLevelRequestedMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ xmlIshEvents = response.psOutXMLEventList;
+ _retrievedIshEvents = new IshEvents(xmlIshEvents).Events;
+ }
+
+ // If incoming RequestedMetadata only requests Progress level, then limit to that
+ var checkRequestedMetadataDetailLevelCount = (new IshFields(RequestedMetadata)).ToRequestedFields(Enumerations.Level.Detail).Count();
+ if (checkRequestedMetadataDetailLevelCount == 0)
+ {
+ // Note on iteratively retrieving and filtering...
+ // RetrieveEventsByProgressIds eventually selects from a simple join of ISH_EVENTPROGRESSDETAILS.PROGRESSID with ISH_EVENTPROGRESS.PROGRESSID;
+ // so if there are no entries in ISH_EVENTPROGRESSDETAILS, then there are no results. Left outer join might have been better but will not be fixed across 10+ fielded product versions.
+ requestedMetadata = requestedMetadata.ToRequestedFields(Enumerations.Level.Progress);
+ WriteDebug("Limiting requestedMetadata to Progress level");
+ }
+
+ // if there is a filter RetrieveEventsByProgressIds after RetrieveEventOverview or on incoming IShEvents
+ var progressRefs = _retrievedIshEvents.Select(ishEvent => Convert.ToInt64(ishEvent.ProgressRef)).ToList();
+ WriteVerbose("Retrieving details for " + progressRefs.Count + " overview events");
+ if (progressRefs.Count != 0)
+ {
+ IshFields metadataFilter = new IshFields(MetadataFilter);
+ //TODO: [Could] could become the highest ishdetailref value to retrieve less, but then you need to 'append' to the incoming IshEvents so low priority
+ long lastDetailId = 0;
+ //TODO: [Could] requestedMetadata can be all levels here
+ var response = IshSession.EventMonitor25.RetrieveEventsByProgressIds(new EventMonitor25ServiceReference.RetrieveEventsByProgressIdsRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ palProgressIds = progressRefs.ToArray(),
+ peLevelFilter = _eventLevel,
+ plLastDetailId = lastDetailId,
+ psXMLEventDataFilter = metadataFilter.ToXml(),
+ psXMLRequestedEventData = requestedMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ xmlIshEvents = response.psOutXMLEventList;
+ _retrievedIshEvents = new IshEvents(xmlIshEvents).Events;
+ }
+
+ WriteVerbose("returned object count[" + _retrievedIshEvents.Count + "]");
+ WriteObject(IshSession, ISHType, _retrievedIshEvents.ConvertAll(x => (IshBaseObject)x), true);
+ }
+ catch (TrisoftAutomationException trisoftAutomationException)
+ {
+ ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
+ }
+ catch (Exception exception)
+ {
+ ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
+ }
+ finally
+ {
+ base.EndProcessing();
+ }
+ }
+ }
+}
+
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Feature/FeatureCmdlet.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Feature/FeatureCmdlet.cs
new file mode 100644
index 00000000..3c1ec9c0
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Feature/FeatureCmdlet.cs
@@ -0,0 +1,32 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Trisoft.ISHRemote.Cmdlets.Feature
+{
+ ///
+ /// Abstract class used for the feature commandlets for condition filtering usage
+ ///
+ /// Inherits from .
+ public abstract class FeatureCmdlet : TrisoftCmdlet
+ {
+ }
+}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Feature/SetIshFeature.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Feature/SetIshFeature.cs
new file mode 100644
index 00000000..b0f22e63
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Feature/SetIshFeature.cs
@@ -0,0 +1,104 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Management.Automation;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+using Trisoft.ISHRemote.Exceptions;
+using Trisoft.ISHRemote.HelperClasses;
+
+namespace Trisoft.ISHRemote.Cmdlets.Feature
+{
+ ///
+ /// The Set-IshFeature cmdlet creates a new IshFeature based on the parameters provided. When IshFeature[] object is passed through the pipeline then the new feature is added based on the parameters provided
+ /// The Set-IshFeature cmdlet creates a new IshFeature based on the parameters provided. When IshFeature[] object is passed through the pipeline then the new feature is added based on the parameters provided
+ ///
+ ///
+ ///
+ /// New-IshSession -WsBaseUrl "https://example.com/ISHWS/" -PSCredential "Admin"
+ /// $ishFeatures = Set-IshFeature -Name "ISHRemoteStringCond" -Value "StringOne" |
+ /// Set-IshFeature -Name "ISHRemoteVersionCond" -Value "12.0.1"
+ ///
+ /// New-IshSession will submit into SessionState, so it can be reused by this cmdlet. Build a Condition Context for passing to Get-DocumentObjData.
+ ///
+ [Cmdlet(VerbsCommon.Set, "IshFeature", SupportsShouldProcess = false)]
+ [OutputType(typeof(IshFeature))]
+ public sealed class SetIshFeature : TrisoftCmdlet
+ {
+ ///
+ /// The IshSession variable holds the authentication and contract information. This object can be initialized using the New-IshSession cmdlet.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false)]
+ [ValidateNotNullOrEmpty]
+ public IshSession IshSession { get; set; }
+
+ ///
+ /// The condition name
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false)]
+ public string Name { get; set; }
+
+ ///
+ /// The condition value
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false)]
+ public string Value { get; set; }
+
+ ///
+ /// The set of condition names and values
+ ///
+ [Parameter(Mandatory = false, ValueFromPipeline = true)]
+ public IshFeature[] IshFeature { get; set; }
+
+ protected override void BeginProcessing()
+ {
+ if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); }
+ if (IshSession == null) { throw new ArgumentException(ISHRemoteSessionStateIshSessionException); }
+ WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession}");
+ base.BeginProcessing();
+ }
+
+ protected override void ProcessRecord()
+ {
+ try
+ {
+ // Work with piped IshFeatures object or create a new one.
+ IshFeatures ishFeatures = new IshFeatures(IshFeature);
+ string name = Name ?? "";
+ string value = Value ?? "";
+
+ WriteVerbose("name[" + name + "] value[" + value + "]");
+
+ if (Name != "")
+ {
+ IshFeature ishFeature = new IshFeature(name, value);
+ ishFeatures.AddFeature(ishFeature);
+ }
+
+ WriteObject(ishFeatures.Features, true);
+ }
+ catch (TrisoftAutomationException trisoftAutomationException)
+ {
+ ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
+ }
+ catch (Exception exception)
+ {
+ ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
+ }
+ }
+ }
+}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/AddIshFolder.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/AddIshFolder.cs
index e0ee944e..06d59ef7 100644
--- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/AddIshFolder.cs
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/AddIshFolder.cs
@@ -206,16 +206,14 @@ protected override void ProcessRecord()
// Add the required fields (needed for pipe operations)
IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, returnFields, Enumerations.ActionMode.Read);
- string xmlIshFolders = "";
var response = IshSession.Folder25.RetrieveMetadataByIshFolderRefs(new Folder25ServiceReference.RetrieveMetadataByIshFolderRefsRequest()
{
psAuthContext = IshSession.AuthenticationContext,
palFolderRefs = foldersToRetrieve.ToArray(),
- psXMLRequestedMetaData = requestedMetadata.ToXml(),
- psOutXMLFolderList = xmlIshFolders
+ psXMLRequestedMetaData = requestedMetadata.ToXml()
});
IshSession.AuthenticationContext = response.psAuthContext;
- xmlIshFolders = response.psOutXMLFolderList;
+ string xmlIshFolders = response.psOutXMLFolderList;
IshFolders retrievedFolders = new IshFolders(xmlIshFolders);
returnedFolders.AddRange(retrievedFolders.Folders);
}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolder.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolder.cs
index 118bb660..9308f2b3 100644
--- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolder.cs
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolder.cs
@@ -238,16 +238,14 @@ protected override void EndProcessing()
foreach (List folderCardIdBatch in devidedFolderCardIdsList)
{
// Process card ids in batches
- string xmlIshFolders = "";
var response = IshSession.Folder25.RetrieveMetadataByIshFolderRefs(new Folder25ServiceReference.RetrieveMetadataByIshFolderRefsRequest()
{
psAuthContext = IshSession.AuthenticationContext,
palFolderRefs = folderCardIdBatch.ToArray(),
- psXMLRequestedMetaData = _requestedMetadata.ToXml(),
- psOutXMLFolderList = xmlIshFolders
+ psXMLRequestedMetaData = _requestedMetadata.ToXml()
});
IshSession.AuthenticationContext = response.psAuthContext;
- xmlIshFolders = response.psOutXMLFolderList;
+ string xmlIshFolders = response.psOutXMLFolderList;
IshFolders retrievedObjects = new IshFolders(xmlIshFolders);
returnIshFolders.AddRange(retrievedObjects.Folders);
currentFolderCardIdCount += folderCardIdBatch.Count;
@@ -263,16 +261,14 @@ protected override void EndProcessing()
foreach (List folderCardIdBatch in devidedFolderCardIdsList)
{
// Process card ids in batches
- string xmlIshFolders = "";
var response = IshSession.Folder25.RetrieveMetadataByIshFolderRefs(new Folder25ServiceReference.RetrieveMetadataByIshFolderRefsRequest()
{
psAuthContext = IshSession.AuthenticationContext,
palFolderRefs = folderCardIdBatch.ToArray(),
- psXMLRequestedMetaData = _requestedMetadata.ToXml(),
- psOutXMLFolderList = xmlIshFolders
+ psXMLRequestedMetaData = _requestedMetadata.ToXml()
});
IshSession.AuthenticationContext = response.psAuthContext;
- xmlIshFolders = response.psOutXMLFolderList;
+ string xmlIshFolders = response.psOutXMLFolderList;
IshFolders retrievedObjects = new IshFolders(xmlIshFolders);
returnIshFolders.AddRange(retrievedObjects.Folders);
currentFolderCardIdCount += folderCardIdBatch.Count;
@@ -293,17 +289,15 @@ protected override void EndProcessing()
Array.Copy(folderPathElements, 1, folderPathTrisoft, 0, folderPathElements.Length - 1);
WriteDebug($"FolderPath[{ folderPath}]");
- string xmlIshFolder = "";
var response = IshSession.Folder25.GetMetaData(new Folder25ServiceReference.GetMetaDataRequest()
{
psAuthContext = IshSession.AuthenticationContext,
peBaseFolder = BaseFolderLabelToEnum(IshSession, baseFolderLabel),
pasFolderPath = folderPathTrisoft,
- psXMLRequestedMetaData = _requestedMetadata.ToXml(),
- psOutXMLFolderList = xmlIshFolder
+ psXMLRequestedMetaData = _requestedMetadata.ToXml()
});
IshSession.AuthenticationContext = response.psAuthContext;
- xmlIshFolder = response.psOutXMLFolderList;
+ string xmlIshFolder = response.psOutXMLFolderList;
IshFolders retrievedFolders = new IshFolders(xmlIshFolder, "ishfolder");
returnIshFolders.AddRange(retrievedFolders.Folders);
}
@@ -312,17 +306,15 @@ protected override void EndProcessing()
// Retrieve using BaseFolder string (enumeration)
var baseFolder = EnumConverter.ToBaseFolder(BaseFolder);
WriteDebug($"BaseFolder[{baseFolder}]");
- string xmlIshFolders = "";
var response = IshSession.Folder25.GetMetaData(new Folder25ServiceReference.GetMetaDataRequest()
{
psAuthContext = IshSession.AuthenticationContext,
peBaseFolder = baseFolder,
pasFolderPath = new string[0],
- psXMLRequestedMetaData = _requestedMetadata.ToXml(),
- psOutXMLFolderList = xmlIshFolders
+ psXMLRequestedMetaData = _requestedMetadata.ToXml()
});
IshSession.AuthenticationContext = response.psAuthContext;
- xmlIshFolders = response.psOutXMLFolderList;
+ string xmlIshFolders = response.psOutXMLFolderList;
IshFolders retrievedFolders = new IshFolders(xmlIshFolders, "ishfolder");
returnIshFolders.AddRange(retrievedFolders.Folders);
}
@@ -410,15 +402,13 @@ private void RetrieveRecursive(IshFolder ishFolder, int currentDepth, int maxDep
if (currentDepth < (maxDepth - 1))
{
WriteDebug($"RetrieveRecursive IshFolderRef[{ishFolder.IshFolderRef}] folderName[{folderName}] ({currentDepth}<{maxDepth})");
- string xmlIshFolders = "";
var responseSubFolders = IshSession.Folder25.GetSubFoldersByIshFolderRef(new Folder25ServiceReference.GetSubFoldersByIshFolderRefRequest()
{
psAuthContext = IshSession.AuthenticationContext,
- plFolderRef = ishFolder.IshFolderRef,
- psOutXMLFolderList = xmlIshFolders
+ plFolderRef = ishFolder.IshFolderRef
});
IshSession.AuthenticationContext = responseSubFolders.psAuthContext;
- xmlIshFolders = responseSubFolders.psOutXMLFolderList;
+ string xmlIshFolders = responseSubFolders.psOutXMLFolderList;
// GetSubFolders contains ishfolder for the parent folder + ishfolder inside for the subfolders
IshFolders retrievedFolders = new IshFolders(xmlIshFolders, "ishfolder/ishfolder");
if (retrievedFolders.Ids.Length > 0)
@@ -429,8 +419,7 @@ private void RetrieveRecursive(IshFolder ishFolder, int currentDepth, int maxDep
{
psAuthContext = IshSession.AuthenticationContext,
palFolderRefs = retrievedFolders.Ids,
- psXMLRequestedMetaData = _requestedMetadata.ToXml(),
- psOutXMLFolderList = xmlIshFolders
+ psXMLRequestedMetaData = _requestedMetadata.ToXml()
});
IshSession.AuthenticationContext = responseRetrieve.psAuthContext;
xmlIshFolders = responseRetrieve.psOutXMLFolderList;
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolderContent.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolderContent.cs
index be42c1ef..3ca280f5 100644
--- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolderContent.cs
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolderContent.cs
@@ -229,34 +229,30 @@ protected override void ProcessRecord()
Array.Copy(folderPathElements, 1, folderPathTrisoft, 0, folderPathElements.Length - 1);
WriteDebug($"FolderPath[{folderPath}]");
- string xmlIshFolder = "";
var responseFolderPath = IshSession.Folder25.GetMetaData(new Folder25ServiceReference.GetMetaDataRequest()
{
psAuthContext = IshSession.AuthenticationContext,
peBaseFolder = BaseFolderLabelToEnum(IshSession, baseFolderLabel),
pasFolderPath = folderPathTrisoft,
- psXMLRequestedMetaData = "",
- psOutXMLFolderList = xmlIshFolder
+ psXMLRequestedMetaData = ""
});
IshSession.AuthenticationContext = responseFolderPath.psAuthContext;
- xmlIshFolder = responseFolderPath.psOutXMLFolderList;
+ string xmlIshFolder = responseFolderPath.psOutXMLFolderList;
IshFolders ishFolders = new IshFolders(xmlIshFolder, "ishfolder");
returnFolderIds.Add(ishFolders.Folders[0].IshFolderRef);
break;
case "BaseFolderGroup":
var baseFolder = EnumConverter.ToBaseFolder(BaseFolder);
- string xmlIshFolders = "";
var responseBaseFolder = IshSession.Folder25.GetMetaData(new Folder25ServiceReference.GetMetaDataRequest()
{
psAuthContext = IshSession.AuthenticationContext,
peBaseFolder = baseFolder,
pasFolderPath = new string[0],
- psXMLRequestedMetaData = "",
- psOutXMLFolderList = xmlIshFolders
+ psXMLRequestedMetaData = ""
});
IshSession.AuthenticationContext = responseBaseFolder.psAuthContext;
- xmlIshFolders = responseBaseFolder.psOutXMLFolderList;
+ string xmlIshFolders = responseBaseFolder.psOutXMLFolderList;
IshFolders retrievedFolders = new IshFolders(xmlIshFolders, "ishfolder");
returnFolderIds.Add(retrievedFolders.Folders[0].IshFolderRef);
break;
@@ -292,15 +288,13 @@ protected override void ProcessRecord()
{
// 2. Doing Retrieve
WriteDebug($"Looping folderId[{returnFolderId}] {++current}/{returnFolderIds.Count}");
- string xmlIshObjects = "";
var responseGetContents = IshSession.Folder25.GetContents(new Folder25ServiceReference.GetContentsRequest()
{
psAuthContext = IshSession.AuthenticationContext,
- plFolderRef = returnFolderId,
- psOutXMLObjList = xmlIshObjects
+ plFolderRef = returnFolderId
});
IshSession.AuthenticationContext = responseGetContents.psAuthContext;
- xmlIshObjects = responseGetContents.psOutXMLObjList;
+ string xmlIshObjects = responseGetContents.psOutXMLObjList;
var ishObjects = new IshObjects(xmlIshObjects);
if (ishObjects.Ids.Length > 0)
@@ -333,8 +327,7 @@ protected override void ProcessRecord()
psAuthContext = IshSession.AuthenticationContext,
pasLogicalIds = logicalIdBatch.ToArray(),
psVersion = VersionFilter,
- psXMLRequestedMetadata = "",
- psOutXMLObjList = xmlIshObjects
+ psXMLRequestedMetadata = ""
});
IshSession.AuthenticationContext = responseRetrieveVersion.psAuthContext;
xmlIshObjects = responseRetrieveVersion.psOutXMLObjList;
@@ -352,8 +345,7 @@ protected override void ProcessRecord()
palVersionRefs = versionRefs.ToArray(),
peStatusFilter = DocumentObj25ServiceReference.eISHStatusgroup.ISHNoStatusFilter,
psXMLMetadataFilter = metadataFilterFields.ToXml(),
- psXMLRequestedMetadata = requestedMetadata.ToXml(),
- psOutXMLObjList = xmlIshObjects
+ psXMLRequestedMetadata = requestedMetadata.ToXml()
});
IshSession.AuthenticationContext = responseRetrieve.psAuthContext;
xmlIshObjects = responseRetrieve.psOutXMLObjList;
@@ -371,8 +363,7 @@ protected override void ProcessRecord()
pasLogicalIds = logicalIdBatch.ToArray(),
peStatusFilter = DocumentObj25ServiceReference.eISHStatusgroup.ISHNoStatusFilter,
psXMLMetadataFilter = metadataFilterFields.ToXml(),
- psXMLRequestedMetadata = requestedMetadata.ToXml(),
- psOutXMLObjList = xmlIshObjects
+ psXMLRequestedMetadata = requestedMetadata.ToXml()
});
IshSession.AuthenticationContext = response.psAuthContext;
xmlIshObjects = response.psOutXMLObjList;
@@ -410,8 +401,7 @@ protected override void ProcessRecord()
psAuthContext = IshSession.AuthenticationContext,
pasLogicalIds = logicalIdBatch.ToArray(),
psVersion = VersionFilter,
- psXMLRequestedMetadata = "",
- psOutXMLObjList = xmlIshObjects
+ psXMLRequestedMetadata = ""
});
IshSession.AuthenticationContext = response.psAuthContext;
xmlIshObjects = response.psOutXMLObjList;
@@ -430,8 +420,7 @@ protected override void ProcessRecord()
palVersionRefs = versionRefs.ToArray(),
peStatusFilter = PublicationOutput25ServiceReference.eISHStatusgroup.ISHNoStatusFilter,
psXMLMetadataFilter = metadataFilterFields.ToXml(),
- psXMLRequestedMetadata = requestedMetadata.ToXml(),
- psOutXMLObjList = xmlIshObjects
+ psXMLRequestedMetadata = requestedMetadata.ToXml()
});
IshSession.AuthenticationContext = responseRetrieve.psAuthContext;
xmlIshObjects = responseRetrieve.psOutXMLObjList;
@@ -449,8 +438,7 @@ protected override void ProcessRecord()
pasLogicalIds = logicalIdBatch.ToArray(),
peStatusFilter = PublicationOutput25ServiceReference.eISHStatusgroup.ISHNoStatusFilter,
psXMLMetadataFilter = metadataFilterFields.ToXml(),
- psXMLRequestedMetadata = requestedMetadata.ToXml(),
- psOutXMLObjList = xmlIshObjects
+ psXMLRequestedMetadata = requestedMetadata.ToXml()
});
IshSession.AuthenticationContext = responseRetrieve.psAuthContext;
xmlIshObjects = responseRetrieve.psOutXMLObjList;
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolderLocation.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolderLocation.cs
index 868cb49c..1a9be55c 100644
--- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolderLocation.cs
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolderLocation.cs
@@ -128,17 +128,15 @@ protected override void ProcessRecord()
Array.Copy(folderPathElements, 1, folderPathTrisoft, 0, folderPathElements.Length - 1);
WriteDebug($"FolderPath[{folderPath}]");
- string xmlIshFolder = "";
var response = IshSession.Folder25.GetMetaData(new Folder25ServiceReference.GetMetaDataRequest()
{
psAuthContext = IshSession.AuthenticationContext,
peBaseFolder = BaseFolderLabelToEnum(IshSession, baseFolderLabel),
pasFolderPath = folderPathTrisoft,
- psXMLRequestedMetaData = "",
- psOutXMLFolderList = xmlIshFolder
+ psXMLRequestedMetaData = ""
});
IshSession.AuthenticationContext = response.psAuthContext;
- xmlIshFolder = response.psOutXMLFolderList;
+ string xmlIshFolder = response.psOutXMLFolderList;
IshFolders ishFolder = new IshFolders(xmlIshFolder, "ishfolder");
returnFolderIds.Add(ishFolder.Folders[0].IshFolderRef);
}
@@ -147,17 +145,15 @@ protected override void ProcessRecord()
{
// 1d. Retrieve subfolder(s) from the specified root folder using BaseFolder string (enumeration)
var baseFolder = EnumConverter.ToBaseFolder(BaseFolder);
- string xmlIshFolders = "";
var response = IshSession.Folder25.GetMetaData(new Folder25ServiceReference.GetMetaDataRequest()
{
psAuthContext = IshSession.AuthenticationContext,
peBaseFolder = baseFolder,
pasFolderPath = new string[0],
- psXMLRequestedMetaData = "",
- psOutXMLFolderList = xmlIshFolders
+ psXMLRequestedMetaData = ""
});
IshSession.AuthenticationContext = response.psAuthContext;
- xmlIshFolders = response.psOutXMLFolderList;
+ string xmlIshFolders = response.psOutXMLFolderList;
IshFolders retrievedFolders = new IshFolders(xmlIshFolders, "ishfolder");
returnFolderIds.Add(retrievedFolders.Folders[0].IshFolderRef);
}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/TrisoftCmdlet.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/TrisoftCmdlet.cs
index 67b362c7..0e59def3 100644
--- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/TrisoftCmdlet.cs
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/TrisoftCmdlet.cs
@@ -229,13 +229,13 @@ internal virtual Folder25ServiceReference.eBaseFolder BaseFolderLabelToEnum(IshS
// The baseFolder is wrong
// EL: DIRTY WORKAROUND BELOW TO THROW AN EXCEPTION WITH ERROR CODE 102001
// Use faulty folder path with quotes added, so we can throw the expected exception with errorcode=102001
- string xmlIshFolder = "";
- var response = ishSession.Folder25.GetMetaData(new GetMetaDataRequest() {
+ var response = ishSession.Folder25.GetMetaData(new GetMetaDataRequest()
+ {
psAuthContext = ishSession._authenticationContext,
peBaseFolder = eBaseFolder.System,
pasFolderPath= new string[] { "'" + baseFolderLabel + "'" },
- psXMLRequestedMetaData = "",
- psOutXMLFolderList = xmlIshFolder });
+ psXMLRequestedMetaData = ""
+ });
return eBaseFolder.Data;
}
@@ -249,15 +249,15 @@ internal virtual string BaseFolderEnumToLabel(IshSession ishSession, Folder25Ser
{
IshFields requestedMetadata = new IshFields();
requestedMetadata.AddField(new IshRequestedMetadataField("FNAME", Enumerations.Level.None, Enumerations.ValueType.All));
- string xmlIshFolder = "";
// Use empty folder path so we can just get the basefolder name
- var response = ishSession.Folder25.GetMetaData(new GetMetaDataRequest() {
+ var response = ishSession.Folder25.GetMetaData(new GetMetaDataRequest()
+ {
psAuthContext = ishSession._authenticationContext,
peBaseFolder = baseFolder,
pasFolderPath = new string[] { },
- psXMLRequestedMetaData = requestedMetadata.ToXml(),
- psOutXMLFolderList = xmlIshFolder });
- xmlIshFolder = response.psOutXMLFolderList;
+ psXMLRequestedMetaData = requestedMetadata.ToXml()
+ });
+ string xmlIshFolder = response.psOutXMLFolderList;
XmlDocument result = new XmlDocument();
result.LoadXml(xmlIshFolder);
XmlElement xmlIshFolderElement = (XmlElement)result.SelectSingleNode("ishfolder");
@@ -286,5 +286,36 @@ internal List> DevideListInBatches(List list, int batchSize)
return outList;
}
+ ///
+ /// Groups IshObjects list by LogicalIds and divides into multiple lists by batchsize so that objects with the same LogicalIds are never split between batches.
+ ///
+ /// List to devide
+ ///
+ /// Multiple lists grouped by LogicalIds and having maximally batchsize elements, but the same LogicalId is never split between batches
+ internal List>DevideListInBatchesByLogicalId(List list, int batchSize)
+ {
+ var outList = new List>();
+
+ if (list != null)
+ {
+ var ishObjectsGroupedByIshRef = list.GroupBy(ishObject => ishObject.IshRef);
+ var tempList = new List(ishObjectsGroupedByIshRef.First().ToList());
+ foreach (var ishObjectsIshRefGroup in ishObjectsGroupedByIshRef.Skip(1))
+ {
+ if (tempList.Count + ishObjectsIshRefGroup.Count() <= batchSize)
+ {
+ tempList.AddRange(ishObjectsIshRefGroup.ToList());
+ }
+ else
+ {
+ outList.Add(tempList);
+ tempList = ishObjectsIshRefGroup.ToList();
+ }
+ }
+ outList.Add(tempList);
+ }
+
+ return outList;
+ }
}
}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/AddIshUser.Tests.ps1 b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/AddIshUser.Tests.ps1
new file mode 100644
index 00000000..efcb9caf
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/AddIshUser.Tests.ps1
@@ -0,0 +1,180 @@
+BeforeAll {
+ $cmdletName = "Add-IshUser"
+ Write-Host ("`r`nLoading ISHRemote.PesterSetup.ps1 over BeforeAll-block for MyCommand[" + $cmdletName + "]...")
+ . (Join-Path (Split-Path -Parent $PSCommandPath) "\..\..\ISHRemote.PesterSetup.ps1")
+
+ Write-Host ("Running "+$cmdletName+" Test Data and Variables initialization")
+}
+
+Describe "Add-IshUser" -Tags "Create" {
+ Context "Add-IshUser ParameterGroup" {
+ It "Parameter IshSession invalid" {
+ { Add-IshUser -IShSession "INVALIDISHSESSION" -Name "INVALIDUSERNAME" } | Should -Throw
+ }
+ }
+ Context "Add-IshUser ParameterGroup" {
+ It "GetType().Name" {
+ $userName = ($cmdletName + " " + (Get-Date -Format "yyyyMMddHHmmssfff") + " Name")
+ $metadata = Set-IshMetadataField -IshSession $ishSession -Name FISHUSERLANGUAGE -Level None -ValueType Element -Value "VLANGUAGEEN" |
+ Set-IshMetadataField -IshSession $ishSession -Name FUSERGROUP -Level None -ValueType Element -Value "VUSERGROUPDEFAULTDEPARTMENT" |
+ Set-IshMetadataField -IshSession $ishSession -Name PASSWORD -Level None -Value "SomethingSecret"
+ $ishObject = Add-IshUser -IshSession $ishSession -Name $userName -Metadata $metadata
+ $ishObject.GetType().Name | Should -BeExactly "IshUser"
+ $ishObject.Count | Should -Be 1
+ (ConvertTo-Json $ishObject).Length -gt 2 | Should -Be $true
+ }
+ It "Parameter Metadata" {
+ $userName = ($cmdletName + " " + (Get-Date -Format "yyyyMMddHHmmssfff") + " Metadata")
+ $metadata = Set-IshMetadataField -IshSession $ishSession -Name FISHUSERLANGUAGE -Level None -ValueType Element -Value "VLANGUAGEEN" |
+ Set-IshMetadataField -IshSession $ishSession -Name FUSERGROUP -Level None -ValueType Element -Value "VUSERGROUPDEFAULTDEPARTMENT" |
+ Set-IshMetadataField -IshSession $ishSession -Name PASSWORD -Level None -Value "SomethingSecret"
+ $ishObject = Add-IshUser -IshSession $ishSession -Name $userName -Metadata $metadata
+ $ishObject.Count | Should -Be 1
+ $ishObject.IshRef -Like "VUSER*" | Should -Be $true
+ }
+ It "Parameter Metadata return descriptive metadata" {
+ $userName = ($cmdletName + " " + (Get-Date -Format "yyyyMMddHHmmssfff") + " Metadata")
+ $metadata = Set-IshMetadataField -IshSession $ishSession -Name FISHUSERLANGUAGE -Level None -ValueType Element -Value "VLANGUAGEEN" |
+ Set-IshMetadataField -IshSession $ishSession -Name FUSERGROUP -Level None -ValueType Element -Value "VUSERGROUPDEFAULTDEPARTMENT" |
+ Set-IshMetadataField -IshSession $ishSession -Name PASSWORD -Level None -Value "SomethingSecret"
+ $ishObject = Add-IshUser -IshSession $ishSession -Name $userName -Metadata $metadata
+ (Get-IshMetadataField -IshSession $ishSession -IshObject $ishObject -Name FISHUSERLANGUAGE -Level None -ValueType Element).Length -gt 1 | Should -Be $true # added user field by element name
+ (Get-IshMetadataField -IshSession $ishSession -IshObject $ishObject -Name FISHUSERLANGUAGE -Level None -ValueType Value).Length -gt 1 | Should -Be $true # added user field by element name, value added by AddDescriptiveFields
+ (Get-IshMetadataField -IshSession $ishSession -IshObject $ishObject -Name FUSERGROUP -Level None -ValueType Element).Length -gt 1 | Should -Be $true # added user field by element name
+ (Get-IshMetadataField -IshSession $ishSession -IshObject $ishObject -Name FUSERGROUP -Level None -ValueType Value).Length -gt 1 | Should -Be $true # added user field by element name, value added by AddDescriptiveFields
+ (Get-IshMetadataField -IshSession $ishSession -IshObject $ishObject -Name USERNAME -Level None).Length -gt 1 | Should -Be $true
+ $ishSession.DefaultRequestedMetadata | Should -Be "Basic"
+ $ishObject.username.Length -ge 1 | Should -Be $true
+ $ishObject.fishusertype.Length -ge 1 | Should -Be $true
+ $ishObject.fishusertype_none_element.StartsWith('VUSERTYPE') | Should -Be $true
+ }
+ It "Parameter Metadata StrictMetadataPreference=Off with INVALIDFIELDNAME" {
+ $strictMetadataPreference = $ishSession.StrictMetadataPreference
+ $ishSession.StrictMetadataPreference = "Off"
+ $userName = ($cmdletName + " " + (Get-Date -Format "yyyyMMddHHmmssfff") + " Metadata")
+ $metadata = Set-IshMetadataField -IshSession $ishSession -Name "FISHUSERLANGUAGE" -Level None -ValueType Element -Value "VLANGUAGEEN" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FUSERGROUP" -Level None -ValueType Element -Value "VUSERGROUPDEFAULTDEPARTMENT" |
+ Set-IshMetadataField -IshSession $ishSession -Name "PASSWORD" -Level None -Value "SomethingSecret" |
+ Set-IshMetadataField -IshSession $ishSession -Name "CREATED-ON" -Level None -Value "12/03/2017" |
+ Set-IshMetadataField -IshSession $ishSession -Name "MODIFIED-ON" -Level None -Value "12/03/2017" |
+ Set-IshMetadataField -IshSession $ishSession -Name "READ-ACCESS" -Level None -Value "SomethingReadAccess" |
+ Set-IshMetadataField -IshSession $ishSession -Name "OWNER" -Level None -Value "SomethingOwner" |
+ Set-IshMetadataField -IshSession $ishSession -Name "INVALIDFIELDNAME" -Level None -Value "SomethingInvalidFieldName"
+ { Add-IshUser -IshSession $ishSession -Name $userName -Metadata $metadata } | Should -Throw
+ $ishSession.StrictMetadataPreference = $strictMetadataPreference
+ }
+ It "Parameter Metadata StrictMetadataPreference=Continue with many system fields" {
+ $strictMetadataPreference = $ishSession.StrictMetadataPreference
+ $ishSession.StrictMetadataPreference = "Continue"
+ $userName = ($cmdletName + " " + (Get-Date -Format "yyyyMMddHHmmssfff") + " Metadata")
+ $metadata = Set-IshMetadataField -IshSession $ishSession -Name "FISHUSERLANGUAGE" -Level None -ValueType Element -Value "VLANGUAGEEN" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FUSERGROUP" -Level None -ValueType Element -Value "VUSERGROUPDEFAULTDEPARTMENT" |
+ Set-IshMetadataField -IshSession $ishSession -Name "PASSWORD" -Level None -Value "SomethingSecret" |
+ Set-IshMetadataField -IshSession $ishSession -Name "READ-ACCESS" -Level None -Value "SomethingReadAccess" |
+ Set-IshMetadataField -IshSession $ishSession -Name "MODIFY-ACCESS" -Level None -Value "SomethingReadAccess" |
+ Set-IshMetadataField -IshSession $ishSession -Name "DELETE-ACCESS" -Level None -Value "SomethingReadAccess" |
+ Set-IshMetadataField -IshSession $ishSession -Name "OWNER" -Level None -Value "SomethingOwner" |
+ Set-IshMetadataField -IshSession $ishSession -Name "USERNAME" -Level None -Value "SomethingInvalidFieldName" | # RemoveSystemFields always removed upon Create
+ Set-IshMetadataField -IshSession $ishSession -Name "NAME" -Level None -Value "SomethingInvalidFieldName" | # RemoveSystemFields always removed upon Create
+ Set-IshMetadataField -IshSession $ishSession -Name "FISHOBJECTACTIVE" -Level None -Value "SomethingInvalidFieldName" | # RemoveSystemFields always removed upon Create
+ Set-IshMetadataField -IshSession $ishSession -Name "FISHUSERDISABLED" -Level None -Value "SomethingInvalidFieldName" | # RemoveSystemFields always removed upon Create
+ Set-IshMetadataField -IshSession $ishSession -Name "RIGHTS" -Level None -Value "SomethingInvalidFieldName" | # RemoveSystemFields always removed upon Create
+ Set-IshMetadataField -IshSession $ishSession -Name "CREATED-ON" -Level None -Value "12/03/2017" | # RemoveSystemFields always removed upon Create
+ Set-IshMetadataField -IshSession $ishSession -Name "MODIFIED-ON" -Level None -Value "12/03/2017" | # RemoveSystemFields always removed upon Create
+ Set-IshMetadataField -IshSession $ishSession -Name "FISHPASSWORDMODIFIEDON" -Level None -Value "12/03/2017" | # RemoveSystemFields always removed upon Create since Kojak/13.0.0
+ Set-IshMetadataField -IshSession $ishSession -Name "FISHLOCKEDSINCE" -Level None -Value "12/03/2017" | # RemoveSystemFields always removed upon Create since Kojak/13.0.0
+ Set-IshMetadataField -IshSession $ishSession -Name "FISHPASSWORDHISTORY" -Level None -Value "NoHistory" | # RemoveSystemFields always removed upon Create since Kojak/13.0.0
+ Set-IshMetadataField -IshSession $ishSession -Name "FISHFAILEDATTEMPTS" -Level None -Value "10" | # RemoveSystemFields always removed upon Create since Kojak/13.0.0
+ Set-IshMetadataField -IshSession $ishSession -Name "FISHFAVORITES" -Level None -Value "23" # RemoveSystemFields always removed upon Create
+ { Add-IshUser -IshSession $ishSession -Name $userName -Metadata $metadata } | Should -Not -Throw
+ $ishSession.StrictMetadataPreference = $strictMetadataPreference
+ }
+ It "Parameter Metadata StrictMetadataPreference=Off with many system fields" {
+ $strictMetadataPreference = $ishSession.StrictMetadataPreference
+ $ishSession.StrictMetadataPreference = "Off"
+ $userName = ($cmdletName + " " + (Get-Date -Format "yyyyMMddHHmmssfff") + " Metadata")
+ $metadata = Set-IshMetadataField -IshSession $ishSession -Name "FISHUSERLANGUAGE" -Level None -ValueType Element -Value "VLANGUAGEEN" |
+ Set-IshMetadataField -IshSession $ishSession -Name "FUSERGROUP" -Level None -ValueType Element -Value "VUSERGROUPDEFAULTDEPARTMENT" |
+ Set-IshMetadataField -IshSession $ishSession -Name "PASSWORD" -Level None -Value "SomethingSecret" |
+ Set-IshMetadataField -IshSession $ishSession -Name "READ-ACCESS" -Level None -Value "SomethingReadAccess" |
+ Set-IshMetadataField -IshSession $ishSession -Name "MODIFY-ACCESS" -Level None -Value "SomethingReadAccess" |
+ Set-IshMetadataField -IshSession $ishSession -Name "DELETE-ACCESS" -Level None -Value "SomethingReadAccess" |
+ Set-IshMetadataField -IshSession $ishSession -Name "OWNER" -Level None -Value "SomethingOwner" |
+ Set-IshMetadataField -IshSession $ishSession -Name "USERNAME" -Level None -Value "SomethingInvalidFieldName" | # RemoveSystemFields always removed upon Create
+ Set-IshMetadataField -IshSession $ishSession -Name "NAME" -Level None -Value "SomethingInvalidFieldName" | # RemoveSystemFields always removed upon Create
+ Set-IshMetadataField -IshSession $ishSession -Name "FISHOBJECTACTIVE" -Level None -Value "SomethingInvalidFieldName" | # RemoveSystemFields always removed upon Create
+ Set-IshMetadataField -IshSession $ishSession -Name "FISHUSERDISABLED" -Level None -Value "SomethingInvalidFieldName" | # RemoveSystemFields always removed upon Create
+ Set-IshMetadataField -IshSession $ishSession -Name "RIGHTS" -Level None -Value "SomethingInvalidFieldName" | # RemoveSystemFields always removed upon Create
+ Set-IshMetadataField -IshSession $ishSession -Name "CREATED-ON" -Level None -Value "12/03/2017" | # RemoveSystemFields always removed upon Create
+ Set-IshMetadataField -IshSession $ishSession -Name "MODIFIED-ON" -Level None -Value "12/03/2017" | # RemoveSystemFields always removed upon Create
+ Set-IshMetadataField -IshSession $ishSession -Name "FISHFAVORITES" -Level None -Value "23" # RemoveSystemFields always removed upon Create
+ if (([Version]$ishSession.ServerVersion).Major -ge 13)
+ {
+ $metadata = $metadata |
+ Set-IshMetadataField -IshSession $ishSession -Name "FISHPASSWORDMODIFIEDON" -Level None -Value "12/03/2017" | # RemoveSystemFields always removed upon Create since Kojak/13.0.0
+ Set-IshMetadataField -IshSession $ishSession -Name "FISHLOCKEDSINCE" -Level None -Value "12/03/2017" | # RemoveSystemFields always removed upon Create since Kojak/13.0.0
+ Set-IshMetadataField -IshSession $ishSession -Name "FISHPASSWORDHISTORY" -Level None -Value "NoHistory" | # RemoveSystemFields always removed upon Create since Kojak/13.0.0
+ Set-IshMetadataField -IshSession $ishSession -Name "FISHFAILEDATTEMPTS" -Level None -Value "10" # RemoveSystemFields always removed upon Create since Kojak/13.0.0
+ }
+ { Add-IshUser -IshSession $ishSession -Name $userName -Metadata $metadata } | Should -Throw
+ $ishSession.StrictMetadataPreference = $strictMetadataPreference
+ }
+ }
+ Context "Add-IshUser IshObjectsGroup" {
+ BeforeAll {
+ $metadata = Set-IshMetadataField -IshSession $ishSession -Name FISHUSERLANGUAGE -Level None -ValueType Element -Value "VLANGUAGEEN" |
+ Set-IshMetadataField -IshSession $ishSession -Name FUSERGROUP -Level None -ValueType Element -Value "VUSERGROUPDEFAULTDEPARTMENT" |
+ Set-IshMetadataField -IshSession $ishSession -Name PASSWORD -Level None -Value "SomethingSecret"
+ $userName = ($cmdletName + " " + (Get-Date -Format "yyyyMMddHHmmssfff") + " A")
+ $ishObjectA = Add-IshUser -IshSession $ishSession -Name $userName -Metadata $metadata
+ $userName = ($cmdletName + " " + (Get-Date -Format "yyyyMMddHHmmssfff") + " B")
+ $ishObjectB = Add-IshUser -IshSession $ishSession -Name $userName -Metadata $metadata
+ $userName = ($cmdletName + " " + (Get-Date -Format "yyyyMMddHHmmssfff") + " C")
+ $ishObjectC = Add-IshUser -IshSession $ishSession -Name $userName -Metadata $metadata
+ $userName = ($cmdletName + " " + (Get-Date -Format "yyyyMMddHHmmssfff") + " D")
+ $ishObjectD = Add-IshUser -IshSession $ishSession -Name $userName -Metadata $metadata
+ $userName = ($cmdletName + " " + (Get-Date -Format "yyyyMMddHHmmssfff") + " E")
+ $ishObjectE = Add-IshUser -IshSession $ishSession -Name $userName -Metadata $metadata
+ $userName = ($cmdletName + " " + (Get-Date -Format "yyyyMMddHHmmssfff") + " F")
+ $ishObjectF = Add-IshUser -IshSession $ishSession -Name $userName -Metadata $metadata
+ Remove-IshUser -IshSession $ishSession -IshObject @($ishObjectA,$ishObjectB,$ishObjectC,$ishObjectD,$ishObjectE,$ishObjectF)
+ Start-Sleep -Milliseconds 1000 # Avoids uniquesness error which only up to the second " Cannot insert duplicate key row in object 'dbo.CARD' with unique index 'CARD_NAME_I1'. The duplicate key value is (VUSERADD-ISHUSER20161012164716068A12/10/2016 16:47:16)."
+ }
+ It "Parameter IshObject invalid" {
+ { Add-IshUser -IShSession $ishSession -IshObject "INVALIDUSER" } | Should -Throw
+ }
+ It "Parameter IshObject Single with implicit IshSession" {
+ $ishObjectA = $ishObjectA | Set-IshMetadataField -Name PASSWORD -Level None -Value "PasswordNotPutOnThePipeline"
+ $ishObjects = Add-IshUser -IshObject $ishObjectA
+ $ishObjects | Remove-IshUser
+ $ishObjects.Count | Should -Be 1
+ }
+ It "Parameter IshObject Multiple with implicit IshSession" {
+ $ishObjectB = $ishObjectB | Set-IshMetadataField -Name PASSWORD -Level None -Value "PasswordNotPutOnThePipeline"
+ $ishObjectC = $ishObjectC | Set-IshMetadataField -Name PASSWORD -Level None -Value "PasswordNotPutOnThePipeline"
+ $ishObjects = Add-IshUser -IshObject @($ishObjectB,$ishObjectC)
+ $ishObjects | Remove-IshUser
+ $ishObjects.Count | Should -Be 2
+ }
+ It "Pipeline IshObject Single" {
+ $ishObjectD = $ishObjectD | Set-IshMetadataField -IshSession $ishSession -Name PASSWORD -Level None -Value "PasswordNotPutOnThePipeline"
+ $ishObjects = $ishObjectD | Add-IshUser -IshSession $ishSession
+ $ishObjects | Remove-IshUser -IshSession $ishSession
+ $ishObjects.Count | Should -Be 1
+ }
+ It "Pipeline IshObject Multiple" {
+ $ishObjectE = $ishObjectE | Set-IshMetadataField -IshSession $ishSession -Name PASSWORD -Level None -Value "PasswordNotPutOnThePipeline"
+ $ishObjectF = $ishObjectF | Set-IshMetadataField -IshSession $ishSession -Name PASSWORD -Level None -Value "PasswordNotPutOnThePipeline"
+ $ishObjects = @($ishObjectE,$ishObjectF) | Add-IshUser -IshSession $ishSession
+ $ishObjects | Remove-IshUser -IshSession $ishSession
+ $ishObjects.Count | Should -Be 2
+ }
+ }
+}
+
+AfterAll {
+ Write-Host ("Running "+$cmdletName+" Test Data and Variables cleanup")
+ $users = Find-IshUser -IshSession $ishSession -MetadataFilter (Set-IshMetadataFilterField -IshSession $ishSession -Name "USERNAME" -FilterOperator like -Value "$cmdletName%")
+ try { Remove-IshUser -IshSession $ishSession -IshObject $users } catch { }
+}
+
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/AddIshUser.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/AddIshUser.cs
new file mode 100644
index 00000000..54888682
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/AddIshUser.cs
@@ -0,0 +1,189 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Management.Automation;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+using Trisoft.ISHRemote.Exceptions;
+using Trisoft.ISHRemote.HelperClasses;
+
+namespace Trisoft.ISHRemote.Cmdlets.User
+{
+ ///
+ /// The Add-IshUser cmdlet adds the new users that are passed through the pipeline or determined via provided parameters
+ /// The Add-IshUser cmdlet adds the new users that are passed through the pipeline or determined via provided parameters
+ ///
+ ///
+ ///
+ /// $ishSession = New-IshSession -WsBaseUrl "https://example.com/InfoShareWS/" -IshUserName "username" -IshUserPassword "userpassword"
+ /// $metadata = Set-IshMetadataField -IshSession $ishSession -Name FISHUSERLANGUAGE -Level None -ValueType Element -Value "VLANGUAGEEN" |
+ /// Set-IshMetadataField -IshSession $ishSession -Name FUSERGROUP -Level None -ValueType Element -Value "VUSERGROUPDEFAULTDEPARTMENT" |
+ /// Set-IshMetadataField -IshSession $ishSession -Name PASSWORD -Level None -Value "SomethingSecret"
+ /// $ishObject = Add-IshUser -Name "NewUserName" -Metadata $metadata
+ ///
+ /// New-IshSession will submit into SessionState, so it can be reused by this cmdlet. Adding a user
+ ///
+ [Cmdlet(VerbsCommon.Add, "IshUser", SupportsShouldProcess = true)]
+ [OutputType(typeof(IshUser))]
+ public sealed class AddIshUser : UserCmdlet
+ {
+ ///
+ /// The IshSession variable holds the authentication and contract information. This object can be initialized using the New-IshSession cmdlet.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectGroup")]
+ [ValidateNotNullOrEmpty]
+ public IshSession IshSession { get; set; }
+
+ ///
+ /// Array with the users to create. This array can be passed through the pipeline or explicitly passed via the parameter.
+ ///
+ [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = "IshObjectGroup")]
+ [AllowEmptyCollection]
+ public IshObject[] IshObject { get; set; }
+
+ ///
+ /// The name of the new user.
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup"), ValidateNotNullOrEmpty]
+ public string Name { get; set; }
+
+ ///
+ /// The metadata to set for the new user.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup"), ValidateNotNull]
+ public IshField[] Metadata { get; set; }
+
+ protected override void BeginProcessing()
+ {
+ if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); }
+ if (IshSession == null) { throw new ArgumentException(ISHRemoteSessionStateIshSessionException); }
+ WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession}");
+ base.BeginProcessing();
+ }
+
+ protected override void ProcessRecord()
+ {
+
+ try
+ {
+ List returnedObjects = new List();
+
+ if (IshObject != null && IshObject.Length == 0)
+ {
+ // Do nothing
+ WriteVerbose("IshObject is empty, so nothing to create");
+ WriteVerbose("IshObject is empty, so nothing to retrieve");
+ }
+ else
+ {
+ List returnUsers = new List();
+ IshFields returnFields;
+
+ // 1. Doing the update
+ WriteDebug("Adding");
+
+ if (IshObject != null)
+ {
+ // 1b. Using IshObject[] pipeline or specificly set
+ int current = 0;
+ foreach (IshObject ishObject in IshObject)
+ {
+ // The USERNAME field needs to be present, all other mandatory fields need to be present as well
+ IshMetadataField userNameValueField =
+ (IshMetadataField)
+ ishObject.IshFields.Retrieve("USERNAME", Enumerations.Level.None,
+ Enumerations.ValueType.Value)[0];
+ string userName = userNameValueField.Value;
+ WriteDebug($"UserName[{userName}] Metadata.length[{ishObject.IshFields.ToXml().Length}] {++current}/{IshObject.Length}");
+ var metadata = IshSession.IshTypeFieldSetup.ToIshMetadataFields(ISHType, ishObject.IshFields, Enumerations.ActionMode.Create);
+ if (ShouldProcess(userName))
+ {
+ var response = IshSession.User25.Create(new User25ServiceReference.CreateRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psUserName = userName,
+ psXMLMetaData = metadata.ToXml()
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ string userId = response.psOutUserId;
+ returnUsers.Add(userId);
+ }
+ }
+ returnFields = (IshObject[0] == null)
+ ? new IshFields()
+ : IshObject[0].IshFields;
+ }
+ else
+ {
+ // 1a. Using Id and Metadata
+ var metadata = IshSession.IshTypeFieldSetup.ToIshMetadataFields(ISHType, new IshFields(Metadata), Enumerations.ActionMode.Create);
+ WriteVerbose("Name[" + Name + "] metadata.length[" + metadata.ToXml().Length + "]");
+ if (ShouldProcess(Name))
+ {
+ var response = IshSession.User25.Create(new User25ServiceReference.CreateRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psUserName = Name,
+ psXMLMetaData = metadata.ToXml()
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ string userId = response.psOutUserId;
+ returnUsers.Add(userId);
+ }
+ returnFields = metadata;
+ }
+
+ // 2. Retrieve the updated material from the database and write it out
+ WriteDebug("Retrieving");
+
+ // 2a. Prepare list of usergroupids and requestedmetadata
+ // 2b. Retrieve the material
+ // Remove Password field explicitly, as we are not allowe to read it
+ returnFields.RemoveField(FieldElements.Password, Enumerations.Level.None, Enumerations.ValueType.All);
+ // Add the required fields (needed for pipe operations)
+ IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, returnFields, Enumerations.ActionMode.Read);
+ var responseRetrieve = IshSession.User25.RetrieveMetaData(new User25ServiceReference.RetrieveMetaDataRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ pasUserIds = returnUsers.ToArray(),
+ peActivityFilter = User25ServiceReference.eActivityFilter.None,
+ psXMLMetadataFilter = "",
+ psXMLRequestedMetaData = requestedMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = responseRetrieve.psAuthContext;
+ string xmlIshObjects = responseRetrieve.psOutXMLObjList;
+ returnedObjects.AddRange(new IshObjects(ISHType, xmlIshObjects).Objects);
+ }
+
+ // 3. Write it
+ WriteVerbose("returned object count[" + returnedObjects.Count + "]");
+ WriteObject(IshSession, ISHType, returnedObjects.ConvertAll(x => (IshBaseObject)x), true);
+ }
+ catch (TrisoftAutomationException trisoftAutomationException)
+ {
+ ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
+ }
+ catch (Exception exception)
+ {
+ ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
+ }
+ }
+ }
+}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/FindIshUser.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/FindIshUser.cs
new file mode 100644
index 00000000..36113e1f
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/FindIshUser.cs
@@ -0,0 +1,121 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Linq;
+using System.Management.Automation;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+using Trisoft.ISHRemote.Exceptions;
+using Trisoft.ISHRemote.HelperClasses;
+
+namespace Trisoft.ISHRemote.Cmdlets.User
+{
+ ///
+ /// The Find-IshUser cmdlet finds users using ActivityFilter and MetadataFilter that are provided
+ /// The Find-IshUser cmdlet finds users using ActivityFilter and MetadataFilter that are provided
+ ///
+ ///
+ ///
+ /// New-IshSession -WsBaseUrl "https://example.com/InfoShareWS/" -PSCredential Admin
+ /// (Find-IshUser).count
+ ///
+ /// New-IshSession will submit into SessionState, so it can be reused by this cmdlet. Counting all users.
+ ///
+ [Cmdlet(VerbsCommon.Find, "IshUser", SupportsShouldProcess = false)]
+ [OutputType(typeof(IshUser))]
+ public sealed class FindIshUser : UserCmdlet
+ {
+ ///
+ /// The IshSession variable holds the authentication and contract information. This object can be initialized using the New-IshSession cmdlet.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false), ValidateNotNullOrEmpty]
+ public IshSession IshSession { get; set; }
+
+ /// ActivityFilter
+ ///
+ /// The activity filter to limit the amount of objects returned. Default is no filtering.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false), ValidateNotNullOrEmpty]
+ public Enumerations.ActivityFilter ActivityFilter
+ {
+ get { return _activityFilter; }
+ set { _activityFilter = value; }
+ }
+
+ ///
+ /// The metadata filter with the filter fields to limit the amount of objects returned. Default is no filtering.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false), ValidateNotNull]
+ public IshField[] MetadataFilter { get; set; }
+
+ ///
+ /// The metadata fields to retrieve
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false), ValidateNotNull]
+ public IshField[] RequestedMetadata { get; set; }
+
+
+
+ #region Private fields
+ ///
+ /// Private field to store the IshType and provide a default for non-mandatory parameters
+ ///
+ private Enumerations.ActivityFilter _activityFilter = Enumerations.ActivityFilter.None;
+ #endregion
+
+ protected override void BeginProcessing()
+ {
+ if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); }
+ if (IshSession == null) { throw new ArgumentException(ISHRemoteSessionStateIshSessionException); }
+ WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession}");
+ base.BeginProcessing();
+ }
+
+ protected override void ProcessRecord()
+ {
+
+ try
+ {
+ IshFields metadataFilter = new IshFields(MetadataFilter);
+ IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, new IshFields(RequestedMetadata), Enumerations.ActionMode.Find);
+ var activityFilter = EnumConverter.ToActivityFilter(ActivityFilter);
+ WriteDebug($"Finding ActivityFilter[{activityFilter}] MetadataFilter.length[{metadataFilter.ToXml().Length}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}]");
+ var response = IshSession.User25.Find(new User25ServiceReference.FindRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ peActivityFilter = activityFilter,
+ psXMLMetadataFilter = metadataFilter.ToXml(),
+ psXMLRequestedMetaData = requestedMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ string xmlIshObjects = response.psOutXMLObjList;
+
+ var returnedObjects = new IshObjects(ISHType, xmlIshObjects).ObjectList;
+ WriteVerbose("returned object count[" + returnedObjects.Count + "]");
+ WriteObject(IshSession, ISHType, returnedObjects.ConvertAll(x => (IshBaseObject)x), true);
+ }
+ catch (TrisoftAutomationException trisoftAutomationException)
+ {
+ ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
+ }
+ catch (Exception exception)
+ {
+ ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
+ }
+ }
+ }
+}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/GetIshUser.Tests.ps1 b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/GetIshUser.Tests.ps1
new file mode 100644
index 00000000..8f28ca88
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/GetIshUser.Tests.ps1
@@ -0,0 +1,76 @@
+BeforeAll {
+ $cmdletName = "Get-IshUser"
+ Write-Host ("`r`nLoading ISHRemote.PesterSetup.ps1 over BeforeAll-block for MyCommand[" + $cmdletName + "]...")
+ . (Join-Path (Split-Path -Parent $PSCommandPath) "\..\..\ISHRemote.PesterSetup.ps1")
+
+ Write-Host ("Running "+$cmdletName+" Test Data and Variables initialization")
+}
+
+Describe "Get-IshUser" -Tags "Create" {
+ Context "Get-IshUser ParameterGroup" {
+ It "Parameter IshSession invalid" {
+ { Get-IshUser -IShSession "INVALIDISHSESSION" -Name "INVALIDUSERNAME" } | Should -Throw
+ }
+ }
+ Context "Get-IshUser ParameterGroup" {
+ BeforeAll {
+ $userName = ($cmdletName + " " + (Get-Date -Format "yyyyMMddHHmmssfff") + " Name")
+ $metadata = Set-IshMetadataField -IshSession $ishSession -Name FISHUSERLANGUAGE -Level None -ValueType Element -Value "VLANGUAGEEN" |
+ Set-IshMetadataField -IshSession $ishSession -Name FUSERGROUP -Level None -ValueType Element -Value "VUSERGROUPDEFAULTDEPARTMENT" |
+ Set-IshMetadataField -IshSession $ishSession -Name PASSWORD -Level None -Value "SomethingSecret"
+ $ishObject = Add-IshUser -IshSession $ishSession -Name $userName -Metadata $metadata
+ }
+ It "Parameter IshSession Implicit" {
+ $ishObject = Get-IshUser -Id $ishObject.IshRef
+ $ishObject.GetType().Name | Should -BeExactly "IshUser"
+ $ishObject.Count | Should -Be 1
+ }
+ It "Parameter Metadata StrictMetadataPreference=Off with PASSWORD" {
+ $strictMetadataPreference = $ishSession.StrictMetadataPreference
+ $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Name PASSWORD -Level None
+ $ishSession.StrictMetadataPreference = "Off"
+ { Get-IshUser -IshSession $ishSession -Id $ishObject.IshRef -RequestedMetadata $requestedMetadata } | Should -Throw
+ $ishSession.StrictMetadataPreference = "Continue"
+ { Get-IshUser -IshSession $ishSession -Id $ishObject.IshRef -RequestedMetadata $requestedMetadata } | Should -Not -Throw
+ $ishSession.StrictMetadataPreference = $strictMetadataPreference
+ }
+ It "Parameter Metadata StrictMetadataPreference=Continue with PASSWORD" {
+ $strictMetadataPreference = $ishSession.StrictMetadataPreference
+ $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Name PASSWORD -Level None
+ $ishSession.StrictMetadataPreference = "Continue"
+ { Get-IshUser -IshSession $ishSession -Id $ishObject.IshRef -RequestedMetadata $requestedMetadata } | Should -Not -Throw
+ $ishSession.StrictMetadataPreference = $strictMetadataPreference
+ }
+ It "Parameter IshSession.DefaultRequestedMetadata=Descriptive on My-Metadata" {
+ $oldDefaultRequestedMetadata = $ishSession.DefaultRequestedMetadata
+ $ishSession.DefaultRequestedMetadata = "Descriptive"
+ $ishObject = Get-IshUser -IshSession $ishSession
+ $ishSession.DefaultRequestedMetadata = $oldDefaultRequestedMetadata
+ $ishObject.GetType().Name | Should -BeExactly "IshUser"
+ $ishObject.IshField.Length | Should -Be 10
+ }
+ It "Parameter IshSession.DefaultRequestedMetadata=Basic on My-Metadata" {
+ $oldDefaultRequestedMetadata = $ishSession.DefaultRequestedMetadata
+ $ishSession.DefaultRequestedMetadata = "Basic"
+ $ishObject = Get-IshUser -IshSession $ishSession
+ $ishSession.DefaultRequestedMetadata = $oldDefaultRequestedMetadata
+ $ishObject.GetType().Name | Should -BeExactly "IshUser"
+ $ishObject.IshField.Length | Should -Be 25
+ }
+ It "Parameter IshSession.DefaultRequestedMetadata=All on My-Metadata" {
+ $oldDefaultRequestedMetadata = $ishSession.DefaultRequestedMetadata
+ $ishSession.DefaultRequestedMetadata = "All"
+ $ishObject = Get-IshUser -IshSession $ishSession
+ $ishSession.DefaultRequestedMetadata = $oldDefaultRequestedMetadata
+ $ishObject.GetType().Name | Should -BeExactly "IshUser"
+ $ishObject.IshField.Length | Should -Be 29
+ }
+ }
+}
+
+AfterAll {
+ Write-Host ("Running "+$cmdletName+" Test Data and Variables cleanup")
+ $users = Find-IshUser -IshSession $ishSession -MetadataFilter (Set-IshMetadataFilterField -IshSession $ishSession -Name "USERNAME" -FilterOperator like -Value "$cmdletName%")
+ try { Remove-IshUser -IshSession $ishSession -IshObject $users } catch { }
+}
+
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/GetIshUser.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/GetIshUser.cs
new file mode 100644
index 00000000..54307702
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/GetIshUser.cs
@@ -0,0 +1,174 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Management.Automation;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+using Trisoft.ISHRemote.Exceptions;
+using Trisoft.ISHRemote.HelperClasses;
+
+namespace Trisoft.ISHRemote.Cmdlets.User
+{
+ ///
+ /// The Get-IshUser cmdlet retrieves the metadata of users that are passed through the pipeline or determined via provided parameters
+ /// The Get-IshUser cmdlet retrieves the metadata of users that are passed through the pipeline or determined via provided parameters
+ ///
+ ///
+ ///
+ /// New-IshSession -WsBaseUrl "https://example.com/InfoShareWS/" -PSCredential Admin
+ /// Get-IshUser
+ ///
+ /// New-IshSession will submit into SessionState, so it can be reused by this cmdlet. Gets the current user (Admin) Basic metadata.
+ ///
+ [Cmdlet(VerbsCommon.Get, "IshUser", SupportsShouldProcess = false)]
+ [OutputType(typeof(IshUser))]
+ public sealed class GetIshUser : UserCmdlet
+ {
+ ///
+ /// The IshSession variable holds the authentication and contract information. This object can be initialized using the New-IshSession cmdlet.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "MyMetadataGroup")]
+ [ValidateNotNullOrEmpty]
+ public IshSession IshSession { get; set; }
+
+ ///
+ /// The activity filter to limit the amount of objects returned. Default is no filtering.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [ValidateNotNullOrEmpty]
+ public Enumerations.ActivityFilter ActivityFilter
+ {
+ get { return _activityFilter; }
+ set { _activityFilter = value; }
+ }
+
+ ///
+ /// The user identifiers for which to retrieve the metadata
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [ValidateNotNullOrEmpty]
+ public string[] Id { get; set; }
+
+ ///
+ /// The metadata filter with the filter fields to limit the amount of objects returned. Default is no filtering.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [ValidateNotNull]
+ public IshField[] MetadataFilter { get; set; }
+
+ ///
+ /// The metadata fields to retrieve
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "MyMetadataGroup")]
+ [ValidateNotNull]
+ public IshField[] RequestedMetadata { get; set; }
+
+ ///
+ /// Users for which to retrieve the metadata. This array can be passed through the pipeline or explicitly passed via the parameter.
+ ///
+ [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = "IshObjectsGroup")]
+ [AllowEmptyCollection]
+ public IshObject[] IshObject { get; set; }
+
+
+ #region Private fields
+ ///
+ /// Private field to store the IshType and provide a default for non-mandatory parameters
+ ///
+ private Enumerations.ActivityFilter _activityFilter = Enumerations.ActivityFilter.None;
+ #endregion
+
+ protected override void BeginProcessing()
+ {
+ if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); }
+ if (IshSession == null) { throw new ArgumentException(ISHRemoteSessionStateIshSessionException); }
+ WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession}");
+ base.BeginProcessing();
+ }
+
+ protected override void ProcessRecord()
+ {
+
+ try
+ {
+ IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, new IshFields(RequestedMetadata), Enumerations.ActionMode.Read);
+ List returnedObjects = new List();
+
+ if (IshObject != null && IshObject.Length == 0)
+ {
+ // Do nothing
+ WriteVerbose("IshObject is empty, so nothing to retrieve");
+ }
+ else
+ {
+ string xmlIshObjects = "";
+ if (Id == null && IshObject == null)
+ {
+ // No Id, nor pipeline input, get My metadata
+ WriteDebug("Retrieving my metadata");
+ var response = IshSession.User25.GetMyMetaData(new User25ServiceReference.GetMyMetaDataRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psXMLRequestedMetaData = requestedMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ xmlIshObjects = response.psOutXMLObjList;
+ }
+ else
+ {
+ User25ServiceReference.eActivityFilter activityFilter =
+ EnumConverter.ToActivityFilter(ActivityFilter);
+ IshFields metadataFilter = new IshFields(MetadataFilter);
+
+ var ids = (IshObject != null) ? new IshObjects(IshObject).Ids : Id;
+ WriteDebug($"Retrieving for Id.length[{ids.Length}] ActivityFilter[{activityFilter}] MetadataFilter.length[{metadataFilter.ToXml().Length}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}]");
+ var response = IshSession.User25.RetrieveMetaData(new User25ServiceReference.RetrieveMetaDataRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ pasUserIds = ids,
+ peActivityFilter = activityFilter,
+ psXMLMetadataFilter = metadataFilter.ToXml(),
+ psXMLRequestedMetaData = requestedMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ xmlIshObjects = response.psOutXMLObjList;
+ }
+ returnedObjects.AddRange(new IshObjects(ISHType, xmlIshObjects).Objects);
+ }
+
+ WriteVerbose("returned object count[" + returnedObjects.Count + "]");
+ WriteObject(IshSession, ISHType, returnedObjects.ConvertAll(x => (IshBaseObject)x), true);
+ }
+ catch (TrisoftAutomationException trisoftAutomationException)
+ {
+ ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
+ }
+ catch (Exception exception)
+ {
+ ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
+ }
+ }
+ }
+}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/RemoveIshUser.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/RemoveIshUser.cs
new file mode 100644
index 00000000..e964130b
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/RemoveIshUser.cs
@@ -0,0 +1,122 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Management.Automation;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+using Trisoft.ISHRemote.Exceptions;
+
+namespace Trisoft.ISHRemote.Cmdlets.User
+{
+ ///
+ /// The Remove-IshUser cmdlet removes the users that are passed through the pipeline or determined via provided parameters
+ /// The Remove-IshUser cmdlet removes the users that are passed through the pipeline or determined via provided parameters
+ ///
+ ///
+ ///
+ /// New-IshSession -WsBaseUrl "https://example.com/InfoShareWS/" -PSCredential Admin
+ /// Get-IshUser | Remove-IshUser
+ ///
+ /// New-IshSession will submit into SessionState, so it can be reused by this cmdlet. Gets the current user (Admin) and tries to remove it, which will fail if the user is linked to objects.
+ ///
+ [Cmdlet(VerbsCommon.Remove, "IshUser", SupportsShouldProcess = true)]
+ public sealed class RemoveIshUser : UserCmdlet
+ {
+ ///
+ /// The IshSession variable holds the authentication and contract information. This object can be initialized using the New-IshSession cmdlet.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectGroup")]
+ [ValidateNotNullOrEmpty]
+ public IshSession IshSession { get; set; }
+
+ ///
+ /// The identifier of the user to remove
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup"), ValidateNotNullOrEmpty]
+ public string Id { get; set; }
+
+ ///
+ /// Array with the users to remove. This array can be passed through the pipeline or explicitly passed via the parameter.
+ ///
+ [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = "IshObjectGroup")]
+ [AllowEmptyCollection]
+ public IshObject[] IshObject { get; set; }
+
+ protected override void BeginProcessing()
+ {
+ if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); }
+ if (IshSession == null) { throw new ArgumentException(ISHRemoteSessionStateIshSessionException); }
+ WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession}");
+ base.BeginProcessing();
+ }
+
+ protected override void ProcessRecord()
+ {
+
+ try
+ {
+ WriteDebug("Deleting");
+
+ if (IshObject!=null)
+ {
+ // 1b. Using IshObject[] pipeline or specificly set
+ int current = 0;
+ foreach (IshObject ishObject in IshObject)
+ {
+ WriteDebug($"Id[{ishObject.IshRef}] {++current}/{IshObject.Length}");
+ if (ShouldProcess(ishObject.IshRef))
+ {
+ var response = IshSession.User25.Delete(new User25ServiceReference.DeleteRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psUserId = ishObject.IshRef
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ }
+ }
+ }
+ else
+ {
+ // 1a. Using Ids
+ WriteVerbose("Id[" + Id + "]");
+ if (ShouldProcess(Id))
+ {
+ var response = IshSession.User25.Delete(new User25ServiceReference.DeleteRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psUserId = Id
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ }
+ }
+
+ // Nothing to retrieve because we just Deleted it, so no output
+ WriteVerbose("returned object count[0]");
+ }
+ catch (TrisoftAutomationException trisoftAutomationException)
+ {
+ ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
+ }
+ catch (Exception exception)
+ {
+ ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
+ }
+ }
+ }
+}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/SetIshUser.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/SetIshUser.cs
new file mode 100644
index 00000000..5fbce226
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/SetIshUser.cs
@@ -0,0 +1,180 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Management.Automation;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+using Trisoft.ISHRemote.Exceptions;
+using Trisoft.ISHRemote.HelperClasses;
+
+namespace Trisoft.ISHRemote.Cmdlets.User
+{
+ ///
+ /// The Set-IshUser cmdlet updates the users that are passed through the pipeline or determined via provided parameters.
+ /// The Set-IshUser cmdlet updates the users that are passed through the pipeline or determined via provided parameters.
+ ///
+ ///
+ ///
+ /// New-IshSession -WsBaseUrl "https://example.com/InfoShareWS/" -PSCredential Admin
+ /// Get-IshUser |
+ /// Set-IshMetadataField -Name FISHEMAIL -Value "ishremote@example.com" |
+ /// Set-IshUser
+ ///
+ /// New-IshSession will submit into SessionState, so it can be reused by this cmdlet. Gets the current user (Admin) adapts the client-side memory structure to hold a new email address and sets in the repository.
+ ///
+ [Cmdlet(VerbsCommon.Set, "IshUser", SupportsShouldProcess = true)]
+ [OutputType(typeof(IshUser))]
+ public sealed class SetIshUser : UserCmdlet
+ {
+ ///
+ /// The IshSession variable holds the authentication and contract information. This object can be initialized using the New-IshSession cmdlet.
+ ///
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")]
+ [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")]
+ [ValidateNotNullOrEmpty]
+ public IshSession IshSession { get; set; }
+
+ ///
+ /// The identifier of the user to update
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup"), ValidateNotNullOrEmpty]
+ public string Id { get; set; }
+
+ ///
+ /// The metadata to set for the user
+ ///
+ [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup"), ValidateNotNull]
+ public IshField[] Metadata { get; set; }
+
+ ///
+ /// Users for which to update the metadata. This array can be passed through the pipeline or explicitly passed via the parameter.
+ ///
+ [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = "IshObjectsGroup")]
+ [AllowEmptyCollection]
+ public IshObject[] IshObject { get; set; }
+
+ protected override void BeginProcessing()
+ {
+ if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); }
+ if (IshSession == null) { throw new ArgumentException(ISHRemoteSessionStateIshSessionException); }
+ WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession}");
+ base.BeginProcessing();
+ }
+
+ protected override void ProcessRecord()
+ {
+
+ try
+ {
+ List returnedObjects = new List();
+
+ if (IshObject != null && IshObject.Length == 0)
+ {
+ // Do nothing
+ WriteVerbose("IshObject is empty, so nothing to update");
+ WriteVerbose("IshObject is empty, so nothing to retrieve");
+ }
+ else
+ {
+ List returnUsers = new List();
+ IshFields returnFields;
+
+ // 1. Doing the update
+ WriteDebug("Updating");
+ if (IshObject != null)
+ {
+ // 1b. Using IshObject[] pipeline or specificly set
+ int current = 0;
+ foreach (IshObject ishObject in IshObject)
+ {
+ WriteDebug($"Id[{ishObject.IshRef}] Metadata.length[{ishObject.IshFields.ToXml().Length}] {++current}/{IshObject.Length}");
+ var metadata = IshSession.IshTypeFieldSetup.ToIshMetadataFields(ISHType, ishObject.IshFields, Enumerations.ActionMode.Update);
+ if (ShouldProcess(ishObject.IshRef))
+ {
+ var response = IshSession.User25.Update(new User25ServiceReference.UpdateRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psUserId = ishObject.IshRef,
+ psXMLMetaData = metadata.ToXml()
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ }
+ returnUsers.Add(ishObject.IshRef);
+ }
+ returnFields = (IshObject[0] == null)
+ ? new IshFields()
+ : IshObject[0].IshFields;
+ }
+ else
+ {
+ // 1a. Using Id and Metadata
+ var metadata = IshSession.IshTypeFieldSetup.ToIshMetadataFields(ISHType, new IshFields(Metadata), Enumerations.ActionMode.Update);
+ WriteDebug($"Id[{Id}] metadata.length[{metadata.ToXml().Length}]");
+ if (ShouldProcess(Id))
+ {
+ var response = IshSession.User25.Update(new User25ServiceReference.UpdateRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ psUserId = Id,
+ psXMLMetaData = metadata.ToXml()
+ });
+ IshSession.AuthenticationContext = response.psAuthContext;
+ }
+ returnUsers.Add(Id);
+ returnFields = metadata;
+ }
+
+ // 2. Retrieve the updated material from the database and write it out
+ WriteDebug("Retrieving");
+
+ // 2a. Prepare list of usergroupids and requestedmetadata
+ // 2b. Retrieve the material
+ // Remove Password field explicitly, as we are not allowed to read it
+ returnFields.RemoveField(FieldElements.Password, Enumerations.Level.None, Enumerations.ValueType.All);
+ // Add the required fields (needed for pipe operations)
+ IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, returnFields, Enumerations.ActionMode.Read);
+ var responseRetrieve = IshSession.User25.RetrieveMetaData(new User25ServiceReference.RetrieveMetaDataRequest()
+ {
+ psAuthContext = IshSession.AuthenticationContext,
+ pasUserIds = returnUsers.ToArray(),
+ peActivityFilter = User25ServiceReference.eActivityFilter.None,
+ psXMLMetadataFilter = "",
+ psXMLRequestedMetaData = requestedMetadata.ToXml()
+ });
+ IshSession.AuthenticationContext = responseRetrieve.psAuthContext;
+ string xmlIshObjects = responseRetrieve.psOutXMLObjList;
+
+ returnedObjects.AddRange(new IshObjects(ISHType, xmlIshObjects).Objects);
+ }
+
+ // 3. Write it
+ WriteVerbose("returned object count[" + returnedObjects.Count + "]");
+ WriteObject(IshSession, ISHType, returnedObjects.ConvertAll(x => (IshBaseObject)x), true);
+ }
+ catch (TrisoftAutomationException trisoftAutomationException)
+ {
+ ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
+ }
+ catch (Exception exception)
+ {
+ ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
+ }
+ }
+ }
+}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/UserCmdlet.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/UserCmdlet.cs
new file mode 100644
index 00000000..0d6d105a
--- /dev/null
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/User/UserCmdlet.cs
@@ -0,0 +1,32 @@
+/*
+* Copyright (c) 2014 All Rights Reserved by the SDL Group.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Management.Automation;
+using Trisoft.ISHRemote.Objects;
+using Trisoft.ISHRemote.Objects.Public;
+using Trisoft.ISHRemote.Exceptions;
+
+namespace Trisoft.ISHRemote.Cmdlets.User
+{
+ public abstract class UserCmdlet : TrisoftCmdlet
+ {
+ public Enumerations.ISHType[] ISHType
+ {
+ get { return new Enumerations.ISHType[] { Enumerations.ISHType.ISHUser }; }
+ }
+ }
+}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Objects/FieldElements.cs b/Source/ISHRemote/Trisoft.ISHRemote/Objects/FieldElements.cs
index 863b825c..9e51298c 100644
--- a/Source/ISHRemote/Trisoft.ISHRemote/Objects/FieldElements.cs
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Objects/FieldElements.cs
@@ -974,5 +974,13 @@ internal class FieldElements
public const string AnnotationSnapshotId = "FISHANNOTSNAPSHOTID";
#endregion
+
+ #region BackgroundTask Fields
+
+ ///
+ /// The ProgressId of the BackgroundTask.
+ ///
+ public const string BackgroundTaskProgressId = "PROGRESSID";
+ #endregion
}
}
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Objects/Public/IshDocumentObj.cs b/Source/ISHRemote/Trisoft.ISHRemote/Objects/Public/IshDocumentObj.cs
index 4076767c..0bbd648d 100644
--- a/Source/ISHRemote/Trisoft.ISHRemote/Objects/Public/IshDocumentObj.cs
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Objects/Public/IshDocumentObj.cs
@@ -24,7 +24,7 @@
namespace Trisoft.ISHRemote.Objects.Public
{
///
- /// A container to allow *.Format.ps1xml do magic, in essence the same as the pipeline object IshObject
+ /// A container to allow *.Format.ps1xml do magic, in essence the same as the pipeline object IshObject
///
public class IshDocumentObj : IshObject
{
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Objects/Public/IshSession.cs b/Source/ISHRemote/Trisoft.ISHRemote/Objects/Public/IshSession.cs
index 13a88f02..373624a8 100644
--- a/Source/ISHRemote/Trisoft.ISHRemote/Objects/Public/IshSession.cs
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Objects/Public/IshSession.cs
@@ -225,8 +225,7 @@ internal IshTypeFieldSetup IshTypeFieldSetup
var response = Settings25.GetMetaData(new Settings25ServiceReference.GetMetaDataRequest()
{
psAuthContext = _authenticationContext,
- psXMLRequestedMetaData = metadata.ToXml(),
- psOutXMLObjList = xmlIshObjects
+ psXMLRequestedMetaData = metadata.ToXml()
});
_authenticationContext = response.psAuthContext;
xmlIshObjects = response.psOutXMLObjList;
@@ -282,13 +281,13 @@ public string UserName
{
//TODO [Could] IshSession could initialize the current IshUser completely based on all available user metadata and store it on the IshSession
string requestedMetadata = "";
- string xmlIshObjects = "";
- var response = User25.GetMyMetaData(new GetMyMetaDataRequest() {
+ var response = User25.GetMyMetaData(new GetMyMetaDataRequest()
+ {
psAuthContext = _authenticationContext,
- psXMLRequestedMetaData= requestedMetadata,
- psOutXMLObjList = xmlIshObjects });
+ psXMLRequestedMetaData= requestedMetadata
+ });
_authenticationContext = response.psAuthContext;
- xmlIshObjects = response.psOutXMLObjList;
+ string xmlIshObjects = response.psOutXMLObjList;
Enumerations.ISHType[] ISHType = { Enumerations.ISHType.ISHUser };
IshObjects ishObjects = new IshObjects(ISHType, xmlIshObjects);
_userName = ishObjects.Objects[0].IshFields.GetFieldValue("USERNAME", Enumerations.Level.None, Enumerations.ValueType.Value);
@@ -308,13 +307,13 @@ public string UserLanguage
{
//TODO [Could] IshSession could initialize the current IshUser completely based on all available user metadata and store it on the IshSession
string requestedMetadata = "";
- string xmlIshObjects = "";
- var response = User25.GetMyMetaData(new GetMyMetaDataRequest() {
+ var response = User25.GetMyMetaData(new GetMyMetaDataRequest()
+ {
psAuthContext = _authenticationContext,
- psXMLRequestedMetaData = requestedMetadata,
- psOutXMLObjList = xmlIshObjects });
+ psXMLRequestedMetaData = requestedMetadata
+ });
_authenticationContext = response.psAuthContext;
- xmlIshObjects = response.psOutXMLObjList;
+ string xmlIshObjects = response.psOutXMLObjList;
Enumerations.ISHType[] ISHType = { Enumerations.ISHType.ISHUser };
IshObjects ishObjects = new IshObjects(ISHType, xmlIshObjects);
_userLanguage = ishObjects.Objects[0].IshFields.GetFieldValue("FISHUSERLANGUAGE", Enumerations.Level.None, Enumerations.ValueType.Value);
diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Objects/Public/IshUser.cs b/Source/ISHRemote/Trisoft.ISHRemote/Objects/Public/IshUser.cs
index 01e9b4db..33489ff7 100644
--- a/Source/ISHRemote/Trisoft.ISHRemote/Objects/Public/IshUser.cs
+++ b/Source/ISHRemote/Trisoft.ISHRemote/Objects/Public/IshUser.cs
@@ -24,7 +24,7 @@
namespace Trisoft.ISHRemote.Objects.Public
{
///
- /// A container to allow *.Format.ps1xml do magic, in essence the same as the pipeline object IshObject
+ /// A container to allow *.Format.ps1xml do magic, in essence the same as the pipeline object IshObject
///
public class IshUser : IshObject
{