def copy_object(self, ref, target_ws_id, target_ws_name, target_name, src_info): # There should be some logic related to DataPalettes if (not target_ws_id) and (not target_ws_name): raise ValueError("Neither target workspace ID nor name is defined") if not src_info: src_info_tuple = self.ws.get_object_info_new({'objects': [{'ref': ref}], 'includeMetadata': 0})[0] src_info = ServiceUtils.objectInfoToObject(src_info_tuple) type_name = src_info['typeModule'] + '.' + src_info['typeName'] type_config = self.DATA_PALETTES_TYPES.get(type_name) if type_config is not None: # Copy with DataPaletteService if target_name: raise ValueError("'target_name' cannot be defined for DataPalette copy") target_ws_name_or_id = self._get_workspace_name_or_id(target_ws_id, target_ws_name) self.dps_cache.call_method("add_to_palette", [{'workspace': target_ws_name_or_id, 'new_refs': [{'ref': ref}]}], self.token) return {'info': src_info} else: if not target_name: target_name = src_info['name'] obj_info_tuple = self.ws.copy_object({'from': {'ref': ref}, 'to': {'wsid': target_ws_id, 'workspace': target_ws_name, 'name': target_name}}) obj_info = ServiceUtils.objectInfoToObject(obj_info_tuple) return {'info': obj_info}
def _completeNewNarrative(self, workspaceId, objectId, importData, is_temporary, title, num_cells): """ 'Completes' the new narrative by updating workspace metadata with the required fields and copying in data from the importData list of references. """ new_meta = { 'narrative': str(objectId), 'is_temporary': is_temporary, 'searchtags': 'narrative', 'cell_count': str(num_cells) } if is_temporary == 'false' and title is not None: new_meta['narrative_nice_name'] = title self.ws.alter_workspace_metadata({'wsi': {'id': workspaceId}, 'new': new_meta}) # copy_to_narrative: if importData: objectsToCopy = [{'ref': x} for x in importData] infoList = self.ws.get_object_info_new({'objects': objectsToCopy, 'includeMetadata': 0}) for item in infoList: objectInfo = ServiceUtils.objectInfoToObject(item) self.copy_object(objectInfo['ref'], workspaceId, None, None, objectInfo) return self.ws.get_workspace_info({'id': workspaceId})
def _create_temp_narrative(self, cells, parameters, importData, includeIntroCell, title): # Migration to python of JavaScript class from https://github.com/kbase/kbase-ui/blob/4d31151d13de0278765a69b2b09f3bcf0e832409/src/client/modules/plugins/narrativemanager/modules/narrativeManager.js#L414 narr_id = int(round(time.time() * 1000)) workspaceName = self.user_id + ':narrative_' + str(narr_id) narrativeName = "Narrative." + str(narr_id) ws = self.ws ws_info = ws.create_workspace({'workspace': workspaceName, 'description': ''}) [narrativeObject, metadataExternal] = self._fetchNarrativeObjects( workspaceName, cells, parameters, includeIntroCell, title ) is_temporary = 'true' if title is not None and title != 'Untitled': is_temporary = 'false' metadataExternal['is_temporary'] = is_temporary objectInfo = ws.save_objects({'workspace': workspaceName, 'objects': [{'type': 'KBaseNarrative.Narrative', 'data': narrativeObject, 'name': narrativeName, 'meta': metadataExternal, 'provenance': [{'script': 'NarrativeManager.py', 'description': 'Created new ' + 'Workspace/Narrative bundle.'}], 'hidden': 0}]})[0] objectInfo = ServiceUtils.objectInfoToObject(objectInfo) ws_info = self._completeNewNarrative(ws_info[0], objectInfo['id'], importData, is_temporary, title, len(narrativeObject['cells'])) return { 'workspaceInfo': ServiceUtils.workspaceInfoToObject(ws_info), 'narrativeInfo': objectInfo }
def find_report_from_object(self, upa): #TODO: # 1. make sure upa's real. # first, fetch object references (without data) ref_list = self.ws_client.list_referencing_objects([{"ref": upa}])[0] # scan it for a report. # if we find at least one, return them # if we find 0, test if it's a copy, and search upstream. if len(ref_list): report_upas = list() for ref_info in ref_list: if "KBaseReport.Report" in ref_info[2]: report_upas.append( ServiceUtils.objectInfoToObject(ref_info)['ref']) if len(report_upas): return self.build_output(upa, report_upas) else: return self.find_report_from_copy_source(upa) else: return self.find_report_from_copy_source(upa)
def _completeNewNarrative(self, workspaceId, objectId, importData): self.ws.alter_workspace_metadata({ 'wsi': { 'id': workspaceId }, 'new': { 'narrative': str(objectId), 'is_temporary': 'true' } }) # copy_to_narrative: if not importData: return objectsToCopy = [{'ref': x} for x in importData] infoList = self.ws.get_object_info_new({ 'objects': objectsToCopy, 'includeMetadata': 0 }) for item in infoList: objectInfo = ServiceUtils.objectInfoToObject(item) self.copy_object(objectInfo['ref'], workspaceId, None, None, objectInfo)