aepp 0.5.1.post1__py3-none-any.whl → 0.5.2.post1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
aepp/fieldgroupmanager.py CHANGED
@@ -39,7 +39,7 @@ class FieldGroupManager:
39
39
  config: Union[dict,ConnectObject] = aepp.config.config_object,
40
40
  description:str="powered by aepp",
41
41
  full:bool=None,
42
- localFolder:str=None,
42
+ localFolder:str | list | None=None,
43
43
  sandbox:str=None,
44
44
  **kwargs
45
45
  )->None:
@@ -71,13 +71,16 @@ class FieldGroupManager:
71
71
  elif config is not None and localFolder is None:
72
72
  self.schemaAPI = Schema(config=config)
73
73
  elif localFolder is not None:
74
- self.localfolder = Path(localFolder)
75
- self.datatypeFolder = self.localfolder / 'datatype'
76
- self.datatypeGlobalFolder = self.datatypeFolder / 'global'
77
- self.fieldgroupFolder = self.localfolder / 'fieldgroup'
78
- self.fieldgroupGlobalFolder = self.fieldgroupFolder / 'global'
79
- self.descriptorFolder = self.localfolder / 'descriptor'
80
- if self.localfolder.exists() is False:
74
+ if isinstance(localFolder, str):
75
+ self.localfolder = [Path(localFolder)]
76
+ elif isinstance(localFolder, list):
77
+ self.localfolder = [Path(folder) for folder in localFolder]
78
+ self.datatypeFolder = [folder / 'datatype' for folder in self.localfolder]
79
+ self.datatypeGlobalFolder = [folder / 'global' for folder in self.datatypeFolder]
80
+ self.fieldgroupFolder = [folder / 'fieldgroup' for folder in self.localfolder]
81
+ self.fieldgroupGlobalFolder = [folder / 'global' for folder in self.fieldgroupFolder]
82
+ self.descriptorFolder = [folder / 'descriptor' for folder in self.localfolder]
83
+ if any([folder.exists() is False for folder in self.localfolder]):
81
84
  raise Exception(f"The local folder {self.localfolder} does not exist. Please create it and extract your sandbox before using it.")
82
85
  self.schemaAPI = None
83
86
  if self.schemaAPI is not None:
@@ -95,9 +98,11 @@ class FieldGroupManager:
95
98
  if fieldGroup.get('meta:tenantNamespace') is not None:
96
99
  self.tenantId = fieldGroup.get('meta:tenantNamespace')
97
100
  elif self.localfolder is not None:
98
- config_json = json.load(FileIO(self.localfolder / 'config.json'))
99
- if config_json.get('tenantId',None) is not None:
100
- self.tenantId = config_json.get('tenantId')
101
+ for folder in self.localfolder:
102
+ config_json = json.load(FileIO(folder / 'config.json'))
103
+ if config_json.get('tenantId',None) is not None:
104
+ self.tenantId = config_json.get('tenantId')
105
+ break
101
106
  else:### Should not be a problem as the element without a tenantId are not supposed to change
102
107
  self.tenantId = " "
103
108
  if fieldGroup is not None:
@@ -126,28 +131,40 @@ class FieldGroupManager:
126
131
  self.fieldGroup = tmp_def
127
132
  self.EDITABLE = False
128
133
  elif self.localfolder is not None:
129
- for json_file in self.fieldgroupFolder.glob('*.json'):
130
- tmp_def = json.load(FileIO(json_file))
131
- if tmp_def.get('$id') == fieldGroup['$id'] or tmp_def.get('meta:altId') == fieldGroup.get('meta:altId') or tmp_def.get('title') == fieldGroup.get('title'):
132
- self.fieldGroup = tmp_def
133
- if self.tenantId[1:] in self.fieldGroup.get('$id'): ## custom field group
134
- if '/datatypes/' in str(self.fieldGroup):
135
- dataTypeSearch = f"(https://ns.adobe.com/{self.tenantId[1:]}/datatypes/[0-9a-z]+?)'"
136
- dataTypes = re.findall(dataTypeSearch,str(self.fieldGroup))
137
- for dt in dataTypes:
138
- dt_manager = DataTypeManager(dt,localFolder=self.localfolder,sandbox=self.sandbox,tenantId=self.tenantId)
139
- self.dataTypes[dt_manager.id] = dt_manager.title
140
- self.dataTypeManagers[dt_manager.title] = dt_manager
141
- else: ## OOTB field group
142
- if 'properties' in self.fieldGroup.keys():
143
- self.fieldGroup['definitions'] = self.fieldGroup['properties']
144
- if self.fieldGroup == {}:
145
- for json_file in self.fieldgroupGlobalFolder.glob('*.json'):
134
+ found = False
135
+ for folder in self.fieldgroupFolder:
136
+ for json_file in folder.glob('*.json'):
146
137
  tmp_def = json.load(FileIO(json_file))
147
138
  if tmp_def.get('$id') == fieldGroup['$id'] or tmp_def.get('meta:altId') == fieldGroup.get('meta:altId') or tmp_def.get('title') == fieldGroup.get('title'):
148
139
  self.fieldGroup = tmp_def
149
- if 'properties' in self.fieldGroup.keys():
150
- self.fieldGroup['definitions'] = self.fieldGroup['properties']
140
+ if self.tenantId[1:] in self.fieldGroup.get('$id'): ## custom field group
141
+ if '/datatypes/' in str(self.fieldGroup):
142
+ dataTypeSearch = f"(https://ns.adobe.com/{self.tenantId[1:]}/datatypes/[0-9a-z]+?)'"
143
+ dataTypes = re.findall(dataTypeSearch,str(self.fieldGroup))
144
+ for dt in dataTypes:
145
+ dt_manager = DataTypeManager(dt,localFolder=self.localfolder,sandbox=self.sandbox,tenantId=self.tenantId)
146
+ self.dataTypes[dt_manager.id] = dt_manager.title
147
+ self.dataTypeManagers[dt_manager.title] = dt_manager
148
+ else: ## OOTB field group
149
+ if 'properties' in self.fieldGroup.keys():
150
+ self.fieldGroup['definitions'] = self.fieldGroup['properties']
151
+ found = True
152
+ break
153
+ if found:
154
+ break
155
+ if self.fieldGroup == {}:
156
+ found = False
157
+ for folder in self.fieldgroupGlobalFolder:
158
+ for json_file in folder.glob('*.json'):
159
+ tmp_def = json.load(FileIO(json_file))
160
+ if tmp_def.get('$id') == fieldGroup['$id'] or tmp_def.get('meta:altId') == fieldGroup.get('meta:altId') or tmp_def.get('title') == fieldGroup.get('title'):
161
+ self.fieldGroup = tmp_def
162
+ if 'properties' in self.fieldGroup.keys():
163
+ self.fieldGroup['definitions'] = self.fieldGroup['properties']
164
+ found = True
165
+ break
166
+ if found:
167
+ break
151
168
  self.EDITABLE = False
152
169
  else: ## if definitions key not present
153
170
  if 'properties' in self.fieldGroup.keys():
@@ -166,19 +183,24 @@ class FieldGroupManager:
166
183
  self.fieldGroup = self.schemaAPI.getFieldGroup(self.fieldGroup['$id'],full=True)
167
184
  self.EDITABLE = True
168
185
  elif self.localfolder is not None: ## looking into local folder
169
- for json_file in self.fieldgroupFolder.glob('*.json'): ## only custom Field groups: TO DO check for OOTB FG without definition
170
- tmp_def = json.load(FileIO(json_file))
171
- if tmp_def.get('$id') == fieldGroup['$id'] or tmp_def.get('meta:altId') == fieldGroup.get('meta:altId') or tmp_def.get('title') == fieldGroup.get('title'):
172
- self.fieldGroup = tmp_def
173
- if self.tenantId[1:] in self.fieldGroup.get('$id'): ## custom field group
174
- if '/datatypes/' in str(self.fieldGroup):
175
- dataTypeSearch = f"(https://ns.adobe.com/{self.tenantId[1:]}/datatypes/[0-9a-z]+?)'"
176
- dataTypes = re.findall(dataTypeSearch,str(self.fieldGroup))
177
- for dt in dataTypes:
178
- dt_manager = DataTypeManager(dt,localFolder=self.localfolder,sandbox=self.sandbox,tenantId=self.tenantId)
179
- self.dataTypes[dt_manager.id] = dt_manager.title
180
- self.dataTypeManagers[dt_manager.title] = dt_manager
181
-
186
+ found = False
187
+ for folder in self.fieldgroupFolder:
188
+ for json_file in folder.glob('*.json'): ## only custom Field groups: TO DO check for OOTB FG without definition
189
+ tmp_def = json.load(FileIO(json_file))
190
+ if tmp_def.get('$id') == fieldGroup['$id'] or tmp_def.get('meta:altId') == fieldGroup.get('meta:altId') or tmp_def.get('title') == fieldGroup.get('title'):
191
+ self.fieldGroup = tmp_def
192
+ if self.tenantId[1:] in self.fieldGroup.get('$id'): ## custom field group
193
+ if '/datatypes/' in str(self.fieldGroup):
194
+ dataTypeSearch = f"(https://ns.adobe.com/{self.tenantId[1:]}/datatypes/[0-9a-z]+?)'"
195
+ dataTypes = re.findall(dataTypeSearch,str(self.fieldGroup))
196
+ for dt in dataTypes:
197
+ dt_manager = DataTypeManager(dt,localFolder=self.localfolder,sandbox=self.sandbox,tenantId=self.tenantId)
198
+ self.dataTypes[dt_manager.id] = dt_manager.title
199
+ self.dataTypeManagers[dt_manager.title] = dt_manager
200
+ found = True
201
+ break
202
+ if found:
203
+ break
182
204
  else:
183
205
  raise ValueError("The field group definition provided does not contains the 'definitions' key. Please check the field group.")
184
206
  else:
@@ -208,26 +230,38 @@ class FieldGroupManager:
208
230
  self.fieldGroup = tmp_def
209
231
  self.EDITABLE = False
210
232
  elif self.localfolder is not None:
211
- for json_file in self.fieldgroupFolder.glob('*.json'):
212
- tmp_def = json.load(FileIO(json_file))
213
- if tmp_def.get('$id') == fieldGroup or tmp_def.get('meta:altId') == fieldGroup or tmp_def.get('title') == fieldGroup:
214
- self.fieldGroup = tmp_def
215
- if tmp_def.get('meta:tenantNamespace',None) is not None:
216
- self.tenantId = tmp_def.get('meta:tenantNamespace')
217
- if '/datatypes/' in str(self.fieldGroup):
218
- dataTypeSearch = f"(https://ns.adobe.com/{self.tenantId[1:]}/datatypes/[0-9a-z]+?)'"
219
- dataTypes = re.findall(dataTypeSearch,str(self.fieldGroup.get('definitions')))
220
- for file in self.datatypeFolder.glob('*.json'):
221
- tmp_def = json.load(FileIO(file))
222
- if tmp_def.get('$id') in dataTypes or tmp_def.get('meta:altId') in dataTypes:
223
- dt_manager = DataTypeManager(tmp_def,localFolder=self.localfolder,sandbox=self.sandbox,tenantId=self.tenantId)
224
- self.dataTypes[dt_manager.id] = dt_manager.title
225
- self.dataTypeManagers[dt_manager.title] = dt_manager
226
- if self.fieldGroup == {}: ## looking into the global folder
227
- for json_file in self.fieldgroupGlobalFolder.glob('*.json'):
233
+ found = False
234
+ for folder in self.fieldgroupFolder:
235
+ for json_file in folder.glob('*.json'):
228
236
  tmp_def = json.load(FileIO(json_file))
229
237
  if tmp_def.get('$id') == fieldGroup or tmp_def.get('meta:altId') == fieldGroup or tmp_def.get('title') == fieldGroup:
230
- self.fieldGroup = tmp_def
238
+ self.fieldGroup = tmp_def
239
+ if tmp_def.get('meta:tenantNamespace',None) is not None:
240
+ self.tenantId = tmp_def.get('meta:tenantNamespace')
241
+ if '/datatypes/' in str(self.fieldGroup):
242
+ dataTypeSearch = f"(https://ns.adobe.com/{self.tenantId[1:]}/datatypes/[0-9a-z]+?)'"
243
+ dataTypes = re.findall(dataTypeSearch,str(self.fieldGroup.get('definitions')))
244
+ for file in self.datatypeFolder.glob('*.json'):
245
+ tmp_def = json.load(FileIO(file))
246
+ if tmp_def.get('$id') in dataTypes or tmp_def.get('meta:altId') in dataTypes:
247
+ dt_manager = DataTypeManager(tmp_def,localFolder=self.localfolder,sandbox=self.sandbox,tenantId=self.tenantId)
248
+ self.dataTypes[dt_manager.id] = dt_manager.title
249
+ self.dataTypeManagers[dt_manager.title] = dt_manager
250
+ found = True
251
+ break
252
+ if found:
253
+ break
254
+ if self.fieldGroup == {}: ## looking into the global folder
255
+ found = False
256
+ for folder in self.fieldgroupGlobalFolder:
257
+ for json_file in folder.glob('*.json'):
258
+ tmp_def = json.load(FileIO(json_file))
259
+ if tmp_def.get('$id') == fieldGroup or tmp_def.get('meta:altId') == fieldGroup or tmp_def.get('title') == fieldGroup:
260
+ self.fieldGroup = tmp_def
261
+ found = True
262
+ break
263
+ if found:
264
+ break
231
265
  else:
232
266
  raise ValueError("the element pass is not a field group definition")
233
267
  else:
@@ -1689,10 +1723,11 @@ class FieldGroupManager:
1689
1723
  res = self.schemaAPI.getDescriptors(prop=f"xdm:sourceSchema=={self.id}")
1690
1724
  elif self.localfolder is not None:
1691
1725
  res = []
1692
- for json_file in self.descriptorFolder.glob('*.json'):
1693
- tmp_def = json.load(FileIO(json_file))
1694
- if tmp_def.get('xdm:sourceSchema') == self.id:
1695
- res.append(tmp_def)
1726
+ for folder in self.descriptorFolder:
1727
+ for json_file in folder.glob('*.json'):
1728
+ tmp_def = json.load(FileIO(json_file))
1729
+ if tmp_def.get('xdm:sourceSchema') == self.id:
1730
+ res.append(tmp_def)
1696
1731
  else:
1697
1732
  raise Exception("Require a schema API connection or local folder. Pass the instance of a Schema class or import a configuration file.")
1698
1733
  return res
aepp/schemamanager.py CHANGED
@@ -39,7 +39,7 @@ class SchemaManager:
39
39
  schemaClass:str="https://ns.adobe.com/xdm/context/profile",
40
40
  config: Union[dict,ConnectObject] = aepp.config.config_object,
41
41
  description : str = "powered by aepp",
42
- localFolder:str=None,
42
+ localFolder:str|list|None=None,
43
43
  sandbox:str=None,
44
44
  **kwargs
45
45
  )->None:
@@ -57,7 +57,7 @@ class SchemaManager:
57
57
  Possible default value: "https://ns.adobe.com/xdm/context/experienceevent", "https://ns.adobe.com/xdm/context/segmentdefinition"
58
58
  config : OPTIONAL : The config object in case you want to override the configuration.
59
59
  description : OPTIONAL : To provide a description to your schema
60
- localFolder : OPTIONAL : If you want to use local storage to create all the connections between schema and field groups, classes and datatypes
60
+ localFolder : OPTIONAL : If you want to use local storage to create all the connections between schema and field groups, classes and datatypes. Can be a set of folders.
61
61
  sandbox : OPTIONAL : If you use localFolder, you can specific the sandbox.
62
62
  """
63
63
  self.fieldGroupIds=[]
@@ -72,17 +72,20 @@ class SchemaManager:
72
72
  elif config is not None and localFolder is None:
73
73
  self.schemaAPI = Schema(config=config)
74
74
  elif localFolder is not None:
75
- self.localfolder = Path(localFolder)
76
- if self.localfolder.exists() is False:
77
- raise Exception(f"The local folder {self.localfolder} does not exist. Please create it and extract your sandbox before using it.")
75
+ if isinstance(localFolder, str):
76
+ self.localfolder = [Path(localFolder)]
77
+ else:
78
+ self.localfolder = [Path(folder) for folder in localFolder]
79
+ if any([folder.exists() is False for folder in self.localfolder]):
80
+ raise Exception(f"One of the local folders {self.localfolder} does not exist. Please create it and extract your sandbox before using it.")
78
81
  self.schemaAPI = None
79
- self.schemaFolder = self.localfolder / 'schema'
80
- self.fieldgroupFolder = self.localfolder / 'fieldgroup'
81
- self.fieldgroupGlobalFolder = self.fieldgroupFolder / 'global'
82
- self.classFolder = self.localfolder / 'class'
83
- self.descriptorFolder = self.localfolder / 'descriptor'
84
- if self.schemaFolder.exists() is False or self.fieldgroupFolder.exists() is False or self.classFolder.exists() is False:
85
- raise Exception(f"{self.schemaFolder} or {self.fieldgroupFolder} or {self.classFolder} does not exist. Please create it and extract your sandbox before using it.")
82
+ self.schemaFolder = [folder / 'schema' for folder in self.localfolder]
83
+ self.fieldgroupFolder = [folder / 'fieldgroup' for folder in self.localfolder]
84
+ self.fieldgroupGlobalFolder = [folder / 'global' for folder in self.fieldgroupFolder]
85
+ self.classFolder = [folder / 'class' for folder in self.localfolder]
86
+ self.descriptorFolder = [folder / 'descriptor' for folder in self.localfolder]
87
+ if any([folder.exists() is False for folder in self.schemaFolder]) or any([folder.exists() is False for folder in self.fieldgroupFolder]) or any([folder.exists() is False for folder in self.classFolder]):
88
+ raise Exception(f"One of the folders {self.schemaFolder} or {self.fieldgroupFolder} or {self.classFolder} does not exist. Please create it and extract your sandbox before using it.")
86
89
  else:
87
90
  raise Exception("You need to provide a schemaAPI instance or a config object to connect to the API or a local folder to use the local storage")
88
91
  if self.schemaAPI is not None:
@@ -99,9 +102,11 @@ class SchemaManager:
99
102
  elif kwargs.get('tenantId') is not None:
100
103
  self.tenantId = f"{kwargs.get('tenantId')}"
101
104
  elif self.localfolder is not None:
102
- config_json = json.load(FileIO(self.localfolder / 'config.json'))
103
- if config_json.get('tenantId',None) is not None:
104
- self.tenantId = config_json.get('tenantId')
105
+ for folder in self.localfolder:
106
+ config_json = json.load(FileIO(folder / 'config.json'))
107
+ if config_json.get('tenantId',None) is not None:
108
+ self.tenantId = config_json.get('tenantId')
109
+ break
105
110
  else: ### Should not be a problem as the element without a tenantId are not supposed to change
106
111
  self.tenantId = " "
107
112
  if type(schema) == dict:
@@ -113,32 +118,47 @@ class SchemaManager:
113
118
  if self.schemaAPI is not None:
114
119
  self.schema = self.schemaAPI.getSchema(self.schema['$id'],full=False,schema_type='xed')
115
120
  elif self.localfolder is not None:
116
- for json_file in self.schemaFolder.glob('*.json'):
117
- tmp_def = json.load(FileIO(json_file))
118
- if tmp_def.get('$id') == self.schema['$id'] or tmp_def.get('meta:altId') == self.schema.get('meta:altId') or tmp_def.get('title') == self.schema.get('title'):
119
- self.schema = tmp_def
120
- if self.schema.get('meta:tenantNamespace') is not None:
121
- self.tenantId = f"_{self.schema.get('meta:tenantNamespace')}"
121
+ found = False
122
+ for folder in self.schemaFolder:
123
+ for json_file in folder.glob('*.json'):
124
+ tmp_def = json.load(FileIO(json_file))
125
+ if tmp_def.get('$id') == self.schema['$id'] or tmp_def.get('meta:altId') == self.schema.get('meta:altId') or tmp_def.get('title') == self.schema.get('title'):
126
+ self.schema = tmp_def
127
+ if self.schema.get('meta:tenantNamespace') is not None:
128
+ self.tenantId = f"_{self.schema.get('meta:tenantNamespace')}"
129
+ found = True
130
+ break
131
+ if found:
122
132
  break
123
133
  self.fieldGroupIds = [obj['$ref'] for obj in allOf if ('/mixins/' in obj['$ref'] or '/experience/' in obj['$ref'] or '/context/' in obj['$ref']) and obj['$ref'] != self.classId]
124
134
  self.classIds = [self.classId]
125
135
  for ref in self.fieldGroupIds:
126
136
  if '/mixins/' in ref and self.tenantId[1:] in ref:
127
137
  if self.localfolder is not None:
128
- for json_file in self.fieldgroupFolder.glob('*.json'):
129
- tmp_def = json.load(FileIO(json_file))
130
- if tmp_def.get('$id') == ref:
131
- definition = tmp_def
138
+ found = False
139
+ for folder in self.fieldgroupFolder:
140
+ for json_file in folder.glob('*.json'):
141
+ tmp_def = json.load(FileIO(json_file))
142
+ if tmp_def.get('$id') == ref:
143
+ definition = tmp_def
144
+ found = True
145
+ break
146
+ if found:
132
147
  break
133
148
  elif self.schemaAPI is not None:
134
149
  definition = self.schemaAPI.getFieldGroup(ref,full=False)
135
150
  fgM = FieldGroupManager(fieldGroup=definition,schemaAPI=self.schemaAPI,localFolder=localFolder,tenantId=self.tenantId,sandbox=self.sandbox)
136
151
  else:
137
152
  if self.localfolder is not None:
138
- for json_file in self.fieldgroupGlobalFolder.glob('*.json'):
139
- tmp_def = json.load(FileIO(json_file))
140
- if tmp_def.get('$id') == ref:
141
- definition = tmp_def
153
+ found = False
154
+ for folder in self.fieldgroupFolder:
155
+ for json_file in folder.glob('*.json'):
156
+ tmp_def = json.load(FileIO(json_file))
157
+ if tmp_def.get('$id') == ref:
158
+ definition = tmp_def
159
+ found = True
160
+ break
161
+ if found:
142
162
  break
143
163
  elif self.schemaAPI is not None:
144
164
  definition = self.schemaAPI.getFieldGroup(ref,full=False)
@@ -158,17 +178,22 @@ class SchemaManager:
158
178
  self.fieldGroupIds = [obj.get('$ref','') for obj in allOf if ('/mixins/' in obj.get('$ref','') or '/experience/' in obj.get('$ref','') or '/context/' in obj.get('$ref','')) and obj.get('$ref','') != self.classId]
159
179
  self.classIds = [self.classId]
160
180
  elif localFolder is not None:
161
- for json_file in self.schemaFolder.glob('*.json'):
162
- tmp_def = json.load(FileIO(json_file))
163
- if tmp_def.get('$id') == schema or tmp_def.get('meta:altId') == schema or schema == tmp_def.get('title'):
164
- self.schema = tmp_def
165
- self.requiredFields = set([el.replace('@','_').replace('xdm:','') for el in self.schema.get('required',[])])
166
- self.__setAttributes__(self.schema)
167
- allOf = self.schema.get("allOf",[])
168
- self.fieldGroupIds = [obj.get('$ref','') for obj in allOf if ('/mixins/' in obj.get('$ref','') or '/experience/' in obj.get('$ref','') or '/context/' in obj.get('$ref','')) and obj.get('$ref','') != self.classId]
169
- self.classIds = [self.classId]
170
- if self.schema.get('meta:tenantNamespace') is not None:
171
- self.tenantId = self.schema.get('meta:tenantNamespace')
181
+ found = False
182
+ for folder in self.schemaFolder:
183
+ for json_file in folder.glob('*.json'):
184
+ tmp_def = json.load(FileIO(json_file))
185
+ if tmp_def.get('$id') == schema or tmp_def.get('meta:altId') == schema or schema == tmp_def.get('title'):
186
+ self.schema = tmp_def
187
+ self.requiredFields = set([el.replace('@','_').replace('xdm:','') for el in self.schema.get('required',[])])
188
+ self.__setAttributes__(self.schema)
189
+ allOf = self.schema.get("allOf",[])
190
+ self.fieldGroupIds = [obj.get('$ref','') for obj in allOf if ('/mixins/' in obj.get('$ref','') or '/experience/' in obj.get('$ref','') or '/context/' in obj.get('$ref','')) and obj.get('$ref','') != self.classId]
191
+ self.classIds = [self.classId]
192
+ if self.schema.get('meta:tenantNamespace') is not None:
193
+ self.tenantId = self.schema.get('meta:tenantNamespace')
194
+ found = True
195
+ break
196
+ if found:
172
197
  break
173
198
  else:
174
199
  raise Exception("You need to provide a schemaAPI instance or a localFolder to use the local storage")
@@ -178,31 +203,51 @@ class SchemaManager:
178
203
  if self.schemaAPI is not None:
179
204
  definition = self.schemaAPI.getFieldGroup(ref,full=False)
180
205
  elif self.localfolder is not None:
181
- for json_file in self.fieldgroupFolder.glob('*.json'):
182
- tmp_def = json.load(FileIO(json_file))
183
- if tmp_def.get('$id') == ref:
184
- definition = tmp_def
185
- break
186
- if definition is None:
187
- for json_file in self.fieldgroupGlobalFolder.glob('*.json'):
206
+ found = False
207
+ for folder in self.fieldgroupFolder:
208
+ for json_file in folder.glob('*.json'):
188
209
  tmp_def = json.load(FileIO(json_file))
189
210
  if tmp_def.get('$id') == ref:
190
211
  definition = tmp_def
212
+ found = True
213
+ break
214
+ if found:
215
+ break
216
+ found = False
217
+ if definition is None:
218
+ for folder in self.fieldgroupGlobalFolder:
219
+ for json_file in folder.glob('*.json'):
220
+ tmp_def = json.load(FileIO(json_file))
221
+ if tmp_def.get('$id') == ref:
222
+ definition = tmp_def
223
+ found = True
224
+ break
225
+ if found:
191
226
  break
192
227
  else:
193
228
  if self.schemaAPI is not None:
194
229
  definition = self.schemaAPI.getFieldGroup(ref,full=False)
195
230
  elif self.localfolder is not None:
196
- for json_file in self.fieldgroupFolder.glob('*.json'):
197
- tmp_def = json.load(FileIO(json_file))
198
- if tmp_def.get('$id') == ref:
199
- definition = tmp_def
200
- break
201
- if definition is None:
202
- for json_file in self.fieldgroupGlobalFolder.glob('*.json'):
231
+ found = False
232
+ for folder in self.fieldgroupFolder:
233
+ for json_file in folder.glob('*.json'):
203
234
  tmp_def = json.load(FileIO(json_file))
204
235
  if tmp_def.get('$id') == ref:
205
236
  definition = tmp_def
237
+ found = True
238
+ break
239
+ if found:
240
+ break
241
+ found = False
242
+ if definition is None:
243
+ for folder in self.fieldgroupGlobalFolder:
244
+ for json_file in folder.glob('*.json'):
245
+ tmp_def = json.load(FileIO(json_file))
246
+ if tmp_def.get('$id') == ref:
247
+ definition = tmp_def
248
+ found = True
249
+ break
250
+ if found:
206
251
  break
207
252
  if 'properties' in definition.keys():
208
253
  definition['definitions'] = definition['properties']
@@ -210,12 +255,17 @@ class SchemaManager:
210
255
  self.fieldGroupsManagers[fgM.title] = fgM
211
256
  for clas in self.classIds:
212
257
  if self.localfolder is not None:
213
- for json_file in self.classFolder.glob('*.json'):
214
- tmp_def = json.load(FileIO(json_file))
215
- if tmp_def.get('$id') == clas:
216
- self.classId = tmp_def['$id']
217
- self.schemaClass = tmp_def['$id']
218
- clsM = ClassManager(tmp_def,schemaAPI=self.schemaAPI,localFolder=localFolder,tenantId=self.tenantId,sandbox=self.sandbox)
258
+ found = False
259
+ for folder in self.classFolder:
260
+ for json_file in folder.glob('*.json'):
261
+ tmp_def = json.load(FileIO(json_file))
262
+ if tmp_def.get('$id') == clas:
263
+ self.classId = tmp_def['$id']
264
+ self.schemaClass = tmp_def['$id']
265
+ clsM = ClassManager(tmp_def,schemaAPI=self.schemaAPI,localFolder=localFolder,tenantId=self.tenantId,sandbox=self.sandbox)
266
+ found = True
267
+ break
268
+ if found:
219
269
  break
220
270
  elif self.schemaAPI is not None:
221
271
  clsM = ClassManager(clas,schemaAPI=self.schemaAPI,localFolder=localFolder,tenantId=self.tenantId,sandbox=self.sandbox)
@@ -243,20 +293,31 @@ class SchemaManager:
243
293
  definition = self.schemaAPI.getFieldGroup(fgId,full=False)
244
294
  elif self.localfolder is not None:
245
295
  definition = None
246
- fieldGroupPath = self.localfolder / 'fieldgroup'
247
- if fieldGroupPath.exists() is False:
248
- raise Exception(f"The local folder {fieldGroupPath} does not exist. Please create it and extract your sandbox before using it.")
249
- for json_file in fieldGroupPath.glob('*.json'):
250
- tmp_def = json.load(FileIO(json_file))
251
- if tmp_def.get('$id') == fgId:
252
- definition = tmp_def
253
- break
254
- if definition is None:
255
- for json_file in self.fieldgroupGlobalFolder.glob('*.json'):
296
+ found = False
297
+ for fieldGroupPath in self.fieldgroupFolder:
298
+ if fieldGroupPath.exists() is False:
299
+ raise Exception(f"The local folder {fieldGroupPath} does not exist. Please create it and extract your sandbox before using it.")
300
+ for json_file in fieldGroupPath.glob('*.json'):
256
301
  tmp_def = json.load(FileIO(json_file))
257
- if tmp_def.get('$id') == ref:
302
+ if tmp_def.get('$id') == fgId:
258
303
  definition = tmp_def
259
- break
304
+ found = True
305
+ break
306
+ if found:
307
+ break
308
+ if definition is None:
309
+ found = False
310
+ for fieldGroupPath in self.fieldgroupGlobalFolder:
311
+ if fieldGroupPath.exists() is False:
312
+ raise Exception(f"The local folder {fieldGroupPath} does not exist. Please create it and extract your sandbox before using it.")
313
+ for json_file in fieldGroupPath.glob('*.json'):
314
+ tmp_def = json.load(FileIO(json_file))
315
+ if tmp_def.get('$id') == fgId:
316
+ definition = tmp_def
317
+ found = True
318
+ break
319
+ if found:
320
+ break
260
321
  fgM = FieldGroupManager(definition,schemaAPI=self.schemaAPI, localFolder=localFolder,tenantId=self.tenantId,sandbox=self.sandbox)
261
322
  self.fieldGroupsManagers[fgM.title] = fgM
262
323
  elif fieldGroups[0] == dict:
@@ -805,12 +866,13 @@ class SchemaManager:
805
866
  elif self.localfolder is not None:
806
867
  res = []
807
868
  fieldGroupsIds = [fg.id for fg in list(self.fieldGroupsManagers.values())]
808
- for json_file in self.descriptorFolder.glob('*.json'):
809
- tmp_def = json.load(FileIO(json_file))
810
- if tmp_def.get('xdm:sourceSchema') == self.id:
811
- res.append(tmp_def)
812
- elif tmp_def.get('xdm:sourceSchema') in fieldGroupsIds:
813
- res.append(tmp_def)
869
+ for folder in self.descriptorFolder:
870
+ for json_file in folder.glob('*.json'):
871
+ tmp_def = json.load(FileIO(json_file))
872
+ if tmp_def.get('xdm:sourceSchema') == self.id:
873
+ res.append(tmp_def)
874
+ elif tmp_def.get('xdm:sourceSchema') in fieldGroupsIds:
875
+ res.append(tmp_def)
814
876
  else:
815
877
  raise Exception("No API connection set and no local folder provided. No descriptors can be retrieved.")
816
878
  return res