Search in sources :

Example 1 with TaskContext

use of de.symeda.sormas.api.task.TaskContext in project SORMAS-Project by hzi-braunschweig.

the class TaskFacadeEjb method notifyAboutNewAssignee.

private void notifyAboutNewAssignee(Task task, User newAssignee, User oldAssignee) {
    // oldAssignee == null => it means it's a new task, this notification should only be sent in case the assignee is changed
    if (oldAssignee == null || Objects.equals(newAssignee, oldAssignee)) {
        return;
    }
    try {
        final TaskContext context = task.getTaskContext();
        final AbstractDomainObject associatedEntity = context == TaskContext.CASE ? task.getCaze() : context == TaskContext.CONTACT ? task.getContact() : context == TaskContext.EVENT ? task.getEvent() : null;
        Map<User, String> userMessages = new HashMap<>();
        userMessages.put(oldAssignee, getTaskNotificationMessage(task, associatedEntity, MessageContents.CONTENT_TASK_GENERAL_UPDATED_ASSIGNEE_SOURCE, MessageContents.CONTENT_TASK_SPECIFIC_UPDATED_ASSIGNEE_SOURCE));
        if (newAssignee != null) {
            userMessages.put(newAssignee, getTaskNotificationMessage(task, associatedEntity, MessageContents.CONTENT_TASK_GENERAL_UPDATED_ASSIGNEE_TARGET, MessageContents.CONTENT_TASK_SPECIFIC_UPDATED_ASSIGNEE_TARGET));
        }
        notificationService.sendNotifications(NotificationType.TASK_UPDATED_ASSIGNEE, MessageSubject.TASK_UPDATED_ASSIGNEE, () -> userMessages);
    } catch (NotificationDeliveryFailedException e) {
        logger.error(String.format("EmailDeliveryFailedException when trying to notify a user about an updated task assignee."));
    }
}
Also used : TaskContext(de.symeda.sormas.api.task.TaskContext) User(de.symeda.sormas.backend.user.User) HashMap(java.util.HashMap) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) NotificationDeliveryFailedException(de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException)

Example 2 with TaskContext

use of de.symeda.sormas.api.task.TaskContext in project SORMAS-Project by hzi-braunschweig.

the class TaskEditForm method updateByTaskContext.

private void updateByTaskContext() {
    TaskContext taskContext = (TaskContext) getFieldGroup().getField(TaskDto.TASK_CONTEXT).getValue();
    // Task types depending on task context
    ComboBox taskType = (ComboBox) getFieldGroup().getField(TaskDto.TASK_TYPE);
    FieldHelper.updateItems(taskType, TaskType.getTaskTypes(taskContext), FieldVisibilityCheckers.withDisease(disease), TaskType.class);
    // context reference depending on task context
    ComboBox caseField = (ComboBox) getFieldGroup().getField(TaskDto.CAZE);
    ComboBox eventField = (ComboBox) getFieldGroup().getField(TaskDto.EVENT);
    ComboBox contactField = (ComboBox) getFieldGroup().getField(TaskDto.CONTACT);
    if (taskContext != null) {
        switch(taskContext) {
            case CASE:
                FieldHelper.setFirstVisibleClearOthers(caseField, eventField, contactField);
                FieldHelper.setFirstRequired(caseField, eventField, contactField);
                break;
            case EVENT:
                FieldHelper.setFirstVisibleClearOthers(eventField, caseField, contactField);
                FieldHelper.setFirstRequired(eventField, caseField, contactField);
                break;
            case CONTACT:
                FieldHelper.setFirstVisibleClearOthers(contactField, caseField, eventField);
                FieldHelper.setFirstRequired(contactField, caseField, eventField);
                break;
            case GENERAL:
                FieldHelper.setFirstVisibleClearOthers(null, caseField, contactField, eventField);
                FieldHelper.setFirstRequired(null, caseField, contactField, eventField);
                break;
        }
    } else {
        FieldHelper.setFirstVisibleClearOthers(null, caseField, eventField, contactField);
        FieldHelper.setFirstRequired(null, caseField, eventField, contactField);
    }
}
Also used : TaskContext(de.symeda.sormas.api.task.TaskContext) ComboBox(com.vaadin.v7.ui.ComboBox)

Example 3 with TaskContext

use of de.symeda.sormas.api.task.TaskContext in project SORMAS-Project by hzi-braunschweig.

the class TaskFacadeEjb method buildTaskUserMessages.

private Map<User, String> buildTaskUserMessages(List<Task> tasks, String generalMessageTag, String specificMessageTag) {
    final Map<User, String> messages = new HashMap<>();
    for (Task task : tasks) {
        final TaskContext context = task.getTaskContext();
        final AbstractDomainObject associatedEntity = context == TaskContext.CASE ? task.getCaze() : context == TaskContext.CONTACT ? task.getContact() : context == TaskContext.EVENT ? task.getEvent() : null;
        String message = getTaskNotificationMessage(task, associatedEntity, generalMessageTag, specificMessageTag);
        if (task.getAssigneeUser() != null) {
            messages.put(task.getAssigneeUser(), message);
        }
        if (task.getObserverUsers() != null) {
            String observerUserMessage = I18nProperties.getString(MessageContents.CONTENT_TASK_OBSERVER_INFORMATION) + "\n\n" + message;
            for (User observerUser : task.getObserverUsers()) {
                messages.put(observerUser, observerUserMessage);
            }
        }
    }
    return messages;
}
Also used : User(de.symeda.sormas.backend.user.User) TaskContext(de.symeda.sormas.api.task.TaskContext) HashMap(java.util.HashMap) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject)

Aggregations

TaskContext (de.symeda.sormas.api.task.TaskContext)3 AbstractDomainObject (de.symeda.sormas.backend.common.AbstractDomainObject)2 User (de.symeda.sormas.backend.user.User)2 HashMap (java.util.HashMap)2 ComboBox (com.vaadin.v7.ui.ComboBox)1 NotificationDeliveryFailedException (de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException)1