{"action":"created","comment":{"url":"https://api.github.com/repos/guardian/grid/pulls/comments/40199917","id":40199917,"diff_hunk":"@@ -146,19 +144,32 @@ object EditsController extends Controller with ArgoHelpers with DynamoEdits {\n   }\n \n   def setMetadataFromUsageRights(id: String) = Authenticated.async { req =>\n-    dynamo.jsonGet(id, \"usageRights\").flatMap { dynamoEntry =>\n+    dynamo.get(id) flatMap { dynamoEntry =>\n+      val edits = dynamoEntry.as[Edits]\n+      val originalMetadata = edits.metadata\n+      val metadataOpt = edits.usageRights.flatMap(usageRightsToMetadata)\n \n-      val usageRights = (dynamoEntry \\ \"usageRights\").asOpt[UsageRights]\n-      val metadataOpt = usageRights.flatMap(metadataFromUsageRights)\n       metadataOpt.map { metadata =>\n-        dynamo.jsonPatch(id, \"metadata\", metadataAsMap(metadata))\n+        // This merge is based on the fact that we know we will override byline and credit.\n+        // TODO: Be more intelligent about this\n+        val mergedMetadata = (metadata.credit, metadata.byline) match {\n+          case (Some(_), Some(_)) =>\n+            originalMetadata.copy(credit = metadata.credit, byline = metadata.byline)\n+          case (Some(_), None) =>\n+            originalMetadata.copy(credit = metadata.credit)\n+          case (None, Some(_)) =>\n+            originalMetadata.copy(byline = metadata.byline)\n+          case _ => originalMetadata\n+        }\n+\n+        dynamo.jsonAdd(id, \"metadata\", metadataAsMap(mergedMetadata))\n           .map(publish(id))\n-          .map(edits => respond(edits.metadata))\n+          .map(edits => respond(edits.metadata, uri = Some(metadataUri(id))))\n       }\n       .getOrElse(Future.failed(EditsValidationError(\"no-matching-metadata-found\", \"Couldn't find any matching metadata\")))","path":"metadata-editor/app/controllers/EditsController.scala","position":39,"original_position":46,"commit_id":"ca24f94cbff568deb4f9e8049424767ef33bdc8e","original_commit_id":"e16e5277d9557653663720bf8bb264836f220a99","user":{"login":"jamesgorrie","id":31692,"avatar_url":"https://avatars.githubusercontent.com/u/31692?v=3","gravatar_id":"","url":"https://api.github.com/users/jamesgorrie","html_url":"https://github.com/jamesgorrie","followers_url":"https://api.github.com/users/jamesgorrie/followers","following_url":"https://api.github.com/users/jamesgorrie/following{/other_user}","gists_url":"https://api.github.com/users/jamesgorrie/gists{/gist_id}","starred_url":"https://api.github.com/users/jamesgorrie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamesgorrie/subscriptions","organizations_url":"https://api.github.com/users/jamesgorrie/orgs","repos_url":"https://api.github.com/users/jamesgorrie/repos","events_url":"https://api.github.com/users/jamesgorrie/events{/privacy}","received_events_url":"https://api.github.com/users/jamesgorrie/received_events","type":"User","site_admin":false},"body":"Saying that -I wasn't handling the 404 - [I've added that now](https://github.com/guardian/grid/commit/ca24f94cbff568deb4f9e8049424767ef33bdc8e).","created_at":"2015-09-23T13:03:56Z","updated_at":"2015-09-23T13:03:56Z","html_url":"https://github.com/guardian/grid/pull/1283#discussion_r40199917","pull_request_url":"https://api.github.com/repos/guardian/grid/pulls/1283","_links":{"self":{"href":"https://api.github.com/repos/guardian/grid/pulls/comments/40199917"},"html":{"href":"https://github.com/guardian/grid/pull/1283#discussion_r40199917"},"pull_request":{"href":"https://api.github.com/repos/guardian/grid/pulls/1283"}}},"pull_request":{"url":"https://api.github.com/repos/guardian/grid/pulls/1283","id":45561572,"html_url":"https://github.com/guardian/grid/pull/1283","diff_url":"https://github.com/guardian/grid/pull/1283.diff","patch_url":"https://github.com/guardian/grid/pull/1283.patch","issue_url":"https://api.github.com/repos/guardian/grid/issues/1283","number":1283,"state":"open","locked":false,"title":"Auto update md from ur","user":{"login":"jamesgorrie","id":31692,"avatar_url":"https://avatars.githubusercontent.com/u/31692?v=3","gravatar_id":"","url":"https://api.github.com/users/jamesgorrie","html_url":"https://github.com/jamesgorrie","followers_url":"https://api.github.com/users/jamesgorrie/followers","following_url":"https://api.github.com/users/jamesgorrie/following{/other_user}","gists_url":"https://api.github.com/users/jamesgorrie/gists{/gist_id}","starred_url":"https://api.github.com/users/jamesgorrie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamesgorrie/subscriptions","organizations_url":"https://api.github.com/users/jamesgorrie/orgs","repos_url":"https://api.github.com/users/jamesgorrie/repos","events_url":"https://api.github.com/users/jamesgorrie/events{/privacy}","received_events_url":"https://api.github.com/users/jamesgorrie/received_events","type":"User","site_admin":false},"body":"__WIP__\r\n\r\n~~Waiting for merging of #1277 to add the UI - but the Dynamo Side now works.~~\r\n\r\nThe problem with before was that we were patching a record that potentially didn't exist, which threw an error. \r\n\r\nSince we're retrieving the `usageRights` anyhow to be able to convert them to metadata, we can just retrieve the whole record and then patch them programatically.","created_at":"2015-09-21T15:19:23Z","updated_at":"2015-09-23T13:03:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f838e8204cfe1fd96273bb2acb2e70a2ae282927","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/guardian/grid/pulls/1283/commits","review_comments_url":"https://api.github.com/repos/guardian/grid/pulls/1283/comments","review_comment_url":"https://api.github.com/repos/guardian/grid/pulls/comments{/number}","comments_url":"https://api.github.com/repos/guardian/grid/issues/1283/comments","statuses_url":"https://api.github.com/repos/guardian/grid/statuses/ca24f94cbff568deb4f9e8049424767ef33bdc8e","head":{"label":"guardian:auto-update-md-from-ur","ref":"auto-update-md-from-ur","sha":"ca24f94cbff568deb4f9e8049424767ef33bdc8e","user":{"login":"guardian","id":164318,"avatar_url":"https://avatars.githubusercontent.com/u/164318?v=3","gravatar_id":"","url":"https://api.github.com/users/guardian","html_url":"https://github.com/guardian","followers_url":"https://api.github.com/users/guardian/followers","following_url":"https://api.github.com/users/guardian/following{/other_user}","gists_url":"https://api.github.com/users/guardian/gists{/gist_id}","starred_url":"https://api.github.com/users/guardian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guardian/subscriptions","organizations_url":"https://api.github.com/users/guardian/orgs","repos_url":"https://api.github.com/users/guardian/repos","events_url":"https://api.github.com/users/guardian/events{/privacy}","received_events_url":"https://api.github.com/users/guardian/received_events","type":"Organization","site_admin":false},"repo":{"id":12298112,"name":"grid","full_name":"guardian/grid","owner":{"login":"guardian","id":164318,"avatar_url":"https://avatars.githubusercontent.com/u/164318?v=3","gravatar_id":"","url":"https://api.github.com/users/guardian","html_url":"https://github.com/guardian","followers_url":"https://api.github.com/users/guardian/followers","following_url":"https://api.github.com/users/guardian/following{/other_user}","gists_url":"https://api.github.com/users/guardian/gists{/gist_id}","starred_url":"https://api.github.com/users/guardian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guardian/subscriptions","organizations_url":"https://api.github.com/users/guardian/orgs","repos_url":"https://api.github.com/users/guardian/repos","events_url":"https://api.github.com/users/guardian/events{/privacy}","received_events_url":"https://api.github.com/users/guardian/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/guardian/grid","description":"The Guardian’s new image management system","fork":false,"url":"https://api.github.com/repos/guardian/grid","forks_url":"https://api.github.com/repos/guardian/grid/forks","keys_url":"https://api.github.com/repos/guardian/grid/keys{/key_id}","collaborators_url":"https://api.github.com/repos/guardian/grid/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/guardian/grid/teams","hooks_url":"https://api.github.com/repos/guardian/grid/hooks","issue_events_url":"https://api.github.com/repos/guardian/grid/issues/events{/number}","events_url":"https://api.github.com/repos/guardian/grid/events","assignees_url":"https://api.github.com/repos/guardian/grid/assignees{/user}","branches_url":"https://api.github.com/repos/guardian/grid/branches{/branch}","tags_url":"https://api.github.com/repos/guardian/grid/tags","blobs_url":"https://api.github.com/repos/guardian/grid/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/guardian/grid/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/guardian/grid/git/refs{/sha}","trees_url":"https://api.github.com/repos/guardian/grid/git/trees{/sha}","statuses_url":"https://api.github.com/repos/guardian/grid/statuses/{sha}","languages_url":"https://api.github.com/repos/guardian/grid/languages","stargazers_url":"https://api.github.com/repos/guardian/grid/stargazers","contributors_url":"https://api.github.com/repos/guardian/grid/contributors","subscribers_url":"https://api.github.com/repos/guardian/grid/subscribers","subscription_url":"https://api.github.com/repos/guardian/grid/subscription","commits_url":"https://api.github.com/repos/guardian/grid/commits{/sha}","git_commits_url":"https://api.github.com/repos/guardian/grid/git/commits{/sha}","comments_url":"https://api.github.com/repos/guardian/grid/comments{/number}","issue_comment_url":"https://api.github.com/repos/guardian/grid/issues/comments{/number}","contents_url":"https://api.github.com/repos/guardian/grid/contents/{+path}","compare_url":"https://api.github.com/repos/guardian/grid/compare/{base}...{head}","merges_url":"https://api.github.com/repos/guardian/grid/merges","archive_url":"https://api.github.com/repos/guardian/grid/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/guardian/grid/downloads","issues_url":"https://api.github.com/repos/guardian/grid/issues{/number}","pulls_url":"https://api.github.com/repos/guardian/grid/pulls{/number}","milestones_url":"https://api.github.com/repos/guardian/grid/milestones{/number}","notifications_url":"https://api.github.com/repos/guardian/grid/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/guardian/grid/labels{/name}","releases_url":"https://api.github.com/repos/guardian/grid/releases{/id}","created_at":"2013-08-22T13:49:31Z","updated_at":"2015-09-23T07:42:38Z","pushed_at":"2015-09-23T13:03:25Z","git_url":"git://github.com/guardian/grid.git","ssh_url":"git@github.com:guardian/grid.git","clone_url":"https://github.com/guardian/grid.git","svn_url":"https://github.com/guardian/grid","homepage":"","size":22936,"stargazers_count":921,"watchers_count":921,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":44,"mirror_url":null,"open_issues_count":64,"forks":44,"open_issues":64,"watchers":921,"default_branch":"master"}},"base":{"label":"guardian:master","ref":"master","sha":"517d2618132e4fb67dcdce3791f4974a68fcfa1f","user":{"login":"guardian","id":164318,"avatar_url":"https://avatars.githubusercontent.com/u/164318?v=3","gravatar_id":"","url":"https://api.github.com/users/guardian","html_url":"https://github.com/guardian","followers_url":"https://api.github.com/users/guardian/followers","following_url":"https://api.github.com/users/guardian/following{/other_user}","gists_url":"https://api.github.com/users/guardian/gists{/gist_id}","starred_url":"https://api.github.com/users/guardian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guardian/subscriptions","organizations_url":"https://api.github.com/users/guardian/orgs","repos_url":"https://api.github.com/users/guardian/repos","events_url":"https://api.github.com/users/guardian/events{/privacy}","received_events_url":"https://api.github.com/users/guardian/received_events","type":"Organization","site_admin":false},"repo":{"id":12298112,"name":"grid","full_name":"guardian/grid","owner":{"login":"guardian","id":164318,"avatar_url":"https://avatars.githubusercontent.com/u/164318?v=3","gravatar_id":"","url":"https://api.github.com/users/guardian","html_url":"https://github.com/guardian","followers_url":"https://api.github.com/users/guardian/followers","following_url":"https://api.github.com/users/guardian/following{/other_user}","gists_url":"https://api.github.com/users/guardian/gists{/gist_id}","starred_url":"https://api.github.com/users/guardian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guardian/subscriptions","organizations_url":"https://api.github.com/users/guardian/orgs","repos_url":"https://api.github.com/users/guardian/repos","events_url":"https://api.github.com/users/guardian/events{/privacy}","received_events_url":"https://api.github.com/users/guardian/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/guardian/grid","description":"The Guardian’s new image management system","fork":false,"url":"https://api.github.com/repos/guardian/grid","forks_url":"https://api.github.com/repos/guardian/grid/forks","keys_url":"https://api.github.com/repos/guardian/grid/keys{/key_id}","collaborators_url":"https://api.github.com/repos/guardian/grid/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/guardian/grid/teams","hooks_url":"https://api.github.com/repos/guardian/grid/hooks","issue_events_url":"https://api.github.com/repos/guardian/grid/issues/events{/number}","events_url":"https://api.github.com/repos/guardian/grid/events","assignees_url":"https://api.github.com/repos/guardian/grid/assignees{/user}","branches_url":"https://api.github.com/repos/guardian/grid/branches{/branch}","tags_url":"https://api.github.com/repos/guardian/grid/tags","blobs_url":"https://api.github.com/repos/guardian/grid/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/guardian/grid/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/guardian/grid/git/refs{/sha}","trees_url":"https://api.github.com/repos/guardian/grid/git/trees{/sha}","statuses_url":"https://api.github.com/repos/guardian/grid/statuses/{sha}","languages_url":"https://api.github.com/repos/guardian/grid/languages","stargazers_url":"https://api.github.com/repos/guardian/grid/stargazers","contributors_url":"https://api.github.com/repos/guardian/grid/contributors","subscribers_url":"https://api.github.com/repos/guardian/grid/subscribers","subscription_url":"https://api.github.com/repos/guardian/grid/subscription","commits_url":"https://api.github.com/repos/guardian/grid/commits{/sha}","git_commits_url":"https://api.github.com/repos/guardian/grid/git/commits{/sha}","comments_url":"https://api.github.com/repos/guardian/grid/comments{/number}","issue_comment_url":"https://api.github.com/repos/guardian/grid/issues/comments{/number}","contents_url":"https://api.github.com/repos/guardian/grid/contents/{+path}","compare_url":"https://api.github.com/repos/guardian/grid/compare/{base}...{head}","merges_url":"https://api.github.com/repos/guardian/grid/merges","archive_url":"https://api.github.com/repos/guardian/grid/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/guardian/grid/downloads","issues_url":"https://api.github.com/repos/guardian/grid/issues{/number}","pulls_url":"https://api.github.com/repos/guardian/grid/pulls{/number}","milestones_url":"https://api.github.com/repos/guardian/grid/milestones{/number}","notifications_url":"https://api.github.com/repos/guardian/grid/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/guardian/grid/labels{/name}","releases_url":"https://api.github.com/repos/guardian/grid/releases{/id}","created_at":"2013-08-22T13:49:31Z","updated_at":"2015-09-23T07:42:38Z","pushed_at":"2015-09-23T13:03:25Z","git_url":"git://github.com/guardian/grid.git","ssh_url":"git@github.com:guardian/grid.git","clone_url":"https://github.com/guardian/grid.git","svn_url":"https://github.com/guardian/grid","homepage":"","size":22936,"stargazers_count":921,"watchers_count":921,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":44,"mirror_url":null,"open_issues_count":64,"forks":44,"open_issues":64,"watchers":921,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/guardian/grid/pulls/1283"},"html":{"href":"https://github.com/guardian/grid/pull/1283"},"issue":{"href":"https://api.github.com/repos/guardian/grid/issues/1283"},"comments":{"href":"https://api.github.com/repos/guardian/grid/issues/1283/comments"},"review_comments":{"href":"https://api.github.com/repos/guardian/grid/pulls/1283/comments"},"review_comment":{"href":"https://api.github.com/repos/guardian/grid/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/guardian/grid/pulls/1283/commits"},"statuses":{"href":"https://api.github.com/repos/guardian/grid/statuses/ca24f94cbff568deb4f9e8049424767ef33bdc8e"}}}}