<s> """<STR_LIT>""" <EOL> from next . database_client . PermStore import PermStore <EOL> from next . api . api_util import DatabaseException <EOL> db = PermStore ( ) <EOL> class TargetMapper : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . database_id = "<STR_LIT>" <EOL> self . bucket_id = "<STR_LIT>" <EOL> return <EOL> def init_empty_target_mapping ( self , exp_uid , n ) : <EOL> """<STR_LIT>""" <EOL> doc = { '<STR_LIT>' : True , '<STR_LIT>' : exp_uid } <EOL> didSucceed , message = db . setDoc ( self . database_id , self . bucket_id , None , doc ) <EOL> if not didSucceed : <EOL> raise DatabaseException ( "<STR_LIT>" % ( message ) ) <EOL> mongotized_target_blob , didSucceed , message = db . getDocsByPattern ( self . database_id , self . bucket_id , { '<STR_LIT>' : exp_uid } ) <EOL> if not didSucceed : <EOL> raise DatabaseException ( "<STR_LIT>" % ( message ) ) <EOL> target_blob_dict = mongotized_target_blob . pop ( <NUM_LIT:0> ) <EOL> return { } <EOL> def create_target_mapping ( self , exp_uid , target_blob ) : <EOL> """<STR_LIT>""" <EOL> didSucceed , message = db . deleteDocsByPattern ( self . database_id , self . bucket_id , { '<STR_LIT>' : exp_uid , '<STR_LIT>' : True } ) <EOL> if not didSucceed : <EOL> raise DatabaseException ( "<STR_LIT>" % ( message ) ) <EOL> doc = { '<STR_LIT>' : False , '<STR_LIT>' : exp_uid } <EOL> didSucceed , message = db . setDoc ( self . database_id , self . bucket_id , None , doc ) <EOL> if not didSucceed : <EOL> raise DatabaseException ( "<STR_LIT>" % ( message ) ) <EOL> for ii in range ( len ( target_blob ) ) : <EOL> target_tmp = target_blob [ ii ] <EOL> target_id = target_tmp [ '<STR_LIT>' ] <EOL> index = ii <EOL> primary_description = target_tmp [ '<STR_LIT>' ] <EOL> primary_type = target_tmp [ '<STR_LIT>' ] <EOL> alt_type = target_tmp [ '<STR_LIT>' ] <EOL> alt_description = target_tmp [ '<STR_LIT>' ] <EOL> doc = { '<STR_LIT:index>' : index , <EOL> '<STR_LIT>' : target_id , <EOL> '<STR_LIT>' : primary_description , <EOL> '<STR_LIT>' : primary_type , <EOL> '<STR_LIT>' : alt_description , <EOL> '<STR_LIT>' : alt_type , <EOL> '<STR_LIT>' : exp_uid } <EOL> didSucceed , message = db . setDoc ( self . database_id , self . bucket_id , None , doc ) <EOL> if not didSucceed : <EOL> raise DatabaseException ( "<STR_LIT>" % ( message ) ) <EOL> mongotized_target_blob , didSucceed , message = db . getDocsByPattern ( self . database_id , self . bucket_id , { '<STR_LIT>' : exp_uid } ) <EOL> if not didSucceed : <EOL> raise DatabaseException ( "<STR_LIT>" % ( message ) ) <EOL> target_blob_dict = mongotized_target_blob . pop ( <NUM_LIT:0> ) <EOL> return target_blob_dict <EOL> def get_target_mapping ( self , exp_uid ) : <EOL> """<STR_LIT>""" <EOL> mongotized_target_blob , didSucceed , message = db . getDocsByPattern ( self . database_id , self . bucket_id , { '<STR_LIT>' : exp_uid } ) <EOL> if not didSucceed : <EOL> raise DatabaseException ( "<STR_LIT>" % ( message ) ) <EOL> for i in range ( len ( mongotized_target_blob ) ) : <EOL> if '<STR_LIT>' in mongotized_target_blob [ i ] . keys ( ) : <EOL> mongotized_target_blob . pop ( i ) <EOL> break <EOL> target_blob_dict = mongotized_target_blob <EOL> return target_blob_dict <EOL> def get_target_data ( self , exp_uid , index ) : <EOL> """<STR_LIT>""" <EOL> target_data , didSucceed , message = db . getDocsByPattern ( self . database_id , self . bucket_id , { '<STR_LIT>' : exp_uid , '<STR_LIT>' : False } ) <EOL> if not didSucceed : <EOL> raise DatabaseException ( "<STR_LIT>" % ( message ) ) <EOL> if not target_data : <EOL> return { '<STR_LIT>' : index , <EOL> '<STR_LIT>' : index , <EOL> '<STR_LIT>' : '<STR_LIT:text>' , <EOL> '<STR_LIT>' : index , <EOL> '<STR_LIT>' : '<STR_LIT:text>' } <EOL> target_data , didSucceed , message = db . getDocsByPattern ( self . database_id , self . bucket_id , { '<STR_LIT>' : exp_uid , '<STR_LIT:index>' : index } ) <EOL> if not didSucceed : <EOL> raise DatabaseException ( "<STR_LIT>" % ( message ) ) <EOL> target_data_dict = target_data . pop ( <NUM_LIT:0> ) <EOL> return target_data_dict <EOL> def get_index_given_targetID ( self , exp_uid , target_id ) : <EOL> """<STR_LIT>""" <EOL> target_data , didSucceed , message = db . getDocsByPattern ( self . database_id , self . bucket_id , { '<STR_LIT>' : exp_uid , '<STR_LIT>' : False } ) <EOL> if not didSucceed : <EOL> raise DatabaseException ( "<STR_LIT>" % ( message ) ) <EOL> if not target_data : <EOL> return target_id <EOL> got_target , didSucceed , message = db . getDocsByPattern ( self . database_id , self . bucket_id , { '<STR_LIT>' : exp_uid , '<STR_LIT>' : target_id } ) <EOL> if not didSucceed : <EOL> raise DatabaseException ( "<STR_LIT>" % ( message ) ) <EOL> got_target = got_target . pop ( <NUM_LIT:0> ) <EOL> index = got_target [ '<STR_LIT:index>' ] <EOL> return int ( index ) <EOL> def get_targetID_given_index ( self , exp_uid , index ) : <EOL> """<STR_LIT>""" <EOL> target_data , didSucceed , message = db . getDocsByPattern ( self . database_id , self . bucket_id , { '<STR_LIT>' : exp_uid , '<STR_LIT>' : True } ) <EOL> if not didSucceed : <EOL> raise DatabaseException ( "<STR_LIT>" % ( message ) ) <EOL> if not target_data : <EOL> return index <EOL> got_target , didSucceed , message = db . getDocsByPattern ( self . database_id , self . bucket_id , { '<STR_LIT>' : exp_uid , '<STR_LIT:index>' : index } ) <EOL> if not didSucceed : <EOL> raise DatabaseException ( "<STR_LIT>" % ( message ) ) <EOL> got_target = got_target . pop ( <NUM_LIT:0> ) <EOL> target_id = got_target [ '<STR_LIT>' ] <EOL> return target_id <EOL> def set_target_data ( self ) : <EOL> return '<STR_LIT>' <EOL> def delete_target_data ( self ) : <EOL> return '<STR_LIT>' <EOL> def verify_target_map_format ( self , exp_uid , target_blob ) : <EOL> for target in enumerate ( target_blob ) : <EOL> if not target [ '<STR_LIT>' ] : return False <EOL> if not target [ '<STR_LIT:index>' ] : return False <EOL> if not target [ '<STR_LIT>' ] : return False <EOL> if not target [ '<STR_LIT>' ] : return False <EOL> if not target [ '<STR_LIT>' ] : return False <EOL> if not target [ '<STR_LIT>' ] : return False <EOL> return True </s>
