def main(obj_data, ws_info, obj_data_v1, conf): """ Index a narrative object on save. We index the latest narratives for: - title and author - cell content - object names and types - created and updated dates - total number of cells """ # Reference for the workspace info type: # https://kbase.us/services/ws/docs/Workspace.html#typedefWorkspace.workspace_info # Reference for the object info type: # https://kbase.us/services/ws/docs/Workspace.html#typedefWorkspace.object_info obj_info = obj_data['info'] obj_id = obj_info[0] obj_metadata = obj_info[-1] if not obj_metadata: raise RuntimeError( f"Cannot index narrative: no metadata for the narrative object. Obj info: {obj_info}" ) [ws_id, _, owner, moddate, _, _, _, _, ws_metadata] = ws_info if not ws_metadata: raise RuntimeError( f"Cannot index narrative: no metadata for the workspace. WS info: {ws_info}" ) if ws_metadata.get('is_temporary') == 'true': logger.debug("Skipping narrative indexing because it is temporary") return is_narratorial = _narrative_is_narratorial(ws_metadata) narrative_title = obj_metadata.get('name') creator = obj_data['creator'] # Get all the types and names of objects in the narrative's workspace. narrative_data_objects = _fetch_objects_in_workspace(ws_id) # Extract all the data we want to index from the notebook cells raw_cells = obj_data['data'].get('cells', []) index_cells = _extract_cells(raw_cells, ws_id) result = { '_action': 'index', 'doc': { 'narrative_title': narrative_title, 'is_narratorial': is_narratorial, 'data_objects': narrative_data_objects, 'owner': owner, 'modified_at': ts_to_epoch(moddate), 'cells': index_cells, 'creator': creator, 'total_cells': len(raw_cells), 'static_narrative_saved': ws_metadata.get('static_narrative_saved'), 'static_narrative_ref': ws_metadata.get('static_narrative'), }, 'index': conf['index_name'], 'id': f"{conf['namespace']}::{ws_id}:{obj_id}", } yield result
def index_narrative(obj_data, ws_info, obj_data_v1): """ Index a narrative object on save. We index the latest narratives for: - title and author - cell content - object names and types - created and updated dates - total number of cells """ # Reference for the workspace info type: # https://kbase.us/services/ws/docs/Workspace.html#typedefWorkspace.workspace_info # Reference for the object info type: # https://kbase.us/services/ws/docs/Workspace.html#typedefWorkspace.object_info obj_info = obj_data['info'] obj_id = obj_info[0] obj_metadata = obj_info[-1] if not obj_metadata: raise RuntimeError( f"Cannot index narrative: no metadata for the narrative object. Obj info: {obj_info}" ) [ws_id, _, owner, moddate, _, _, _, _, ws_metadata] = ws_info if not ws_metadata: raise RuntimeError( f"Cannot index narrative: no metadata for the workspace. WS info: {ws_info}" ) is_temporary = _narrative_is_temporary(ws_metadata) is_narratorial = _narrative_is_narratorial(ws_metadata) narrative_title = obj_metadata.get('name') creator = obj_data['creator'] # Get all the types and names of objects in the narrative's workspace. narrative_data_objects = _fetch_objects_in_workspace(ws_id) # Extract all the data we want to index from the notebook cells raw_cells = obj_data['data'].get('cells', []) index_cells = _extract_cells(raw_cells, ws_id) result = { '_action': 'index', 'doc': { 'narrative_title': narrative_title, 'is_temporary': is_temporary, 'is_narratorial': is_narratorial, 'data_objects': narrative_data_objects, 'owner': owner, 'modified_at': ts_to_epoch(moddate), 'cells': index_cells, 'creator': creator, 'total_cells': len(raw_cells), }, 'index': _NARRATIVE_INDEX_NAME, 'id': f'{_NAMESPACE}::{ws_id}:{obj_id}', } yield result
def _save_obj_version(key, ver, info_tup, ws_info): objid = info_tup[0] wsid = info_tup[6] obj_name = info_tup[1] hsh = info_tup[8] size = info_tup[9] epoch = ts_to_epoch(info_tup[3]) logger.info(f"Saving ws_object_version with key {key}") save('ws_object_version', [{ '_key': key, 'workspace_id': wsid, 'object_id': objid, 'version': ver, 'name': obj_name, 'hash': hsh, 'size': size, 'epoch': epoch, 'deleted': False, 'is_public': ws_info[6] == 'r', }])
def _save_workspace(ws_info): """Save the ws_workspace vertex given an object info tuple.""" wsid = ws_info[0] # Workspace info tuple is as follows: # 0 1 2 3 4 5 6 7 8 # [id,name,owner,moddate,maxobjid,user_perms,globalread,lockstat,metadata] metadata = ws_info[-1] logger.info(f'Saving workspace vertex {wsid}') save( 'ws_workspace', { '_key': str(wsid), 'narr_name': metadata.get('narrative_nice_name', ''), 'owner': ws_info[2], 'max_obj_id': ws_info[4], 'lock_status': ws_info[7], 'name': ws_info[1], 'mod_epoch': ts_to_epoch(ws_info[3]), 'is_public': ws_info[6] == 'r', 'is_deleted': False, 'metadata': metadata })