def invokeadaptermethod(self, adapter_id, method_name, **data): """ Public web method, to be used when invoking specific methods from external Adapters/Algorithms. """ algo_group = self.flow_service.get_algo_group_by_identifier(adapter_id) try: adapter_instance = self.flow_service.build_adapter_instance( algo_group) result = self.flow_service.fire_operation( adapter_instance, base.get_logged_user(), base.get_current_project().id, method_name, **data) base.set_info_message("Submit OK!") if isinstance(adapter_instance, ABCDisplayer) and isinstance( result, dict): base.remove_from_session(base.KEY_MESSAGE) result[ABCDisplayer.KEY_IS_ADAPTER] = True result[base.KEY_DISPLAY_MENU] = True result[base.KEY_OPERATION_ID] = adapter_instance.operation_id result[base.KEY_ADAPTER] = adapter_id if KEY_CONTROLLS not in result: result[KEY_CONTROLLS] = None return self.fill_default_attributes(result, algo_group) except OperationException, excep: base.set_warning_message('Problem when submitting data!') self.logger.error( "Invalid method, or wrong parameters when invoking external method on post!" ) self.logger.exception(excep)
def step(self, step_key=None): """ Choose exact action/adapter for current step. """ category = self.flow_service.get_category_by_id(step_key) if category is None: message = 'Inconsistent Step Name! Please excuse the wrong link!' base.set_warning_message(message) self.logger.warning(message + '- Wrong step:' + str(step_key)) raise cherrypy.HTTPRedirect('/tvb') step_name = category.displayname.lower() template_specification = dict(mainContent="header_menu", section_name=step_name, controlPage=None, title="Select an algorithm", displayControl=False) adapters_list = [] for algo_group in self.flow_service.get_groups_for_categories( [category]): if algo_group.ui_display < 0: continue adapter_link = self.get_url_adapter(step_key, algo_group.id) adapters_list.append({ base.KEY_TITLE: algo_group.displayname, 'link': adapter_link, 'description': algo_group.description, 'subsection': algo_group.subsection_name }) self.analyze_adapters = adapters_list template_specification[base.KEY_SUBMENU_LIST] = adapters_list return self.fill_default_attributes(template_specification)
def get_template_for_adapter(self, project_id, step_key, algo_group, submit_url, session_reset=True): """ Get Input HTML Interface template or a given adapter """ try: if session_reset: self.context.clean_from_session() group = None # Cache some values in session, for performance previous_tree = self.context.get_current_input_tree() previous_sub_step = self.context.get_current_substep() if not session_reset and previous_tree is not None and previous_sub_step == algo_group.id: adapter_interface = previous_tree else: group, adapter_interface = self.flow_service.prepare_adapter( project_id, algo_group) self.context.add_adapter_to_session(algo_group, adapter_interface) category = self.flow_service.get_category_by_id(step_key) title = "Fill parameters for step " + category.displayname.lower() if group: title = title + " - " + group.displayname current_defaults = self.context.get_current_default() if current_defaults is not None: #Change default values in tree, according to selected input adapter_interface = ABCAdapter.fill_defaults( adapter_interface, current_defaults) template_specification = dict(submitLink=submit_url, inputList=adapter_interface, title=title) self._populate_section(algo_group, template_specification) return template_specification except OperationException, oexc: self.logger.error("Inconsistent Adapter") self.logger.exception(oexc) base.set_warning_message( 'Inconsistent Adapter! Please review the link (development problem)!' )