use of io.lumeer.api.model.DefaultViewConfig in project engine by Lumeer.
the class DefaultViewConfigCodec method decode.
@Override
public DefaultViewConfig decode(final BsonReader bsonReader, final DecoderContext decoderContext) {
Document bson = configCodec.decode(bsonReader, decoderContext);
String userId = bson.getString(USER_ID);
String perspective = bson.getString(PERSPECTIVE);
String collectionId = bson.getString(KEY);
Object config = bson.get(CONFIG);
Date updateAtDate = bson.getDate(UPDATED_AT);
ZonedDateTime updatedAt = updateAtDate != null ? ZonedDateTime.ofInstant(updateAtDate.toInstant(), ZoneOffset.UTC) : null;
var defaultConfig = new DefaultViewConfig(collectionId, perspective, config, updatedAt);
defaultConfig.setUserId(userId);
return defaultConfig;
}
use of io.lumeer.api.model.DefaultViewConfig in project engine by Lumeer.
the class UserFacadeIT method testCreateUserWithInitialData.
@Test
public void testCreateUserWithInitialData() throws IOException {
String dashboardJson = "{\"search\":{\"documents\":{\"groupBy\":\"priority\",\"sortBy\":[{\"attribute\":\"state\"},{\"attribute\":\"dueDate\",\"type\":\"desc\"},{\"attribute\":\"priority\"},{\"attribute\":\"lastUsed\"}]}}}";
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> dashboard = mapper.readValue(dashboardJson, Map.class);
List<NotificationSetting> notificationSettings = List.of(new NotificationSetting(NotificationType.DUE_DATE_SOON, NotificationChannel.Internal, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.PAST_DUE_DATE, NotificationChannel.Internal, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.DUE_DATE_CHANGED, NotificationChannel.Internal, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.ORGANIZATION_SHARED, NotificationChannel.Email, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.TASK_COMMENTED, NotificationChannel.Email, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.TASK_MENTIONED, NotificationChannel.Email, NotificationFrequency.Immediately));
InitialUserData data = new InitialUserData(dashboard, notificationSettings, Language.CS);
initialUserDataDao.upsert(data);
userFacade.createUser(organizationId1, prepareUser(organizationId1, USER1));
User stored = getUser(organizationId1, USER1);
assertThat(stored).isNotNull();
assertThat(stored.getName()).isEqualTo(USER1);
assertThat(stored.getEmail()).isEqualTo(USER1);
assertThat(stored.getLanguage()).isEqualTo(Language.CS.toString());
assertThat(stored.getNotificationsSettingsList()).hasSizeGreaterThanOrEqualTo(6);
assertThat(stored.getNotificationsSettingsList()).containsAll(notificationSettings);
assertThat(stored.getNotificationsLanguage()).isEqualTo(Language.CS.toString());
assertThat(stored.getOrganizations()).containsOnly(organizationId1);
List<DefaultViewConfig> configs = defaultViewConfigDao.getConfigs(stored.getId());
assertThat(configs).hasSize(1);
assertThat(configs.get(0).getKey()).isEqualTo("default");
assertThat(configs.get(0).getPerspective()).isEqualTo(Perspective.Search.toString());
assertThat(mapper.writeValueAsString(configs.get(0).getConfig())).isEqualTo(dashboardJson);
}
use of io.lumeer.api.model.DefaultViewConfig 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.DefaultViewConfig in project engine by Lumeer.
the class UserFacade method patchNewUserDefaultData.
private void patchNewUserDefaultData(User user, List<Project> projects, List<InitialUserData> dataList, Map<String, List<DefaultViewConfig>> configsMap) {
// global settings
InitialUserData data = dataList.stream().filter(datum -> datum.getProjectId() == null).findFirst().orElse(null);
if (data != null) {
var language = data.getLanguage() != null ? data.getLanguage().toString() : null;
user.setLanguage(language);
user.setNotifications(new NotificationsSettings(data.getNotifications(), language));
}
for (Project project : projects) {
InitialUserData projectData = dataList.stream().filter(datum -> Objects.equals(datum.getProjectId(), project.getId())).findFirst().orElse(data);
if (projectData != null && projectData.getDashboard() != null) {
configsMap.computeIfAbsent(project.getId(), id -> new ArrayList<>());
var defaultViewConfig = new DefaultViewConfig("default", Perspective.Search.getValue(), projectData.getDashboard(), ZonedDateTime.now());
defaultViewConfig.setUserId(user.getEmail());
configsMap.get(project.getId()).add(defaultViewConfig);
}
}
}
use of io.lumeer.api.model.DefaultViewConfig in project engine by Lumeer.
the class MongoDefaultViewConfigDao method updateConfig.
@Override
public DefaultViewConfig updateConfig(final DefaultViewConfig config) {
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER).upsert(true);
try {
Bson update = new Document("$set", config);
final DefaultViewConfig returnedConfig = databaseCollection().findOneAndUpdate(configFilter(config), update, options);
if (updateDefaultViewConfigEvent != null) {
updateDefaultViewConfigEvent.fire(new UpdateDefaultViewConfig(returnedConfig));
}
return returnedConfig;
} catch (MongoException ex) {
throw new StorageException("Cannot update default view config " + config, ex);
}
}
Aggregations