Search in sources :

Example 6 with MessageConversation

use of org.hisp.dhis.message.MessageConversation in project dhis2-core by dhis2.

the class SystemUpdateService method sendMessageForEachVersion.

public void sendMessageForEachVersion(Map<Semver, Map<String, String>> patchVersions) {
    Set<User> recipients = getRecipients();
    for (Map.Entry<Semver, Map<String, String>> entry : patchVersions.entrySet()) {
        Semver version = entry.getKey();
        Map<String, String> message = entry.getValue();
        for (User recipient : recipients) {
            // Check if message has been sent before using
            // version.getValue() as extMessageId
            List<MessageConversation> existingMessages = messageService.getMatchingExtId(version.getValue());
            if (existingMessages.isEmpty()) {
                MessageConversationParams params = new MessageConversationParams.Builder().withRecipients(ImmutableSet.of(recipient)).withSubject(NEW_VERSION_AVAILABLE_MESSAGE_SUBJECT).withText(buildMessageText(message)).withMessageType(MessageType.SYSTEM).withExtMessageId(version.getValue()).build();
                messageService.sendMessage(params);
            }
        }
    }
}
Also used : User(org.hisp.dhis.user.User) MessageConversationParams(org.hisp.dhis.message.MessageConversationParams) MessageConversation(org.hisp.dhis.message.MessageConversation) Semver(com.vdurmont.semver4j.Semver) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 7 with MessageConversation

use of org.hisp.dhis.message.MessageConversation in project dhis2-core by dhis2.

the class CurrentUserController method getInboxMessageConversations.

@RequestMapping(value = "/inbox/messageConversations", produces = { "application/json", "text/*" })
public void getInboxMessageConversations(HttpServletResponse response) throws Exception {
    User user = currentUserService.getCurrentUser();
    if (user == null) {
        throw new NotAuthenticatedException();
    }
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    List<MessageConversation> messageConversations = new ArrayList<>(messageService.getMessageConversations(0, MAX_OBJECTS));
    for (org.hisp.dhis.message.MessageConversation messageConversation : messageConversations) {
        messageConversation.setAccess(aclService.getAccess(messageConversation, user));
    }
    renderService.toJson(response.getOutputStream(), messageConversations);
}
Also used : User(org.hisp.dhis.user.User) NotAuthenticatedException(org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException) MessageConversation(org.hisp.dhis.message.MessageConversation) ArrayList(java.util.ArrayList) MessageConversation(org.hisp.dhis.message.MessageConversation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with MessageConversation

use of org.hisp.dhis.message.MessageConversation in project dhis2-core by dhis2.

the class ToggleFollowUpAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    MessageConversation conversation = messageService.getMessageConversation(id);
    message = String.valueOf(conversation.toggleFollowUp(currentUserService.getCurrentUser()));
    messageService.updateMessageConversation(conversation);
    return SUCCESS;
}
Also used : MessageConversation(org.hisp.dhis.message.MessageConversation)

Example 9 with MessageConversation

use of org.hisp.dhis.message.MessageConversation in project dhis2-core by dhis2.

the class SendReplyAction method execute.

// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    Assert.hasText(text, "Text must be defined");
    String metaData = MessageService.META_USER_AGENT + ServletActionContext.getRequest().getHeader(ContextUtils.HEADER_USER_AGENT);
    MessageConversation conversation = messageService.getMessageConversation(conversationId);
    messageService.sendReply(conversation, text, metaData, false);
    return SUCCESS;
}
Also used : MessageConversation(org.hisp.dhis.message.MessageConversation)

Example 10 with MessageConversation

use of org.hisp.dhis.message.MessageConversation in project dhis2-core by dhis2.

the class HibernateMessageConversationStore method mapRowToMessageConversations.

private MessageConversation mapRowToMessageConversations(Object[] row) {
    MessageConversation mc = (MessageConversation) row[0];
    UserMessage um = (UserMessage) row[1];
    User ui = (User) row[2];
    User ls = (User) row[3];
    mc.setRead(um.isRead());
    mc.setFollowUp(um.isFollowUp());
    if (ui != null) {
        mc.setUserFirstname(ui.getFirstName());
        mc.setUserSurname(ui.getSurname());
    }
    if (ls != null) {
        mc.setLastSenderFirstname(ls.getFirstName());
        mc.setLastSenderSurname(ls.getSurname());
    }
    return mc;
}
Also used : User(org.hisp.dhis.user.User) MessageConversation(org.hisp.dhis.message.MessageConversation) UserMessage(org.hisp.dhis.message.UserMessage)

Aggregations

MessageConversation (org.hisp.dhis.message.MessageConversation)10 User (org.hisp.dhis.user.User)4 NotAuthenticatedException (org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Semver (com.vdurmont.semver4j.Semver)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Interpretation (org.hisp.dhis.interpretation.Interpretation)1 MessageConversationParams (org.hisp.dhis.message.MessageConversationParams)1 UserMessage (org.hisp.dhis.message.UserMessage)1 Inbox (org.hisp.dhis.webapi.webdomain.user.Inbox)1