def set_operation_and_group_visibility(self, entity_gid, is_visible, is_operation_group=False): """ Sets the operation visibility. If 'is_operation_group' is True than this method will change the visibility for all the operation from the OperationGroup with the GID field equal to 'entity_gid'. """ def set_visibility(op): # workaround: # 'reload' the operation so that it has the project property set. # get_operations_in_group does not eager load it and now we're out of a sqlalchemy session # write_operation_metadata requires that property op = dao.get_operation_by_id(op.id) # end hack op.visible = is_visible self.structure_helper.write_operation_metadata(op) dao.store_entity(op) def set_group_descendants_visibility(operation_group_id): ops_in_group = dao.get_operations_in_group(operation_group_id) for group_op in ops_in_group: set_visibility(group_op) if is_operation_group: op_group_id = dao.get_operationgroup_by_gid(entity_gid).id set_group_descendants_visibility(op_group_id) else: operation = dao.get_operation_by_gid(entity_gid) #we assure that if the operation belongs to a group than the visibility will be changed for the entire group if operation.fk_operation_group is not None: set_group_descendants_visibility(operation.fk_operation_group) else: set_visibility(operation)
def set_operation_and_group_visibility(self, entity_gid, is_visible, is_operation_group=False): """ Sets the operation visibility. If 'is_operation_group' is True than this method will change the visibility for all the operation from the OperationGroup with the GID field equal to 'entity_gid'. """ def set_visibility(op): # workaround: # 'reload' the operation so that it has the project property set. # get_operations_in_group does not eager load it and now we're out of a sqlalchemy session # write_operation_metadata requires that property op = dao.get_operation_by_id(op.id) # end hack op.visible = is_visible self.structure_helper.write_operation_metadata(op) dao.store_entity(op) def set_group_descendants_visibility(operation_group_id): ops_in_group = dao.get_operations_in_group(operation_group_id) for group_op in ops_in_group: set_visibility(group_op) if is_operation_group: op_group_id = dao.get_operationgroup_by_gid(entity_gid).id set_group_descendants_visibility(op_group_id) else: operation = dao.get_operation_by_gid(entity_gid) # we assure that if the operation belongs to a group than the visibility will be changed for the entire group if operation.fk_operation_group is not None: set_group_descendants_visibility(operation.fk_operation_group) else: set_visibility(operation)
def build_structure_for_operation_group(operation_group_gid): group = dao.get_operationgroup_by_gid(operation_group_gid) operation = dao.get_operations_in_group(group.id, only_first_operation=True) algo = dao.get_algorithm_by_id(operation.fk_from_algo) structure = NodeStructure(operation_group_gid, algo.name) structure.data = NodeData.build_node_for_operation(operation, group.id) return structure
def build_structure_for_operation_group(operation_group_gid): group = dao.get_operationgroup_by_gid(operation_group_gid) operation = dao.get_operations_in_group(group.id, only_first_operation=True) algo = dao.get_algorithm_by_id(operation.fk_from_algo) structure = NodeStructure(operation_group_gid, algo.displayname) structure.data = NodeData.build_node_for_operation(operation, group.id) return structure
def __init__(self, operation_group_gid): NodeStructure.__init__(self, operation_group_gid, "") group = dao.get_operationgroup_by_gid(operation_group_gid) operation = dao.get_operations_in_group(group.id, only_first_operation=True) algo = dao.get_algorithm_by_id(operation.fk_from_algo) node_data = NodeData(MAX_SHAPE_SIZE, OPERATION_GROUP_SHAPE_COLOR, OPERATION_GROUP_SHAPE, NODE_OPERATION_GROUP_TYPE, group.id, str(operation.start_date)) self.name = algo.name self.data = node_data
def get_operation_group_by_gid(operation_group_gid): """ Loads OperationGroup from DB""" return dao.get_operationgroup_by_gid(operation_group_gid)
def _retrieve_operations_in_order(self, project, import_path, importer_operation_id=None): # type: (Project, str, int) -> list[Operation2ImportData] retrieved_operations = [] for root, _, files in os.walk(import_path): if OPERATION_XML in files: # Previous Operation format for uploading previous versions of projects operation_file_path = os.path.join(root, OPERATION_XML) operation, operation_xml_parameters, _ = self.build_operation_from_file( project, operation_file_path) operation.import_file = operation_file_path self.logger.debug("Found operation in old XML format: " + str(operation)) retrieved_operations.append( Operation2ImportData( operation, root, info_from_xml=operation_xml_parameters)) else: # We strive for the new format with ViewModelH5 main_view_model = None dt_paths = [] all_view_model_files = [] for file in files: if file.endswith(FilesHelper.TVB_STORAGE_FILE_EXTENSION): h5_file = os.path.join(root, file) try: h5_class = H5File.h5_class_from_file(h5_file) if h5_class is ViewModelH5: all_view_model_files.append(h5_file) if not main_view_model: view_model = h5.load_view_model_from_file( h5_file) if type( view_model ) in self.view_model2adapter.keys(): main_view_model = view_model else: file_update_manager = FilesUpdateManager() file_update_manager.upgrade_file(h5_file) dt_paths.append(h5_file) except Exception: self.logger.warning( "Unreadable H5 file will be ignored: %s" % h5_file) if main_view_model is not None: alg = self.view_model2adapter[type(main_view_model)] op_group_id = None if main_view_model.operation_group_gid: op_group = dao.get_operationgroup_by_gid( main_view_model.operation_group_gid.hex) if not op_group: op_group = OperationGroup( project.id, ranges=json.loads(main_view_model.ranges), gid=main_view_model.operation_group_gid.hex) op_group = dao.store_entity(op_group) op_group_id = op_group.id operation = Operation( main_view_model.gid.hex, project.fk_admin, project.id, alg.id, status=STATUS_FINISHED, user_group=main_view_model.generic_attributes. operation_tag, start_date=datetime.now(), completion_date=datetime.now(), op_group_id=op_group_id, range_values=main_view_model.range_values) operation.create_date = main_view_model.create_date operation.visible = main_view_model.generic_attributes.visible self.logger.debug( "Found main ViewModel to create operation for it: " + str(operation)) retrieved_operations.append( Operation2ImportData(operation, root, main_view_model, dt_paths, all_view_model_files)) elif len(dt_paths) > 0: alg = dao.get_algorithm_by_module(TVB_IMPORTER_MODULE, TVB_IMPORTER_CLASS) default_adapter = ABCAdapter.build_adapter(alg) view_model = default_adapter.get_view_model_class()() view_model.data_file = dt_paths[0] vm_path = h5.store_view_model(view_model, root) all_view_model_files.append(vm_path) operation = Operation(view_model.gid.hex, project.fk_admin, project.id, alg.id, status=STATUS_FINISHED, start_date=datetime.now(), completion_date=datetime.now()) self.logger.debug( "Found no ViewModel in folder, so we default to " + str(operation)) if importer_operation_id: operation.id = importer_operation_id retrieved_operations.append( Operation2ImportData(operation, root, view_model, dt_paths, all_view_model_files, True)) return sorted(retrieved_operations, key=lambda op_data: op_data.order_field)