-
Notifications
You must be signed in to change notification settings - Fork 4
/
json_object_parser.py
90 lines (79 loc) · 2.41 KB
/
json_object_parser.py
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
def getCommunityObj(communityName, parentCommunityName = None):
comm_obj = {}
comm_obj['resourceType'] = 'Community'
comm_obj['identifier'] = {
'name': communityName
}
if parentCommunityName != None:
comm_obj['parent'] = {
'name': parentCommunityName
}
return comm_obj
def getDomainObj(communityName, domainName, domainType):
obj = {}
obj['resourceType'] = 'Domain'
obj['identifier'] = {
'name': domainName,
'community': {
'name': communityName
}
}
obj['type'] = {
'name': domainType
}
return obj
def getAssetObj(communityName, domainName, assetName, assetType, displayName = None, attributes = None, relations = None):
obj = {}
obj['resourceType'] = 'Asset'
obj['identifier'] = {
'name': assetName,
'domain': {
'name': domainName,
'community': {
'name': communityName
}
}
}
if attributes != None:
attributes_obj = {}
if not type(attributes[0]) is tuple:
attributes_obj[attributes[0]] = [{
'value': attributes[1]
}]
else:
for attributeKey, attributeValue in attributes:
attributes_obj[attributeKey] = [{
'value': attributeValue
}]
if displayName != None:
attributes_obj['Print Name'] = [{
'value': displayName
}]
obj['attributes'] = attributes_obj
# TODO: remove display name and add print name as attr
if attributes == None and displayName != None:
attributes_obj = {}
attributes_obj['Print Name'] = [{
'value': displayName
}]
obj['attributes'] = attributes_obj
if relations != None:
obj['relations'] = {
relations[0]: [
{
'name': relations[1],
'domain': {
'name': domainName,
'community': {
'name': communityName
}
}
}
]
}
# if displayName != None:
# obj['displayName'] = displayName
obj['type'] = {
'name': assetType
}
return obj