@Override public void convertToEntity(Note domain, NoteEntity entity) throws BusinessServiceException { if (domain != null) { try { NoteHelper.convertToEntity(domain, entity); UserEntity userEntity = userDao.getEntityInstance(domain.getUserId()); if (userEntity == null) { throw new BusinessServiceException("Such user doesn't exist."); } if (entity != null) { entity.setUser(userEntity); } ScheduleEntity scheduleEntity = scheduleDao.getEntityInstance(domain.getScheduleId()); if (scheduleEntity == null) { throw new BusinessServiceException("Such schedule doesn't exist."); } if (entity != null) { entity.setSchedule(scheduleEntity); } } catch (DataAccessException e) { throw new BusinessServiceException("Conversion to note entity error.", e); } } }
@Override public Note convertToDomain(NoteEntity entity) throws BusinessServiceException { if (entity == null) { return null; } Note note = NoteHelper.convertToDomain(entity); note.setUser(UserHelper.convertToDomain(entity.getUser())); note.setSchedule(ScheduleHelper.convertToDomain(entity.getSchedule())); return note; }