private Employee convertEmployeeFormToEmployee(EmployeeForm employeeForm) { if (employeeForm.getPosition() == Position.Cook) { Cook employee = new Cook(); List<CookedDishes> cookedDishes = new ArrayList<>(); List<String> cookedDishesIdList = convertDelimitedStringToList(employeeForm.getCookedDishes()); populateEmployee(employeeForm, employee); cookedDishesIdList.forEach( id -> cookedDishes.add(cookedDishesServiceDao.findById(Integer.parseInt(id)))); employee.setCookedDishes(cookedDishes); return employee; } else if (employeeForm.getPosition() == Position.Waiter) { Waiter employee = new Waiter(); List<Orders> orders = new ArrayList<>(); List<String> ordersIdList = convertDelimitedStringToList(employeeForm.getOrders()); ordersIdList.forEach(id -> orders.add(orderServiceDao.findById(Integer.parseInt(id)))); populateEmployee(employeeForm, employee); employee.setOrders(orders); return employee; } else { Employee employee = new Employee(); populateEmployee(employeeForm, employee); return employee; } }
private EmployeeForm convertEmployeeToEmployeeForm(Employee employee) { EmployeeForm employeeForm = new EmployeeForm(); if (employee.getPosition() == Position.Cook) { Cook cook = (Cook) employee; List<String> cookedDishesIdList = new ArrayList<>(); List<CookedDishes> cookedDishes = cook.getCookedDishes(); cookedDishes.forEach(dish -> cookedDishesIdList.add(dish.getId().toString())); String cookedDishesString = convertListToDelimitedString(cookedDishesIdList); employeeForm.setCookedDishes(cookedDishesString); populateEmployeeForm(employeeForm, cook); if ("".equals(employeeForm.getCookedDishes())) { employeeForm.setCookedDishes("No cooked dishes"); } return employeeForm; } else if (employee.getPosition() == Position.Waiter) { Waiter waiter = (Waiter) employee; List<String> ordersIdList = new ArrayList<>(); List<Orders> orders = waiter.getOrders(); orders.forEach(order -> ordersIdList.add(order.getId().toString())); String ordersString = convertListToDelimitedString(ordersIdList); employeeForm.setOrders(ordersString); populateEmployeeForm(employeeForm, waiter); if ("".equals(employeeForm.getOrders())) { employeeForm.setOrders("No orders"); } return employeeForm; } else { populateEmployeeForm(employeeForm, employee); return employeeForm; } }