示例#1
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)
示例#2
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)
示例#3
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)
示例#4
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)
示例#5
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)
示例#6
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)
示例#7
0
 def run(self):
     """
     This function executes the client requests in multithreaded fashion.
     Controls the transfer of bytes between client and server.
     First, the length of the request is received which in turn
     is used to receive the request data.
     This request data is passed to the requestHandler function
     and we obtain the response.
     This response is then further forwarded to the respective client
     in the same manager as the request was received by the server
     from the client.
     """
     databytes = b""
     to_recieve = 1024
     while len(databytes) < to_recieve:
         bytes_read = self.obj.client_socket.recv(to_recieve -
                                                  len(databytes))
         databytes += bytes_read
     request_data_length = int(databytes.decode("utf-8").strip())
     databytes = b""
     to_recieve = request_data_length
     while len(databytes) < to_recieve:
         bytes_read = self.obj.client_socket.recv(to_recieve -
                                                  len(databytes))
         databytes += bytes_read
     request_data = databytes.decode("utf-8")
     request = Request.from_json(request_data)
     response = self.obj.requestHandler(request)
     response_data = response.to_json()
     self.obj.client_socket.sendall(
         bytes(str(len(response_data)).ljust(1024), encoding="utf-8"))
     self.obj.client_socket.sendall(bytes(response_data, "utf-8"))
     self.obj.client_socket.close()
示例#8
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)
示例#9
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)
示例#10
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)
示例#11
0
 def add_designation(self):
     title = input("Enter 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:
         validationException = ValidationException.from_json(
             response.error_json_string)
         if validationException.message and len(
                 validationException.message) > 0:
             print(validationException.message)
         if validationException.exceptions:
             for exception in validationException.exceptions.values():
                 print(exception[1])
示例#12
0
 def delete_designation(self):
     code = int(input("Enter code to delete : "))
     designation = Designation(code, "aa")
     request = Request(manager="DesignationManager",
                       action="delete",
                       request_object=designation)
     network_client = NetworkClient()
     response = network_client.send(request)
     if response.success:
         print("Designation deleted")
     else:
         validationException = ValidationException.from_json(
             response.error_json_string)
         if validationException.message and len(
                 validationException.message) > 0:
             print(validationException.message)
         if validationException.exceptions:
             for exception in validationException.exceptions.values():
                 print(exception[1])
 def run(self):
     data_bytes = b''
     to_receive = 1024
     while len(data_bytes) < to_receive:
         bytes_read = self.client_socket.recv(to_receive - len(data_bytes))
         data_bytes += bytes_read
     request_data_length = int(data_bytes.decode("utf-8").strip())
     data_bytes = b''
     to_receive = request_data_length
     while len(data_bytes) < to_receive:
         bytes_read = self.client_socket.recv(to_receive - len(data_bytes))
         data_bytes += bytes_read
     request_data = data_bytes.decode("utf-8")
     request = Request.from_json(request_data)
     response = self.requestHandler(request)
     response_data = response.to_json()
     self.client_socket.sendall(
         bytes(str(len(response_data)).ljust(1024), 'utf-8'))
     self.client_socket.sendall(bytes(response_data, 'utf-8'))
     self.client_socket.close()
示例#14
0
 def get_all_designations(self):
     request = Request(manager="DesignationManager", action="getAll")
     network_client = NetworkClient()
     response = network_client.send(request)
     if response.success:
         designations = json.loads(response.result_json_string)
         designationsList = list(
             map(lambda obj: Designation(**obj), designations))
         for designation in designationsList:
             print(
                 f"Code : {designation.code}, Title : {designation.title}")
     else:
         validationException = ValidationException.from_json(
             response.error_json_string)
         if validationException.message and len(
                 validationException.message) > 0:
             print(validationException.message)
         if validationException.exceptions:
             for exception in validationException.exceptions.values():
                 print(exception[1])
示例#15
0
 def get_designation(self):
     code = int(input("Enter code to search : "))
     designation = Designation(code, "aa")
     request = Request(manager="DesignationManager",
                       action="search",
                       request_object=designation)
     network_client = NetworkClient()
     response = network_client.send(request)
     if response.success:
         designation = Designation.from_json(response.result_json_string)
         print(f"Code : {designation.code}, Title : {designation.title}")
     else:
         validationException = ValidationException.from_json(
             response.error_json_string)
         if validationException.message and len(
                 validationException.message) > 0:
             print(validationException.message)
         if validationException.exceptions:
             for exception in validationException.exceptions.values():
                 print(exception[1])
示例#16
0
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)
from network_client.client import NetworkClient
from network_common.wrappers import Request, Response
client = NetworkClient()
request = Request("DesignationManager", "getAll")
response = client.send(request)
from common.hr import Designation
from network_common.wrappers import Request
r1 = Request("DesignationManager", "getAllDesignations")
str = r1.to_json()
print(str)
print("*" * 25)
r2 = Request.from_json(str)
print("Manager : ", r2.manager)
print("Action : ", r2.action)
print("JSON String : ", r2.json_string)
print("*" * 25)
示例#19
0
from common.hr import Designation
from network_common.wrappers import Request, Wrapper
r1 = Request("DesignationManager", "getDesignationByCode", Wrapper(10))
str = r1.to_json()
print(str)
print("*" * 25)
r2 = Request.from_json(str)
print("Manager : ", r2.manager)
print("Action : ", r2.action)
print("JSON String : ", r2.json_string)
print("*" * 25)
value = Wrapper.from_json(r2.json_string)
print(value, type(value))
示例#20
0
文件: test7.py 项目: SarthKale/HR-App
from network_client.client import NetworkClient
from network_common.wrappers import Request

client = NetworkClient()
request = Request("DesignationMaster", "getAll")
response = client.send(request)
示例#21
0
from common.hr import Designation
from network_common.wrappers import Request
d1 = Designation(10, "Carpenter")
d1._validate_values()
r1 = Request("DesignationManager", "add", d1)
str = r1.to_json()
print(str)
print("*" * 25)
r2 = Request.from_json(str)
print("Manager : ", r2.manager)
print("Action : ", r2.action)
print("JSON String : ", r2.json_string)
print("*" * 25)
d2 = Designation.from_json(r2.json_string)
print(d2)
print("Code : ", d2.code)
print("Title : ", d2.title)
print("Exceptions : ", d2.exceptions)
print("Has exception : ", d2.has_exceptions)