# # # did validate # else: # # inform the user of the success # print('Validation of ' + object_id + ' succeeded.') # # # post the new object(s). SHOULD HANDLE ERRORS GRACEFULLY # response = new_ENCODE(object_collection,new_object) # if object is not found, verify and post it if (old_object.get(u'title') == u'Not Found') | (old_object.get(u'title') == u'Home'): # clean object of unpatchable or nonexistent properties. SHOULD INFORM USER OF ANYTHING THAT DOESN"T GET POSTED. new_object = CleanJSON(new_object,object_schema,'POST') new_object = FlatJSON(new_object,keys) print(new_object) # test the new object if ValidJSON(object_type,object_id,new_object,keys): # post the new object(s). SHOULD HANDLE ERRORS GRACEFULLY new_object = CleanJSON(new_object,object_schema,'POST') response = new_ENCODE(object_type,new_object,keys) object_check = GetENCODE(str(response[u'@graph'][0][u'@id']),keys) print(object_check[u'@id'], object_check[u'uuid']) # if object is found, check for differences and patch it if needed/valid. elif put_status: # clean object of unpatchable or nonexistent properties. SHOULD INFORM USER OF ANYTHING THAT DOESN"T GET PUT. new_object = CleanJSON(new_object,object_schema,'POST')
email = "*****@*****.**" # Stanford accounts won't work! password = "******" spreadname = 'Import Test Sheet' rowsize = 2 colsize = 52 # load object SHOULD HANDLE ERRORS GRACEFULLY print('Opening ' + data_file) object_list = ReadJSON(data_file) # find out what types of objects you have. use as worksheet names. # also, change all json object values to strings typelist = [] for json_object in object_list: json_object = FlatJSON(json_object, keys) typetemp = str(json_object['@type'][0]) typelist.append(typetemp) for name, value in json_object.items(): if type(value) is list: if value == []: json_object[name] = '' elif type(value[0]) is dict: json_object[name] = str(value) else: json_object[name] = ', '.join(value) elif (type(value) is int) | (type(value) is float): json_object[name] = str(value) typelist = list(set(typelist)) typelist.sort()
#if '.json' in object_filename: # load object SHOULD HANDLE ERRORS GRACEFULLY print('Opening ' + data_file) json_object = ReadJSON('objects/' + data_file) # if the returned json object is not a list, put it in one if type(json_object) is dict: object_list = [] object_list.append(json_object) elif type(json_object) is list: object_list = json_object for new_object in object_list: new_object = FlatJSON(new_object,keys) # define object parameters. NEEDS TO RUN A CHECK TO CONFIRM THESE EXIST FIRST. object_type = str(new_object[u'@type'][0]) object_id = str(new_object[u'@id']) object_uuid = str(new_object[u'uuid']) object_name = str(new_object[u'accession']) # check to see if object already exists # PROBLEM: SHOULD CHECK UUID AND NOT USE ANY SHORTCUT METADATA THAT MIGHT NEED TO CHANGE # BUT CAN'T USE UUID IF NEW... HENCE PROBLEM old_object = FlatJSON(get_ENCODE(object_id,keys),keys) # # test the validity of new object # if not ValidJSON(object_type,object_id,new_object): # # get relevant schema
#if '.json' in object_filename: # load object SHOULD HANDLE ERRORS GRACEFULLY print('Opening ' + data_file) json_object = ReadJSON('objects/' + data_file) # if the returned json object is not a list, put it in one if type(json_object) is dict: object_list = [] object_list.append(json_object) elif type(json_object) is list: object_list = json_object for new_object in object_list: new_object = FlatJSON(new_object, keys) # define object parameters. NEEDS TO RUN A CHECK TO CONFIRM THESE EXIST FIRST. object_type = str(new_object[u'@type'][0]) object_id = str(new_object[u'@id']) object_uuid = str(new_object[u'uuid']) object_name = str(new_object[u'accession']) # check to see if object already exists # PROBLEM: SHOULD CHECK UUID AND NOT USE ANY SHORTCUT METADATA THAT MIGHT NEED TO CHANGE # BUT CAN'T USE UUID IF NEW... HENCE PROBLEM old_object = FlatJSON(get_ENCODE(object_id, keys), keys) # # test the validity of new object # if not ValidJSON(object_type,object_id,new_object): # # get relevant schema
# search criteria search_value_string = 'GM12893' search_key_string = 'biosample_term_name' # file name for saved objects find_file = 'find.json' # retrieve the relevant objects master_objects = ElasticSearchJSON(server,query,object_type,hitnum) # flatten objects and select based on search criteria object_list = [] for master_object in master_objects: master_object = FlatJSON(master_object,keys) for key,value in master_object.items(): if search_key_string in str(key): #print(key) if type(value) is unicode: if search_value_string in str(value): print('Object ' + master_object[u'accession'] + ' Selected. ' + str(key) + ' - ' + value) object_list.append(master_object) break if type(value) is list: for entry in value: if search_value_string in str(entry): print('Object ' + master_object[u'accession'] + ' Selected. ' + str(key) + ' - ' + entry) object_list.append(master_object) break
email = "*****@*****.**" # Stanford accounts won't work! password = "******" spreadname = 'Import Test Sheet' rowsize = 2 colsize = 52 # load object SHOULD HANDLE ERRORS GRACEFULLY print('Opening ' + data_file) object_list = ReadJSON(data_file) # find out what types of objects you have. use as worksheet names. # also, change all json object values to strings typelist = [] for json_object in object_list: json_object = FlatJSON(json_object,keys) typetemp = str(json_object['@type'][0]) typelist.append(typetemp) for name,value in json_object.items(): if type(value) is list: if value == []: json_object[name] = '' elif type(value[0]) is dict: json_object[name] = str(value) else: json_object[name] = ', '.join(value) elif (type(value) is int) | (type(value) is float): json_object[name] = str(value) typelist = list(set(typelist)) typelist.sort()