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 js_server = self.pool.get('jasper.server') 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 curr = self.browse(cr, uid, ids[0], context=context) 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'), str(e).decode('utf-8'))
def check_auth(self, cr, uid, ids, context=None): """ Check if we can contact JasperServer instance and check the authentification """ 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: return self.write(cr, uid, ids, {'status': _('Error, server not found %s %d') % (js.host, js.port)}, context=context) except jasperlib.AuthError: return self.write(cr, uid, ids, {'status': _('Error, Authentification failed for %s/%s') % (js.user, js.pwd)}, context=context) return self.write(cr, uid, ids, {'status': _('Connection OK')}, context=context)