use of io.lumeer.api.model.Language 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;
}
use of io.lumeer.api.model.Language in project engine by Lumeer.
the class LumeerBridge method removeDocumentsInView.
@SuppressWarnings("unused")
public void removeDocumentsInView(final String viewId) {
try {
final View view = task.getDaoContextSnapshot().getViewDao().getViewById(viewId);
final Query query = view.getQuery().getFirstStem(0, Task.MAX_VIEW_DOCUMENTS);
final Language language = Language.fromString(task.getCurrentLocale());
final Set<RoleType> roles = PermissionUtils.getUserRolesInResource(task.getDaoContextSnapshot().getOrganization(), task.getDaoContextSnapshot().getProject(), view, task.getInitiator(), task.getGroups());
final AllowedPermissions permissions = new AllowedPermissions(roles);
final List<Document> documents = DocumentUtils.getDocuments(task.getDaoContextSnapshot(), query, task.getInitiator(), language, permissions, task.getTimeZone());
documents.stream().filter(d -> task.getDaoContextSnapshot().increaseDeletionCounter() <= Task.MAX_CREATED_AND_DELETED_DOCUMENTS_AND_LINKS).forEach(d -> operations.add(new DocumentRemovalOperation(d)));
} catch (Exception e) {
cause = e;
throw e;
}
}
use of io.lumeer.api.model.Language in project engine by Lumeer.
the class LumeerBridge method readView.
@SuppressWarnings("unused")
public List<DocumentBridge> readView(final String viewId) {
try {
final View view = task.getDaoContextSnapshot().getViewDao().getViewById(viewId);
final Query query = view.getQuery().getFirstStem(0, Task.MAX_VIEW_DOCUMENTS);
final Language language = Language.fromString(task.getCurrentLocale());
final Set<RoleType> roles = PermissionUtils.getUserRolesInResource(task.getDaoContextSnapshot().getOrganization(), task.getDaoContextSnapshot().getProject(), view, task.getInitiator(), task.getGroups());
final AllowedPermissions permissions = new AllowedPermissions(roles);
final List<Document> documents = DocumentUtils.getDocuments(task.getDaoContextSnapshot(), query, task.getInitiator(), language, permissions, task.getTimeZone());
return documents.stream().map(DocumentBridge::new).collect(toList());
} catch (Exception e) {
cause = e;
throw e;
}
}
use of io.lumeer.api.model.Language in project engine by Lumeer.
the class TemplateService method getTemplates.
@GET
public List<Project> getTemplates() {
Language language = requestDataKeeper.getUserLanguage();
final String organizationId = templateFacade.getTemplateOrganizationId(language);
if (StringUtils.isEmpty(organizationId)) {
return List.of();
}
var organization = organizationDao.getOrganizationById(organizationId);
workspaceKeeper.setOrganization(organization);
return projectFacade.getPublicProjects().stream().peek(project -> setProjectOrganizationId(project, organizationId)).collect(Collectors.toList());
}
use of io.lumeer.api.model.Language in project engine by Lumeer.
the class DelayedActionProcessor method executeActions.
private void executeActions(final List<DelayedAction> actions) {
// org id -> users
final Map<String, List<User>> userCache = new HashMap<>();
clearCache();
aggregateActions(actions).forEach(action -> {
final String organizationId = action.getData().getString(DelayedAction.DATA_ORGANIZATION_ID);
final List<User> allUsers = userCache.computeIfAbsent(organizationId, orgId -> userDao.getAllUsers(orgId));
// mix in users from actions
allUsers.addAll(getUsersFromActions(actions, allUsers));
// id -> user
final Map<String, User> users = getUsers(allUsers);
final Map<String, Language> userLanguages = initializeLanguages(users.values());
// email -> id
final Map<String, String> userIds = getUserIds(users.values());
final Language lang = userLanguages.getOrDefault(action.getReceiver(), Language.EN);
final User receiverUser = userIds.containsKey(action.getReceiver()) ? users.get(userIds.get(action.getReceiver())) : null;
final Collection collection = checkActionResourceExistsAndFillData(action, receiverUser);
if (collection != null) {
// if we do not know anything about the user, make sure to send the notification; otherwise check the user settings
if (receiverUser == null || isNotificationEnabled(action, receiverUser)) {
if (action.getNotificationChannel() == NotificationChannel.Email) {
final User user = userIds.containsKey(action.getInitiator()) ? users.get(userIds.get(action.getInitiator())) : null;
final String sender = user != null ? emailSenderFacade.formatUserReference(user) : "";
final String from = user != null ? emailSenderFacade.formatFrom(user) : "";
final String recipient = action.getReceiver();
final Map<String, Object> additionalData = processData(action.getData(), lang, receiverUser);
emailSenderFacade.sendEmailFromTemplate(getEmailTemplate(action), lang, sender, from, recipient, getEmailSubjectPart(action, additionalData, lang), additionalData);
} else if (action.getNotificationChannel() == NotificationChannel.Internal && userIds.containsKey(action.getReceiver())) {
UserNotification notification = createUserNotification(users.get(userIds.get(action.getReceiver())), action, lang);
notification = userNotificationDao.createNotification(notification);
if (pusherClient != null) {
pusherClient.trigger(List.of(createUserNotificationEvent(notification, PusherFacade.CREATE_EVENT_SUFFIX, userIds.get(action.getReceiver()))));
}
}
}
// reschedule past due actions
if (!rescheduleDueDateAction(actions, action, receiverUser, collection)) {
markActionAsCompleted(actions, action);
}
} else {
markActionAsCompleted(actions, action);
}
});
}
Aggregations