Search in sources :

Example 1 with DefaultViewConfig

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;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Document(org.bson.Document) DefaultViewConfig(io.lumeer.api.model.DefaultViewConfig) Date(java.util.Date)

Example 2 with DefaultViewConfig

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);
}
Also used : InitialUserData(io.lumeer.api.model.InitialUserData) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.auth.AuthenticatedUser) NotificationSetting(io.lumeer.api.model.NotificationSetting) DefaultViewConfig(io.lumeer.api.model.DefaultViewConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with DefaultViewConfig

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;
}
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 4 with DefaultViewConfig

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);
        }
    }
}
Also used : Project(io.lumeer.api.model.Project) InitialUserData(io.lumeer.api.model.InitialUserData) DefaultViewConfig(io.lumeer.api.model.DefaultViewConfig) NotificationsSettings(io.lumeer.api.model.NotificationsSettings)

Example 5 with 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);
    }
}
Also used : MongoException(com.mongodb.MongoException) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Document(org.bson.Document) ReturnDocument(com.mongodb.client.model.ReturnDocument) UpdateDefaultViewConfig(io.lumeer.engine.api.event.UpdateDefaultViewConfig) DefaultViewConfig(io.lumeer.api.model.DefaultViewConfig) UpdateDefaultViewConfig(io.lumeer.engine.api.event.UpdateDefaultViewConfig) StorageException(io.lumeer.storage.api.exception.StorageException) Bson(org.bson.conversions.Bson)

Aggregations

DefaultViewConfig (io.lumeer.api.model.DefaultViewConfig)5 InitialUserData (io.lumeer.api.model.InitialUserData)3 NotificationsSettings (io.lumeer.api.model.NotificationsSettings)2 Project (io.lumeer.api.model.Project)2 User (io.lumeer.api.model.User)2 ZonedDateTime (java.time.ZonedDateTime)2 Auth0Exception (com.auth0.exception.Auth0Exception)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MongoException (com.mongodb.MongoException)1 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)1 ReturnDocument (com.mongodb.client.model.ReturnDocument)1 DefaultWorkspace (io.lumeer.api.model.DefaultWorkspace)1 Feedback (io.lumeer.api.model.Feedback)1 InvitationType (io.lumeer.api.model.InvitationType)1 Language (io.lumeer.api.model.Language)1 NotificationSetting (io.lumeer.api.model.NotificationSetting)1 Organization (io.lumeer.api.model.Organization)1 Permission (io.lumeer.api.model.Permission)1 Perspective (io.lumeer.api.model.Perspective)1 ProductDemo (io.lumeer.api.model.ProductDemo)1