Module: ASModel::RepositoryTransfers::ClassMethods

Defined in:
backend/app/model/ASModel_transfers.rb

Instance Method Summary collapse

Instance Method Details

#report_incompatible_constraints(source_repository, target_repository) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'backend/app/model/ASModel_transfers.rb', line 51

def report_incompatible_constraints(source_repository, target_repository)
  problems = {}

  repo_unique_constraints.each do |constraint|
    target_repo_values = self.filter(:repo_id => target_repository.id).
                              select(constraint[:property])

    overlapping_in_source = self.filter(:repo_id => source_repository.id,
                                        constraint[:property] => target_repo_values).
                                 select(:id)

    if overlapping_in_source.count > 0
      overlapping_in_source.each do |obj|
        problems[obj.uri] ||= []
        problems[obj.uri] << {
          :json_property => constraint[:json_property],
          :message => constraint[:message]
        }
      end
    end
  end

  if !problems.empty?
    raise TransferConstraintError.new(problems)
  end
end

#transfer_all(source_repository, target_repository) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'backend/app/model/ASModel_transfers.rb', line 79

def transfer_all(source_repository, target_repository)
  if self.columns.include?(:repo_id)

    report_incompatible_constraints(source_repository, target_repository)


    # One delete marker per URI
    if self.has_jsonmodel?
      jsonmodel = self.my_jsonmodel
      self.filter(:repo_id => source_repository.id).select(:id).each do |row|
        Tombstone.create(:uri => jsonmodel.uri_for(row[:id], :repo_id => source_repository.id))
      end
    end

    self.filter(:repo_id => source_repository.id).
         update(:repo_id => target_repository.id,
                :system_mtime => Time.now)
  end
end