@SuppressWarnings("unchecked")
	@RequestMapping(value = "/loginAuthentication", method = RequestMethod.POST)
	public ModelAndView loginAuthentication(HttpServletRequest req,ModelAndView model) throws IOException {
		// Create the Object for EmployeeBeanClass
		//EmployeeBeanClass employee = EmployeeBeanClass.getInstance();
		PersistenceManager pm = PMF.get().getPersistenceManager();
		HttpSession session = req.getSession();
		// Getting the input from the front end and assign into local variable..
		String emailId = req.getParameter("EmailId");
		String password = req.getParameter("Password");

		// It is used to check the Login status
		int loginState = 0;
		try {
			// Query filter is used to filter the particular field with
			// value
			Query query = pm.newQuery(EmployeeBeanClass.class);
			query.setFilter("employeeEmailId =='" + emailId + "' ");
			
			// using the List to get the entries from the data store
			List<EmployeeBeanClass> employees = (List<EmployeeBeanClass>) query
					.execute();
			EmployeeBeanClass employeeLogin = employees.get(0);		
			if (employeeLogin.getPassword().equals(password)) {			
				// Creating the session and setting the employee details
				// into the session variables				
				session.setAttribute("EmployeeName",
						employeeLogin.getEmployeeName());
				session.setAttribute("EmployeeId",
						employeeLogin.getEmployeeId());
				session.setAttribute("EmployeeDoj",
						employeeLogin.getEmployeeDoj());
				session.setAttribute("EmailId",
						employeeLogin.getEmployeeEmailId());
				session.setAttribute("MobileNo", employeeLogin.getMobileNo());
				session.setAttribute("CompanyName","Adaptavant Technologies Pvt Ltd.");
				session.setAttribute("Team", employeeLogin.getTeam());
				session.setAttribute("role", employeeLogin.getRole());

				Query teamLeader = pm.newQuery(EmployeeBeanClass.class);
				query.setFilter(" team == '" + employeeLogin.getTeam() + "' ");
						
				List<EmployeeBeanClass> tlName = (List<EmployeeBeanClass>) teamLeader.execute();
				for(EmployeeBeanClass teamLead :tlName){
					if(teamLead.getRole().equals("TeamLeader")){
						session.setAttribute("TeamLead", teamLead.getEmployeeEmailId());
				
					}
				}	

				loginState = 1;

			} 			
			 
			model.setViewName("LoginTemplate");

		} catch (Exception e) {
			// Incase of any failure in try block Error information stored in
			// logs
			log.info("Login Failed Because of : " + e);

		} finally {
			// Close the Persistence Manager
			pm.close();
		}
		if (loginState == 1) {
			return model;

		} else {
			return new ModelAndView("LoginPage", "model",
					"EmailId or Password Mismatch LoginFailed");
		}
	}