{"action":"created","comment":{"url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/pulls/comments/148042392","pull_request_review_id":73224667,"id":148042392,"diff_hunk":"@@ -0,0 +1,213 @@\n+package store\n+\n+import (\n+\t\"context\"\n+\t\"errors\"\n+\t\"fmt\"\n+\t\"io\"\n+\n+\t\"github.com/ONSdigital/dp-hierarchy-api/models\"\n+\t\"github.com/ONSdigital/go-ns/log\"\n+\tbolt \"github.com/johnnadratowski/golang-neo4j-bolt-driver\"\n+\t\"github.com/johnnadratowski/golang-neo4j-bolt-driver/structures/graph\"\n+)\n+\n+const (\n+\texistStmt       = \"MATCH (i:`_hierarchy_node_%s_%s`) RETURN i LIMIT 1\"\n+\tgetHierStmt     = \"MATCH (i:`_hierarchy_node_%s_%s`) WHERE NOT (i)-[:hasParent]->() RETURN i LIMIT 1\" // TODO check if this LIMIT is valid\n+\tgetCodeStmt     = \"MATCH (i:`_hierarchy_node_%s_%s` {code:{code}}) RETURN i\"\n+\tgetChildrenStmt = \"MATCH (i:`_hierarchy_node_%s_%s` {code:{code}})<-[r:hasParent]-(child) RETURN child\"\n+\tgetParentStmt   = \"MATCH (i:`_hierarchy_node_%s_%s` {code:{code}})-[r:hasParent]->(parent) RETURN parent\"\n+\tgetAncestryStmt = \"MATCH (i:`_hierarchy_node_%s_%s` {code:{code}})-[r:hasParent *]->(parent) RETURN parent\"\n+)\n+\n+type Store struct {\n+\tdbPool bolt.ClosableDriverPool\n+}\n+\n+type neoArgMap map[string]interface{}\n+\n+type Storer interface {\n+\tClose(ctx context.Context) error\n+\tGetCodelist(hierarchy *models.Hierarchy) (string, error)\n+\tGetHierarchy(hierarchy *models.Hierarchy) (*models.Response, error)\n+\tGetCode(hierarchy *models.Hierarchy, code string) (*models.Response, error)\n+}\n+\n+func New(dbUrl string) (Storer, error) {\n+\tpool, err := bolt.NewClosableDriverPool(dbUrl, 5)\n+\tif err != nil {\n+\t\tlog.Error(err, nil)\n+\t\treturn nil, err\n+\t}\n+\treturn &Store{dbPool: pool}, nil\n+}\n+\n+func (s Store) Close(ctx context.Context) error {\n+\terrChan := make(chan error)\n+\tgo func() {\n+\t\terrChan <- s.dbPool.Close()\n+\t}()\n+\n+\tselect {\n+\tcase err := <-errChan:\n+\t\treturn err\n+\tcase <-ctx.Done():\n+\t\treturn ctx.Err()\n+\t}\n+}\n+\n+func (s Store) GetCodelist(hierarchy *models.Hierarchy) (string, error) {\n+\tneoStmt := fmt.Sprintf(existStmt, hierarchy.InstanceId, hierarchy.Dimension)\n+\tlogData := log.Data{\"statement\": neoStmt}\n+\n+\tlog.Trace(\"executing exists query\", logData)\n+\tconn, err := s.dbPool.OpenPool()\n+\tif err != nil {\n+\t\treturn \"\", err\n+\t}\n+\tdefer conn.Close()\n+\trows, err := conn.QueryNeo(neoStmt, nil)\n+\tif err != nil {\n+\t\treturn \"\", err\n+\t}\n+\tdefer rows.Close()\n+\n+\tdata, _, err := rows.All()\n+\tif len(data) == 0 {\n+\t\treturn \"\", nil\n+\t}\n+\tprops := data[0][0].(graph.Node).Properties\n+\treturn props[\"codeList\"].(string), nil","path":"store/neo4j.go","position":null,"original_position":81,"commit_id":"4e33a36f6f5cba5b03be98f8568d34e0a8d45bfc","original_commit_id":"625d419e27bb8213084e3b1948952484e4610a92","user":{"login":"gedge","id":151578,"avatar_url":"https://avatars2.githubusercontent.com/u/151578?v=4","gravatar_id":"","url":"https://api.github.com/users/gedge","html_url":"https://github.com/gedge","followers_url":"https://api.github.com/users/gedge/followers","following_url":"https://api.github.com/users/gedge/following{/other_user}","gists_url":"https://api.github.com/users/gedge/gists{/gist_id}","starred_url":"https://api.github.com/users/gedge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gedge/subscriptions","organizations_url":"https://api.github.com/users/gedge/orgs","repos_url":"https://api.github.com/users/gedge/repos","events_url":"https://api.github.com/users/gedge/events{/privacy}","received_events_url":"https://api.github.com/users/gedge/received_events","type":"User","site_admin":false},"body":"see also 2nd PR on builder","created_at":"2017-10-31T16:00:18Z","updated_at":"2017-10-31T16:00:18Z","html_url":"https://github.com/ONSdigital/dp-hierarchy-api/pull/6#discussion_r148042392","pull_request_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/pulls/6","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/pulls/comments/148042392"},"html":{"href":"https://github.com/ONSdigital/dp-hierarchy-api/pull/6#discussion_r148042392"},"pull_request":{"href":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/pulls/6"}},"in_reply_to_id":148007099},"pull_request":{"url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/pulls/6","id":149736476,"html_url":"https://github.com/ONSdigital/dp-hierarchy-api/pull/6","diff_url":"https://github.com/ONSdigital/dp-hierarchy-api/pull/6.diff","patch_url":"https://github.com/ONSdigital/dp-hierarchy-api/pull/6.patch","issue_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/issues/6","number":6,"state":"open","locked":false,"title":"Feature/unstubination robust","user":{"login":"gedge","id":151578,"avatar_url":"https://avatars2.githubusercontent.com/u/151578?v=4","gravatar_id":"","url":"https://api.github.com/users/gedge","html_url":"https://github.com/gedge","followers_url":"https://api.github.com/users/gedge/followers","following_url":"https://api.github.com/users/gedge/following{/other_user}","gists_url":"https://api.github.com/users/gedge/gists{/gist_id}","starred_url":"https://api.github.com/users/gedge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gedge/subscriptions","organizations_url":"https://api.github.com/users/gedge/orgs","repos_url":"https://api.github.com/users/gedge/repos","events_url":"https://api.github.com/users/gedge/events{/privacy}","received_events_url":"https://api.github.com/users/gedge/received_events","type":"User","site_admin":false},"body":"### What\r\n\r\nadd use of database, more robust shutdown, rather large rework of spec\r\n\r\nalso see https://github.com/ONSdigital/dp-hierarchy-builder/pull/3\r\n","created_at":"2017-10-31T09:41:31Z","updated_at":"2017-10-31T16:00:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0651b55b653fefab0d2b0b6075388e82206c7cec","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/pulls/6/commits","review_comments_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/pulls/6/comments","review_comment_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/issues/6/comments","statuses_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/statuses/4e33a36f6f5cba5b03be98f8568d34e0a8d45bfc","head":{"label":"ONSdigital:feature/unstubination-robust","ref":"feature/unstubination-robust","sha":"4e33a36f6f5cba5b03be98f8568d34e0a8d45bfc","user":{"login":"ONSdigital","id":6865137,"avatar_url":"https://avatars0.githubusercontent.com/u/6865137?v=4","gravatar_id":"","url":"https://api.github.com/users/ONSdigital","html_url":"https://github.com/ONSdigital","followers_url":"https://api.github.com/users/ONSdigital/followers","following_url":"https://api.github.com/users/ONSdigital/following{/other_user}","gists_url":"https://api.github.com/users/ONSdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/ONSdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ONSdigital/subscriptions","organizations_url":"https://api.github.com/users/ONSdigital/orgs","repos_url":"https://api.github.com/users/ONSdigital/repos","events_url":"https://api.github.com/users/ONSdigital/events{/privacy}","received_events_url":"https://api.github.com/users/ONSdigital/received_events","type":"Organization","site_admin":false},"repo":{"id":99344187,"name":"dp-hierarchy-api","full_name":"ONSdigital/dp-hierarchy-api","owner":{"login":"ONSdigital","id":6865137,"avatar_url":"https://avatars0.githubusercontent.com/u/6865137?v=4","gravatar_id":"","url":"https://api.github.com/users/ONSdigital","html_url":"https://github.com/ONSdigital","followers_url":"https://api.github.com/users/ONSdigital/followers","following_url":"https://api.github.com/users/ONSdigital/following{/other_user}","gists_url":"https://api.github.com/users/ONSdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/ONSdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ONSdigital/subscriptions","organizations_url":"https://api.github.com/users/ONSdigital/orgs","repos_url":"https://api.github.com/users/ONSdigital/repos","events_url":"https://api.github.com/users/ONSdigital/events{/privacy}","received_events_url":"https://api.github.com/users/ONSdigital/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ONSdigital/dp-hierarchy-api","description":null,"fork":false,"url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api","forks_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/forks","keys_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/teams","hooks_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/hooks","issue_events_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/issues/events{/number}","events_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/events","assignees_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/assignees{/user}","branches_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/branches{/branch}","tags_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/tags","blobs_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/statuses/{sha}","languages_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/languages","stargazers_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/stargazers","contributors_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/contributors","subscribers_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/subscribers","subscription_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/subscription","commits_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/contents/{+path}","compare_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/merges","archive_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/downloads","issues_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/issues{/number}","pulls_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/pulls{/number}","milestones_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/milestones{/number}","notifications_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/labels{/name}","releases_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/releases{/id}","deployments_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/deployments","created_at":"2017-08-04T13:13:14Z","updated_at":"2017-08-09T15:22:41Z","pushed_at":"2017-10-31T15:59:38Z","git_url":"git://github.com/ONSdigital/dp-hierarchy-api.git","ssh_url":"git@github.com:ONSdigital/dp-hierarchy-api.git","clone_url":"https://github.com/ONSdigital/dp-hierarchy-api.git","svn_url":"https://github.com/ONSdigital/dp-hierarchy-api","homepage":null,"size":217,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"cmd-develop"}},"base":{"label":"ONSdigital:cmd-develop","ref":"cmd-develop","sha":"09dc1dc461341afb7219ebbb961b8f4e3782c388","user":{"login":"ONSdigital","id":6865137,"avatar_url":"https://avatars0.githubusercontent.com/u/6865137?v=4","gravatar_id":"","url":"https://api.github.com/users/ONSdigital","html_url":"https://github.com/ONSdigital","followers_url":"https://api.github.com/users/ONSdigital/followers","following_url":"https://api.github.com/users/ONSdigital/following{/other_user}","gists_url":"https://api.github.com/users/ONSdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/ONSdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ONSdigital/subscriptions","organizations_url":"https://api.github.com/users/ONSdigital/orgs","repos_url":"https://api.github.com/users/ONSdigital/repos","events_url":"https://api.github.com/users/ONSdigital/events{/privacy}","received_events_url":"https://api.github.com/users/ONSdigital/received_events","type":"Organization","site_admin":false},"repo":{"id":99344187,"name":"dp-hierarchy-api","full_name":"ONSdigital/dp-hierarchy-api","owner":{"login":"ONSdigital","id":6865137,"avatar_url":"https://avatars0.githubusercontent.com/u/6865137?v=4","gravatar_id":"","url":"https://api.github.com/users/ONSdigital","html_url":"https://github.com/ONSdigital","followers_url":"https://api.github.com/users/ONSdigital/followers","following_url":"https://api.github.com/users/ONSdigital/following{/other_user}","gists_url":"https://api.github.com/users/ONSdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/ONSdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ONSdigital/subscriptions","organizations_url":"https://api.github.com/users/ONSdigital/orgs","repos_url":"https://api.github.com/users/ONSdigital/repos","events_url":"https://api.github.com/users/ONSdigital/events{/privacy}","received_events_url":"https://api.github.com/users/ONSdigital/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ONSdigital/dp-hierarchy-api","description":null,"fork":false,"url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api","forks_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/forks","keys_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/teams","hooks_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/hooks","issue_events_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/issues/events{/number}","events_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/events","assignees_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/assignees{/user}","branches_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/branches{/branch}","tags_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/tags","blobs_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/statuses/{sha}","languages_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/languages","stargazers_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/stargazers","contributors_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/contributors","subscribers_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/subscribers","subscription_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/subscription","commits_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/contents/{+path}","compare_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/merges","archive_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/downloads","issues_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/issues{/number}","pulls_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/pulls{/number}","milestones_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/milestones{/number}","notifications_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/labels{/name}","releases_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/releases{/id}","deployments_url":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/deployments","created_at":"2017-08-04T13:13:14Z","updated_at":"2017-08-09T15:22:41Z","pushed_at":"2017-10-31T15:59:38Z","git_url":"git://github.com/ONSdigital/dp-hierarchy-api.git","ssh_url":"git@github.com:ONSdigital/dp-hierarchy-api.git","clone_url":"https://github.com/ONSdigital/dp-hierarchy-api.git","svn_url":"https://github.com/ONSdigital/dp-hierarchy-api","homepage":null,"size":217,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"cmd-develop"}},"_links":{"self":{"href":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/pulls/6"},"html":{"href":"https://github.com/ONSdigital/dp-hierarchy-api/pull/6"},"issue":{"href":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/issues/6"},"comments":{"href":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/ONSdigital/dp-hierarchy-api/statuses/4e33a36f6f5cba5b03be98f8568d34e0a8d45bfc"}},"author_association":"NONE"}}
{"actor":{"display_login":"gedge"}}