cleanup update_relation a bit on the driver side
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 11 May 2012 16:22:41 +0000 (18:22 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 11 May 2012 16:22:41 +0000 (18:22 +0200)
sfa/managers/driver.py
sfa/managers/registry_manager.py
sfa/plc/pldriver.py

index cdd6fae..d6a81be 100644 (file)
@@ -57,6 +57,15 @@ class Driver:
     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
     ########################################
index 12aea4e..fe9d2e9 100644 (file)
@@ -246,15 +246,18 @@ class RegistryManager:
     # 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
@@ -262,7 +265,7 @@ class RegistryManager:
         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):
     
@@ -335,7 +338,7 @@ class RegistryManager:
         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)
     
@@ -383,7 +386,7 @@ class RegistryManager:
             dsession.commit()
         
         # update membership for researchers, pis, owners, operators
-        self.update_relations (record, new_record)
+        self.update_driver_relations (record, new_record)
         
         return 1 
     
index e0c6e3b..07273ca 100644 (file)
@@ -525,9 +525,9 @@ class PlDriver (Driver):
 
     ####################
     # 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))
@@ -539,8 +539,10 @@ class PlDriver (Driver):
             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))
 
         
     ########################################