Skip to content

Commit

Permalink
Sorting implementation for Logs/Messages and Recordings (#2992)
Browse files Browse the repository at this point in the history
Sorting implementation for Logs/Messages, Logs/Recordings and Logs/Notifications
  • Loading branch information
Antonis Tsakiridis authored Jul 16, 2018
1 parent 88332e4 commit 95e4148
Show file tree
Hide file tree
Showing 42 changed files with 2,381 additions and 470 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,60 +119,59 @@
</if>
<choose>
<when test="sortByDate != null">
<if test="sortByDate.name() == 'ASCENDING'">
<if test="sortByDate.name() == 'ASC'">
order by date_created ASC
</if>
<if test="sortByDate.name() == 'DESCENDING'">
<if test="sortByDate.name() == 'DESC'">
order by date_created DESC
</if>
</when>
<when test="sortByFrom != null">
<if test="sortByFrom.name() == 'ASCENDING'">
order by sender ASC
<if test="sortByFrom.name() == 'ASC'">
order by sender ASC, date_created DESC
</if>
<if test="sortByFrom.name() == 'DESCENDING'">
order by sender DESC
<if test="sortByFrom.name() == 'DESC'">
order by sender DESC, date_created DESC
</if>
</when>

<when test="sortByTo != null">
<if test="sortByTo.name() == 'ASCENDING'">
order by recipient ASC
<if test="sortByTo.name() == 'ASC'">
order by recipient ASC, date_created DESC
</if>
<if test="sortByTo.name() == 'DESCENDING'">
order by recipient DESC
<if test="sortByTo.name() == 'DESC'">
order by recipient DESC, date_created DESC
</if>
</when>
<when test="sortByDirection != null">
<if test="sortByDirection.name() == 'ASCENDING'">
order by direction ASC
<if test="sortByDirection.name() == 'ASC'">
order by direction ASC, date_created DESC
</if>
<if test="sortByDirection.name() == 'DESCENDING'">
order by direction DESC
<if test="sortByDirection.name() == 'DESC'">
order by direction DESC, date_created DESC
</if>
</when>
<when test="sortByStatus != null">
<if test="sortByStatus.name() == 'ASCENDING'">
order by status ASC
<if test="sortByStatus.name() == 'ASC'">
order by status ASC, date_created DESC
</if>
<if test="sortByStatus.name() == 'DESCENDING'">
order by status DESC
<if test="sortByStatus.name() == 'DESC'">
order by status DESC, date_created DESC
</if>
</when>
<when test="sortByDuration != null">
<if test="sortByDuration.name() == 'ASCENDING'">
order by duration ASC
<if test="sortByDuration.name() == 'ASC'">
order by duration ASC, date_created DESC
</if>
<if test="sortByDuration.name() == 'DESCENDING'">
order by duration DESC
<if test="sortByDuration.name() == 'DESC'">
order by duration DESC, date_created DESC
</if>
</when>
<when test="sortByPrice != null">
<if test="sortByPrice.name() == 'ASCENDING'">
order by cast(price as unsigned) ASC
<if test="sortByPrice.name() == 'ASC'">
order by cast(price as unsigned) ASC, date_created DESC
</if>
<if test="sortByPrice.name() == 'DESCENDING'">
order by cast(price as unsigned) DESC
<if test="sortByPrice.name() == 'DESC'">
order by cast(price as unsigned) DESC, date_created DESC
</if>
</when>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,53 @@
<if test="endTime != null">
AND date_created &lt;= DATE_ADD(#{endTime},INTERVAL 1 DAY)
</if>
order by date_created
LIMIT #{limit} OFFSET #{offset}
<choose>
<when test="sortByDate != null">
<if test="sortByDate.name() == 'ASC'">
order by date_created ASC
</if>
<if test="sortByDate.name() == 'DESC'">
order by date_created DESC
</if>
</when>
<when test="sortByLog != null">
<if test="sortByLog.name() == 'ASC'">
order by log ASC, date_created DESC
</if>
<if test="sortByLog.name() == 'DESC'">
order by log DESC, date_created DESC
</if>
</when>
<when test="sortByErrorCode != null">
<if test="sortByErrorCode.name() == 'ASC'">
order by error_code ASC, date_created DESC
</if>
<if test="sortByErrorCode.name() == 'DESC'">
order by error_code DESC, date_created DESC
</if>
</when>
<when test="sortByCallSid != null">
<if test="sortByCallSid.name() == 'ASC'">
order by call_sid ASC, date_created DESC
</if>
<if test="sortByCallSid.name() == 'DESC'">
order by call_sid DESC, date_created DESC
</if>
</when>
<when test="sortByMessageText != null">
<if test="sortByMessageText.name() == 'ASC'">
order by message_text ASC, date_created DESC
</if>
<if test="sortByMessageText.name() == 'DESC'">
order by message_text DESC, date_created DESC
</if>
</when>
<otherwise>
order by date_created DESC
</otherwise>
</choose>
<if test="limit != null">
LIMIT #{limit} OFFSET #{offset}
</if>
</select>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,37 @@
<if test="endTime != null">
AND date_created &lt;= DATE_ADD(#{endTime},INTERVAL 1 DAY)
</if>
order by date_created
LIMIT #{limit} OFFSET #{offset}
<choose>
<when test="sortByDate != null">
<if test="sortByDate.name() == 'ASC'">
order by date_created ASC
</if>
<if test="sortByDate.name() == 'DESC'">
order by date_created DESC
</if>
</when>
<when test="sortByDuration != null">
<if test="sortByDuration.name() == 'ASC'">
order by duration ASC, date_created DESC
</if>
<if test="sortByDuration.name() == 'DESC'">
order by duration DESC, date_created DESC
</if>
</when>
<when test="sortByCallSid != null">
<if test="sortByCallSid.name() == 'ASC'">
order by call_sid ASC, date_created DESC
</if>
<if test="sortByCallSid.name() == 'DESC'">
order by call_sid DESC, date_created DESC
</if>
</when>
<otherwise>
order by date_created DESC
</otherwise>
</choose>
<if test="limit != null">
LIMIT #{limit} OFFSET #{offset}
</if>
</select>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
-->
<mapper namespace="org.mobicents.servlet.sip.restcomm.dao.SmsMessagesDao">
<insert id="addSmsMessage" parameterType="map">
INSERT INTO restcomm_sms_messages (sid, date_created, date_updated, date_sent,
INSERT INTO restcomm_sms_messages (sid, date_created, date_updated, date_sent,
account_sid, sender, recipient, body, status, direction,
price, api_version, uri, status_callback, status_callback_method) VALUES (#{sid},
price, api_version, uri, status_callback, status_callback_method) VALUES (#{sid},
#{date_created}, #{date_updated}, #{date_sent}, #{account_sid}, #{sender}, #{recipient}, #{body},
#{status}, #{direction}, #{price}, #{api_version}, #{uri}, #{status_callback},
#{status_callback_method});
Expand Down Expand Up @@ -76,7 +76,7 @@
</if>
<!-- select * from "restcomm_sms_messages" where "start_time" >= '2013-08-23' order by "start_time" ; -->
<if test="startTime != null">
AND date_created &gt;= #{startTime}
AND date_created &gt;= #{startTime}
</if>
<if test="endTime != null">
AND date_created &lt;= DATE_ADD(#{endTime},INTERVAL 1 DAY)
Expand Down Expand Up @@ -112,6 +112,9 @@
<if test="sender != null">
AND sender like #{sender}
</if>
<if test="status != null">
AND status like #{status}
</if>
<if test="body != null">
AND body like '%'|| #{body} ||'%'
</if>
Expand All @@ -122,8 +125,70 @@
<if test="endTime != null">
AND date_created &lt;= DATE_ADD(#{endTime},INTERVAL 1 DAY)
</if>
order by date_created
LIMIT #{limit} OFFSET #{offset}
<choose>
<when test="sortByDate != null">
<if test="sortByDate.name() == 'ASC'">
order by date_created ASC
</if>
<if test="sortByDate.name() == 'DESC'">
order by date_created DESC
</if>
</when>
<when test="sortByFrom != null">
<if test="sortByFrom.name() == 'ASC'">
order by sender ASC, date_created DESC
</if>
<if test="sortByFrom.name() == 'DESC'">
order by sender DESC, date_created DESC
</if>
</when>
<when test="sortByTo != null">
<if test="sortByTo.name() == 'ASC'">
order by recipient ASC, date_created DESC
</if>
<if test="sortByTo.name() == 'DESC'">
order by recipient DESC, date_created DESC
</if>
</when>
<when test="sortByDirection != null">
<if test="sortByDirection.name() == 'ASC'">
order by direction ASC, date_created DESC
</if>
<if test="sortByDirection.name() == 'DESC'">
order by direction DESC, date_created DESC
</if>
</when>
<when test="sortByStatus != null">
<if test="sortByStatus.name() == 'ASC'">
order by status ASC, date_created DESC
</if>
<if test="sortByStatus.name() == 'DESC'">
order by status DESC, date_created DESC
</if>
</when>
<when test="sortByBody != null">
<if test="sortByBody.name() == 'ASC'">
order by body ASC, date_created DESC
</if>
<if test="sortByBody.name() == 'DESC'">
order by body DESC, date_created DESC
</if>
</when>
<when test="sortByPrice != null">
<if test="sortByPrice.name() == 'ASC'">
order by cast(price as unsigned) ASC, date_created DESC
</if>
<if test="sortByPrice.name() == 'DESC'">
order by cast(price as unsigned) DESC, date_created DESC
</if>
</when>
<otherwise>
order by date_created DESC
</otherwise>
</choose>
<if test="limit != null and offset != null">
LIMIT #{limit} OFFSET #{offset}
</if>
</select>

<select id="findBySmppMessageId" parameterType="map" resultType="hashmap">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,59 +122,59 @@
</where>
<choose>
<when test="sortByDate != null">
<if test="sortByDate.name() == 'ASCENDING'">
<if test="sortByDate.name() == 'ASC'">
order by "date_created" ASC
</if>
<if test="sortByDate.name() == 'DESCENDING'">
<if test="sortByDate.name() == 'DESC'">
order by "date_created" DESC
</if>
</when>
<when test="sortByFrom != null">
<if test="sortByFrom.name() == 'ASCENDING'">
order by "sender" ASC
<if test="sortByFrom.name() == 'ASC'">
order by "sender" ASC, "date_created" DESC
</if>
<if test="sortByFrom.name() == 'DESCENDING'">
order by "sender" DESC
<if test="sortByFrom.name() == 'DESC'">
order by "sender" DESC, "date_created" DESC
</if>
</when>
<when test="sortByTo != null">
<if test="sortByTo.name() == 'ASCENDING'">
order by "recipient" ASC
<if test="sortByTo.name() == 'ASC'">
order by "recipient" ASC, "date_created" DESC
</if>
<if test="sortByTo.name() == 'DESCENDING'">
order by "recipient" DESC
<if test="sortByTo.name() == 'DESC'">
order by "recipient" DESC, "date_created" DESC
</if>
</when>
<when test="sortByDirection != null">
<if test="sortByDirection.name() == 'ASCENDING'">
order by "direction" ASC
<if test="sortByDirection.name() == 'ASC'">
order by "direction" ASC, "date_created" DESC
</if>
<if test="sortByDirection.name() == 'DESCENDING'">
order by "direction" DESC
<if test="sortByDirection.name() == 'DESC'">
order by "direction" DESC, "date_created" DESC
</if>
</when>
<when test="sortByStatus != null">
<if test="sortByStatus.name() == 'ASCENDING'">
order by "status" ASC
<if test="sortByStatus.name() == 'ASC'">
order by "status" ASC, "date_created" DESC
</if>
<if test="sortByStatus.name() == 'DESCENDING'">
order by "status" DESC
<if test="sortByStatus.name() == 'DESC'">
order by "status" DESC, "date_created" DESC
</if>
</when>
<when test="sortByDuration != null">
<if test="sortByDuration.name() == 'ASCENDING'">
order by "duration" ASC
<if test="sortByDuration.name() == 'ASC'">
order by "duration" ASC, "date_created" DESC
</if>
<if test="sortByDuration.name() == 'DESCENDING'">
order by "duration" DESC
<if test="sortByDuration.name() == 'DESC'">
order by "duration" DESC, "date_created" DESC
</if>
</when>
<when test="sortByPrice != null">
<if test="sortByPrice.name() == 'ASCENDING'">
order by cast("price" as int) ASC
<if test="sortByPrice.name() == 'ASC'">
order by cast("price" as int) ASC, "date_created" DESC
</if>
<if test="sortByPrice.name() == 'DESCENDING'">
order by cast("price" as int) DESC
<if test="sortByPrice.name() == 'DESC'">
order by cast("price" as int) DESC, "date_created" DESC
</if>
</when>
<otherwise>
Expand Down
Loading

0 comments on commit 95e4148

Please sign in to comment.