Java tutorial
package com.abm.mainet.common.service; import java.io.File; import java.io.Serializable; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.Set; import javax.annotation.Resource; import org.apache.commons.io.FileUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.abm.mainet.authentication.ldap.ILDAPManager; import com.abm.mainet.authentication.ldap.UserProfile; import com.abm.mainet.common.constant.MainetConstants; import com.abm.mainet.common.dto.EmployeeDTO; import com.abm.mainet.common.dto.EmployeeSearchDTO; import com.abm.mainet.common.integration.dms.client.FileNetApplicationClient; import com.abm.mainet.common.integration.dms.fileUpload.FileUploadUtility; import com.abm.mainet.common.master.dao.IEmployeeDAO; import com.abm.mainet.common.master.domain.Department; import com.abm.mainet.common.master.domain.Designation; import com.abm.mainet.common.master.domain.Employee; import com.abm.mainet.common.master.domain.GroupMaster; import com.abm.mainet.common.master.domain.LocationMasEntity; import com.abm.mainet.common.master.domain.Organisation; import com.abm.mainet.common.master.dto.EmployeeBean; import com.abm.mainet.common.master.mapper.EmployeeServiceMapper; import com.abm.mainet.common.master.repository.EmployeeJpaRepository; import com.abm.mainet.common.utility.ApplicationSession; import com.abm.mainet.common.utility.LookUp; import com.abm.mainet.common.utility.UserSession; import com.abm.mainet.common.utility.Utility; @Service public class EmployeeService implements IEmployeeService, Serializable { private static final long serialVersionUID = 1L; @Autowired @Qualifier("ldapManager") private ILDAPManager ldapManager; @Autowired private IEmployeeDAO employeeDAO; @Resource private EmployeeServiceMapper employeeServiceMapper; @Resource private EmployeeJpaRepository employeeJpaRepository; @Override @Transactional public EmployeeDTO getEmployeeById(Long empId, Organisation organisation, String isdeleted) { EmployeeDTO employeeDTO = new EmployeeDTO(); Employee emp = employeeDAO.getEmployeeById(empId, organisation, isdeleted); employeeDTO = employeeServiceMapper.mapEmployeeTOEmployeeDTO(emp); employeeDTO.setDesignationId(emp.getDesignation().getDsgid()); /* employeeDTO.setDpDeptid(emp.getTbDepartment().getDpDeptid()); */ employeeDTO.setLocaDeptId(emp.getTbLocationMas().getLocId()); employeeDTO.setTitle(emp.getCpdTtlId()); employeeDTO.setUpdatedDate(new Date()); employeeDTO.setUpdatedBy(emp.getEmpId()); // employeeDTO.setUserId(emp.getUserId()); return employeeDTO; } @Override @Transactional public Employee getAuthenticatedEmployee(String emploginname, String emppassword, Long emplType, Organisation organisation, String isdeleted) { return employeeDAO.getAuthenticatedEmployee(emploginname, Utility.encryptPassword(emploginname, emppassword), emplType, organisation, isdeleted); } @Override @Transactional public List<Employee> getEmployeeByEmpEMailAndType(String empEMail, Long empType, Organisation organisation, String isDeleted, boolean isAgency) { return employeeDAO.getEmployeeByEmailIdAndEmpType(empEMail, empType, organisation, isDeleted, isAgency); } @Override @Transactional public List<Employee> getEmployeeByEmpMobileNo(String empMobileNo, Organisation organisation, String isDeleted) { return employeeDAO.getEmployeeByEmpMobileNo(empMobileNo, organisation, isDeleted); } @Override @Transactional public List<Employee> getEmployeeByEmpMobileNoAndType(String empMobileNo, Long empType, Organisation organisation, String isDeleted, boolean isAgency) { List<Employee> employeeList = employeeDAO.getEmployeeByEmpMobileNoAndEmpType(empMobileNo, empType, organisation, isDeleted, isAgency); return employeeList; } @Override @Transactional public Employee saveEmployeeDetails(Employee newEmployee, Organisation organisation, LocationMasEntity departmentLocation, Designation designation, Department department, Employee userId) { this.setEmployeeCreateParams(newEmployee, organisation, departmentLocation, designation, department, userId); Employee savedEmployee = employeeDAO.saveEmployee(newEmployee); UserProfile uProfile = new UserProfile(); uProfile.setFirstName(savedEmployee.getEmpname()); uProfile.setLastName(savedEmployee.getEmplname()); uProfile.setPwd(savedEmployee.getEmppassword()); uProfile.setRole(savedEmployee.getGmid().toString()); uProfile.setuID(savedEmployee.getEmploginname()); uProfile.setUserType("D"); ldapManager.updateUser(uProfile); return savedEmployee; } @Override @Transactional public Employee updateEmployeeDetails(Employee updateEmployee, Employee userId) { this.setEmployeeUpdateParams(updateEmployee, userId); Employee employeeUpdated = employeeDAO.saveEmployee(updateEmployee); UserProfile uProfile = new UserProfile(); uProfile.setFirstName(employeeUpdated.getEmpname()); uProfile.setLastName(employeeUpdated.getEmplname()); uProfile.setPwd(employeeUpdated.getEmppassword()); uProfile.setRole(employeeUpdated.getGmid().toString()); uProfile.setuID(employeeUpdated.getEmploginname()); uProfile.setUserType("D"); ldapManager.updateUser(uProfile); return employeeUpdated; } @Override @Transactional public Employee updateEmployeePassword(Employee updateEmployee, String newPassword, Employee userId) { /* * if(updateEmployee.getAutMob().equals("N")){ * updateEmployee.setAutMob(MainetConstants.IsDeleted.DELETE); } */ this.setEmployeeUpdateParams(updateEmployee, userId); updateEmployee.setEmppassword(Utility.encryptPassword(updateEmployee.getEmploginname(), newPassword)); Employee employeeUpdated = employeeDAO.saveEmployee(updateEmployee); UserProfile uProfile = new UserProfile(); uProfile.setFirstName(employeeUpdated.getEmpname()); uProfile.setLastName(employeeUpdated.getEmplname()); uProfile.setPwd(employeeUpdated.getEmppassword()); uProfile.setRole(employeeUpdated.getGmid().toString()); uProfile.setuID(employeeUpdated.getEmploginname()); uProfile.setUserType("D"); ldapManager.updateUser(uProfile); return employeeUpdated; } @Override @Transactional public Employee setEmployeePassword(Employee updateEmployee, String newPassword, Employee userId) { if (updateEmployee.getAutMob().equals("N")) { updateEmployee.setAutMob(MainetConstants.IsDeleted.DELETE); } this.setEmployeeUpdateParams(updateEmployee, userId); updateEmployee.setEmppassword(Utility.encryptPassword(updateEmployee.getEmploginname(), newPassword)); Employee employeeUpdated = employeeDAO.saveEmployee(updateEmployee); UserProfile uProfile = new UserProfile(); uProfile.setFirstName(employeeUpdated.getEmpname()); uProfile.setLastName(employeeUpdated.getEmplname()); uProfile.setPwd(employeeUpdated.getEmppassword()); uProfile.setRole(employeeUpdated.getGmid().toString()); uProfile.setuID(employeeUpdated.getEmploginname()); uProfile.setUserType("D"); ldapManager.updateUser(uProfile); return employeeUpdated; } /** * @Method private method to set {@link Employee} creation time parameter. * @param newEmployee * {@link Employee} * @param organisation * {@link Organisation} * @param departmentLocation * {@link DepartmentLocation} * @param designation * {@link Designation} * @param department * {@link Department} * @param userId * {@link Employee} */ private void setEmployeeCreateParams(Employee newEmployee, Organisation organisation, LocationMasEntity departmentLocation, Designation designation, Department department, Employee userId) { DateFormat getTime = new SimpleDateFormat("hh:mm aa"); Date date = new Date(); newEmployee.setOrganisation(organisation); // newEmployee.setOndate(date); // newEmployee.setOntime(getTime.format(date)); newEmployee.setIsDeleted(MainetConstants.IsDeleted.ZERO); // Default_value_is_"N" // newEmployee.setAutEmail(MainetConstants.IsDeleted.NOT_DELETE);// // Default_value_is_"N" if (UserSession.getCurrent().getAapleTrackId() != null && !UserSession.getCurrent().getAapleTrackId().isEmpty()) { newEmployee.setAutMob(MainetConstants.IsDeleted.DELETE); newEmployee.setEmppassword(newEmployee.getEmppassword()); } else { newEmployee.setAutMob(MainetConstants.IsDeleted.NOT_DELETE); newEmployee.setEmppassword( Utility.encryptPassword(newEmployee.getEmploginname(), newEmployee.getEmppassword())); } newEmployee.setTbLocationMas(departmentLocation); newEmployee.setDesignation(designation); newEmployee.setTbDepartment(department); newEmployee.setUserId(userId.getEmpId()); newEmployee.setLangId(UserSession.getCurrent().getLanguageId()); newEmployee.setIsuploaded(MainetConstants.IsUploaded.NOT_UPLOADED); } /** * @Method private method to set {@link Employee} update time parameter. * @param newEmployee * {@link Employee} * @param userId * {@link Employee} */ private void setEmployeeUpdateParams(Employee updateEmployee, Employee userId) { // DateFormat getTime = new SimpleDateFormat("hh:mm aa"); Date date = new Date(); updateEmployee.setUpdatedDate(date); updateEmployee.setUpdatedBy(userId.getUserId()); updateEmployee.setLangId(UserSession.getCurrent().getLanguageId()); /* * if(updateEmployee.getAutMob().equals("Y")){ * updateEmployee.setAutMob("N"); }else{ * updateEmployee.setAutMob(MainetConstants.IsDeleted.DELETE); } */ } @Override @Transactional public Employee getEmployeeByLoginName(String emploginname, Organisation organisation, String isDeleted) { return employeeDAO.getEmployeeByLoginName(emploginname, organisation, isDeleted); } @Override @Transactional public List<Employee> getEmployeeListByLoginName(String emploginname, Organisation organisation, String isDeleted) { return employeeDAO.getEmployeeListByLoginName(emploginname, organisation, isDeleted); } @Override @Transactional public List<Employee> getAllListEmployeeByDeptId(Organisation org, long DeptId) { return employeeDAO.getAllEmployeeByDeptId(org, DeptId); } @Override @Transactional public Employee saveEmployee(Employee employee) { return employeeDAO.saveEmployee(employee); } @Override @Transactional public List<Employee> getAllAgencyList() { return employeeDAO.getAllAgencyList(UserSession.getCurrent().getOrganisation()); } @Override @Transactional public List<EmployeeDTO> getEmployeeByAgencyTypeAndBySortOption(Long agencyType, String agencyName, String sortValue, Long orgId) { return employeeDAO.getEmployeeByAgencyTypeAndBySortOption(agencyType, agencyName, sortValue, orgId); } @Override @Transactional public Employee getAgencyByEmplTypeAndEmail(String email, Long agencyType, Organisation organisation, String isDeleted) { return employeeDAO.getAgencyByEmplTypeAndEmail(email, agencyType, organisation, isDeleted); } @Override @Transactional public void saveEditProfileInfo(Employee modifiedEmployee) { // modifiedEmployee.updateAuditFields(); employeeDAO.persistModifiedCitizenInfo(modifiedEmployee); UserProfile uProfile = new UserProfile(); uProfile.setFirstName(modifiedEmployee.getEmpname()); uProfile.setLastName(modifiedEmployee.getEmplname()); uProfile.setPwd(modifiedEmployee.getEmppassword()); uProfile.setRole(modifiedEmployee.getGmid().toString()); uProfile.setuID(modifiedEmployee.getEmploginname()); uProfile.setUserType("D"); ldapManager.updateUser(uProfile); } @Override @Transactional public void setEmployeeLoggedInFlag(Employee currentLoggedInEmployee) { currentLoggedInEmployee.setLoggedIn("Y"); // currentLoggedInEmployee.setLastLoggedIn(new Date()); employeeDAO.setEmployeeLoggedInFlag(currentLoggedInEmployee); } @Override @Transactional public void resetEmployeeLoggedInFlag(Employee loggingOutEmployee) { employeeDAO.resetEmployeeLoggedInFlag(MainetConstants.IsLookUp.STATUS.NO, loggingOutEmployee.getEmpId()); } @Transactional @Override public List<EmployeeSearchDTO> getAllEmployeeInfoByOrgID(String empName) { return employeeDAO.findEmployeeInfo(empName, UserSession.getCurrent().getOrganisation()); } @Override public Employee saveEmployeeForAgency(Employee employee) { // TODO Auto-generated method stub return employeeDAO.saveEmployeeForAgency(employee); } public List<LookUp> getAllEmployee(List<Object[]> emp) { List<LookUp> list = new ArrayList<LookUp>(0); ListIterator<Object[]> listIterator = emp.listIterator(); while (listIterator.hasNext()) { Object[] obj = listIterator.next(); LookUp title = getEmpTitle(obj); String fname = (String) obj[1]; String lname = " "; if (obj[2] != null) { lname = (String) obj[2]; } String fullName = " "; if (title.getLookUpDesc() != null) { fullName = title.getLookUpDesc() + " " + fname + " " + lname; } else { fullName = " " + fname + " " + lname; } // fullName = fname + " " + lname; LookUp lookUp = new LookUp("", fullName); lookUp.setLookUpId((long) obj[4]); list.add(lookUp); } return list; } private LookUp getEmpTitle(Object[] obj) { return ApplicationSession.getInstance() .getNonHierarchicalLookUp(UserSession.getCurrent().getOrganisation().getOrgid(), (Long) obj[0]); } @Override public Map<Long, String> getEmployeeLookUp() { // TODO Auto-generated method stub return employeeDAO.getEmployeeLookUp(UserSession.getCurrent().getOrganisation()); } @Override @Transactional(readOnly = true) public Employee getAdminEncryptAuthenticatedEmployee(String emploginname, String emppassword, Long emplType, Long empId, Organisation organisation, String isdeleted) { return employeeDAO.getAdminAuthenticatedEmployee(emploginname, emppassword, emplType, empId, organisation, isdeleted); } @Override @Transactional(readOnly = true) public Employee getAuthenticatedEncryptEmployee(String emploginname, String emppassword, Long emplType, Organisation organisation, String isdeleted) { return employeeDAO.getAuthenticatedEmployee(emploginname, emppassword, emplType, organisation, isdeleted); } @Override public void setTpLicenseDataFromAuthorizer(Employee entity) { if (entity.getAuthStatus() != null && entity.getAuthStatus().equals(MainetConstants.AuthStatus.APPROVED)) { employeeDAO.generateLicenseData(entity); } } @Override @Transactional(readOnly = true) public int getCountOfGroup(Long gmId, Long orgId, String isDeleted) { return employeeDAO.getCountOfGroup(gmId, orgId, isDeleted); } @Override public EmployeeBean findById(Long empId) { Employee employeeEntity = employeeJpaRepository.findOne(empId); return employeeServiceMapper.mapEmployeeEntityToEmployee(employeeEntity); } @Override public List<EmployeeBean> findAll() { Iterable<Employee> entities = employeeJpaRepository.findAll(); List<EmployeeBean> beans = new ArrayList<EmployeeBean>(); for (Employee employeeEntity : entities) { beans.add(employeeServiceMapper.mapEmployeeEntityToEmployee(employeeEntity)); } return beans; } @Override @Transactional public EmployeeBean create(EmployeeBean employee, String directory, FileNetApplicationClient fileNetApplicationClient) { Employee employeeEntity = new Employee(); employee.setLangId(Long.valueOf(UserSession.getCurrent().getLanguageId())); employee.setLmoddate(new Date()); employee.setOrgid(Long.valueOf(UserSession.getCurrent().getOrganisation().getOrgid())); employee.setUserId(Long.valueOf(UserSession.getCurrent().getEmployee().getEmpId())); employee.setLgIpMac(Utility.getMacAddress()); employee.setIsdeleted("0"); employee.setIsuploaded("Y"); employee.setAutMob("Y"); employee.setAutEmail("Y"); employee.setAuthStatus("A"); employee.setEmppassword(Utility.encryptPassword(employee.getEmploginname(), employee.getNewPassword())); //String days=CommonMasterUtility.getCPDValue("PED"); Calendar now = Calendar.getInstance(); //if(days!=null) now.add(Calendar.DATE, 1); Date date = now.getTime(); employee.setEmpexpiredt(date); List<File> list = null; for (Map.Entry<Long, Set<File>> entry : FileUploadUtility.getCurrent().getFileMap().entrySet()) { list = new ArrayList<File>(entry.getValue()); Iterator<File> setFilesItr = entry.getValue().iterator(); String tempDirPath = MainetConstants.operator.EMPTY; while (setFilesItr.hasNext()) { File file = setFilesItr.next(); tempDirPath = directory + MainetConstants.FILE_PATH_SEPARATOR + entry.getKey().toString(); //tpProgressPhotoUploadDetail.setPudCaption(uploadDoc.get(Integer.parseInt(entry.getKey().toString())).getPudCaption()); if (entry.getKey().longValue() == 0) { employee.setEmpphotoPath(tempDirPath + MainetConstants.FILE_PATH_SEPARATOR + file.getName()); } if (entry.getKey().longValue() == 1) { employee.setScansignature(tempDirPath + MainetConstants.FILE_PATH_SEPARATOR + file.getName()); } if (entry.getKey().longValue() == 2) { employee.setEmpuiddocPath(tempDirPath); employee.setEmpUidDocName(file.getName()); } try { fileNetApplicationClient.uploadFileList(list, tempDirPath); } catch (Exception e) { e.printStackTrace(); return employee; } } } employeeServiceMapper.mapEmployeeToEmployeeEntity(employee, employeeEntity); employeeEntity.setLmodDate(new Date()); employeeEntity.setIsDeleted("0"); employeeEntity.setEmpphotopath(employee.getEmpphotoPath()); employeeEntity.setEmpuiddocpath(employee.getEmpuiddocPath()); Employee employeeEntitySaved = employeeJpaRepository.save(employeeEntity); flushServerFolder(); EmployeeBean empBean = employeeServiceMapper.mapEmployeeEntityToEmployee(employeeEntitySaved); UserProfile uProfile = new UserProfile(); uProfile.setFirstName(empBean.getEmpname()); uProfile.setLastName(empBean.getEmplname()); uProfile.setPwd(empBean.getEmppassword()); uProfile.setRole(empBean.getGmid().toString()); uProfile.setuID(empBean.getEmploginname()); uProfile.setUserType("D"); ldapManager.createUser(uProfile); return empBean; } @Override @Transactional public EmployeeBean update(EmployeeBean employee) { Employee employeeEntity = employeeJpaRepository.findOne(employee.getEmpId()); employeeServiceMapper.mapEmployeeToEmployeeEntity(employee, employeeEntity); Employee employeeEntitySaved = employeeJpaRepository.save(employeeEntity); EmployeeBean empBean = employeeServiceMapper.mapEmployeeEntityToEmployee(employeeEntitySaved); UserProfile uProfile = new UserProfile(); uProfile.setFirstName(empBean.getEmpname()); uProfile.setLastName(empBean.getEmplname()); uProfile.setPwd(empBean.getEmppassword()); uProfile.setRole(empBean.getGmid().toString()); uProfile.setuID(empBean.getEmploginname()); uProfile.setUserType("D"); ldapManager.updateUser(uProfile); return empBean; } public EmployeeJpaRepository getEmployeeJpaRepository() { return employeeJpaRepository; } public void setEmployeeJpaRepository(EmployeeJpaRepository employeeJpaRepository) { this.employeeJpaRepository = employeeJpaRepository; } public EmployeeServiceMapper getEmployeeServiceMapper() { return employeeServiceMapper; } public void setEmployeeServiceMapper(EmployeeServiceMapper employeeServiceMapper) { this.employeeServiceMapper = employeeServiceMapper; } @Override public List<EmployeeBean> getEmployeeData(Long deptId, Long locId, Long designId, Long orgid) { List<Employee> employeeEntity = null; if (locId != null && designId != null) { employeeEntity = employeeJpaRepository.findEmployeeData(deptId, locId, designId, orgid); } else if (locId == null && designId == null) { employeeEntity = employeeJpaRepository.findEmployeeData(deptId, orgid); } else if (locId == null && designId != null) { employeeEntity = employeeJpaRepository.findEmployeeDatabyDesign(deptId, designId, orgid); } else if (locId != null && designId == null) { employeeEntity = employeeJpaRepository.findEmployeeDataByLocID(deptId, locId, orgid); } List<EmployeeBean> beans = new ArrayList<EmployeeBean>(); for (Employee empEntity : employeeEntity) { beans.add(employeeServiceMapper.mapEmployeeEntityToEmployee(empEntity)); } return beans; } @Override @Transactional public EmployeeBean updateEmployee(EmployeeBean employee, String directry, FileNetApplicationClient filenetClient) { Employee employeeEntity = employeeJpaRepository.findOne(employee.getEmpId()); List<File> list = null; if (FileUploadUtility.getCurrent().getFileMap().entrySet() != null && !FileUploadUtility.getCurrent().getFileMap().entrySet().isEmpty()) { for (Map.Entry<Long, Set<File>> entry : FileUploadUtility.getCurrent().getFileMap().entrySet()) { list = new ArrayList<File>(entry.getValue()); Iterator<File> setFilesItr = entry.getValue().iterator(); String tempDirPath = MainetConstants.operator.EMPTY; while (setFilesItr.hasNext()) { File file = setFilesItr.next(); tempDirPath = directry + MainetConstants.FILE_PATH_SEPARATOR + employee.getEmpId().toString() + MainetConstants.FILE_PATH_SEPARATOR + entry.getKey().toString(); // tpProgressPhotoUploadDetail.setPudCaption(uploadDoc.get(Integer.parseInt(entry.getKey().toString())).getPudCaption()); if (entry.getKey().longValue() == 0 && file != null) { employee.setEmpphotoPath( tempDirPath + MainetConstants.FILE_PATH_SEPARATOR + file.getName()); } else { employee.setEmpphotoPath(employeeEntity.getEmpphotopath()); } if (entry.getKey().longValue() == 1 && file != null) { employee.setScansignature( tempDirPath + MainetConstants.FILE_PATH_SEPARATOR + file.getName()); } else { employee.setScansignature(employeeEntity.getScansignature()); } if (entry.getKey().longValue() == 2 && file != null) { employee.setEmpuiddocPath(tempDirPath); employee.setEmpUidDocName(file.getName()); } else { employee.setEmpuiddocPath(employeeEntity.getEmpuiddocpath()); employee.setEmpUidDocName(employeeEntity.getEmpuiddocname()); } try { filenetClient.uploadFileList(list, tempDirPath); } catch (Exception e) { e.printStackTrace(); return employee; } } } } else { employee.setEmpphotoPath(employeeEntity.getEmpphotopath()); employee.setScansignature(employeeEntity.getScansignature()); employee.setEmpuiddocPath(employeeEntity.getEmpuiddocpath()); employee.setEmpUidDocName(employeeEntity.getEmpuiddocname()); } flushServerFolder(); if (employeeEntity != null) { employee.setDsgid(employeeEntity.getDesignation().getDsgid()); employee.setDpDeptid(Long.valueOf(employeeEntity.getTbDepartment().getDpDeptid())); employee.setDepid(employeeEntity.getTbLocationMas().getLocId()); employee.setEmpisecuritykey(employeeEntity.getEmpisecuritykey()); // employee.setEmployeeNo(employeeEntity.getEmployeeNo()); employee.setAddFlag(employeeEntity.getAddFlag()); // employee.setAgencyLocation(employeeEntity.getAgencyLocation()); // employee.setAgencyName(employeeEntity.getAgencyName()); // employee.setAgencyNoofExp(employeeEntity.getAgencyNoofExp()); // employee.setAgQualification(employeeEntity.getAgQualification()); employee.setAutBy(employeeEntity.getAutBy()); // employee.setAgRegNo(employeeEntity.getAgRegNo()); employee.setAutDate(employeeEntity.getAutDate()); // employee.setAutEmail(employeeEntity.getAutEmail()); employee.setAuthStatus(employeeEntity.getAuthStatus()); employee.setAutMob(employeeEntity.getAutMob()); employee.setCentraleno(employeeEntity.getCentraleno()); employee.setEmplType(employeeEntity.getEmplType()); employee.setEmpCorAdd1(employeeEntity.getEmpCorAdd1()); employee.setEmpCorAdd2(employeeEntity.getEmpCorAdd2()); employee.setEmpCorPincode(employeeEntity.getEmpCorPincode()); employee.setEmppayrollnumber(employeeEntity.getEmppayrollnumber()); employee.setAddFlag(employeeEntity.getAddFlag()); employee.setEmpnew(employeeEntity.getEmpnew()); // employee.setLangId(employeeEntity.getLangId()); employee.setLmoddate(new Date()); employee.setOrgid(Long.valueOf(employeeEntity.getOrganisation().getOrgid())); // employee.setUserId(employeeEntity.getUserId()); employee.setUpdatedBy(Long.valueOf(UserSession.getCurrent().getEmployee().getEmpId())); employee.setUpdatedDate(new Date()); employee.setLgIpMac(employeeEntity.getLgIpMac()); employee.setLgIpMacUpd(Utility.getMacAddress()); // employee.setLastLoggedin(employeeEntity.getLastLoggedin()); employee.setIsdeleted("0"); employee.setIsuploaded(employeeEntity.getIsuploaded()); if (employee.getModeFlag().equals("Y") && employee.getUpdatelogin() != null && employee.getUpdatelogin().equals("Y")) { employee.setEmppassword( Utility.encryptPassword(employee.getEmploginname(), employee.getNewPassword())); } else { employee.setEmppassword(employeeEntity.getEmppassword()); } } employeeServiceMapper.mapEmployeeToEmployeeEntity(employee, employeeEntity); Employee employeeEntitySaved = employeeJpaRepository.save(employeeEntity); EmployeeBean empBean = employeeServiceMapper.mapEmployeeEntityToEmployee(employeeEntitySaved); UserProfile uProfile = new UserProfile(); uProfile.setFirstName(empBean.getEmpname()); uProfile.setLastName(empBean.getEmplname()); uProfile.setPwd(empBean.getEmppassword()); uProfile.setRole(empBean.getGmid().toString()); uProfile.setuID(empBean.getEmploginname()); uProfile.setUserType("D"); ldapManager.updateUser(uProfile); return empBean; } public void flushServerFolder() { try { String path = FileUploadUtility.getCurrent().getExistingFolderPath(); if (path != null) { File cacheFolderStructure = new File(FileUploadUtility.getCurrent().getExistingFolderPath()); FileUtils.deleteDirectory(cacheFolderStructure); } } catch (Throwable e) { e.printStackTrace(); } } @Override public void deleteEmployee(Long empid, Long orgId) { employeeJpaRepository.deleteEmployee(empid, orgId); } @Override public List<EmployeeBean> getRegisterdMobile(String empmobno, Long orgId) { List<Employee> employeeEntity = null; employeeEntity = employeeJpaRepository.getRegisterdMobile(empmobno, orgId); List<EmployeeBean> beans = new ArrayList<EmployeeBean>(); for (Employee empEntity : employeeEntity) { beans.add(employeeServiceMapper.mapEmployeeEntityToEmployee(empEntity)); } return beans; } @Override public List<EmployeeBean> getRegisterdEmail(String empemail, Long orgId) { List<Employee> employeeEntity = null; employeeEntity = employeeJpaRepository.getRegisterdEmail(empemail, orgId); List<EmployeeBean> beans = new ArrayList<EmployeeBean>(); for (Employee empEntity : employeeEntity) { beans.add(employeeServiceMapper.mapEmployeeEntityToEmployee(empEntity)); } return beans; } @Override public List<EmployeeBean> getRegisterdLoginName(String emploginname, Long orgId) { List<Employee> employeeEntity = null; employeeEntity = employeeJpaRepository.getRegisterdLoginName(emploginname, orgId); List<EmployeeBean> beans = new ArrayList<EmployeeBean>(); for (Employee empEntity : employeeEntity) { beans.add(employeeServiceMapper.mapEmployeeEntityToEmployee(empEntity)); } return beans; } /* * (non-Javadoc) * * @see * com.abm.mainetservice.web.masters.employee.business.service.EmployeeService * #getGroupList(long) */ @Override public Map<Long, String> getGroupList(long orgid) { List<GroupMaster> grpEntity = null; grpEntity = employeeJpaRepository.getGroupList(orgid); Map<Long, String> list = new LinkedHashMap<Long, String>(); if (grpEntity != null && !grpEntity.isEmpty()) { for (GroupMaster mas : grpEntity) { list.put(mas.getGmId(), mas.getGrCode()); } } return list; } @Override public List<GroupMaster> getGroupDataList(long orgid) { List<GroupMaster> grpEntity = employeeJpaRepository.getGroupList(orgid); return grpEntity; } @Override public List<EmployeeBean> getAllEmployee(Long orgId) { List<Employee> entities = employeeJpaRepository.getAllEmployee(orgId); List<EmployeeBean> beans = new ArrayList<EmployeeBean>(); for (Employee employeeEntity : entities) { beans.add(employeeServiceMapper.mapEmployeeEntityToEmployee(employeeEntity)); } return beans; } @Override public int validateEmployee(String emploginname, Long orgid) { int empCounter = 0; Long count = employeeJpaRepository.validateEmployee(emploginname, orgid); if (count != null) { empCounter = count.intValue(); } return empCounter; } @Override public List<Object[]> getAllEmployeeNames(Long orgId) { List<Object[]> entities = employeeJpaRepository.getAllEmployeeNames(orgId); return entities; } /* * (non-Javadoc) * * @see * com.abm.mainetservice.web.masters.employee.business.service.EmployeeService * #findAllEmpByDept(java.lang.Long, java.lang.Long) */ @Override @Transactional(readOnly = true) public List<Object[]> findAllEmpByDept(Long orgId, Long deptId) { List<Object[]> entities = employeeJpaRepository.findAllEmpByDept(orgId, deptId); return entities; } /*@Override @Transactional(readOnly = true) public List<Employee> findAllEmployeeByDept(Long orgId, Long deptId) { return employeeJpaRepository.findAllEmployeeByDept(orgId, deptId); } */ /* * (non-Javadoc) * * @see * com.abm.mainetservice.web.masters.employee.business.service.EmployeeService * #findAllEmployeeByLocation(com.abm.mainetservice.web.common.entity. * LocationMasEntity) */ @Override @Transactional(readOnly = true) public List<Employee> findAllEmployeeByLocation(Long locId) { return employeeJpaRepository.findAllEmployeeByLocation(locId); } @Override @Transactional(readOnly = true) public List<Object[]> getAllEmpByDesignation(Long desgId, Long orgId) { List<Object[]> empList = employeeJpaRepository.getAllEmpByDesignation(desgId, orgId); return empList; } @Override @Transactional(readOnly = true) public List<Employee> findAllEmployeeByDept(Long orgId, Long deptId) { return employeeJpaRepository.findAllEmployeeByDept(orgId, deptId); } @Override public LocationMasEntity findEmployeeLocation(String empName, Long orgId) { Employee employeeEntity = employeeJpaRepository.findEmployeeByName(empName, orgId); return employeeEntity.getTbLocationMas(); } @Override public List<EmployeeBean> getAllEmployeeWithLoggedInEmployeeNotPresent(Long orgId, Long empId) { List<Employee> entities = employeeJpaRepository.getAllEmployeeWithLoggedInEmployeeNotPresent(orgId, empId); List<EmployeeBean> beans = new ArrayList<EmployeeBean>(); for (Employee employeeEntity : entities) { beans.add(employeeServiceMapper.mapEmployeeEntityToEmployee(employeeEntity)); } return beans; } @Override @Transactional(readOnly = true) public List<Employee> getByGmId(Long gmId) { return (List<Employee>) employeeJpaRepository.getByGmId(gmId); } @Override public Employee findEmployeeById(Long empId) { Employee employeeEntity = employeeJpaRepository.findOne(empId); return employeeEntity; } @Override @Transactional(readOnly = true) public List<Object[]> findAllEmpByLocation(Long orgId, Long deptId, List<Long> locationId) { return employeeJpaRepository.findAllEmpByLocation(orgId, deptId, locationId); } @Override @Transactional(readOnly = true) public List<Object[]> findAllRoleByLocation(Long orgId, Long deptId, List<Long> locationId) { return employeeJpaRepository.findAllRoleByLocation(orgId, deptId, locationId); } }