-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathincoming-phone-numbers.xml
More file actions
109 lines (98 loc) · 5.81 KB
/
incoming-phone-numbers.xml
File metadata and controls
109 lines (98 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?xml version="1.0" encoding="UTF-8"?>
<!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)
-->
<mapper namespace="org.mobicents.servlet.sip.restcomm.dao.IncomingPhoneNumbersDao">
<insert id="addIncomingPhoneNumber" parameterType="map">
INSERT INTO "restcomm_incoming_phone_numbers" ("sid", "date_created", "date_updated", "friendly_name", "account_sid", "phone_number", "cost", "api_version",
"voice_caller_id_lookup", "voice_url", "voice_method", "voice_fallback_url", "voice_fallback_method", "status_callback", "status_callback_method",
"voice_application_sid", "sms_url", "sms_method", "sms_fallback_url", "sms_fallback_method", "sms_application_sid", "uri", "voice_capable", "sms_capable",
"mms_capable", "fax_capable", "pure_sip") VALUES(#{sid},
#{date_created}, #{date_updated}, #{friendly_name}, #{account_sid}, #{phone_number}, #{cost}, #{api_version}, #{voice_caller_id_lookup},
#{voice_url}, #{voice_method}, #{voice_fallback_url}, #{voice_fallback_method}, #{status_callback}, #{status_callback_method},
#{voice_application_sid}, #{sms_url}, #{sms_method}, #{sms_fallback_url}, #{sms_fallback_method}, #{sms_application_sid}, #{uri},
#{voice_capable}, #{sms_capable}, #{mms_capable}, #{fax_capable}, #{pure_sip});
</insert>
<select id="getIncomingPhoneNumber" parameterType="string" resultType="hashmap">
SELECT * FROM "restcomm_incoming_phone_numbers" WHERE "sid"=#{sid};
</select>
<select id="getIncomingPhoneNumberByValue" parameterType="string" resultType="hashmap">
SELECT * FROM "restcomm_incoming_phone_numbers" WHERE "phone_number"=#{phone_number};
</select>
<select id="getIncomingPhoneNumbers" parameterType="string" resultType="hashmap">
SELECT * FROM "restcomm_incoming_phone_numbers" WHERE "account_sid"=#{account_sid};
</select>
<!--
<select id="getIncomingPhoneNumbersByFriendlyName" parameterType="string" resultType="hashmap">
SELECT * 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>
</select>
-->
<!-- along with the DID it returns the application frien-->
<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_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">
DELETE FROM "restcomm_incoming_phone_numbers" WHERE "sid"=#{sid};
</delete>
<delete id="removeIncomingPhoneNumbers" parameterType="string">
DELETE FROM "restcomm_incoming_phone_numbers" WHERE "account_sid"=#{account_sid};
</delete>
<update id="updateIncomingPhoneNumber" parameterType="map">
UPDATE "restcomm_incoming_phone_numbers" SET "friendly_name"=#{friendly_name}, "voice_caller_id_lookup"=#{voice_caller_id_lookup}, "voice_url"=#{voice_url},
"voice_method"=#{voice_method}, "voice_fallback_url"=#{voice_fallback_url}, "voice_fallback_method"=#{voice_fallback_method}, "status_callback"=#{status_callback},
"status_callback_method"=#{status_callback_method}, "voice_application_sid"=#{voice_application_sid}, "sms_url"=#{sms_url}, "sms_method"=#{sms_method},
"sms_fallback_url"=#{sms_fallback_url}, "sms_fallback_method"=#{sms_fallback_method}, "sms_application_sid"=#{sms_application_sid}, "voice_capable"=#{voice_capable},
"sms_capable"=#{sms_capable}, "mms_capable"=#{mms_capable}, "fax_capable"=#{fax_capable} WHERE "sid"=#{sid};
</update>
</mapper>