Here is thefull code:
def get_asset_data(self,
indent=0,
offset=0,
size=17,
limit=5000,
debug=0,
**kwargs):
get_asset_data_dttm = timestamp()
if debug >= 1:
print('\t' * indent,
'get_asset_data::'.ljust(size),
get_asset_data_dttm)
rc = int(0)
messages = []
indent1 = indent+1
#######################################################################################
# Before I can get the final asset data, I need to get a list of the assets to exclude
# This will give me all of the assets for the Technical Data Asset community
#######################################################################################
userParams = {}
userParams['communityId'] = 'b23eedc6-ffa3-4c67-8974-e5d5a36b513c'
params = {}
for k, v in kwargs.items():
params[k] = v
collibraResponseTechnicalAssets = requests.get(self.collibraRestURL + '/assets',
auth=HTTPBasicAuth(self.username, self.password),
params = userParams)
# Get total asset records for technical Data Community from restAPI
myTotalTechnicalAssets= collibraResponseTechnicalAssets.json()['total']
print("Total domain records: " + str(myTotalTechnicalAssets))
# Get the number of times the 'for' loop has to execute to get all the records
loopCountTA = (-(-myTotalTechnicalAssets//1000))
print("Total domain loops: " + str(loopCountTA))
#quit()
############################################################################
# Now to go back and loop for loopCountTA times to create a file of assets
# I don't want
############################################################################
technical_data_assets_set = {''}
for i in range(loopCountTA + 1):
#for i in range(loopCountTA + 1):
userParams = {}
userParams['communityId'] = 'b23eedc6-ffa3-4c67-8974-e5d5a36b513c'
userParams['offset'] = i * 1000
params = {}
for k, v in kwargs.items():
params[k] = v
collibraResponseTechnicalAssets2 = requests.get(self.collibraRestURL + '/assets',
auth=HTTPBasicAuth(self.username, self.password),
params = userParams)
#print(userParams)
technical_data_assets = create_response_tuple(collibraResponseTechnicalAssets2)
result_list_TA = technical_data_assets[1].get("results")
for j in range(len(result_list_TA)):
if 'domain' in result_list_TA[j]:
technical_data_assets_set.add(result_list_TA[j]['domain'].get('id'))
#print(technical_data_assets_set)
#quit()
#######################################################################################
# I need a loop counter for the assets
#######################################################################################
params = {}
for k, v in kwargs.items():
params[k] = v
collibraResponseAssetsCount = requests.get(self.collibraRestURL + '/assets',
auth=HTTPBasicAuth(self.username, self.password))
# Get total asset records
myTotalAssetsCount = collibraResponseAssetsCount.json()['total']
print("Total asset records: " + str(myTotalAssetsCount))
# Get the number of times the 'for' loop has to execute to get all the records
loopCountAssets = (-(-myTotalAssetsCount // 1000))
print("Total asset loops: " + str(loopCountAssets))
#quit()
#####################################################################################
# Now get asset data
#####################################################################################
#for k in range(loopCountAssets + 1):
for ii in range(2):
userParams2 = {}
userParams2['limit'] = 5000
userParams2['offset'] = ii * 1000
params = {}
for k, v in kwargs.items():
params[k] = v
collibraResponseAssets = requests.get(self.collibraRestURL + '/assets',
auth=HTTPBasicAuth(self.username, self.password),
params = userParams2)
asset_data = create_response_tuple(collibraResponseAssets)
if asset_data[0] != 200:
messages.append('ERROR: Asset Data Collibra extract has encountered errors!')
http_error(asset_data, messages, indent=indent1, debug=1)
quit()
result_list_Assets = asset_data[1].get("results")
if result_list_Assets[ii]['domain'].get('id') not in technical_data_assets_set:
modified_dictionary = {'id': '',
'createdBy': '',
'createdOn': '',
'lastModifiedBy': '',
'lastModifiedOn': '',
'system': '',
'resourceType': '',
'name': '',
'displayName': '',
'articulationScore': float(0),
'excludedFromAutoHyperlinking': bool,
'domain': {'id': '', 'resourceType':'', 'name':''},
'type': {'id':'', 'resourceType':'', 'name':''},
'status': {'id': '', 'resourceType': '', 'name': ''},
'avgRating': float(0),
'ratingsCount': int(0)}
modified_dictionary['id'] = result_list_Assets[ii]['id']
modified_dictionary['createdBy'] = result_list_Assets[ii]['createdBy']
modified_dictionary['createdOn'] = result_list_Assets[ii]['createdOn']
modified_dictionary['lastModifiedBy'] = result_list_Assets[ii]['lastModifiedBy']
modified_dictionary['lastModifiedOn'] = result_list_Assets[ii]['lastModifiedOn']
modified_dictionary['system'] = result_list_Assets[ii]['system']
modified_dictionary['resourceType'] = result_list_Assets[ii]['resourceType']
modified_dictionary['name'] = result_list_Assets[ii]['name']
modified_dictionary['displayName'] = result_list_Assets[ii]['displayName']
modified_dictionary['articulationScore'] = result_list_Assets[ii].get('articulationScore',0)
modified_dictionary['excludedFromAutoHyperlinking'] = result_list_Assets[ii]['excludedFromAutoHyperlinking']
modified_domain = {'id': '', 'resourceType': '', 'name': ''}
if 'domain' in result_list_Assets[ii]:
modified_domain['id'] = result_list_Assets[ii]['domain'].get('id')
modified_domain['resourceType'] = result_list_Assets[ii]['domain'].get('resourceType')
modified_domain['name'] = result_list_Assets[ii]['domain'].get('name')
modified_dictionary['domain'] = modified_domain
if debug >= 3: print('domain type:', type(modified_dictionary['domain']))
modified_type = {'id': '', 'resourceType': '', 'name': ''}
if 'type' in result_list_Assets[ii]:
modified_type['id'] = result_list_Assets[ii]['type'].get('id')
modified_type['resourceType'] = result_list_Assets[ii]['type'].get('resourceType')
modified_type['name'] = result_list_Assets[ii]['type'].get('name')
modified_dictionary['type'] = modified_type
if debug >= 3: print('type:', type(modified_dictionary['type']))
modified_status = {'id': '', 'resourceType': '', 'name': ''}
if 'status' in result_list_Assets[ii]:
modified_status['id'] = result_list_Assets[ii]['status'].get('id')
modified_status['resourceType'] = result_list_Assets[ii]['status'].get('resourceType')
modified_status['name'] = result_list_Assets[ii]['status'].get('name')
modified_dictionary['status'] = modified_status
if debug >= 3: print('status type:', type(modified_dictionary['status']))
modified_dictionary['avgRating'] = result_list_Assets[ii]['avgRating']
modified_dictionary['ratingsCount'] = result_list_Assets[ii]['ratingsCount']
result_list_Assets[ii] = modified_dictionary
if debug >= 3: print()
#dump(result_list_Assets)
#quit()
if debug >= 2:
print('\t\t\tAsset Data Status Code: ', asset_data[0])
if debug >= 4:
print('\t\t\tAsset Data: ', asset_data)
#dump(asset_data[1], caller='List of all Asset Data fields')
#dump(asset_data[1].get("results")[0], caller='Contents of one individual Asset Data result record')
if abs(debug) >= 5:
timestamp(get_asset_data_dttm,
label='get_asset_data',
indent=indent,
debug=1)
return(rc, messages, asset_data)