Beispiel #1
0
 def copy_object(self, ref, target_ws_id, target_ws_name, target_name,
                 src_info):
     """
     Copies an object from one workspace to another.
     """
     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.object_info_to_object(src_info_tuple)
     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.object_info_to_object(obj_info_tuple)
     return {'info': obj_info}
Beispiel #2
0
    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.object_info_to_object(item)
                self.copy_object(objectInfo['ref'], workspaceId, None, None,
                                 objectInfo)

        return self.ws.get_workspace_info({'id': workspaceId})
Beispiel #3
0
    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.object_info_to_object(objectInfo)
        ws_info = self._completeNewNarrative(ws_info[0], objectInfo['id'],
                                             importData, is_temporary, title,
                                             len(narrativeObject['cells']))
        return {
            'workspaceInfo': ServiceUtils.workspace_info_to_object(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.object_info_to_object(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)