def _clear_tables(self): conn = g.engine.connect() conn.execute('commit') for table in Node().get_subclass_table_names(): if table != Node.__tablename__: conn.execute('delete from {}'.format(table)) for table in Edge.get_subclass_table_names(): if table != Edge.__tablename__: conn.execute('delete from {}'.format(table)) conn.execute('delete from _voided_nodes') conn.execute('delete from _voided_edges') conn.close()
def import_keywords(self): nodes = [] for keyword in self.metadata['keywords'].split(","): keyword=keyword.strip() node = self.driver.nodes().labels('keyword').props({'value':keyword}).first() if not node: doc = self.signpost.create() node = Node(label='keyword',node_id = doc.did,properties = {'value':keyword}) self.driver.node_merge(node=node) print 'create new keyword %s' % keyword nodes.append(node) return nodes
def fake_get_nodes(dids): nodes = [] for did in dids: try: file_name = files.get(did, {})["data"]["file_name"] except ValueError: file_name = did nodes.append( Node( node_id=did, label="file", acl=["open"], properties={ "file_name": file_name, "file_size": len("fake data for {}".format(did)), "md5sum": "fake_md5sum", "state": "live", }, )) return nodes
def import_metadata(self): with self.driver.session_scope(): if not self.validate_metadata(): return doc = self.signpost.create() doc.urls=[self.metadata['url']] doc.identifiers = { 'ark':self.search_identifier('ark:/31807/osdc-'+doc.did.split('-')[0]) } doc.patch() properties = self.metadata.copy() del properties['url'] del properties['keywords'] node = Node(node_id=doc.did,label='dataset',properties=properties) self.driver.node_merge(node=node) keyword_nodes = self.import_keywords() for keyword in keyword_nodes: self.driver.edge_insert(Edge(node.node_id,keyword.node_id,'member_of')) print 'metadata %s created' % doc.did