use of com.sequenceiq.cloudbreak.domain.UserProfile in project cloudbreak by hortonworks.
the class UserProfileServiceTest method getShouldAddUIProps.
@Test
public void getShouldAddUIProps() {
when(userProfileRepository.save(any(UserProfile.class))).thenReturn(new UserProfile());
ArgumentCaptor<UserProfile> userProfileCaptor = ArgumentCaptor.forClass(UserProfile.class);
String account = "account1";
String owner = "123-123-123";
userProfileService.get(account, owner);
verify(userProfileRepository).save(userProfileCaptor.capture());
UserProfile capturedProfile = userProfileCaptor.getValue();
assertNotNull(capturedProfile.getUiProperties());
}
use of com.sequenceiq.cloudbreak.domain.UserProfile in project cloudbreak by hortonworks.
the class UserProfileServiceTest method getFillUserNameIfEmpty.
@Test
public void getFillUserNameIfEmpty() {
String account = "account1";
String owner = "123-123-123";
UserProfile foundProfile = new UserProfile();
foundProfile.setOwner(owner);
foundProfile.setAccount(account);
String username = "test@hortonworks.com";
when(userProfileRepository.findOneByOwnerAndAccount(anyString(), anyString())).thenReturn(foundProfile);
when(userProfileRepository.save(any(UserProfile.class))).thenReturn(new UserProfile());
ArgumentCaptor<UserProfile> userProfileCaptor = ArgumentCaptor.forClass(UserProfile.class);
UserProfile returnedUserProfile = userProfileService.get(account, owner, username);
verify(userProfileRepository).save(userProfileCaptor.capture());
UserProfile capturedProfile = userProfileCaptor.getValue();
assertEquals(account, capturedProfile.getAccount());
assertEquals(owner, capturedProfile.getOwner());
assertEquals(username, capturedProfile.getUserName());
assertNotNull(returnedUserProfile);
}
use of com.sequenceiq.cloudbreak.domain.UserProfile in project cloudbreak by hortonworks.
the class ImageCatalogService method setImageCatalogAsDefault.
private void setImageCatalogAsDefault(ImageCatalog imageCatalog) {
UserProfile userProfile = getUserProfile();
userProfile.setImageCatalog(imageCatalog);
userProfileService.save(userProfile);
}
use of com.sequenceiq.cloudbreak.domain.UserProfile in project cloudbreak by hortonworks.
the class UserProfileService method put.
public void put(UserProfileRequest request, IdentityUser user) {
UserProfile userProfile = get(user.getAccount(), user.getUserId(), user.getUsername());
if (request.getCredentialId() != null) {
Credential credential = credentialService.get(request.getCredentialId(), userProfile.getAccount());
userProfile.setCredential(credential);
} else if (request.getCredentialName() != null) {
Credential credential = credentialService.get(request.getCredentialName(), userProfile.getAccount());
userProfile.setCredential(credential);
}
for (Entry<String, Object> uiStringObjectEntry : request.getUiProperties().entrySet()) {
Map<String, Object> map = userProfile.getUiProperties().getMap();
if (map == null || map.isEmpty()) {
map = new HashMap<>();
}
map.put(uiStringObjectEntry.getKey(), uiStringObjectEntry.getValue());
try {
userProfile.setUiProperties(new Json(map));
} catch (JsonProcessingException ignored) {
throw new BadRequestException("The modification of the ui properties was unsuccesfull.");
}
}
userProfileRepository.save(userProfile);
}
use of com.sequenceiq.cloudbreak.domain.UserProfile in project cloudbreak by hortonworks.
the class UserProfileService method get.
public UserProfile get(String account, String owner, String userName) {
UserProfile userProfile = userProfileRepository.findOneByOwnerAndAccount(account, owner);
if (userProfile == null) {
userProfile = new UserProfile();
userProfile.setAccount(account);
userProfile.setOwner(owner);
userProfile.setUserName(userName);
addUiProperties(userProfile);
userProfile = userProfileRepository.save(userProfile);
} else if (userProfile.getUserName() == null && userName != null) {
userProfile.setUserName(userName);
userProfile = userProfileRepository.save(userProfile);
}
return userProfile;
}
Aggregations