def process_request(cls, params_dict): response = {} http_status_code = 200 targets_uuids = params_dict[ParameterFactory.uuid()] criteria = {UUID: {"$in": targets_uuids}} try: records = cls._DB_CONNECTOR.find(TARGETS_COLLECTION, criteria, {ID:0}) response["deleted"] = {} if len(records) > 0: # Record records for record in records: response["deleted"][record[UUID]] = record # Delete records from database result = cls._DB_CONNECTOR.remove(TARGETS_COLLECTION, criteria) # Delete files from disk only if removal from DB was successful if result and result['n'] == len(response["deleted"]): for _,record in response["deleted"].iteritems(): os.remove(record[FILEPATH]) else: del response["deleted"] raise Exception("Error deleting records from the database: %s" % result) else: http_status_code = 404 except: response[ERROR] = str(sys.exc_info()[1]) http_status_code = 500 return make_response(jsonify(response), http_status_code)
def process_request(cls, params_dict): response = {} http_status_code = 200 targets_uuids = params_dict[ParameterFactory.uuid()] criteria = {UUID: {"$in": targets_uuids}} try: records = cls._DB_CONNECTOR.find(TARGETS_COLLECTION, criteria, {ID: 0}) response["deleted"] = {} if len(records) > 0: # Record records for record in records: response["deleted"][record[UUID]] = record # Delete records from database result = cls._DB_CONNECTOR.remove(TARGETS_COLLECTION, criteria) # Delete files from disk only if removal from DB was successful if result and result['n'] == len(response["deleted"]): for _, record in response["deleted"].iteritems(): os.remove(record[FILEPATH]) else: del response["deleted"] raise Exception( "Error deleting records from the database: %s" % result) else: http_status_code = 404 except: response[ERROR] = str(sys.exc_info()[1]) http_status_code = 500 return make_response(jsonify(response), http_status_code)
def parameters(cls): parameters = [ ParameterFactory.uuid(), ] return parameters