@@ -341,6 +341,20 @@ def delete(self, pathogen_id):
341341
342342 with get_db_cursor () as cursor :
343343 if hard_delete :
344+
345+ # Check if there are associated schemas
346+ cursor .execute ("""
347+ SELECT COUNT(*) as count FROM schemas
348+ WHERE pathogen_id = %s
349+ """ , (pathogen_id ,))
350+
351+ schema_count = cursor .fetchone ()['count' ]
352+
353+ if schema_count > 0 :
354+ return {
355+ 'error' : f'Cannot delete pathogen: { schema_count } schema(s) are still associated with it. Delete schemas first or use soft delete.'
356+ }, 400
357+
344358 # Hard delete - permanently remove from database
345359 cursor .execute ("""
346360 DELETE FROM pathogens
@@ -2672,11 +2686,6 @@ def post(self):
26722686 try :
26732687 data = request .get_json ()
26742688
2675- print ('========================================' )
2676- print ("Incoming search query:" )
2677- print (data )
2678- print ('========================================' )
2679-
26802689 # convert json data to string and replace all .keyword with ''
26812690 data_str = json .dumps (data ).replace ('.keyword' , '' )
26822691 data = json .loads (data_str )
@@ -2731,10 +2740,6 @@ def post(self):
27312740 if not data :
27322741 return {'error' : 'No JSON data provided' }, 400
27332742
2734- print ("Final Query ========================" )
2735- print (data ['query' ])
2736- print ("===================================" )
2737-
27382743 results = query_elastic (data )
27392744
27402745 print (results )
@@ -2830,6 +2835,41 @@ def post(self):
28302835 logger .exception (f"Error during reindexing: { str (e )} " )
28312836 return {'error' : f'Reindexing error: { str (e )} ' }, 500
28322837
2838+ ##########################
2839+ ### JOBS MONITORING
2840+ ##########################
2841+
2842+ jobs_ns = api .namespace ('jobs' , description = 'Job monitoring endpoints' )
2843+
2844+ @jobs_ns .route ('/' )
2845+ class JobsList (Resource ):
2846+
2847+ ### GET /jobs ###
2848+
2849+ @jobs_ns .doc ('list_jobs' )
2850+ @require_auth (keycloak_auth )
2851+ @require_permission ('system_admin_access' )
2852+ def get (self ):
2853+ """List all jobs from the jobs table"""
2854+
2855+ try :
2856+ with get_db_cursor () as cursor :
2857+ cursor .execute ("""
2858+ SELECT * FROM jobs
2859+ ORDER BY created_at DESC
2860+ """ )
2861+
2862+ jobs = cursor .fetchall ()
2863+
2864+ return {
2865+ 'jobs' : jobs ,
2866+ 'total' : len (jobs )
2867+ }
2868+
2869+ except Exception as e :
2870+ logger .exception (f"Error retrieving jobs: { str (e )} " )
2871+ return {'error' : f'Database error: { str (e )} ' }, 500
2872+
28332873
28342874
28352875##########################
0 commit comments