Skip to content

Commit

Permalink
Added reportValidation option.
Browse files Browse the repository at this point in the history
Set the Entry_RCB value in the Entry_Generated_File.
  • Loading branch information
serbanvoinea committed Feb 28, 2024
1 parent 8c2fec3 commit 8b91473
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def load(config_filename):
else:
hatrac_namespace = 'hatrac/{}/pdb'.format(hatrac_namespace)

reportValidation = cfg.get('reportValidation', 'Yes')
email_file = cfg.get('mail', None)
if not email_file or not os.path.isfile(email_file):
logger.error('email file must be provided and exist.')
Expand Down Expand Up @@ -203,6 +204,7 @@ def load(config_filename):
export_order_by=export_order_by, \
combo1_columns=combo1_columns, \
dictSdb=dictSdb, \
reportValidation=reportValidation, \
CifCheck=CifCheck, \
hatrac_namespace=hatrac_namespace, \
entry=entry, \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def __init__(self, **kwargs):
self.credentials = kwargs.get("credentials")
self.validation_dir = kwargs.get("validation_dir")
self.timeout = kwargs.get("timeout")
self.reportValidation = True if kwargs.get("reportValidation")=='Yes' else False
self.store = HatracStore(
self.scheme,
self.host,
Expand Down Expand Up @@ -209,6 +210,31 @@ def getUserId(self, schema, table, rid):
self.logger.error('%s' % ''.join(traceback.format_exception(et, ev, tb)))
return None

"""
Get the user_id
"""
def getUserRCB(self, schema, table, rid):
try:
"""
Query for detecting the user email
"""
url = '/attribute/{}:{}/RID={}/RCB'.format(urlquote(schema), urlquote(table), urlquote(rid))
self.logger.debug('Query user_id URL: "{}"'.format(url))

resp = self.catalog.get(url)
resp.raise_for_status()
rows = resp.json()
if len(rows) == 1:
row = resp.json()[0]
return row['RCB']
else:
return None
except:
et, ev, tb = sys.exc_info()
self.logger.error('got exception "%s"' % str(ev))
self.logger.error('%s' % ''.join(traceback.format_exception(et, ev, tb)))
return None

"""
Send Linux email notification
"""
Expand Down Expand Up @@ -1890,6 +1916,7 @@ def validateExportmmCIF(self, input_dir, filename, year, entry_id, rid, user, pr
self.cleanupDataScratch()
return (1, 'Can not cleanup the entry file tables')

entry_RCB = self.getUserRCB('PDB', 'entry', rid)
currentDirectory=os.getcwd()
os.chdir('{}'.format(input_dir))
args = [self.CifCheck, '-f', '{}/{}'.format(input_dir, filename), '-dictSdb', self.dictSdb]
Expand Down Expand Up @@ -1986,6 +2013,7 @@ def validateExportmmCIF(self, input_dir, filename, year, entry_id, rid, user, pr
'File_Bytes': file_size,
'File_MD5': hexa_md5,
'Structure_Id': entry_id,
'Entry_RCB': entry_RCB,
'File_Type': 'mmCIF',
'mmCIF_Schema_Version': urlquote(self.mmCIF_Schema_Version)
}
Expand Down Expand Up @@ -2237,6 +2265,7 @@ def report_validation(self, rid, entry_id, user, user_id):
"""
Get the System Generated mmCIF File
"""
entry_RCB = self.getUserRCB('PDB', 'entry', rid)
url = f'/entity/PDB:entry/RID={rid}/PDB:Entry_Generated_File/File_Type=mmCIF'
self.logger.debug(f'Query URL: {url}')
resp = self.catalog.get(url)
Expand Down Expand Up @@ -2319,6 +2348,7 @@ def report_validation(self, rid, entry_id, user, user_id):
'File_Bytes': file_size,
'File_MD5': hexa_md5,
'Structure_Id': entry_id,
'Entry_RCB': entry_RCB,
'File_Type': file_type
}
if self.createEntity('PDB:Entry_Generated_File', row, rid, user) == None:
Expand Down Expand Up @@ -2373,6 +2403,7 @@ def generate_JSON_mmCIF_content(self, rid, entry_id, user, user_id):
"""
Get the System Generated mmCIF File
"""
entry_RCB = self.getUserRCB('PDB', 'entry', rid)
url = f'/entity/PDB:entry/RID={rid}/PDB:Entry_Generated_File/File_Type=mmCIF'
self.logger.debug(f'Query URL: {url}')
resp = self.catalog.get(url)
Expand Down Expand Up @@ -2433,6 +2464,7 @@ def generate_JSON_mmCIF_content(self, rid, entry_id, user, user_id):
'File_Bytes': file_size,
'File_MD5': hexa_md5,
'Structure_Id': entry_id,
'Entry_RCB': entry_RCB,
'File_Type': 'JSON: mmCIF content'
}
if self.createEntity('PDB:Entry_Generated_File', row, rid, user) == None:
Expand Down Expand Up @@ -2602,17 +2634,28 @@ def addReleaseRecords(self, rid, hold=False, user_id=None):
'File_Bytes': file_size
},
user)
if self.report_validation(rid, entry_id, user, user_id) != (None, None, None):
if self.generate_JSON_mmCIF_content(rid, entry_id, user, user_id) != None:
self.updateAttributes('PDB',
'entry',
rid,
["Process_Status", "Workflow_Status"],
{'RID': rid,
'Process_Status': Process_Status_Terms['SUCCESS'],
'Workflow_Status': 'REL' if hold==False else 'HOLD'
},
user)
if self.reportValidation:
if self.report_validation(rid, entry_id, user, user_id) != (None, None, None):
if self.generate_JSON_mmCIF_content(rid, entry_id, user, user_id) != None:
self.updateAttributes('PDB',
'entry',
rid,
["Process_Status", "Workflow_Status"],
{'RID': rid,
'Process_Status': Process_Status_Terms['SUCCESS'],
'Workflow_Status': 'REL' if hold==False else 'HOLD'
},
user)
else:
self.updateAttributes('PDB',
'entry',
rid,
["Process_Status", "Workflow_Status"],
{'RID': rid,
'Process_Status': Process_Status_Terms['SUCCESS'],
'Workflow_Status': 'REL' if hold==False else 'HOLD'
},
user)
except:
et, ev, tb = sys.exc_info()
self.logger.error('got unexpected exception "%s"' % str(ev))
Expand Down

0 comments on commit 8b91473

Please sign in to comment.