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();
}
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));
}
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());
}
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;
}
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;
}
Aggregations