Class: Event
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Event
- Defined in:
- backend/app/model/event.rb
Class Method Summary collapse
-
.for_archival_record_merge(target, victims) ⇒ Object
-
.for_cataloging(agent_uri, record_uri) ⇒ Object
-
.for_component_transfer(archival_object_uri, source_resource_uri, target_resource_uri) ⇒ Object
Some canned creators for system generated events.
-
.for_repository_transfer(old_repo, new_repo, record) ⇒ Object
-
.sequel_to_jsonmodel(objs, opts = {}) ⇒ Object
Instance Method Summary collapse
Class Method Details
.for_archival_record_merge(target, victims) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'backend/app/model/event.rb', line 108 def self.for_archival_record_merge(target, victims) user = User[:username => RequestContext.get(:current_username)] merge_note = "" victims.each do |victim| victim_json = victim.class.to_jsonmodel(victim) if victim_json['identifier'] identifier = Identifiers.format(Identifiers.parse(victim_json['identifier'])) else identifier = victim_json['digital_object_id'] end merge_note += (identifier + " -- " + victim_json['title'] + "\n") end event = JSONModel(:event).from_hash( :linked_agents => [{ "role" => "implementer", "ref" => JSONModel(:agent_person).uri_for(user.agent_record_id) }], :event_type => 'component_transfer', :outcome => 'pass', :outcome_note => merge_note, :timestamp => Time.now.utc.iso8601, :linked_records => [{:ref => target.uri, :role => 'outcome'}] ) Event.create_from_json(event, :system_generated => true) end |
.for_cataloging(agent_uri, record_uri) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'backend/app/model/event.rb', line 92 def self.for_cataloging(agent_uri, record_uri) #build event event = JSONModel(:event).from_hash( :linked_agents => [{:ref => agent_uri, :role => 'implementer'}], :event_type => 'cataloged', :timestamp => Time.now.utc.iso8601, :linked_records => [{:ref => record_uri, :role => 'outcome'}] ) RequestContext.in_global_repo do Event.create_from_json(event, :system_generated => true) end end |
.for_component_transfer(archival_object_uri, source_resource_uri, target_resource_uri) ⇒ Object
Some canned creators for system generated events
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'backend/app/model/event.rb', line 69 def self.for_component_transfer(archival_object_uri, source_resource_uri, target_resource_uri) # first get the current user user = User[:username => RequestContext.get(:current_username)] # build event event = JSONModel(:event).from_hash({ "event_type" => "component_transfer", "timestamp" => Time.now.utc.iso8601, "linked_records" => [ {"role" => "source", "ref" => source_resource_uri}, {"role" => "outcome", "ref" => target_resource_uri}, {"role" => "transfer", "ref" => archival_object_uri}, ], "linked_agents" => [ {"role" => "implementer", "ref" => JSONModel(:agent_person).uri_for(user.agent_record_id)} ] }) # save the event to the DB in the global context self.create_from_json(event, :system_generated => true) end |
.for_repository_transfer(old_repo, new_repo, record) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'backend/app/model/event.rb', line 143 def self.for_repository_transfer(old_repo, new_repo, record) event = { :linked_agents => [ { "role" => "transmitter", "ref" => JSONModel(:agent_corporate_entity).uri_for(old_repo.agent_representation_id) }, { "role" => "recipient", "ref" => JSONModel(:agent_corporate_entity).uri_for(new_repo.agent_representation_id) } ].reject {|l| l['ref'].nil?}, :linked_records => [ { "role" => "transfer", "ref" => record.uri } ], :event_type => 'custody_transfer', :timestamp => Time.now.utc.iso8601, } Event.create_from_json(JSONModel(:event).from_hash(event), :system_generated => true) end |
.sequel_to_jsonmodel(objs, opts = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'backend/app/model/event.rb', line 52 def self.sequel_to_jsonmodel(objs, opts = {}) jsons = super jsons.each do |json| if json['timestamp'] json['timestamp'] = json['timestamp'].iso8601 end end jsons end |
Instance Method Details
#has_active_linked_records? ⇒ Boolean
41 42 43 44 45 46 47 48 49 |
# File 'backend/app/model/event.rb', line 41 def has_active_linked_records? self.(:event_link).each do |linked_record| if linked_record.values.has_key?(:suppressed) && linked_record[:suppressed] == 0 return true end end return false end |