@@ -35,36 +35,6 @@ export function CompasSclDataService() {
35
35
return CompasSettings ( ) . compasSettings . sclDataServiceUrl ;
36
36
}
37
37
38
- function createCreateRequest (
39
- sclName : string ,
40
- comment : string | null ,
41
- doc : Document
42
- ) : string {
43
- return `<?xml version="1.0" encoding="UTF-8"?>
44
- <sds:CreateRequest xmlns:sds="${ SDS_NAMESPACE } ">
45
- <sds:Name>${ sclName } </sds:Name>
46
- <sds:Comment>${ comment ?? '' } </sds:Comment>
47
- <sds:SclData><![CDATA[${ formatXml (
48
- new XMLSerializer ( ) . serializeToString (
49
- doc . documentElement ) ) } ]]></sds:SclData>
50
- </sds:CreateRequest>` ;
51
- }
52
-
53
- function createUpdateRequest (
54
- changeSet : ChangeSet ,
55
- comment : string | null ,
56
- doc : Document
57
- ) : string {
58
- return `<?xml version="1.0" encoding="UTF-8"?>
59
- <sds:UpdateRequest xmlns:sds="${ SDS_NAMESPACE } ">
60
- <sds:ChangeSet>${ changeSet } </sds:ChangeSet>
61
- <sds:Comment>${ comment ?? '' } </sds:Comment>
62
- <sds:SclData><![CDATA[${ formatXml (
63
- new XMLSerializer ( ) . serializeToString (
64
- doc . documentElement ) ) } ]]></sds:SclData>
65
- </sds:UpdateRequest>` ;
66
- }
67
-
68
38
return {
69
39
useWebsocket ( ) : boolean {
70
40
return CompasSettings ( ) . useWebsockets ( ) ;
@@ -120,7 +90,10 @@ export function CompasSclDataService() {
120
90
. then ( parseXml ) ;
121
91
} ,
122
92
123
- getSclDocument ( type : string , id : string ) : Promise < Document > {
93
+ getSclDocumentUsingRest (
94
+ type : string ,
95
+ id : string
96
+ ) : Promise < Document > {
124
97
const sclUrl =
125
98
getSclDataServiceUrl ( ) + '/scl/v1/' + type + '/' + id ;
126
99
return fetch ( sclUrl )
@@ -130,7 +103,30 @@ export function CompasSclDataService() {
130
103
. then ( extractSclFromResponse ) ;
131
104
} ,
132
105
133
- getSclDocumentVersion (
106
+ getSclDocumentUsingWebsockets (
107
+ element : Element ,
108
+ type : string ,
109
+ id : string ,
110
+ callback : ( scl : Document ) => void ,
111
+ ) {
112
+ const request =
113
+ `<?xml version="1.0" encoding="UTF-8"?>
114
+ <sds:GetWsRequest xmlns:sds="${ SDS_NAMESPACE } ">
115
+ <sds:Id>${ id } </sds:Id>
116
+ </sds:GetWsRequest>` ;
117
+
118
+ const sclUrl = getSclDataServiceUrl ( ) + '/scl-ws/v1/' + type + '/get' ;
119
+ Websockets ( element , 'CompasSclDataService' ) . execute (
120
+ getWebsocketUri ( sclUrl ) ,
121
+ request ,
122
+ async ( response : Document ) => {
123
+ const scl = await extractSclFromResponse ( response ) ;
124
+ callback ( scl ) ;
125
+ }
126
+ ) ;
127
+ } ,
128
+
129
+ getSclDocumentVersionUsingRest (
134
130
type : string ,
135
131
id : string ,
136
132
version : string
@@ -150,6 +146,31 @@ export function CompasSclDataService() {
150
146
. then ( extractSclFromResponse ) ;
151
147
} ,
152
148
149
+ getSclDocumentVersionUsingWebsockets (
150
+ element : Element ,
151
+ type : string ,
152
+ id : string ,
153
+ version : string ,
154
+ callback : ( scl : Document ) => void ,
155
+ ) {
156
+ const request =
157
+ `<?xml version="1.0" encoding="UTF-8"?>
158
+ <sds:GetVersionWsRequest xmlns:sds="${ SDS_NAMESPACE } ">
159
+ <sds:Id>${ id } </sds:Id>
160
+ <sds:Version>${ version } </sds:Version>
161
+ </sds:GetVersionWsRequest>` ;
162
+
163
+ const sclUrl = getSclDataServiceUrl ( ) + '/scl-ws/v1/' + type + '/get-version' ;
164
+ Websockets ( element , 'CompasSclDataService' ) . execute (
165
+ getWebsocketUri ( sclUrl ) ,
166
+ request ,
167
+ async ( response : Document ) => {
168
+ const scl = await extractSclFromResponse ( response ) ;
169
+ callback ( scl ) ;
170
+ }
171
+ ) ;
172
+ } ,
173
+
153
174
deleteSclDocumentVersion (
154
175
type : string ,
155
176
id : string ,
@@ -177,13 +198,23 @@ export function CompasSclDataService() {
177
198
} ,
178
199
179
200
addSclDocumentUsingRest ( type : string , body : CreateRequestBody ) : Promise < Document > {
201
+ const request =
202
+ `<?xml version="1.0" encoding="UTF-8"?>
203
+ <sds:CreateRequest xmlns:sds="${ SDS_NAMESPACE } ">
204
+ <sds:Name>${ body . sclName } </sds:Name>
205
+ <sds:Comment>${ body . comment ?? '' } </sds:Comment>
206
+ <sds:SclData><![CDATA[${ formatXml (
207
+ new XMLSerializer ( ) . serializeToString (
208
+ body . doc . documentElement ) ) } ]]></sds:SclData>
209
+ </sds:CreateRequest>` ;
210
+
180
211
const sclUrl = getSclDataServiceUrl ( ) + '/scl/v1/' + type ;
181
212
return fetch ( sclUrl , {
182
213
method : 'POST' ,
183
214
headers : {
184
215
'Content-Type' : 'application/xml' ,
185
216
} ,
186
- body : createCreateRequest ( body . sclName , body . comment , body . doc ) ,
217
+ body : request ,
187
218
} )
188
219
. catch ( handleError )
189
220
. then ( handleResponse )
@@ -197,10 +228,20 @@ export function CompasSclDataService() {
197
228
body : CreateRequestBody ,
198
229
callback : ( scl : Document ) => void ,
199
230
) {
231
+ const request =
232
+ `<?xml version="1.0" encoding="UTF-8"?>
233
+ <sds:CreateWsRequest xmlns:sds="${ SDS_NAMESPACE } ">
234
+ <sds:Name>${ body . sclName } </sds:Name>
235
+ <sds:Comment>${ body . comment ?? '' } </sds:Comment>
236
+ <sds:SclData><![CDATA[${ formatXml (
237
+ new XMLSerializer ( ) . serializeToString (
238
+ body . doc . documentElement ) ) } ]]></sds:SclData>
239
+ </sds:CreateWsRequest>` ;
240
+
200
241
const sclUrl = getSclDataServiceUrl ( ) + '/scl-ws/v1/' + type + '/create' ;
201
242
Websockets ( element , 'CompasSclDataService' ) . execute (
202
243
getWebsocketUri ( sclUrl ) ,
203
- createCreateRequest ( body . sclName , body . comment , body . doc ) ,
244
+ request ,
204
245
async ( response : Document ) => {
205
246
const scl = await extractSclFromResponse ( response ) ;
206
247
callback ( scl ) ;
@@ -213,14 +254,24 @@ export function CompasSclDataService() {
213
254
id : string ,
214
255
body : UpdateRequestBody
215
256
) : Promise < Document > {
257
+ const request =
258
+ `<?xml version="1.0" encoding="UTF-8"?>
259
+ <sds:UpdateRequest xmlns:sds="${ SDS_NAMESPACE } ">
260
+ <sds:ChangeSet>${ body . changeSet } </sds:ChangeSet>
261
+ <sds:Comment>${ body . comment ?? '' } </sds:Comment>
262
+ <sds:SclData><![CDATA[${ formatXml (
263
+ new XMLSerializer ( ) . serializeToString (
264
+ body . doc . documentElement ) ) } ]]></sds:SclData>
265
+ </sds:UpdateRequest>` ;
266
+
216
267
const sclUrl =
217
268
getSclDataServiceUrl ( ) + '/scl/v1/' + type + '/' + id ;
218
269
return fetch ( sclUrl , {
219
270
method : 'PUT' ,
220
271
headers : {
221
272
'Content-Type' : 'application/xml' ,
222
273
} ,
223
- body : createUpdateRequest ( body . changeSet , body . comment , body . doc ) ,
274
+ body : request ,
224
275
} )
225
276
. catch ( handleError )
226
277
. then ( handleResponse )
@@ -235,10 +286,21 @@ export function CompasSclDataService() {
235
286
body : UpdateRequestBody ,
236
287
callback : ( scl : Document ) => void ,
237
288
) {
238
- const sclUrl = getSclDataServiceUrl ( ) + '/scl-ws/v1/' + type + '/update/' + id ;
289
+ const request =
290
+ `<?xml version="1.0" encoding="UTF-8"?>
291
+ <sds:UpdateWsRequest xmlns:sds="${ SDS_NAMESPACE } ">
292
+ <sds:Id>${ id } </sds:Id>
293
+ <sds:ChangeSet>${ body . changeSet } </sds:ChangeSet>
294
+ <sds:Comment>${ body . comment ?? '' } </sds:Comment>
295
+ <sds:SclData><![CDATA[${ formatXml (
296
+ new XMLSerializer ( ) . serializeToString (
297
+ body . doc . documentElement ) ) } ]]></sds:SclData>
298
+ </sds:UpdateWsRequest>`
299
+
300
+ const sclUrl = getSclDataServiceUrl ( ) + '/scl-ws/v1/' + type + '/update' ;
239
301
Websockets ( element , 'CompasSclDataService' ) . execute (
240
302
getWebsocketUri ( sclUrl ) ,
241
- createUpdateRequest ( body . changeSet , body . comment , body . doc ) ,
303
+ request ,
242
304
async ( response : Document ) => {
243
305
const scl = await extractSclFromResponse ( response ) ;
244
306
callback ( scl ) ;
0 commit comments