Class: Ddr::Batch::BatchObjectRelationship

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/ddr/batch/batch_object_relationship.rb

Constant Summary collapse

RELATIONSHIP_ADMIN_POLICY =
"admin_policy"
RELATIONSHIP_COLLECTION =
"collection"
RELATIONSHIP_PARENT =
"parent"
RELATIONSHIP_ITEM =
"item"
RELATIONSHIP_COMPONENT =
"component"
RELATIONSHIP_ATTACHED_TO =
"attached_to"
RELATIONSHIPS =
[ RELATIONSHIP_ADMIN_POLICY, RELATIONSHIP_COLLECTION, RELATIONSHIP_PARENT, RELATIONSHIP_ITEM,
RELATIONSHIP_COMPONENT, RELATIONSHIP_ATTACHED_TO ]
OPERATION_ADD =
"ADD"
OPERATION_DELETE =
"DELETE"
OPERATION_UPDATE =
"UPDATE"
OPERATIONS =
[ OPERATION_ADD, OPERATION_DELETE, OPERATION_UPDATE ]
OBJECT_TYPE_REC_ID =
"REC_ID"
OBJECT_TYPE_REPO_ID =
"REPO_ID"
OBJECT_TYPES =
[ OBJECT_TYPE_REC_ID, OBJECT_TYPE_REPO_ID ]

Instance Method Summary collapse

Instance Method Details

#object_model_must_be_correct_for_relationshipObject


70
71
72
73
74
75
76
77
78
79
# File 'app/models/ddr/batch/batch_object_relationship.rb', line 70

def object_model_must_be_correct_for_relationship
  if relationship_reflection = Ddr::Utils.relationship_object_reflection(batch_object.model, name)
    klass = Ddr::Utils.reflection_object_class(relationship_reflection)
    if klass.present?
      unless object_model == klass.name
        errors.add(:object, "#{name} relationship object #{object} exists but is not a(n) #{klass}")
      end
    end
  end
end

#object_rec_id?Boolean

Returns:

  • (Boolean)

41
42
43
# File 'app/models/ddr/batch/batch_object_relationship.rb', line 41

def object_rec_id?
  object_type == OBJECT_TYPE_REC_ID
end

#object_repo_id?Boolean

Returns:

  • (Boolean)

45
46
47
# File 'app/models/ddr/batch/batch_object_relationship.rb', line 45

def object_repo_id?
  object_type == OBJECT_TYPE_REPO_ID
end

#record_must_be_in_batchObject


49
50
51
52
53
# File 'app/models/ddr/batch/batch_object_relationship.rb', line 49

def record_must_be_in_batch
  batch_objects.find(object).present?
rescue ActiveRecord::RecordNotFound
    errors.add(:object, "#{object} not found in this batch")
end

#relationship_name_must_be_valid_for_modelObject


64
65
66
67
68
# File 'app/models/ddr/batch/batch_object_relationship.rb', line 64

def relationship_name_must_be_valid_for_model
  unless Ddr::Utils.relationship_object_reflection(batch_object.model, name).present?
    errors.add(:name, "#{batch_object.model} does not define a(n) #{name} relationship")
  end
end

#repo_object_must_existObject


55
56
57
58
59
60
61
62
# File 'app/models/ddr/batch/batch_object_relationship.rb', line 55

def repo_object_must_exist
  unless found_pids.keys.include?(object)
    obj = ActiveFedora::Base.find(object)
    add_found_pid(obj.id, obj.class.name)
  end
rescue ActiveFedora::ObjectNotFoundError
  errors.add(:object, "#{object} not found in repository")
end