public static Message createTestProcessedMessage( String channelId, String serverId, long messageId, String content) { Calendar receivedDate = Calendar.getInstance(); Message message = new Message(); message.setMessageId(messageId); message.setChannelId(channelId); message.setServerId(serverId); message.setReceivedDate(receivedDate); message.setProcessed(true); ConnectorMessage sourceMessage = new ConnectorMessage( channelId, message.getMessageId(), 0, serverId, message.getReceivedDate(), Status.TRANSFORMED); message.getConnectorMessages().put(0, sourceMessage); ConnectorMessage destinationMessage = new ConnectorMessage( channelId, message.getMessageId(), 1, serverId, message.getReceivedDate(), Status.SENT); message.getConnectorMessages().put(1, destinationMessage); sourceMessage.setRaw( new MessageContent( channelId, message.getMessageId(), 0, ContentType.RAW, content, null, false)); destinationMessage.setRaw( new MessageContent( channelId, message.getMessageId(), 1, ContentType.RAW, content, null, false)); return message; }
@Override protected List<Message> getItems(int offset, int limit) throws Exception { List<Map<String, Object>> maps; SqlSession session = SqlConfig.getSqlSessionManager().openSession(); params.put("offset", offset); params.put("limit", limit); try { maps = session.selectList("Message.getMessagesToPrune", params); } finally { session.close(); } List<Message> messages = new ArrayList<Message>(); DonkeyDao dao = daoFactory.getDao(); try { for (Map<String, Object> map : maps) { Long messageId = (Long) map.get("id"); long connectorReceivedDateMillis = ((Calendar) map.get("mm_received_date")).getTimeInMillis(); Map<Integer, ConnectorMessage> connectorMessages = null; connectorMessages = dao.getConnectorMessages(channelId, messageId); Message message = new Message(); message.setMessageId(messageId); message.setChannelId(channelId); message.setReceivedDate((Calendar) map.get("received_date")); message.setProcessed((Boolean) map.get("processed")); message.setServerId((String) map.get("server_id")); message.setImportId((Long) map.get("import_id")); message.getConnectorMessages().putAll(connectorMessages); messages.add(message); contentMessageIds.add(messageId); if (messageDateThreshold != null && connectorReceivedDateMillis < messageDateThreshold.getTimeInMillis()) { messageIds.add(messageId); } } return messages; } finally { dao.close(); } }