{"action":"created","issue":{"url":"https://api.github.com/repos/archivesspace/archivesspace/issues/326","labels_url":"https://api.github.com/repos/archivesspace/archivesspace/issues/326/labels{/name}","comments_url":"https://api.github.com/repos/archivesspace/archivesspace/issues/326/comments","events_url":"https://api.github.com/repos/archivesspace/archivesspace/issues/326/events","html_url":"https://github.com/archivesspace/archivesspace/issues/326","id":113050689,"number":326,"title":"[ead import] - incorrect parsing of primary language of materials","user":{"login":"walkerdb","id":7026330,"avatar_url":"https://avatars.githubusercontent.com/u/7026330?v=3","gravatar_id":"","url":"https://api.github.com/users/walkerdb","html_url":"https://github.com/walkerdb","followers_url":"https://api.github.com/users/walkerdb/followers","following_url":"https://api.github.com/users/walkerdb/following{/other_user}","gists_url":"https://api.github.com/users/walkerdb/gists{/gist_id}","starred_url":"https://api.github.com/users/walkerdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/walkerdb/subscriptions","organizations_url":"https://api.github.com/users/walkerdb/orgs","repos_url":"https://api.github.com/users/walkerdb/repos","events_url":"https://api.github.com/users/walkerdb/events{/privacy}","received_events_url":"https://api.github.com/users/walkerdb/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-10-23T16:08:15Z","updated_at":"2015-11-04T15:40:56Z","closed_at":"2015-11-04T15:40:56Z","body":"The [current behavior](https://github.com/archivesspace/archivesspace/blob/master/backend/app/converters/ead_converter.rb#L177) of the ASpace EAD importer is to re-assign the primary language of materials in the resource every time it encounters a ```<language>``` tag, mapping it to the value of that tag's ```@langcode``` attribute.\r\n\r\nSince this is an indiscriminate process, given a ```<langmaterial>``` tag of the following:\r\n\r\n```xml\r\n<langmaterial>\r\n   The material is mostly in <language langcode=\"eng\" encodinganalog=\"041\">English</language>; \r\n   some correspondence is in <language langcode=\"arm\" encodinganalog=\"041\">Armenian;</language>; \r\n   select items are in <language langcode=\"ger\" encodinganalog=\"041\">German</language>.\r\n</langmaterial>\r\n```\r\n\r\nby the end of the import the primary language of materials will have been assigned to \"German\", which is not correct.\r\n\r\n---------------\r\n\r\nWe wrote up the following fix at the bentley, and would be happy to make a PR if it seems acceptable. The change assumes that the first language tag appearing in the langmaterial element is the primary language of materials for the ead, and preserves the old note-making behavior for langmaterial tags:\r\n\r\n```ruby\r\nwith \"langmaterial\" do\r\n  # assigning the primary language of materials for the ead\r\n  # assumed to be the first language appearing in the langmaterial tag\r\n  langmaterial = Nokogiri::XML::DocumentFragment.parse(inner_xml)\r\n  langmaterial.children.each do |child|\r\n    if child.name == 'language'\r\n      set ancestor(:resource, :archival_object), :language, child.attr(\"langcode\")\r\n      break\r\n    end\r\n  end\r\n\r\n  # write full tag content to a note, subbing out the language tags\r\n  # copied verbatim from old langmaterial code\r\n  content = inner_xml\r\n  next if content =~ /\\A<language langcode=\\\"[a-z]+\\\"\\/>\\Z/\r\n\r\n  if content.match(/\\A<language langcode=\\\"[a-z]+\\\"\\s*>([^<]+)<\\/language>\\Z/)\r\n    content = $1\r\n  end\r\n\r\n  make :note_singlepart, {\r\n    :type => \"langmaterial\",\r\n    :persistent_id => att('id'),\r\n    :content => format_content( content.sub(/<head>.*?<\\/head>/, '') )\r\n  } do |note|\r\n    set ancestor(:resource, :archival_object), :notes, note\r\n  end\r\nend\r\n```"},"comment":{"url":"https://api.github.com/repos/archivesspace/archivesspace/issues/comments/153767026","html_url":"https://github.com/archivesspace/archivesspace/issues/326#issuecomment-153767026","issue_url":"https://api.github.com/repos/archivesspace/archivesspace/issues/326","id":153767026,"user":{"login":"walkerdb","id":7026330,"avatar_url":"https://avatars.githubusercontent.com/u/7026330?v=3","gravatar_id":"","url":"https://api.github.com/users/walkerdb","html_url":"https://github.com/walkerdb","followers_url":"https://api.github.com/users/walkerdb/followers","following_url":"https://api.github.com/users/walkerdb/following{/other_user}","gists_url":"https://api.github.com/users/walkerdb/gists{/gist_id}","starred_url":"https://api.github.com/users/walkerdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/walkerdb/subscriptions","organizations_url":"https://api.github.com/users/walkerdb/orgs","repos_url":"https://api.github.com/users/walkerdb/repos","events_url":"https://api.github.com/users/walkerdb/events{/privacy}","received_events_url":"https://api.github.com/users/walkerdb/received_events","type":"User","site_admin":false},"created_at":"2015-11-04T15:40:56Z","updated_at":"2015-11-04T15:40:56Z","body":"Fix was merged, so I'll close the issue. Thanks!"}}