GitHub PullRequestReviewCommentEvent at 2014-11-05 10:33:54
Repository: pul-store
Actor: houndci
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/pulibrary/pul-store/pulls/comments/19865054","id":19865054,"diff_hunk":"@@ -0,0 +1,185 @@\n+require 'nokogiri'\n+module PulStore::Lae::Exportable\n+\n+\n+\n+\n+  # opts:\n+  #   unsolrize: get keys back to name in model where possible. Default: true\n+  #   prod_only: only return the hash if state it \"In Production\". Default: true\n+  def to_yaml(opts={})\n+    self.to_export(opts).to_yaml\n+  end\n+\n+  # opts:\n+  #   unsolrize: get keys back to name in model where possible. Default: true\n+  #   prod_only: only return the hash if state it \"In Production\". Default: true\n+  def to_export(opts={})\n+    if self.class == PulStore::Lae::Folder\n+      return self.to_folder_export_hash(opts)\n+    elsif self.class == PulStore::Lae::Box\n+      folders = []\n+      self.folders.each do |f| \n+        folder_h = f.to_folder_export_hash(opts)\n+        folders << folder_h unless folder_h.nil?\n+      end\n+      return folders\n+    end\n+  end\n+\n+  # Return Solr-flavored XML; intended for indexing in external systems.\n+  def to_solr_xml(opts={})\n+    blanks = ['', [], ['']]\n+    atomic_fields_we_want = %w{ \n+      id barcode date_uploaded date_modified physical_number project_label \n+      date_created earliest_created latest_created sort_title height_in_cm \n+      width_in_cm page_count rights\n+    }\n+    array_fields_we_want = %w{\n+      contributor creator title alternative_title description publisher\n+      series category\n+    }\n+    #k, sub_k (k = key for field (may point to an array), sub_k = key for hash)\n+    hash_values_we_want = {\n+      'geographic_origin' => %w{ label iso_3166_2_code gac_code geoname_id },\n+      'geographic_subject' => %w{ label iso_3166_2_code gac_code geoname_id },\n+      'subject' => %w{ label },\n+      'genre' => %w{ pul_label },\n+      'language' => %w{ label },\n+      'box' => %w{ barcode physical_location physical_number },\n+      'project' =>  %w{ label }\n+    }\n+    export_hashes = self.to_export(opts)\n+    export_hashes = [ export_hashes ] unless export_hashes.kind_of?(Array)\n+    bob = Nokogiri::XML::Builder.new do |xml|\n+      xml.send(:add) do \n+        export_hashes.each do |export_hash|\n+          xml.send(:doc_) do\n+            export_hash.each do |k,v|\n+              if blanks.include?(v)\n+                # skip it. blank? doesn't quite work because of ['']\n+              elsif atomic_fields_we_want.include?(k)\n+                xml.send(:field, v, name: k) unless blanks.include?(v)\n+              elsif array_fields_we_want.include?(k)\n+                v.each do |member|\n+                  xml.send(:field, member, name: k) unless blanks.include?(member)\n+                end\n+              elsif hash_values_we_want.has_key?(k)\n+                if v.kind_of?(Array) # array of hashes\n+                  v.each do |hsh|\n+                    hash_values_we_want[k].each do |sub_k|\n+                      xml.send(:field, hsh[sub_k], name: \"#{k}_#{sub_k}\") unless blanks.include?(v)\n+                    end\n+                  end\n+                else # v is a hash\n+                  hash_values_we_want[k].each do |sub_k|\n+                    xml.send(:field, v[sub_k], name: \"#{k}_#{sub_k}\") unless blanks.include?(v)\n+                  end\n+                end\n+              end\n+            end\n+            if export_hash['active_fedora_model_ssi'] == 'PulStore::Lae::Folder'\n+              # static alternatives keep us from having to call to_export twice\n+              graph = PulStore::Lae::Folder.to_graph(export_hash)\n+              ttl = PulStore::Lae::Folder.to_ttl(graph)\n+              xml.send(:field, ttl, name: :ttl)\n+            end\n+\n+          end\n+        end\n+      end    \n+    end\n+    return bob.to_xml\n+  end\n+\n+  protected\n+\n+  def unsolrize_key(s)\n+    if s.to_s.include? '__'\n+      s.scan( /^.+__(.+)_.+$/).last.first\n+    else\n+      s.to_s\n+    end\n+  end\n+\n+  def unsolrize(hsh)\n+    Hash[hsh.map {|k, v| [unsolrize_key(k), v] }]\n+  end\n+\n+  # opts:\n+  #   unsolrize: get keys back to name in model where possible. Default: true\n+  #   prod_only: return nil if workflow_state is not \"In Production\". Default: true\n+  def to_folder_export_hash(opts={})\n+    unsolrize = opts.fetch(:unsolrize, true)\n+    prod_only = opts.fetch(:prod_only, false)\n+\n+    if prod_only && self.workflow_state != 'In Production'\n+      return nil\n+    end\n+    \n+    excludes = PUL_STORE_CONFIG['lae_export_exclude']\n+    folder_h = self.to_solr.except(*excludes['folder'])\n+\n+    # Bring in Data stored in AR models\n+    unless folder_h['desc_metadata__geographic_subject_tesim'].blank?\n+      geo_subjects = []\n+      folder_h['desc_metadata__geographic_subject_tesim'].each do |g_str|\n+       geo_subjects << PulStore::Lae::Area.where(label: g_str).first.attributes.except('id')\n+      end\n+      folder_h['geographic_subject'] = geo_subjects unless geo_subjects.empty?\n+      folder_h.delete('desc_metadata__geographic_subject_tesim')\n+    end\n+\n+    unless folder_h['desc_metadata__subject_tesim'].blank?\n+      subjects = []\n+      folder_h['desc_metadata__subject_tesim'].each do |s|\n+        subjects << PulStore::Lae::Subject.where(label: s).first.attributes.except('id', 'category_id')\n+      end\n+      folder_h['subject'] = subjects unless subjects.empty?\n+      folder_h.delete('desc_metadata__subject_tesim')\n+    end\n+\n+    unless folder_h['desc_metadata__genre_tesim'].blank?\n+      genres = []\n+      folder_h['desc_metadata__genre_tesim'].each do |s|\n+        genres << PulStore::Lae::Genre.where(pul_label: s).first.attributes.except('id')\n+      end\n+      folder_h['genre'] = genres unless genres.empty?\n+      folder_h.delete('desc_metadata__genre_tesim')\n+    end\n+\n+    unless folder_h['desc_metadata__language_tesim'].blank?\n+      languages = []\n+      folder_h['desc_metadata__language_tesim'].each do |l|\n+        languages << Language.where(label: l).first.attributes.except('id')\n+      end\n+      folder_h['language'] = languages unless languages.empty?\n+      folder_h.delete('desc_metadata__language_tesim')\n+    end\n+\n+    unless folder_h['desc_metadata__geographic_origin_tesim'].blank?\n+      origin_label = folder_h['desc_metadata__geographic_origin_tesim']\n+      origin_hash = PulStore::Lae::Area.where(label: origin_label).first.attributes.except('id')\n+      folder_h['geographic_origin'] = origin_hash.nil? ? origin_label : origin_hash\n+      folder_h.delete('desc_metadata__geographic_origin_tesim')\n+    end\n+    \n+    # Pages\n+    folder_h['pages'] = []\n+    self.pages(response_format: :solr).sort_by { |h| h['desc_metadata__sort_order_isi'] }.each do |p|\n+      data = p.except(*excludes['page'])\n+      folder_h['pages'] << (unsolrize ? unsolrize(data) : data)\n+    end\n+\n+    # Box\n+    box_data = self.box.to_solr.except(*excludes['box'])\n+    folder_h['box'] = unsolrize ? unsolrize(box_data) : box_data\n+\n+    project_data = self.project.to_solr.except(*excludes['project'])\n+    folder_h['project'] = unsolrize ? unsolrize(project_data) : project_data\n+\n+    unsolrize ? unsolrize(folder_h) : folder_h\n+  end\n+\n+","path":"app/models/concerns/pul_store/lae/exportable.rb","position":184,"original_position":184,"commit_id":"5eff545debdeab9876c9707a24789987b341d8ad","original_commit_id":"5eff545debdeab9876c9707a24789987b341d8ad","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=2","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Extra blank line detected.<br>Extra empty line detected at body end.","created_at":"2014-11-05T10:33:54Z","updated_at":"2014-11-05T10:33:54Z","html_url":"https://github.com/pulibrary/pul-store/pull/319#discussion_r19865054","pull_request_url":"https://api.github.com/repos/pulibrary/pul-store/pulls/319","_links":{"self":{"href":"https://api.github.com/repos/pulibrary/pul-store/pulls/comments/19865054"},"html":{"href":"https://github.com/pulibrary/pul-store/pull/319#discussion_r19865054"},"pull_request":{"href":"https://api.github.com/repos/pulibrary/pul-store/pulls/319"}}},"pull_request":{"url":"https://api.github.com/repos/pulibrary/pul-store/pulls/319","id":23896685,"html_url":"https://github.com/pulibrary/pul-store/pull/319","diff_url":"https://github.com/pulibrary/pul-store/pull/319.diff","patch_url":"https://github.com/pulibrary/pul-store/pull/319.patch","issue_url":"https://api.github.com/repos/pulibrary/pul-store/issues/319","number":319,"state":"open","locked":false,"title":"Adds Solr views for box and folder, ttl view for folder","user":{"login":"jpstroop","id":999701,"avatar_url":"https://avatars.githubusercontent.com/u/999701?v=2","gravatar_id":"","url":"https://api.github.com/users/jpstroop","html_url":"https://github.com/jpstroop","followers_url":"https://api.github.com/users/jpstroop/followers","following_url":"https://api.github.com/users/jpstroop/following{/other_user}","gists_url":"https://api.github.com/users/jpstroop/gists{/gist_id}","starred_url":"https://api.github.com/users/jpstroop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpstroop/subscriptions","organizations_url":"https://api.github.com/users/jpstroop/orgs","repos_url":"https://api.github.com/users/jpstroop/repos","events_url":"https://api.github.com/users/jpstroop/events{/privacy}","received_events_url":"https://api.github.com/users/jpstroop/received_events","type":"User","site_admin":false},"body":"","created_at":"2014-11-05T10:33:46Z","updated_at":"2014-11-05T10:33:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a8334d65c52a0e773ba43f91f25dc52b9c44ee9c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pulibrary/pul-store/pulls/319/commits","review_comments_url":"https://api.github.com/repos/pulibrary/pul-store/pulls/319/comments","review_comment_url":"https://api.github.com/repos/pulibrary/pul-store/pulls/comments/{number}","comments_url":"https://api.github.com/repos/pulibrary/pul-store/issues/319/comments","statuses_url":"https://api.github.com/repos/pulibrary/pul-store/statuses/5eff545debdeab9876c9707a24789987b341d8ad","head":{"label":"pulibrary:refine_yaml_export","ref":"refine_yaml_export","sha":"5eff545debdeab9876c9707a24789987b341d8ad","user":{"login":"pulibrary","id":1827800,"avatar_url":"https://avatars.githubusercontent.com/u/1827800?v=2","gravatar_id":"","url":"https://api.github.com/users/pulibrary","html_url":"https://github.com/pulibrary","followers_url":"https://api.github.com/users/pulibrary/followers","following_url":"https://api.github.com/users/pulibrary/following{/other_user}","gists_url":"https://api.github.com/users/pulibrary/gists{/gist_id}","starred_url":"https://api.github.com/users/pulibrary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pulibrary/subscriptions","organizations_url":"https://api.github.com/users/pulibrary/orgs","repos_url":"https://api.github.com/users/pulibrary/repos","events_url":"https://api.github.com/users/pulibrary/events{/privacy}","received_events_url":"https://api.github.com/users/pulibrary/received_events","type":"Organization","site_admin":false},"repo":{"id":13654398,"name":"pul-store","full_name":"pulibrary/pul-store","owner":{"login":"pulibrary","id":1827800,"avatar_url":"https://avatars.githubusercontent.com/u/1827800?v=2","gravatar_id":"","url":"https://api.github.com/users/pulibrary","html_url":"https://github.com/pulibrary","followers_url":"https://api.github.com/users/pulibrary/followers","following_url":"https://api.github.com/users/pulibrary/following{/other_user}","gists_url":"https://api.github.com/users/pulibrary/gists{/gist_id}","starred_url":"https://api.github.com/users/pulibrary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pulibrary/subscriptions","organizations_url":"https://api.github.com/users/pulibrary/orgs","repos_url":"https://api.github.com/users/pulibrary/repos","events_url":"https://api.github.com/users/pulibrary/events{/privacy}","received_events_url":"https://api.github.com/users/pulibrary/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pulibrary/pul-store","description":"PUL Administrative Hydra Head","fork":false,"url":"https://api.github.com/repos/pulibrary/pul-store","forks_url":"https://api.github.com/repos/pulibrary/pul-store/forks","keys_url":"https://api.github.com/repos/pulibrary/pul-store/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pulibrary/pul-store/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pulibrary/pul-store/teams","hooks_url":"https://api.github.com/repos/pulibrary/pul-store/hooks","issue_events_url":"https://api.github.com/repos/pulibrary/pul-store/issues/events{/number}","events_url":"https://api.github.com/repos/pulibrary/pul-store/events","assignees_url":"https://api.github.com/repos/pulibrary/pul-store/assignees{/user}","branches_url":"https://api.github.com/repos/pulibrary/pul-store/branches{/branch}","tags_url":"https://api.github.com/repos/pulibrary/pul-store/tags","blobs_url":"https://api.github.com/repos/pulibrary/pul-store/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pulibrary/pul-store/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pulibrary/pul-store/git/refs{/sha}","trees_url":"https://api.github.com/repos/pulibrary/pul-store/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pulibrary/pul-store/statuses/{sha}","languages_url":"https://api.github.com/repos/pulibrary/pul-store/languages","stargazers_url":"https://api.github.com/repos/pulibrary/pul-store/stargazers","contributors_url":"https://api.github.com/repos/pulibrary/pul-store/contributors","subscribers_url":"https://api.github.com/repos/pulibrary/pul-store/subscribers","subscription_url":"https://api.github.com/repos/pulibrary/pul-store/subscription","commits_url":"https://api.github.com/repos/pulibrary/pul-store/commits{/sha}","git_commits_url":"https://api.github.com/repos/pulibrary/pul-store/git/commits{/sha}","comments_url":"https://api.github.com/repos/pulibrary/pul-store/comments{/number}","issue_comment_url":"https://api.github.com/repos/pulibrary/pul-store/issues/comments/{number}","contents_url":"https://api.github.com/repos/pulibrary/pul-store/contents/{+path}","compare_url":"https://api.github.com/repos/pulibrary/pul-store/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pulibrary/pul-store/merges","archive_url":"https://api.github.com/repos/pulibrary/pul-store/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pulibrary/pul-store/downloads","issues_url":"https://api.github.com/repos/pulibrary/pul-store/issues{/number}","pulls_url":"https://api.github.com/repos/pulibrary/pul-store/pulls{/number}","milestones_url":"https://api.github.com/repos/pulibrary/pul-store/milestones{/number}","notifications_url":"https://api.github.com/repos/pulibrary/pul-store/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pulibrary/pul-store/labels{/name}","releases_url":"https://api.github.com/repos/pulibrary/pul-store/releases{/id}","created_at":"2013-10-17T16:20:18Z","updated_at":"2014-09-08T20:12:59Z","pushed_at":"2014-11-05T10:32:12Z","git_url":"git://github.com/pulibrary/pul-store.git","ssh_url":"git@github.com:pulibrary/pul-store.git","clone_url":"https://github.com/pulibrary/pul-store.git","svn_url":"https://github.com/pulibrary/pul-store","homepage":"","size":28968,"stargazers_count":3,"watchers_count":3,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":64,"forks":1,"open_issues":64,"watchers":3,"default_branch":"development"}},"base":{"label":"pulibrary:development","ref":"development","sha":"8e89eaf9c7e80e534160f86f5aba05da5d412713","user":{"login":"pulibrary","id":1827800,"avatar_url":"https://avatars.githubusercontent.com/u/1827800?v=2","gravatar_id":"","url":"https://api.github.com/users/pulibrary","html_url":"https://github.com/pulibrary","followers_url":"https://api.github.com/users/pulibrary/followers","following_url":"https://api.github.com/users/pulibrary/following{/other_user}","gists_url":"https://api.github.com/users/pulibrary/gists{/gist_id}","starred_url":"https://api.github.com/users/pulibrary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pulibrary/subscriptions","organizations_url":"https://api.github.com/users/pulibrary/orgs","repos_url":"https://api.github.com/users/pulibrary/repos","events_url":"https://api.github.com/users/pulibrary/events{/privacy}","received_events_url":"https://api.github.com/users/pulibrary/received_events","type":"Organization","site_admin":false},"repo":{"id":13654398,"name":"pul-store","full_name":"pulibrary/pul-store","owner":{"login":"pulibrary","id":1827800,"avatar_url":"https://avatars.githubusercontent.com/u/1827800?v=2","gravatar_id":"","url":"https://api.github.com/users/pulibrary","html_url":"https://github.com/pulibrary","followers_url":"https://api.github.com/users/pulibrary/followers","following_url":"https://api.github.com/users/pulibrary/following{/other_user}","gists_url":"https://api.github.com/users/pulibrary/gists{/gist_id}","starred_url":"https://api.github.com/users/pulibrary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pulibrary/subscriptions","organizations_url":"https://api.github.com/users/pulibrary/orgs","repos_url":"https://api.github.com/users/pulibrary/repos","events_url":"https://api.github.com/users/pulibrary/events{/privacy}","received_events_url":"https://api.github.com/users/pulibrary/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pulibrary/pul-store","description":"PUL Administrative Hydra Head","fork":false,"url":"https://api.github.com/repos/pulibrary/pul-store","forks_url":"https://api.github.com/repos/pulibrary/pul-store/forks","keys_url":"https://api.github.com/repos/pulibrary/pul-store/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pulibrary/pul-store/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pulibrary/pul-store/teams","hooks_url":"https://api.github.com/repos/pulibrary/pul-store/hooks","issue_events_url":"https://api.github.com/repos/pulibrary/pul-store/issues/events{/number}","events_url":"https://api.github.com/repos/pulibrary/pul-store/events","assignees_url":"https://api.github.com/repos/pulibrary/pul-store/assignees{/user}","branches_url":"https://api.github.com/repos/pulibrary/pul-store/branches{/branch}","tags_url":"https://api.github.com/repos/pulibrary/pul-store/tags","blobs_url":"https://api.github.com/repos/pulibrary/pul-store/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pulibrary/pul-store/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pulibrary/pul-store/git/refs{/sha}","trees_url":"https://api.github.com/repos/pulibrary/pul-store/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pulibrary/pul-store/statuses/{sha}","languages_url":"https://api.github.com/repos/pulibrary/pul-store/languages","stargazers_url":"https://api.github.com/repos/pulibrary/pul-store/stargazers","contributors_url":"https://api.github.com/repos/pulibrary/pul-store/contributors","subscribers_url":"https://api.github.com/repos/pulibrary/pul-store/subscribers","subscription_url":"https://api.github.com/repos/pulibrary/pul-store/subscription","commits_url":"https://api.github.com/repos/pulibrary/pul-store/commits{/sha}","git_commits_url":"https://api.github.com/repos/pulibrary/pul-store/git/commits{/sha}","comments_url":"https://api.github.com/repos/pulibrary/pul-store/comments{/number}","issue_comment_url":"https://api.github.com/repos/pulibrary/pul-store/issues/comments/{number}","contents_url":"https://api.github.com/repos/pulibrary/pul-store/contents/{+path}","compare_url":"https://api.github.com/repos/pulibrary/pul-store/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pulibrary/pul-store/merges","archive_url":"https://api.github.com/repos/pulibrary/pul-store/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pulibrary/pul-store/downloads","issues_url":"https://api.github.com/repos/pulibrary/pul-store/issues{/number}","pulls_url":"https://api.github.com/repos/pulibrary/pul-store/pulls{/number}","milestones_url":"https://api.github.com/repos/pulibrary/pul-store/milestones{/number}","notifications_url":"https://api.github.com/repos/pulibrary/pul-store/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pulibrary/pul-store/labels{/name}","releases_url":"https://api.github.com/repos/pulibrary/pul-store/releases{/id}","created_at":"2013-10-17T16:20:18Z","updated_at":"2014-09-08T20:12:59Z","pushed_at":"2014-11-05T10:32:12Z","git_url":"git://github.com/pulibrary/pul-store.git","ssh_url":"git@github.com:pulibrary/pul-store.git","clone_url":"https://github.com/pulibrary/pul-store.git","svn_url":"https://github.com/pulibrary/pul-store","homepage":"","size":28968,"stargazers_count":3,"watchers_count":3,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":64,"forks":1,"open_issues":64,"watchers":3,"default_branch":"development"}},"_links":{"self":{"href":"https://api.github.com/repos/pulibrary/pul-store/pulls/319"},"html":{"href":"https://github.com/pulibrary/pul-store/pull/319"},"issue":{"href":"https://api.github.com/repos/pulibrary/pul-store/issues/319"},"comments":{"href":"https://api.github.com/repos/pulibrary/pul-store/issues/319/comments"},"review_comments":{"href":"https://api.github.com/repos/pulibrary/pul-store/pulls/319/comments"},"review_comment":{"href":"https://api.github.com/repos/pulibrary/pul-store/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/pulibrary/pul-store/pulls/319/commits"},"statuses":{"href":"https://api.github.com/repos/pulibrary/pul-store/statuses/5eff545debdeab9876c9707a24789987b341d8ad"}}}}