예제 #1
0
 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)
예제 #2
0
 def search_employee_by_id(self):
     """
     Retrieves the desired employee data by taking employee id
     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.
     """
     try:
         emp_id = int(input("Enter the Employee ID : "))
         request = Request(manager="EmployeeManager",
                           action="get_by_id",
                           request_object=Wrapper(emp_id))
         network_client = NetworkClient()
         response = network_client.send(request)
         if response.success:
             employee = Employee.from_json(response.result_json)
             print(
                 f"ID : {employee.emp_id} Name : {employee.name}, Designation : {employee.designation_code}, Gender : {employee.gender}"
             )
         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(f"ID is of unexpected type, it should be of type {type(0)}")
     print("-" * 50)
예제 #3
0
 def search_by_name(self):
     """
     Retrieves all the desired employees' data by taking employee's name
     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.
     """
     try:
         name = input("Enter the Name of the Employee : ")
         request = Request(manager="EmployeeManager",
                           action="get_by_name",
                           request_object=Wrapper(name))
         network_client = NetworkClient()
         response = network_client.send(request)
         if response.success:
             employees = ListHandler.from_json(response.result_json)
             for employee in employees:
                 print(
                     f"ID : {employee.emp_id} Name : {employee.name}, Designation : {employee.designation_code}, Gender : {employee.gender}"
                 )
         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 for Name!!")
     print("-" * 50)
예제 #4
0
 def get_all_designations(self):
     """
     Retrieves all the available designation entries and displays them.
     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
     in the form of a list.
     """
     request = Request(manager="DesignationManager", action="getall")
     network_client = NetworkClient()
     response = network_client.send(request)
     if response.success:
         designations = ListHandler.from_json(response.result_json)
         for designation in designations:
             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)
예제 #5
0
 def get_all_employees(self):
     """
     Retrieves all the available employee entries and displays them.
     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
     in the form of a list.
     """
     request = Request(manager="EmployeeManager", action="getall")
     network_client = NetworkClient()
     response = network_client.send(request)
     if response.success:
         employees = ListHandler.from_json(response.result_json)
         for employee in employees:
             print(
                 f"ID : {employee.emp_id} Name : {employee.name}, Designation : {employee.designation_code}, Gender : {employee.gender}"
             )
     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)
예제 #6
0
 def remove_employee(self):
     """
     deletes one of the existing employee data in the Employee Table
     by taking the employee ID as input at runtime,
     and sending it via a Wrapper class object to the request 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:
         emp_id = int(input("Enter the Employee ID : "))
         request = Request(manager="EmployeeManager",
                           action="remove",
                           request_object=Wrapper(emp_id))
         network_client = NetworkClient()
         response = network_client.send(request)
         if response.success:
             print("Employee Deleted")
         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(
             f"employee id is of unexpected type, it should be of type {type(0)}"
         )
     print("-" * 50)
예제 #7
0
 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)
예제 #8
0
 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)
예제 #9
0
 def add_employee(self):
     """
     adds a new employee's data to the Employee Table
     by taking the employee's required data as input at runtime
     and creating an Employee 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:
         name = None
         designation_code = None
         date = None
         month = None
         year = None
         salary = None
         gender = None
         indian = None
         pan_no = None
         aadhar = None
         name = input("Enter Name of the Employee : ")
         designation_code = int(
             input("Enter the Designation Number of the Employee : "))
         date = int(input("Enter the Date : "))
         month = int(input("Enter the Month : "))
         year = int(input("Enter the Year : "))
         salary = float(input("Enter the Salary of the Employee : "))
         gender = input("Enter the Gender of the Employee : ")
         indian = int(input("Enter 1 for Indian otherwise enter 0 : "))
         pan_no = input("Enter the PAN Number of the employee : ")
         aadhar = input("Enter the Aadhar Number of the employee : ")
         employee = Employee(0, name, designation_code, date, month, year,
                             salary, gender, indian, pan_no, aadhar)
         request = Request(manager="EmployeeManager",
                           action="add",
                           request_object=employee)
         network_client = NetworkClient()
         response = network_client.send(request)
         if response.success:
             print("Employee 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])
     except:
         print(
             f"Invalid entry type for fields of employee information form!")
     print("-" * 50)
예제 #10
0
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