77 del self[key] |
77 del self[key] |
78 |
78 |
79 |
79 |
80 class AbstractSource(object): |
80 class AbstractSource(object): |
81 """an abstract class for sources""" |
81 """an abstract class for sources""" |
|
82 # does the source copy data into the system source, or is it a *true* source |
|
83 # (i.e. entities are not stored physically here) |
|
84 copy_based_source = False |
82 |
85 |
83 # boolean telling if modification hooks should be called when something is |
86 # boolean telling if modification hooks should be called when something is |
84 # modified in this source |
87 # modified in this source |
85 should_call_hooks = True |
88 should_call_hooks = True |
86 # boolean telling if the repository should connect to this source during |
89 # boolean telling if the repository should connect to this source during |
202 |
205 |
203 def init_creating(self): |
206 def init_creating(self): |
204 """method called by the repository once ready to create a new instance""" |
207 """method called by the repository once ready to create a new instance""" |
205 pass |
208 pass |
206 |
209 |
207 def init(self, activated, session=None): |
210 def init(self, activated, source_entity): |
208 """method called by the repository once ready to handle request. |
211 """method called by the repository once ready to handle request. |
209 `activated` is a boolean flag telling if the source is activated or not. |
212 `activated` is a boolean flag telling if the source is activated or not. |
210 """ |
213 """ |
211 pass |
214 pass |
212 |
215 |
319 # card 1 relation ? ...) |
322 # card 1 relation ? ...) |
320 if self.support_relation(rtype): |
323 if self.support_relation(rtype): |
321 return rtype in self.cross_relations |
324 return rtype in self.cross_relations |
322 return rtype not in self.dont_cross_relations |
325 return rtype not in self.dont_cross_relations |
323 |
326 |
324 def before_entity_insertion(self, session, lid, etype, eid): |
327 def before_entity_insertion(self, session, lid, etype, eid, sourceparams): |
325 """called by the repository when an eid has been attributed for an |
328 """called by the repository when an eid has been attributed for an |
326 entity stored here but the entity has not been inserted in the system |
329 entity stored here but the entity has not been inserted in the system |
327 table yet. |
330 table yet. |
328 |
331 |
329 This method must return the an Entity instance representation of this |
332 This method must return the an Entity instance representation of this |
332 entity = self.repo.vreg['etypes'].etype_class(etype)(session) |
335 entity = self.repo.vreg['etypes'].etype_class(etype)(session) |
333 entity.eid = eid |
336 entity.eid = eid |
334 entity.cw_edited = EditedEntity(entity) |
337 entity.cw_edited = EditedEntity(entity) |
335 return entity |
338 return entity |
336 |
339 |
337 def after_entity_insertion(self, session, lid, entity): |
340 def after_entity_insertion(self, session, lid, entity, sourceparams): |
338 """called by the repository after an entity stored here has been |
341 """called by the repository after an entity stored here has been |
339 inserted in the system table. |
342 inserted in the system table. |
340 """ |
343 """ |
341 pass |
344 pass |
|
345 |
|
346 def _load_mapping(self, session=None, **kwargs): |
|
347 if not 'CWSourceSchemaConfig' in self.schema: |
|
348 self.warning('instance is not mapping ready') |
|
349 return |
|
350 if session is None: |
|
351 _session = self.repo.internal_session() |
|
352 else: |
|
353 _session = session |
|
354 try: |
|
355 for schemacfg in _session.execute( |
|
356 'Any CFG,CFGO,S WHERE ' |
|
357 'CFG options CFGO, CFG cw_schema S, ' |
|
358 'CFG cw_for_source X, X eid %(x)s', {'x': self.eid}).entities(): |
|
359 self.add_schema_config(schemacfg, **kwargs) |
|
360 finally: |
|
361 if session is None: |
|
362 _session.close() |
342 |
363 |
343 def add_schema_config(self, schemacfg, checkonly=False): |
364 def add_schema_config(self, schemacfg, checkonly=False): |
344 """added CWSourceSchemaConfig, modify mapping accordingly""" |
365 """added CWSourceSchemaConfig, modify mapping accordingly""" |
345 msg = schemacfg._cw._("this source doesn't use a mapping") |
366 msg = schemacfg._cw._("this source doesn't use a mapping") |
346 raise ValidationError(schemacfg.eid, {None: msg}) |
367 raise ValidationError(schemacfg.eid, {None: msg}) |