def get_current_translators(database): """Returns all the translators that haven't been removed. """ collection = get_translator_collection(database) argument = mongo_utils.make_single_field_argument("remove_date", None) cursor = mongo_utils.mongo_find_records(collection, argument=argument) return mongo_utils.unload_cursor(cursor)
def get_all_structures(database, args=None): """Returns all the structures in storage. """ collection = get_structure_collection(database) if args: arguments = [ mongo_utils.make_single_field_argument(arg['key'], arg['value'], arg_type=arg['operation']) for arg in args ] argument = general_utils.merge_list_of_dicts(arguments) cursor = mongo_utils.mongo_find_records(collection, argument=argument) else: cursor = mongo_utils.mongo_find_records(collection) return mongo_utils.unload_cursor(cursor)
def get_all_projects(): """Returns all the project objects as a list as they currently exist in the program storage. """ collection = get_project_collection() cursor = mongo_utils.mongo_find_records(collection, named_tuple=False) return mongo_utils.unload_cursor(cursor)
def get_current_records(database, structure): """Returns all the records that haven't been removed for a given structure. """ collection = get_record_collection(database, structure) argument = mongo_utils.make_single_field_argument("remove_date", None) cursor = mongo_utils.mongo_find_records(collection, argument=argument) return mongo_utils.unload_cursor(cursor)
def get_all_evaluations(project, current_only=False): """ Returns all evaluations as a list of evaluation dictionary objects. Optionally can specify current_only to retrieve only the most current record for each evaluation. """ collection = get_evaluation_collection(project) cursor = mongo_utils.mongo_find_records(collection, named_tuple=False) return mongo_utils.unload_cursor(cursor)
def get_all_current_groups(database): """Returns all groups that are current (no removal date) in the current database. """ collection = get_group_collection(database) argument = mongo_utils.make_single_field_argument('remove_date', None) cursor = mongo_utils.mongo_find_records(collection, argument=argument) return mongo_utils.unload_cursor(cursor)
def get_all_components(database, current_only=False): """ Returns all components as a list of component dictionary objects. Optionally can specify current_only to retrieve only the most current record for each component. """ collection = get_component_collection(database) cursor = mongo_utils.mongo_find_records(collection, named_tuple=False) return mongo_utils.unload_cursor(cursor)
def get_evaluations_by_name(project, name): """ Returns all the evaluations by name, if it exists, otherwise returns False """ collection = get_evaluation_collection(project) argument = mongo_utils.make_single_field_argument('name', name) cursor = mongo_utils.mongo_find_records(collection, argument=argument, named_tuple=False) return mongo_utils.unload_cursor(cursor)
def get_components_by_name(database, name): """ Returns all the components by name, if it exists, otherwise returns False """ collection = get_component_collection(database) argument = mongo_utils.make_single_field_argument('name', name) cursor = mongo_utils.mongo_find_records(collection, argument=argument, named_tuple=False) return mongo_utils.unload_cursor(cursor)
def get_removed_evaluations(project): """Returns evaluations that have been removed from the specified project. Optionally can return all records (including older) if current_only is set to False. """ collection = get_evaluation_collection(project) argument = mongo_utils.make_single_field_argument('status', 'removed') cursor = mongo_utils.mongo_find_records(collection, argument=argument, named_tuple=False) return mongo_utils.unload_cursor(cursor)
def get_all_current_evaluations(project): """Returns all evaluations that are current (no removal date) in the current project. """ collection = get_evaluation_collection(project) argument = mongo_utils.make_single_field_argument('remove_date', None) cursor = mongo_utils.mongo_find_records(collection, argument=argument, named_tuple=False) return mongo_utils.unload_cursor(cursor)
def get_record_by_id(database, collection, record_id): """Returns the record for the given id. """ collection = get_record_collection(database, collection) argument = mongo_utils.make_single_field_argument('_id', record_id) cursor = mongo_utils.mongo_find_records(collection, argument=argument) record_list = mongo_utils.unload_cursor(cursor) try: return record_list[0] except IndexError: return None
def get_group_by_id(database, group_id): """Returns the group by the given id. """ collection = get_group_collection(database) argument = mongo_utils.make_single_field_argument('_id', group_id) cursor = mongo_utils.mongo_find_records(collection, argument=argument) group_list = mongo_utils.unload_cursor(cursor) try: return group_list[0] except IndexError: return None
def get_project_by_name(project_name): """Returns the project object with the matching passed name. """ collection = get_project_collection() argument = mongo_utils.make_single_field_argument("name", project_name) cursor = mongo_utils.mongo_find_records(collection, argument=argument, named_tuple=False) project_list = mongo_utils.unload_cursor(cursor) try: return project_list[0] except: return None
def get_component_by_id(database, component_id): """Returns the component by the given id. """ collection = get_component_collection(database) argument = mongo_utils.make_single_field_argument('_id', component_id) cursor = mongo_utils.mongo_find_records(collection, argument=argument, named_tuple=False) component_list = mongo_utils.unload_cursor(cursor) try: return component_list[0] except IndexError: return None
def get_evaluation_by_id(project, evaluation_id): """Returns the evaluation by the given id. """ collection = get_evaluation_collection(project) argument = mongo_utils.make_single_field_argument('_id', evaluation_id) cursor = mongo_utils.mongo_find_records(collection, argument=argument, named_tuple=False) evaluation_list = mongo_utils.unload_cursor(cursor) try: return evaluation_list[0] except IndexError: return None
def get_evaluations_by_workflow(project, workflow): """Returns all evaluations for the given workflow. """ collection = get_evaluation_collection(project) argument = mongo_utils.make_single_field_argument('workflow', workflow) cursor = mongo_utils.mongo_find_records(collection, argument=argument, named_tuple=False) evaluation_list = mongo_utils.unload_cursor(cursor) try: return evaluation_list except IndexError: return None
def get_function_by_id(project, function_id): """Returns the function by the given id. """ function_id = ObjectId(function_id) collection = get_language_collection(project) argument = mongo_utils.make_single_field_argument('_id', function_id) cursor = mongo_utils.mongo_find_records(collection, argument=argument, named_tuple=False) function_list = mongo_utils.unload_cursor(cursor) try: return function_list[0] except IndexError: return None
def get_all_templates_by_structure_name(database, structure_name): """Returns all templates in storage for the given structure name. """ collection = get_template_collection(database) arguments = [] arguments.append( mongo_utils.make_single_field_argument('structure', structure_name)) argument = general_utils.merge_list_of_dicts(arguments) cursor = mongo_utils.mongo_find_records(collection, argument=argument) template_list = mongo_utils.unload_cursor(cursor) try: return template_list except IndexError: return None
def replace_evaluation_by_id(project, evaluation_id, evaluation): """Replaces the current evaluation with the new evaluation. Returns the new evaluation. """ collection = get_evaluation_collection(project) argument = mongo_utils.make_single_field_argument('_id', evaluation_id) cursor = mongo_utils.mongo_replace_one(collection, evaluation, argument) if cursor.matched_count == 1: cursor = mongo_utils.mongo_find_records(collection, argument=argument, named_tuple=False) evaluation_list = mongo_utils.unload_cursor(cursor) try: return evaluation_list[0] except IndexError: return None
def replace_component_by_id(database, component_id, component): """Replaces the current component with the new component. Returns the new component. """ collection = get_component_collection(database) argument = mongo_utils.make_single_field_argument('_id', component_id) cursor = mongo_utils.mongo_replace_one(collection, component, argument) if cursor.matched_count == 1: cursor = mongo_utils.mongo_find_records(collection, argument=argument, named_tuple=False) component_list = mongo_utils.unload_cursor(cursor) try: return component_list[0] except IndexError: return None
def get_default_profile(database): """Returns the current profile by name. """ collection = get_profile_collection(database) arguments = [] arguments.append(mongo_utils.make_single_field_argument('default', True)) arguments.append( mongo_utils.make_single_field_argument('remove_date', None)) argument = general_utils.merge_list_of_dicts(arguments) cursor = mongo_utils.mongo_find_records(collection, argument=argument) profile_list = mongo_utils.unload_cursor(cursor) try: return profile_list[0] except IndexError: return None
def replace_workflow_by_id(project, workflow_id, workflow): """Replaces the current workflow with the new workflow. Returns the new workflow. """ collection = get_workflow_collection(project) argument = mongo_utils.make_single_field_argument('_id', workflow_id) cursor = mongo_utils.mongo_replace_one(collection, workflow, argument) if cursor.matched_count == 1: cursor = mongo_utils.mongo_find_records(collection, argument=argument, named_tuple=False) workflow_list = mongo_utils.unload_cursor(cursor) try: return workflow_list[0] except IndexError: return None
def get_template_by_id(database, template_id): """Returns the template by id. """ collection = get_template_collection(database) template_id = mongo_utils.ensure_objectid(template_id) arguments = [] arguments.append(mongo_utils.make_single_field_argument( '_id', template_id)) argument = general_utils.merge_list_of_dicts(arguments) cursor = mongo_utils.mongo_find_records(collection, argument=argument) template_list = mongo_utils.unload_cursor(cursor) try: return template_list[0] except IndexError: return None
def get_translator_by_id(database, translator_id): """Returns the current translator by id. """ collection = get_translator_collection(database) arguments = [] arguments.append( mongo_utils.make_single_field_argument('_id', translator_id)) arguments.append( mongo_utils.make_single_field_argument('remove_date', None)) argument = general_utils.merge_list_of_dicts(arguments) cursor = mongo_utils.mongo_find_records(collection, argument=argument) translator_list = mongo_utils.unload_cursor(cursor) try: return translator_list[0] except IndexError: return None
def replace_project_by_id(project_id, project): """Replaces a project matching the given id with the new project object. Returns the new project object. """ collection = get_project_collection() argument = mongo_utils.make_single_field_argument("_id", project_id) cursor = mongo_utils.mongo_replace_one(collection, project, argument) if cursor.matched_count == 1: cursor = mongo_utils.mongo_find_records(collection, argument=argument, named_tuple=False) project_list = mongo_utils.unload_cursor(cursor) try: return project_list[0] except: return None return None
def get_template_by_name(database, structure, name): """Returns the current template by name. """ collection = get_template_collection(database) arguments = [] arguments.append( mongo_utils.make_single_field_argument('structure', structure)) arguments.append(mongo_utils.make_single_field_argument('name', name)) arguments.append( mongo_utils.make_single_field_argument('remove_date', None)) argument = general_utils.merge_list_of_dicts(arguments) cursor = mongo_utils.mongo_find_records(collection, argument=argument) template_list = mongo_utils.unload_cursor(cursor) try: return template_list[0] except IndexError: return None
def get_structure_by_id(database, structure_id): """Returns the current profile by name. """ structure_id = mongo_utils.ensure_objectid(structure_id) collection = get_structure_collection(database) arguments = [] arguments.append( mongo_utils.make_single_field_argument('_id', structure_id)) arguments.append( mongo_utils.make_single_field_argument('remove_date', None)) argument = general_utils.merge_list_of_dicts(arguments) cursor = mongo_utils.mongo_find_records(collection, argument=argument) structure_list = mongo_utils.unload_cursor(cursor) try: return structure_list[0] except IndexError: return None
def get_workflow_evaluations_by_name(project, workflow, name): """Returns all evaluations in the given workflow with the given name. """ collection = get_evaluation_collection(project) arguments = [] arguments.append(mongo_utils.make_single_field_argument('name', name)) arguments.append( mongo_utils.make_single_field_argument('workflow', workflow)) argument = general_utils.merge_list_of_dicts(arguments) cursor = mongo_utils.mongo_find_records(collection, argument=argument, named_tuple=False) evaluation_list = mongo_utils.unload_cursor(cursor) try: return evaluation_list except IndexError: return None
def get_current_evaluation_by_name(project, name): """Returns the current evaluation by name. """ collection = get_evaluation_collection(project) arguments = [] arguments.append(mongo_utils.make_single_field_argument('name', name)) arguments.append( mongo_utils.make_single_field_argument('remove_date', None)) argument = general_utils.merge_list_of_dicts(arguments) cursor = mongo_utils.mongo_find_records(collection, argument=argument, named_tuple=False) evaluation_list = mongo_utils.unload_cursor(cursor) try: return evaluation_list[0] except IndexError: return None