}
} else {
String prevDepartmentId = null;
//set employment detail
Employment employment = null;
if ("create".equals(action)) {
employment = new Employment();
} else {
try {
employment = (Employment) userDao.getUserById(user.getId()).getEmployments().iterator().next();
} catch (Exception e) {
employment = new Employment();
}
}
prevDepartmentId = employment.getDepartmentId();
employment.setUserId(user.getId());
employment.setEmployeeCode(employeeCode);
employment.setRole(employeeRole);
employment.setOrganizationId((employeeOrganization != null && !employeeOrganization.isEmpty()) ? employeeOrganization : null);
employment.setDepartmentId((employeeDepartment != null && !employeeDepartment.isEmpty()) ? employeeDepartment : null);
employment.setGradeId((employeeGrade != null && !employeeGrade.isEmpty()) ? employeeGrade : null);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
try {
if (employeeStartDate != null && employeeStartDate.trim().length() > 0) {
employment.setStartDate(df.parse(employeeStartDate));
} else {
employment.setStartDate(null);
}
if (employeeEndDate != null && employeeEndDate.trim().length() > 0) {
employment.setEndDate(df.parse(employeeEndDate));
} else {
employment.setEndDate(null);
}
} catch (Exception e) {
LogUtil.error(getClass().getName(), e, "Set Employee Date error");
}
if (employment.getId() == null) {
employment.setUser(user);
employmentDao.addEmployment(employment);
} else {
employmentDao.updateEmployment(employment);
}