@Transactional public Result execute() { Employee employee = allEmployees.get(empId); Result result = getValidator().validateForResult(this); result.addErrors(isPaymentMethodHourly(employee.getPaymentMethod())); if (!result.isValid()) return result; Employee updatedEmployee = addTimeCardToEmployee(employee); allEmployees.save(updatedEmployee); return result; }
private Employee addTimeCardToEmployee(Employee employee) { // TODO make immutable HourlyPayment hourlyPayment = (HourlyPayment) employee.getPaymentMethod(); hourlyPayment.addTimeCard(timeCard); return employee; }