def documents_data(solution_id, filter_obj=None): context = tracer.get_context(request_id=str(uuid4()), log_level="INFO") context.start_span(component=__name__) try: filter_query = {"solution_id": solution_id, "is_root": True, "$or": [{"is_test": False}, {"is_test": {"$exists": False}}]} projection_fields = dict() for field in DOCUMENT_SUMMARY_FIELDS: projection_fields[field] = 1 apply_filters(filter_obj, filter_query) documents = find_documents(filter_obj, DOCUMENTS_COLLECTION, filter_query, solution_id, projection_fields=projection_fields) documents_total_count = MongoDbConn.count(DOCUMENTS_COLLECTION, filter_query) resp = {'config': summary_config, 'data': documents, 'total_count': documents_total_count} return {"status": "success", "msg": "documents data", "data": resp} # TODO raise specific exception except Exception as e: context.log(message=str(e), obj={"tb": traceback.format_exc()}) return {"status": "failure", "msg": str(e), "data": {}} finally: context.end_span()
def check_entity_used_elsewhere(domain_name, entity_name, solution_id): context = tracer.get_context(request_id=str(uuid4()), log_level="ERROR") context.start_span(component=__name__) try: query = { "attributes": { "$elemMatch": { "key_name": entity_name, "type": "entity" } }, "entity_name": { "$ne": domain_name }, "solution_id": solution_id } entities_count = MongoDbConn.count(ENTITY_COLLECTION, query) return True if entities_count > 0 else False # TODO raise specific exception except Exception as e: context.log(message=str(e), obj={"tb": traceback.format_exc()}) return True finally: context.end_span()