Ejemplo n.º 1
0
 def new_portlet_configuration(portlet_id,
                               tab_nr=-1,
                               index_in_tab=-1,
                               portlet_name='Default'):
     """
     Return a new portlet configuration entitiy with default parameters.
     
     :param portlet_id: the id of the portlet for which a configuration will
         be stored
     :param tab_nr: the index of the currently selected tab
     :param index_in_tab: the index from the currently selected tab
     
     """
     portlet_entity = dao.get_portlet_by_id(portlet_id)
     if portlet_entity is None:
         raise InvalidPortletConfiguration(
             "No portlet entity located in database with id=%s." %
             portlet_id)
     portlet_configurer = PortletConfigurer(portlet_entity)
     configuration = portlet_configurer.create_new_portlet_configuration(
         portlet_name)
     for wf_step in configuration.analyzers:
         wf_step.tab_index = tab_nr
         wf_step.index_in_tab = index_in_tab
     configuration.visualizer.tab_index = tab_nr
     configuration.visualizer.index_in_tab = index_in_tab
     return configuration
Ejemplo n.º 2
0
    def _get_portlet_configurer(self, portlet_id):

        if portlet_id not in self.cache_portlet_configurators:

            portlet_entity = dao.get_portlet_by_id(portlet_id)
            if portlet_entity is None:
                raise InvalidPortletConfiguration("No portlet entity located in database with id=%s. " % portlet_id)

            self.cache_portlet_configurators[portlet_id] = PortletConfigurer(portlet_entity)
            self.logger.debug("Recently parsed portlet XML:" + str([portlet_entity]))

        return self.cache_portlet_configurators[portlet_id]
Ejemplo n.º 3
0
 def test_portlet_configurable_interface(self):
     """
     A simple test for the get configurable interface method.
     """        
     test_portlet = dao.get_portlet_by_identifier("TA1TA2")
     
     result = PortletConfigurer(test_portlet).get_configurable_interface()
     self.assertEqual(len(result), 2, "Length of the resulting interface not as expected")
     for one_entry in result:
         for entry in one_entry.interface:
             if entry['name'] == 'test1':
                 self.assertTrue(entry['default'] == 'step_0[0]', "Overwritten default not in effect.")
             if entry['name'] == 'test2':
                 self.assertTrue(entry['default'] == '0', "Value that was not overwritten changed.")
Ejemplo n.º 4
0
 def update_portlet_configuration(portlet_configuration,
                                  submited_parameters):
     """
     :param portlet_configuration: the portlet configuration that needs to be updated
     :param submited_parameters: a list of parameters as submitted from the UI. This 
         is a dictionary in the form : 
         {'dynamic' : {name:value pairs}, 'static' : {name:value pairs}}
         
     All names are prefixed with adapter specific generated prefix.
     """
     portlet_entity = dao.get_portlet_by_id(
         portlet_configuration.portlet_id)
     portlet_configurer = PortletConfigurer(portlet_entity)
     return portlet_configurer.update_portlet_configuration(
         portlet_configuration, submited_parameters)
Ejemplo n.º 5
0
    def build_portlet_interface(self, portlet_configuration, project_id):
        """
        From a portlet_id and a project_id, first build the portlet
        entity then get it's configurable interface. 
        
        :param portlet_configuration: a portlet configuration entity. It holds at the
            least the portlet_id, and in case any default parameters were saved
            they can be rebuilt from the analyzers // visualizer parameters
        :param project_id: the id of the current project   
            
        :returns: the portlet interface will be of the following form::
            [{'interface': adapter_interface, 
            'prefix': prefix_for_parameter_names, 
            'subalg': {algorithm_field_name: default_algorithm_value},
            'algo_group': algorithm_group,
            'alg_ui_name': displayname},
            ......]
            A list of dictionaries for each adapter that makes up the portlet.
            
        """
        portlet_entity = dao.get_portlet_by_id(
            portlet_configuration.portlet_id)
        if portlet_entity is None:
            raise InvalidPortletConfiguration(
                "No portlet entity located in database with id=%s. "
                "Portlet configuration %s is not valid." %
                (portlet_configuration.portlet_id, portlet_configuration))
        portlet_configurer = PortletConfigurer(portlet_entity)
        portlet_interface = portlet_configurer.get_configurable_interface()
        self.logger.debug("Created interface for portlet " +
                          str([portlet_entity]))

        for adapter_conf in portlet_interface:
            interface = adapter_conf.interface
            interface = FlowService().prepare_parameters(
                interface, project_id, adapter_conf.group.fk_category)
            interface = ABCAdapter.prepare_param_names(interface,
                                                       adapter_conf.prefix)
            adapter_conf.interface = interface

        portlet_configurer.update_default_values(portlet_interface,
                                                 portlet_configuration)
        portlet_configurer.prefix_adapters_parameters(portlet_interface)

        return portlet_interface