-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathEmployeeCreateCommand.java
More file actions
68 lines (53 loc) · 1.77 KB
/
EmployeeCreateCommand.java
File metadata and controls
68 lines (53 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@Service
public class EmployeeCreateCommand implements ResultCommandInterface<Employee> {
private Employee employee;
private boolean initialEmployee;
private EmployeeRepository employeeRepository;
final EmployeeEntity employeeEntity;
public Employee validate() {
if (initialEmployee == true) {
employee.setClassification(
EmployeeClassification.GENERAL_MANAGER.getClassification());
}
employeeEntity =
this.employeeRepository.save(employeeEntity(this.employee));
this.employee.setId(employeeEntity.getId());
this.employee.setPassword(StringUtils.EMPTY);
this.employee.setCreatedOn(employeeEntity.getCreatedOn());
this.employee.setEmployeeId(
employeeEntity.getEmployeeId());
return this.employee;
}
private void checkIfEmpty() {
if (StringUtils.isBlank(this.eployee.getFirstName())) {
throw new Exception("firstNameIsEmpty");
}
if (StringUtils.isBlank(this.employee.getLastName())) {
throw new Exception("lastNameIsEmpty");
}
if (StringUtils.isBlank(this.employee.getPassword())) {
throw new Exception("passwordIsEmpty");
}
if (isInitialEmployee == false
&& (EmployeeClassification.map(this.employee.getClassification()) == EmployeeClassification.NOT_DEFINED)) {
throw new Exception("classification");
}
}
public Employee getEmployee() {
return employee;
}
public EmployeeCreateCommand setEmployee(final Employee employee) {
this.employee = employee;
return this.employee;
}
public boolean getInitialEmployee() {
return this.initialEmployee;
}
public EmployeeCreateCommand setInitialEmployee(final boolean setInitial) {
initialEmployee = setInitial;
return initialEmployee;
}
public EmployeeCreate() {
initialEmployee = false;
}
}