Commit 45f6bbe8 authored by hrishikesh.r's avatar hrishikesh.r

Made Further changes to Oee_handlers.py

parent 071b0650
from scripts.logging import logger from scripts.logging import logger
from scripts.utils.mongo_util import MongoCollectionBaseClass from scripts.utils.mongo_util import MongoCollectionBaseClass
from scripts.schemas.oee_config_schema import oee_tag_mapping_list, get_oee_tag, update_oee_tags, project_id from scripts.schemas.oee_config_schema import Oee_Tag_Mapping_List, Get_Oee_Tag, Update_Oee_Tags, Get_Project_Id
from scripts.constants import CommonKeys
from scripts.db.mongo.ilens_configuration import database
from scripts.db.mongo.ilens_configuration.collections import collection_constants
from scripts.utils.mongo_util import MongoCollectionBaseClass
from scripts.schemas import mongo_schema
from scripts.constants.db_connections import mongo_client from scripts.constants.db_connections import mongo_client
class Oee_Services: class Oee_Services:
def __init__(self): def __init__(self, project_id=Get_Project_Id.project_id):
try: try:
self.connect = MongoCollectionBaseClass(mongo_client=mongo_client, database="ilens_configuration", self.connect = collection_constants(mongo_client=mongo_client)
collection="oee_tag_mapping")
except Exception as e: except Exception as e:
logger.exception("Error while connecting to mongodb") logger.exception("Error while connecting to mongodb")
def oee_tag_mapping(self, oee_tag_mapping_list: oee_tag_mapping_list): def oee_tag_mapping(self, oee_tag_mapping_list: Oee_Tag_Mapping_List):
try: try:
return_json = {"message": "failure", "status": "failure", "message": "data not inserted in to mongodb"}
insert_json = {"hierarchy": oee_tag_mapping_list.hierarchy, insert_json = {"hierarchy": oee_tag_mapping_list.hierarchy,
"project_id": oee_tag_mapping_list.project_id, "project_id": oee_tag_mapping_list.project_id,
"meta": oee_tag_mapping_list.project_id, "meta": oee_tag_mapping_list.project_id,
...@@ -24,18 +28,12 @@ class Oee_Services: ...@@ -24,18 +28,12 @@ class Oee_Services:
result = self.connect.insert_one(data=insert_json) result = self.connect.insert_one(data=insert_json)
if result: if result:
logger.info("Data inserted in to mongodb successfully") logger.info("Data inserted in to mongodb successfully")
return_json["message"] = "success"
return_json["status"] = "success"
else: else:
logger.info("Unable to insert data in to Mongodb") logger.info("Unable to insert data in to Mongodb")
return return_json
except Exception as e: except Exception as e:
logger.exception("Error occurred while inserting data") logger.exception("Error occurred while inserting data")
def get_oee_tag_mapping(self, get_oee_tag: Get_Oee_Tag):
def get_oee_tag_mapping(self, get_oee_tag: get_oee_tag):
try: try:
return_json = {"message": "failure", "status": "failure", "data": "data not found"} return_json = {"message": "failure", "status": "failure", "data": "data not found"}
query = {'project_id': get_oee_tag.project_id} query = {'project_id': get_oee_tag.project_id}
...@@ -43,10 +41,6 @@ class Oee_Services: ...@@ -43,10 +41,6 @@ class Oee_Services:
no_of_documents = self.connect.count_documents(query=query) no_of_documents = self.connect.count_documents(query=query)
result = self.connect.find(query=query).skip(skips).limit(get_oee_tag.page_num) result = self.connect.find(query=query).skip(skips).limit(get_oee_tag.page_num)
if result: if result:
return_json["message"] = "success"
return_json["status"] = "success"
return_json["data"] = result
return_json["total_records"] = no_of_documents
if skips < no_of_documents: if skips < no_of_documents:
return_json["endOfrecords"] = False return_json["endOfrecords"] = False
else: else:
...@@ -55,8 +49,7 @@ class Oee_Services: ...@@ -55,8 +49,7 @@ class Oee_Services:
except Exception as e: except Exception as e:
logger.exception(f"Exception occured while fetching data as {e}") logger.exception(f"Exception occured while fetching data as {e}")
def delete_oee_tags(self, project_id: Get_Project_Id):
def delete_oee_tags(self, project_id: project_id):
try: try:
return_json = {"message": "failure", "status": "failure", "data": "data not found"} return_json = {"message": "failure", "status": "failure", "data": "data not found"}
query = {"project_id": project_id.project_id} query = {"project_id": project_id.project_id}
...@@ -69,17 +62,11 @@ class Oee_Services: ...@@ -69,17 +62,11 @@ class Oee_Services:
except Exception as e: except Exception as e:
logger.exception(f"Exception occurred while fetching data as {e}") logger.exception(f"Exception occurred while fetching data as {e}")
def update_oee_tags(self, update_oee_tags: Update_Oee_Tags):
def update_oee_tags(self, update_oee_tags: update_oee_tags):
try: try:
return_json = {"message": "failure", "status": "failure", "data": "data not found"} query = {"project_id": ['update_oee_tags.project_id']}
query = {"project_id": ['update_oee_tags.projec_id']} result = self.connect.update_one(query=query)
result = self.connect.update_one(query=query, data=return_json)
if result: if result:
return_json["message"] = "success" return result
return_json["status"] = "success"
return_json["data"] = result
return return_json
except Exception as e: except Exception as e:
logger.exception(f"Exception occured while fetching data as {e}") logger.exception(f"Exception occured while fetching data as {e}")
from pydantic import BaseModel
from typing import Any, Optional
from scripts.constants import CommonKeys
from scripts.db.mongo.ilens_configuration import database
from scripts.db.mongo.ilens_configuration.collections import collection_constants
from scripts.utils.mongo_util import MongoCollectionBaseClass
class ConstantsSchema(BaseModel):
type: Optional[str]
data: Optional[Any]
map_json: Optional[Any]
content_type: Optional[Any]
content: Optional[Any]
class Constants(MongoCollectionBaseClass):
def __init__(self, mongo_client):
super().__init__(mongo_client, database=database,
collection=collection_constants)
from pydantic import BaseModel from pydantic import BaseModel
class oee_tag_mapping_list(BaseModel): class Oee_Tag_Mapping_List(BaseModel):
hierarchy: str hierarchy: str
project_id: str project_id: str
meta: str meta: str
oee_tag_mapping: str oee_tag_mapping: str
class get_oee_tag(BaseModel): class Get_Oee_Tag(BaseModel):
project_id: str project_id: str
page_size: str page_size: str
page_num: str page_num: str
class Get_Project_Id(BaseModel):
class project_id(BaseModel):
project_id: str project_id: str
class update_oee_tags(BaseModel): class Update_Oee_Tags(BaseModel):
project_id: str project_id: str
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment