-
Notifications
You must be signed in to change notification settings - Fork 6
/
sample23-get-data-source-errors.ps1
182 lines (158 loc) · 6.98 KB
/
sample23-get-data-source-errors.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#import
. "$global:rootDir\Helpers\EndpointsClass.ps1"
. "$global:rootDir\Helpers\WriteInformationClass.ps1"
$workspaceId = 1000000
$loadFile01Path = "\\files\T001\Files\SampleDataSources\load_file_05.dat"
$loadFile02Path = "\\files\T001\Files\SampleDataSources\notExistingFile.dat"
$importId = New-Guid
$source01Id = New-Guid
$source02Id = New-Guid
$global:Endpoints = [Endpoints]::new($workspaceId)
$global:WriteInformation = [WriteInformation]::new()
Context "Sample23 Get Data Source errors" {
Describe "Create job" {
$uri = $global:Endpoints.importJobCreateUri($importId)
$body = @{
applicationName = "Import-service-sample-app"
correlationID = "Sample-job-00023"
} | ConvertTo-Json -Depth 10
$response = $global:WebRequest.callPost($uri, $body)
$global:WebRequest.checkIfSuccess($response)
Write-Information -MessageData "Job $importId created" -InformationAction Continue
}
Describe "Create document configuration" {
$uri = $global:Endpoints.documentConfigurationUri($importId)
$jobConfigurationBody = '{
"importSettings" :
{
"Overlay":null,
"Native":{
"FilePathColumnIndex": "22",
"FileNameColumnIndex": "13"
},
"Image":null,
"Fields": {
"FieldMappings": [
{
"ColumnIndex": 0,
"Field": "Control Number",
"ContainsID": false,
"ContainsFilePath": false
},
{
"ColumnIndex": 1,
"Field": "Custodian - Single Choice",
"ContainsID": false,
"ContainsFilePath": false
},
{
"ColumnIndex": 11,
"Field": "Email To",
"ContainsID": false,
"ContainsFilePath": false
},
{
"ColumnIndex": 5,
"Field": "Date Sent",
"ContainsID": false,
"ContainsFilePath": false
}
]
},
"Folder":null
}
}'
$response = $global:WebRequest.callPost($uri, $jobConfigurationBody)
$global:WebRequest.checkIfSuccess($response)
Write-Information -MessageData "Job configuration created" -InformationAction Continue
}
Describe "Add Source 01" {
$uri = $global:Endpoints.importSourceAddUri($importId, $source01Id)
$dataSourceConfigurationBody = @{
dataSourceSettings = @{
path = $loadFile01Path
firstLineContainsColumnNames = $true
startLine = 0
columnDelimiter = "|"
quoteDelimiter = "^"
newLineDelimiter = "#"
nestedValueDelimiter = "&"
multiValueDelimiter = "$"
endOfLine = 0
encoding = $null
cultureInfo = "en-us"
type = 2
}
} | ConvertTo-Json -Depth 10
$response = $global:WebRequest.callPost($uri, $dataSourceConfigurationBody)
$global:WebRequest.checkIfSuccess($response)
Write-Information -MessageData "Source $sourceId added" -InformationAction Continue
}
Describe "Add Source 02" {
$uri = $global:Endpoints.importSourceAddUri($importId, $source02Id)
$dataSourceConfigurationBody = @{
dataSourceSettings = @{
path = $loadFile02Path
firstLineContainsColumnNames = $false
startLine = 0
columnDelimiter = "|"
quoteDelimiter = "^"
newLineDelimiter = "#"
nestedValueDelimiter = "&"
multiValueDelimiter = "$"
endOfLine = 0
encoding = $null
cultureInfo = "en-us"
type = 2
}
} | ConvertTo-Json -Depth 10
$response = $global:WebRequest.callPost($uri, $dataSourceConfigurationBody)
$global:WebRequest.checkIfSuccess($response)
Write-Information -MessageData "Source $sourceId added" -InformationAction Continue
}
Describe "Begin job" {
$uri = $global:Endpoints.importJobBeginUri($importId)
$beginBody = ""
$response = $global:WebRequest.callPost($uri, $beginBody)
$global:WebRequest.checkIfSuccess($response)
Write-Information -MessageData "Job began" -InformationAction Continue
}
Describe "End job" {
$uri = $global:Endpoints.importJobEndUri($importId)
$endBody = ""
$response = $global:WebRequest.callPost($uri, $endBody)
$global:WebRequest.checkIfSuccess($response)
Write-Information -MessageData "End job called" -InformationAction Continue
}
Describe "Wait for import to complete" {
$uri = $global:Endpoints.importJobDetailsUri($importId)
$jobDetailsResponse = $global:WebRequest.callGet($uri)
$global:WebRequest.checkIfSuccess($response)
$isJobFinished = $jobDetailsResponse."Value"."IsFinished"
[int]$sleepTime = 5
while($isJobFinished -ne $true)
{
Start-Sleep -Seconds $sleepTime
$jobDetailsResponse = $global:WebRequest.callGet($uri)
$global:WebRequest.checkIfSuccess($response)
$isJobFinished = $jobDetailsResponse."Value"."IsFinished"
$state = $jobDetailsResponse."Value"."State"
Write-Information -MessageData "Current job status: $state" -InformationAction Continue
}
}
Describe "Imported records info" {
$uri = $global:Endpoints.importSourceProgressUri($importId, $source01Id)
$global:WriteInformation.getDataSourceProgress($uri)
$global:WriteInformation.gateDataSourceErrors($importId, $source01Id)
$uri = $global:Endpoints.importSourceProgressUri($importId, $source02Id)
$global:WriteInformation.getDataSourceProgress($uri)
$global:WriteInformation.gateDataSourceErrors($importId, $source02Id)
#Example console output for sample files
#Import progress: Total records: 4, Imported records: 2, Records with errors: 2
#Data source [Id01] state: CompletedWithItemErrors
#Data source item errors:
#Import progress: Total records: 2, Imported records: 2, Records with errors: 0
#Data source [Id02] state: Completed
#Data source item errors:
}
}