{"action":"created","comment":{"url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/pulls/comments/150255066","pull_request_review_id":75780685,"id":150255066,"diff_hunk":"@@ -0,0 +1,100 @@\n+/**\n+ * Copyright 2008 The University of North Carolina at Chapel Hill\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *         http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package edu.unc.lib.dl.cdr.services.processing;\n+\n+import static edu.unc.lib.dl.acl.util.Permission.editResourceType;\n+\n+import edu.unc.lib.dl.acl.service.AccessControlService;\n+import edu.unc.lib.dl.acl.util.AgentPrincipals;\n+import edu.unc.lib.dl.fcrepo4.FileObject;\n+import edu.unc.lib.dl.fcrepo4.RepositoryObject;\n+import edu.unc.lib.dl.fcrepo4.RepositoryObjectFactory;\n+import edu.unc.lib.dl.fcrepo4.RepositoryObjectLoader;\n+import edu.unc.lib.dl.fcrepo4.WorkObject;\n+import edu.unc.lib.dl.fedora.PID;\n+import edu.unc.lib.dl.model.InvalidOperationForObjectType;\n+import edu.unc.lib.dl.rdf.Cdr;\n+import edu.unc.lib.dl.rdf.Premis;\n+\n+/**\n+ * Service that manages setting a primary object on a work\n+ *\n+ * @author harring\n+ *\n+ */\n+public class SetPrimaryObjectService {\n+\n+    private AccessControlService aclService;\n+    private RepositoryObjectLoader repoObjLoader;\n+    private RepositoryObjectFactory repoObjFactory;\n+\n+    /**\n+     * Sets file object with the given pid as the primary object for its work using the agent principals provided.\n+     *\n+     * @param agent security principals of the agent making request.\n+     * @param fileObjPid the file object to be set as primary object\n+     */\n+    public void setPrimaryObject(AgentPrincipals agent, PID fileObjPid) {\n+\n+        aclService.assertHasAccess(\"Insufficient privileges to set \" + fileObjPid.getUUID() + \" as primary object\",\n+                fileObjPid, agent.getPrincipals(), editResourceType);\n+\n+        RepositoryObject repoObj = repoObjLoader.getRepositoryObject(fileObjPid);\n+\n+        if (!(repoObj instanceof FileObject)) {\n+            throw new InvalidOperationForObjectType(\"Cannot set \" + fileObjPid.getUUID()\n+                    + \" as primary object, since objects of type \" + repoObj.getClass().getName()\n+                    + \" are not eligible.\");\n+        }\n+\n+        RepositoryObject parent = repoObj.getParent();\n+        if(!(parent instanceof WorkObject)) {\n+            throw new InvalidOperationForObjectType(\"Object of type \" + parent.getClass().getName()\n+            + \" cannot have a primary object.\");\n+        }\n+        repoObjFactory.createRelationship(parent.getPid(), Cdr.primaryObject, parent.getModel()\n+                .createResource(fileObjPid.getRepositoryPath()));\n+\n+        repoObj.getPremisLog()","path":"services/src/main/java/edu/unc/lib/dl/cdr/services/processing/SetPrimaryObjectService.java","position":71,"original_position":71,"commit_id":"d5c57057484b87507bd7419e470c43b77110c435","original_commit_id":"d5c57057484b87507bd7419e470c43b77110c435","user":{"login":"harringj","id":21954788,"avatar_url":"https://avatars2.githubusercontent.com/u/21954788?v=4","gravatar_id":"","url":"https://api.github.com/users/harringj","html_url":"https://github.com/harringj","followers_url":"https://api.github.com/users/harringj/followers","following_url":"https://api.github.com/users/harringj/following{/other_user}","gists_url":"https://api.github.com/users/harringj/gists{/gist_id}","starred_url":"https://api.github.com/users/harringj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harringj/subscriptions","organizations_url":"https://api.github.com/users/harringj/orgs","repos_url":"https://api.github.com/users/harringj/repos","events_url":"https://api.github.com/users/harringj/events{/privacy}","received_events_url":"https://api.github.com/users/harringj/received_events","type":"User","site_admin":false},"body":"yep, already gone :-)","created_at":"2017-11-10T14:57:41Z","updated_at":"2017-11-10T14:57:41Z","html_url":"https://github.com/UNC-Libraries/Carolina-Digital-Repository/pull/667#discussion_r150255066","pull_request_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/pulls/667","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/pulls/comments/150255066"},"html":{"href":"https://github.com/UNC-Libraries/Carolina-Digital-Repository/pull/667#discussion_r150255066"},"pull_request":{"href":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/pulls/667"}},"in_reply_to_id":150068379},"pull_request":{"url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/pulls/667","id":151489332,"html_url":"https://github.com/UNC-Libraries/Carolina-Digital-Repository/pull/667","diff_url":"https://github.com/UNC-Libraries/Carolina-Digital-Repository/pull/667.diff","patch_url":"https://github.com/UNC-Libraries/Carolina-Digital-Repository/pull/667.patch","issue_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/issues/667","number":667,"state":"open","locked":false,"title":"Cdr 1920 set primary object","user":{"login":"harringj","id":21954788,"avatar_url":"https://avatars2.githubusercontent.com/u/21954788?v=4","gravatar_id":"","url":"https://api.github.com/users/harringj","html_url":"https://github.com/harringj","followers_url":"https://api.github.com/users/harringj/followers","following_url":"https://api.github.com/users/harringj/following{/other_user}","gists_url":"https://api.github.com/users/harringj/gists{/gist_id}","starred_url":"https://api.github.com/users/harringj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harringj/subscriptions","organizations_url":"https://api.github.com/users/harringj/orgs","repos_url":"https://api.github.com/users/harringj/repos","events_url":"https://api.github.com/users/harringj/events{/privacy}","received_events_url":"https://api.github.com/users/harringj/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-11-08T20:39:36Z","updated_at":"2017-11-10T14:57:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9be5126b1e14ede64864523cbe1815493cecf8fc","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/pulls/667/commits","review_comments_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/pulls/667/comments","review_comment_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/pulls/comments{/number}","comments_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/issues/667/comments","statuses_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/statuses/d5c57057484b87507bd7419e470c43b77110c435","head":{"label":"UNC-Libraries:cdr-1920-set-primary-object","ref":"cdr-1920-set-primary-object","sha":"d5c57057484b87507bd7419e470c43b77110c435","user":{"login":"UNC-Libraries","id":552066,"avatar_url":"https://avatars0.githubusercontent.com/u/552066?v=4","gravatar_id":"","url":"https://api.github.com/users/UNC-Libraries","html_url":"https://github.com/UNC-Libraries","followers_url":"https://api.github.com/users/UNC-Libraries/followers","following_url":"https://api.github.com/users/UNC-Libraries/following{/other_user}","gists_url":"https://api.github.com/users/UNC-Libraries/gists{/gist_id}","starred_url":"https://api.github.com/users/UNC-Libraries/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UNC-Libraries/subscriptions","organizations_url":"https://api.github.com/users/UNC-Libraries/orgs","repos_url":"https://api.github.com/users/UNC-Libraries/repos","events_url":"https://api.github.com/users/UNC-Libraries/events{/privacy}","received_events_url":"https://api.github.com/users/UNC-Libraries/received_events","type":"Organization","site_admin":false},"repo":{"id":2357859,"name":"Carolina-Digital-Repository","full_name":"UNC-Libraries/Carolina-Digital-Repository","owner":{"login":"UNC-Libraries","id":552066,"avatar_url":"https://avatars0.githubusercontent.com/u/552066?v=4","gravatar_id":"","url":"https://api.github.com/users/UNC-Libraries","html_url":"https://github.com/UNC-Libraries","followers_url":"https://api.github.com/users/UNC-Libraries/followers","following_url":"https://api.github.com/users/UNC-Libraries/following{/other_user}","gists_url":"https://api.github.com/users/UNC-Libraries/gists{/gist_id}","starred_url":"https://api.github.com/users/UNC-Libraries/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UNC-Libraries/subscriptions","organizations_url":"https://api.github.com/users/UNC-Libraries/orgs","repos_url":"https://api.github.com/users/UNC-Libraries/repos","events_url":"https://api.github.com/users/UNC-Libraries/events{/privacy}","received_events_url":"https://api.github.com/users/UNC-Libraries/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/UNC-Libraries/Carolina-Digital-Repository","description":"Carolina Digital Repository","fork":false,"url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository","forks_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/forks","keys_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/keys{/key_id}","collaborators_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/teams","hooks_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/hooks","issue_events_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/issues/events{/number}","events_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/events","assignees_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/assignees{/user}","branches_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/branches{/branch}","tags_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/tags","blobs_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/git/refs{/sha}","trees_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/git/trees{/sha}","statuses_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/statuses/{sha}","languages_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/languages","stargazers_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/stargazers","contributors_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/contributors","subscribers_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/subscribers","subscription_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/subscription","commits_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/commits{/sha}","git_commits_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/git/commits{/sha}","comments_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/comments{/number}","issue_comment_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/issues/comments{/number}","contents_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/contents/{+path}","compare_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/compare/{base}...{head}","merges_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/merges","archive_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/downloads","issues_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/issues{/number}","pulls_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/pulls{/number}","milestones_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/milestones{/number}","notifications_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/labels{/name}","releases_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/releases{/id}","deployments_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/deployments","created_at":"2011-09-09T20:22:21Z","updated_at":"2017-04-15T00:55:02Z","pushed_at":"2017-11-10T14:08:43Z","git_url":"git://github.com/UNC-Libraries/Carolina-Digital-Repository.git","ssh_url":"git@github.com:UNC-Libraries/Carolina-Digital-Repository.git","clone_url":"https://github.com/UNC-Libraries/Carolina-Digital-Repository.git","svn_url":"https://github.com/UNC-Libraries/Carolina-Digital-Repository","homepage":"http://www.lib.unc.edu/blogs/cdr/index.php/about/","size":103532,"stargazers_count":9,"watchers_count":9,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"archived":false,"open_issues_count":4,"forks":10,"open_issues":4,"watchers":9,"default_branch":"fcrepo4"}},"base":{"label":"UNC-Libraries:fcrepo4","ref":"fcrepo4","sha":"ba96aad1e80dd8aeff6f2474952cd519870969a0","user":{"login":"UNC-Libraries","id":552066,"avatar_url":"https://avatars0.githubusercontent.com/u/552066?v=4","gravatar_id":"","url":"https://api.github.com/users/UNC-Libraries","html_url":"https://github.com/UNC-Libraries","followers_url":"https://api.github.com/users/UNC-Libraries/followers","following_url":"https://api.github.com/users/UNC-Libraries/following{/other_user}","gists_url":"https://api.github.com/users/UNC-Libraries/gists{/gist_id}","starred_url":"https://api.github.com/users/UNC-Libraries/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UNC-Libraries/subscriptions","organizations_url":"https://api.github.com/users/UNC-Libraries/orgs","repos_url":"https://api.github.com/users/UNC-Libraries/repos","events_url":"https://api.github.com/users/UNC-Libraries/events{/privacy}","received_events_url":"https://api.github.com/users/UNC-Libraries/received_events","type":"Organization","site_admin":false},"repo":{"id":2357859,"name":"Carolina-Digital-Repository","full_name":"UNC-Libraries/Carolina-Digital-Repository","owner":{"login":"UNC-Libraries","id":552066,"avatar_url":"https://avatars0.githubusercontent.com/u/552066?v=4","gravatar_id":"","url":"https://api.github.com/users/UNC-Libraries","html_url":"https://github.com/UNC-Libraries","followers_url":"https://api.github.com/users/UNC-Libraries/followers","following_url":"https://api.github.com/users/UNC-Libraries/following{/other_user}","gists_url":"https://api.github.com/users/UNC-Libraries/gists{/gist_id}","starred_url":"https://api.github.com/users/UNC-Libraries/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UNC-Libraries/subscriptions","organizations_url":"https://api.github.com/users/UNC-Libraries/orgs","repos_url":"https://api.github.com/users/UNC-Libraries/repos","events_url":"https://api.github.com/users/UNC-Libraries/events{/privacy}","received_events_url":"https://api.github.com/users/UNC-Libraries/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/UNC-Libraries/Carolina-Digital-Repository","description":"Carolina Digital Repository","fork":false,"url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository","forks_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/forks","keys_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/keys{/key_id}","collaborators_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/teams","hooks_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/hooks","issue_events_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/issues/events{/number}","events_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/events","assignees_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/assignees{/user}","branches_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/branches{/branch}","tags_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/tags","blobs_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/git/refs{/sha}","trees_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/git/trees{/sha}","statuses_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/statuses/{sha}","languages_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/languages","stargazers_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/stargazers","contributors_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/contributors","subscribers_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/subscribers","subscription_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/subscription","commits_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/commits{/sha}","git_commits_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/git/commits{/sha}","comments_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/comments{/number}","issue_comment_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/issues/comments{/number}","contents_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/contents/{+path}","compare_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/compare/{base}...{head}","merges_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/merges","archive_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/downloads","issues_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/issues{/number}","pulls_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/pulls{/number}","milestones_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/milestones{/number}","notifications_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/labels{/name}","releases_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/releases{/id}","deployments_url":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/deployments","created_at":"2011-09-09T20:22:21Z","updated_at":"2017-04-15T00:55:02Z","pushed_at":"2017-11-10T14:08:43Z","git_url":"git://github.com/UNC-Libraries/Carolina-Digital-Repository.git","ssh_url":"git@github.com:UNC-Libraries/Carolina-Digital-Repository.git","clone_url":"https://github.com/UNC-Libraries/Carolina-Digital-Repository.git","svn_url":"https://github.com/UNC-Libraries/Carolina-Digital-Repository","homepage":"http://www.lib.unc.edu/blogs/cdr/index.php/about/","size":103532,"stargazers_count":9,"watchers_count":9,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"archived":false,"open_issues_count":4,"forks":10,"open_issues":4,"watchers":9,"default_branch":"fcrepo4"}},"_links":{"self":{"href":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/pulls/667"},"html":{"href":"https://github.com/UNC-Libraries/Carolina-Digital-Repository/pull/667"},"issue":{"href":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/issues/667"},"comments":{"href":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/issues/667/comments"},"review_comments":{"href":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/pulls/667/comments"},"review_comment":{"href":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/pulls/667/commits"},"statuses":{"href":"https://api.github.com/repos/UNC-Libraries/Carolina-Digital-Repository/statuses/d5c57057484b87507bd7419e470c43b77110c435"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"harringj"}}