Search in sources :

Example 11 with UserProfile

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());
}
Also used : UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 12 with UserProfile

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);
}
Also used : UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 13 with UserProfile

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);
}
Also used : UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile)

Example 14 with 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);
}
Also used : Credential(com.sequenceiq.cloudbreak.domain.Credential) UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Json(com.sequenceiq.cloudbreak.domain.json.Json) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 15 with 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;
}
Also used : UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile)

Aggregations

UserProfile (com.sequenceiq.cloudbreak.domain.UserProfile)17 Test (org.junit.Test)7 Matchers.anyString (org.mockito.Matchers.anyString)6 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)4 CloudbreakImageCatalogV2 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2)2 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)2 Stack (com.sequenceiq.cloudbreak.domain.Stack)2 OperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.OperationDetails)2 Before (org.junit.Before)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)1 Credential (com.sequenceiq.cloudbreak.domain.Credential)1 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)1 Json (com.sequenceiq.cloudbreak.domain.json.Json)1 BlueprintDetails (com.sequenceiq.cloudbreak.structuredevent.event.BlueprintDetails)1 ClusterDetails (com.sequenceiq.cloudbreak.structuredevent.event.ClusterDetails)1 NotificationDetails (com.sequenceiq.cloudbreak.structuredevent.event.NotificationDetails)1 StackDetails (com.sequenceiq.cloudbreak.structuredevent.event.StackDetails)1 StructuredFlowErrorEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredFlowErrorEvent)1