Parent

Class Index [+]

Quicksearch

TaskJuggler::ReportServlet

Public Class Methods

get_instance(config, options) click to toggle source
    # File lib/daemon/WebServer.rb, line 86
86:     def self.get_instance(config, options)
87:       self.new(config, *options)
88:     end
new(config, *options) click to toggle source
    # File lib/daemon/WebServer.rb, line 82
82:     def initialize(config, *options)
83:       @broker = options[0]
84:     end

Public Instance Methods

do_GET(req, res) click to toggle source
     # File lib/daemon/WebServer.rb, line 90
 90:     def do_GET(req, res)
 91:       @req = req
 92:       @res = res
 93:       begin
 94:         projectId = req.query['project']
 95:         reportId = req.query['report']
 96:         if projectId.nil? || reportId.nil?
 97:           generateWelcomePage(projectId)
 98:         else
 99:           attributes = req.query['attributes'] || ''
100:           attributes = URLParameter.decode(attributes) unless attributes.empty?
101:           generateReport(projectId, reportId, attributes)
102:         end
103:       rescue
104:       end
105:     end

Private Instance Methods

error(message) click to toggle source
     # File lib/daemon/WebServer.rb, line 213
213:     def error(message)
214:       @res.status = 412
215:       @res.body = "ERROR: #{message}"
216:       @res['content-type'] = 'text/plain'
217:       raise "Error: #{message}"
218:     end
generateReport(projectId, reportId, attributes) click to toggle source
     # File lib/daemon/WebServer.rb, line 109
109:     def generateReport(projectId, reportId, attributes)
110:       # Request the Project credentials from the ProbjectBroker.
111:       @ps_uri, @ps_authKey = @broker.getProject(projectId)
112:       if @ps_uri.nil?
113:         error("No project with ID #{projectId} loaded")
114:       end
115:       # Get the responsible ReportServer that can generate the report.
116:       begin
117:         @projectServer = DRbObject.new(nil, @ps_uri)
118:         @rs_uri, @rs_authKey = @projectServer.getReportServer(@ps_authKey)
119:         @reportServer = DRbObject.new(nil, @rs_uri)
120:       rescue
121:         error("Cannot get report server")
122:       end
123:       # Create two StringIO buffers that will receive the $stdout and $stderr
124:       # text from the report server. This buffer will contain the generated
125:       # report as HTML encoded text.
126:       stdOut = StringIO.new('')
127:       stdErr = StringIO.new('')
128:       begin
129:         @reportServer.connect(@rs_authKey, stdOut, stdErr, $stdin, true)
130:       rescue
131:         error("Can't connect IO: #{$!}")
132:       end
133: 
134:       # Ask the ReportServer to generate the reports with the provided ID.
135:       begin
136:         @reportServer.generateReport(@rs_authKey, reportId, false, attributes)
137:       rescue
138:         stdOut.rewind
139:         stdErr.rewind
140:         error("Report server crashed: #{$!}\n#{stdErr.read}\n#{stdOut.read}")
141:       end
142:       # Disconnect the ReportServer
143:       begin
144:         @reportServer.disconnect(@rs_authKey)
145:       rescue
146:         error("Can't disconnect IO: #{$!}")
147:       end
148:       # And send a termination request.
149:       begin
150:         @reportServer.terminate(@rs_authKey)
151:       rescue
152:         error("Report server termination failed: #{$!}")
153:       end
154:       @reportServer = nil
155: 
156:       @res['content-type'] = 'text/html'
157:       stdErr.rewind
158:       $stderr.puts stdErr.read
159:       # To read the $stdout of the ReportServer we need to rewind the buffer
160:       # and then read the full text.
161:       stdOut.rewind
162:       @res.body = stdOut.read
163:     end
generateWelcomePage(projectId) click to toggle source
     # File lib/daemon/WebServer.rb, line 165
165:     def generateWelcomePage(projectId)
166:       projects = @broker.getProjectList
167: 
168:       text = "== Welcome to the TaskJuggler Project Server ==\n----\n"
169:       projects.each do |id|
170:         if id == projectId
171:           # Show the list of reports for this project.
172:           text << "* [/taskjuggler #{getProjectName(id)}]\n"
173:           reports = getReportList(id)
174:           if reports.empty?
175:             text << "** This project has no reports defined.\n"
176:           else
177:             reports.each do |reportId, reportName|
178:               text << "** [/taskjuggler?project=#{id};report=#{reportId} " +
179:                       "#{reportName}]\n"
180:             end
181:           end
182:         else
183:           # Just show a link to open the report list.
184:           text << "* [/taskjuggler?project=#{id} #{getProjectName(id)}]\n"
185:         end
186:       end
187:       rt = RichText.new(text)
188:       rti = rt.generateIntermediateFormat
189:       rti.sectionNumbers = false
190:       page = HTMLDocument.new
191:       page.generateHead("The TaskJuggler Project Server")
192:       page << rti.to_html
193:       @res['content-type'] = 'text/html'
194:       @res.body = page.to_s
195:     end
getProjectName(id) click to toggle source
     # File lib/daemon/WebServer.rb, line 197
197:     def getProjectName(id)
198:       uri, authKey = @broker.getProject(id)
199:       return nil unless uri
200:       projectServer = DRbObject.new(nil, uri)
201:       return nil unless projectServer
202:       projectServer.getProjectName(authKey)
203:     end
getReportList(id) click to toggle source
     # File lib/daemon/WebServer.rb, line 205
205:     def getReportList(id)
206:       uri, authKey = @broker.getProject(id)
207:       return [] unless uri
208:       projectServer = DRbObject.new(nil, uri)
209:       return [] unless projectServer
210:       projectServer.getReportList(authKey)
211:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.