{"action":"created","comment":{"url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/pulls/comments/24404722","id":24404722,"diff_hunk":"@@ -0,0 +1,111 @@\n+namespace :adl do\n+\n+  desc 'Import ADL files to Valhal'\n+\n+  task :import, [:path] => :environment do |task, args|\n+    if (!Dir.exist?(\"#{args.path}\"))\n+      raise \"Directory #{args.path} does not exists\"\n+    end\n+\n+    adl_activity = Administration::Activity.find('changeme:1')\n+\n+    Dir.glob(\"#{args.path}/*/*.xml\").each do |fname|\n+      puts \"file #{fname}\"\n+      doc = Nokogiri::XML(File.open(fname))\n+\n+      if (doc.xpath(\"//xmlns:teiHeader/xmlns:fileDesc\").size > 0)\n+        id = doc.xpath(\"//xmlns:teiHeader/xmlns:fileDesc/xmlns:publicationStmt/xmlns:idno\").text\n+        puts (\"  ID is #{id}\")\n+        sysno = nil\n+        volno = nil\n+        unless id.blank?\n+          puts (\"  ID is #{id}\")\n+\n+          sysno = id.split(\":\")[0]\n+          volno = id.split(\":\")[1]\n+          puts (\" sysno #{sysno} vol #{volno}\")\n+        end\n+\n+        i = nil\n+        i = find_instance(sysno) unless sysno.blank? || sysno == '000000000'\n+        i = create_new_work_and_instance(sysno,doc,adl_activity) if i.nil?\n+        add_contentfile_to_instance(fname,i) unless i.nil?\n+      end\n+    end\n+  end\n+\n+\n+  private\n+\n+  def find_instance(sysno)\n+    puts \"searching for instances\"\n+    result = ActiveFedora::SolrService.query('system_number_tesim:\"'+sysno+'\" && active_fedora_model_ssi:Instance')\n+    if (result.size > 0)\n+      puts \"  found instance #{result[0]['id']}\"\n+      Instance.find(result[0]['id'])\n+    else\n+      puts \"  no instance found\"\n+      nil\n+    end\n+  end\n+\n+  def create_new_work_and_instance(sysno,doc,adl_activity)\n+    w = Work.new\n+    doc.xpath(\"//xmlns:teiHeader/xmlns:fileDesc/xmlns:titleStmt/xmlns:title\").each do |n|\n+      w.add_title(value: n.text)\n+    end\n+\n+    doc.xpath(\"//xmlns:teiHeader/xmlns:fileDesc/xmlns:titleStmt/xmlns:author\").each do |n|\n+      unless doc.xpath(\"//xmlns:teiHeader/xmlns:fileDesc/xmlns:titleStmt/xmlns:author\").text.blank?\n+        names = doc.xpath(\"//xmlns:teiHeader/xmlns:fileDesc/xmlns:titleStmt/xmlns:author\").text.split(' ')\n+        surname = names.pop\n+        forename = names.join(' ')","path":"lib/tasks/adl.rake","position":62,"original_position":62,"commit_id":"17ad5bfcd4fa53580f1d555dd240170ea20f3ca7","original_commit_id":"17ad5bfcd4fa53580f1d555dd240170ea20f3ca7","user":{"login":"davidgrove73","id":2640002,"avatar_url":"https://avatars.githubusercontent.com/u/2640002?v=3","gravatar_id":"","url":"https://api.github.com/users/davidgrove73","html_url":"https://github.com/davidgrove73","followers_url":"https://api.github.com/users/davidgrove73/followers","following_url":"https://api.github.com/users/davidgrove73/following{/other_user}","gists_url":"https://api.github.com/users/davidgrove73/gists{/gist_id}","starred_url":"https://api.github.com/users/davidgrove73/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidgrove73/subscriptions","organizations_url":"https://api.github.com/users/davidgrove73/orgs","repos_url":"https://api.github.com/users/davidgrove73/repos","events_url":"https://api.github.com/users/davidgrove73/events{/privacy}","received_events_url":"https://api.github.com/users/davidgrove73/received_events","type":"User","site_admin":false},"body":"for nogen findes navnet opdelt i TEI-header, dem hvor der er hentet data fra Aleph. Men det gælder ikke alle TEI-filer, f.eks ingen af forfatterportrætterne","created_at":"2015-02-10T11:14:36Z","updated_at":"2015-02-10T11:14:36Z","html_url":"https://github.com/Det-Kongelige-Bibliotek/valhal/pull/80#discussion_r24404722","pull_request_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/pulls/80","_links":{"self":{"href":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/pulls/comments/24404722"},"html":{"href":"https://github.com/Det-Kongelige-Bibliotek/valhal/pull/80#discussion_r24404722"},"pull_request":{"href":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/pulls/80"}}},"pull_request":{"url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/pulls/80","id":28915775,"html_url":"https://github.com/Det-Kongelige-Bibliotek/valhal/pull/80","diff_url":"https://github.com/Det-Kongelige-Bibliotek/valhal/pull/80.diff","patch_url":"https://github.com/Det-Kongelige-Bibliotek/valhal/pull/80.patch","issue_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/issues/80","number":80,"state":"open","locked":false,"title":"Adl load","user":{"login":"davidgrove73","id":2640002,"avatar_url":"https://avatars.githubusercontent.com/u/2640002?v=3","gravatar_id":"","url":"https://api.github.com/users/davidgrove73","html_url":"https://github.com/davidgrove73","followers_url":"https://api.github.com/users/davidgrove73/followers","following_url":"https://api.github.com/users/davidgrove73/following{/other_user}","gists_url":"https://api.github.com/users/davidgrove73/gists{/gist_id}","starred_url":"https://api.github.com/users/davidgrove73/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidgrove73/subscriptions","organizations_url":"https://api.github.com/users/davidgrove73/orgs","repos_url":"https://api.github.com/users/davidgrove73/repos","events_url":"https://api.github.com/users/davidgrove73/events{/privacy}","received_events_url":"https://api.github.com/users/davidgrove73/received_events","type":"User","site_admin":false},"body":"First attempt at a initial load task","created_at":"2015-02-09T12:16:11Z","updated_at":"2015-02-10T11:14:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2a1e3bb342f2990f27ee7dc53b392150f2f62f74","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/pulls/80/commits","review_comments_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/pulls/80/comments","review_comment_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/pulls/comments/{number}","comments_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/issues/80/comments","statuses_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/statuses/17ad5bfcd4fa53580f1d555dd240170ea20f3ca7","head":{"label":"Det-Kongelige-Bibliotek:adl_load","ref":"adl_load","sha":"17ad5bfcd4fa53580f1d555dd240170ea20f3ca7","user":{"login":"Det-Kongelige-Bibliotek","id":2632010,"avatar_url":"https://avatars.githubusercontent.com/u/2632010?v=3","gravatar_id":"","url":"https://api.github.com/users/Det-Kongelige-Bibliotek","html_url":"https://github.com/Det-Kongelige-Bibliotek","followers_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/followers","following_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/following{/other_user}","gists_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/gists{/gist_id}","starred_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/subscriptions","organizations_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/orgs","repos_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/repos","events_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/events{/privacy}","received_events_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/received_events","type":"Organization","site_admin":false},"repo":{"id":24938485,"name":"valhal","full_name":"Det-Kongelige-Bibliotek/valhal","owner":{"login":"Det-Kongelige-Bibliotek","id":2632010,"avatar_url":"https://avatars.githubusercontent.com/u/2632010?v=3","gravatar_id":"","url":"https://api.github.com/users/Det-Kongelige-Bibliotek","html_url":"https://github.com/Det-Kongelige-Bibliotek","followers_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/followers","following_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/following{/other_user}","gists_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/gists{/gist_id}","starred_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/subscriptions","organizations_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/orgs","repos_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/repos","events_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/events{/privacy}","received_events_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Det-Kongelige-Bibliotek/valhal","description":"Curation and management interface for KB's digital objects","fork":false,"url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal","forks_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/forks","keys_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/teams","hooks_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/hooks","issue_events_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/issues/events{/number}","events_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/events","assignees_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/assignees{/user}","branches_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/branches{/branch}","tags_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/tags","blobs_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/git/refs{/sha}","trees_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/statuses/{sha}","languages_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/languages","stargazers_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/stargazers","contributors_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/contributors","subscribers_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/subscribers","subscription_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/subscription","commits_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/commits{/sha}","git_commits_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/git/commits{/sha}","comments_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/comments{/number}","issue_comment_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/issues/comments/{number}","contents_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/contents/{+path}","compare_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/merges","archive_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/downloads","issues_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/issues{/number}","pulls_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/pulls{/number}","milestones_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/milestones{/number}","notifications_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/labels{/name}","releases_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/releases{/id}","created_at":"2014-10-08T11:56:10Z","updated_at":"2014-12-19T12:33:29Z","pushed_at":"2015-02-10T09:49:15Z","git_url":"git://github.com/Det-Kongelige-Bibliotek/valhal.git","ssh_url":"git@github.com:Det-Kongelige-Bibliotek/valhal.git","clone_url":"https://github.com/Det-Kongelige-Bibliotek/valhal.git","svn_url":"https://github.com/Det-Kongelige-Bibliotek/valhal","homepage":"","size":1789,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":20,"forks":1,"open_issues":20,"watchers":0,"default_branch":"master"}},"base":{"label":"Det-Kongelige-Bibliotek:adl_dev","ref":"adl_dev","sha":"c177b710483adc7f61a37c3203fe57af5d226c3e","user":{"login":"Det-Kongelige-Bibliotek","id":2632010,"avatar_url":"https://avatars.githubusercontent.com/u/2632010?v=3","gravatar_id":"","url":"https://api.github.com/users/Det-Kongelige-Bibliotek","html_url":"https://github.com/Det-Kongelige-Bibliotek","followers_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/followers","following_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/following{/other_user}","gists_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/gists{/gist_id}","starred_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/subscriptions","organizations_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/orgs","repos_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/repos","events_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/events{/privacy}","received_events_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/received_events","type":"Organization","site_admin":false},"repo":{"id":24938485,"name":"valhal","full_name":"Det-Kongelige-Bibliotek/valhal","owner":{"login":"Det-Kongelige-Bibliotek","id":2632010,"avatar_url":"https://avatars.githubusercontent.com/u/2632010?v=3","gravatar_id":"","url":"https://api.github.com/users/Det-Kongelige-Bibliotek","html_url":"https://github.com/Det-Kongelige-Bibliotek","followers_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/followers","following_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/following{/other_user}","gists_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/gists{/gist_id}","starred_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/subscriptions","organizations_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/orgs","repos_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/repos","events_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/events{/privacy}","received_events_url":"https://api.github.com/users/Det-Kongelige-Bibliotek/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Det-Kongelige-Bibliotek/valhal","description":"Curation and management interface for KB's digital objects","fork":false,"url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal","forks_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/forks","keys_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/teams","hooks_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/hooks","issue_events_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/issues/events{/number}","events_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/events","assignees_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/assignees{/user}","branches_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/branches{/branch}","tags_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/tags","blobs_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/git/refs{/sha}","trees_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/statuses/{sha}","languages_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/languages","stargazers_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/stargazers","contributors_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/contributors","subscribers_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/subscribers","subscription_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/subscription","commits_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/commits{/sha}","git_commits_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/git/commits{/sha}","comments_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/comments{/number}","issue_comment_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/issues/comments/{number}","contents_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/contents/{+path}","compare_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/merges","archive_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/downloads","issues_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/issues{/number}","pulls_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/pulls{/number}","milestones_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/milestones{/number}","notifications_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/labels{/name}","releases_url":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/releases{/id}","created_at":"2014-10-08T11:56:10Z","updated_at":"2014-12-19T12:33:29Z","pushed_at":"2015-02-10T09:49:15Z","git_url":"git://github.com/Det-Kongelige-Bibliotek/valhal.git","ssh_url":"git@github.com:Det-Kongelige-Bibliotek/valhal.git","clone_url":"https://github.com/Det-Kongelige-Bibliotek/valhal.git","svn_url":"https://github.com/Det-Kongelige-Bibliotek/valhal","homepage":"","size":1789,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":20,"forks":1,"open_issues":20,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/pulls/80"},"html":{"href":"https://github.com/Det-Kongelige-Bibliotek/valhal/pull/80"},"issue":{"href":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/issues/80"},"comments":{"href":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/issues/80/comments"},"review_comments":{"href":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/pulls/80/comments"},"review_comment":{"href":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/pulls/80/commits"},"statuses":{"href":"https://api.github.com/repos/Det-Kongelige-Bibliotek/valhal/statuses/17ad5bfcd4fa53580f1d555dd240170ea20f3ca7"}}}}