Search in sources :

Example 1 with Language

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;
}
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 Language

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;
    }
}
Also used : AllowedPermissions(io.lumeer.api.model.AllowedPermissions) SelectedWorkspace(io.lumeer.api.SelectedWorkspace) Arrays(java.util.Arrays) TaskExecutor(io.lumeer.core.task.TaskExecutor) PrintTextOperation(io.lumeer.core.task.executor.operation.PrintTextOperation) CollectionUtil(io.lumeer.api.util.CollectionUtil) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) User(io.lumeer.api.model.User) FileAttachmentData(io.lumeer.core.task.executor.operation.data.FileAttachmentData) Operation(io.lumeer.core.task.executor.operation.Operation) TextPrintRequest(io.lumeer.core.task.executor.request.TextPrintRequest) StringUtils(org.apache.commons.lang3.StringUtils) UserMessageOperation(io.lumeer.core.task.executor.operation.UserMessageOperation) BigDecimal(java.math.BigDecimal) SmtpConfigurationBuilder(io.lumeer.core.task.executor.request.SmtpConfigurationBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceType(io.lumeer.api.model.ResourceType) Map(java.util.Map) AddLinkFileAttachmentOperation(io.lumeer.core.task.executor.operation.AddLinkFileAttachmentOperation) Collectors.toSet(java.util.stream.Collectors.toSet) ConstraintManager(io.lumeer.core.constraint.ConstraintManager) DocumentOperation(io.lumeer.core.task.executor.operation.DocumentOperation) RoleType(io.lumeer.api.model.RoleType) View(io.lumeer.api.model.View) ViewPermissionsOperation(io.lumeer.core.task.executor.operation.ViewPermissionsOperation) DataDocument(io.lumeer.engine.api.data.DataDocument) Value(org.graalvm.polyglot.Value) DummySequenceOperation(io.lumeer.core.task.executor.operation.DummySequenceOperation) Document(io.lumeer.api.model.Document) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) LinkInstance(io.lumeer.api.model.LinkInstance) StandardCharsets(java.nio.charset.StandardCharsets) LinkType(io.lumeer.api.model.LinkType) Group(io.lumeer.api.model.Group) DefaultConfigurationProducer(io.lumeer.core.facade.configuration.DefaultConfigurationProducer) PrintAttributeOperation(io.lumeer.core.task.executor.operation.PrintAttributeOperation) SendSmtpEmailRequest(io.lumeer.core.task.executor.request.SendSmtpEmailRequest) List(java.util.List) SendEmailOperation(io.lumeer.core.task.executor.operation.SendEmailOperation) EmailSecurityType(io.lumeer.core.util.EmailSecurityType) Optional(java.util.Optional) Attribute(io.lumeer.api.model.Attribute) WithId(io.lumeer.api.model.common.WithId) SendSmtpEmailOperation(io.lumeer.core.task.executor.operation.SendSmtpEmailOperation) ChangesTracker(io.lumeer.core.task.executor.ChangesTracker) LongAdder(java.util.concurrent.atomic.LongAdder) LinkOperation(io.lumeer.core.task.executor.operation.LinkOperation) Engine(com.floreysoft.jmte.Engine) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocumentCreationOperation(io.lumeer.core.task.executor.operation.DocumentCreationOperation) SendEmailRequest(io.lumeer.core.task.executor.request.SendEmailRequest) HashMap(java.util.HashMap) AllowedPermissions(io.lumeer.api.model.AllowedPermissions) ArrayList(java.util.ArrayList) NavigationOperation(io.lumeer.core.task.executor.operation.NavigationOperation) SearchQueryStem(io.lumeer.storage.api.query.SearchQueryStem) HashSet(java.util.HashSet) Language(io.lumeer.api.model.Language) LinkCreationOperation(io.lumeer.core.task.executor.operation.LinkCreationOperation) PrintRequest(io.lumeer.core.task.executor.request.PrintRequest) DocumentRemovalOperation(io.lumeer.core.task.executor.operation.DocumentRemovalOperation) Query(io.lumeer.api.model.Query) ResourceOperation(io.lumeer.core.task.executor.operation.ResourceOperation) ContextualTask(io.lumeer.core.task.ContextualTask) LinkTypeUtil(io.lumeer.api.util.LinkTypeUtil) Task(io.lumeer.core.task.Task) PermissionUtils(io.lumeer.api.util.PermissionUtils) IOException(java.io.IOException) UserMessageRequest(io.lumeer.core.task.executor.request.UserMessageRequest) NavigationRequest(io.lumeer.core.task.executor.request.NavigationRequest) SmtpConfiguration(io.lumeer.core.task.executor.request.SmtpConfiguration) SearchQuery(io.lumeer.storage.api.query.SearchQuery) AddDocumentFileAttachmentOperation(io.lumeer.core.task.executor.operation.AddDocumentFileAttachmentOperation) DocumentUtils(io.lumeer.core.util.DocumentUtils) FileAttachment(io.lumeer.api.model.FileAttachment) Collectors.toList(java.util.stream.Collectors.toList) ResourceVariable(io.lumeer.api.model.ResourceVariable) PdfCreator(io.lumeer.core.pdf.PdfCreator) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) Query(io.lumeer.api.model.Query) SearchQuery(io.lumeer.storage.api.query.SearchQuery) Language(io.lumeer.api.model.Language) RoleType(io.lumeer.api.model.RoleType) DocumentRemovalOperation(io.lumeer.core.task.executor.operation.DocumentRemovalOperation) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) View(io.lumeer.api.model.View) IOException(java.io.IOException)

Example 3 with Language

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;
    }
}
Also used : AllowedPermissions(io.lumeer.api.model.AllowedPermissions) Query(io.lumeer.api.model.Query) SearchQuery(io.lumeer.storage.api.query.SearchQuery) Language(io.lumeer.api.model.Language) RoleType(io.lumeer.api.model.RoleType) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) View(io.lumeer.api.model.View) IOException(java.io.IOException)

Example 4 with Language

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());
}
Also used : TemplateMetadata(io.lumeer.api.model.TemplateMetadata) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ProjectFacade(io.lumeer.core.facade.ProjectFacade) Path(javax.ws.rs.Path) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Inject(javax.inject.Inject) Project(io.lumeer.api.model.Project) OrganizationDao(io.lumeer.storage.api.dao.OrganizationDao) List(java.util.List) MediaType(javax.ws.rs.core.MediaType) Language(io.lumeer.api.model.Language) QueryParam(javax.ws.rs.QueryParam) RequestScoped(javax.enterprise.context.RequestScoped) BadRequestException(javax.ws.rs.BadRequestException) RequestDataKeeper(io.lumeer.core.auth.RequestDataKeeper) TemplateFacade(io.lumeer.core.facade.TemplateFacade) Language(io.lumeer.api.model.Language) GET(javax.ws.rs.GET)

Example 5 with Language

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);
        }
    });
}
Also used : User(io.lumeer.api.model.User) HashMap(java.util.HashMap) UserNotification(io.lumeer.api.model.UserNotification) Language(io.lumeer.api.model.Language) Collection(io.lumeer.api.model.Collection) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

Language (io.lumeer.api.model.Language)5 ArrayList (java.util.ArrayList)3 AllowedPermissions (io.lumeer.api.model.AllowedPermissions)2 Collection (io.lumeer.api.model.Collection)2 Document (io.lumeer.api.model.Document)2 Query (io.lumeer.api.model.Query)2 RoleType (io.lumeer.api.model.RoleType)2 User (io.lumeer.api.model.User)2 View (io.lumeer.api.model.View)2 List (java.util.List)2 Engine (com.floreysoft.jmte.Engine)1 SelectedWorkspace (io.lumeer.api.SelectedWorkspace)1 Attribute (io.lumeer.api.model.Attribute)1 FileAttachment (io.lumeer.api.model.FileAttachment)1 Group (io.lumeer.api.model.Group)1 InitialUserData (io.lumeer.api.model.InitialUserData)1 LinkInstance (io.lumeer.api.model.LinkInstance)1 LinkType (io.lumeer.api.model.LinkType)1 NotificationSetting (io.lumeer.api.model.NotificationSetting)1 Project (io.lumeer.api.model.Project)1