def test_get_provenance_history(self):
        # in general, the display id (ex: TEST0010-LK-1-1-1) will dictate the corresponding
        # number of entity entries returned.  Basically, the entity entry count should equal the number of hyphens
        # in the display id plus one.  For example, TEST0010 will have 1 entity entry.  TEST0010-LK will have two: one for the donor TEST0010
        # and one for the organ TEST0010-LK.
        confdata = Provenance.load_config_file()
        conn = Neo4jConnection(confdata['neo4juri'], confdata['neo4jusername'],
                               confdata['neo4jpassword'])
        driver = conn.get_driver()
        donor_list = Entity.get_entities_by_type(driver, 'Donor')
        prov = Provenance(confdata['appclientid'], confdata['appclientsecret'],
                          confdata['UUID_WEBSERVICE_URL'])

        # walk through the first 5 donors and test them
        for x in range(6):
            history_data_str = prov.get_provenance_history(
                driver, donor_list[x])
            history_data = eval(history_data_str)
            self.assertEqual(len(history_data['entity']), 1)

        sample_list = Entity.get_entities_by_type(driver, 'Sample')
        # walk through the first 20 samples and test them
        for x in range(20):
            sample_item = Entity.get_entity(driver, sample_list[x])
            history_data_str = prov.get_provenance_history(
                driver, sample_list[x])
            history_data = eval(history_data_str)
            display_id = sample_item['hubmap_identifier']
            hypen_count = str(display_id).count('-')
            self.assertEqual(len(history_data['entity']), hypen_count + 1)
Beispiel #2
0
    def get_provenance_data_object(self, token, groupUUID=None):
        provenance_group = None
        try:
            if groupUUID != None:
                provenance_group = self.get_group_by_identifier(groupUUID)
            else:
                #manually find the group id given the current user:
                group_uuid = None
                entity = Entity(self.provenance_config['APP_CLIENT_ID'],
                                self.provenance_config['APP_CLIENT_SECRET'],
                                self.provenance_config['UUID_WEBSERVICE_URL'])
                group_list = entity.get_user_groups(token)
                for grp in group_list:
                    if grp['generateuuid'] == True:
                        groupUUID = grp['uuid']
                        # if provenance_group is already set, this means the user belongs to more than one writable group
                        if provenance_group != None:
                            ValueError(
                                'Error: Current user is a member of multiple groups allowed to create new entities.  The user must select which one to use'
                            )
                        provenance_group = self.get_group_by_identifier(
                            groupUUID)

                        #TODO: THIS IS HARDCODED!!  WE NEED TO CHANGE THIS TO TRACK TEST GROUPS DIFFERENTLY

                        # for now if the group is the IEC Testing group, keep looking for a different group
                        # only use the IEC Testing group if no other writable group is found for the user
                        # NOTE: this code will simply return the first writable group it encounters
                        if groupUUID != '5bd084c8-edc2-11e8-802f-0e368f3075e8':
                            break
                if groupUUID == None:
                    raise ValueError(
                        'Unauthorized: Current user is not a member of a group allowed to create new entities'
                    )
        except ValueError as ve:
            raise ve
        ret_provenance_group = {
            HubmapConst.PROVENANCE_GROUP_UUID_ATTRIBUTE:
            groupUUID,
            HubmapConst.PROVENANCE_GROUP_NAME_ATTRIBUTE:
            provenance_group['displayname']
        }
        authcache = None
        if AuthHelper.isInitialized() == False:
            authcache = AuthHelper.create(
                self.provenance_config['appclientid'],
                self.provenance_config['appclientsecret'])
        else:
            authcache = AuthHelper.instance()
        userinfo = authcache.getUserInfo(token, True)
        ret_provenance_group[
            HubmapConst.PROVENANCE_SUB_ATTRIBUTE] = userinfo['sub']
        ret_provenance_group[
            HubmapConst.PROVENANCE_USER_EMAIL_ATTRIBUTE] = userinfo['email']
        ret_provenance_group[
            HubmapConst.
            PROVENANCE_USER_DISPLAYNAME_ATTRIBUTE] = userinfo['name']
        return ret_provenance_group
Beispiel #3
0
def write_data_to_neo4j(conf_data, token, data_dict):
    conn = Neo4jConnection(conf_data['NEO4J_SERVER'],
                           conf_data['NEO4J_USERNAME'],
                           conf_data['NEO4J_PASSWORD'])
    driver = conn.get_driver()
    with driver.session() as session:
        tx = None
        try:
            tx = session.begin_transaction()
            for dict_item in data_dict:
                current_uuid = []
                try:
                    current_uuid = Entity.get_uuid_list(
                        conf_data['UUID_WEBSERVICE_URL'], token, [dict_item])
                except ValueError as ve:
                    print("Unable to resolve UUID for: " + str(dict_item))
                    continue
                # remove single quotes and replace with double quotes
                metadata_entry = str(data_dict[dict_item]).replace('\'', '"')
                stmt = "MATCH (e)-[:{has_metadata_rel}]-(m) WHERE e.{uuid_attr} = '{uuid}' SET m += {{ {metadata_attr} : '{metadata_entry}' }}".format(
                    has_metadata_rel=HubmapConst.HAS_METADATA_REL,
                    uuid_attr=HubmapConst.UUID_ATTRIBUTE,
                    uuid=current_uuid[0],
                    metadata_attr=HubmapConst.METADATA_ATTRIBUTE,
                    metadata_entry=metadata_entry)
                print('Executing stmt: ' + stmt)
                tx.run(stmt)
        except Exception as e:
            print("Exception encountered: " + str(e))
            tx.rollback()
        tx.commit()
Beispiel #4
0
def call_index_process(conf_data, token, data_dict):
    #reindex this node in elasticsearch
    for dict_item in data_dict:
        current_uuid = []
        try:
            try:
                current_uuid = Entity.get_uuid_list(
                    conf_data['UUID_WEBSERVICE_URL'], token, [dict_item])
            except ValueError as ve:
                print("Unable to resolve UUID for: " + str(dict_item))
                continue
            rspn = requests.put(
                conf_data['SEARCH_WEBSERVICE_URL'] + "/reindex/" +
                current_uuid[0],
                headers={'Authorization': 'Bearer ' + str(token)})
        except:
            print("Error happened when calling reindex web service")
Beispiel #5
0
 def get_collection(self, driver, uuid):
     try:
         return Entity.get_entity(driver, uuid)
     except BaseException as be:
         pprint(be)
         raise be
Beispiel #6
0
 def get_metadata_by_source(driver, identifier): 
     try:
         return Entity.get_entities_by_relationship(driver, identifier, HubmapConst.HAS_METADATA_REL)
     except BaseException as be:
         pprint(be)
         raise be
Beispiel #7
0
 def get_metadata(driver, identifier): 
     try:
         return Entity.get_entity(driver, identifier)
     except BaseException as be:
         pprint(be)
         raise be