Skip to content

Commit

Permalink
Copied changes to numbers mybatis descriptor to all places throughout…
Browse files Browse the repository at this point in the history
… the codebase (tests, mysql descriptors etc.)

Refers #2608
  • Loading branch information
otsakir committed Nov 9, 2017
1 parent a52451b commit 16466de
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
</if>
<if test="phoneNumber != null">
AND n.phone_number like #{phoneNumber}
</if>
<if test="applicationSid != null">
AND (n.voice_application_sid = #{applicationSid} OR n.sms_application_sid = #{applicationSid} OR n.ussd_application_sid = #{applicationSid} OR n.refer_application_sid = #{applicationSid})
</if>
<choose>
<when test="sortBy == 'phone_number'">
Expand All @@ -90,6 +93,9 @@
<if test="phoneNumber != null">
AND phone_number like #{phoneNumber}
</if>
<if test="applicationSid != null">
AND (voice_application_sid = #{applicationSid} OR sms_application_sid = #{applicationSid} OR ussd_application_sid = #{applicationSid} OR refer_application_sid = #{applicationSid})
</if>

</select>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
<if test="phoneNumber != null">
AND "n"."phone_number" like #{phoneNumber}
</if>
<if test="applicationSid != null">
AND ("n"."voice_application_sid" = #{applicationSid} OR "n"."sms_application_sid" = #{applicationSid} OR "n"."ussd_application_sid" = #{applicationSid} OR "n"."refer_application_sid" = #{applicationSid})
</if>
<choose>
<when test="sortBy == 'phone_number'">
order by "n"."phone_number" ${sortDirection}
Expand All @@ -92,8 +95,10 @@
<if test="phoneNumber != null">
AND "phone_number" like #{phoneNumber}
</if>

</select>
<if test="applicationSid != null">
AND ("voice_application_sid" = #{applicationSid} OR "sms_application_sid" = #{applicationSid} OR "ussd_application_sid" = #{applicationSid} OR "refer_application_sid" = #{applicationSid})
</if>
</select>


<delete id="removeIncomingPhoneNumber" parameterType="string">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ TeleStax, Open Source Cloud Communications
~ Copyright 2011-2014, Telestax Inc and individual contributors
~ by the @authors tag.
~
~ This program is free software: you can redistribute it and/or modify
~ under the terms of the GNU Affero General Public License as
~ published by the Free Software Foundation; either version 3 of
~ the License, or (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>
~
-->

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--
@author thomas.quintana@telestax.com (Thomas Quintana)
Expand Down
37 changes: 21 additions & 16 deletions restcomm/restcomm.dao/src/test/resources/incoming-phone-numbers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,37 @@
<if test="phoneNumber != null">
AND "n"."phone_number" like #{phoneNumber}
</if>
<if test="applicationSid != null">
AND ("n"."voice_application_sid" = #{applicationSid} OR "n"."sms_application_sid" = #{applicationSid} OR "n"."ussd_application_sid" = #{applicationSid} OR "n"."refer_application_sid" = #{applicationSid})
</if>
<choose>
<when test="sortBy == 'phone_number'">
order by "n"."phone_number" ${sortDirection}
</when>
<when test="sortBy == 'friendly_name'">
order by "n"."friendly_name" ${sortDirection}
</when>
<otherwise>
order by "n"."phone_number" ${sortDirection}
</otherwise>
</choose>
<when test="sortBy == 'phone_number'">
order by "n"."phone_number" ${sortDirection}
</when>
<when test="sortBy == 'friendly_name'">
order by "n"."friendly_name" ${sortDirection}
</when>
<otherwise>
order by "n"."phone_number" ${sortDirection}
</otherwise>
</choose>

LIMIT #{limit} OFFSET #{offset}
</select>

<select id="getTotalIncomingPhoneNumbersByUsingFilters" parameterType="org.restcomm.connect.dao.entities.IncomingPhoneNumberFilter" resultType="int">
SELECT COUNT(*) FROM "restcomm_incoming_phone_numbers" WHERE "account_sid"=#{accountSid}
SELECT COUNT(*) FROM "restcomm_incoming_phone_numbers" WHERE "account_sid"=#{accountSid}

<if test="friendlyName != null">
<if test="friendlyName != null">
AND "friendly_name"=#{friendlyName}
</if>
<if test="phoneNumber != null">
AND "phone_number" like #{phoneNumber}
</if>

</select>
<if test="applicationSid != null">
AND ("voice_application_sid" = #{applicationSid} OR "sms_application_sid" = #{applicationSid} OR "ussd_application_sid" = #{applicationSid} OR "refer_application_sid" = #{applicationSid})
</if>
</select>


<delete id="removeIncomingPhoneNumber" parameterType="string">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ protected Response getIncomingPhoneNumbers(final String accountSid, final PhoneN
try{
String phoneNumberFilter = info.getQueryParameters().getFirst("PhoneNumber");
String friendlyNameFilter = info.getQueryParameters().getFirst("FriendlyName");
String applicationSid = info.getQueryParameters().getFirst("ApplicationSid");
String page = info.getQueryParameters().getFirst("Page");
String reverse = info.getQueryParameters().getFirst("Reverse");
String pageSize = info.getQueryParameters().getFirst("PageSize");
Expand All @@ -306,14 +307,14 @@ protected Response getIncomingPhoneNumbers(final String accountSid, final PhoneN
int pageAsInt = Integer.parseInt(page);
int offset = (page == "0") ? 0 : (((pageAsInt - 1) * limit) + limit);
IncomingPhoneNumberFilter incomingPhoneNumberFilter = new IncomingPhoneNumberFilter(accountSid, friendlyNameFilter,
phoneNumberFilter);
phoneNumberFilter, applicationSid);
final int total = dao.getTotalIncomingPhoneNumbers(incomingPhoneNumberFilter);

if (pageAsInt > (total / limit)) {
return status(javax.ws.rs.core.Response.Status.BAD_REQUEST).build();
}

incomingPhoneNumberFilter = new IncomingPhoneNumberFilter(accountSid, friendlyNameFilter, phoneNumberFilter, null, sortBy,
incomingPhoneNumberFilter = new IncomingPhoneNumberFilter(accountSid, friendlyNameFilter, phoneNumberFilter, applicationSid, sortBy,
reverse, limit, offset);

final List<IncomingPhoneNumber> incomingPhoneNumbers = dao.getIncomingPhoneNumbersByFilter(incomingPhoneNumberFilter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,55 @@
-->

<!-- along with the DID it returns the application frien-->
<select id="getIncomingPhoneNumbersByFriendlyName" parameterType="string" resultType="hashmap">
<select id="getIncomingPhoneNumbersByFriendlyName" parameterType="org.restcomm.connect.dao.entities.IncomingPhoneNumberFilter" resultType="hashmap">
SELECT
"n".*,
"a_voice"."friendly_name" "voice_application_name",
"a_sms"."friendly_name" "sms_application_name",
"a_ussd"."friendly_name" "ussd_application_name"
"a_ussd"."friendly_name" "ussd_application_name",
"a_refer"."friendly_name" "refer_application_name"
FROM "restcomm_incoming_phone_numbers" "n"
LEFT OUTER JOIN "restcomm_applications" "a_voice" ON "n"."voice_application_sid" = "a_voice"."sid"
LEFT OUTER JOIN "restcomm_applications" "a_sms" ON "n"."sms_application_sid" = "a_sms"."sid"
LEFT OUTER JOIN "restcomm_applications" "a_ussd" ON "n"."ussd_application_sid" = "a_ussd"."sid"
LEFT OUTER JOIN "restcomm_applications" "a_refer" ON "n"."refer_application_sid" = "a_refer"."sid"
WHERE "account_sid"=#{accountSid}
<if test="friendlyName != null">
AND "n"."friendly_name"=#{friendlyName}
</if>
<if test="phoneNumber != null">
AND "n"."phone_number" like #{phoneNumber}
</if>
<if test="applicationSid != null">
AND ("n"."voice_application_sid" = #{applicationSid} OR "n"."sms_application_sid" = #{applicationSid} OR "n"."ussd_application_sid" = #{applicationSid} OR "n"."refer_application_sid" = #{applicationSid})
</if>
<choose>
<when test="sortBy == 'phone_number'">
order by "n"."phone_number" ${sortDirection}
</when>
<when test="sortBy == 'friendly_name'">
order by "n"."friendly_name" ${sortDirection}
</when>
<otherwise>
order by "n"."phone_number" ${sortDirection}
</otherwise>
</choose>

LIMIT #{limit} OFFSET #{offset}
</select>

<select id="getTotalIncomingPhoneNumbersByUsingFilters" parameterType="org.restcomm.connect.dao.entities.IncomingPhoneNumberFilter" resultType="int">
SELECT COUNT(*) FROM "restcomm_incoming_phone_numbers" WHERE "account_sid"=#{accountSid}

<if test="friendlyName != null">
AND "friendly_name"=#{friendlyName}
</if>
<if test="phoneNumber != null">
AND "phone_number" like #{phoneNumber}
</if>
<if test="applicationSid != null">
AND ("voice_application_sid" = #{applicationSid} OR "sms_application_sid" = #{applicationSid} OR "ussd_application_sid" = #{applicationSid} OR "refer_application_sid" = #{applicationSid})
</if>
</select>

<delete id="removeIncomingPhoneNumber" parameterType="string">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,55 @@
-->

<!-- along with the DID it returns the application frien-->
<select id="getIncomingPhoneNumbersByFriendlyName" parameterType="string" resultType="hashmap">
<select id="getIncomingPhoneNumbersByFriendlyName" parameterType="org.restcomm.connect.dao.entities.IncomingPhoneNumberFilter" resultType="hashmap">
SELECT
"n".*,
"a_voice"."friendly_name" "voice_application_name",
"a_sms"."friendly_name" "sms_application_name",
"a_ussd"."friendly_name" "ussd_application_name"
"a_ussd"."friendly_name" "ussd_application_name",
"a_refer"."friendly_name" "refer_application_name"
FROM "restcomm_incoming_phone_numbers" "n"
LEFT OUTER JOIN "restcomm_applications" "a_voice" ON "n"."voice_application_sid" = "a_voice"."sid"
LEFT OUTER JOIN "restcomm_applications" "a_sms" ON "n"."sms_application_sid" = "a_sms"."sid"
LEFT OUTER JOIN "restcomm_applications" "a_ussd" ON "n"."ussd_application_sid" = "a_ussd"."sid"
LEFT OUTER JOIN "restcomm_applications" "a_refer" ON "n"."refer_application_sid" = "a_refer"."sid"
WHERE "account_sid"=#{accountSid}
<if test="friendlyName != null">
AND "n"."friendly_name"=#{friendlyName}
</if>
<if test="phoneNumber != null">
AND "n"."phone_number" like #{phoneNumber}
</if>
<if test="applicationSid != null">
AND ("n"."voice_application_sid" = #{applicationSid} OR "n"."sms_application_sid" = #{applicationSid} OR "n"."ussd_application_sid" = #{applicationSid} OR "n"."refer_application_sid" = #{applicationSid})
</if>
<choose>
<when test="sortBy == 'phone_number'">
order by "n"."phone_number" ${sortDirection}
</when>
<when test="sortBy == 'friendly_name'">
order by "n"."friendly_name" ${sortDirection}
</when>
<otherwise>
order by "n"."phone_number" ${sortDirection}
</otherwise>
</choose>

LIMIT #{limit} OFFSET #{offset}
</select>

<select id="getTotalIncomingPhoneNumbersByUsingFilters" parameterType="org.restcomm.connect.dao.entities.IncomingPhoneNumberFilter" resultType="int">
SELECT COUNT(*) FROM "restcomm_incoming_phone_numbers" WHERE "account_sid"=#{accountSid}

<if test="friendlyName != null">
AND "friendly_name"=#{friendlyName}
</if>
<if test="phoneNumber != null">
AND "phone_number" like #{phoneNumber}
</if>
<if test="applicationSid != null">
AND ("voice_application_sid" = #{applicationSid} OR "sms_application_sid" = #{applicationSid} OR "ussd_application_sid" = #{applicationSid} OR "refer_application_sid" = #{applicationSid})
</if>
</select>

<delete id="removeIncomingPhoneNumber" parameterType="string">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,55 @@
-->

<!-- along with the DID it returns the application frien-->
<select id="getIncomingPhoneNumbersByFriendlyName" parameterType="string" resultType="hashmap">
<select id="getIncomingPhoneNumbersByFriendlyName" parameterType="org.restcomm.connect.dao.entities.IncomingPhoneNumberFilter" resultType="hashmap">
SELECT
"n".*,
"a_voice"."friendly_name" "voice_application_name",
"a_sms"."friendly_name" "sms_application_name",
"a_ussd"."friendly_name" "ussd_application_name"
"a_ussd"."friendly_name" "ussd_application_name",
"a_refer"."friendly_name" "refer_application_name"
FROM "restcomm_incoming_phone_numbers" "n"
LEFT OUTER JOIN "restcomm_applications" "a_voice" ON "n"."voice_application_sid" = "a_voice"."sid"
LEFT OUTER JOIN "restcomm_applications" "a_sms" ON "n"."sms_application_sid" = "a_sms"."sid"
LEFT OUTER JOIN "restcomm_applications" "a_ussd" ON "n"."ussd_application_sid" = "a_ussd"."sid"
LEFT OUTER JOIN "restcomm_applications" "a_refer" ON "n"."refer_application_sid" = "a_refer"."sid"
WHERE "account_sid"=#{accountSid}
<if test="friendlyName != null">
AND "n"."friendly_name"=#{friendlyName}
</if>
<if test="phoneNumber != null">
AND "n"."phone_number" like #{phoneNumber}
</if>
<if test="applicationSid != null">
AND ("n"."voice_application_sid" = #{applicationSid} OR "n"."sms_application_sid" = #{applicationSid} OR "n"."ussd_application_sid" = #{applicationSid} OR "n"."refer_application_sid" = #{applicationSid})
</if>
<choose>
<when test="sortBy == 'phone_number'">
order by "n"."phone_number" ${sortDirection}
</when>
<when test="sortBy == 'friendly_name'">
order by "n"."friendly_name" ${sortDirection}
</when>
<otherwise>
order by "n"."phone_number" ${sortDirection}
</otherwise>
</choose>

LIMIT #{limit} OFFSET #{offset}
</select>

<select id="getTotalIncomingPhoneNumbersByUsingFilters" parameterType="org.restcomm.connect.dao.entities.IncomingPhoneNumberFilter" resultType="int">
SELECT COUNT(*) FROM "restcomm_incoming_phone_numbers" WHERE "account_sid"=#{accountSid}

<if test="friendlyName != null">
AND "friendly_name"=#{friendlyName}
</if>
<if test="phoneNumber != null">
AND "phone_number" like #{phoneNumber}
</if>
<if test="applicationSid != null">
AND ("voice_application_sid" = #{applicationSid} OR "sms_application_sid" = #{applicationSid} OR "ussd_application_sid" = #{applicationSid} OR "refer_application_sid" = #{applicationSid})
</if>
</select>

<delete id="removeIncomingPhoneNumber" parameterType="string">
Expand Down

0 comments on commit 16466de

Please sign in to comment.