class ProfileServiceImpl extends BaseTransactionalService implements ProfileService {

    @Override
    public ServiceResult<UserProfileResource> getUserProfile(Long userId) {
        return find(userRepository.findById(userId), notFoundError(User.class, userId))
                .andOnSuccess(user -> {
                    UserProfileResource profileDetails = assignUserProfileDetails(user);

                    if (user.getProfileId() != null) {
                        Profile profile = profileRepository.findById(user.getProfileId()).get();
                        profileDetails.setAddress(addressMapper.mapToResource(profile.getAddress()));
                        profileDetails.setCreatedBy(profile.getCreatedBy().getName());
                        profileDetails.setCreatedOn(profile.getCreatedOn());
                        profileDetails.setModifiedBy(profile.getModifiedBy().getName());
                        profileDetails.setModifiedOn(profile.getModifiedOn());
                    }
                    return serviceSuccess(profileDetails);
                });
    }

}