parameters: (self, request, response)
docstring: Handles add search definition request.
  
      Args:
        request: request object.
        response: response object.
  
      Raises:
        SearchPublishServeException, psycopg2.Warning/Error.
docstring_summary: Handles add search definition request.
docstring_tokens: Handles add search definition request .
function: def HandleAddSearchDefRequest(self, request, response):
      """Handles add search definition request.
  
      Args:
        request: request object.
        response: response object.
  
      Raises:
        SearchPublishServeException, psycopg2.Warning/Error.
      """
      logger.debug("HandleAddSearchDefRequest...")
  
      search_def_name = request.GetIdentifier(constants.SEARCH_DEF_NAME)
      if not search_def_name:
        raise exceptions.SearchPublishServeException(
            "HandleAddSearchDefRequest: missing or invalid name of search"
            " definition.")
  
      search_def_content = request.GetParameter(constants.SEARCH_DEF)
      if not search_def_content:
        raise exceptions.SearchPublishServeException(
            "HandleAddSearchDefRequest: missing search definition data.")
  
      try:
        # The content of SearchDef will be sanitized when de-serializing.
        search_def_content_obj = basic_types.SearchDefContent.Deserialize(
            search_def_content)
      except Exception as e:
        raise exceptions.SearchPublishServeException(
            "HandleAddSearchDefRequest:"
            " couldn't parse search definition data. Error: %s", str(e))
  
      # Update search definition content serializing from object.
      search_def_content = search_def_content_obj.DumpJson()
  
      # Check if search definition already exists.
      search_def_id = self._QuerySearchDefId(search_def_name)
      logger.debug("HandleAddSearchDefRequest: search_def_id: %d", search_def_id)
  
      if search_def_id > 0:
        # It's ok if search definition already exists. It means we edit existing
        # search definition.
        logger.debug("Update search definition: %s", search_def_name)
  
        if search_def_name in SearchPublishManager.SYSTEM_SEARCH_DEF_LIST:
          raise exceptions.SearchPublishServeException(
              "HandleAddSearchDefRequest:"
              " system default search definition can't be edited.")
  
        query_string = (
            "UPDATE search_def_table SET search_def_content = %s"
            " WHERE search_def_id = %s")
        self._DbModify(query_string, (search_def_content, search_def_id))
      else:
        logger.debug("Add search definition: %s", search_def_name)
        query_string = (
            "INSERT INTO search_def_table (search_def_name, search_def_content)"
            " VALUES(%s, %s)")
        self._DbModify(query_string, (search_def_name, search_def_content))
  
      search_def_obj = self.__BuildSearchDefObj(
          search_def_name, search_def_content)
  
      http_io.ResponseWriter.AddJsonBody(
          response, constants.STATUS_SUCCESS, search_def_obj)
function_tokens: def HandleAddSearchDefRequest ( self , request , response ) : logger . debug ( "HandleAddSearchDefRequest..." ) search_def_name = request . GetIdentifier ( constants . SEARCH_DEF_NAME ) if not search_def_name : raise exceptions . SearchPublishServeException ( "HandleAddSearchDefRequest: missing or invalid name of search" " definition." ) search_def_content = request . GetParameter ( constants . SEARCH_DEF ) if not search_def_content : raise exceptions . SearchPublishServeException ( "HandleAddSearchDefRequest: missing search definition data." ) try : # The content of SearchDef will be sanitized when de-serializing. search_def_content_obj = basic_types . SearchDefContent . Deserialize ( search_def_content ) except Exception as e : raise exceptions . SearchPublishServeException ( "HandleAddSearchDefRequest:" " couldn't parse search definition data. Error: %s" , str ( e ) ) # Update search definition content serializing from object. search_def_content = search_def_content_obj . DumpJson ( ) # Check if search definition already exists. search_def_id = self . _QuerySearchDefId ( search_def_name ) logger . debug ( "HandleAddSearchDefRequest: search_def_id: %d" , search_def_id ) if search_def_id > 0 : # It's ok if search definition already exists. It means we edit existing # search definition. logger . debug ( "Update search definition: %s" , search_def_name ) if search_def_name in SearchPublishManager . SYSTEM_SEARCH_DEF_LIST : raise exceptions . SearchPublishServeException ( "HandleAddSearchDefRequest:" " system default search definition can't be edited." ) query_string = ( "UPDATE search_def_table SET search_def_content = %s" " WHERE search_def_id = %s" ) self . _DbModify ( query_string , ( search_def_content , search_def_id ) ) else : logger . debug ( "Add search definition: %s" , search_def_name ) query_string = ( "INSERT INTO search_def_table (search_def_name, search_def_content)" " VALUES(%s, %s)" ) self . _DbModify ( query_string , ( search_def_name , search_def_content ) ) search_def_obj = self . __BuildSearchDefObj ( search_def_name , search_def_content ) http_io . ResponseWriter . AddJsonBody ( response , constants . STATUS_SUCCESS , search_def_obj )