Parent

Class Index [+]

Quicksearch

TaskJuggler::ReportServlet

Public Class Methods

get_instance(config, options) click to toggle source
    # File lib/taskjuggler/daemon/ReportServlet.rb, line 25
25:     def self.get_instance(config, options)
26:       self.new(config, *options)
27:     end
new(config, *options) click to toggle source
    # File lib/taskjuggler/daemon/ReportServlet.rb, line 20
20:     def initialize(config, *options)
21:       super
22:       @broker = options[0]
23:     end

Public Instance Methods

do_GET(req, res) click to toggle source
    # File lib/taskjuggler/daemon/ReportServlet.rb, line 29
29:     def do_GET(req, res)
30:       @req = req
31:       @res = res
32:       begin
33:         projectId = req.query['project']
34:         reportId = req.query['report']
35:         if projectId.nil? || reportId.nil?
36:           generateWelcomePage(projectId)
37:         else
38:           attributes = req.query['attributes'] || ''
39:           attributes = URLParameter.decode(attributes) unless attributes.empty?
40:           generateReport(projectId, reportId, attributes)
41:         end
42:       rescue
43:       end
44:     end

Private Instance Methods

error(message) click to toggle source
     # File lib/taskjuggler/daemon/ReportServlet.rb, line 157
157:     def error(message)
158:       @res.status = 412
159:       @res.body = "ERROR: #{message}"
160:       @res['content-type'] = 'text/plain'
161:       raise "Error: #{message}"
162:     end
generateReport(projectId, reportId, attributes) click to toggle source
     # File lib/taskjuggler/daemon/ReportServlet.rb, line 48
 48:     def generateReport(projectId, reportId, attributes)
 49:       # Request the Project credentials from the ProbjectBroker.
 50:       @ps_uri, @ps_authKey = @broker.getProject(projectId)
 51:       if @ps_uri.nil?
 52:         error("No project with ID #{projectId} loaded")
 53:       end
 54:       # Get the responsible ReportServer that can generate the report.
 55:       begin
 56:         @projectServer = DRbObject.new(nil, @ps_uri)
 57:         @rs_uri, @rs_authKey = @projectServer.getReportServer(@ps_authKey)
 58:         @reportServer = DRbObject.new(nil, @rs_uri)
 59:       rescue
 60:         error("Cannot get report server")
 61:       end
 62:       # Create two StringIO buffers that will receive the $stdout and $stderr
 63:       # text from the report server. This buffer will contain the generated
 64:       # report as HTML encoded text. They will be send via DRb, so we have to
 65:       # extend them with DRbUndumped.
 66:       stdOut = StringIO.new('')
 67:       stdOut.extend(DRbUndumped)
 68:       stdErr = StringIO.new('')
 69:       stdErr.extend(DRbUndumped)
 70: 
 71:       begin
 72:         @reportServer.connect(@rs_authKey, stdOut, stdErr, $stdin, true)
 73:       rescue
 74:         error("Can't connect IO: #{$!}")
 75:       end
 76: 
 77:       # Ask the ReportServer to generate the reports with the provided ID.
 78:       begin
 79:         @reportServer.generateReport(@rs_authKey, reportId, false, nil,
 80:                                      attributes)
 81:       rescue
 82:         stdOut.rewind
 83:         stdErr.rewind
 84:         error("Report server crashed: #{$!}\n#{stdErr.read}\n#{stdOut.read}")
 85:       end
 86:       # Disconnect the ReportServer
 87:       begin
 88:         @reportServer.disconnect(@rs_authKey)
 89:       rescue
 90:         error("Can't disconnect IO: #{$!}")
 91:       end
 92:       # And send a termination request.
 93:       begin
 94:         @reportServer.terminate(@rs_authKey)
 95:       rescue
 96:         error("Report server termination failed: #{$!}")
 97:       end
 98:       @reportServer = nil
 99: 
100:       @res['content-type'] = 'text/html'
101:       stdErr.rewind
102:       $stderr.puts stdErr.read
103:       # To read the $stdout of the ReportServer we need to rewind the buffer
104:       # and then read the full text.
105:       stdOut.rewind
106:       @res.body = stdOut.read
107:     end
generateWelcomePage(projectId) click to toggle source
     # File lib/taskjuggler/daemon/ReportServlet.rb, line 109
109:     def generateWelcomePage(projectId)
110:       projects = @broker.getProjectList
111: 
112:       text = "== Welcome to the TaskJuggler Project Server ==\n----\n"
113:       projects.each do |id|
114:         if id == projectId
115:           # Show the list of reports for this project.
116:           text << "* [/taskjuggler #{getProjectName(id)}]\n"
117:           reports = getReportList(id)
118:           if reports.empty?
119:             text << "** This project has no reports defined.\n"
120:           else
121:             reports.each do |reportId, reportName|
122:               text << "** [/taskjuggler?project=#{id};report=#{reportId} " +
123:                       "#{reportName}]\n"
124:             end
125:           end
126:         else
127:           # Just show a link to open the report list.
128:           text << "* [/taskjuggler?project=#{id} #{getProjectName(id)}]\n"
129:         end
130:       end
131:       rt = RichText.new(text)
132:       rti = rt.generateIntermediateFormat
133:       rti.sectionNumbers = false
134:       page = HTMLDocument.new
135:       page.generateHead("The TaskJuggler Project Server")
136:       page.html << rti.to_html
137:       @res['content-type'] = 'text/html'
138:       @res.body = page.to_s
139:     end
getProjectName(id) click to toggle source
     # File lib/taskjuggler/daemon/ReportServlet.rb, line 141
141:     def getProjectName(id)
142:       uri, authKey = @broker.getProject(id)
143:       return nil unless uri
144:       projectServer = DRbObject.new(nil, uri)
145:       return nil unless projectServer
146:       projectServer.getProjectName(authKey)
147:     end
getReportList(id) click to toggle source
     # File lib/taskjuggler/daemon/ReportServlet.rb, line 149
149:     def getReportList(id)
150:       uri, authKey = @broker.getProject(id)
151:       return [] unless uri
152:       projectServer = DRbObject.new(nil, uri)
153:       return [] unless projectServer
154:       projectServer.getReportList(authKey)
155:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.