-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSharepointSPOAPI.xml
More file actions
737 lines (655 loc) · 29.9 KB
/
SharepointSPOAPI.xml
File metadata and controls
737 lines (655 loc) · 29.9 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="IRIS" version="26" zv="IRIS for Windows (x86-64) 2024.1.1 (Build 347U)" ts="2024-12-13 13:59:22">
<Class name="Component.Generic.RequesterService">
<Description>
Standard Service that sends a blank Ens Request out on schedule or interval</Description>
<Super>Ens.BusinessService</Super>
<TimeChanged>67177,47867.4953578</TimeChanged>
<TimeCreated>67177,47863.8765992</TimeCreated>
<Parameter name="ADAPTER">
<Default>Ens.InboundAdapter</Default>
</Parameter>
<Property name="TargetConfigNames">
<Description>
Configuration item(s) to which to send messages</Description>
<Type>%String</Type>
<Parameter name="MAXLEN" value="2000"/>
</Property>
<Parameter name="SETTINGS">
<Default><![CDATA[TargetConfigNames:Basic:selector?multiSelect=1&context={Ens.ContextSearch/ProductionItems?targets=1&productionName=@productionId},SearchTableClass::selector?context={Ens.ContextSearch/SearchTableClasses?host=EnsLib.HL7.Service.Standard},LocalFacilityApplication,Framing:Connection:selector?context={Ens.ContextSearch/getDisplayList?host=@currHostId&prop=Framing},AckMode,UseAckCommitCodes,IgnoreInboundAck,AddNackERR,NackErrorCode,BatchHandling,MessageSchemaCategory:Basic:selector?context={Ens.ContextSearch/SchemaCategories?host=EnsLib.HL7.Service.Standard},DefCharEncoding::selector?context={Ens.ContextSearch/CharacterSets}]]></Default>
</Parameter>
<Method name="OnGetConnections">
<ClassMethod>1</ClassMethod>
<FormalSpec>*pArray:%String,pItem:Ens.Config.Item</FormalSpec>
<Implementation><![CDATA[
Do ##super(.pArray,pItem)
If pItem.GetModifiedSetting("TargetConfigNames",.tValue) {
For i=1:1:$L(tValue,",") { Set tOne=$ZStrip($P(tValue,",",i),"<>W") Continue:""=tOne Set pArray(tOne)="" }
}
]]></Implementation>
</Method>
<Method name="OnProcessInput">
<FormalSpec>pInput:%RegisteredObject,*pOutput:%RegisteredObject</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
set req = ##class(Ens.Request).%New()
Set sc = ..SendRequestAsync(..TargetConfigNames, req, .pResponse)
Quit sc
]]></Implementation>
</Method>
</Class>
<Class name="Component.SharePointOnline.Operations.SharePointOnlineRESTOperation">
<Description>
All API calls are made from here to SPO
Files are downloaded as Ens.Streamconainer's, everything is is responded as a EnsLib.HTTP.GenericMessage</Description>
<Super>EnsLib.REST.Operation,%CSP.REST</Super>
<TimeChanged>67187,46599.7765621</TimeChanged>
<TimeCreated>67186,49987.0820287</TimeCreated>
<Parameter name="INVOCATION">
<Default>Queue</Default>
</Parameter>
<Property name="SharepointSitename">
<Description><![CDATA[
The name of Site created within your tennacy you wish to interact with.<br/>
e.g. https://intersystems.sharepoint.com/sites/Test-Site<br/>
This will be URLEncoded automatically at the point of transmit]]></Description>
<Type>%String</Type>
<InitialExpression>"Test-Site"</InitialExpression>
<Required>1</Required>
</Property>
<Property name="SharepointFilePath">
<Description><![CDATA[
The name of Document folder created within your Site you wish to interact with.<br />
e.g. https://intersystems.sharepoint.com/sites/Test-Site/Shared Documents/ <br />
This will be URLEncoded automatically at the point of transmit <br />]]></Description>
<Type>%String</Type>
<InitialExpression>"Shared Documents"</InitialExpression>
<Required>1</Required>
</Property>
<Property name="OverwriteExistingFile">
<Description>
Overwrite file if exists already on SPO site</Description>
<Type>%String</Type>
<InitialExpression>"true"</InitialExpression>
<Required>1</Required>
<Parameter name="VALUELIST" value=",true,false"/>
</Property>
<Property name="GetOnlyNewFiles">
<Description>
If false gets all files in folder, if true it will get all files from last time a file was downloaded via this operation</Description>
<Type>%String</Type>
<InitialExpression>"true"</InitialExpression>
<Required>1</Required>
<Parameter name="VALUELIST" value=",true,false"/>
</Property>
<Property name="CondensedHTMLResponse">
<Description>
Default is don't need all the info off the response so just return the Status line </Description>
<Type>%Boolean</Type>
<InitialExpression>1</InitialExpression>
<Required>1</Required>
</Property>
<Property name="OAuthClientApplicationName">
<Description>
The OAuth server application setup in TIE for downloading a Client Credential</Description>
<Type>%String</Type>
<InitialExpression>"SPO"</InitialExpression>
<Required>1</Required>
<Parameter name="MAXLEN" value="64"/>
<Parameter name="MINLEN" value="1"/>
</Property>
<Property name="OAuthScope">
<Description>
The scope you setup on your SPO Application in Azure</Description>
<Type>%String</Type>
<Parameter name="MAXLEN" value="1024"/>
</Property>
<Property name="OAuthTokenSessionId">
<Description>
A unique name to track your access token</Description>
<Type>%String</Type>
<InitialExpression>"SPO"</InitialExpression>
<Required>1</Required>
</Property>
<Property name="Params">
<Description><![CDATA[
For SPO the Params should be {"resource":"00000003-0000-0ff1-ce00-000000000000/{TennantName}.sharepoint.com@{TennantID}"} <p>
00000003-0000-0ff1-ce00-000000000000 is the ResourceID asigned to SPO by Microsoft, and should not change <p>
{TennantName} should be changed to the same as the HTTP server e.g.intersystems.sharepoint.com <p>
{TennantID} is the ID for your server name tennancy ]]></Description>
<Type>%String</Type>
<InitialExpression>"{'resource':'00000003-0000-0ff1-ce00-000000000000/{TennantName}.sharepoint.com@{TennantID}'}"</InitialExpression>
<Required>1</Required>
<Parameter name="MAXLEN" value="500000"/>
</Property>
<Parameter name="SETTINGS">
<Default>SharepointSitename:Basic,SharepointFilePath:Basic,OverwriteExistingFile:Basic,GetOnlyNewFiles:Basic,CondensedHTMLResponse:Basic,OAuthClientApplicationName:OAuth,OAuthScope:OAuth,OAuthTokenSessionId:OAuth, Params:OAuth</Default>
</Parameter>
<Method name="OnGetConnections">
<ClassMethod>1</ClassMethod>
<FormalSpec>*pArray:%String,pItem:Ens.Config.Item</FormalSpec>
<Implementation><![CDATA[
d pItem.PopulateModifiedSettings()
s (tValue,tIndex)=""
for
{
s tSetting = pItem.ModifiedSettings.GetNext(.tIndex) q:tIndex=""
if tSetting.Name = "SharepointSitename" s tValue=tSetting.Value q:tIndex=""
If tSetting.Name = "SharepointFilePath" Set tValue=tValue_","_tSetting.Value q:tIndex=""
if tSetting.Name = "OverwriteExistingFile" s tValue=tSetting.Value q:tIndex=""
If tSetting.Name = "GetOnlyNewFiles" Set tValue=tValue_","_tSetting.Value q:tIndex=""
if tSetting.Name = "CondensedHTMLResponse" s tValue=tSetting.Value q:tIndex=""
If tSetting.Name = "OAuthClientApplicationName" Set tValue=tValue_","_tSetting.Value q:tIndex=""
if tSetting.Name = "OAuthScope" s tValue=tSetting.Value q:tIndex=""
If tSetting.Name = "OAuthTokenSessionId" Set tValue=tValue_","_tSetting.Value q:tIndex=""
If tSetting.Name = "Params" Set tValue=tValue_","_tSetting.Value q:tIndex=""
}
for i=1:1:$Length(tValue,",")
{
s tOne=$ZStrip($p(tValue,",",i),"<>W") Continue:""=tOne s pArray(tOne)=""
}
]]></Implementation>
</Method>
<Method name="GetFileList">
<FormalSpec>pQuery:Ens.Request,*pResponse:EnsLib.HTTP.GenericMessage</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
s filter=""
if (""_..GetOnlyNewFiles = "true")
{
s a="",b=..%RequestHeader.TargetConfigName
//logical mode so status is 9
//&SQL(SELECT Max(TimeProcessed) INTO :a FROM Ens.MessageHeader where TargetConfigName=:b AND Status = 9 )
&SQL(SELECT TOP 1 TimeProcessed INTO :a FROM Ens.MessageHeader head WHERE head.Status = 9 AND (head.SourceConfigName = :b AND head.MessageBodyClassName = 'Ens.StreamContainer') ORDER BY head.ID Desc)
IF SQLCODE<0 {WRITE "SQLCODE error ",SQLCODE RETURN %msg}
//needs encoded to time for API as XSD time, a should be timestamp value hopefully
set XSDtime=##Class(%Library.StringTimeStamp).LogicalToXSD(a)
//there's a Z on XSD time...
set XSDtime=$EXTRACT(XSDtime,1,$LENGTH(XSDtime)-1)
$$$TRACE(XSDtime)
s filter = "?$filter=TimeLastModified gt datetime'"_XSDtime_"'"
s filtervalue = "TimeLastModified gt datetime'"_XSDtime_"'"
s filter = "?$filter="_$$$URLENCODE("TimeLastModified gt datetime'"_XSDtime_"'")
if a=""{s filter =""}
}
Set tHttpRequest=##class(%Net.HttpRequest).%New()
set tHttpRequest.WriteRawMode=1
do tHttpRequest.SetHeader("Accept","application/json;odata=verbose")
do tHttpRequest.SetHeader("Content-Type","application/json")
Set ..Adapter.URL="/sites/"_$$$URLENCODE(..SharepointSitename)_"/_api/web/GetFolderByServerRelativeUrl('"_$$$URLENCODE(..SharepointFilePath)_"')/Files"_filter
Set tSC=..AddAccessToken(.tHttpRequest)
if $$$ISERR(tSC) quit tSC
$$$TRACE("Get File list changes from "_..Adapter.URL)
Set tHttpResponse = ##class(%Net.HttpResponse).%New()
S send="GET"
$$$TRACE("Sending to "_..Adapter.URL)
s tSC = ..SendRequest(.tHttpResponse,send,tHttpRequest, .pResponse)
Quit ..constructResponse(.tHttpResponse,.pResponse)
]]></Implementation>
</Method>
<Method name="DeleteFile">
<FormalSpec>pRequest:Messages.Generic.GenericDocument,*pResponse:EnsLib.HTTP.GenericMessage</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
$$$TRACE("Delete file "_pRequest.FileName)
Set tHttpRequest=##class(%Net.HttpRequest).%New()
set tHttpRequest.WriteRawMode=1
do tHttpRequest.SetHeader("Accept","application/json;odata=verbose")
do tHttpRequest.SetHeader("Content-Type","application/json")
Set ..Adapter.URL="/sites/"_$$$URLENCODE(..SharepointSitename)_"/_api/web/GetFolderByServerRelativeUrl('"_$$$URLENCODE(..SharepointFilePath)_"')/Files('"_$$$URLENCODE(pRequest.FileName)_"')"
$$$TRACE("Delete File from "_..Adapter.URL)
Set tSC=..AddAccessToken(.tHttpRequest)
//s tHttpRequest.EntityBody=##Class(%Stream.FileBinary).%New()
//s sc=tHttpRequest.EntityBody.Write(pQuery.StringValue)
Set tHttpResponse = ##class(%Net.HttpResponse).%New()
S send="DELETE"
$$$TRACE("Sending to "_..Adapter.URL)
s tSC = ..SendRequest(.tHttpResponse,send,tHttpRequest, .pResponse)
Quit ..constructResponse(.tHttpResponse,.pResponse)
]]></Implementation>
</Method>
<Method name="DownloadFile">
<FormalSpec>pRequest:Ens.StringContainer,*pDownloadResponse:Ens.StreamContainer</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
set binaryStream =##Class(%Stream.FileBinary).%New()
s tSC=$$$OK
Set tHttpRequest=##class(%Net.HttpRequest).%New()
set tHttpRequest.WriteRawMode=1
Set tHttpRequest.Https = 1
do tHttpRequest.SetHeader("Accept","application/json")
do tHttpRequest.SetHeader("Content-Type","application/json")
//do tHttpRequest.SetHeader("Connection","keep-alive")
Set tSC=..AddAccessToken(.tHttpRequest)
Set ..Adapter.URL="/sites/"_$$$URLENCODE(..SharepointSitename)_"/_api/web/GetFolderByServerRelativeUrl('"_$$$URLENCODE(..SharepointFilePath)_"')/Files('"_$$$URLENCODE(pRequest.StringValue)_"')/OpenBinaryStream()"
Set tHttpResponse = ##class(%Net.HttpResponse).%New()
S send="GET"
$$$TRACE("Getting file from "_..Adapter.URL)
s tSC = ..SendRequest(.tHttpResponse,send,tHttpRequest, .pResponse)
//Set tSC=..Adapter.SendFormDataArray(.tHttpResponse, send, tHttpRequest)
Do tHttpResponse.Data.Rewind()
while 'tHttpResponse.Data.AtEnd {
set tSC=binaryStream.Write(tHttpResponse.Data.Read(,.tSC1))
if 'tSC1 quit
}
set pDownloadResponse =##Class(Ens.StreamContainer).%New(binaryStream)
set pDownloadResponse.OriginalFilename=pRequest.StringValue
Q tSC
]]></Implementation>
</Method>
<Method name="AddFile">
<FormalSpec>pFileToUpload:Ens.StreamContainer,*pResponse:EnsLib.HTTP.GenericMessage</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
s fn=$$$URLENCODE(##Class(%File).GetFilename(pFileToUpload.OriginalFilename))
Set tHttpRequest=##class(%Net.HttpRequest).%New()
set tHttpRequest.WriteRawMode=1
do tHttpRequest.SetHeader("Accept","application/json;odata=verbose")
do tHttpRequest.SetHeader("Content-Type","application/json")
Set ..Adapter.URL="/sites/"_$$$URLENCODE(..SharepointSitename)_"/_api/web/GetFolderByServerRelativeUrl('"_$$$URLENCODE(..SharepointFilePath)_"')/Files/add(url='"_fn_"',overwrite="_$$$URLENCODE(..OverwriteExistingFile)_")"
Set tSC=..AddAccessToken(.tHttpRequest)
if $$$ISERR(tSC){Q tSC}
s tHttpRequest.EntityBody=##Class(%Stream.FileBinary).%New()
s sc=tHttpRequest.EntityBody.CopyFromAndSave(pFileToUpload.Stream)
Set tHttpResponse = ##class(%Net.HttpResponse).%New()
S send="POST"
$$$TRACE("Sending to "_..Adapter.URL)
s tSC = ..SendRequest(.tHttpResponse,send,tHttpRequest, .pResponse)
Quit ..constructResponse(.tHttpResponse,.pResponse)
]]></Implementation>
</Method>
<Method name="SendRequest">
<FormalSpec>*tHttpResponse:%Net.HttpResponse,send:%String,tHttpRequest:%Net.HttpRequest,*pResponse:EnsLib.HTTP.GenericMessage</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
s tSC=$$$OK
Set tSC=..Adapter.SendFormDataArray(.tHttpResponse, send, tHttpRequest)
$$$TRACE(tHttpResponse)
//If there was an error and there was a http response with size then display the error output it along with the data
If $$$ISERR(tSC)&&$IsObject(tHttpResponse)&&$IsObject(tHttpResponse.Data)&&tHttpResponse.Data.Size
{
$$$TRACE(tHttpResponse.Data.Read())
Set tSC = $$$ERROR($$$EnsErrGeneral,$$$StatusDisplayString(tSC)_":"_tHttpResponse.Data.Read())
}
Quit:$$$ISERR(tSC)
$$$TRACE(tHttpResponse.StatusCode)
//i think there was a quicker way to do the 200 example i'll have a look MOR 20241204
if (tHttpResponse.StatusCode<300)
{
s tSC=$$$OK
}
else //not a 200 response so report back the error
{
set message=tHttpResponse.StatusCode_": "_tHttpResponse.StatusLine_". "
if $IsObject(tHttpResponse.Data)
{
Try {
while 'tHttpResponse.Data.AtEnd {
set message=message_tHttpResponse.Data.Read(,.tSC1)
}
}
Catch ex {
//Not bothered as then
}
}
}
Q tSC
]]></Implementation>
</Method>
<Method name="constructResponse">
<Internal>1</Internal>
<FormalSpec>pHttpResponse:%Net.HttpResponse,*pResponse:EnsLib.HTTP.GenericMessage</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
$$$TRACE("construct response")
Set tSC=$$$OK
Set tStream=##class(%GlobalBinaryStream).%New()
if '..CondensedHTMLResponse{
If $IsObject(pHttpResponse.Data) {
Set tStream=pHttpResponse.Data
} Else {
Set tSC=tStream.Write(pHttpResponse.Data) Quit:$$$ISERR(tSC) tSC
}
Set pResponse=##class(EnsLib.HTTP.GenericMessage).%New(tStream,,pHttpResponse)
}
else{
Set pResponse=##class(EnsLib.HTTP.GenericMessage).%New()
}
set tSC= pResponse.Stream.CopyFromAndSave(tStream)
Do pResponse.HTTPHeaders.SetAt(pHttpResponse.StatusCode,"StatusCode")
Do pResponse.HTTPHeaders.SetAt(pHttpResponse.StatusLine,"StatusLine")
Quit tSC
]]></Implementation>
</Method>
<Method name="AddAccessToken">
<Description>
Assemble Envelope and Body into HTTP EntityBody stream</Description>
<FormalSpec><![CDATA[&pHttpRequest:%Net.HttpRequest]]></FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
$$$TRACE("AddAccessToken")
Set tSC = $$$OK
#dim error as %OAuth2.Error
Try {
; sessionId has a 50 charactor limit
; This should support multiple requests in the same production session
//Set sessionId=..%SessionId
Set sessionId=..OAuthTokenSessionId
Set isAuthorised = ##class(%SYS.OAuth2.AccessToken).IsAuthorized(..OAuthClientApplicationName,sessionId,..OAuthScope,.accessToken,,.responseProperties,.error)
;Throw:'$$$NULLOREF=error ..ExceptionFromOAuth2Error(error)
Throw:$isobject(error) ..ExceptionFromOAuth2Error(error)
If 'isAuthorised {
$$$TRACE("Not Authorised currently")
//Add any Parameters
s paramsarr = [].%FromJSON(..Params)
s iterator = paramsarr.%GetIterator()
s properties=""
While iterator.%GetNext(.key,.value)
{
s properties(key)=value
}
Set tSC = ##class(%SYS.OAuth2.Authorization).GetAccessTokenClient(..OAuthClientApplicationName,..OAuthScope,.properties,.error,.sessionId)
$$$TRACE("AddAccessToken isAuthorised " _ tSC)
$$$TRACE(error.ErrorDescription)
Throw:$isobject(error) ..ExceptionFromOAuth2Error(error)
}
; sendType is the mode of sending access token to resource server
; The default is "header"
Set sendType = "header"
;The default for sslConfiguration comes from the OAuth2.Client instance.
Set tSC = ##class(%SYS.OAuth2.AccessToken).AddAccessToken(pHttpRequest,sendType,,..OAuthClientApplicationName,sessionId)
} Catch exception {
Set tSC = exception.AsStatus()
$$$TRACE("EXCEPTION")
$$$TRACE("AddAccessToken Code" _ exception.Code)
$$$TRACE("AddAccessToken Location" _ exception.Location)
$$$TRACE("AddAccessToken Data" _ exception.Data)
}
Return tSC
]]></Implementation>
</Method>
<Method name="ExceptionFromOAuth2Error">
<FormalSpec>pError:%OAuth2.Error</FormalSpec>
<ReturnType>%Exception.StatusException</ReturnType>
<Implementation><![CDATA[
Set errorText = pError.AsString()
$$$LOGERROR(errorText)
Set tSC = $$$ERROR($$$GeneralError,errorText)
Return ##class(%Exception.StatusException).CreateFromStatus(tSC)
;Or
;If you wish to create one with %New then the 4th argument is a $lb of data values to the error %Status, e.g.
;Set exception = ##class(%Exception.StatusException).%New(Name,Code,Location,$lb(arg1,arg2,arg3,arg4))
]]></Implementation>
</Method>
<XData name="MessageMap">
<Data><![CDATA[
<MapItems>
<MapItem MessageType="Ens.StreamContainer">
<Method>AddFile</Method>
</MapItem>
<MapItem MessageType="Messages.Generic.GenericDocument">
<Method>DeleteFile</Method>
</MapItem>
<MapItem MessageType="Ens.StringContainer">
<Method>DownloadFile</Method>
</MapItem>
<MapItem MessageType="Ens.Request">
<Method>GetFileList</Method>
</MapItem>
</MapItems>
]]></Data>
</XData>
</Class>
<Class name="Component.SharePointOnline.Processes.SPOProcessManager">
<Description>
A class for dealing with filelists from SPO - SharePointOnline.
The class firsts gets a list of files and downloads before uploading to a nother folder location </Description>
<Super>Ens.BusinessProcess</Super>
<TimeChanged>67187,50202.758465</TimeChanged>
<TimeCreated>67186,51877.9876118</TimeCreated>
<Parameter name="SETTINGS">
<Default>SharePointService:SharepointService,UploadFileToService:SharepointService,DeleteFileAfterDownload:SharepointService</Default>
</Parameter>
<Property name="SharePointService">
<Description>
The service to send all API requests to</Description>
<Type>%String</Type>
<InitialExpression>"SharepointRESTConnector"</InitialExpression>
</Property>
<Property name="UploadFileToService">
<Description>
the file adapter to upload all files too, after downloaded from SPO</Description>
<Type>%String</Type>
<InitialExpression>"SharepointDownloadFileEndpoint"</InitialExpression>
</Property>
<Property name="DeleteFileAfterDownload">
<Description>
Default is don't delete file from Sharepoint site after, if true the file will be deleted from SPO.</Description>
<Type>%Boolean</Type>
<InitialExpression>0</InitialExpression>
<Required>1</Required>
</Property>
<Method name="OnGetConnections">
<ClassMethod>1</ClassMethod>
<FormalSpec>*pArray:%String,pItem:Ens.Config.Item</FormalSpec>
<Implementation><![CDATA[
Do pItem.PopulateModifiedSettings()
Set (tValue,tIndex)=""
For
{
Set tSetting = pItem.ModifiedSettings.GetNext(.tIndex) Quit:tIndex=""
If tSetting.Name="SharePointService" Set tValue=tValue_","_tSetting.Value
If tSetting.Name="UploadFileToService" Set tValue=tValue_","_tSetting.Value
}
For i=1:1:$Length(tValue,",")
{
Set tOne=$ZStrip($P(tValue,",",i),"<>W") Continue:""=tOne Set pArray(tOne)=""
}
]]></Implementation>
</Method>
<Method name="OnRequest">
<FormalSpec>pRequest:Ens.Request,*pResponse:EnsLib.HTTP.GenericMessage</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
s response=##Class(EnsLib.HTTP.GenericMessage).%New()
set tSC=..SendRequestSync(..SharePointService,pRequest,.response,60) Quit:$$$ISERR(tSC)
s d=""
set result = [].%FromJSON(response.StreamCF)
s resa= [].%FromJSON(result.d.%ToJSON())
s resb=[].%FromJSON(resa.results.%ToJSON())
s iter=resb.%GetIterator()
s i=0
while iter.%GetNext(.key,.val)
{
$$$TRACE("Download and upload "_resb.%Get(i).Name)
//download file
Try
{
s str=##Class(Ens.StringContainer).%New(resb.%Get(i).Name)
set tSC=..SendRequestSync(..SharePointService,str,.response,60) Quit:$$$ISERR(tSC)
//upload file
if tSC=$$$OK {s tSC=..SendRequestSync(..UploadFileToService, response,60)}
if ..DeleteFileAfterDownload
{
s dao=##Class(Messages.Generic.GenericDocument).%New()
s dao.FileName = str.StringValue
s tSC=..SendRequestSync(..SharePointService,dao, response,60)
}
s i=i+1
}
Catch ex
{
Set tSC = ex.AsStatus()
}
}
Quit tSC
]]></Implementation>
</Method>
<Storage name="Default">
<Type>%Storage.Persistent</Type>
<DefaultData>DownloadFileProcessDefaultData</DefaultData>
<Data name="DownloadFileProcessDefaultData">
<Subscript>"DownloadFileProcess"</Subscript>
<Value name="1">
<Value>SharePointService</Value>
</Value>
<Value name="2">
<Value>UploadFileToService</Value>
</Value>
<Value name="3">
<Value>DeleteFileAfterDownload</Value>
</Value>
</Data>
</Storage>
</Class>
<Project name="EnsExportItem_2024-12-13 13-58-00_991+0" LastModified="2024-12-13 13:59:22.8847776">
<ProjectDescription>Studio Project generated starting from Production Configuration Item 'SRFT.Live : SharepointFileProcessor' at 2024-12-13 13:58:00.991 UTC</ProjectDescription>
<Items>
<ProjectItem name="Component.Generic.RequesterService" type="CLS"></ProjectItem>
<ProjectItem name="Component.SharePointOnline.Operations.SharePointOnlineRESTOperation" type="CLS"></ProjectItem>
<ProjectItem name="Component.SharePointOnline.Processes.SPOProcessManager" type="CLS"></ProjectItem>
<ProjectItem name="Messages.Generic.GenericDocument" type="CLS"></ProjectItem>
<ProjectItem name="Settings:SharepointDownloadFileEndpoint.PTD" type="PTD"></ProjectItem>
<ProjectItem name="Settings:SharepointDownloadFileRequesterService.PTD" type="PTD"></ProjectItem>
<ProjectItem name="Settings:SharepointFileProcessor.PTD" type="PTD"></ProjectItem>
<ProjectItem name="Settings:SharepointRESTConnector.PTD" type="PTD"></ProjectItem>
<ProjectItem name="EnsExportNotes.EnsExportItem_2024-12-13 13-58-00_991+0.PTD" type="PTD"></ProjectItem>
</Items>
</Project>
<Class name="Messages.Generic.GenericDocument">
<Super>%Persistent,%XML.Adaptor</Super>
<TimeChanged>66007,48685.907867</TimeChanged>
<TimeCreated>65993,42980.556019</TimeCreated>
<Property name="FileName">
<Type>%String</Type>
</Property>
<Property name="FileSource">
<Type>%String</Type>
</Property>
<Property name="PracticeCode">
<Type>%String</Type>
</Property>
<Property name="DistrictNumber">
<Type>%String</Type>
</Property>
<Property name="NHSNumber">
<Type>%String</Type>
</Property>
<Property name="SurName">
<Type>%String</Type>
</Property>
<Property name="ForeName">
<Type>%String</Type>
</Property>
<Property name="Gender">
<Type>%String</Type>
</Property>
<Property name="DateOfBirth">
<Type>%String</Type>
</Property>
<Property name="DateOfEvent">
<Type>%String</Type>
</Property>
<Property name="DateOfLetter">
<Type>%String</Type>
</Property>
<Property name="Base64Letter">
<Type>%Stream.FileBinary</Type>
</Property>
<Storage name="Default">
<Type>%Storage.Persistent</Type>
<DataLocation>^Messages.GA6E7.GenericDocu8689D</DataLocation>
<DefaultData>GenericDocumentDefaultData</DefaultData>
<IdLocation>^Messages.GA6E7.GenericDocu8689D</IdLocation>
<IndexLocation>^Messages.GA6E7.GenericDocu8689I</IndexLocation>
<StreamLocation>^Messages.GA6E7.GenericDocu8689S</StreamLocation>
<ExtentSize>100000</ExtentSize>
<Data name="GenericDocumentDefaultData">
<Structure>listnode</Structure>
<Subscript/>
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>FileName</Value>
</Value>
<Value name="3">
<Value>FileSource</Value>
</Value>
<Value name="4">
<Value>PracticeCode</Value>
</Value>
<Value name="5">
<Value>DistrictNumber</Value>
</Value>
<Value name="6">
<Value>NHSNumber</Value>
</Value>
<Value name="7">
<Value>SurName</Value>
</Value>
<Value name="8">
<Value>ForeName</Value>
</Value>
<Value name="9">
<Value>Gender</Value>
</Value>
<Value name="10">
<Value>DateOfBirth</Value>
</Value>
<Value name="11">
<Value>DateOfEvent</Value>
</Value>
<Value name="12">
<Value>DateOfLetter</Value>
</Value>
<Value name="13">
<Value>Base64Letter</Value>
</Value>
</Data>
</Storage>
</Class>
<Document name="EnsExportNotes.EnsExportItem_2024-12-13 13-58-00_991+0.PTD"><ProjectTextDocument name="EnsExportNotes.EnsExportItem_2024-12-13 13-58-00_991+0" description="Export Notes for export EnsExportItem_2024-12-13 13-58-00_991+0">
<![CDATA[<Deployment>
<Creation>
<Machine>SRHTTIEPREPROD.SRHT.NHS.UK</Machine>
<Instance>ENSEMBLE2</Instance>
<Namespace>SRFT</Namespace>
<SourceProduction>SRFT.Live</SourceProduction>
<Username>MOReilly</Username>
<UTC>2024-12-13 13:59:22.869</UTC>
</Creation>
<Notes>
<Line num="1">sharepoint api #openexchange</Line>
</Notes>
<Contents>
<ExportProject>EnsExportItem_2024-12-13 13-58-00_991+0</ExportProject>
<Item num="1">Component.Generic.RequesterService.CLS</Item>
<Item num="2">Component.SharePointOnline.Operations.SharePointOnlineRESTOperation.CLS</Item>
<Item num="3">Component.SharePointOnline.Processes.SPOProcessManager.CLS</Item>
<Item num="4">Messages.Generic.GenericDocument.CLS</Item>
<Item num="5">Settings:SharepointDownloadFileEndpoint.PTD</Item>
<Item num="6">Settings:SharepointDownloadFileRequesterService.PTD</Item>
<Item num="7">Settings:SharepointFileProcessor.PTD</Item>
<Item num="8">Settings:SharepointRESTConnector.PTD</Item>
</Contents>
<ProductionClassInExport></ProductionClassInExport>
</Deployment>
]]></ProjectTextDocument>
</Document>
<Document name="Settings:SharepointDownloadFileEndpoint.PTD"><ProjectTextDocument name="Settings:SharepointDownloadFileEndpoint" description="Settings for SharepointDownloadFileEndpoint in Production SRFT.Live">
<![CDATA[<Item Name="SharepointDownloadFileEndpoint" Category="SharePointOnline" ClassName="EnsLib.File.PassthroughOperation" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule=""><Setting Target="Adapter" Name="FilePath">D:\SharepointTesting\Downloaded</Setting><Setting Target="Host" Name="Filename">%f</Setting></Item>
]]></ProjectTextDocument>
</Document>
<Document name="Settings:SharepointDownloadFileRequesterService.PTD"><ProjectTextDocument name="Settings:SharepointDownloadFileRequesterService" description="Settings for SharepointDownloadFileRequesterService in Production SRFT.Live">
<![CDATA[<Item Name="SharepointDownloadFileRequesterService" Category="SharePointOnline" ClassName="Component.Generic.RequesterService" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule=""><Setting Target="Adapter" Name="CallInterval">600</Setting><Setting Target="Host" Name="TargetConfigNames">SharepointFileProcessor</Setting></Item>
]]></ProjectTextDocument>
</Document>
<Document name="Settings:SharepointFileProcessor.PTD"><ProjectTextDocument name="Settings:SharepointFileProcessor" description="Settings for SharepointFileProcessor in Production SRFT.Live">
<![CDATA[<Item Name="SharepointFileProcessor" Category="SharePointOnline" ClassName="Component.SharePointOnline.Processes.SPOProcessManager" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="true" Schedule=""><Setting Target="Host" Name="UploadFileToService">SharepointDownloadFileEndpoint</Setting><Setting Target="Host" Name="SharePointService">SharepointRESTConnector</Setting><Setting Target="Host" Name="DeleteFileAfterDownload">0</Setting></Item>
]]></ProjectTextDocument>
</Document>
<Document name="Settings:SharepointRESTConnector.PTD"><ProjectTextDocument name="Settings:SharepointRESTConnector" description="Settings for SharepointRESTConnector in Production SRFT.Live">
<![CDATA[<Item Name="SharepointRESTConnector" Category="SharePointOnline" ClassName="Component.SharePointOnline.Operations.SharePointOnlineRESTOperation" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="true" Schedule=""><Setting Target="Adapter" Name="HTTPPort">443</Setting><Setting Target="Adapter" Name="HTTPServer">greatermanchester.sharepoint.com</Setting><Setting Target="Adapter" Name="Credentials"></Setting><Setting Target="Adapter" Name="SSLConfig">SharepointOnline</Setting><Setting Target="Adapter" Name="URL"></Setting><Setting Target="Host" Name="CondensedHTMLResponse">0</Setting><Setting Target="Adapter" Name="SSLCheckServerIdentity">0</Setting><Setting Target="Host" Name="GetOnlyNewFiles">true</Setting><Setting Target="Adapter" Name="LocalInterface">192.168.48.158 (IPv4 Ethernet0)</Setting></Item>
]]></ProjectTextDocument>
</Document></Export>