def check_auth(self, cr, uid, ids, context=None): """ Check if we can join the JasperServer instance, send the authentification and check the result """ js_config = self.read(cr, uid, ids[0], context=context) try: js = jasperlib.Jasper(host=js_config['host'], port=js_config['port'], user=js_config['user'], pwd=js_config['pass']) js.auth() except jasperlib.ServerNotFound: message = _('Error, JasperServer not found at %s (port: %d)') % ( js.host, js.port) # noqa _logger.error(message) return self.write(cr, uid, ids, {'status': message}, context=context) except jasperlib.AuthError: message = _( 'Error, JasperServer authentification failed for user %s/%s' ) % (js.user, js.pwd) # noqa _logger.error(message) return self.write(cr, uid, ids, {'status': message}, context=context) return self.write(cr, uid, ids, {'status': _('JasperServer Connection OK')}, context=context)
def check_report(self, cr, uid, ids, context=None): # TODO, use jasperlib to check if report exists curr = self.browse(cr, uid, ids[0], context=context) js_server = self.pool['jasper.server'] if curr.server_id: jss = js_server.browse(cr, uid, curr.server_id.id, context=context) else: js_server_ids = js_server.search(cr, uid, [('enable', '=', True)], context=context) if not js_server_ids: raise osv.except_osv( _('Error'), _('No JasperServer configuration found !') ) jss = js_server.browse(cr, uid, js_server_ids[0], context=context) def compose_path(basename): return jss['prefix'] and \ '/' + jss['prefix'] + '/instances/%s/%s' or basename try: js = jasperlib.Jasper(jss.host, jss.port, jss.user, jss['pass']) js.auth() uri = compose_path('/openerp/bases/%s/%s') % (cr.dbname, curr.report_unit) envelop = js.run_report(uri=uri, output='PDF', params={}) js.send(jasperlib.SoapEnv('runReport', envelop).output()) except jasperlib.ServerNotFound: raise osv.except_osv( _('Error'), _('Error, server not found %s %d') % (js.host, js.port)) except jasperlib.AuthError: raise osv.except_osv( _('Error'), _('Error, Authentification failed for %s/%s') % (js.user, js.pwd)) except jasperlib.ServerError, e: raise osv.except_osv(_('Error'), e)
special_dict['CUSTOM_' + d.upper()] = self.custom[d] # If special value is available in context, # we add them as parameters if context.get('jasper') and isinstance(context['jasper'], dict): for d in context['jasper'].keys(): special_dict['CONTEXT_' + d.upper()] = context['jasper'][d] par = parameter_dict(self.attrs, d_par, special_dict) # Execute the before query if it available if js_conf.get('before'): self.cr.execute(js_conf['before'], {'id': ex}) try: js = jslib.Jasper(js_conf['host'], js_conf['port'], js_conf['user'], js_conf['pass']) js.auth() envelop = js.run_report(uri=self.path or self.attrs['params'][1], output=self.outputFormat.upper(), params=par) response = js.send( jslib.SoapEnv('runReport', envelop).output()) content = response['data'] mimetype = response['content-type'] ParseResponse(response, pdf_list, self.outputFormat) except jslib.ServerNotFound: raise JasperException(_('Error'), _('Server not found !')) except jslib.AuthError: raise JasperException(_('Error'), _('Autentification failed !')) # noqa