def insert_single_edge(self, project, type, edge): try: retVal = self.__get_edge_parameters(project, type)[0][0] source_label = retVal['source_label'] target_label = retVal['target_label'] is_doubled = retVal['isdoubled'] except IndexError: raise interface_errors.GraphNonExistElementError( 'It is strange, the validator does not work') source_id = edge.pop('source_id') target_id = edge.pop('target_id') attributes = self.converter(dict_=edge, prefix_='', connector_=':', join_element_=', ', parenthesis_=['{', '}']) try: return self.__insert_edge(source_id, source_label, target_id, target_label, type, attributes, is_doubled)[0][0]['id'] except GraphError as ge: raise interface_errors.GraphInterfaceException( 'Unexpected exception occurred. The exception: {}'.format( str(ge)))
def delete_single_node(self, id): try: return self.__delete_node(id)[0][0]['id'] except GraphError as ge: raise interface_errors.GraphInterfaceException(str(ge)) except IndexError as ie: raise interface_errors.GraphNonExistElementError( 'Node does not exist')
def delete_single_edge_non_typed(self, source_id, target_id): try: return self.__delete_single_edge(source_id, target_id, None)[0][0]['collection'] except GraphError as ge: raise interface_errors.GraphInterfaceException( 'Unexpected error: {0}'.format(str(ge))) except IndexError: raise interface_errors.GraphNonExistElementError( 'The given edge does not exist')
def get_single_edge_typed(self, source_id, target_id, type): try: return self.__get_single_edge(source_id, target_id, type)[0][0]['edge'].properties except GraphError: raise interface_errors.GraphInterfaceException('Unexpected error') except IndexError: raise interface_errors.GraphNonExistElementError( 'The given edge does not exist')
def get_single_edge_non_typed(self, source_id, target_id): try: result = self.__get_single_edge(source_id, target_id, None)[0] retVal = [] for res in result: retVal.append(res['node'].properties) return retVal except GraphError: raise interface_errors.GraphInterfaceException('Unexpected error') except IndexError: raise interface_errors.GraphNonExistElementError( 'The given edge does not exist')
def get_bulk_node(self, type, list_of_node_ids): retVal = [] try: result = self.__get_bulk_node(type, list_of_node_ids)[0] for res in result: retVal.append(res['node'].properties) return retVal except GraphError as ge: raise interface_errors.GraphInterfaceException( "Unexpected error. The exception is {0}".format(str(ge))) except IndexError: raise interface_errors.GraphNonExistElementError( 'The requested graph nodes do not exist')
def delete_bulk_node(self, type, list_of_ids): retVal = [] try: result = self.__delete_bulk_node(type, list_of_ids)[0] for res in result: retVal.append(res['id']) return retVal except GraphError as ge: raise interface_errors.GraphInterfaceException( "Unexpected error. The exception is {0}".format(str(ge))) #It is always raised when a node has, at least, one edge except IndexError: raise interface_errors.GraphNonExistElementError( 'The requested graph nodes do not exist')
def delete_meta_node(self, project, title): try: return self.__delete_ontology_node(project, title)[0][0]['id'] except (GraphError, KeyError, IndexError): raise interface_errors.GraphNonExistElementError( 'The requested node is not exist')
def get_single_node(self, id): try: return self.__get_node(id)[0][0]['node'].properties except GraphError: raise interface_errors.GraphNonExistElementError( "The given node does not exist: {0}".format(id))