<s> import dbutils <EOL> from operation import ( Operation , OperationResult , OperationFailure , Optional , <EOL> NonNegativeInteger , PositiveInteger , Review , Commit , File ) <EOL> from reviewing . comment import CommentChain , validateCommentChain , createCommentChain , createComment <EOL> class ValidateCommentChain ( Operation ) : <EOL> def __init__ ( self ) : <EOL> Operation . __init__ ( self , { "<STR_LIT>" : Review , <EOL> "<STR_LIT>" : set ( [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> "<STR_LIT>" : Optional ( Commit ) , <EOL> "<STR_LIT>" : Commit , <EOL> "<STR_LIT:file>" : File , <EOL> "<STR_LIT>" : PositiveInteger , <EOL> "<STR_LIT:count>" : PositiveInteger } ) <EOL> def process ( self , db , user , review , origin , child , file , offset , count , parent = None ) : <EOL> verdict , data = validateCommentChain ( db , review , origin , parent , child , file , offset , count ) <EOL> return OperationResult ( verdict = verdict , ** data ) <EOL> def checkComment ( text ) : <EOL> if not text . strip ( ) : <EOL> raise OperationFailure ( code = "<STR_LIT>" , <EOL> title = "<STR_LIT>" , <EOL> message = "<STR_LIT>" ) <EOL> class CreateCommentChain ( Operation ) : <EOL> def __init__ ( self ) : <EOL> Operation . __init__ ( self , { "<STR_LIT>" : Review , <EOL> "<STR_LIT>" : set ( [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> "<STR_LIT>" : Optional ( { "<STR_LIT>" : Commit , <EOL> "<STR_LIT>" : NonNegativeInteger , <EOL> "<STR_LIT:count>" : PositiveInteger } ) , <EOL> "<STR_LIT>" : Optional ( { "<STR_LIT>" : set ( [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> "<STR_LIT>" : Optional ( Commit ) , <EOL> "<STR_LIT>" : Commit , <EOL> "<STR_LIT:file>" : File , <EOL> "<STR_LIT>" : PositiveInteger , <EOL> "<STR_LIT:count>" : PositiveInteger } ) , <EOL> "<STR_LIT:text>" : str } ) <EOL> def process ( self , db , user , review , chain_type , text , commit_context = None , file_context = None ) : <EOL> checkComment ( text ) <EOL> if commit_context : <EOL> chain_id = createCommentChain ( db , user , review , chain_type , ** commit_context ) <EOL> elif file_context : <EOL> chain_id = createCommentChain ( db , user , review , chain_type , ** file_context ) <EOL> else : <EOL> chain_id = createCommentChain ( db , user , review , chain_type ) <EOL> comment_id = createComment ( db , user , chain_id , text , first = True ) <EOL> db . commit ( ) <EOL> return OperationResult ( chain_id = chain_id , comment_id = comment_id , draft_status = review . getDraftStatus ( db , user ) ) <EOL> class CreateComment ( Operation ) : <EOL> def __init__ ( self ) : <EOL> Operation . __init__ ( self , { "<STR_LIT>" : int , <EOL> "<STR_LIT:text>" : str } ) <EOL> def process ( self , db , user , chain_id , text ) : <EOL> checkComment ( text ) <EOL> chain = CommentChain . fromId ( db , chain_id , user ) <EOL> comment_id = createComment ( db , user , chain_id , text ) <EOL> db . commit ( ) <EOL> return OperationResult ( comment_id = comment_id , draft_status = chain . review . getDraftStatus ( db , user ) ) </s>
