def update (self, old_sfa_record, new_sfa_record, hrn, new_key):
return True
+ # callack for register/update
+ # this allows to capture changes in the relations between objects
+ # the ids below are the ones found in the 'pointer' field
+ # this can get typically called with
+ # 'slice' 'user' 'researcher' slice_id user_ids
+ # 'authority' 'user' 'pi' authority_id user_ids
+ def update_relation (self, subject_type, target_type, relation_name, subject_id, link_ids):
+ pass
+
########################################
########## aggregate oriented
########################################
# subject_record describes the subject of the relationships
# ref_record contains the target values for the various relationships we need to manage
# (to begin with, this is just the slice x person relationship)
- def update_relations (self, subject_obj, ref_obj):
+ def update_driver_relations (self, subject_obj, ref_obj):
type=subject_obj.type
- if type=='slice':
- self.update_relation(subject_obj, 'researcher', ref_obj.researcher, 'user')
+ #for (k,v) in subject_obj.__dict__.items(): print k,'=',v
+ if type=='slice' and hasattr(ref_obj,'researcher'):
+ self.update_driver_relation(subject_obj, ref_obj.researcher, 'user', 'researcher')
+ elif type=='authority' and hasattr(ref_obj,'pi'):
+ self.update_driver_relation(subject_obj,ref_obj.pi, 'user', 'pi')
# field_key is the name of one field in the record, typically 'researcher' for a 'slice' record
# hrns is the list of hrns that should be linked to the subject from now on
# target_type would be e.g. 'user' in the 'slice' x 'researcher' example
- def update_relation (self, record_obj, field_key, hrns, target_type):
+ def update_driver_relation (self, record_obj, hrns, target_type, relation_name):
# locate the linked objects in our db
subject_type=record_obj.type
subject_id=record_obj.pointer
link_id_tuples = dbsession.query(RegRecord.pointer).filter_by(type=target_type).filter(RegRecord.hrn.in_(hrns)).all()
# sqlalchemy returns named tuples for columns
link_ids = [ tuple.pointer for tuple in link_id_tuples ]
- self.driver.update_relation (subject_type, target_type, subject_id, link_ids)
+ self.driver.update_relation (subject_type, target_type, relation_name, subject_id, link_ids)
def Register(self, api, record_dict):
dbsession.commit()
# update membership for researchers, pis, owners, operators
- self.update_relations (record, record)
+ self.update_driver_relations (record, record)
return record.get_gid_object().save_to_string(save_parents=True)
dsession.commit()
# update membership for researchers, pis, owners, operators
- self.update_relations (record, new_record)
+ self.update_driver_relations (record, new_record)
return 1
####################
# plcapi works by changes, compute what needs to be added/deleted
- def update_relation (self, subject_type, target_type, subject_id, target_ids):
+ def update_relation (self, subject_type, target_type, relation_name, subject_id, target_ids):
# hard-wire the code for slice/user for now, could be smarter if needed
- if subject_type =='slice' and target_type == 'user':
+ if subject_type =='slice' and target_type == 'user' and relation_name == 'researcher':
subject=self.shell.GetSlices (subject_id)[0]
current_target_ids = subject['person_ids']
add_target_ids = list ( set (target_ids).difference(current_target_ids))
for target_id in del_target_ids:
logger.debug ("del_target_id = %s (type=%s)"%(target_id,type(target_id)))
self.shell.DeletePersonFromSlice (target_id, subject_id)
+ elif subject_type == 'authority' and target_type == 'user' and relation_name == 'pi':
+ logger.log ("WARNING: XXX todo pldriver.update_relation not implemented for the 'pi' relationship")
else:
- logger.info('unexpected relation to maintain, %s -> %s'%(subject_type,target_type))
+ logger.info('unexpected relation %s to maintain, %s -> %s'%(relation_name,subject_type,target_type))
########################################