-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbSDDV5_Classes.py
More file actions
851 lines (694 loc) · 37.8 KB
/
bSDDV5_Classes.py
File metadata and controls
851 lines (694 loc) · 37.8 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
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
import csv
import requests
import requests.auth
#Custom libraries
import json
#API_Endpoint = "https://bsdd-prototype.azure-api.net/api/"
API_EndPoint = 'https://test.bsdd.buildingsmart.org/api/';
# API ressources
Resource_Domains = "Domain/v2"
Resource_Classification = "Classification/v3"
Resource_Country = "Country/v1"
Resource_Search_Open = 'SearchListOpen/v2' #Unsecured
Resource_Search_Secured = 'SearchList/v2' #secured
# Custom made Resources
Resource_ExportFile = "RequestExportFile/preview"
Resource_Languages = "Language/v1"
Resource_ReferenceDocument = "ReferenceDocument/v1"
Resource_Unit = "Unit/v1"
Resource_DomainClassificationTree = "Domain/v2/Classifications"
Resource_TextSearch_Open = 'TextSearchListOpen/v5'
Resource_Material_Details = 'Material/v1'
Resource_List_Material_Domain = 'Material/SearchOpen/preview'
Resource_Property_Details = 'Property/v2'
Resource_PropertyValue_Details = 'PropertyValue/v1'
class TObject():
name = ''
namespaceUri = ''
#----------------------------------------------------------------------------------------------------
# Read a JSON value
def ReadVal(self, _JObj, _key):
res = ''
if _key in _JObj:
try :
res = _JObj[_key]
except:
res ='error'
return res
#----------------------------------------------------------------------------------------------------
#----------------------#
# Country #
#----------------------#
class TCountry(TObject):
code = ''
def FillValuesFromJSON(self, _content):
self.name = self.ReadVal(_content, 'name')
self.code = self.ReadVal(_content, 'code')
#----------------------#
# Classification #
#----------------------#
class TClassification(TObject):
def __init__(self): #Added constructor to expand available properties for this object
self.definition = ''
self.IFCLinks = []
self.Properties = []
self.namespaceUri = []
self.uid = []
# Read the values from the JSON response
def FillValuesFromJSON(self, _content):
self.name = self.ReadVal(_content, 'name')
self.namespaceUri = self.ReadVal(_content, 'namespaceUri')
self.definition = self.ReadVal(_content, 'definition')
# Ask the API for the classification details
def Load_Details(self, _content):
if "relatedIfcEntityNames" in _content:
for item in _content["relatedIfcEntityNames"]:
self.IFCLinks.append(item)
# Properties attached to the classification
if "classificationProperties" in _content:
for item in _content["classificationProperties"]:
NewProperty = TProperty()
NewProperty.FillValuesFromJSON(item)
self.Properties.append(NewProperty)
# Properties attached to the classification
if "namespaceUri" in _content:
for item in _content["namespaceUri"]:
NewProperty = TProperty()
NewProperty.FillValuesFromJSON(item)
self.Properties.append(NewProperty)
# Save properties list values of the class into a csv file
def SaveToCSV(self, _Name):
with open(_Name + '_Properties.csv' , 'w+') as csvfile:
MyFields = ['Name' , 'Domain', 'URI', 'Definition', 'dataType']
writer = csv.DictWriter(csvfile, delimiter=';' , fieldnames=MyFields)
writer.writeheader()
for item in self.Properties:
writer.writerow({'Name' : item.name, 'Domain': item.domain , 'URI' : item.namespaceUri, 'Definition' : item.definition, 'dataType' : item.dataType})
#----------------------#
# Property #
#----------------------#
class TProperty(TObject):
def __init__(self): #Added constructor for future expansion of available properties for this object
self.definition = ""
self.domain = ""
self.dataType = ""
# Read the values from the JSON response
def FillValuesFromJSON(self, _content):
self.name = self.ReadVal(_content, 'name')
self.domain = self.ReadVal(_content, 'propertyDomainName')
self.namespaceUri = self.ReadVal(_content, 'propertyNamespaceUri')
self.definition = self.ReadVal(_content, 'description')
self.dataType = self.ReadVal(_content, "dataType")
#----------------------#
# Domain #
#----------------------#
class TDomain(TObject):
def __init__(self): #Added constructor for future expansion of available properties for this object
self.version = ''
self.organizationNameOwner = ''
self.defaultLanguageCode = ''
self.license = ''
self.licenseUrl = ''
self.qualityAssuranceProcedure = ''
self.qualityAssuranceProcedureUrl = ''
self.Classes = []
# Read the values from the JSON response
def FillValuesFromJSON(self, _content):
self.namespaceUri = self.ReadVal(_content, 'namespaceUri')
self.name = self.ReadVal(_content, 'name')
self.version = self.ReadVal(_content, 'version')
self.organizationNameOwner = self.ReadVal(_content, 'organizationNameOwner')
self.defaultLanguageCode = self.ReadVal(_content, 'defaultLanguageCode')
self.license = self.ReadVal(_content, 'license')
self.licenseUrl = self.ReadVal(_content, 'licenseUrl')
self.qualityAssuranceProcedure = self.ReadVal(_content, 'qualityAssuranceProcedure')
self.qualityAssuranceProcedureUrl = self.ReadVal(_content, 'qualityAssuranceProcedureUrl')
# Save classifications list values of the domain into a csv file
def SaveToCSV(self):
with open(self.name + '_Classes.csv' , 'w+') as csvfile:
MyFields = ['Name' , 'URI', 'Definition']
writer = csv.DictWriter(csvfile, delimiter=';' , fieldnames=MyFields)
writer.writeheader()
for item in self.Classes:
writer.writerow({'Name' : item.name, 'URI' : item.namespaceUri, 'Definition' : item.definition})
# Dump data into json format, for visualization and saving in a GUI or file
def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=1)
#CUSTOM MADE CLASSES: These classes were created to accomodate all the available requests from the RESTful API
#----------------------#
# Language #
#----------------------#
class TLanguage(TObject):
def __init__(self):
self.isoCode = ''
def FillValuesFromJSON(self, _content):
self.name = self.ReadVal(_content, 'name')
self.namespaceUri = self.ReadVal(_content, 'namespaceUri')
self.isoCode = self.ReadVal(_content, 'isoCode')
#----------------------#
# ReferenceDocuments #
#----------------------#
class TReferenceDocument(TObject):
def __init__(self):
self.title = ''
self.date = ''
def FillValuesFromJSON(self, _content):
self.name = self.ReadVal(_content, 'name')
self.namespaceUri = self.ReadVal(_content, 'namespaceUri')
self.title = self.ReadVal(_content, 'title')
self.date = self.ReadVal(_content, 'date')
#----------------------#
# Unit #
#----------------------#
class TUnit(TObject):
def __init__(self):
self.code = ''
self.symbol = ''
def FillValuesFromJSON(self, _content):
self.name = self.ReadVal(_content, 'name')
self.namespaceUri = self.ReadVal(_content, 'namespaceUri')
self.code = self.ReadVal(_content, 'code')
self.symbol = self.ReadVal(_content, 'symbol')
#------------------------------------------------------------------------#
# This class contains #
# - authorization #
# - Header formatting of a request (with & without token) #
# - Send of a Get request for a specific ressource #
# - Calls to the API Ressources #
#------------------------------------------------------------------------#
class TPostman():
def __init__(self): #Added constructor for future expansion of available properties for this object
self.Domains = [] # Used to store domains received from an API call
self.Countries = [] # used to store the list of countries received from an API call
self.Token = None # used to store the token received from an authorization call
#CUSTOM MADE HOLDERS
self.Languages = [] # Used to store list of languages available in bSDD received from an API call
self.ReferenceDocuments = [] # Used to store list of reference documents available in bSDD received from an API call
self.Units = [] # Used to store list of units available in bSDD received from an API call
#----------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------
# get an authorization token - will open a web browser for the credentials
#----------------------------------------------------------------------------------------------------
def Authorize(self):
bSDD_ClientID = '4aba821f-d4ff-498b-a462-c2837dbbba70'
bSDD_Scope = "https://buildingsmartservices.onmicrosoft.com/api/read"
from msal import PublicClientApplication
bSDD_authority = 'https://buildingsmartservices.b2clogin.com/tfp/buildingsmartservices.onmicrosoft.com/b2c_1_signupsignin'
app = PublicClientApplication( bSDD_ClientID, authority = bSDD_authority) #need localhost redirection on azure portal for the client ID
flow = app.initiate_auth_code_flow(scopes=[bSDD_Scope])
#First try to see if there are accounts in cache. If not or an error is received, get token interactively through browser
#By standard, cache is only maintaned during a given Python session (runtime session of the code), since it is store in-memory (not persistent). In order to build a persistent version, the app instance constructor PublicClientApplication must receive a cache, that may be created manually with the SerializableTokenCache() class. See https://msal-python.readthedocs.io/en/latest/#msal.SerializableTokenCache and https://msal-python.readthedocs.io/en/latest/ for more information on that.
result = None
accounts = app.get_accounts()
if accounts:
result = app.acquire_token_silent(scopes=[bSDD_Scope], account=accounts[0])
if not result:
self.Token = app.acquire_token_interactive(scopes=[bSDD_Scope])
print('logged in')
#----------------------------------------------------------------------------------------------------
# Format the header of a query
#----------------------------------------------------------------------------------------------------
def setHeader(self):
if self.Token:
myheader = {
'content-type': 'application/json',
'Accept' :'application/json', # We want JSON
'Authorization' : 'Bearer ' + (self.Token['access_token']) #if logged in, here is the received token to send for secured API call
}
else :
myheader = {
'content-type': 'application/json',
'Accept' :'application/json',
}
return myheader
#----------------------------------------------------------------------------------------------------
# Send a GET API Call
#----------------------------------------------------------------------------------------------------
def get(self, _resource, _params):
#print (_params)#Uncomment to check the parameters sent
mResponse = requests.get(API_EndPoint + _resource, headers=self.setHeader(), params=_params)
#print (mResponse.url) #uncomment to see the URL sent
#print(mResponse.text) #uncomment to see the result of the call in the console
#sometimes it is needed to be able to access the header of the response
self.header = mResponse.headers
#Status code is also passed secondarily for optional error handling or visualization on the GUI
return mResponse.json(), mResponse.status_code
#----------------------------------------------------------------------------------------------------
# Get available countries - /api/Country/v1:
#----------------------------------------------------------------------------------------------------
def get_Countries(self, _SaveResult):
Response, request_status = self.get(Resource_Country, "")
#Browse the results
NbRes = 0
for item in Response:
Country = TCountry()
Country.FillValuesFromJSON(item)
self.Countries.append(Country)
if _SaveResult:
True
#TODO: Implement and test saving this information in a CSV file
#Save domain list to a csv file
#self.Save_Domains_To_CSV()
#----------------------------------------------------------------------------------------------------
# Get available domains - /api/Domain/v2:
#----------------------------------------------------------------------------------------------------
def get_Domains(self, _SaveResult):
Response, request_status = self.get(Resource_Domains, "")
#Browse the results
NbRes = 0
for item in Response:
Domain = TDomain()
Domain.FillValuesFromJSON(item)
self.Domains.append(Domain)
NbRes = NbRes + 1
if _SaveResult:
#Save domain list to a csv file
self.Save_Domains_To_CSV()
return NbRes
#----------------------------------------------------------------------------------------------------
# Get Classes of domains - /api/SearchList/v2
#----------------------------------------------------------------------------------------------------
def get_Domain_Classes(self, _DomainURI, _LanguageCode, _SaveResult, _Get_Details):
# params of the request
payload = dict()
payload["DomainNamespaceUri"] = _DomainURI
#Language code for the request ; EN for Internation English
payload["LanguageCode"] = _LanguageCode
Response, request_status = self.get(Resource_Search_Secured, payload)
NbRes = Response["numberOfClassificationsFound"]
for item in Response['domains']: #in this case we should have just 1 ! (Since we informed a URI from a specific domain)
ReadDomain = self.GetDomainFromURI(item['namespaceUri'])
for item2 in item["classifications"]:
NewClass = TClassification()
NewClass.FillValuesFromJSON(item2)
ReadDomain.Classes.append(NewClass)
#If details are required, a request is launched for each class
if _Get_Details:
payloadClass = dict()
payloadClass["namespaceUri"] = NewClass.namespaceUri
payloadClass["languageCode"] = _LanguageCode
payloadClass["includeChildClassificationReferences"] = False #we don't ask for the hierarchy we just want properties
mResponse = self.get(Resource_Classification, payloadClass)
NewClass.Load_Details(mResponse)
if _SaveResult:
#Save the classes informations to a csv
ReadDomain.SaveToCSV();
return NbRes
#----------------------------------------------------------------------------------------------------
# Retrieve the properties of a classification (i.e. retrieve all properties of a given definition) - /api/Classification/v3
#----------------------------------------------------------------------------------------------------
def Get_Classification_Properties(self, _ClassificationURI, _LanguageCode, _SaveResult, _ClassificationName = None): #Classification name, optional, just to nicely name the excel export
payloadClass = dict()
payloadClass["namespaceUri"] = _ClassificationURI
payloadClass["languageCode"] = _LanguageCode
payloadClass["includeChildClassificationReferences"] = False #we don't ask for the hierarchy we just want properties
mResponse, request_status = self.get(Resource_Classification, payloadClass)
mClassification = TClassification()
NbRes = 0
if "relatedIfcEntityNames" in mResponse:
for item in mResponse["relatedIfcEntityNames"]:
mClassification.IFCLinks.append(item)
# Get the properties attached to the classification
if "classificationProperties" in mResponse:
for item in mResponse["classificationProperties"]:
mProperty = TProperty()
mProperty.FillValuesFromJSON(item)
mClassification.Properties.append(mProperty)
NbRes += 1
#Save the properties informations to a csv
if _SaveResult:
mClassification.SaveToCSV(_ClassificationName)
return NbRes, mResponse, request_status #Expanded to return more inputs than originally returned
#----------------------------------------------------------------------------------------------------
# Retrieve a the classes of a domain linked to an IFC Entity - /api/SearchListOpen/v2
#----------------------------------------------------------------------------------------------------
def get_Linked_Classes(self, _DomainURI, _LanguageCode, _IFCEntity, _SaveResult, _Get_Details):
# params of the request
payload = dict()
payload["DomainNamespaceUri"] = _DomainURI
#Language code for the request ; EN for Internation English
payload["LanguageCode"] = _LanguageCode
payload["RelatedIfcEntity"] = _IFCEntity
Response, request_status = self.get(Resource_Search_Open, payload)
NbRes = Response["numberOfClassificationsFound"]
for item in Response['domains']: #in this case we should have just 1 !
ReadDomain = self.GetDomainFromURI(item['namespaceUri'])
for item2 in item["classifications"]:
NewClass = TClassification()
NewClass.FillValuesFromJSON(item2)
ReadDomain.Classes.append(NewClass)
#If details are required, a request is launched for each one
if _Get_Details:
payloadClass = dict()
payloadClass["namespaceUri"] = NewClass.namespaceUri
payloadClass["languageCode"] = _LanguageCode
payloadClass["includeChildClassificationReferences"] = False #we don't ask for the hierarchy we just want properties
mResponse = self.get(Resource_Classification, payloadClass)
NewClass.Load_Details(mResponse)
if _SaveResult:
#Save the classes informations to a csv
ReadDomain.SaveToCSV();
return NbRes
#----------------------------------------------------------------------------------------------------
# Retrieve a domain from its URI, in the list of domains got from the API ressource "Domain"
#----------------------------------------------------------------------------------------------------
def GetDomainFromURI(self, _URI):
i = 0;
for item in self.Domains:
if item.namespaceUri == _URI:
return item
break
#----------------------------------------------------------------------------------------------------
# Save domains list into a csv file
#----------------------------------------------------------------------------------------------------
def Save_Domains_To_CSV(self):
with open('bSDD_Domains.csv' , 'w+') as csvfile:
MyFields = ['Name' , 'URI']
writer = csv.DictWriter(csvfile, delimiter=';' , fieldnames=MyFields)
writer.writeheader()
for item in self.Domains:
writer.writerow({'Name' : item.name, 'URI' : item.namespaceUri})
#----------------------------------------------------------------------------------------------------
# Get available Languages (CUSTOM MADE) - /api/Language/v1:
#----------------------------------------------------------------------------------------------------
def get_Languages(self, _SaveResult):
Response, request_status = self.get(Resource_Languages, "")
#Browse the results
NbRes = 0
for item in Response:
Language = TLanguage()
Language.FillValuesFromJSON(item)
self.Languages.append(Language)
NbRes = NbRes + 1
if _SaveResult:
True
#TODO: Implement a way to save this information in a CSV file
#Save domain list to a csv file
#self.Save_Domains_To_CSV()
return NbRes
#----------------------------------------------------------------------------------------------------
# Get available Reference Documents (CUSTOM MADE) - /api/ReferenceDocument/v1:
#----------------------------------------------------------------------------------------------------
def get_ReferenceDocuments(self, _SaveResult):
Response, request_status = self.get(Resource_ReferenceDocument, "")
#Browse the results
NbRes = 0
for item in Response:
ReferenceDocument = TReferenceDocument()
ReferenceDocument.FillValuesFromJSON(item)
self.ReferenceDocuments.append(ReferenceDocument)
NbRes = NbRes + 1
if _SaveResult:
True
#TODO: Implement a way to save this information in a CSV file
#Save domain list to a csv file
#self.Save_Domains_To_CSV()
saveFile = open("C:/Users/renan.000/Desktop/save.json", "w")
saveFile = json.dump(Response, saveFile, indent = 1)
#Return number of results, i.e., number of Reference Documents available in bSDD
return NbRes
#----------------------------------------------------------------------------------------------------
# Get available Units (CUSTOM MADE) - /api/Unit/v1
#----------------------------------------------------------------------------------------------------
def get_Units(self, _SaveResult):
Response, request_status = self.get(Resource_Unit, "")
#Browse the results
NbRes = 0
for item in Response:
Unit = TUnit()
Unit.FillValuesFromJSON(item)
self.Units.append(Unit)
NbRes = NbRes + 1
if _SaveResult:
True
#TODO: Implement a way to save this information in a CSV file
#Save domain list to a csv file
#self.Save_Domains_To_CSV()
#Return number of results, i.e., number of Units available in bSDD
return NbRes
#----------------------------------------------------------------------------------------------------
# Get Domain with a classification tree (CUSTOM MADE) - /api/Domain/v2/Classifications:
#----------------------------------------------------------------------------------------------------
def get_Domain_Classes_Tree(self, _DomainURI, _useNestedClassifications, _SaveResult):
#This is the GET "/api/Domain/v2/Classifications - Get Domain with the classification tree"
#TODO: Implement verification of response status
#params of the request
payload = dict()
payload["namespaceUri"] = _DomainURI
payload["useNestedClassifications"] = _useNestedClassifications
# Response = self.get(Resource_Search_Secured, payload)
Response, request_status = self.get(Resource_DomainClassificationTree, payload)
#TODO: find a way to compute classification number from the JSON file received
#NbRes stores the amount of classifications retrieved in the response
#NbRes = len(Response['classifications'])
NbRes=1
#Unwrapping the Response and saving to the global bsdd variable of the script
#This is useful if we are going to cache information to avoid lots of retrievals
#TODO: check the method contract and make sure everything in Response is properly unwrapped. As of now, we are just passing Response to the GUI, to show, and will not update bsdd variable.
#From the list of domains already retrieved when initializing the API with the method "self.get_Domains()", retrieve the general structure of the domain, so we can populate it with data from the classifications retrieved, by having access to the field ".Classes" that is part of the "Domain" data structure.
ReadDomain = self.GetDomainFromURI(_DomainURI)
'''
for item in Response['classifications']: #iterate through each classification found in the domain:
NewClass = TClassification()
NewClass.FillValuesFromJSON(item)
#If details are required, a request is launched for each class
if _useNestedClassifications:
payloadClass = dict()
payloadClass["namespaceUri"] = NewClass.namespaceUri
payloadClass["includeChildClassificationReferences"] = True #we don't ask for the hierarchy we just want properties
mResponse = self.get(Resource_Classification, payloadClass)
NewClass.Load_Details(mResponse)
ReadDomain.Classes.append(NewClass)
'''
if _SaveResult:
#Save the classes informations to a csv
#ReadDomain.SaveToCSV();
#TODO: implement a way to save results here
True
return NbRes, Response, request_status
#----------------------------------------------------------------------------------------------------
# Make an Open Search on bSDD (CUSTOM MADE) - /api/TextSearchListOpen/v5:
#----------------------------------------------------------------------------------------------------
def get_TextOpen_Search(self, _SearchText, _TypeFilter, _FilteringDomainUris, _SaveResult):
# params of the request
payload = dict()
payload["SearchText"] = _SearchText #A list of strings
payload["TypeFilter"] = _TypeFilter #It is a string
payload["DomainNamespaceUris"] = _FilteringDomainUris #A list of strings
Response, request_status = self.get(Resource_TextSearch_Open, payload)
#TODO: Implement NbRes for this method
#NbRes = Response["numberOfClassificationsFound"]
NbRes=1
'''
for item in Response['domains']: #in this case we should have just 1 !
ReadDomain = self.GetDomainFromURI(item['namespaceUri'])
for item2 in item["classifications"]:
NewClass = TClassification()
NewClass.FillValuesFromJSON(item2)
ReadDomain.Classes.append(NewClass)
#If details are required, a request is launched for each one
if _Get_Details:
payloadClass = dict()
payloadClass["namespaceUri"] = NewClass.namespaceUri
payloadClass["languageCode"] = _LanguageCode
payloadClass["includeChildClassificationReferences"] = False #we don't ask for the hierarchy we just want properties
mResponse = self.get(Resource_Classification, payloadClass)
NewClass.Load_Details(mResponse)
'''
if _SaveResult:
#TODO: Need to implement a way to save the Response data
#Save the classes informations to a csv
#ReadDomain.SaveToCSV();
True
return NbRes, Response, request_status
#----------------------------------------------------------------------------------------------------
# Make a search about materials details on bSDD (CUSTOM MADE) - /api/Material/v1:
#----------------------------------------------------------------------------------------------------
def get_Material_Details(self, _namespaceURI, _languageCode, _includeChildMaterialReferences, _SaveResult):
# params of the request
payload = dict()
payload["namespaceUri"] = _namespaceURI #A list of strings
payload["languageCode"] = _languageCode #It is a string
payload["includeChildMaterialReferences"] = _includeChildMaterialReferences #A list of strings
Response, request_status = self.get(Resource_Material_Details, payload)
#TODO: Implement NbRes for this method
#NbRes = Response["numberOfClassificationsFound"]
NbRes=1
'''
for item in Response['domains']: #in this case we should have just 1 !
ReadDomain = self.GetDomainFromURI(item['namespaceUri'])
for item2 in item["classifications"]:
NewClass = TClassification()
NewClass.FillValuesFromJSON(item2)
ReadDomain.Classes.append(NewClass)
#If details are required, a request is launched for each one
if _Get_Details:
payloadClass = dict()
payloadClass["namespaceUri"] = NewClass.namespaceUri
payloadClass["languageCode"] = _LanguageCode
payloadClass["includeChildClassificationReferences"] = False #we don't ask for the hierarchy we just want properties
mResponse = self.get(Resource_Classification, payloadClass)
NewClass.Load_Details(mResponse)
'''
if _SaveResult:
#TODO: Need to implement a way to save the Response data
#Save the classes informations to a csv
#ReadDomain.SaveToCSV();
True
return NbRes, Response, request_status
#----------------------------------------------------------------------------------------------------
# Make a serch to get a list of Materials from a given Domain, without details (CUSTOM MADE) - /api/Material/SearchOpen/preview:
#----------------------------------------------------------------------------------------------------
def get_List_Material_Domain(self, _DomainNamespaceURI, _SearchText, _LanguageCode, _SaveResult):
# params of the request
payload = dict()
payload["DomainNamespaceUri"] = _DomainNamespaceURI #A list of strings
payload["SearchText"] = _SearchText #It is a string
payload["LanguageCode"] = _LanguageCode #A list of strings
Response, request_status = self.get(Resource_List_Material_Domain, payload)
#TODO: Implement NbRes for this method
#NbRes = Response["numberOfClassificationsFound"]
NbRes=1
'''
for item in Response['domains']: #in this case we should have just 1 !
ReadDomain = self.GetDomainFromURI(item['namespaceUri'])
for item2 in item["classifications"]:
NewClass = TClassification()
NewClass.FillValuesFromJSON(item2)
ReadDomain.Classes.append(NewClass)
#If details are required, a request is launched for each one
if _Get_Details:
payloadClass = dict()
payloadClass["namespaceUri"] = NewClass.namespaceUri
payloadClass["languageCode"] = _LanguageCode
payloadClass["includeChildClassificationReferences"] = False #we don't ask for the hierarchy we just want properties
mResponse = self.get(Resource_Classification, payloadClass)
NewClass.Load_Details(mResponse)
'''
if _SaveResult:
#TODO: Need to implement a way to save the Response data
#Save the classes informations to a csv
#ReadDomain.SaveToCSV();
True
return NbRes, Response, request_status
#----------------------------------------------------------------------------------------------------
# Make a search to get the details of a given Property (CUSTOM MADE) - /api/Property/v2:
#----------------------------------------------------------------------------------------------------
def get_Property_Details(self, _namespaceURI, _languageCode, _SaveResult):
# params of the request
payload = dict()
payload["namespaceUri"] = _namespaceURI #A list of strings. Namespace URI of the property
payload["languageCode"] = _languageCode #A list of strings
Response, request_status = self.get(Resource_Property_Details, payload)
#TODO: Implement NbRes for this method
#NbRes = Response["numberOfClassificationsFound"]
NbRes=1
'''
for item in Response['domains']: #in this case we should have just 1 !
ReadDomain = self.GetDomainFromURI(item['namespaceUri'])
for item2 in item["classifications"]:
NewClass = TClassification()
NewClass.FillValuesFromJSON(item2)
ReadDomain.Classes.append(NewClass)
#If details are required, a request is launched for each one
if _Get_Details:
payloadClass = dict()
payloadClass["namespaceUri"] = NewClass.namespaceUri
payloadClass["languageCode"] = _LanguageCode
payloadClass["includeChildClassificationReferences"] = False #we don't ask for the hierarchy we just want properties
mResponse = self.get(Resource_Classification, payloadClass)
NewClass.Load_Details(mResponse)
'''
if _SaveResult:
#TODO: Need to implement a way to save the Response data
#Save the classes informations to a csv
#ReadDomain.SaveToCSV();
True
return NbRes, Response, request_status
#----------------------------------------------------------------------------------------------------
# Make a search to get the details of a Property value (CUSTOM MADE) - /api/PropertyValue/v1:
#----------------------------------------------------------------------------------------------------
def get_PropertyValue_Details(self, _namespaceURI, _languageCode, _SaveResult):
# params of the request
payload = dict()
payload["namespaceUri"] = _namespaceURI #A list of strings. Namespace URI of the property
payload["languageCode"] = _languageCode #A list of strings
Response, request_status = self.get(Resource_PropertyValue_Details, payload)
#TODO: Implement NbRes for this method
#NbRes = Response["numberOfClassificationsFound"]
NbRes=1
'''
for item in Response['domains']: #in this case we should have just 1 !
ReadDomain = self.GetDomainFromURI(item['namespaceUri'])
for item2 in item["classifications"]:
NewClass = TClassification()
NewClass.FillValuesFromJSON(item2)
ReadDomain.Classes.append(NewClass)
#If details are required, a request is launched for each one
if _Get_Details:
payloadClass = dict()
payloadClass["namespaceUri"] = NewClass.namespaceUri
payloadClass["languageCode"] = _LanguageCode
payloadClass["includeChildClassificationReferences"] = False #we don't ask for the hierarchy we just want properties
mResponse = self.get(Resource_Classification, payloadClass)
NewClass.Load_Details(mResponse)
'''
if _SaveResult:
#TODO: Need to implement a way to save the Response data
#Save the classes informations to a csv
#ReadDomain.SaveToCSV();
True
return NbRes, Response, request_status
#----------------------------------------------------------------------------------------------------
# Make open search about classifications - /api/SearchList/v2
#----------------------------------------------------------------------------------------------------
def get_Open_Search_Classifications(self, _DomainURI, _SearchText, _LanguageCode, _RelatedIfcEntity, _SaveResult):
# params of the request
payload = dict()
payload["DomainNamespaceUri"] = _DomainURI
payload["SearchText"] = _SearchText
#Language code for the request ; EN for Internation English
payload["LanguageCode"] = _LanguageCode
payload["RelatedIfcEntity"] = _RelatedIfcEntity
Response, request_status = self.get(Resource_Search_Open, payload)
#TODO: Implement NbRes for this method
#NbRes = Response["numberOfClassificationsFound"]
NbRes = 1
'''
for item in Response['domains']: #in this case we should have just 1 ! (Since we informed a URI from a specific domain)
ReadDomain = self.GetDomainFromURI(item['namespaceUri'])
for item2 in item["classifications"]:
NewClass = TClassification()
NewClass.FillValuesFromJSON(item2)
ReadDomain.Classes.append(NewClass)
#If details are required, a request is launched for each class
if _Get_Details:
payloadClass = dict()
payloadClass["namespaceUri"] = NewClass.namespaceUri
payloadClass["languageCode"] = _LanguageCode
payloadClass["includeChildClassificationReferences"] = False #we don't ask for the hierarchy we just want properties
mResponse = self.get(Resource_Classification, payloadClass)
NewClass.Load_Details(mResponse)
'''
if _SaveResult:
#TODO: Need to implement a way to save the Response data
#Save the classes informations to a csv
#ReadDomain.SaveToCSV();
True
return NbRes, Response, request_status
#----------------------------------------------------------------------------------------------------
# Request a file with an export of a domain (CUSTOM MADE) - /api/RequestExportFile/preview:
#----------------------------------------------------------------------------------------------------
def RequestExportOfADomain(self, _SaveResult):
Response = self.get(Resource_ExportFile, "")
#Browse the results
NbRes = 0
for item in Response:
Domain = TDomain()
Domain.FillValuesFromJSON(item)
self.Domains.append(Domain)
NbRes = NbRes + 1
if _SaveResult:
#Save domain list to a csv file
self.Save_Domains_To_CSV()
return NbRes