@Test public void getProfileInfoWhenUserOrgExists() { UserOrg expectedUserOrg = createAndSetUserOrg(); expectedUserOrg.setWebsite("unknown.com"); AcmUser user = new AcmUser(); user.setUserId(USER_ID); AcmGroup group = new AcmGroup(); group.setName("ACM_INVESTIGATOR"); Set<AcmGroup> groups = new HashSet<>(); groups.add(group); user.setGroups(groups); expect(mockUserOrgDao.findByUserId(USER_ID)).andReturn(expectedUserOrg); expect(mockUserDao.findByUserId(USER_ID)).andReturn(user); replayAll(); ProfileDTO profileDTO = userOrgService.getProfileInfo(USER_ID, mockAuthentication); verifyAll(); assertEquals(expectedUserOrg.getWebsite(), profileDTO.getWebsite()); assertEquals(expectedUserOrg.getUser().getUserId(), profileDTO.getUserId()); assertEquals(group.getName(), profileDTO.getGroups().get(0)); assertEquals(expectedUserOrg.getOrganization().getOrganizationValue(), profileDTO.getCompanyName()); }
@Override @Transactional public ProfileDTO getProfileInfo(String userId, Authentication authentication) { UserOrg userOrg = getUserOrgForUserId(userId); if (userOrg == null) { log.info("Profile info for the user [{}] is not found", userId); userOrg = createUserOrgForUser(userId); try { userOrg = saveUserOrgTransaction(userOrg, authentication); getEventPublisher().publishProfileEvent(userOrg, authentication, true, true); } catch (MuleException e) { log.error("UserOrg for user [{}] was not saved. {}", userId, e); getEventPublisher().publishProfileEvent(userOrg, authentication, true, false); } } AcmUser user = userDao.findByUserId(userId); return createProfileDTO(userOrg, user.getGroups()); }
UserOrgServiceImpl implements UserOrgService { @Override @Transactional public ProfileDTO getProfileInfo(String userId, Authentication authentication) { UserOrg userOrg = getUserOrgForUserId(userId); if (userOrg == null) { log.info("Profile info for the user [{}] is not found", userId); userOrg = createUserOrgForUser(userId); try { userOrg = saveUserOrgTransaction(userOrg, authentication); getEventPublisher().publishProfileEvent(userOrg, authentication, true, true); } catch (MuleException e) { log.error("UserOrg for user [{}] was not saved. {}", userId, e); getEventPublisher().publishProfileEvent(userOrg, authentication, true, false); } } AcmUser user = userDao.findByUserId(userId); return createProfileDTO(userOrg, user.getGroups()); } }
UserOrgServiceImpl implements UserOrgService { @Override @Transactional public ProfileDTO getProfileInfo(String userId, Authentication authentication) { UserOrg userOrg = getUserOrgForUserId(userId); if (userOrg == null) { log.info("Profile info for the user [{}] is not found", userId); userOrg = createUserOrgForUser(userId); try { userOrg = saveUserOrgTransaction(userOrg, authentication); getEventPublisher().publishProfileEvent(userOrg, authentication, true, true); } catch (MuleException e) { log.error("UserOrg for user [{}] was not saved. {}", userId, e); getEventPublisher().publishProfileEvent(userOrg, authentication, true, false); } } AcmUser user = userDao.findByUserId(userId); return createProfileDTO(userOrg, user.getGroups()); }  }
UserOrgServiceImpl implements UserOrgService { @Override @Transactional public ProfileDTO getProfileInfo(String userId, Authentication authentication) { UserOrg userOrg = getUserOrgForUserId(userId); if (userOrg == null) { log.info("Profile info for the user [{}] is not found", userId); userOrg = createUserOrgForUser(userId); try { userOrg = saveUserOrgTransaction(userOrg, authentication); getEventPublisher().publishProfileEvent(userOrg, authentication, true, true); } catch (MuleException e) { log.error("UserOrg for user [{}] was not saved. {}", userId, e); getEventPublisher().publishProfileEvent(userOrg, authentication, true, false); } } AcmUser user = userDao.findByUserId(userId); return createProfileDTO(userOrg, user.getGroups()); }  @Override UserOrg getUserOrgForUserId(String userId); @Override String getProfileLocation(); @Override @Transactional UserOrg saveUserOrgTransaction(UserOrg userOrgInfo, Authentication authentication); @Override @Transactional ProfileDTO getProfileInfo(String userId, Authentication authentication); @Override @Transactional ProfileDTO saveUserOrgInfo(ProfileDTO profile, Authentication authentication); UserDao getUserDao(); void setUserDao(UserDao userDao); OrganizationService getOrganizationService(); void setOrganizationService(OrganizationService organizationService); UserOrgDao getUserOrgDao(); void setUserOrgDao(UserOrgDao userOrgDao); MuleContextManager getMuleContextManager(); void setMuleContextManager(MuleContextManager muleContextManager); ProfileEventPublisher getEventPublisher(); void setEventPublisher(ProfileEventPublisher eventPublisher); AcmGroupDao getGroupDao(); void setGroupDao(AcmGroupDao groupDao); GroupService getGroupService(); void setGroupService(GroupService groupService); String getDefaultCmisId(); void setDefaultCmisId(String defaultCmisId); ProfileConfig getProfileConfig(); void setProfileConfig(ProfileConfig profileConfig); }
UserOrgServiceImpl implements UserOrgService { @Override @Transactional public ProfileDTO getProfileInfo(String userId, Authentication authentication) { UserOrg userOrg = getUserOrgForUserId(userId); if (userOrg == null) { log.info("Profile info for the user [{}] is not found", userId); userOrg = createUserOrgForUser(userId); try { userOrg = saveUserOrgTransaction(userOrg, authentication); getEventPublisher().publishProfileEvent(userOrg, authentication, true, true); } catch (MuleException e) { log.error("UserOrg for user [{}] was not saved. {}", userId, e); getEventPublisher().publishProfileEvent(userOrg, authentication, true, false); } } AcmUser user = userDao.findByUserId(userId); return createProfileDTO(userOrg, user.getGroups()); }  @Override UserOrg getUserOrgForUserId(String userId); @Override String getProfileLocation(); @Override @Transactional UserOrg saveUserOrgTransaction(UserOrg userOrgInfo, Authentication authentication); @Override @Transactional ProfileDTO getProfileInfo(String userId, Authentication authentication); @Override @Transactional ProfileDTO saveUserOrgInfo(ProfileDTO profile, Authentication authentication); UserDao getUserDao(); void setUserDao(UserDao userDao); OrganizationService getOrganizationService(); void setOrganizationService(OrganizationService organizationService); UserOrgDao getUserOrgDao(); void setUserOrgDao(UserOrgDao userOrgDao); MuleContextManager getMuleContextManager(); void setMuleContextManager(MuleContextManager muleContextManager); ProfileEventPublisher getEventPublisher(); void setEventPublisher(ProfileEventPublisher eventPublisher); AcmGroupDao getGroupDao(); void setGroupDao(AcmGroupDao groupDao); GroupService getGroupService(); void setGroupService(GroupService groupService); String getDefaultCmisId(); void setDefaultCmisId(String defaultCmisId); ProfileConfig getProfileConfig(); void setProfileConfig(ProfileConfig profileConfig);  }