class Teneo::DataModel::IngestModel

noinspection RailsParamDefResolve

Public Class Methods

from_hash(hash, id_tags = [:ingest_agreement_id, :name]) click to toggle source
Calls superclass method Teneo::DataModel::Base::from_hash
# File lib/teneo/data_model/ingest_model.rb, line 34
def self.from_hash(hash, id_tags = [:ingest_agreement_id, :name])
  agreement_name = hash.delete(:ingest_agreement)
  query = agreement_name ? {name: agreement_name} : {id: hash[:ingest_agreement_id]}
  ingest_agreement = record_finder Teneo::DataModel::IngestAgreement, query
  hash[:ingest_agreement_id] = ingest_agreement.id

  representations = hash.delete(:representations)

  item = super(hash, id_tags) do |item, h|
    item.access_right = record_finder Teneo::DataModel::AccessRight, name: h.delete(:access_right)
    item.retention_policy = record_finder Teneo::DataModel::RetentionPolicy, name: h.delete(:retention_policy)
  end

  if representations
    item.representations.clear
    representations.each_with_index do |representation, index|
      representation[:ingest_model_id] = item.id
      representation[:position] = index + 1
      Teneo::DataModel::Representation.from_hash(representation)
    end
    item.save!
  end

  item
end

Public Instance Methods

template_reference() click to toggle source
# File lib/teneo/data_model/ingest_model.rb, line 29
def template_reference
  return if template.nil?
  errors.add(:template_id, 'should be a template') unless template.ingest_agreement.nil?
end