Search in sources :

Example 1 with NotificationSetting

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

the class InitialUserDataCodec method decode.

@Override
public InitialUserData decode(final BsonReader bsonReader, final DecoderContext decoderContext) {
    Document bson = configCodec.decode(bsonReader, decoderContext);
    String projectId = bson.getString(PROJECT_ID);
    Object dashboardConfig = bson.get(DASHBOARD);
    Language language = Language.fromString(bson.getString(LANGUAGE));
    List<Document> notificationsList = bson.getList(NOTIFICATIONS, Document.class);
    List<NotificationSetting> notifications = new ArrayList<>();
    if (notificationsList != null) {
        notifications = notificationsList.stream().map(NotificationSettingCodec::convertFromDocument).collect(Collectors.toList());
    }
    var data = new InitialUserData(dashboardConfig, notifications, language);
    data.setProjectId(projectId);
    return data;
}
Also used : InitialUserData(io.lumeer.api.model.InitialUserData) Language(io.lumeer.api.model.Language) ArrayList(java.util.ArrayList) NotificationSetting(io.lumeer.api.model.NotificationSetting) Document(org.bson.Document)

Example 2 with NotificationSetting

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

the class NotificationSettingCodec method convertFromDocument.

public static NotificationSetting convertFromDocument(final Document bson) {
    final String notificationTypeString = bson.getString(NotificationSetting.NOTIFICATION_TYPE);
    final NotificationType notificationType = notificationTypeString != null ? NotificationType.valueOf(notificationTypeString) : null;
    final String notificationChannelString = bson.getString(NotificationSetting.NOTIFICATION_CHANNEL);
    final NotificationChannel notificationChannel = notificationChannelString != null ? NotificationChannel.valueOf(notificationChannelString) : null;
    final String notificationFrequencyString = bson.getString(NotificationSetting.NOTIFICATION_FREQUENCY);
    final NotificationFrequency notificationFrequency = notificationFrequencyString != null ? NotificationFrequency.valueOf(notificationFrequencyString) : null;
    return new NotificationSetting(notificationType, notificationChannel, notificationFrequency);
}
Also used : NotificationChannel(io.lumeer.api.model.NotificationChannel) NotificationFrequency(io.lumeer.api.model.NotificationFrequency) NotificationType(io.lumeer.api.model.NotificationType) NotificationSetting(io.lumeer.api.model.NotificationSetting)

Example 3 with NotificationSetting

use of io.lumeer.api.model.NotificationSetting 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 4 with NotificationSetting

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

the class UserCodec method decode.

@Override
@SuppressWarnings("unchecked")
public User decode(final BsonReader bsonReader, final DecoderContext decoderContext) {
    Document bson = documentCodec.decode(bsonReader, decoderContext);
    String id = bson.getObjectId(ID).toHexString();
    String name = bson.getString(NAME);
    String email = bson.getString(EMAIL);
    List<String> authIds = bson.get(AUTH_IDS, List.class);
    // old style
    Set<String> organizations;
    if (bson.containsKey(ALL_GROUPS)) {
        List<Document> documentList = bson.get(ALL_GROUPS, List.class);
        organizations = convertGroupsMapToOrganizations(documentList);
    } else {
        List<String> organizationsList = bson.getList(ORGANIZATIONS, String.class);
        organizations = organizationsList != null ? new HashSet<>(organizationsList) : Collections.emptySet();
    }
    String defaultOrganizationId = bson.getString(DEFAULT_ORGANIZATION_ID);
    String defaultProjectId = bson.getString(DEFAULT_PROJECT_ID);
    List<String> wishes = bson.get(User.WISHES, List.class);
    Boolean agreement = bson.getBoolean(AGREEMENT);
    ZonedDateTime agreementDate = null;
    if (bson.getDate(AGREEMENT_DATE) != null) {
        agreementDate = ZonedDateTime.ofInstant(bson.getDate(AGREEMENT_DATE).toInstant(), ZoneOffset.UTC);
    }
    Boolean newsletter = bson.getBoolean(NEWSLETTER);
    Boolean wizardDismissed = bson.getBoolean(WIZARD_DISMISSED);
    Boolean affiliatePartner = bson.getBoolean(AFFILIATE_PARTNER);
    Boolean emailVerified = bson.getBoolean(EMAIL_VERIFIED);
    String referral = bson.getString(REFERRAL);
    String language = bson.getString(LANGUAGE);
    String timeZone = bson.getString(TIME_ZONE);
    List<NotificationSetting> notificationSettings;
    final String notificationsLanguage = bson.getString(NOTIFICATIONS_LANGUAGE);
    List<Document> notifications = bson.getList(NOTIFICATIONS, Document.class);
    if (notifications != null && notifications.size() != 2 && notifications.size() != 0) {
        // it is not empty and it does not contain just the following 2 settings
        notificationSettings = new ArrayList<>(notifications).stream().map(NotificationSettingCodec::convertFromDocument).collect(Collectors.toList());
        if (notificationSettings.stream().filter(ns -> ns.getNotificationType() == NotificationType.TASK_COMMENTED && ns.getNotificationChannel() == NotificationChannel.Internal).findFirst().isEmpty()) {
            notificationSettings.add(new NotificationSetting(NotificationType.TASK_COMMENTED, NotificationChannel.Internal, NotificationFrequency.Immediately));
            notificationSettings.add(new NotificationSetting(NotificationType.TASK_MENTIONED, NotificationChannel.Internal, NotificationFrequency.Immediately));
        }
        if (notificationSettings.stream().filter(ns -> ns.getNotificationType() == NotificationType.TASK_REOPENED && ns.getNotificationChannel() == NotificationChannel.Internal).findFirst().isEmpty()) {
            notificationSettings.add(new NotificationSetting(NotificationType.TASK_REOPENED, NotificationChannel.Internal, NotificationFrequency.Immediately));
        }
        if (notificationSettings.stream().anyMatch(ns -> ns.getNotificationType() == NotificationType.TASK_ASSIGNED && ns.getNotificationChannel() == NotificationChannel.Email) && notificationSettings.stream().filter(ns -> ns.getNotificationType() == NotificationType.TASK_REOPENED && ns.getNotificationChannel() == NotificationChannel.Email).findFirst().isEmpty()) {
            notificationSettings.add(new NotificationSetting(NotificationType.TASK_REOPENED, NotificationChannel.Email, NotificationFrequency.Immediately));
        }
    } else {
        notificationSettings = List.of(new NotificationSetting(NotificationType.ORGANIZATION_SHARED, NotificationChannel.Internal, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.PROJECT_SHARED, NotificationChannel.Internal, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.COLLECTION_SHARED, NotificationChannel.Internal, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.VIEW_SHARED, NotificationChannel.Internal, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.BULK_ACTION, NotificationChannel.Internal, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.TASK_ASSIGNED, NotificationChannel.Internal, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.TASK_REOPENED, NotificationChannel.Internal, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.TASK_UPDATED, NotificationChannel.Internal, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.TASK_REMOVED, NotificationChannel.Internal, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.TASK_UNASSIGNED, NotificationChannel.Internal, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.STATE_UPDATE, NotificationChannel.Internal, NotificationFrequency.Immediately), 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.TASK_COMMENTED, NotificationChannel.Internal, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.TASK_MENTIONED, NotificationChannel.Internal, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.ORGANIZATION_SHARED, NotificationChannel.Email, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.PROJECT_SHARED, NotificationChannel.Email, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.COLLECTION_SHARED, NotificationChannel.Email, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.VIEW_SHARED, NotificationChannel.Email, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.BULK_ACTION, NotificationChannel.Email, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.TASK_ASSIGNED, NotificationChannel.Email, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.TASK_REOPENED, NotificationChannel.Email, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.TASK_UPDATED, NotificationChannel.Email, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.TASK_REMOVED, NotificationChannel.Email, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.TASK_UNASSIGNED, NotificationChannel.Email, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.STATE_UPDATE, NotificationChannel.Email, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.DUE_DATE_SOON, NotificationChannel.Email, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.PAST_DUE_DATE, NotificationChannel.Email, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.DUE_DATE_CHANGED, NotificationChannel.Email, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.TASK_COMMENTED, NotificationChannel.Email, NotificationFrequency.Immediately), new NotificationSetting(NotificationType.TASK_MENTIONED, NotificationChannel.Email, NotificationFrequency.Immediately));
    }
    Document hints = bson.get(HINTS, Document.class);
    NotificationsSettings settings = new NotificationsSettings(notificationSettings, notificationsLanguage);
    User user = new User(id, name, email, organizations, wishes, agreement, agreementDate, newsletter, wizardDismissed, referral, settings, new DataDocument(hints == null ? new Document() : hints));
    user.setAuthIds(authIds != null ? new HashSet<>(authIds) : new HashSet<>());
    user.setDefaultWorkspace(new DefaultWorkspace(defaultOrganizationId, defaultProjectId));
    user.setAffiliatePartner(affiliatePartner != null && affiliatePartner);
    user.setEmailVerified(emailVerified != null && emailVerified);
    user.setTimeZone(timeZone);
    user.setLanguage(language);
    Document onboarding = bson.get(ONBOARDING, Document.class);
    UserOnboarding userOnboarding = onboarding != null ? UserOnboardingCodec.convertFromDocument(onboarding) : new UserOnboarding();
    user.setOnboarding(userOnboarding);
    return user;
}
Also used : Document(org.bson.Document) NotificationSetting(io.lumeer.api.model.NotificationSetting) NotificationType(io.lumeer.api.model.NotificationType) NotificationChannel(io.lumeer.api.model.NotificationChannel) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) User(io.lumeer.api.model.User) CodecRegistry(org.bson.codecs.configuration.CodecRegistry) BsonReader(org.bson.BsonReader) BsonValue(org.bson.BsonValue) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ZoneOffset(java.time.ZoneOffset) UserOnboarding(io.lumeer.api.model.UserOnboarding) DecoderContext(org.bson.codecs.DecoderContext) EncoderContext(org.bson.codecs.EncoderContext) DataDocument(io.lumeer.engine.api.data.DataDocument) BsonObjectId(org.bson.BsonObjectId) Set(java.util.Set) NotificationFrequency(io.lumeer.api.model.NotificationFrequency) Collectors(java.util.stream.Collectors) DefaultWorkspace(io.lumeer.api.model.DefaultWorkspace) List(java.util.List) NotificationsSettings(io.lumeer.api.model.NotificationsSettings) Codec(org.bson.codecs.Codec) ObjectId(org.bson.types.ObjectId) BsonWriter(org.bson.BsonWriter) CollectibleCodec(org.bson.codecs.CollectibleCodec) Collections(java.util.Collections) DataDocument(io.lumeer.engine.api.data.DataDocument) User(io.lumeer.api.model.User) DefaultWorkspace(io.lumeer.api.model.DefaultWorkspace) UserOnboarding(io.lumeer.api.model.UserOnboarding) ArrayList(java.util.ArrayList) Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument) NotificationsSettings(io.lumeer.api.model.NotificationsSettings) ZonedDateTime(java.time.ZonedDateTime) NotificationSetting(io.lumeer.api.model.NotificationSetting) HashSet(java.util.HashSet)

Aggregations

NotificationSetting (io.lumeer.api.model.NotificationSetting)4 InitialUserData (io.lumeer.api.model.InitialUserData)2 NotificationChannel (io.lumeer.api.model.NotificationChannel)2 NotificationFrequency (io.lumeer.api.model.NotificationFrequency)2 NotificationType (io.lumeer.api.model.NotificationType)2 User (io.lumeer.api.model.User)2 ArrayList (java.util.ArrayList)2 Document (org.bson.Document)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DefaultViewConfig (io.lumeer.api.model.DefaultViewConfig)1 DefaultWorkspace (io.lumeer.api.model.DefaultWorkspace)1 Language (io.lumeer.api.model.Language)1 NotificationsSettings (io.lumeer.api.model.NotificationsSettings)1 UserOnboarding (io.lumeer.api.model.UserOnboarding)1 AuthenticatedUser (io.lumeer.core.auth.AuthenticatedUser)1 DataDocument (io.lumeer.engine.api.data.DataDocument)1 ZoneOffset (java.time.ZoneOffset)1 ZonedDateTime (java.time.ZonedDateTime)1 Collections (java.util.Collections)1 Date (java.util.Date)1