-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodes.py
More file actions
182 lines (154 loc) · 6.59 KB
/
Nodes.py
File metadata and controls
182 lines (154 loc) · 6.59 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
import json
import os
import re
def find_nodes(files, folder):
nodes = []
for json_file in files:
json_code = json.load(open(os.path.join(folder, json_file), 'r'))
if not isinstance(json_code, list):
new_json_code = []
for json_category in json_code['_children'].keys():
json_items = json_code['_children'][json_category]
if isinstance(json_items, list):
for json_item in json_items:
if isinstance(json_item, dict) and '__reference_comparison_key' in json_item:
new_json_code.append(json_item)
json_code = new_json_code
for item in json_code:
node = {}
if not isinstance(item, dict):
continue
node_name = item.get("__reference_comparison_key")
if node_name:
node['name'] = node_name
node['display_name'] = node_name[2:].split("[")[0].strip().split(":")[1].strip()
node_type = classify_item_type(node_name)
node['class'] = node_type
node['program'] = node_name.split("[")[1].strip()[:-3].replace("ClientProgram:", "")
item_string = str(item)
node['content'] = get_content(item, node_type, item_string)
# Build connections and filter out self-references
refs = get_references(item_string)
node['connections'] = [r for r in refs if r != node_name]
node['order'] = "primary"
node['query'] = "False"
# Store raw and prettified JSON for consistent display/search
node['raw'] = item
try:
node_pretty = json.dumps(item, indent=2, sort_keys=True, default=str)
except Exception:
node_pretty = item_string
node['json_pretty'] = node_pretty
node['json'] = node_pretty # use prettified JSON as the stored JSON string
if "qry" in item_string:
node['query'] = "True"
my_array = []
if node_type is not None:
nodes.append(node)
return nodes
def get_content(json_obj, node_type, string):
"""Extract the content from the item name."""
if node_type == "MessageConfig":
return json_obj['message']['body'], json_obj['message']['subject'], json_obj['message']['notificationText']
if node_type == "Incentive":
return json_obj['name'], json_obj['info']
if node_type == "CustomFieldDef":
default_value = json_obj['defaultValue']
if "_dummy__formula" in string and default_value is None:
default_value = "Calculated Using Formula"
return json_obj['fieldType'], json_obj['fieldDataType'], default_value
if node_type == "ClientPageLayout":
content = ""
if 'pageLayoutElements' in json_obj:
for section in json_obj['pageLayoutElements']:
if 'HTMLContent' in section:
html_content = section['HTMLContent']
if html_content is not None:
if html_content.strip() != "":
content += html_content + '\n'
return content
return None
def classify_item_type(name):
"""Classify the item type based on its name."""
if "<<MessageConfig:" in name:
return "MessageConfig"
elif "<<ClientTopic:" in name:
return "ClientTopic"
elif "<<StandaloneFormula:" in name:
return "StandaloneFormula"
elif "<<ClientPageLayout:" in name:
return "ClientPageLayout"
elif "<<MessageCategory:" in name:
return "MessageCategory"
elif "<<CustomFieldDef:" in name:
return "CustomFieldDef"
elif "<<Incentive:" in name:
return "Incentive"
elif "<<Rule:" in name:
return "Rule"
elif "<<ClientRaffle:" in name:
return "ClientRaffle"
elif "<<ClientReward:" in name:
return "ClientReward"
elif "<<ClientProgram" in name:
return "ClientProgram"
elif "<<ClientTaskHandlerDefinition:" in name:
return "ClientTaskHandlerDefinition"
elif "<<RuleSet:" in name:
if "None" not in name:
return "RuleSet"
else:
return None
else:
return None
def get_references(string):
"""Extract references from the item string."""
references = []
for match in re.finditer(r'<<[^>]+>>', string):
reference = match.group(0).strip()
if reference and str(reference) not in references:
if classify_item_type(str(reference)) is not None:
references.append(str(reference))
return references
def create_secondary_nodes(nodes):
all_nodes = []
all_nodes_names = set()
for node in nodes:
all_nodes_names.add(node['name'])
all_nodes.append(node)
for node in all_nodes:
for connection in node['connections']:
connection = str(connection).strip()
if connection not in all_nodes_names:
all_nodes_names.add(connection)
if connection.startswith("<<") and connection.endswith(">>") and ":" in connection:
pass
else:
continue
if classify_item_type(connection) == "ClientProgram":
new_node = {
'name': connection,
'display_name': connection.split(":")[1].strip()[:-2],
'class': classify_item_type(connection),
'program': connection.split(":")[1].strip()[:-2],
'content': None,
'connections': [],
'order': "secondary",
'query': "False",
'json': None
}
else:
new_node = {
'name': connection,
'display_name': connection[2:].split("[")[0].strip().split(":")[1].strip(),
'class': classify_item_type(connection),
'program': connection.split("[")[1].strip()[:-3].replace("ClientProgram:", ""),
'content': None,
'connections': [],
'order': "secondary",
'query': "False",
'json': None
}
if new_node['class'] is not None:
all_nodes.append(new_node)
return all_nodes