def setUp(self): """ Prepare before each test. """ self.project_service = ProjectService() self.flow_service = FlowService() self.structure_helper = FilesHelper() self.test_user = TestFactory.create_user() self.test_project = TestFactory.create_project(self.test_user, "ProjectStructure") self.relevant_filter = StaticFiltersFactory.build_datatype_filters(single_filter=StaticFiltersFactory.RELEVANT_VIEW) self.full_filter = StaticFiltersFactory.build_datatype_filters(single_filter=StaticFiltersFactory.FULL_VIEW)
def editstructure(self, project_id=None, last_selected_tab="treeTab", first_level=DataTypeMetaData.KEY_STATE, second_level=DataTypeMetaData.KEY_SUBJECT, filter_input="", visibility_filter=None, **_ignored): """ Return the page skeleton for displaying the project structure. """ if (project_id is None) or (not int(project_id)): raise cherrypy.HTTPRedirect('/project') selected_project = self.project_service.find_project(project_id) self._mark_selected(selected_project) data = self.project_service.get_filterable_meta() filters = StaticFiltersFactory.build_datatype_filters( selected=visibility_filter) template_specification = dict(mainContent="project/structure", baseUrl=cfg.BASE_URL, title=selected_project.name, project=selected_project, data=data, lastSelectedTab=last_selected_tab, firstLevelSelection=first_level, secondLevelSelection=second_level, filterInputValue=filter_input, filters=filters) return self.fill_default_attributes(template_specification, 'data')
def readjsonstructure(self, project_id, visibility_filter=StaticFiltersFactory.FULL_VIEW, first_level=None, second_level=None, filter_value=None): """ AJAX exposed method. Will return the complete JSON for Project's structure, or filtered tree (filter only Relevant entities or Burst only Data). """ if first_level is None or second_level is None: first_level, second_level = self.get_project_structure_grouping() else: self.set_project_structure_grouping(first_level, second_level) selected_filter = StaticFiltersFactory.build_datatype_filters( single_filter=visibility_filter) project = self.project_service.find_project(project_id) json_structure = self.project_service.get_project_structure( project, selected_filter, first_level, second_level, filter_value) # This JSON encoding is necessary, otherwise we will get an error # from JSTree library while trying to load with AJAX # the content of the tree. encoder = JSONEncoder() return encoder.iterencode(json_structure)
def editstructure(self, project_id=None, last_selected_tab="treeTab", first_level=None, second_level=None, filter_input="", visibility_filter=None, **_ignored): """ Return the page skeleton for displaying the project structure. """ try: int(project_id) except (ValueError, TypeError): raise cherrypy.HTTPRedirect('/project') if first_level is None or second_level is None: first_level, second_level = self.get_project_structure_grouping() selected_project = self.project_service.find_project(project_id) self._mark_selected(selected_project) data = self.project_service.get_filterable_meta() filters = StaticFiltersFactory.build_datatype_filters( selected=visibility_filter) template_specification = dict(mainContent="project/structure", baseUrl=TvbProfile.current.web.BASE_URL, title=selected_project.name, project=selected_project, data=data, lastSelectedTab=last_selected_tab, firstLevelSelection=first_level, secondLevelSelection=second_level, filterInputValue=filter_input, filters=filters) return self.fill_default_attributes(template_specification, 'data')
def test_operation_page_filter(self): """ Tests that default filters for operation page are indeed generated """ DUMMY_USER_ID = 1 entity = FilteringTest.DummyFilterClass() entity.id = 1 op_page_filters = StaticFiltersFactory.build_operations_filters(entity, DUMMY_USER_ID) self.assertTrue(isinstance(op_page_filters, list), "We expect a list of filters.") for entry in op_page_filters: self.assertTrue(isinstance(entry, FilterChain), "We expect a list of filters.")
def test_operation_page_filter(self): DUMMY_USER_ID = 1 entity = FilteringTest.DummyFilterClass() entity.id = 1 op_page_filters = StaticFiltersFactory.build_operations_filters( entity, DUMMY_USER_ID) self.assertTrue(isinstance(op_page_filters, list), "We expect a list of filters.") for entry in op_page_filters: self.assertTrue(isinstance(entry, FilterChain), "We expect a list of filters.")
def __get_operations_filters(self): """ Filters for VIEW_ALL_OPERATIONS page. Get from session currently selected filters, or build a new set of filters. """ session_filtes = common.get_from_session(self.KEY_OPERATION_FILTERS) if session_filtes: return session_filtes else: sim_group = self.flow_service.get_algorithm_by_module_and_class(SIMULATOR_MODULE, SIMULATOR_CLASS)[1] new_filters = StaticFiltersFactory.build_operations_filters(sim_group, common.get_logged_user().id) common.add2session(self.KEY_OPERATION_FILTERS, new_filters) return new_filters
def test_operation_page_filter(self): """ Tests that default filters for operation page are indeed generated """ DUMMY_USER_ID = 1 entity = TestFiltering.DummyFilterClass() entity.id = 1 op_page_filters = StaticFiltersFactory.build_operations_filters( entity, DUMMY_USER_ID) assert isinstance(op_page_filters, list), "We expect a list of filters." for entry in op_page_filters: assert isinstance(entry, FilterChain), "We expect a list of filters."
def __get_operations_filters(self): """ Filters for VIEW_ALL_OPERATIONS page. Get from session currently selected filters, or build a new set of filters. """ session_filtes = common.get_from_session(self.KEY_OPERATION_FILTERS) if session_filtes: return session_filtes else: sim_group = self.flow_service.get_algorithm_by_module_and_class(SIMULATOR_MODULE, SIMULATOR_CLASS) new_filters = StaticFiltersFactory.build_operations_filters(sim_group, common.get_logged_user().id) common.add2session(self.KEY_OPERATION_FILTERS, new_filters) return new_filters
def readjsonstructure(self, project_id, visibility_filter=StaticFiltersFactory.FULL_VIEW, first_level=None, second_level=None, filter_value=None): """ AJAX exposed method. Will return the complete JSON for Project's structure, or filtered tree (filter only Relevant entities or Burst only Data). """ if first_level is None or second_level is None: first_level, second_level = self.get_project_structure_grouping() else: self.set_project_structure_grouping(first_level, second_level) selected_filter = StaticFiltersFactory.build_datatype_filters(single_filter=visibility_filter) project = self.project_service.find_project(project_id) json_structure = self.project_service.get_project_structure(project, selected_filter, first_level, second_level, filter_value) # This JSON encoding is necessary, otherwise we will get an error # from JSTree library while trying to load with AJAX # the content of the tree. encoder = JSONEncoder() return encoder.iterencode(json_structure)
def editstructure(self, project_id=None, last_selected_tab="treeTab", first_level=None, second_level=None, filter_input="", visibility_filter=None, **_ignored): """ Return the page skeleton for displaying the project structure. """ try: int(project_id) except (ValueError, TypeError): raise cherrypy.HTTPRedirect('/project') if first_level is None or second_level is None: first_level, second_level = self.get_project_structure_grouping() selected_project = self.project_service.find_project(project_id) self._mark_selected(selected_project) data = self.project_service.get_filterable_meta() filters = StaticFiltersFactory.build_datatype_filters(selected=visibility_filter) template_specification = dict(mainContent="project/structure", baseUrl=TvbProfile.current.web.BASE_URL, title=selected_project.name, project=selected_project, data=data, lastSelectedTab=last_selected_tab, firstLevelSelection=first_level, secondLevelSelection=second_level, filterInputValue=filter_input, filters=filters) return self.fill_default_attributes(template_specification, 'data')
def create_json(self, item_gid, item_type, visibility_filter): """ Method used for creating a JSON representation of a graph. """ selected_filter = StaticFiltersFactory.build_datatype_filters( single_filter=visibility_filter) graph_branches = [] project = bc.get_current_project() is_upload_operation = (item_type == graph_structures.NODE_OPERATION_TYPE) and \ (self.project_service.is_upload_operation(item_gid) or item_gid == "firstOperation") if is_upload_operation: uploader_operations = self.project_service.get_all_operations_for_uploaders( project.id) for operation in uploader_operations: dt_outputs = self.project_service.get_results_for_operation( operation.id, selected_filter) dt_outputs = self._create_datatype_nodes(dt_outputs) parent_op = self._create_operation_nodes([operation], item_gid) branch = graph_structures.GraphBranch([], parent_op, dt_outputs, []) graph_branches.append(branch) graph = graph_structures.GraphStructure(graph_branches) return graph.to_json() dt_inputs, parent_op, dt_outputs, op_inputs = [], [], [], [] if item_type == graph_structures.NODE_OPERATION_TYPE: dt_inputs = ProjectService.get_datatype_and_datatypegroup_inputs_for_operation( item_gid, selected_filter) parent_op = self.project_service.load_operation_by_gid(item_gid) dt_outputs = self.project_service.get_results_for_operation( parent_op.id, selected_filter) #create graph nodes dt_inputs, parent_op, dt_outputs, op_inputs = self._create_nodes( dt_inputs, [parent_op], dt_outputs, [], item_gid) elif item_type == graph_structures.NODE_OPERATION_GROUP_TYPE: parent_op_group = self.project_service.get_operation_group_by_gid( item_gid) dt_inputs = self.project_service.get_datatypes_inputs_for_operation_group( parent_op_group.id, selected_filter) datatype_group = self.project_service.get_datatypegroup_by_op_group_id( parent_op_group.id) datatype = self.project_service.get_datatype_by_id( datatype_group.id) dt_inputs = self._create_datatype_nodes(dt_inputs) parent_op = graph_structures.OperationGroupNodeStructure( parent_op_group.gid) parent_op.selected = True parent_op = [parent_op] if selected_filter.display_name == StaticFiltersFactory.RELEVANT_VIEW and datatype.visible is False: dt_outputs = [] else: dt_outputs = self._create_datatype_nodes([datatype]) elif item_type == graph_structures.NODE_DATATYPE_TYPE: selected_dt = ABCAdapter.load_entity_by_gid(item_gid) if self.project_service.is_datatype_group(item_gid): datatype_group = self.project_service.get_datatypegroup_by_gid( selected_dt.gid) parent_op_group = self.project_service.get_operation_group_by_id( datatype_group.fk_operation_group) dt_inputs = self.project_service.get_datatypes_inputs_for_operation_group( parent_op_group.id, selected_filter) op_inputs = self.project_service.get_operations_for_datatype_group( selected_dt.id, selected_filter) op_inputs_in_groups = self.project_service.get_operations_for_datatype_group( selected_dt.id, selected_filter, only_in_groups=True) #create graph nodes dt_inputs, parent_op, dt_outputs, op_inputs = self._create_nodes( dt_inputs, [], [selected_dt], op_inputs, item_gid) parent_op = [ graph_structures.OperationGroupNodeStructure( parent_op_group.gid) ] op_inputs_in_groups = self._create_operation_group_nodes( op_inputs_in_groups) op_inputs.extend(op_inputs_in_groups) else: parent_op = self.flow_service.load_operation( selected_dt.fk_from_operation) dt_inputs = ProjectService.get_datatype_and_datatypegroup_inputs_for_operation( parent_op.gid, selected_filter) op_inputs = self.project_service.get_operations_for_datatype( selected_dt.gid, selected_filter) op_inputs_in_groups = self.project_service.get_operations_for_datatype( selected_dt.gid, selected_filter, only_in_groups=True) dt_outputs = self.project_service.get_results_for_operation( parent_op.id, selected_filter) #create graph nodes dt_inputs, parent_op, dt_outputs, op_inputs = self._create_nodes( dt_inputs, [parent_op], dt_outputs, op_inputs, item_gid) op_inputs_in_groups = self._create_operation_group_nodes( op_inputs_in_groups) op_inputs.extend(op_inputs_in_groups) else: self.logger.error("Invalid item type: " + str(item_type)) raise Exception("Invalid item type.") branch = graph_structures.GraphBranch(dt_inputs, parent_op, dt_outputs, op_inputs) graph_branches.append(branch) graph = graph_structures.GraphStructure(graph_branches) return graph.to_json()
def create_json(self, item_gid, item_type, visibility_filter): """ Method used for creating a JSON representation of a graph. """ selected_filter = StaticFiltersFactory.build_datatype_filters(single_filter=visibility_filter) project = common.get_current_project() is_upload_operation = (item_type == graph_structures.NODE_OPERATION_TYPE) and \ (self.project_service.is_upload_operation(item_gid) or item_gid == "firstOperation") if is_upload_operation: graph_branches = [] uploader_operations = self.project_service.get_all_operations_for_uploaders(project.id) for operation in uploader_operations: dt_outputs = self.project_service.get_results_for_operation(operation.id, selected_filter) dt_outputs = self._create_datatype_nodes(dt_outputs) parent_op = self._create_operation_nodes([operation], item_gid) branch = graph_structures.GraphComponent([], parent_op, dt_outputs, []) graph_branches.append(branch) graph = graph_structures.FullGraphStructure(graph_branches) return graph.prepare_for_json() dt_inputs, parent_op, dt_outputs, op_inputs = [], [], [], [] if item_type == graph_structures.NODE_OPERATION_TYPE: dt_inputs = ProjectService.get_datatype_and_datatypegroup_inputs_for_operation(item_gid, selected_filter) parent_op = self.project_service.load_operation_by_gid(item_gid) dt_outputs = self.project_service.get_results_for_operation(parent_op.id, selected_filter) #create graph nodes dt_inputs, parent_op, dt_outputs, op_inputs = self._create_nodes(dt_inputs, [parent_op], dt_outputs, [], item_gid) elif item_type == graph_structures.NODE_OPERATION_GROUP_TYPE: parent_op_group = self.project_service.get_operation_group_by_gid(item_gid) dt_inputs = self.project_service.get_datatypes_inputs_for_operation_group(parent_op_group.id, selected_filter) datatype_group = self.project_service.get_datatypegroup_by_op_group_id(parent_op_group.id) datatype = self.project_service.get_datatype_by_id(datatype_group.id) dt_inputs = self._create_datatype_nodes(dt_inputs) parent_op = graph_structures.NodeStructure.build_structure_for_operation_group(parent_op_group.gid) parent_op.selected = True parent_op = [parent_op] if selected_filter.display_name == StaticFiltersFactory.RELEVANT_VIEW and datatype.visible is False: dt_outputs = [] else: dt_outputs = self._create_datatype_nodes([datatype]) elif item_type == graph_structures.NODE_DATATYPE_TYPE: selected_dt = ABCAdapter.load_entity_by_gid(item_gid) if self.project_service.is_datatype_group(item_gid): datatype_group = self.project_service.get_datatypegroup_by_gid(selected_dt.gid) parent_op_group = self.project_service.get_operation_group_by_id(datatype_group.fk_operation_group) dt_inputs = self.project_service.get_datatypes_inputs_for_operation_group(parent_op_group.id, selected_filter) op_inputs = self.project_service.get_operations_for_datatype_group(selected_dt.id, selected_filter) op_inputs_in_groups = self.project_service.get_operations_for_datatype_group(selected_dt.id, selected_filter, only_in_groups=True) #create graph nodes dt_inputs, parent_op, dt_outputs, op_inputs = self._create_nodes(dt_inputs, [], [selected_dt], op_inputs, item_gid) parent_op = [graph_structures.NodeStructure.build_structure_for_operation_group(parent_op_group.gid)] op_inputs_in_groups = self._create_operation_group_nodes(op_inputs_in_groups) op_inputs.extend(op_inputs_in_groups) else: parent_op = self.flow_service.load_operation(selected_dt.fk_from_operation) dt_inputs = ProjectService.get_datatype_and_datatypegroup_inputs_for_operation(parent_op.gid, selected_filter) op_inputs = self.project_service.get_operations_for_datatype(selected_dt.gid, selected_filter) op_inputs_in_groups = self.project_service.get_operations_for_datatype(selected_dt.gid, selected_filter, only_in_groups=True) dt_outputs = self.project_service.get_results_for_operation(parent_op.id, selected_filter) #create graph nodes dt_inputs, parent_op, dt_outputs, op_inputs = self._create_nodes(dt_inputs, [parent_op], dt_outputs, op_inputs, item_gid) op_inputs_in_groups = self._create_operation_group_nodes(op_inputs_in_groups) op_inputs.extend(op_inputs_in_groups) else: self.logger.error("Invalid item type: " + str(item_type)) raise Exception("Invalid item type.") branch = graph_structures.GraphComponent(dt_inputs, parent_op, dt_outputs, op_inputs) graph = graph_structures.FullGraphStructure([branch]) return graph.prepare_for_json()