-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathEmployeeUpdateCommand.java
More file actions
59 lines (47 loc) · 1.45 KB
/
EmployeeUpdateCommand.java
File metadata and controls
59 lines (47 loc) · 1.45 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
@Service
public class EmployeeUpdateCommand implements ResultCommandInterface<Employee> {
private Employee employee;
private EmployeeRepository employeeRepository;
private UUID employeeId;
public Employee validate() {
this.validateProperties();
this.updateEntity();
return this.employee;
}
// Helper methods
private void validateProperties() {
if (StringUtils.isBlank(this.employee.getFirstName())) {
throw new Exception("firstNameIsEmpty");
}
if (StringUtils.isBlank(this.employee.getLastName())) {
throw new Exception("lastNameIsEmpty");
}
if (EmployeeClassification.map(this.employee.getClassification()) == EmployeeClassification.NOT_DEFINED) {
throw new Exception("classification");
}
}
private void updateEntity() {
final EmployeeEntity employeeEntity =
this.employeeRepository.findById(this.employeeId);
if (employeeEntity) {
throw new Exception("employeeDoesNotExist");
}
this.employee = employeeEntity.get()
.synchronize(this.employee);
this.employeeRepository.save(employeeEntity.get());
}
public UUID getEmployeeId() {
return this.employeeId;
}
public EmployeeUpdateCommand setEmployeeId(final UUID idSet) {
this.employeeId = idSet;
return this.employeeId;
}
public Employee getEmployee() {
return this.employee;
}
public EmployeeUpdate setEmployee(final Employee employee) {
this.employee = employee;
return this;
}
}