<s> from mongoengine import ValidationError <EOL> from pecan import abort <EOL> from pecan . rest import RestController <EOL> import six <EOL> from st2common import log as logging <EOL> from st2common . models . api . base import jsexpose <EOL> from st2common . models . api . rule import RuleTypeAPI <EOL> from st2common . persistence . rule import RuleType <EOL> http_client = six . moves . http_client <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class RuleTypesController ( RestController ) : <EOL> """<STR_LIT>""" <EOL> @ staticmethod <EOL> def __get_by_id ( id ) : <EOL> try : <EOL> return RuleType . get_by_id ( id ) <EOL> except ( ValueError , ValidationError ) as e : <EOL> msg = '<STR_LIT>' % ( id , e ) <EOL> LOG . exception ( msg ) <EOL> abort ( http_client . NOT_FOUND , msg ) <EOL> @ staticmethod <EOL> def __get_by_name ( name ) : <EOL> try : <EOL> return [ RuleType . get_by_name ( name ) ] <EOL> except ValueError as e : <EOL> LOG . debug ( '<STR_LIT>' , name , e ) <EOL> return [ ] <EOL> @ jsexpose ( arg_types = [ str ] ) <EOL> def get_one ( self , id ) : <EOL> """<STR_LIT>""" <EOL> runnertype_db = RuleTypesController . __get_by_id ( id ) <EOL> runnertype_api = RuleTypeAPI . from_model ( runnertype_db ) <EOL> return runnertype_api <EOL> @ jsexpose ( arg_types = [ str ] ) <EOL> def get_all ( self , ** kw ) : <EOL> """<STR_LIT>""" <EOL> runnertype_dbs = RuleType . get_all ( ** kw ) <EOL> runnertype_apis = [ RuleTypeAPI . from_model ( runnertype_db ) <EOL> for runnertype_db in runnertype_dbs ] <EOL> return runnertype_apis </s>
