(self)
return f'Saved graph to ID: {self._resource_id}'
Save the search in the database.

        Raises:
            ValueError: if there are values missing in order to save the query.
Save the search in the database.
Save the search in the database .
def save(self):
        """Save the search in the database.

        Raises:
            ValueError: if there are values missing in order to save the query.
        """
        if not self.name:
            raise ValueError(
                'No name for the graph. Please select a name first.')

        if not self.description:
            logger.warning(
                'No description selected for graph, saving without one')

        if self._resource_id:
            resource_url = (
                f'{self.api.api_root}/sketches/{self._sketch.id}/graphs/'
                f'{self._resource_id}/')
        else:
            resource_url = (
                f'{self.api.api_root}/sketches/{self._sketch.id}/graphs/')

        cytoscape_json = nx.readwrite.json_graph.cytoscape_data(self.graph)
        elements = cytoscape_json.get('elements', [])
        element_list = []
        for group in elements:
            for element in elements[group]:
                element['group'] = group
                element_list.append(element)

        data = {
            'name': self.name,
            'graph_config': self._serialize(self.graph_config),
            'description': self.description,
            'elements': element_list,
        }

        response = self.api.session.post(resource_url, json=data)
        status = error.check_return_status(response, logger)
        if not status:
            error.error_message(
                response, 'Unable to save search', error=RuntimeError)

        response_json = error.get_response_json(response, logger)

        graph_dict = response_json.get('objects', [{}])[0]
        self._resource_id = graph_dict.get('id', 0)
        return f'Saved graph to ID: {self._resource_id}'
def save ( self ) : if not self . name : raise ValueError ( 'No name for the graph. Please select a name first.' ) if not self . description : logger . warning ( 'No description selected for graph, saving without one' ) if self . _resource_id : resource_url = ( f'{self.api.api_root}/sketches/{self._sketch.id}/graphs/' f'{self._resource_id}/' ) else : resource_url = ( f'{self.api.api_root}/sketches/{self._sketch.id}/graphs/' ) cytoscape_json = nx . readwrite . json_graph . cytoscape_data ( self . graph ) elements = cytoscape_json . get ( 'elements' , [ ] ) element_list = [ ] for group in elements : for element in elements [ group ] : element [ 'group' ] = group element_list . append ( element ) data = { 'name' : self . name , 'graph_config' : self . _serialize ( self . graph_config ) , 'description' : self . description , 'elements' : element_list , } response = self . api . session . post ( resource_url , json = data ) status = error . check_return_status ( response , logger ) if not status : error . error_message ( response , 'Unable to save search' , error = RuntimeError ) response_json = error . get_response_json ( response , logger ) graph_dict = response_json . get ( 'objects' , [ { } ] ) [ 0 ] self . _resource_id = graph_dict . get ( 'id' , 0 ) return f'Saved graph to ID: {self._resource_id}'