adding marshmallow for validation 67/13667/6
authorrajdeep11 <rajdeep.sin@samsung.com>
Sat, 19 Oct 2024 10:15:09 +0000 (15:45 +0530)
committerrajdeep11 <rajdeep.sin@samsung.com>
Mon, 28 Oct 2024 06:55:43 +0000 (12:25 +0530)
created folder schemas

Change-Id: I5dafedd4848ae88ae1025053fafcc24b3d7ea1fc
Signed-off-by: rajdeep11 <rajdeep.sin@samsung.com>
requirements.txt
tox.ini
trainingmgr/models/__init__.py
trainingmgr/models/featuregroup.py
trainingmgr/models/trainingjob.py
trainingmgr/schemas/__init__.py [new file with mode: 0644]
trainingmgr/schemas/featuregroup_schema.py [new file with mode: 0644]
trainingmgr/schemas/trainingjob_schema.py [new file with mode: 0644]
trainingmgr/trainingmgr_main.py

index 113da19..ed9af3e 100644 (file)
@@ -29,4 +29,6 @@ validators==0.20.0
 Werkzeug==2.2.2
 Flask-SQLAlchemy
 Flask-Migrate
-psycopg2-binary
\ No newline at end of file
+psycopg2-binary==2.9.10
+marshmallow-sqlalchemy
+flask-marshmallow
\ No newline at end of file
diff --git a/tox.ini b/tox.ini
index 70bf1d4..af484df 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -44,6 +44,8 @@ deps=
   Werkzeug==2.2.2
   validators==0.20.0
   Flask-Migrate
+  marshmallow-sqlalchemy
+  flask-marshmallow
 
 setenv = cd  = {toxinidir}/tests
 commands =
index d6bf951..aa18ff7 100644 (file)
@@ -1,3 +1,20 @@
+# ==================================================================================
+#
+#       Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#          http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+# ==================================================================================
 from flask_sqlalchemy import SQLAlchemy
 
 db = SQLAlchemy()
index b434280..2c59b6f 100644 (file)
@@ -1,3 +1,20 @@
+# ==================================================================================
+#
+#       Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#          http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+# ==================================================================================
 from . import db
 
 class FeatureGroup(db.Model):
@@ -13,9 +30,9 @@ class FeatureGroup(db.Model):
     db_org = db.Column(db.String(128), nullable=False)
     measurement = db.Column(db.String(1000), nullable=False)
     enable_dme = db.Column(db.Boolean, nullable=False)
-    measured_obj_class = db.Column(db.String(20000), nullable=False)
-    dme_port = db.Column(db.String(128), nullable=False)
-    source_name = db.Column(db.String(20000), nullable=False)
+    measured_obj_class = db.Column(db.String(20000), nullable=True)
+    dme_port = db.Column(db.String(128), nullable=True)
+    source_name = db.Column(db.String(20000), nullable=True)
 
     def __repr__(self):
         return f'<featuregroup {self.featuregroup_name}>'
\ No newline at end of file
index 85ae701..56f87bf 100644 (file)
@@ -1,3 +1,21 @@
+# ==================================================================================
+#
+#       Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#          http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+# ==================================================================================
+
 from . import db
 from datetime import datetime
 from sqlalchemy.sql import func
@@ -23,9 +41,9 @@ class TrainingJob(db.Model):
     model_url = db.Column(db.String(1000), nullable=False)
     notification_url = db.Column(db.String(1000), nullable=False)
     deletion_in_progress = db.Column(db.Boolean, nullable=False)
-    is_mme = db.Column(db.Boolean, nullable=False)
-    model_name = db.Column(db.String(128), nullable=False)
-    model_info = db.Column(db.String(1000), nullable=False)
+    is_mme = db.Column(db.Boolean, nullable=True)
+    model_name = db.Column(db.String(128), nullable=True)
+    model_info = db.Column(db.String(1000), nullable=True)
 
     def __repr__(self):
         return f'<Trainingjob {self.trainingjob_name}>'
\ No newline at end of file
diff --git a/trainingmgr/schemas/__init__.py b/trainingmgr/schemas/__init__.py
new file mode 100644 (file)
index 0000000..f23121c
--- /dev/null
@@ -0,0 +1,8 @@
+from flask_marshmallow import Marshmallow
+
+ma = Marshmallow()
+
+from trainingmgr.schemas.trainingjob_schema import TrainingJobSchema
+from trainingmgr.schemas.featuregroup_schema import FeatureGroupSchema
+
+__all_ = ['TrainingJobSchema', 'FeatureGroupSchema']
\ No newline at end of file
diff --git a/trainingmgr/schemas/featuregroup_schema.py b/trainingmgr/schemas/featuregroup_schema.py
new file mode 100644 (file)
index 0000000..ce2ae1d
--- /dev/null
@@ -0,0 +1,26 @@
+# ==================================================================================
+#
+#       Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#          http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+# ==================================================================================
+
+from trainingmgr.schemas import ma
+from trainingmgr.models import FeatureGroup
+
+class FeatureGroupSchema(ma.SQLAlchemyAutoSchema):
+    class Meta:
+        model = FeatureGroup
+        include_relationships = True
+        load_instance = True
diff --git a/trainingmgr/schemas/trainingjob_schema.py b/trainingmgr/schemas/trainingjob_schema.py
new file mode 100644 (file)
index 0000000..38b6a6d
--- /dev/null
@@ -0,0 +1,26 @@
+# ==================================================================================
+#
+#       Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#          http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+# ==================================================================================
+
+from trainingmgr.schemas import ma
+from trainingmgr.models import TrainingJob
+
+class TrainingJobSchema(ma.SQLAlchemyAutoSchema):
+    class Meta:
+        model = TrainingJob
+        include_relationships = True
+        load_instance = True
\ No newline at end of file
index 91ddc47..385d9ee 100644 (file)
@@ -56,6 +56,7 @@ from trainingmgr.db.common_db_fun import get_data_extraction_in_progress_trainin
     get_field_of_given_version,get_all_jobs_latest_status_version, get_info_of_latest_version, \
     get_feature_groups_db, get_feature_group_by_name_db, delete_feature_group_by_name, delete_trainingjob_version, change_field_value_by_version
 from trainingmgr.models import db, TrainingJob, FeatureGroup
+from trainingmgr.schemas import ma, TrainingJobSchema , FeatureGroupSchema
 
 APP = Flask(__name__)
 TRAININGMGR_CONFIG_OBJ = None