Search in sources :

Example 1 with DefaultWorkspace

use of io.lumeer.api.model.DefaultWorkspace in project engine by Lumeer.

the class UserFacadeIT method testSetWorkspaceAndRemove.

@Test
public void testSetWorkspaceAndRemove() {
    DefaultWorkspace defaultWorkspace = new DefaultWorkspace(organization.getId(), project.getId());
    userFacade.setDefaultWorkspace(defaultWorkspace);
    User currentUser = userFacade.getCurrentUser();
    assertThat(currentUser.getDefaultWorkspace()).isNotNull();
    projectDao.deleteProject(project.getId());
    currentUser = userFacade.getCurrentUser();
    assertThat(currentUser.getDefaultWorkspace()).isNull();
}
Also used : User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.auth.AuthenticatedUser) DefaultWorkspace(io.lumeer.api.model.DefaultWorkspace) Test(org.junit.Test)

Example 2 with DefaultWorkspace

use of io.lumeer.api.model.DefaultWorkspace in project engine by Lumeer.

the class UserFacadeIT method testSetWorkspaceNotExisting.

@Test
public void testSetWorkspaceNotExisting() {
    DefaultWorkspace defaultWorkspace = new DefaultWorkspace("5aedf1030b4e0ec3f46502d8", "5aedf1030b4e0ec3f46502d8");
    assertThatExceptionOfType(ResourceNotFoundException.class).isThrownBy(() -> userFacade.setDefaultWorkspace(defaultWorkspace));
}
Also used : DefaultWorkspace(io.lumeer.api.model.DefaultWorkspace) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) Test(org.junit.Test)

Example 3 with DefaultWorkspace

use of io.lumeer.api.model.DefaultWorkspace in project engine by Lumeer.

the class UserFacadeIT method testSetWorkspace.

@Test
public void testSetWorkspace() {
    DefaultWorkspace defaultWorkspace = new DefaultWorkspace(organization.getId(), project.getId());
    userFacade.setDefaultWorkspace(defaultWorkspace);
    User currentUser = userFacade.getCurrentUser();
    assertThat(currentUser.getDefaultWorkspace()).isNotNull();
    assertThat(currentUser.getDefaultWorkspace().getOrganizationId()).isEqualTo(organization.getId());
    assertThat(currentUser.getDefaultWorkspace().getOrganizationCode()).isEqualTo(organization.getCode());
    assertThat(currentUser.getDefaultWorkspace().getProjectId()).isEqualTo(project.getId());
    assertThat(currentUser.getDefaultWorkspace().getProjectCode()).isEqualTo(project.getCode());
}
Also used : User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.auth.AuthenticatedUser) DefaultWorkspace(io.lumeer.api.model.DefaultWorkspace) Test(org.junit.Test)

Example 4 with DefaultWorkspace

use of io.lumeer.api.model.DefaultWorkspace in project engine by Lumeer.

the class UserFacade method createUsersWithDefaultData.

private List<User> createUsersWithDefaultData(final String organizationId, @Nullable final String projectId, final List<User> users) {
    List<InitialUserData> dataList = initialUserDataDao.get();
    Map<String, List<DefaultViewConfig>> defaultViewConfigsMap = new HashMap<>();
    List<Project> projects = projectDao.getAllProjects();
    List<User> createdUsers = users.stream().map(user -> {
        User storedUser = userDao.getUserByEmail(user.getEmail());
        if (storedUser == null) {
            user.setOrganization(organizationId);
            user.setDefaultWorkspace(new DefaultWorkspace(organizationId, projectId));
            patchNewUserDefaultData(user, projects, dataList, defaultViewConfigsMap);
            return createUserAndSendNotification(organizationId, user);
        }
        storedUser.setOrganizations(UserUtil.mergeOrganizations(storedUser.getOrganizations(), Set.of(organizationId)));
        if (storedUser.getDefaultWorkspace() == null) {
            storedUser.setDefaultWorkspace(new DefaultWorkspace(organizationId, projectId));
        }
        User updatedUser = updateExistingUser(organizationId, storedUser);
        return keepOnlyCurrentOrganization(updatedUser, organizationId);
    }).collect(Collectors.toList());
    Map<String, String> emailToIdMap = createdUsers.stream().collect(Collectors.toMap(User::getEmail, User::getId));
    for (Project project : projects) {
        List<DefaultViewConfig> configs = defaultViewConfigsMap.getOrDefault(project.getId(), new ArrayList<>()).stream().peek(config -> config.setUserId(emailToIdMap.get(config.getUserId()))).collect(Collectors.toList());
        if (configs.size() > 0) {
            defaultViewConfigDao.setProject(project);
            defaultViewConfigDao.insertConfigs(configs);
        }
    }
    return createdUsers;
}
Also used : RoleUtils(io.lumeer.api.util.RoleUtils) ProjectDao(io.lumeer.storage.api.dao.ProjectDao) ZonedDateTime(java.time.ZonedDateTime) User(io.lumeer.api.model.User) UpdateDefaultWorkspace(io.lumeer.engine.api.event.UpdateDefaultWorkspace) InvitationType(io.lumeer.api.model.InvitationType) StringUtils(org.apache.commons.lang3.StringUtils) DefaultViewConfigDao(io.lumeer.storage.api.dao.DefaultViewConfigDao) Resource(io.lumeer.api.model.common.Resource) Map(java.util.Map) UserAuth0Utils(io.lumeer.core.auth.UserAuth0Utils) Permission(io.lumeer.api.model.Permission) RoleType(io.lumeer.api.model.RoleType) DataDocument(io.lumeer.engine.api.data.DataDocument) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) TimeZone(java.util.TimeZone) Auth0Exception(com.auth0.exception.Auth0Exception) Set(java.util.Set) Feedback(io.lumeer.api.model.Feedback) Collectors(java.util.stream.Collectors) UpdateCurrentUser(io.lumeer.engine.api.event.UpdateCurrentUser) UserLoginDao(io.lumeer.storage.api.dao.UserLoginDao) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) CreateOrUpdateUser(io.lumeer.engine.api.event.CreateOrUpdateUser) List(java.util.List) Optional(java.util.Optional) ReloadGroups(io.lumeer.engine.api.event.ReloadGroups) Utils(io.lumeer.core.util.Utils) UserDao(io.lumeer.storage.api.dao.UserDao) HashMap(java.util.HashMap) Perspective(io.lumeer.api.model.Perspective) DefaultViewConfig(io.lumeer.api.model.DefaultViewConfig) GroupDao(io.lumeer.storage.api.dao.GroupDao) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) OrganizationDao(io.lumeer.storage.api.dao.OrganizationDao) Language(io.lumeer.api.model.Language) Role(io.lumeer.api.model.Role) FeedbackDao(io.lumeer.storage.api.dao.FeedbackDao) UserInvitation(io.lumeer.api.model.UserInvitation) UserOnboarding(io.lumeer.api.model.UserOnboarding) Organization(io.lumeer.api.model.Organization) Event(javax.enterprise.event.Event) RemoveUser(io.lumeer.engine.api.event.RemoveUser) UserUtil(io.lumeer.api.util.UserUtil) InitialUserData(io.lumeer.api.model.InitialUserData) ProductDemo(io.lumeer.api.model.ProductDemo) DefaultWorkspace(io.lumeer.api.model.DefaultWorkspace) Project(io.lumeer.api.model.Project) UnsuccessfulOperationException(io.lumeer.engine.api.exception.UnsuccessfulOperationException) InitialUserDataDao(io.lumeer.storage.api.dao.InitialUserDataDao) RequestScoped(javax.enterprise.context.RequestScoped) NotificationsSettings(io.lumeer.api.model.NotificationsSettings) Collections(java.util.Collections) BadFormatException(io.lumeer.core.exception.BadFormatException) User(io.lumeer.api.model.User) UpdateCurrentUser(io.lumeer.engine.api.event.UpdateCurrentUser) CreateOrUpdateUser(io.lumeer.engine.api.event.CreateOrUpdateUser) RemoveUser(io.lumeer.engine.api.event.RemoveUser) UpdateDefaultWorkspace(io.lumeer.engine.api.event.UpdateDefaultWorkspace) DefaultWorkspace(io.lumeer.api.model.DefaultWorkspace) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Project(io.lumeer.api.model.Project) InitialUserData(io.lumeer.api.model.InitialUserData) List(java.util.List) ArrayList(java.util.ArrayList) DefaultViewConfig(io.lumeer.api.model.DefaultViewConfig)

Example 5 with DefaultWorkspace

use of io.lumeer.api.model.DefaultWorkspace in project engine by Lumeer.

the class UserFacade method getCurrentUser.

public User getCurrentUser() {
    User user = authenticatedUser.getCurrentUser();
    DefaultWorkspace defaultWorkspace = user.getDefaultWorkspace();
    if (defaultWorkspace == null || defaultWorkspace.getOrganizationId() == null || defaultWorkspace.getProjectId() == null) {
        return user;
    }
    try {
        Organization organization = organizationDao.getOrganizationById(defaultWorkspace.getOrganizationId());
        defaultWorkspace.setOrganizationCode(organization.getCode());
        projectDao.setOrganization(organization);
        Project project = projectDao.getProjectById(defaultWorkspace.getProjectId());
        defaultWorkspace.setProjectCode(project.getCode());
    } catch (ResourceNotFoundException e) {
        user.setDefaultWorkspace(null);
    }
    return user;
}
Also used : Project(io.lumeer.api.model.Project) User(io.lumeer.api.model.User) UpdateCurrentUser(io.lumeer.engine.api.event.UpdateCurrentUser) CreateOrUpdateUser(io.lumeer.engine.api.event.CreateOrUpdateUser) RemoveUser(io.lumeer.engine.api.event.RemoveUser) Organization(io.lumeer.api.model.Organization) UpdateDefaultWorkspace(io.lumeer.engine.api.event.UpdateDefaultWorkspace) DefaultWorkspace(io.lumeer.api.model.DefaultWorkspace) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException)

Aggregations

DefaultWorkspace (io.lumeer.api.model.DefaultWorkspace)8 User (io.lumeer.api.model.User)7 Test (org.junit.Test)4 Organization (io.lumeer.api.model.Organization)3 Project (io.lumeer.api.model.Project)3 AuthenticatedUser (io.lumeer.core.auth.AuthenticatedUser)3 CreateOrUpdateUser (io.lumeer.engine.api.event.CreateOrUpdateUser)3 RemoveUser (io.lumeer.engine.api.event.RemoveUser)3 UpdateCurrentUser (io.lumeer.engine.api.event.UpdateCurrentUser)3 UpdateDefaultWorkspace (io.lumeer.engine.api.event.UpdateDefaultWorkspace)3 ResourceNotFoundException (io.lumeer.storage.api.exception.ResourceNotFoundException)3 NotificationsSettings (io.lumeer.api.model.NotificationsSettings)2 UserOnboarding (io.lumeer.api.model.UserOnboarding)2 DataDocument (io.lumeer.engine.api.data.DataDocument)2 Auth0Exception (com.auth0.exception.Auth0Exception)1 DefaultViewConfig (io.lumeer.api.model.DefaultViewConfig)1 Feedback (io.lumeer.api.model.Feedback)1 InitialUserData (io.lumeer.api.model.InitialUserData)1 InvitationType (io.lumeer.api.model.InvitationType)1 Language (io.lumeer.api.model.Language)1