Package in.partake.model.dto

Examples of in.partake.model.dto.UserReceivedMessage


public class UserReceivedMessageTestDataProvider extends TestDataProvider<UserReceivedMessage> {
    @Override
    public UserReceivedMessage create(long pkNumber, String pkSalt, int objNumber) {
        UUID uuid = new UUID(pkNumber, pkSalt.hashCode());
        return new UserReceivedMessage(uuid, "senderId", "receiverId", "eventId", "messageId",
                false, MessageDelivery.SUCCESS, null, null, new DateTime(objNumber), null);
    }
View Full Code Here


    }

    @Override
    public List<UserReceivedMessage> createSamples() {
        List<UserReceivedMessage> array = new ArrayList<UserReceivedMessage>();
        array.add(new UserReceivedMessage(new UUID(0, 0), "senderId", "receiverId", "eventId", "messageId", false, MessageDelivery.SUCCESS, null, null, new DateTime(0L), null));
        array.add(new UserReceivedMessage(new UUID(0, 1), "senderId", "receiverId", "eventId", "messageId", false, MessageDelivery.SUCCESS, null, null, new DateTime(0L), null));
        array.add(new UserReceivedMessage(new UUID(0, 0), "senderId1", "receiverId", "eventId", "messageId", false, MessageDelivery.SUCCESS, null, null, new DateTime(0L), null));
        array.add(new UserReceivedMessage(new UUID(0, 0), "senderId", "receiverId1", "eventId", "messageId", false, MessageDelivery.SUCCESS, null, null, new DateTime(0L), null));
        array.add(new UserReceivedMessage(new UUID(0, 0), "senderId", "receiverId", "eventId1", "messageId", false, MessageDelivery.SUCCESS, null, null, new DateTime(0L), null));
        array.add(new UserReceivedMessage(new UUID(0, 0), "senderId", "receiverId", "eventId", "messageId1", false, MessageDelivery.SUCCESS, null, null, new DateTime(0L), null));
        array.add(new UserReceivedMessage(new UUID(0, 0), "senderId", "receiverId", "eventId", "messageId", true, MessageDelivery.SUCCESS, null, null, new DateTime(0L), null));
        array.add(new UserReceivedMessage(new UUID(0, 0), "senderId", "receiverId", "eventId", "messageId", false, MessageDelivery.FAIL, null, null, new DateTime(0L), null));
        array.add(new UserReceivedMessage(new UUID(0, 0), "senderId", "receiverId", "eventId", "messageId", false, MessageDelivery.SUCCESS, new DateTime(1L), null, new DateTime(0L), null));
        array.add(new UserReceivedMessage(new UUID(0, 0), "senderId", "receiverId", "eventId", "messageId", false, MessageDelivery.SUCCESS, null, new DateTime(1L), new DateTime(0L), null));
        array.add(new UserReceivedMessage(new UUID(0, 0), "senderId", "receiverId", "eventId", "messageId", false, MessageDelivery.SUCCESS, null, null, new DateTime(1L), null));
        array.add(new UserReceivedMessage(new UUID(0, 0), "senderId", "receiverId", "eventId", "messageId", false, MessageDelivery.SUCCESS, null, null, new DateTime(0L), new DateTime(1L)));
        return array;
    }
View Full Code Here

    @Override
    public void createFixtures(PartakeConnection con, IPartakeDAOs daos) throws DAOException {
        IUserReceivedMessageAccess dao = daos.getUserReceivedMessageAccess();
        dao.truncate(con);

        dao.put(con, new UserReceivedMessage(USER_RECEIVED_MESSAGE_INQUEUE_ID,
                DEFAULT_SENDER_ID, DEFAULT_RECEIVER_ID, DEFAULT_EVENT_ID, DEFAULT_MESSAGE_ID.toString(),
                false, MessageDelivery.INQUEUE, null, null, new DateTime(0L), null));
    }
View Full Code Here

                // InvalidAfter 後であれば、message を update して envelope を消去
                // TODO: Refine this code!
                if (envelope.getInvalidAfter() != null && envelope.getInvalidAfter().isBefore(TimeUtil.getCurrentDateTime())) {
                    Logger.warn("run : envelope id " + envelope.getId() + " could not be sent : Time out.");
                    if (envelope.getUserMessageId() != null) {
                        UserReceivedMessage userMessage = daos.getUserReceivedMessageAccess().find(con, UUID.fromString(envelope.getUserMessageId()));
                        if (userMessage != null) {
                            UserReceivedMessage message = new UserReceivedMessage(userMessage);
                            message.setDelivery(MessageDelivery.FAIL);
                            message.setModifiedAt(TimeUtil.getCurrentDateTime());
                            daos.getUserReceivedMessageAccess().put(con, message);
                        }
                    }

                    if (envelope.getTwitterMessageId() != null) {
                        TwitterMessage twitterMessage = daos.getTwitterMessageAccess().find(con, envelope.getTwitterMessageId());
                        if (twitterMessage != null) {
                            TwitterMessage message = new TwitterMessage(twitterMessage);
                            message.setDelivery(MessageDelivery.FAIL);
                            message.setModifiedAt(TimeUtil.getCurrentDateTime());
                            daos.getTwitterMessageAccess().put(con, message);
                        }
                    }

                    if (envelope.getUserNotificationId() != null) {
                        UserNotification notification = daos.getUserNotificationAccess().find(con, envelope.getUserNotificationId());
                        if (notification != null) {
                            UserNotification message = new UserNotification(notification);
                            message.setDelivery(MessageDelivery.FAIL);
                            message.setModifiedAt(TimeUtil.getCurrentDateTime());
                            daos.getUserNotificationAccess().put(con, message);
                        }
                    }

                    it.remove();
View Full Code Here

     * Envelope を送信する。true を返すと送ることができた / もうこれ以上送ってはいけないという意味になる。
     * @param envelope
     * @return
     */
    private void sendUserMessage(PartakeConnection con, IPartakeDAOs daos, DataIterator<MessageEnvelope> it, MessageEnvelope envelope) throws DAOException {
        UserReceivedMessage userMessage = daos.getUserReceivedMessageAccess().find(con, UUID.fromString(envelope.getUserMessageId()));
        if (userMessage == null) {
            didSendUserMessage(con, daos, it, envelope, userMessage, MessageDelivery.FAIL);
            return;
        }

        UserEx receiver = UserDAOFacade.getUserEx(con, daos, userMessage.getReceiverId());
        if (receiver == null) {
            didSendUserMessage(con, daos, it, envelope, userMessage, MessageDelivery.FAIL);
            return;
        }

        UserPreference pref = daos.getUserPreferenceAccess().find(con, receiver.getId());
        if (pref == null)
            pref = UserPreference.getDefaultPreference(receiver.getId());

        // twitter message を受け取らない設定になっていれば送らない。
        if (!pref.isReceivingTwitterMessage()) {
            didSendUserMessage(con, daos, it, envelope, userMessage, MessageDelivery.NOT_DELIVERED);
            return;
        }

        UserTwitterLink twitterLinkage = receiver.getTwitterLinkage();
        if (twitterLinkage == null || !twitterLinkage.isAuthorized()) {
            Logger.warn("sendDirectMessage : envelope id " + envelope.getId() + " could not be sent : No access token");
            didSendUserMessage(con, daos, it, envelope, userMessage, MessageDelivery.FAIL);
            return;
        }

        try {
            Message message = daos.getMessageAccess().find(con, UUID.fromString(userMessage.getMessageId()));
            long twitterId = twitterLinkage.getTwitterId();

            Event event = null;
            if (userMessage.getEventId() != null)
                event = daos.getEventAccess().find(con, userMessage.getEventId());

            String url = "http://partake.in/messages/" + userMessage.getId();
            String messageBody;
            if (event != null) {
                int rest = 140;
                String format = "[PRTK] %s 「%s」に関する新着メッセージがあります。 : %s";
                rest -= Util.codePointCount(format);
View Full Code Here

        }
    }

    private void didSendUserMessage(PartakeConnection con, IPartakeDAOs daos,
            DataIterator<MessageEnvelope> it, MessageEnvelope envelope, UserReceivedMessage message, MessageDelivery delivery) throws DAOException {
        UserReceivedMessage userMessage = new UserReceivedMessage(message);
        userMessage.setDelivery(delivery);
        userMessage.setModifiedAt(TimeUtil.getCurrentDateTime());

        daos.getUserReceivedMessageAccess().put(con, userMessage);
        it.remove();
    }
View Full Code Here

import java.util.UUID;

public class MessageDAOFacade {

    public static UserMessageEx findUserReceivedMessage(PartakeConnection con, IPartakeDAOs daos, UUID messageId) throws DAOException {
        UserReceivedMessage receivedMessage = daos.getUserReceivedMessageAccess().find(con, messageId);
        if (receivedMessage == null)
            return null;

        UserEx sender = UserDAOFacade.getUserEx(con, daos, receivedMessage.getSenderId());
        if (sender == null)
            return null;

        Event event = daos.getEventAccess().find(con, receivedMessage.getEventId());
        if (event == null)
            return null;

        Message message = daos.getMessageAccess().find(con, UUID.fromString(receivedMessage.getMessageId()));
        if (message == null)
            return null;

        return new UserMessageEx(receivedMessage, sender, event, message);
    }
View Full Code Here

                pref = UserPreference.getDefaultPreference(participation.getUserId());

            MessageDelivery delivery = pref.isReceivingTwitterMessage() ? MessageDelivery.INQUEUE : MessageDelivery.NOT_DELIVERED;

            UUID userMessageId = daos.getUserReceivedMessageAccess().getFreshId(con);
            UserReceivedMessage userMessage = new UserReceivedMessage(userMessageId, sender.getId(), participation.getUserId(), eventId, messageId.toString(),
                    false, delivery, null, null, TimeUtil.getCurrentDateTime(), null);
            daos.getUserReceivedMessageAccess().put(con, userMessage);

            if (delivery == MessageDelivery.NOT_DELIVERED)
                continue;
View Full Code Here

import org.codehaus.jackson.node.ObjectNode;

class EntityUserReceivedMessageMapper extends Postgres9EntityDataMapper<UserReceivedMessage> {
    public UserReceivedMessage map(ObjectNode obj) {
        return new UserReceivedMessage(obj).freeze();
    }
View Full Code Here

        if (!user.getId().equals(message.getReceiverId()))
            throw new PartakeException(UserErrorCode.FORBIDDEN_MESSAGE_SHOW);

        if (!message.isOpened()) {
            UserReceivedMessage newMessage = new UserReceivedMessage(message);
            newMessage.setOpened(true);
            newMessage.setModifiedAt(TimeUtil.getCurrentDateTime());
            daos.getUserReceivedMessageAccess().put(con, newMessage);
        }

        return message;
    }
View Full Code Here

TOP

Related Classes of in.partake.model.dto.UserReceivedMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.