def update_designation(self): """ edits any of the existing designations to the Designation Table by taking the designation code and title as input at runtime and creating a Designation class object. Creates a request class object, sends it using the NetworkClient class object and receives a response class object. This response object is then processed and prints the data sent in the response. """ try: code = int(input("Enter the Designation Code : ")) title = input("Enter the Designation Name : ") designation = Designation(code, title) request = Request(manager="DesignationManager", action="update", request_object=designation) network_client = NetworkClient() response = network_client.send(request) if response.success: print("Designation Update") else: er = ExceptionHandler.from_json(response.error_json) if er.exceptions is None: print(er.message) else: for exception in er.exceptions.values(): print(exception[1]) except: print( "Invalid entry type for fields of employee information form!") print("-" * 50)
def search_designation_by_title(self): """ Retrieves the desired designation by taking designation title as input at runtime. Creates a request class object, and sending it via a Wrapper class object to the request class object. Then sends it using the NetworkClient class object and receives a response class object. This response object is then processed and prints the data sent in the response. """ title = input("Enter the Designation Name : ") request = Request(manager="DesignationManager", action="getbytitle", request_object=Wrapper(title)) network_client = NetworkClient() response = network_client.send(request) if response.success: designation = Designation.from_json(response.result_json) print( f"Code : {designation.code} Designation : {designation.title}") else: er = ExceptionHandler.from_json(response.error_json) if er.exceptions is None: print(er.message) else: for exception in er.exceptions.values(): print(exception[1]) print("-" * 50)
def add_designation(self): """ adds a new designation to the Designation Table by taking the designation title as input at runtime and creating a Designation class object. Creates a request class object, sends it using the NetworkClient class object and receives a response class object. This response object is then processed and prints the data sent in the response. """ title = input("Enter the Designation to add : ") designation = Designation(0, title) request = Request(manager="DesignationManager", action="add", request_object=designation) network_client = NetworkClient() response = network_client.send(request) if response.success: print("Designation Added") else: er = ExceptionHandler.from_json(response.error_json) if er.exceptions is None: print(er.message) else: for exception in er.exceptions.values(): print(exception[1]) print("-" * 50)
from all_common.hr import Designation from sk_components.components import Wrapper from network_common.wrappers import Response d1 = Designation(-10, "Carpenter") d1._validate_values() r1 = Response(True, result_obj=d1) jst = r1.to_json() print(jst) print("-" * 25) r2 = Response.from_json(jst) print("Success :", r2.success) print("Error JSON :", r2.error_json) print("Result JSON :", r2.result_json) print("-" * 25) d2 = Designation.from_json(r2.result_json) print("Code :", d2.code, "Designation :", d2.title, "Exceptions :", d2.exceptions, "Has Exceptions :", d2.has_exceptions, sep="\n")
from all_common.hr import Designation d1 = Designation(10, "Carpenter") d1._validate_values() jstr = d1.to_json() print(jstr) print("*" * 30) d1 = Designation.from_json(jstr) print("Code :", d1.code) print("Title :", d1.title) print("Exceptions :", d1.exceptions) print("Has Exceptions :", d1.has_exceptions)
def requestHandler(request): """ This function process the Request object from the server and generates response data by interacting with the data-layer. This response data is then wrapped in a Response object which is returned to the network server. Functionality: If the request is the action is in Designation Master, the JSON object is converted to Designation object of all_common module which is further converted to Designation object of data-layer. This object is passed to the appropriate data-layer method and thus retrieve data This data is again converted to JSON string and the response object is created. This processed object is then returned. In another case, if the request is in Employee Master, the JSON object is converted to Employee object of all_common module which is further converted to the Employee object of data-layer. This object is passed to the appropriate data-layer method and thus retrieve data This data is again converted to JSON string and the response object is created. This processed object is then returned. To obtain a convertible Designation/Employee object, it often uses Wrapper and List Handler class. While if an exception gets raised it uses ExceptionHandler class to be processed which can be wrapped in the Response object. Arguments: request(Request): it is the object that wraps the data required to understand the request sent by the client and to process the response. Raises: DataLayerError: if some error occurs at the data layer, it raises DataLayerError. Return Value: returns the Response object. """ print(request.manager) print(request.action) print(request.json_string) if "designation" in request.manager.lower( ) and "add" in request.action.lower(): try: designation = Designation.from_json(request.json_string) if designation.has_exceptions: response = Response( success=False, error=ExceptionHandler(exceptions=designation.exceptions)) return response dl_designation = dld(code=designation.code, title=designation.title) HRDLHandler.add_designation(dl_designation) response = Response(success=True) return response except DataLayerError as dle: response = Response(success=False, error=ExceptionHandler(**dle.__dict__)) return response if "employee" in request.manager.lower() and "add" in request.action.lower( ): try: employee = Employee.from_json(request.json_string) if employee.has_exceptions: response = Response( success=False, error=ExceptionHandler(exceptions=employee.exceptions)) return response dl_employee = dlemp(**employee.__dict__) HRDLHandler.add_employee(dl_employee) response = Response(success=True) return response except DataLayerError as dle: response = Response(success=False, error=ExceptionHandler(**dle.__dict__)) return response if "employee" in request.manager.lower( ) and "update" in request.action.lower(): try: employee = Employee.from_json(request.json_string) if employee.has_exceptions: response = Response( success=False, error=ExceptionHandler(exceptions=employee.exceptions)) return response dl_employee = dlemp(**employee.__dict__) HRDLHandler.update_employee(dl_employee) response = Response(success=True) return response except DataLayerError as dle: response = Response(success=False, error=ExceptionHandler(**dle.__dict__)) return response if "employee" in request.manager.lower( ) and "remove" in request.action.lower(): try: emp_id = Wrapper.from_json(request.json_string) HRDLHandler.delete_employee(emp_id) response = Response(success=True) return response except DataLayerError as dle: response = Response(success=False, error=ExceptionHandler(**dle.__dict__)) return response if "employee" in request.manager.lower() and "id" in request.action.lower( ): try: emp_id = Wrapper.from_json(request.json_string) dl_employee = HRDLHandler.get_employee_by_id(emp_id) employee = Employee(dl_employee.emp_id, dl_employee.name, dl_employee.designation_code, dl_employee.date, dl_employee.month, dl_employee.year, dl_employee.salary, dl_employee.gender, dl_employee.indian, dl_employee.pan_no, dl_employee.aadhar) response = Response(success=True, result_obj=employee) return response except DataLayerError as dle: response = Response(success=False, error=ExceptionHandler(**dle.__dict__)) return response if "designation" in request.manager.lower( ) and "update" in request.action.lower(): try: designation = Designation.from_json(request.json_string) if designation.has_exceptions: response = Response( success=False, error=ExceptionHandler(exceptions=designation.exceptions)) return response dl_designation = dld(code=designation.code, title=designation.title) HRDLHandler.update_designation(dl_designation) response = Response(success=True) return response except DataLayerError as dle: response = Response(success=False, error=ExceptionHandler(**dle.__dict__)) return response if "designation" in request.manager.lower( ) and "remove" in request.action.lower(): try: code = Wrapper.from_json(request.json_string) HRDLHandler.delete_designation(code) response = Response(success=True) return response except DataLayerError as dle: response = Response(success=False, error=ExceptionHandler(**dle.__dict__)) return response if "employee" in request.manager.lower() and "all" in request.action.lower( ): try: employees = HRDLHandler.get_employees() response = Response(success=True, result_obj=ListHandler(employees)) return response except DataLayerError as dle: response = Response(success=False, error=ExceptionHandler(**dle.__dict__)) return response if "employee" in request.manager.lower( ) and "name" in request.action.lower(): try: name = json.loads(request.json_string) employees = HRDLHandler.get_employee_by_name(name) if len(employees) == 0: raise DataLayerError( message=f"No Employee with the name : {name}") response = Response(success=True, result_obj=ListHandler(employees)) return response except DataLayerError as dle: response = Response(success=False, error=ExceptionHandler(**dle.__dict__)) return response if "designation" in request.manager.lower( ) and "all" in request.action.lower(): try: designations = HRDLHandler.get_designations() response = Response(success=True, result_obj=ListHandler(designations)) return response except DataLayerError as dle: response = Response(success=False, error=ExceptionHandler(**dle.__dict__)) return response if "designation" in request.manager.lower( ) and "code" in request.action.lower(): try: code = Wrapper.from_json(request.json_string) dldesignation = HRDLHandler.get_designation_by_code(code) designation = Designation(code=dldesignation.code, title=dldesignation.title) response = Response(success=True, result_obj=designation) return response except DataLayerError as dle: response = Response(success=False, error=ExceptionHandler(**dle.__dict__)) return response if "designation" in request.manager.lower( ) and "title" in request.action.lower(): try: title = json.loads(request.json_string) dldesignation = HRDLHandler.get_designation_by_title(title) designation = Designation(code=dldesignation.code, title=dldesignation.title) response = Response(success=True, result_obj=designation) return response except DataLayerError as dle: response = Response(success=False, error=ExceptionHandler(**dle.__dict__)) return response
from all_common.hr import Designation from network_common.wrappers import Request d1 = Designation(10, "Carpenter") d1._validate_values() r1 = Request("Designation Master", "add", d1) jstr = r1.to_json() print(jstr) print("*" * 30) r2 = Request.from_json(jstr) print("Manager :", r2.manager) print("Action :", r2.action) print("JSON String :", r2.json_string) print("*" * 30) d2 = Designation.from_json(r2.json_string) print("Code :", d2.code) print("Title :", d2.title) print("Exceptions :", d2.exceptions) print("Has Exceptions :", d2.has_exceptions)