1 # Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de).
3 # This file is part of ECS.
5 # ECS is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Affero General Public License as
7 # published by the Free Software Foundation, either version 3 of
8 # the License, or (at your option) any later version.
10 # ECS is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public
16 # License along with ECS. If not, see <http://www.gnu.org/licenses/>.
19 class EventsController < ApplicationController
21 before_action :authentication
22 before_action :add_cookie_header # only for anonymous participants
29 count = params["count"].blank? ? -1 : params["count"].to_i
30 events_render(@participant.id, count)
37 count = params["count"].blank? ? 1 : params["count"].to_i
38 events_render(@participant.id, count)
40 rescue ActiveRecord::StaleObjectError, ActiveRecord::RecordNotFound => error
41 logger.info "**** Concurrent access at events queue (max_tries=#{max_tries})."
43 retry unless max_tries <= 0
50 def events_render(participant_id, count)
53 Event.for_participant(participant_id,count).each do |event|
56 # do not destroy message if another reference in events to the message
57 # exists or the message is not marked as removed
58 unless Event.find_by_message_id(event.message.id) or !event.message.removed
64 :ressource => event.message.ressource.namespace + "/" +
65 event.message.ressource.ressource + "/" +
66 event.message.id.to_s,
67 :status => event.ev_type.name
70 respond_to do |format|
71 format.json { render :json => JSON.pretty_generate(events) }
72 format.xml { render :xml => events }
73 format.text { render :plain => events_render_txt(events) }
77 def events_render_txt(events)
79 events.each do |event|
80 events_txt << event[:ressource] + " " + event[:status] + "\r\n"