def get_operation_details(self, operation_gid, is_group): """ :returns: an entity OperationOverlayDetails filled with all information for current operation details. """ if is_group: operation_group = self.get_operation_group_by_gid(operation_gid) operation = dao.get_operations_in_group(operation_group.id, False, True) ## Reload, to make sure all attributes lazy are populated as well. operation = dao.get_operation_by_gid(operation.gid) no_of_op_in_group = dao.get_operations_in_group(operation_group.id, is_count=True) datatype_group = self.get_datatypegroup_by_op_group_id(operation_group.id) count_result = dao.count_datatypes_in_group(datatype_group.id) else: operation = dao.get_operation_by_gid(operation_gid) if operation is None: return None no_of_op_in_group = 1 count_result = dao.count_resulted_datatypes(operation.id) username = dao.get_user_by_id(operation.fk_launched_by).username burst = dao.get_burst_for_operation_id(operation.id) datatypes_param, all_special_params = ProjectService._review_operation_inputs(operation.gid) op_pid = dao.get_operation_process_for_operation(operation.id) op_details = OperationOverlayDetails(operation, username, len(datatypes_param), count_result, burst, no_of_op_in_group, op_pid) ## Add all parameter which are set differently by the user on this Operation. if all_special_params is not None: op_details.add_scientific_fields(all_special_params) return op_details
def get_operation_details(self, operation_gid, is_group): """ :returns: an entity OperationOverlayDetails filled with all information for current operation details. """ if is_group: operation_group = self.get_operation_group_by_gid(operation_gid) operation = dao.get_operations_in_group(operation_group.id, False, True) # Reload, to make sure all attributes lazy are populated as well. operation = dao.get_operation_by_gid(operation.gid) no_of_op_in_group = dao.get_operations_in_group(operation_group.id, is_count=True) datatype_group = self.get_datatypegroup_by_op_group_id(operation_group.id) count_result = dao.count_datatypes_in_group(datatype_group.id) else: operation = dao.get_operation_by_gid(operation_gid) if operation is None: return None no_of_op_in_group = 1 count_result = dao.count_resulted_datatypes(operation.id) user_display_name = dao.get_user_by_id(operation.fk_launched_by).display_name burst = dao.get_burst_for_operation_id(operation.id) datatypes_param, all_special_params = self._review_operation_inputs(operation.gid) op_pid = dao.get_operation_process_for_operation(operation.id) op_details = OperationOverlayDetails(operation, user_display_name, len(datatypes_param), count_result, burst, no_of_op_in_group, op_pid) # Add all parameter which are set differently by the user on this Operation. if all_special_params is not None: op_details.add_scientific_fields(all_special_params) return op_details
def test_set_visibility_operation(self, operation_factory): """ Same flow of operations as per test_set_visibilty_datatype just for operation entity. """ operation = operation_factory() assert operation.visible self.project_c.set_visibility('operation', operation.gid, 'False') operation = dao.get_operation_by_gid(operation.gid) assert not operation.visible self.project_c.set_visibility('operation', operation.gid, 'True') operation = dao.get_operation_by_gid(operation.gid) assert operation.visible
def test_set_visibility_operation(self): """ Same flow of operations as per test_set_visibilty_datatype just for operation entity. """ dt_factory = DatatypesFactory() operation = dt_factory.operation self.assertTrue(operation.visible) self.project_c.set_visibility('operation', operation.gid, 'False') operation = dao.get_operation_by_gid(operation.gid) self.assertFalse(operation.visible) self.project_c.set_visibility('operation', operation.gid, 'True') operation = dao.get_operation_by_gid(operation.gid) self.assertTrue(operation.visible)
def test_set_visibility_operation(self): """ Same flow of operations as per test_set_visibilty_datatype just for operation entity. """ dt_factory = DatatypesFactory() operation = dt_factory.operation self.assertTrue(operation.visible) self.project_c.set_visibility('operation', operation.gid, 'False') operation = dao.get_operation_by_gid(operation.gid) self.assertFalse(operation.visible) self.project_c.set_visibility('operation', operation.gid, 'True') operation = dao.get_operation_by_gid(operation.gid) self.assertTrue(operation.visible)
def _review_operation_inputs(self, operation_gid): """ :returns: A list of DataTypes that are used as input parameters for the specified operation. And a dictionary will all operation parameters different then the default ones. """ operation = dao.get_operation_by_gid(operation_gid) try: adapter = ABCAdapter.build_adapter(operation.algorithm) return review_operation_inputs_from_adapter(adapter, operation) except Exception: self.logger.exception("Could not load details for operation %s" % operation_gid) parameters = json.loads(operation.parameters) if 'gid' in parameters.keys(): changed_parameters = dict( Warning= "Algorithm changed dramatically. We can not offer more details" ) else: changed_parameters = dict( Warning= "GID parameter is missing. Old implementation of the operation." ) return [], changed_parameters
def _review_operation_inputs(self, operation_gid): """ :returns: A list of DataTypes that are used as input parameters for the specified operation. And a dictionary will all operation parameters different then the default ones. """ # todo rewrite after neotraits TVB-2687 operation = dao.get_operation_by_gid(operation_gid) parameters = json.loads(operation.parameters) try: adapter = ABCAdapter.build_adapter(operation.algorithm) return adapter.review_operation_inputs(parameters) except Exception: self.logger.exception("Could not load details for operation %s" % operation_gid) inputs_datatypes = [] changed_parameters = dict( Warning= "Algorithm changed dramatically. We can not offer more details" ) for submit_param in parameters.values(): self.logger.debug("Searching DT by GID %s" % submit_param) datatype = ABCAdapter.load_entity_by_gid(str(submit_param)) if datatype is not None: inputs_datatypes.append(datatype) return inputs_datatypes, changed_parameters
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 _import_image(self, src_folder, metadata_file, project_id, target_images_path): """ Create and store a image entity. """ figure_dict = XMLReader(os.path.join(src_folder, metadata_file)).read_metadata() actual_figure = os.path.join( src_folder, os.path.split(figure_dict['file_path'])[1]) if not os.path.exists(actual_figure): self.logger.warning("Expected to find image path %s .Skipping" % actual_figure) return # TODO: this will never match in the current form. What to do ? op = dao.get_operation_by_gid(figure_dict['fk_from_operation']) figure_dict['fk_op_id'] = op.id if op is not None else None figure_dict['fk_user_id'] = self.user_id figure_dict['fk_project_id'] = project_id figure_entity = manager_of_class(ResultFigure).new_instance() figure_entity = figure_entity.from_dict(figure_dict) stored_entity = dao.store_entity(figure_entity) # Update image meta-data with the new details after import figure = dao.load_figure(stored_entity.id) shutil.move(actual_figure, target_images_path) self.logger.debug("Store imported figure") self.files_helper.write_image_metadata(figure)
def get_operagion(self): """ Return the operation that was saved on this entity. Should only be called if beforehand 'set_operation' was called on this entity. """ if self.OP_GID not in self._data_dict: return None return dao.get_operation_by_gid(self._data_dict.get(self.OP_GID, None))
def get_operagion(self): """ Return the operation that was saved on this entity. Should only be called if beforehand 'set_operation' was called on this entity. """ if self.OP_GID not in self._data_dict: return None return dao.get_operation_by_gid(self._data_dict.get(self.OP_GID, None))
def _review_operation_inputs(operation_gid): """ :returns: A list of DataTypes that are used as input parameters for the specified operation. And a dictionary will all operation parameters different then the default ones. """ operation = dao.get_operation_by_gid(operation_gid) parameters = json.loads(operation.parameters) adapter = ABCAdapter.build_adapter(operation.algorithm.algo_group) return adapter.review_operation_inputs(parameters)
def _review_operation_inputs(operation_gid): """ :returns: A list of DataTypes that are used as input parameters for the specified operation. And a dictionary will all operation parameters different then the default ones. """ operation = dao.get_operation_by_gid(operation_gid) parameters = json.loads(operation.parameters) adapter = ABCAdapter.build_adapter(operation.algorithm.algo_group) return adapter.review_operation_inputs(parameters)
def __init__(self, operation_gid): NodeStructure.__init__(self, operation_gid, "") operation = dao.get_operation_by_gid(operation_gid) algo = dao.get_algorithm_by_id(operation.fk_from_algo) node_data = NodeData(MAX_SHAPE_SIZE, OPERATION_SHAPE_COLOR, OPERATION_SHAPE, NODE_OPERATION_TYPE, operation.id, str(operation.start_date)) self.name = algo.name self.data = node_data
def __init__(self, operation_gid): NodeStructure.__init__(self, operation_gid, "") operation = dao.get_operation_by_gid(operation_gid) algo = dao.get_algorithm_by_id(operation.fk_from_algo) node_data = NodeData(MAX_SHAPE_SIZE, OPERATION_SHAPE_COLOR, OPERATION_SHAPE, NODE_OPERATION_TYPE, operation.id, str(operation.start_date)) self.name = algo.name self.data = node_data
def set_operation_and_group_visibility(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'. """ if not is_operation_group: #we assure that if the operation belongs to a group than the visibility will be changed for the entire group operation = dao.get_operation_by_gid(entity_gid) if operation.fk_operation_group is not None: op_group = dao.get_operationgroup_by_id(operation.fk_operation_group) entity_gid = op_group.gid is_operation_group = True dao.set_operation_and_group_visibility(entity_gid, is_visible, is_operation_group)
def get_operation_id(self): """ Return the operation that was saved on this entity. Should only be called if beforehand 'set_operation' was called on this entity. """ if self.OP_GID not in self._data_dict: return None operation_gid = self._data_dict.get(self.OP_GID, None) operation = dao.get_operation_by_gid(operation_gid) if operation: return operation.id LOGGER.warning("When restoring Workflow Step %s, we could not find operation " "for GID %s" % (self.get_algorithm().name, operation_gid)) return None
def get_operation_id(self): """ Return the operation that was saved on this entity. Should only be called if beforehand 'set_operation' was called on this entity. """ if self.OP_GID not in self._data_dict: return None operation_gid = self._data_dict.get(self.OP_GID, None) operation = dao.get_operation_by_gid(operation_gid) if operation: return operation.id LOGGER.warning("When restoring Workflow Step %s, we could not find operation " "for GID %s" % (self.get_algorithm().name, operation_gid)) return None
def _populate_image(self, file_name, project_id): """ Create and store a image entity. """ figure_dict = XMLReader(file_name).read_metadata() new_path = os.path.join(os.path.split(file_name)[0], os.path.split(figure_dict['file_path'])[1]) if not os.path.exists(new_path): self.logger.warn("Expected to find image path %s .Skipping" % new_path) op = dao.get_operation_by_gid(figure_dict['fk_from_operation']) figure_dict['fk_op_id'] = op.id if op is not None else None figure_dict['fk_user_id'] = self.user_id figure_dict['fk_project_id'] = project_id figure_entity = manager_of_class(model.ResultFigure).new_instance() figure_entity = figure_entity.from_dict(figure_dict) stored_entity = dao.store_entity(figure_entity) # Update image meta-data with the new details after import figure = dao.load_figure(stored_entity.id) self.logger.debug("Store imported figure") self.files_helper.write_image_metadata(figure)
def _populate_image(self, file_name, project_id): """ Create and store a image entity. """ figure_dict = XMLReader(file_name).read_metadata() new_path = os.path.join(os.path.split(file_name)[0], os.path.split(figure_dict['file_path'])[1]) if not os.path.exists(new_path): self.logger.warn("Expected to find image path %s .Skipping" % new_path) op = dao.get_operation_by_gid(figure_dict['fk_from_operation']) figure_dict['fk_op_id'] = op.id if op is not None else None figure_dict['fk_user_id'] = self.user_id figure_dict['fk_project_id'] = project_id figure_entity = manager_of_class(model.ResultFigure).new_instance() figure_entity = figure_entity.from_dict(figure_dict) stored_entity = dao.store_entity(figure_entity) # Update image meta-data with the new details after import figure = dao.load_figure(stored_entity.id) self.logger.debug("Store imported figure") self.files_helper.write_image_metadata(figure)
def _review_operation_inputs(self, operation_gid): """ :returns: A list of DataTypes that are used as input parameters for the specified operation. And a dictionary will all operation parameters different then the default ones. """ operation = dao.get_operation_by_gid(operation_gid) parameters = json.loads(operation.parameters) try: adapter = ABCAdapter.build_adapter(operation.algorithm) return adapter.review_operation_inputs(parameters) except IntrospectionException: self.logger.warning("Could not find adapter class for operation %s" % operation_gid) inputs_datatypes = [] changed_parameters = dict(Warning="Algorithm was Removed. We can not offer more details") for submit_param in parameters.values(): self.logger.debug("Searching DT by GID %s" % submit_param) datatype = ABCAdapter.load_entity_by_gid(str(submit_param)) if datatype is not None: inputs_datatypes.append(datatype) return inputs_datatypes, changed_parameters
def load_operation_by_gid(operation_gid): """ Retrieve loaded Operation from DB""" return dao.get_operation_by_gid(operation_gid)
def load_operation_by_gid(operation_gid): """ Retrieve loaded Operation from DB""" return dao.get_operation_by_gid(operation_gid)