use of io.lumeer.api.model.DefaultWorkspace in project engine by Lumeer.
the class UserFacade method setDefaultWorkspace.
public void setDefaultWorkspace(DefaultWorkspace workspace) {
Organization organization;
if (workspace.getOrganizationId() != null) {
organization = checkOrganizationPermissions(workspace.getOrganizationId(), RoleType.Read);
} else {
organization = checkOrganizationPermissionsByCode(workspace.getOrganizationCode(), RoleType.Read);
}
projectDao.setOrganization(organization);
Project project;
if (workspace.getProjectId() != null) {
project = checkProjectPermissions(organization.getId(), workspace.getProjectId(), RoleType.Read);
} else {
project = checkProjectPermissionsByCode(organization.getId(), workspace.getProjectCode(), RoleType.Read);
}
DefaultWorkspace defaultWorkspace = new DefaultWorkspace(organization.getId(), project.getId());
User currentUser = authenticatedUser.getCurrentUser();
currentUser.setDefaultWorkspace(defaultWorkspace);
User updatedUser = userDao.updateUser(currentUser.getId(), currentUser);
userCache.updateUser(updatedUser.getEmail(), updatedUser);
if (updateDefaultWorkspaceEvent != null) {
updateDefaultWorkspaceEvent.fire(new UpdateDefaultWorkspace(organization, project));
}
}
use of io.lumeer.api.model.DefaultWorkspace in project engine by Lumeer.
the class UserFacadeIT method testSetWorkspaceAndChange.
@Test
public void testSetWorkspaceAndChange() {
DefaultWorkspace defaultWorkspace = new DefaultWorkspace(organization.getId(), project.getId());
userFacade.setDefaultWorkspace(defaultWorkspace);
User currentUser = userFacade.getCurrentUser();
assertThat(currentUser.getDefaultWorkspace().getOrganizationCode()).isNotEqualTo("newCode");
assertThat(currentUser.getDefaultWorkspace().getProjectCode()).isNotEqualTo("someNewCode");
project.setCode("someNewCode");
projectDao.updateProject(project.getId(), project);
organization.setCode("newCode");
organizationDao.updateOrganization(organization.getId(), organization);
currentUser = userFacade.getCurrentUser();
assertThat(currentUser.getDefaultWorkspace().getOrganizationCode()).isEqualTo("newCode");
assertThat(currentUser.getDefaultWorkspace().getProjectCode()).isEqualTo("someNewCode");
}
use of io.lumeer.api.model.DefaultWorkspace 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;
}
Aggregations