use of com.axelor.apps.hr.db.repo.EmployeeRepository in project axelor-open-suite by axelor.
the class UserHrController method createUser.
@Transactional
public void createUser(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
User user = context.asType(User.class);
EmployeeRepository employeeRepository = Beans.get(EmployeeRepository.class);
User employeeUser = new User();
employeeUser.setActivateOn(user.getActivateOn());
employeeUser.setExpiresOn(user.getExpiresOn());
employeeUser.setCode(user.getCode());
employeeUser.setGroup(user.getGroup());
if (context.containsKey("_id")) {
Object employeeId = context.get("_id");
if (employeeId != null) {
Employee employee = employeeRepository.find(Long.parseLong(employeeId.toString()));
employeeUser.setEmployee(employeeRepository.find(employee.getId()));
if (employee.getContactPartner() != null) {
String employeeName = employee.getContactPartner().getName();
if (employee.getContactPartner().getFirstName() != null) {
employeeName += " " + employee.getContactPartner().getFirstName();
}
employeeUser.setName(employeeName);
if (employee.getContactPartner().getEmailAddress() != null) {
employeeUser.setEmail(employee.getContactPartner().getEmailAddress().getAddress());
}
}
if (employee.getMainEmploymentContract() != null) {
employeeUser.setActiveCompany(employee.getMainEmploymentContract().getPayCompany());
}
List<EmploymentContract> contractList = employee.getEmploymentContractList();
if (contractList != null && !contractList.isEmpty()) {
for (EmploymentContract employmentContract : contractList) {
employeeUser.addCompanySetItem(employmentContract.getPayCompany());
}
}
CharSequence password = Beans.get(UserService.class).generateRandomPassword();
employeeUser.setPassword(password.toString());
employee.setUser(employeeUser);
}
}
Beans.get(UserRepository.class).save(employeeUser);
response.setCanClose(true);
}
use of com.axelor.apps.hr.db.repo.EmployeeRepository in project axelor-open-suite by axelor.
the class AppraisalController method createAppraisals.
public void createAppraisals(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
Set<Map<String, Object>> employeeSet = new HashSet<Map<String, Object>>();
employeeSet.addAll((Collection<? extends Map<String, Object>>) context.get("employeeSet"));
Set<Employee> employees = new HashSet<Employee>();
EmployeeRepository employeeRepo = Beans.get(EmployeeRepository.class);
for (Map<String, Object> emp : employeeSet) {
Long empId = Long.parseLong(emp.get("id").toString());
employees.add(employeeRepo.find(empId));
}
Long templateId = Long.parseLong(context.get("templateId").toString());
Appraisal appraisalTemplate = Beans.get(AppraisalRepository.class).find(templateId);
Boolean send = (Boolean) context.get("sendAppraisals");
Set<Long> createdIds = Beans.get(AppraisalService.class).createAppraisals(appraisalTemplate, employees, send);
response.setView(ActionView.define("Appraisal").model(Appraisal.class.getName()).add("grid", "appraisal-grid").add("form", "appraisal-form").param("search-filters", "appraisal-fitlers").domain("self.id in :createdIds").context("createdIds", createdIds).map());
response.setCanClose(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations