Class Core::Providers::Multiverse::Provider
In: core/serviceproviders/multiverse/provider.rb
Parent: Object

This provider interfaces with the Multiverse, the different universes and the knowledge stored in them.

Methods

Included Modules

Core::Interfaces::ServiceProvider

Public Class methods

=============================================== public methods

[Source]

# File core/serviceproviders/multiverse/provider.rb, line 31
        def initialize(params={})
          @builder = Multiverse::Builder.new(params)
          @controller = params[:controller]
          @properties_category_id = $config.get_option(:multiverse_category_id).to_i
          @sorted_multiverse = {}
        end

Public Instance methods

Create and save a new extended Node. The expected parameters are:

  • parent_id: The id of the parent of this node (can be nil)
  • uui: The unique id of the universe
  • type: The type of node inside the Universe

All parameters are required.

[Source]

# File core/serviceproviders/multiverse/provider.rb, line 145
        def service_multiverse_create_node(*args)
          if (args.size != 3)
            raise ServiceRequestInvalidArgumentError.new('Invalid parameters. Required parameters: parent_id, uuid, type')
          end
          
          parent_id = args[0]
          uuid = args[1]
          type = args[2]
          
          node_desc = service_multiverse_find_node(uuid, type)
          node = @controller.request_service( :model_add_node, parent_id, 0, node_desc[:name])
          
          node_info = { :uid => uuid, :type => type, :properties => node_desc[:properties].values }
          info_xml = @controller.request_service(:interfaceerator_to_xml, node_info )
          
          @controller.request_service( :model_add_note, 
                                        node.id, 
                                        Core::VERSION.string,
                                        @properties_category_id,
                                        info_xml )
        end

Given a universe uid, and a node type, this service returns the hash containing the node information. The expected parameters are:

  • universe_uid: The unique id of the universe
  • node_type: The type of node inside the universe

All parameters are required.

[Source]

# File core/serviceproviders/multiverse/provider.rb, line 68
        def service_multiverse_find_node(*args)
          if (args.size != 2)
            raise ServiceRequestInvalidArgumentError.new('Invalid parameters. Required parameters: universe_uid, node_type')
          end
          
          universe_uid = args[0]
          node_type = args[1]
          
          universe = service_multiverse_find_universe(universe_uid)
          universe.nodes.each do |node|
            return node if node[:type] == node_type
          end
        end

Given a universe uid, this service returns the Universe object associated with it. The expected parameters are:

  • uid: The unique id of the universe

All parameters are required.

[Source]

# File core/serviceproviders/multiverse/provider.rb, line 48
        def service_multiverse_find_universe(*args)
          if (args.size != 1)
            raise ServiceRequestInvalidArgumentError.new('Invalid parameters. Required parameters: uid')
          end
          uid = args[0]
          
          if @sorted_multiverse.size.zero?
            @builder.multiverse.each do |universe|
              @sorted_multiverse[universe.meta[:uid]] = universe
            end
          end
          @sorted_multiverse.fetch(uid, nil)
        end

This method is used to check that all the required supporting elements exist in the server side. For instance it checks that the special Note Categories exist and so forth.

[Source]

# File core/serviceproviders/multiverse/provider.rb, line 86
        def service_multiverse_init
          # FIXME: Is this code used?
          category_name = nil
          begin
            category_name = $config.get_option(:multiverse_category_name)
          rescue
            $config.put_option(:multiverse_category_name, "multiverse_category_#{VERSION::STRING}")
            retry
          end

          category_id = nil
          begin
            category_id = $config.get_option(:multiverse_category_id)
          rescue
            cat = @controller.request_service(:model_find_category_by_name, category_name)
            if cat.nil?
              cat = @controller.request_service(:model_add_category, category_name)
            end
            $config.put_option(:multiverse_category_id, cat.id)
            retry
          end
          
          $logger.debug{ "Multiverse category is: #{category_name}, #{category_id}" }
        end

Create and save a new extended Node. The expected parameters are:

  • universe_uid: The unique id of the universe
  • node_type: The type of node inside the Universe
  • property_key: The property key

All parameters are required.

[Source]

# File core/serviceproviders/multiverse/provider.rb, line 173
        def service_multiverse_populator_for(*args)
          if (args.size != 3)
            raise ServiceRequestInvalidArgumentError.new('Invalid parameters. Required parameters: universe_uid, node_type, property_key')
          end
          
          universe_uid = args[0]
          node_type = args[1] 
          property_key = args[2]
          
          node_info = service_multiverse_find_node(universe_uid, node_type)
          property = node_info[:properties].fetch(property_key, nil)
          return nil if property.nil?
          if property.populator
            instance = property.populator
            if !instance.class.included_modules.include?(Interfaces::PropertyPopulator)
              raise "Please ensure that your populator #{instance.class.to_s} includes the Core::Providers::Multiverse::Interfaces::PropertyPopulator module."
            end
            
          end
          return property.populator
        end

Update the attributes of a Note in the server. The expected parameters are:

  • node_id: The id of the node to update
  • properties: The array of properties to store for this node

All parameters are required.

[Source]

# File core/serviceproviders/multiverse/provider.rb, line 117
        def service_multiverse_save_node_properties(*args)
          if (args.size != 2)
            raise ServiceRequestInvalidArgumentError.new('Invalid parameters. Required parameters: node_id, properties')
          end
          node_id = args[0]
          properties = args[1]
        
          node = @controller.request_service(:model_find_node, node_id)
          node_info = { 
            :uid => node.universe_uid, 
            :type => node.node_type, 
            :properties => properties }
          info_xml = @controller.request_service(:interfaceerator_to_xml, node_info )
                    
          @controller.request_service(:model_update_note, 
                                        node_id,
                                        node.properties_id,
                                        Core::VERSION.string, 
                                        @properties_category_id, 
                                        info_xml)                                        
        end

Return the list of universes of this Multiverse

[Source]

# File core/serviceproviders/multiverse/provider.rb, line 39
        def service_multiverse_universe_list
          return @builder.multiverse
        end

[Validate]