diff --git a/app/modules/confirmemail/models.py b/app/modules/confirmemail/models.py
index 85c96d5b6..c57bf4fe0 100644
--- a/app/modules/confirmemail/models.py
+++ b/app/modules/confirmemail/models.py
@@ -1,5 +1,5 @@
from app import db
-class Confirmemail(db.Model):
+class Confirmemail():
id = db.Column(db.Integer, primary_key=True)
diff --git a/app/modules/dataset/templates/dataset/view_dataset.html b/app/modules/dataset/templates/dataset/view_dataset.html
index e1e1036c4..e2541b1cb 100644
--- a/app/modules/dataset/templates/dataset/view_dataset.html
+++ b/app/modules/dataset/templates/dataset/view_dataset.html
@@ -331,22 +331,6 @@
{{ dataset.count_fea
View
-
-
-
-
-
diff --git a/app/modules/flamapy/models.py b/app/modules/flamapy/models.py
index e69de29bb..61249a3be 100755
--- a/app/modules/flamapy/models.py
+++ b/app/modules/flamapy/models.py
@@ -0,0 +1,5 @@
+from app import db
+
+
+class Flamapy():
+ id = db.Column(db.Integer, primary_key=True)
diff --git a/app/modules/flamapy/routes.py b/app/modules/flamapy/routes.py
index d1adc90b2..482357fd6 100755
--- a/app/modules/flamapy/routes.py
+++ b/app/modules/flamapy/routes.py
@@ -2,76 +2,11 @@
from app.modules.hubfile.services import HubfileService
from flask import send_file, jsonify
from app.modules.flamapy import flamapy_bp
-from flamapy.interfaces.python.flamapy_feature_model import FLAMAFeatureModel
-from flamapy.core.exceptions import FlamaException
import os
-from antlr4 import CommonTokenStream, FileStream
-from uvl.UVLCustomLexer import UVLCustomLexer
-from uvl.UVLPythonParser import UVLPythonParser
-from antlr4.error.ErrorListener import ErrorListener
-
logger = logging.getLogger(__name__)
-@flamapy_bp.route('/flamapy/check_uvl', methods=['POST'])
-def check_uvl():
- # Obtener la ruta del archivo desde los datos de la solicitud
- data = request.get_json()
- filepath = data.get("filepath")
-
- class CustomErrorListener(ErrorListener):
- def __init__(self):
- self.errors = []
-
- def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):
- if "\\t" in msg:
- warning_message = (
- f"The UVL has the following warning that prevents reading it: "
- f"Line {line}:{column} - {msg}"
- )
- print(warning_message)
- self.errors.append(warning_message)
- else:
- error_message = (
- f"The UVL has the following error that prevents reading it: "
- f"Line {line}:{column} - {msg}"
- )
- self.errors.append(error_message)
-
- try:
- input_stream = FileStream(filepath)
- lexer = UVLCustomLexer(input_stream)
-
- error_listener = CustomErrorListener()
-
- lexer.removeErrorListeners()
- lexer.addErrorListener(error_listener)
-
- stream = CommonTokenStream(lexer)
- parser = UVLPythonParser(stream)
-
- parser.removeErrorListeners()
- parser.addErrorListener(error_listener)
-
- # Optional: Commented out for now
- # tree = parser.featureModel()
-
- if error_listener.errors:
- return jsonify({"errors": error_listener.errors}), 400
-
- # After parsing, try transforming the model
- try:
- FLAMAFeatureModel(filepath) # Example usage
- return jsonify({"message": "Valid Model"}), 200
-
- except FlamaException as fe:
- return jsonify({"error": f"Model transformation failed: {str(fe)}"}), 400
-
- except Exception as e:
- return jsonify({"error": str(e)}), 500
-
-
@flamapy_bp.route('/flamapy/valid/', methods=['GET'])
def valid(file_id):
return jsonify({"success": True, "file_id": file_id})
diff --git a/app/modules/flamapy/services.py b/app/modules/flamapy/services.py
index e0f09de2b..95361a740 100755
--- a/app/modules/flamapy/services.py
+++ b/app/modules/flamapy/services.py
@@ -1,7 +1,63 @@
from app.modules.flamapy.repositories import FlamapyRepository
from core.services.BaseService import BaseService
+from flamapy.interfaces.python.flamapy_feature_model import FLAMAFeatureModel
+from flamapy.core.exceptions import FlamaException
+
+from antlr4 import CommonTokenStream, FileStream
+from uvl.UVLCustomLexer import UVLCustomLexer
+from uvl.UVLPythonParser import UVLPythonParser
+from antlr4.error.ErrorListener import ErrorListener
class FlamapyService(BaseService):
def __init__(self):
super().__init__(FlamapyRepository())
+
+ def check_uvl(self, filepath: str):
+
+ class CustomErrorListener(ErrorListener):
+
+ def __init__(self):
+ self.errors = []
+
+ def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):
+ if "\\t" in msg:
+ warning_message = (
+ f"The UVL has the following warning that prevents reading it: "
+ f"Line {line}:{column} - {msg}"
+ )
+ self.errors.append(warning_message)
+ else:
+ error_message = (
+ f"The UVL has the following error that prevents reading it: "
+ f"Line {line}:{column} - {msg}"
+ )
+ self.errors.append(error_message)
+
+ try:
+ input_stream = FileStream(filepath)
+ lexer = UVLCustomLexer(input_stream)
+
+ error_listener = CustomErrorListener()
+
+ lexer.removeErrorListeners()
+ lexer.addErrorListener(error_listener)
+
+ stream = CommonTokenStream(lexer)
+ parser = UVLPythonParser(stream)
+
+ parser.removeErrorListeners()
+ parser.addErrorListener(error_listener)
+
+ if error_listener.errors:
+ return {"errors": error_listener.errors}, 400
+
+ try:
+ FLAMAFeatureModel(filepath)
+ return {"message": "Valid Model"}, 200
+
+ except FlamaException as fe:
+ return {"error": f"Model transformation failed: {str(fe)}"}, 400
+
+ except Exception as e:
+ return {"error": str(e)}, 500
diff --git a/app/modules/hubfile/routes.py b/app/modules/hubfile/routes.py
index 81f8961a9..a2a8ce288 100644
--- a/app/modules/hubfile/routes.py
+++ b/app/modules/hubfile/routes.py
@@ -1,9 +1,9 @@
from datetime import datetime
import os
import uuid
-from flask import current_app, jsonify, make_response, request, send_from_directory, url_for
+from app.modules.flamapy.services import FlamapyService
+from flask import current_app, jsonify, make_response, request, send_from_directory
from flask_login import current_user, login_required
-import requests
from app.modules.hubfile import hubfile_bp
from app.modules.hubfile.models import HubfileViewRecord
from app.modules.hubfile.services import HubfileDownloadRecordService, HubfileService
@@ -13,6 +13,8 @@
hubfile_download_record_service = HubfileDownloadRecordService()
+flamapy_service = FlamapyService()
+
@hubfile_bp.route("/hubfile/upload", methods=["POST"])
@login_required
@@ -36,16 +38,13 @@ def upload_file():
except Exception as e:
return jsonify({"message": str(e)}), 500
- # Llamar a la ruta de validación `check_uvl` con una petición interna
- check_uvl_url = url_for('flamapy.check_uvl', _external=True)
- try:
- response = requests.post(check_uvl_url, json={"filepath": temp_file_path})
- if response.status_code != 200:
- # Si no es válido, eliminar el archivo temporal y retornar error
- os.remove(temp_file_path)
- return response.json(), response.status_code
- except requests.RequestException as e:
- return jsonify({"error": str(e)}), 500
+ # Llamar directamente a `check_uvl` pasando la ruta temporal del archivo
+ validation_result, status_code = flamapy_service.check_uvl(temp_file_path)
+
+ if status_code != 200:
+ # Si no es válido, eliminar el archivo temporal y retornar error
+ os.remove(temp_file_path)
+ return jsonify(validation_result), status_code
# Si el archivo es válido, guardarlo permanentemente
new_filename = file.filename