lib/cul-fedora/item.rb in cul-fedora-0.8.6 vs lib/cul-fedora/item.rb in cul-fedora-1.0.0

- old
+ new

@@ -1,6 +1,11 @@ require "open3" +begin + require "active_support/core_ext/array/extract_options" +rescue + require "activesupport" +end module Cul module Fedora class Item @@ -38,10 +43,11 @@ def exists? begin request return true rescue Exception => e # we should really do some better checking of error type etc here + logger.error e.message return false end end def request(options = {}) @@ -80,20 +86,22 @@ items << @server.item(result_node.attributes["uri"].value) end i = i + MAX_LIST_MEMBERS_PER_REQUEST end return items - rescue + rescue Exception => e + logger.error e.message [] end end def getSize() begin request(:method => "/objects", :sdef => "methods/ldpd:sdef.Aggregator", :request => "getSize").to_i - rescue - -1 + rescue Exception => e + logger.error e.message + return -1 end end def describedBy begin @@ -101,21 +109,23 @@ result = request(params) Nokogiri::XML(result).css("sparql>results>result>description").collect do |metadata| @server.item(metadata.attributes["uri"].value) end rescue Exception => e + logger.error e.message [] end end def belongsTo begin result = Nokogiri::XML(datastream("RELS-EXT")) result.xpath("/rdf:RDF/rdf:Description/*[local-name()='memberOf']").collect do |member| @server.item(member.attributes["resource"].value) end - rescue + rescue Exception => e + logger.error e.message [] end end def index_for_ac2(options = {}) @@ -134,10 +144,11 @@ get_fullname = lambda { |node| node.nil? ? nil : (node.css("namePart[@type='family']").collect(&:content) | node.css("namePart[@type='given']").collect(&:content)).join(", ") } author_roles = ["author","creator","editor","speaker","moderator","interviewee","interviewer","contributor"] other_name_roles = ["thesis advisor"] corporate_author_roles = ["author"] + corporate_department_roles = ["originator"] organizations = [] departments = [] begin @@ -180,11 +191,11 @@ if name_node.css("role>roleTerm").collect(&:content).any? { |role| author_roles.include?(role) } note_org = true all_author_names << fullname if(!name_node["ID"].nil?) - add_field.call("author_id_uni", name_node["ID"]) + add_field.call("author_uni", name_node["ID"]) end add_field.call("author_search", fullname.downcase) add_field.call("author_facet", fullname) elsif name_node.css("role>roleTerm").collect(&:content).any? { |role| other_name_roles.include?(role) } @@ -207,11 +218,11 @@ end end mods.css("name[@type='corporate']").each do |corp_name_node| - if(!corp_name_node["ID"].nil? && corp_name_node["ID"].include?("originator")) + if((!corp_name_node["ID"].nil? && corp_name_node["ID"].include?("originator")) || corp_name_node.css("role>roleTerm").collect(&:content).any? { |role| corporate_department_roles.include?(role) }) name_part = corp_name_node.at_css("namePart").text if(name_part.include?(". ")) name_part_split = name_part.split(". ") organizations.push(name_part_split[0].strip) departments.push(name_part_split[1].strip) @@ -228,35 +239,34 @@ add_field.call("author_search", fullname.downcase) add_field.call("author_facet", fullname) end end - add_field.call("authors_display",all_author_names.join("; ")) - add_field.call("pub_date", mods.at_css("*[@keyDate='yes']")) + add_field.call("author_display",all_author_names.join("; ")) + add_field.call("pub_date_facet", mods.at_css("*[@keyDate='yes']")) mods.css("genre").each do |genre_node| add_field.call("genre_facet", genre_node) add_field.call("genre_search", genre_node) - end add_field.call("abstract", mods.at_css("abstract")) add_field.call("handle", mods.at_css("identifier[@type='hdl']")) mods.css("subject").each do |subject_node| if(subject_node.attributes.count == 0) subject_node.css("topic").each do |topic_node| add_field.call("keyword_search", topic_node.content.downcase) - add_field.call("subject", topic_node) + add_field.call("subject_facet", topic_node) add_field.call("subject_search", topic_node) end end end - add_field.call("tableOfContents", mods.at_css("tableOfContents")) + add_field.call("table_of_contents", mods.at_css("tableOfContents")) mods.css("note").each { |note| add_field.call("notes", note) } if (related_host = mods.at_css("relatedItem[@type='host']")) book_journal_title = related_host.at_css("titleInfo>title") @@ -275,11 +285,11 @@ add_field.call("issn", related_host.at_css("identifier[@type='issn']")) end if(related_series = mods.at_css("relatedItem[@type='series']")) if(related_series.has_attribute?("ID")) - add_field.call("series", related_series.at_css("titleInfo>title")) + add_field.call("series_facet", related_series.at_css("titleInfo>title")) end end add_field.call("publisher", mods.at_css("relatedItem>originInfo>publisher")) add_field.call("publisher_location", mods.at_css("relatedItem > originInfo>place>placeTerm[@type='text']")) @@ -288,26 +298,27 @@ mods.css("physicalDescription>internetMediaType").each { |mt| add_field.call("media_type_facet", mt) } mods.css("typeOfResource").each { |tr| add_field.call("type_of_resource_facet", tr)} mods.css("subject>geographic").each do |geo| - add_field.call("geographic_area", geo) + add_field.call("geographic_area_display", geo) add_field.call("geographic_area_search", geo) end - add_field.call("export_as_mla_citation_txt","") + # This is just a placeholder, reminding us that we need to implement citations in some way + # add_field.call("export_as_mla_citation_txt","") if(organizations.count > 0) organizations = organizations.uniq organizations.each do |organization| - add_field.call("affiliation_organization", organization) + add_field.call("organization_facet", organization) end end if(departments.count > 0) departments = departments.uniq departments.each do |department| - add_field.call("affiliation_department", department.to_s.sub(", Department of", "").strip) + add_field.call("department_facet", department.to_s.sub(", Department of", "").strip) end end end