{"action":"created","comment":{"url":"https://api.github.com/repos/MUSIT-Norway/musit/pulls/comments/105622187","pull_request_review_id":26509166,"id":105622187,"diff_hunk":"@@ -0,0 +1,206 @@\n+package repositories.dao\n+\n+import com.google.inject.{Inject, Singleton}\n+import models.events.AnalysisResults.AnalysisResult\n+import models.events.{Analysis, AnalysisCollection, AnalysisEvent}\n+import no.uio.musit.MusitResults.{MusitDbError, MusitResult, MusitSuccess}\n+import no.uio.musit.models.{EventId, ObjectUUID}\n+import play.api.Logger\n+import play.api.db.slick.DatabaseConfigProvider\n+import play.api.libs.concurrent.Execution.Implicits.defaultContext\n+import play.api.libs.json.Json\n+import slick.dbio.DBIOAction\n+import slick.dbio.Effect.All\n+\n+import scala.concurrent.Future\n+import scala.util.control.NonFatal\n+\n+@Singleton\n+class AnalysisDao @Inject() (\n+    val dbConfigProvider: DatabaseConfigProvider\n+) extends Tables {\n+\n+  val logger = Logger(classOf[AnalysisDao])\n+\n+  import driver.api._\n+\n+  private val noaction: DBIO[Unit] = DBIO.successful(())\n+\n+  private def insertAnalysisAction(event: EventRow): DBIO[EventId] = {\n+    analysisTable returning analysisTable.map(_.id) += event\n+  }\n+\n+  private def insertResultAction(result: ResultRow): DBIO[Long] = {\n+    resultTable returning resultTable.map(_.id) += result\n+  }\n+\n+  private def insertAnalysisWithResultAction(a: Analysis): DBIO[EventId] = {\n+    for {\n+      id <- insertAnalysisAction(asEventTuple(a))\n+      _ <- a.result.map(r => insertResultAction(asResultTuple(id, r))).getOrElse(noaction)\n+    } yield id\n+  }\n+\n+  private def insertChildEventsAction(\n+    pid: EventId,\n+    events: Seq[Analysis]\n+  ): DBIO[Seq[EventId]] = {\n+    val batch = events.map { e =>\n+      insertAnalysisWithResultAction(e.copy(partOf = Some(pid)))\n+    }\n+    DBIO.sequence(batch)\n+  }\n+\n+  private def findByIdAction(id: EventId): DBIO[Option[AnalysisEvent]] = {\n+    analysisTable.filter(_.id === id).result.headOption.map { res =>\n+      res.flatMap(fromEventRow)\n+    }\n+  }\n+\n+  private def resultForEventIdAction(id: EventId): DBIO[Option[AnalysisResult]] = {\n+    resultTable.filter(_.eventId === id).result.headOption.map { res =>\n+      res.flatMap(fromResultRow)\n+    }\n+  }\n+\n+  private def listChildrenAction(parentId: EventId): DBIO[Seq[Analysis]] = {\n+    val query = analysisTable.filter(_.partOf === parentId) joinLeft\n+      resultTable on (_.id === _.eventId)\n+\n+    query.result.map { res =>\n+      res.map { row =>\n+        fromEventRow(row._1)","path":"service_analysis/app/repositories/dao/AnalysisDao.scala","position":72,"original_position":72,"commit_id":"6a9cd0e44b0ad1648b83e6da30eee5efcf5986fa","original_commit_id":"6a9cd0e44b0ad1648b83e6da30eee5efcf5986fa","user":{"login":"codacy-bot","id":19940114,"avatar_url":"https://avatars2.githubusercontent.com/u/19940114?v=3","gravatar_id":"","url":"https://api.github.com/users/codacy-bot","html_url":"https://github.com/codacy-bot","followers_url":"https://api.github.com/users/codacy-bot/followers","following_url":"https://api.github.com/users/codacy-bot/following{/other_user}","gists_url":"https://api.github.com/users/codacy-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/codacy-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codacy-bot/subscriptions","organizations_url":"https://api.github.com/users/codacy-bot/orgs","repos_url":"https://api.github.com/users/codacy-bot/repos","events_url":"https://api.github.com/users/codacy-bot/events{/privacy}","received_events_url":"https://api.github.com/users/codacy-bot/received_events","type":"User","site_admin":false},"body":"![Codacy](https://www.codacy.com/assets/images/favicon.png) Issue found: [Usage of get on optional type.](https://www.codacy.com/app/MUSIT-Norway/musit/pullRequest?prid=526574)","created_at":"2017-03-13T09:51:32Z","updated_at":"2017-03-13T09:51:32Z","html_url":"https://github.com/MUSIT-Norway/musit/pull/256#discussion_r105622187","pull_request_url":"https://api.github.com/repos/MUSIT-Norway/musit/pulls/256","_links":{"self":{"href":"https://api.github.com/repos/MUSIT-Norway/musit/pulls/comments/105622187"},"html":{"href":"https://github.com/MUSIT-Norway/musit/pull/256#discussion_r105622187"},"pull_request":{"href":"https://api.github.com/repos/MUSIT-Norway/musit/pulls/256"}}},"pull_request":{"url":"https://api.github.com/repos/MUSIT-Norway/musit/pulls/256","id":107076142,"html_url":"https://github.com/MUSIT-Norway/musit/pull/256","diff_url":"https://github.com/MUSIT-Norway/musit/pull/256.diff","patch_url":"https://github.com/MUSIT-Norway/musit/pull/256.patch","issue_url":"https://api.github.com/repos/MUSIT-Norway/musit/issues/256","number":256,"state":"open","locked":false,"title":"MUSARK-863: Preparation of `service_analysis` module","user":{"login":"kpmeen","id":3736963,"avatar_url":"https://avatars0.githubusercontent.com/u/3736963?v=3","gravatar_id":"","url":"https://api.github.com/users/kpmeen","html_url":"https://github.com/kpmeen","followers_url":"https://api.github.com/users/kpmeen/followers","following_url":"https://api.github.com/users/kpmeen/following{/other_user}","gists_url":"https://api.github.com/users/kpmeen/gists{/gist_id}","starred_url":"https://api.github.com/users/kpmeen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kpmeen/subscriptions","organizations_url":"https://api.github.com/users/kpmeen/orgs","repos_url":"https://api.github.com/users/kpmeen/repos","events_url":"https://api.github.com/users/kpmeen/events{/privacy}","received_events_url":"https://api.github.com/users/kpmeen/received_events","type":"User","site_admin":false},"body":"Preparing project for development on new module for handling analysis of museum objects.","created_at":"2017-02-20T21:05:04Z","updated_at":"2017-03-13T09:51:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"49c30b49a5f739493f6121fd2fa31002b174aedd","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/MUSIT-Norway/musit/pulls/256/commits","review_comments_url":"https://api.github.com/repos/MUSIT-Norway/musit/pulls/256/comments","review_comment_url":"https://api.github.com/repos/MUSIT-Norway/musit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/MUSIT-Norway/musit/issues/256/comments","statuses_url":"https://api.github.com/repos/MUSIT-Norway/musit/statuses/6a9cd0e44b0ad1648b83e6da30eee5efcf5986fa","head":{"label":"kpmeen:MUSARK-863","ref":"MUSARK-863","sha":"6a9cd0e44b0ad1648b83e6da30eee5efcf5986fa","user":{"login":"kpmeen","id":3736963,"avatar_url":"https://avatars0.githubusercontent.com/u/3736963?v=3","gravatar_id":"","url":"https://api.github.com/users/kpmeen","html_url":"https://github.com/kpmeen","followers_url":"https://api.github.com/users/kpmeen/followers","following_url":"https://api.github.com/users/kpmeen/following{/other_user}","gists_url":"https://api.github.com/users/kpmeen/gists{/gist_id}","starred_url":"https://api.github.com/users/kpmeen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kpmeen/subscriptions","organizations_url":"https://api.github.com/users/kpmeen/orgs","repos_url":"https://api.github.com/users/kpmeen/repos","events_url":"https://api.github.com/users/kpmeen/events{/privacy}","received_events_url":"https://api.github.com/users/kpmeen/received_events","type":"User","site_admin":false},"repo":{"id":64735433,"name":"musit","full_name":"kpmeen/musit","owner":{"login":"kpmeen","id":3736963,"avatar_url":"https://avatars0.githubusercontent.com/u/3736963?v=3","gravatar_id":"","url":"https://api.github.com/users/kpmeen","html_url":"https://github.com/kpmeen","followers_url":"https://api.github.com/users/kpmeen/followers","following_url":"https://api.github.com/users/kpmeen/following{/other_user}","gists_url":"https://api.github.com/users/kpmeen/gists{/gist_id}","starred_url":"https://api.github.com/users/kpmeen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kpmeen/subscriptions","organizations_url":"https://api.github.com/users/kpmeen/orgs","repos_url":"https://api.github.com/users/kpmeen/repos","events_url":"https://api.github.com/users/kpmeen/events{/privacy}","received_events_url":"https://api.github.com/users/kpmeen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kpmeen/musit","description":"Norwegian university museums IT organization (MUSIT); cultural history and natural history database with store integration","fork":true,"url":"https://api.github.com/repos/kpmeen/musit","forks_url":"https://api.github.com/repos/kpmeen/musit/forks","keys_url":"https://api.github.com/repos/kpmeen/musit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kpmeen/musit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kpmeen/musit/teams","hooks_url":"https://api.github.com/repos/kpmeen/musit/hooks","issue_events_url":"https://api.github.com/repos/kpmeen/musit/issues/events{/number}","events_url":"https://api.github.com/repos/kpmeen/musit/events","assignees_url":"https://api.github.com/repos/kpmeen/musit/assignees{/user}","branches_url":"https://api.github.com/repos/kpmeen/musit/branches{/branch}","tags_url":"https://api.github.com/repos/kpmeen/musit/tags","blobs_url":"https://api.github.com/repos/kpmeen/musit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kpmeen/musit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kpmeen/musit/git/refs{/sha}","trees_url":"https://api.github.com/repos/kpmeen/musit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kpmeen/musit/statuses/{sha}","languages_url":"https://api.github.com/repos/kpmeen/musit/languages","stargazers_url":"https://api.github.com/repos/kpmeen/musit/stargazers","contributors_url":"https://api.github.com/repos/kpmeen/musit/contributors","subscribers_url":"https://api.github.com/repos/kpmeen/musit/subscribers","subscription_url":"https://api.github.com/repos/kpmeen/musit/subscription","commits_url":"https://api.github.com/repos/kpmeen/musit/commits{/sha}","git_commits_url":"https://api.github.com/repos/kpmeen/musit/git/commits{/sha}","comments_url":"https://api.github.com/repos/kpmeen/musit/comments{/number}","issue_comment_url":"https://api.github.com/repos/kpmeen/musit/issues/comments{/number}","contents_url":"https://api.github.com/repos/kpmeen/musit/contents/{+path}","compare_url":"https://api.github.com/repos/kpmeen/musit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kpmeen/musit/merges","archive_url":"https://api.github.com/repos/kpmeen/musit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kpmeen/musit/downloads","issues_url":"https://api.github.com/repos/kpmeen/musit/issues{/number}","pulls_url":"https://api.github.com/repos/kpmeen/musit/pulls{/number}","milestones_url":"https://api.github.com/repos/kpmeen/musit/milestones{/number}","notifications_url":"https://api.github.com/repos/kpmeen/musit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kpmeen/musit/labels{/name}","releases_url":"https://api.github.com/repos/kpmeen/musit/releases{/id}","deployments_url":"https://api.github.com/repos/kpmeen/musit/deployments","created_at":"2016-08-02T07:39:07Z","updated_at":"2016-08-02T07:39:09Z","pushed_at":"2017-03-13T09:49:07Z","git_url":"git://github.com/kpmeen/musit.git","ssh_url":"git@github.com:kpmeen/musit.git","clone_url":"https://github.com/kpmeen/musit.git","svn_url":"https://github.com/kpmeen/musit","homepage":"","size":17770,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"MUSIT-Norway:master","ref":"master","sha":"7d17c8b54fdfb56f14d451efce66a8a242f2c19a","user":{"login":"MUSIT-Norway","id":17343809,"avatar_url":"https://avatars1.githubusercontent.com/u/17343809?v=3","gravatar_id":"","url":"https://api.github.com/users/MUSIT-Norway","html_url":"https://github.com/MUSIT-Norway","followers_url":"https://api.github.com/users/MUSIT-Norway/followers","following_url":"https://api.github.com/users/MUSIT-Norway/following{/other_user}","gists_url":"https://api.github.com/users/MUSIT-Norway/gists{/gist_id}","starred_url":"https://api.github.com/users/MUSIT-Norway/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MUSIT-Norway/subscriptions","organizations_url":"https://api.github.com/users/MUSIT-Norway/orgs","repos_url":"https://api.github.com/users/MUSIT-Norway/repos","events_url":"https://api.github.com/users/MUSIT-Norway/events{/privacy}","received_events_url":"https://api.github.com/users/MUSIT-Norway/received_events","type":"Organization","site_admin":false},"repo":{"id":52344845,"name":"musit","full_name":"MUSIT-Norway/musit","owner":{"login":"MUSIT-Norway","id":17343809,"avatar_url":"https://avatars1.githubusercontent.com/u/17343809?v=3","gravatar_id":"","url":"https://api.github.com/users/MUSIT-Norway","html_url":"https://github.com/MUSIT-Norway","followers_url":"https://api.github.com/users/MUSIT-Norway/followers","following_url":"https://api.github.com/users/MUSIT-Norway/following{/other_user}","gists_url":"https://api.github.com/users/MUSIT-Norway/gists{/gist_id}","starred_url":"https://api.github.com/users/MUSIT-Norway/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MUSIT-Norway/subscriptions","organizations_url":"https://api.github.com/users/MUSIT-Norway/orgs","repos_url":"https://api.github.com/users/MUSIT-Norway/repos","events_url":"https://api.github.com/users/MUSIT-Norway/events{/privacy}","received_events_url":"https://api.github.com/users/MUSIT-Norway/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/MUSIT-Norway/musit","description":"Norwegian university museums IT organization (MUSIT); cultural history and natural history database with store integration","fork":false,"url":"https://api.github.com/repos/MUSIT-Norway/musit","forks_url":"https://api.github.com/repos/MUSIT-Norway/musit/forks","keys_url":"https://api.github.com/repos/MUSIT-Norway/musit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MUSIT-Norway/musit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MUSIT-Norway/musit/teams","hooks_url":"https://api.github.com/repos/MUSIT-Norway/musit/hooks","issue_events_url":"https://api.github.com/repos/MUSIT-Norway/musit/issues/events{/number}","events_url":"https://api.github.com/repos/MUSIT-Norway/musit/events","assignees_url":"https://api.github.com/repos/MUSIT-Norway/musit/assignees{/user}","branches_url":"https://api.github.com/repos/MUSIT-Norway/musit/branches{/branch}","tags_url":"https://api.github.com/repos/MUSIT-Norway/musit/tags","blobs_url":"https://api.github.com/repos/MUSIT-Norway/musit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MUSIT-Norway/musit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MUSIT-Norway/musit/git/refs{/sha}","trees_url":"https://api.github.com/repos/MUSIT-Norway/musit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MUSIT-Norway/musit/statuses/{sha}","languages_url":"https://api.github.com/repos/MUSIT-Norway/musit/languages","stargazers_url":"https://api.github.com/repos/MUSIT-Norway/musit/stargazers","contributors_url":"https://api.github.com/repos/MUSIT-Norway/musit/contributors","subscribers_url":"https://api.github.com/repos/MUSIT-Norway/musit/subscribers","subscription_url":"https://api.github.com/repos/MUSIT-Norway/musit/subscription","commits_url":"https://api.github.com/repos/MUSIT-Norway/musit/commits{/sha}","git_commits_url":"https://api.github.com/repos/MUSIT-Norway/musit/git/commits{/sha}","comments_url":"https://api.github.com/repos/MUSIT-Norway/musit/comments{/number}","issue_comment_url":"https://api.github.com/repos/MUSIT-Norway/musit/issues/comments{/number}","contents_url":"https://api.github.com/repos/MUSIT-Norway/musit/contents/{+path}","compare_url":"https://api.github.com/repos/MUSIT-Norway/musit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MUSIT-Norway/musit/merges","archive_url":"https://api.github.com/repos/MUSIT-Norway/musit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MUSIT-Norway/musit/downloads","issues_url":"https://api.github.com/repos/MUSIT-Norway/musit/issues{/number}","pulls_url":"https://api.github.com/repos/MUSIT-Norway/musit/pulls{/number}","milestones_url":"https://api.github.com/repos/MUSIT-Norway/musit/milestones{/number}","notifications_url":"https://api.github.com/repos/MUSIT-Norway/musit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MUSIT-Norway/musit/labels{/name}","releases_url":"https://api.github.com/repos/MUSIT-Norway/musit/releases{/id}","deployments_url":"https://api.github.com/repos/MUSIT-Norway/musit/deployments","created_at":"2016-02-23T08:53:04Z","updated_at":"2017-03-02T22:48:53Z","pushed_at":"2017-03-13T09:49:08Z","git_url":"git://github.com/MUSIT-Norway/musit.git","ssh_url":"git@github.com:MUSIT-Norway/musit.git","clone_url":"https://github.com/MUSIT-Norway/musit.git","svn_url":"https://github.com/MUSIT-Norway/musit","homepage":"","size":19024,"stargazers_count":8,"watchers_count":8,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":3,"forks":7,"open_issues":3,"watchers":8,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/MUSIT-Norway/musit/pulls/256"},"html":{"href":"https://github.com/MUSIT-Norway/musit/pull/256"},"issue":{"href":"https://api.github.com/repos/MUSIT-Norway/musit/issues/256"},"comments":{"href":"https://api.github.com/repos/MUSIT-Norway/musit/issues/256/comments"},"review_comments":{"href":"https://api.github.com/repos/MUSIT-Norway/musit/pulls/256/comments"},"review_comment":{"href":"https://api.github.com/repos/MUSIT-Norway/musit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/MUSIT-Norway/musit/pulls/256/commits"},"statuses":{"href":"https://api.github.com/repos/MUSIT-Norway/musit/statuses/6a9cd0e44b0ad1648b83e6da30eee5efcf5986fa"}}}}
{"actor":{"display_login":"codacy-bot"}}