<commit_before>require 'spqr/spqr'

require 'mrg/grid/config-proxies'

module Mrg
  module Grid
    module Config
      class Store
        include ::SPQR::Manageable

        qmf_package_name 'mrg.grid.config'
        qmf_class_name 'Store'

        def Store.find_by_id(u)
          @singleton ||= Store.new
        end

        def Store.find_all
          @singleton ||= Store.new
          [@singleton]
        end

        ### Property method declarations
        # property APIVersionNumber uint32 The version of the API the store supports
        attr_accessor :apiVersionNumber
        qmf_property :apiVersionNumber, :uint32, :desc=>"The version of the API the store supports", :index=>false
        ### Schema method declarations
        
        def GetDefaultGroup
          return Group.DEFAULT_GROUP
        end
        
        expose :GetDefaultGroup do |args|
          args.declare :obj, :objId, :out, {}
        end
        
        # GetGroup 
        # * query (map/I)
        #   A map(queryType, value) that defines the group desired. The queryType can be either 'ID' or 'Name'. 'ID' queryTypes will search for a group with the ID defined in value. 'Name' queryTypes will search for a group with the name defined in value.
        # * obj (objId/O)
        def GetGroup(query)
          qentries = query.entries
          raise ArgumentError.new("Invalid group query #{query.inspect}") if qentries.size != 1
          qkind, qkey = query.entries.pop
          qkind = qkind.upcase
          
          case qkind
          when "ID"
            return Group.find(qkey)
          when "NAME"
            return Group.find_first_by_name(qkey)
          else raise ArgumentError.new("Invalid group query kind #{qkind}")
          end
        end
        
        expose :GetGroup do |args|
          args.declare :obj, :objId, :out, {}
          args.declare :query, :map, :in, {}
        end

        def GetGroupByName(name)
          GetGroup({"NAME"=>name})
        end
        
        expose :GetGroupByName do |args|
          args.declare :name, :sstr, :in, {}
          args.declare :obj, :objId, :out, {}
        end
        
        # AddExplicitGroup 
        # * name (sstr/I)
        # * obj (objId/O)
        def AddExplicitGroup(name)
          # Print values of input parameters
          log.debug "AddExplicitGroup: name => #{name.inspect}"
          raise "Group name #{name} is already taken" if Group.find_first_by_name(name)
          raise "Group name #{name} is invalid; group names may not start with '+++'" if name.slice(0,3) == "+++"
          Group.create(:name=>name)
        end
        
        expose :AddExplicitGroup do |args|
          args.declare :obj, :objId, :out, {}
          args.declare :name, :sstr, :in, {}
        end
        
        # RemoveGroup 
        # * uid (uint32/I)
        def RemoveGroup(uid)
          # Print values of input parameters
          log.debug "RemoveGroup: uid => #{uid.inspect}"
          Group.find(uid).delete
        end
        
        expose :RemoveGroup do |args|
          args.declare :uid, :uint32, :in, {}
        end
        
        # GetFeature 
        # * name (sstr/I)
        # * obj (objId/O)
        def GetFeature(name)
          # Print values of input parameters
          log.debug "GetFeature: name => #{name.inspect}"
          Feature.find_first_by_name(name)
        end
        
        expose :GetFeature do |args|
          args.declare :obj, :objId, :out, {}
          args.declare :name, :sstr, :in, {}
        end
        
        # AddFeature 
        # * name (sstr/I)
        # * obj (objId/O)
        def AddFeature(name)
          # Print values of input parameters
          log.debug "AddFeature: name => #{name.inspect}"
          raise "Feature name #{name} is already taken" if Feature.find_first_by_name(name)
          return Feature.create(:name=>name)
        end
        
        expose :AddFeature do |args|
          args.declare :obj, :objId, :out, {}
          args.declare :name, :sstr, :in, {}
        end
        
        # RemoveFeature 
        # * uid (uint32/I)
        def RemoveFeature(uid)
          # Print values of input parameters
          log.debug "RemoveFeature: uid => #{uid.inspect}"
          Feature.find(uid).delete
        end
        
        expose :RemoveFeature do |args|
          args.declare :uid, :uint32, :in, {}
        end
        
        # GetConfiguration 
        # * query (map/I)
        #   A query that defines the configuration desired. Valid values for the key are 'ID' or 'Name'. 'ID' keys should contain a specific ConfigurationId as its value, whereas 'Name' keys should contain a Configuration Name as its value
        # * obj (objId/O)
        def GetConfiguration(query)
          # Print values of input parameters
          log.debug "GetConfiguration: query => #{query.inspect}"
          # Assign values to output parameters
          obj ||= nil
          # Return value
          return obj
        end
        
        expose :GetConfiguration do |args|
          args.declare :obj, :objId, :out, {}
          args.declare :query, :map, :in, {}
        end
        
        # ChangeConfiguration 
        # * uid (uint32/I)
        def ChangeConfiguration(uid)
          # Print values of input parameters
          log.debug "ChangeConfiguration: uid => #{uid.inspect}"
        end
        
        expose :ChangeConfiguration do |args|
          args.declare :uid, :uint32, :in, {}
        end
        
        # ActivateConfiguration 
        # * explain (map/O)
        #   A map containing an explanation of why the configuration isn't valid, or
        #   an empty map if the configuration was successfully pushed out
        
        def ActivateConfiguration()
          dirty_nodes = Node.get_dirty_nodes
          this_version = ::Rhubarb::Util::timestamp
          
          results = Hash[*dirty_nodes.map {|node| node.validate}.reject {|result| result == true}.flatten]
          
          if results.keys.size > 0
            return results
          end
                    
          dirty_nodes.each {|dn| dn.last_updated_version = this_version }
          
          DirtyElement.delete_all
          
          new_config_event(dirty_nodes, this_version)
          
          results
        end
        
        expose :ActivateConfiguration do |args|
          args.declare :explain, :map, :out, {}
        end
        
        # AddNode 
        # * name (sstr/I)
        # * obj (objId/O)
        def AddNode(name)
          # Print values of input parameters
          log.debug "AddNode: name => #{name.inspect}"

          n = Node.find_first_by_name(name)
          <commit_msg>Call new_config_event with a list of node names, not a list of node objects.<commit_after>require 'spqr/spqr'

require 'mrg/grid/config-proxies'

module Mrg
  module Grid
    module Config
      class Store
        include ::SPQR::Manageable

        qmf_package_name 'mrg.grid.config'
        qmf_class_name 'Store'

        def Store.find_by_id(u)
          @singleton ||= Store.new
        end

        def Store.find_all
          @singleton ||= Store.new
          [@singleton]
        end

        ### Property method declarations
        # property APIVersionNumber uint32 The version of the API the store supports
        attr_accessor :apiVersionNumber
        qmf_property :apiVersionNumber, :uint32, :desc=>"The version of the API the store supports", :index=>false
        ### Schema method declarations
        
        def GetDefaultGroup
          return Group.DEFAULT_GROUP
        end
        
        expose :GetDefaultGroup do |args|
          args.declare :obj, :objId, :out, {}
        end
        
        # GetGroup 
        # * query (map/I)
        #   A map(queryType, value) that defines the group desired. The queryType can be either 'ID' or 'Name'. 'ID' queryTypes will search for a group with the ID defined in value. 'Name' queryTypes will search for a group with the name defined in value.
        # * obj (objId/O)
        def GetGroup(query)
          qentries = query.entries
          raise ArgumentError.new("Invalid group query #{query.inspect}") if qentries.size != 1
          qkind, qkey = query.entries.pop
          qkind = qkind.upcase
          
          case qkind
          when "ID"
            return Group.find(qkey)
          when "NAME"
            return Group.find_first_by_name(qkey)
          else raise ArgumentError.new("Invalid group query kind #{qkind}")
          end
        end
        
        expose :GetGroup do |args|
          args.declare :obj, :objId, :out, {}
          args.declare :query, :map, :in, {}
        end

        def GetGroupByName(name)
          GetGroup({"NAME"=>name})
        end
        
        expose :GetGroupByName do |args|
          args.declare :name, :sstr, :in, {}
          args.declare :obj, :objId, :out, {}
        end
        
        # AddExplicitGroup 
        # * name (sstr/I)
        # * obj (objId/O)
        def AddExplicitGroup(name)
          # Print values of input parameters
          log.debug "AddExplicitGroup: name => #{name.inspect}"
          raise "Group name #{name} is already taken" if Group.find_first_by_name(name)
          raise "Group name #{name} is invalid; group names may not start with '+++'" if name.slice(0,3) == "+++"
          Group.create(:name=>name)
        end
        
        expose :AddExplicitGroup do |args|
          args.declare :obj, :objId, :out, {}
          args.declare :name, :sstr, :in, {}
        end
        
        # RemoveGroup 
        # * uid (uint32/I)
        def RemoveGroup(uid)
          # Print values of input parameters
          log.debug "RemoveGroup: uid => #{uid.inspect}"
          Group.find(uid).delete
        end
        
        expose :RemoveGroup do |args|
          args.declare :uid, :uint32, :in, {}
        end
        
        # GetFeature 
        # * name (sstr/I)
        # * obj (objId/O)
        def GetFeature(name)
          # Print values of input parameters
          log.debug "GetFeature: name => #{name.inspect}"
          Feature.find_first_by_name(name)
        end
        
        expose :GetFeature do |args|
          args.declare :obj, :objId, :out, {}
          args.declare :name, :sstr, :in, {}
        end
        
        # AddFeature 
        # * name (sstr/I)
        # * obj (objId/O)
        def AddFeature(name)
          # Print values of input parameters
          log.debug "AddFeature: name => #{name.inspect}"
          raise "Feature name #{name} is already taken" if Feature.find_first_by_name(name)
          return Feature.create(:name=>name)
        end
        
        expose :AddFeature do |args|
          args.declare :obj, :objId, :out, {}
          args.declare :name, :sstr, :in, {}
        end
        
        # RemoveFeature 
        # * uid (uint32/I)
        def RemoveFeature(uid)
          # Print values of input parameters
          log.debug "RemoveFeature: uid => #{uid.inspect}"
          Feature.find(uid).delete
        end
        
        expose :RemoveFeature do |args|
          args.declare :uid, :uint32, :in, {}
        end
        
        # GetConfiguration 
        # * query (map/I)
        #   A query that defines the configuration desired. Valid values for the key are 'ID' or 'Name'. 'ID' keys should contain a specific ConfigurationId as its value, whereas 'Name' keys should contain a Configuration Name as its value
        # * obj (objId/O)
        def GetConfiguration(query)
          # Print values of input parameters
          log.debug "GetConfiguration: query => #{query.inspect}"
          # Assign values to output parameters
          obj ||= nil
          # Return value
          return obj
        end
        
        expose :GetConfiguration do |args|
          args.declare :obj, :objId, :out, {}
          args.declare :query, :map, :in, {}
        end
        
        # ChangeConfiguration 
        # * uid (uint32/I)
        def ChangeConfiguration(uid)
          # Print values of input parameters
          log.debug "ChangeConfiguration: uid => #{uid.inspect}"
        end
        
        expose :ChangeConfiguration do |args|
          args.declare :uid, :uint32, :in, {}
        end
        
        # ActivateConfiguration 
        # * explain (map/O)
        #   A map containing an explanation of why the configuration isn't valid, or
        #   an empty map if the configuration was successfully pushed out
        
        def ActivateConfiguration()
          dirty_nodes = Node.get_dirty_nodes
          this_version = ::Rhubarb::Util::timestamp
          
          results = Hash[*dirty_nodes.map {|node| node.validate}.reject {|result| result == true}.flatten]
          
          if results.keys.size > 0
            return results
          end
                    
          dirty_nodes.each {|dn| dn.last_updated_version = this_version }
          
          DirtyElement.delete_all
          
          new_config_event(dirty_nodes.map {|dn| dn.name}, this_version)
          
          results
        end
        
        expose :ActivateConfiguration do |args|
          args.declare :explain, :map, :out, {}
        end
        
        # AddNode 
        # * name (sstr/I)
        # * obj (objId/O)
        def AddNode(name)
          # Print values of input parameters
          log.debug "AddNode: name => #{name.inspect}"

          n = Node.find_first_by_name(name)
          
{'fraction_non_alphanumeric': 0.0945546019532406, 'fraction_numerical': 0.002959455460195324, 'mean_word_length': 1.6846077457795432, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7530066', 'n_tokens_mistral': 3811, 'n_tokens_neox': 3738, 'n_words': 1105}