/src/main/java/net/frontlinesms/data/repository/MessageDao.java

https://github.com/ssembajjwe/frontlinesms-core · Java · 243 lines · 34 code · 28 blank · 181 comment · 0 complexity · 3c9aed9bd9b3aa9adaf75d63b2661cc9 MD5 · raw file

  1. /*
  2. * FrontlineSMS <http://www.frontlinesms.com>
  3. * Copyright 2007, 2008 kiwanja
  4. *
  5. * This file is part of FrontlineSMS.
  6. *
  7. * FrontlineSMS is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * FrontlineSMS is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with FrontlineSMS. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. package net.frontlinesms.data.repository;
  21. import java.util.Collection;
  22. import java.util.List;
  23. import net.frontlinesms.data.Order;
  24. import net.frontlinesms.data.domain.*;
  25. import net.frontlinesms.data.domain.FrontlineMessage.Field;
  26. /**
  27. * Factory for creating instances of net.frontlinesms.data.Message
  28. * @author Alex
  29. */
  30. public interface MessageDao {
  31. /**
  32. * Gets all messages for the specified number.
  33. * @param type
  34. * @param number
  35. * @param sortBy Message Field to sort the results by
  36. * @param order direction to order results in
  37. * @param start TODO
  38. * @param end TODO
  39. * @param startIndex
  40. * @param limit the maximum number of messages to recover
  41. * @param index the result index of the messages to recover
  42. * @return
  43. */
  44. public List<FrontlineMessage> getMessagesForMsisdn(FrontlineMessage.Type type, String number, Field sortBy, Order order, Long start, Long end, int startIndex, int limit);
  45. /**
  46. * Gets all messages for the specified number.
  47. * @param number
  48. * @param sortBy Message Field to sort the results by
  49. * @param order direction to order results in
  50. * @param start TODO
  51. * @param end TODO
  52. * @param limit the maximum number of messages to recover
  53. * @param index the result index of the messages to recover
  54. * @return
  55. */
  56. public List<FrontlineMessage> getMessagesForMsisdn(FrontlineMessage.Type type, String number, Field sortBy, Order order, Long start, Long end);
  57. /**
  58. * Gets message count for the specified number.
  59. * @param number
  60. * @param start TODO
  61. * @param end TODO
  62. * @return
  63. */
  64. public int getMessageCountForMsisdn(FrontlineMessage.Type type, String number, Long start, Long end);
  65. /**
  66. * Gets count of SMS sent for the specified number.
  67. * @param number
  68. * @param start TODO
  69. * @param end TODO
  70. * @return
  71. */
  72. public int getSMSCountForMsisdn(String number, Long start, Long end);
  73. /**
  74. * Gets count of SMS sent.
  75. * @param start TODO
  76. * @param end TODO
  77. * @return
  78. */
  79. public int getSMSCount(Long start, Long end);
  80. /**
  81. * Gets count of SMS sent for the specified keyword.
  82. * @param keyword
  83. * @param start TODO
  84. * @param end TODO
  85. * @return
  86. */
  87. public int getSMSCountForKeyword(Keyword keyword, Long start, Long end);
  88. /**
  89. * Gets all messages of a particular type (SENT, RECEIVED, ALL) which begin with the specified keyword. If
  90. * the supplied keyword is NULL, it will be ignored (i.e. all messages of requested type will be returned).
  91. * @param messageType message type(s) to be retrieved, or Message.TYPE_ALL for all messages
  92. * @param keyword word messages should start with, or NULL to retrieve all messages
  93. * @param sortBy Message Field to sort the results by
  94. * @param order direction to order results in
  95. * @param start TODO
  96. * @param end TODO
  97. * @param limit the maximum number of messages to recover
  98. * @param index the result index of the messages to recover
  99. * @return
  100. * FIXME keyword should never be null for this method, and messageType should be understood to
  101. * be TYPE_RECEIVED always. If other functionality is required, the method should be renamed
  102. * or new methods created.
  103. */
  104. public List<FrontlineMessage> getMessagesForKeyword(FrontlineMessage.Type messageType, Keyword keyword, Field sortBy, Order order, Long start, Long end, int startIndex, int limit);
  105. /**
  106. * Gets all messages of a particular type (SENT, RECEIVED, ALL).
  107. * @param messageType message type(s) to be retrieved, or Message.TYPE_ALL for all messages
  108. * @param sortBy Message Field to sort the results by
  109. * @param order direction to order results in
  110. * @return
  111. */
  112. public List<FrontlineMessage> getMessages(FrontlineMessage.Type messageType, Field sortBy, Order order);
  113. /**
  114. * Gets all messages of a particular type (SENT, RECEIVED, ALL) which begin with the specified keyword.
  115. * @param messageType message type(s) to be retrieved, or Message.TYPE_ALL for all messages
  116. * @param keyword word messages should start with
  117. * @return
  118. */
  119. public List<FrontlineMessage> getMessagesForKeyword(FrontlineMessage.Type messageType, Keyword keyword);
  120. public List<FrontlineMessage> getMessagesForKeyword(FrontlineMessage.Type messageType, Keyword keyword, Long start, Long end);
  121. public List<FrontlineMessage> getMessagesForStati(FrontlineMessage.Type messageType, FrontlineMessage.Status[] messageStatuses, Field sortBy, Order order, int startIndex, int limit);
  122. /**
  123. * Get the total number of messages with the supplied statuses.
  124. * @param messageType
  125. * @param messageStati
  126. * @return
  127. */
  128. public int getMessageCount(FrontlineMessage.Type messageType, FrontlineMessage.Status... messageStatuses);
  129. /**
  130. * Gets all messages of a particular type (SENT, RECEIVED, ALL) which begin with the specified keyword. If
  131. * the supplied keyword is NULL, it will be ignored (i.e. all messages of requested type will be returned).
  132. *
  133. * @param messageType message type(s) to be retrieved, or Message.TYPE_ALL for all messages
  134. * @param keyword word messages should start with, or NULL to retrieve all messages
  135. * @param sortBy Message Field to sort the results by
  136. * @param order direction to order results in
  137. * @param index the result index of the messages to recover
  138. * @param limit the maximum number of messages to recover
  139. * @return
  140. */
  141. public List<FrontlineMessage> getMessages(FrontlineMessage.Type messageType, Keyword keyword, Field sortBy, Order order);
  142. /**
  143. * Gets all messages.
  144. * @return all messages in the system
  145. */
  146. public List<FrontlineMessage> getAllMessages();
  147. /**
  148. * Gets a page of messages.
  149. * @param type the type of the message
  150. * @param field the field to sort by
  151. * @param order the order to sort by
  152. * @param start the start date for the messages
  153. * @param end the end date for the messages
  154. * @param startIndex the index of the first message to get
  155. * @param limit the maximum number of messages to get
  156. * @return list of all messages conforming to the specified constraints and sorted in a particular way.
  157. *
  158. */
  159. public List<FrontlineMessage> getAllMessages(FrontlineMessage.Type type, Field field, Order order, Long start, Long end, int startIndex, int limit);
  160. /**
  161. * Gets the number of messages of a specific type from between the specified dates
  162. * @param type
  163. * @param start the start date as a java timestamp, or <code>null</code> for no start date restriction
  164. * @param end the end date as a java timestamp, or <code>null</code> for no start date restriction
  165. * @return count of messages
  166. */
  167. public int getMessageCount(FrontlineMessage.Type type, Long start, Long end);
  168. /**
  169. * Gets all messages with the supplied status and type.
  170. * @param type
  171. * @param status
  172. * @return
  173. */
  174. public Collection<FrontlineMessage> getMessages(FrontlineMessage.Type type, FrontlineMessage.Status... status);
  175. /**
  176. * Gets the number of messagesthere are of the given type for the given keyword.
  177. * @param messageType
  178. * @param keyword
  179. * @param start
  180. * @param end
  181. * @return
  182. */
  183. public int getMessageCount(FrontlineMessage.Type messageType, Keyword keyword, Long start, Long end);
  184. /**
  185. * Gets the outgoing message with the matching SMSC Reference Number sent to
  186. * a number ending with the supplied msisdn suffix.
  187. * @param targetMsisdnSuffix last N digits of the target's msisdn
  188. * @param smscReference
  189. * @return
  190. */
  191. public FrontlineMessage getMessageForStatusUpdate(String targetMsisdnSuffix, int smscReference);
  192. /** @return the number of messages sent to the specified phone numbers within the specified dates */
  193. public int getMessageCount(FrontlineMessage.Type messageType, List<String> phoneNumbers, Long messageHistoryStart, Long messageHistoryEnd);
  194. /** @return the messages sent or received to/from the specified phone numbers within the specified dates */
  195. public List<FrontlineMessage> getMessages(FrontlineMessage.Type messageType, List<String> phoneNumbers, Long messageHistoryStart, Long messageHistoryEnd);
  196. /** @return the messages sent or received to/from the specified phone numbers within the specified dates */
  197. public List<FrontlineMessage> getMessages(FrontlineMessage.Type messageType, List<String> phoneNumbers, Long messageHistoryStart, Long messageHistoryEnd, int startIndex, int limit);
  198. /** @return all messages sent or received within the specified dates */
  199. public List<FrontlineMessage> getMessages(FrontlineMessage.Type messageType, Long messageHistoryStart, Long messageHistoryEnd);
  200. /**
  201. * Delete the supplied message to the data source.
  202. * @param message the message to be deleted
  203. */
  204. public void deleteMessage(FrontlineMessage message);
  205. /**
  206. * Save the supplied message to the data source.
  207. * @param message the message to be saved
  208. */
  209. public void saveMessage(FrontlineMessage message);
  210. /**
  211. * Update the supplied message in the data source.
  212. * @param message the message to be updated
  213. */
  214. public void updateMessage(FrontlineMessage message);
  215. }