Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,35 @@
<!--
@author gvagenas@telestax.com (George Vagenas)
-->
<mapper namespace="org.restcomm.connect.dao.ExtensionsConfigurationDao">
<insert id="addConfiguration" parameterType="map">
<mapper namespace="org.restcomm.connect.dao.ExtensionsRulesDao">
<insert id="addExtensionRules" parameterType="map">
INSERT INTO restcomm_extensions_configuration (sid, extension, configuration_data, configuration_type,
date_created, date_updated, enabled) VALUES (#{sid}, #{extension}, #{configuration_data}, #{configuration_type},
#{date_created}, #{date_updated}, #{enabled});
</insert>

<update id="updateConfiguration" parameterType="map">
<update id="updateExtensionRules" parameterType="map">
UPDATE restcomm_extensions_configuration SET configuration_data=#{configuration_data}, configuration_type=#{configuration_type}, date_updated=#{date_updated}, enabled=#{enabled}
WHERE sid=#{sid}
</update>

<select id="getConfigurationByName" parameterType="map" resultType="hashmap">
<select id="getExtensionRulesByName" parameterType="map" resultType="hashmap">
SELECT * FROM restcomm_extensions_configuration WHERE extension=#{extension};
</select>

<select id="getConfigurationBySid" parameterType="map" resultType="hashmap">
<select id="getExtensionRulesBySid" parameterType="map" resultType="hashmap">
SELECT * FROM restcomm_extensions_configuration WHERE sid=#{sid};
</select>

<select id="getAllConfiguration" parameterType="map" resultType="hashmap">
<select id="getAllExtensionRules" parameterType="map" resultType="hashmap">
SELECT * FROM restcomm_extensions_configuration;
</select>

<delete id="deleteConfigurationBySid" parameterType="string">
<delete id="deleteExtensionRulesBySid" parameterType="string">
DELETE FROM restcomm_extensions_configuration WHERE sid=#{sid};
</delete>

<delete id="deleteConfigurationByName" parameterType="string">
<delete id="deleteExtensionRulesByName" parameterType="string">
DELETE FROM restcomm_extensions_configuration WHERE extension=#{extension};
</delete>

Expand All @@ -62,22 +62,22 @@
SELECT date_updated FROM restcomm_extensions_configuration WHERE sid=#{sid};
</select>

<select id="getAccountExtensionConfiguration" parameterType="map" resultType="hashmap">
<select id="getAccountExtensionRules" parameterType="map" resultType="hashmap">
SELECT configuration_data, account_sid AS "sid", extension_sid AS "extension" FROM restcomm_accounts_extensions
WHERE account_sid=#{account_sid} AND extension_sid=#{extension_sid};
</select>

<insert id="addAccountExtensionConfiguration" parameterType="map">
<insert id="addAccountExtensionRules" parameterType="map">
INSERT INTO restcomm_accounts_extensions (account_sid, extension_sid, configuration_data)
VALUES (#{account_sid}, #{extension_sid}, #{configuration_data});
</insert>

<update id="updateAccountExtensionConfiguration" parameterType="map">
<update id="updateAccountExtensionRules" parameterType="map">
UPDATE restcomm_accounts_extensions SET configuration_data=#{configuration_data}
WHERE account_sid=#{account_sid} AND extension_sid=#{extension_sid};
</update>

<delete id="deleteAccountExtensionConfiguration" parameterType="map">
<delete id="deleteAccountExtensionRules" parameterType="map">
DELETE FROM restcomm_accounts_extensions
WHERE account_sid=#{account_sid} AND extension_sid=#{extension_sid};
</delete>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,35 @@
<!--
@author gvagenas@telestax.com (George Vagenas)
-->
<mapper namespace="org.restcomm.connect.dao.ExtensionsConfigurationDao">
<insert id="addConfiguration" parameterType="map">
<mapper namespace="org.restcomm.connect.dao.ExtensionsRulesDao">
<insert id="addExtensionRules" parameterType="map">
INSERT INTO "restcomm_extensions_configuration" ("sid", "extension", "configuration_data", "configuration_type",
"date_created", "date_updated", "enabled") VALUES (#{sid}, #{extension}, #{configuration_data}, #{configuration_type},
#{date_created}, #{date_updated}, #{enabled});
</insert>

<update id="updateConfiguration" parameterType="map">
<update id="updateExtensionRules" parameterType="map">
UPDATE "restcomm_extensions_configuration" SET "configuration_data"=#{configuration_data}, "configuration_type"=#{configuration_type}, "date_updated"=#{date_updated}, "enabled"=#{enabled}
WHERE "sid"=#{sid}
</update>

<select id="getConfigurationByName" parameterType="map" resultType="hashmap">
<select id="getExtensionRulesByName" parameterType="map" resultType="hashmap">
SELECT * FROM "restcomm_extensions_configuration" WHERE "extension"=#{extension};
</select>

<select id="getConfigurationBySid" parameterType="map" resultType="hashmap">
<select id="getExtensionRulesBySid" parameterType="map" resultType="hashmap">
SELECT * FROM "restcomm_extensions_configuration" WHERE "sid"=#{sid};
</select>

<select id="getAllConfiguration" parameterType="map" resultType="hashmap">
<select id="getAllExtensionRules" parameterType="map" resultType="hashmap">
SELECT * FROM "restcomm_extensions_configuration";
</select>

<delete id="deleteConfigurationBySid" parameterType="string">
<delete id="deleteExtensionRulesBySid" parameterType="string">
DELETE FROM "restcomm_extensions_configuration" WHERE "sid"=#{sid};
</delete>

<delete id="deleteConfigurationByName" parameterType="string">
<delete id="deleteExtensionRulesByName" parameterType="string">
DELETE FROM "restcomm_extensions_configuration" WHERE "extension"=#{extension};
</delete>

Expand All @@ -68,22 +68,22 @@
SELECT "date_updated" FROM "restcomm_extensions_configuration" WHERE "sid"=#{sid};
</select>

<select id="getAccountExtensionConfiguration" parameterType="map" resultType="hashmap">
<select id="getAccountExtensionRules" parameterType="map" resultType="hashmap">
SELECT "configuration_data", "account_sid" AS "sid", "extension_sid" AS "extension" FROM "restcomm_accounts_extensions"
WHERE "account_sid"=#{account_sid} AND "extension_sid"=#{extension_sid};
</select>

<insert id="addAccountExtensionConfiguration" parameterType="map">
<insert id="addAccountExtensionRules" parameterType="map">
INSERT INTO "restcomm_accounts_extensions" ("account_sid", "extension_sid", "configuration_data")
VALUES (#{account_sid}, #{extension_sid}, #{configuration_data});
</insert>

<update id="updateAccountExtensionConfiguration" parameterType="map">
<update id="updateAccountExtensionRules" parameterType="map">
UPDATE "restcomm_accounts_extensions" SET "configuration_data"=#{configuration_data}
WHERE "account_sid"=#{account_sid} AND "extension_sid"=#{extension_sid};
</update>

<delete id="deleteAccountExtensionConfiguration" parameterType="map">
<delete id="deleteAccountExtensionRules" parameterType="map">
DELETE FROM "restcomm_accounts_extensions"
WHERE "account_sid"=#{account_sid} AND "extension_sid"=#{extension_sid};
</delete>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,59 @@
*/
@Immutable
public final class Sid {

private static String CALL_SID_STRING = "ID[a-zA-Z0-9]{32}-CA[a-zA-Z0-9]{32}";
public static final Pattern pattern = Pattern.compile("[a-zA-Z0-9]{34}");
public static final Pattern callSidPattern = Pattern.compile("ID[a-zA-Z0-9]{32}-CA[a-zA-Z0-9]{32}");
public static final Pattern callSidPattern = Pattern.compile(CALL_SID_STRING);

private final String id;

public enum Type {
ACCOUNT, APPLICATION, ANNOUNCEMENT, CALL, CLIENT, CONFERENCE, GATEWAY, INVALID, NOTIFICATION, PHONE_NUMBER, RECORDING, REGISTRATION, SHORT_CODE, SMS_MESSAGE, TRANSCRIPTION, INSTANCE, EXTENSION_CONFIGURATION, GEOLOCATION, ORGANIZATION, PROFILE
CALL(null, CALL_SID_STRING),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how this Sid refactoring is related to original PR issue, but im fine with it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

went overboard with it, we just needed to add a getType to the Sid because we dont know what the incoming Sid is in getEfectiveConfiguration

ACCOUNT("AC"),
APPLICATION("AP"),
ANNOUNCEMENT("AN"),

CLIENT("CL"),
CONFERENCE("CF"),
GATEWAY("GW"),

NOTIFICATION("NO"),
PHONE_NUMBER("PN"),
RECORDING("RE"),
REGISTRATION("RG"),
SHORT_CODE("SC"),
SMS_MESSAGE("SM"),
TRANSCRIPTION("TR"),
INSTANCE("ID"),
EXTENSION_CONFIGURATION("EX"),
GEOLOCATION("GL"),
ORGANIZATION("OR"),
PROFILE("PR"),
INVALID("IN");

private final String prefix;
private final String regex;
private final Pattern pattern;
private static final String UUID_PATTERN = "[a-zA-Z0-9]{32}";
private Type(final String prefix) {
this(prefix, null);
}
private Type(final String prefix, String regex) {
this.prefix = prefix;
if(regex==null) {
this.regex = prefix + UUID_PATTERN;
}else{
this.regex = regex;
}
pattern = Pattern.compile(this.regex);
}
public String getPrefix() {
return prefix;
}
public boolean isType(Sid sid) {
return pattern.matcher(sid.toString()).matches();
}
};

private static final Sid INVALID_SID = new Sid("IN00000000000000000000000000000000");
Expand All @@ -51,6 +98,18 @@ public Sid(final String id) throws IllegalArgumentException {
}
}

public static Type getType(Sid sid) {
Type res = Type.INVALID;

for(Type type: Type.values()) {
if(type.isType(sid)) {
res = type;
break;
}
}
return res;
}

@Override
public boolean equals(Object object) {
if (this == object) {
Expand All @@ -74,7 +133,7 @@ public static Sid generate(final Type type, String string) {
String token = new Md5Hash(string).toString();
switch (type) {
case ACCOUNT: {
return new Sid("AC" + token);
return new Sid(type.getPrefix() + token);
}
default: {
return generate(type);
Expand All @@ -85,66 +144,32 @@ public static Sid generate(final Type type, String string) {
public static Sid generate(final Type type) {
final String uuid = UUID.randomUUID().toString().replace("-", "");
switch (type) {
case ACCOUNT: {
return new Sid("AC" + uuid);
}
case APPLICATION: {
return new Sid("AP" + uuid);
}
case ANNOUNCEMENT: {
return new Sid("AN" + uuid);
}
case CALL: {
//https://github.com/RestComm/Restcomm-Connect/issues/1907
return new Sid(RestcommConfiguration.getInstance().getMain().getInstanceId() + "-CA" + uuid);
}
case CLIENT: {
return new Sid("CL" + uuid);
}
case CONFERENCE: {
return new Sid("CF" + uuid);
}
case GATEWAY: {
return new Sid("GW" + uuid);
}
case INVALID: {
case INVALID:{
return INVALID_SID;
}
case NOTIFICATION: {
return new Sid("NO" + uuid);
}
case PHONE_NUMBER: {
return new Sid("PN" + uuid);
}
case RECORDING: {
return new Sid("RE" + uuid);
}
case REGISTRATION: {
return new Sid("RG" + uuid);
}
case SHORT_CODE: {
return new Sid("SC" + uuid);
}
case SMS_MESSAGE: {
return new Sid("SM" + uuid);
}
case TRANSCRIPTION: {
return new Sid("TR" + uuid);
}
case INSTANCE: {
return new Sid("ID" + uuid);
}
case EXTENSION_CONFIGURATION: {
return new Sid("EX" + uuid);
}
case GEOLOCATION: {
return new Sid("GL" + uuid);
}
case ORGANIZATION: {
return new Sid("OR" + uuid);
}
case PROFILE: {
return new Sid("PR" + uuid);
case ACCOUNT:
case APPLICATION:
case ANNOUNCEMENT:
case CLIENT:
case CONFERENCE:
case GATEWAY:
case NOTIFICATION:
case PHONE_NUMBER:
case RECORDING:
case REGISTRATION:
case SHORT_CODE:
case SMS_MESSAGE:
case TRANSCRIPTION:
case INSTANCE:
case EXTENSION_CONFIGURATION:
case GEOLOCATION:
case ORGANIZATION:
case PROFILE:{
return new Sid(type.getPrefix() + uuid);
}
default: {
return null;
Expand All @@ -164,4 +189,5 @@ public int hashCode() {
public String toString() {
return id;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.junit.Test;
import org.restcomm.connect.commons.dao.Sid;
import org.restcomm.connect.commons.dao.Sid.Type;

public class SidTest {

Expand Down Expand Up @@ -51,4 +52,19 @@ public void testOldCallSid() {
}
}

@Test
public void testGetType() {
try{
for(Type t : Sid.Type.values()) {
//TODO: mock static class RestcommConfiguration
if(!t.equals(Type.CALL)) {
Sid s = Sid.generate(t);
Type t2 = Sid.getType(s);

assertEquals(t, t2);
}
}
}catch(Exception e){
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public interface DaoManager extends Configurable, LifeCycle {

MediaResourceBrokerDao getMediaResourceBrokerDao();

ExtensionsConfigurationDao getExtensionsConfigurationDao();
ExtensionsRulesDao getExtensionsRulesDao ();

GeolocationDao getGeolocationDao();

Expand Down
Loading