[Archivesspace_Users_Group] Plugin: Custom import mapping for MarcXML Agents, help

Brian Hoffman brianjhoffman at gmail.com
Wed Sep 9 08:20:01 EDT 2015


Hi,

I think you made the problem quite clear. I think the key is this: it’s not that obvious, but the MarcXML converter has a few different styles for mapping XML nodes to the ASpace data model. You are using the ‘object’ mapping:


> config["/record"][:map]["controlfield[@tag='001']"] = {:rel => something, :obj => something …}


This is meant to make it easy to do the mappings by just filling out those object properties, but it isn’t that flexible. You probably want to just use the other option, which is to map the controlfield to a functional block that will receive two parameters: the base resource record and the XML node. For an example, see:

https://github.com/archivesspace/archivesspace/blob/master/backend/app/converters/marcxml_accession_converter.rb#L74 <https://github.com/archivesspace/archivesspace/blob/master/backend/app/converters/marcxml_accession_converter.rb#L74>

However, your case is a little unusual, in that you are mapping two siblings to a single ASpace record, so you’re going to have to use a trick to get access to the agent record created by the standard mapping. Something like this:

config["/record"][:map]["controlfield[@tag='001']”] = -> (resource, node) {
  existing_agent_uri = resource.linked_agents.find {|link| link[:ref] =~ /people/ }
  existing_agent = @batch.working_area.find {|obj| obj.uri == existing_agent_uri }
  make(:name_person) do |name|
    name.primary = node.xpath(“subfield[@code=‘a’]).inner_text
    # add more name fields as necessary
    existing_agent.names << name
  end
}

That’s just an idea and may not work as is. If you want to put your code up on Github I can try to help more.

Brian
 



> On Sep 9, 2015, at 1:35 AM, Carlos Lemus <carlos.lemus at unlv.edu> wrote:
> 
> Hello, 
> 
> My question is how do i map the controlfield to one agent? it is currently creating two and the control field does not have a primary name to complete the job (Returns an error primary name missing)
> 
> I am working on a plugin to import agents from a marcxml file. There is a lot of fields the current mapping for agents doesn't have. To begin, I have started with trying to import the authority id from the controlfield tag=001. I have been able to mimic and learn a lot of the mapping system through yale_marcxml2accession plugin. 
> 
> I've been able to accomplish importing mapping the authority id to the field, but only if i add a pirmary name to the name_person object, because what is happening is it is creating two agents as far as I can see from the log debugs I created. One of the log debugs is in the agent template (working with the agent/person template mix) 
> #<JSONModel(:agent_person) {"jsonmodel_type"=>"agent_person", "agent_contacts"=>[], "linked_agent_roles"=>[], "external_documents"=>[], "rights_statements"=>[], "notes"=>[], "dates_of_existence"=>[], "names"=>[#<JSONModel(:name_person) {"jsonmodel_type"=>"name_person", "use_dates"=>[], "authorized"=>false, "is_display_name"=>false, "sort_name_auto_generate"=>true, "uri"=>nil, "primary_name"=>"Goodman", "rest_of_name"=>"Oscar Baylin,", "dates"=>"1939-", "name_order"=>"inverted", "source"=>"ingest"}>], "related_agents"=>[], "uri"=>"/agents/people/import_7faac81f-c32b-4bb5-8a5a-8daff5d1161b", "dates"=>"1939-"}>
> 
> and the other is from the mapping of the code below (working with the authority id)
>  #<JSONModel(:agent_person) {"jsonmodel_type"=>"agent_person", "agent_contacts"=>[], "linked_agent_roles"=>[], "external_documents"=>[], "rights_statements"=>[], "notes"=>[], "dates_of_existence"=>[], "names"=>[#<JSONModel(:name_person) {"jsonmodel_type"=>"name_person", "use_dates"=>[], "authorized"=>false, "is_display_name"=>false, "sort_name_auto_generate"=>true, "uri"=>nil, "authority_id"=>"n 2003051366", "name_order"=>"direct", "source"=>"ingest"}>], "related_agents"=>[], "uri"=>"/agents/people/import_9ff38423-fbaa-4d9c-bd1e-e3a65f4244c7"}>
> 
> 
> The code below also debugs the resource that shows both agents under the linked agents 
> #<JSONModel(:resource) {"jsonmodel_type"=>"resource", "external_ids"=>[], "subjects"=>[], "linked_events"=>[], "extents"=>[], "dates"=>[], "external_documents"=>[], "rights_statements"=>[], "linked_agents"=>[{:role=>"subject", :terms=>[], :relator=>nil, :ref=>"/agents/people/import_7faac81f-c32b-4bb5-8a5a-8daff5d1161b"}, {:role=>"subject", :terms=>[], :relator=>nil, :ref=>"/agents/people/import_9ff38423-fbaa-4d9c-bd1e-e3a65f4244c7"}], "restrictions"=>false, "revision_statements"=>[], "instances"=>[], "deaccessions"=>[], "related_accessions"=>[], "classifications"=>[], "notes"=>[], "hello_worlds"=>[], "uri"=>"/repositories/import/resources/import_9ed9d5ea-7ee6-47a5-986c-db937dd78d88", "language"=>nil, "finding_aid_description_rules"=>"rda", "id_0"=>"imported-1e46e675-3833-4483-ada1-5960a16004c6"}>
> 
> I want to basically end up with the two of these combined in the sense of primary_name, dates, authority_id, etc can be imported as one agent. There is some relationship to the first agent created I'm missing if someone could help me fill that link I'd appreciate it. Let me know if I need to clarify anything.
> 
> 
> config["/record"][:map]["controlfield[@tag='001']"] = {
>     :rel => -> resource, agent {
>        resource[:linked_agents] << {
>          # stashed value for the role
>          :role => agent['_role'] || 'subject',
>          :terms => agent['_terms'] || [],
>          :relator => agent['_relator'],
>          :ref => agent.uri
>        }
>        Log.debug(agent)
>        Log.debug(resource)
>      },
>     :obj => :agent_person,
>     :map => {
>     "self::controlfield" => {
>        :obj => :name_person,
>        :rel => :names,
>        :map => {
>           "self::controlfield" => -> name, node {
>  
>               val = node.inner_text
>              #name['primary_name'] = test 
>              name['authority_id'] = val
>        }
>     },
>     :defaults => {
>        :name_order => 'direct',
>        :source => 'ingest'
>     }
>     }
>    }
>  }
> 
> Thank you
> 
> 
> 
> _______________________________________________
> Archivesspace_Users_Group mailing list
> Archivesspace_Users_Group at lyralists.lyrasis.org
> http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lyralists.lyrasis.org/pipermail/archivesspace_users_group/attachments/20150909/6282af7f/attachment.html>


More information about the Archivesspace_Users_Group mailing list