class Libis::Services::Digitool::DigitalEntityManager

Public Class Methods

new() click to toggle source
# File lib/libis/services/digitool/digital_entity_manager.rb, line 16
def initialize
  setup 'DigitalEntityManager'
end

Public Instance Methods

add_relations(pid, relation_type, related_pids) click to toggle source
# File lib/libis/services/digitool/digital_entity_manager.rb, line 113
def add_relations(pid, relation_type, related_pids)
  relations = []
  related_pids.each do |p|
    relations << {'cmd' => 'insert',
                  'type' => relation_type.to_s,
                  'pid' => p.to_s
    }
  end
  update_object({'pid' => pid.to_s,
                 'relation' => relations
                },
                {'relation' => 'delta'}
  )
end
create_object(de_info) click to toggle source
# File lib/libis/services/digitool/digital_entity_manager.rb, line 20
def create_object(de_info)
  de_call = create_digital_entity_call de_info, 'create'
  request :digital_entity_call, :general => general.to_s, :digital_entity_call => de_call.to_s
end
delete_object(pid) click to toggle source
# File lib/libis/services/digitool/digital_entity_manager.rb, line 30
def delete_object(pid)
  de_info = {'pid' => pid}
  de_options = {'metadata' => 'all', 'relation' => 'all'}
  de_call1 = create_digital_entity_call de_info, 'update', de_options
  result = request :digital_entity_call, :general => 200.to_s, :digital_entity_call => de_call1.to_s
  return result if result[:error] and result[:error].size > 0
  de_call2 = create_digital_entity_call de_info, 'delete'
  request :digital_entity_call, :general => general.to_s, :digital_entity_call => de_call2.to_s
end
retrieve_object(pid) click to toggle source
# File lib/libis/services/digitool/digital_entity_manager.rb, line 40
def retrieve_object(pid)
  de_info = {'pid' => pid}
  de_call = create_digital_entity_call de_info, 'retrieve'
  request :digital_entity_call, :general => general.to_s, :digital_entity_call => de_call.to_s
end
update_object(de_info, update_options = {}) click to toggle source
# File lib/libis/services/digitool/digital_entity_manager.rb, line 25
def update_object(de_info, update_options = {})
  de_call = create_digital_entity_call de_info, 'update', update_options
  request :digital_entity_call, :general => general.to_s, :digital_entity_call => de_call.to_s
end
update_stream(pid, filename) click to toggle source
# File lib/libis/services/digitool/digital_entity_manager.rb, line 128
def update_stream(pid, filename)
  update_object({'pid' => pid,
                 'stream_ref' =>
                     {'cmd' => 'update',
                      'store_command' => 'copy',
                      'location' => 'nfs',
                      'file_name' => filename
                     }
                }
  )
end

Private Instance Methods

create_digital_entity_call(de_info = {}, command = 'create', update_options = {}) click to toggle source
# File lib/libis/services/digitool/digital_entity_manager.rb, line 142
def create_digital_entity_call(de_info = {}, command = 'create', update_options = {})
  # de_info is a hash like this:
  # { 'vpid' => 0, || 'pid' => 0,
  #   'control' => { 'label' => 'abc', 'usage_type' => 'archive' },
  #   'metadata' => [ { 'name' => 'descriptive', 'type' => 'dc', 'value' => '<record>...</record>'},
  #                   { 'cmd' => 'insert', 'link_to_exists' => true, 'mid' => '12345' } ],
  #   'relation' => [ { 'cmd' => 'update', 'type' => 'manifestation', 'pid' => '12345' },
  #                   { 'cmd' => 'delete', 'type' => 'part_of', pid => '12345' } ],
  #   'stream_ref' => { 'file_name' => 'abc.tif', 'file_extension' => 'tif', ... }
  # }
  # update_options is something like this:
  # { 'metadata' => 'delta',
  #   'relation' => 'all',
  # }
  digital_entity_call = Libis::Tools::XmlDocument.new
  root = digital_entity_call.create_node('digital_entity_call',
                                         :namespaces => {:node_ns => 'xb',
                                                         'xb' => 'http://com/exlibris/digitool/repository/api/xmlbeans'})
  digital_entity_call.root = root

  root << (digital_entity = digital_entity_call.create_node('xb:digital_entity'))
  digital_entity << digital_entity_call.create_text_node('pid', de_info['pid']) if de_info['pid']
  digital_entity << digital_entity_call.create_text_node('vpid', de_info['vpid']) if de_info['vpid']
  if de_info['control']
    digital_entity << (ctrl = digital_entity_call.create_node('control'))
    de_info['control'].each { |k, v| ctrl << digital_entity_call.create_text_node(k.to_s, v.to_s) }
  end
  if de_info['metadata'] || update_options['metadata']
    attributes = {}
    cmd = update_options.delete 'metadata'
    attributes['cmd'] = 'delete_and_insert_' + cmd if cmd
    digital_entity << (mds = digital_entity_call.create_node('mds', :attributes => attributes))
    if de_info['metadata']
      de_info['metadata'].each do |m|
        attributes = {}
        shared = m.delete 'shared'
        attributes['shared'] = shared if shared
        cmd = m.delete 'cmd'
        attributes['cmd'] = cmd if cmd
        link_to_exists = m.delete 'link_to_exists'
        attributes['link_to_exists'] = link_to_exists if link_to_exists
        mds << (md = digital_entity_call.create_node('md', :attributes => attributes))
        m.each { |k, v| md << digital_entity_call.create_text_node(k.to_s, v.to_s) }
      end
    end
  end
  if de_info['relation'] || update_options['relation']
    attributes = {}
    cmd = update_options.delete 'relation'
    attributes['cmd'] = 'delete_and_insert_' + cmd if cmd
    digital_entity << (relations = digital_entity_call.create_node('relations', :attributes => attributes))
    if de_info['relation']
      de_info['relation'].each do |r|
        attributes = {}
        cmd = r.delete 'cmd'
        attributes['cmd'] = cmd if cmd
        relations << (relation = digital_entity_call.create_node('relation', :attributes => attributes))
        r.each { |k, v| relation << digital_entity_call.create_text_node(k.to_s, v.to_s) }
      end
    end
  end
  f = de_info['stream_ref']
  if f
    attributes = {}
    cmd = f.delete 'cmd'
    attributes['cmd'] = cmd if cmd
    store_command = f.delete 'store_command'
    attributes['store_command'] = store_command if store_command
    location = f.delete 'location'
    attributes['location'] = location if location
    digital_entity << (stream_ref = digital_entity_call.create_node('stream_ref', :attributes => attributes))
    de_info['stream_ref'].each { |k, v| stream_ref << digital_entity_call.create_text_node(k.to_s, v.to_s) }
  end
  root << digital_entity_call.create_text_node('command', command)
  digital_entity_call.document
end