Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA 02110-1301 USA, or see the FSF site: http://www.fsf.org. -->

<restcomm>
<extensions>
<!--
<extension>
Expand All @@ -18,4 +19,5 @@
<enabled>true</enabled>
</extension>
-->
</extensions>
</extensions>
</restcomm>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CREATE MEMORY TABLE "restcomm_gateways"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"
CREATE MEMORY TABLE "restcomm_media_servers" ( "ms_id" INT GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1) NOT NULL, "local_ip" VARCHAR(34) NOT NULL, "local_port" INT NOT NULL, "remote_ip" VARCHAR(34) NOT NULL UNIQUE, "remote_port" INT NOT NULL, "compatibility" VARCHAR(34) DEFAULT 'rms', "response_timeout" VARCHAR(34), "external_address" VARCHAR(34))
CREATE MEMORY TABLE "restcomm_media_resource_broker_entity" ("conference_sid" VARCHAR(34) NOT NULL, "slave_ms_id" VARCHAR(34) NOT NULL, "slave_ms_bridge_ep_id" VARCHAR(34),"slave_ms_cnf_ep_id" VARCHAR(34),"is_bridged_together" BOOLEAN DEFAULT FALSE,PRIMARY KEY ("conference_sid" , "slave_ms_id"))
CREATE MEMORY TABLE PUBLIC."restcomm_extensions_configuration"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"extension" VARCHAR(255) NOT NULL,"configuration_data" VARCHAR(16777216),"configuration_type" VARCHAR(255) NOT NULL,"date_created" TIMESTAMP NOT NULL,"date_updated" TIMESTAMP, "enabled" BOOLEAN DEFAULT TRUE NOT NULL)
CREATE MEMORY TABLE PUBLIC."restcomm_accounts_extensions" ("account_sid" VARCHAR(34) NOT NULL, "extension_sid" VARCHAR(34) NOT NULL, PRIMARY KEY("account_sid", "extension_sid"), "configuration_data" VARCHAR(16777216))
CREATE MEMORY TABLE "restcomm_geolocation"("sid" VARCHAR(34) NOT NULL PRIMARY KEY, "date_created" DATETIME NOT NULL, "date_updated" DATETIME NOT NULL, "date_executed" DATETIME NOT NULL, "account_sid" VARCHAR(34) NOT NULL, "source" VARCHAR(30), "device_identifier" VARCHAR(30) NOT NULL, "geolocation_type" VARCHAR(15) NOT NULL, "response_status" VARCHAR(30), "cell_id" VARCHAR(10), "location_area_code" VARCHAR(10), "mobile_country_code" INTEGER, "mobile_network_code" VARCHAR(3), "network_entity_address" BIGINT, "age_of_location_info" INTEGER, "device_latitude" VARCHAR(15), "device_longitude" VARCHAR(15), "accuracy" BIGINT, "physical_address" VARCHAR(50), "internet_address" VARCHAR(50), "formatted_address" VARCHAR(200), "location_timestamp" DATETIME, "event_geofence_latitude" VARCHAR(15), "event_geofence_longitude" VARCHAR(15), "radius" BIGINT, "geolocation_positioning_type" VARCHAR(15), "last_geolocation_response" VARCHAR(10), "cause" VARCHAR(150), "api_version" VARCHAR(10) NOT NULL, "uri" LONGVARCHAR NOT NULL)
CREATE USER SA PASSWORD ""
GRANT DBA TO SA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ date_updated DATETIME,
enabled BOOLEAN NOT NULL DEFAULT TRUE
);

CREATE TABLE restcomm_accounts_extensions (
account_sid VARCHAR(34) NOT NULL,
extension_sid VARCHAR(34) NOT NULL,
configuration_data LONGTEXT NOT NULL,
PRIMARY KEY (account_sid, extension_sid)
);

INSERT INTO restcomm_accounts VALUES (
"ACae6e420f425248d6a26948c17a9e2acf",
Date("2012-04-24"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,24 @@
<select id="getDateUpdatedBySid" parameterType="String" resultType="date">
SELECT date_updated FROM restcomm_extensions_configuration WHERE sid=#{sid};
</select>

<select id="getAccountExtensionConfiguration" 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 INTO restcomm_accounts_extensions (account_sid, extension_sid, configuration_data)
VALUES (#{account_sid}, #{extension_sid}, #{configuration_data});
</insert>

<update id="updateAccountExtensionConfiguration" 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 FROM restcomm_accounts_extensions
WHERE account_sid=#{account_sid} AND extension_sid=#{extension_sid};
</delete>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,24 @@
<select id="getDateUpdatedBySid" parameterType="String" resultType="date">
SELECT "date_updated" FROM "restcomm_extensions_configuration" WHERE "sid"=#{sid};
</select>
</mapper>

<select id="getAccountExtensionConfiguration" 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 INTO "restcomm_accounts_extensions" ("account_sid", "extension_sid", "configuration_data")
VALUES (#{account_sid}, #{extension_sid}, #{configuration_data});
</insert>

<update id="updateAccountExtensionConfiguration" 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 FROM "restcomm_accounts_extensions"
WHERE "account_sid"=#{account_sid} AND "extension_sid"=#{extension_sid};
</delete>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,33 @@ public interface ExtensionsConfigurationDao {
* @return
*/
boolean validate(ExtensionConfiguration extensionConfiguration);

/**
* Get account specific ExtensionConfiguration
* @param accountSid
* @param extensionSid
* @return ExtensionConfiguration
*/
ExtensionConfiguration getAccountExtensionConfiguration(String accountSid, String extensionSid);

/**
* Add a new account specific ExtensionConfiguration
* @param extensionConfiguration
* @param accountSid
*/
void addAccountExtensionConfiguration(ExtensionConfiguration extensionConfiguration, Sid accountSid) throws ConfigurationException;

/**
* Update an existing account specific ExtensionConfiguration
* @param extensionConfiguration
* @param accountSid
*/
void updateAccountExtensionConfiguration(ExtensionConfiguration extensionConfiguration, Sid accountSid) throws ConfigurationException;

/**
* Delete account specific ExtensionConfiguration
* @param accountSid
* @param extensionSid
*/
void deleteAccountExtensionConfiguration(String accountSid, String extensionSid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ private ExtensionConfiguration toExtensionConfiguration(final Map<String, Object
return new ExtensionConfiguration(sid, extension, enabled, confData, confType, dateCreated, dateUpdated);
}

private ExtensionConfiguration toAccountsExtensionConfiguration(final Map<String, Object> map) {
final Sid sid = new Sid((String)map.get("extension"));
final String extension = (String) map.get("extension");
final Object confData = map.get("configuration_data");
return new ExtensionConfiguration(sid, extension, true, confData, null, null, null);
}

private Map<String, Object> toMap(final ExtensionConfiguration extensionConfiguration) {
final Map<String, Object> map = new HashMap<String, Object>();
map.put("sid", DaoUtils.writeSid(extensionConfiguration.getSid()));
Expand All @@ -276,4 +283,86 @@ private Map<String, Object> toMap(final ExtensionConfiguration extensionConfigur
map.put("enabled", extensionConfiguration.isEnabled());
return map;
}

@Override
public ExtensionConfiguration getAccountExtensionConfiguration(String accountSid, String extensionSid) {
final SqlSession session = sessions.openSession();
ExtensionConfiguration extensionConfiguration = null;
try {
Map<String, Object> params = new HashMap<String, Object>();
params.put("account_sid", accountSid.toString());
params.put("extension_sid", extensionSid.toString());
final Map<String, Object> result = session.selectOne(namespace + "getAccountExtensionConfiguration", params);
if (result != null) {
extensionConfiguration = toAccountsExtensionConfiguration(result);
}
return extensionConfiguration;
} finally {
session.close();
}
}

@Override
public void addAccountExtensionConfiguration(ExtensionConfiguration extensionConfiguration, Sid accountSid) throws ConfigurationException {
final SqlSession session = sessions.openSession();
try {
if (extensionConfiguration != null && extensionConfiguration.getConfigurationData() != null) {
if (validate(extensionConfiguration)) {
final Map<String, Object> map = new HashMap<String, Object>();
map.put("account_sid", DaoUtils.writeSid(accountSid));
map.put("extension_sid", DaoUtils.writeSid(extensionConfiguration.getSid()));

if (extensionConfiguration.getConfigurationData() != null)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@abdulazizali77 I believe that first thing we should do is to check that configuration data is not null and then proceed, if data is null we shouldn't attempt to do an insert in the DB.
Also, the check should be done at ExtensionsConfigurationEndpoint for add and update operations

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@gvagenas I want to address the REST design + implementation issues in #2127

map.put("configuration_data", extensionConfiguration.getConfigurationData());

session.insert(namespace + "addAccountExtensionConfiguration", map);
session.commit();
} else {
throw new ConfigurationException("Exception trying to add new configuration, validation failed. configuration type: "
+ extensionConfiguration.getConfigurationType());
}
}
} finally {
session.close();
}
}

@Override
public void updateAccountExtensionConfiguration(ExtensionConfiguration extensionConfiguration, Sid accountSid)
throws ConfigurationException {
final SqlSession session = sessions.openSession();
try {
if (extensionConfiguration != null && extensionConfiguration.getConfigurationData() != null) {
if (validate(extensionConfiguration)) {
final Map<String, Object> map = new HashMap<String, Object>();
map.put("account_sid", DaoUtils.writeSid(accountSid));
map.put("extension_sid", DaoUtils.writeSid(extensionConfiguration.getSid()));

if (extensionConfiguration.getConfigurationData() != null)
map.put("configuration_data", extensionConfiguration.getConfigurationData());
session.update(namespace + "updateAccountExtensionConfiguration", map);
} else {
throw new ConfigurationException("Exception trying to update configuration, validation failed. configuration type: "
+ extensionConfiguration.getConfigurationType());
}
}
session.commit();
} finally {
session.close();
}
}

@Override
public void deleteAccountExtensionConfiguration(String accountSid, String extensionSid) {
final SqlSession session = sessions.openSession();
try {
Map<String, Object> params = new HashMap<String, Object>();
params.put("account_sid", accountSid.toString());
params.put("extension_sid", extensionSid.toString());
session.delete(namespace + "deleteAccountExtensionConfiguration", params);
session.commit();
} finally {
session.close();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* TeleStax, Open Source Cloud Communications
* Copyright 2011-2013, Telestax Inc and individual contributors
* by the @authors tag.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.restcomm.connect.extension.api;
import org.apache.commons.configuration.Configuration;

public class ExtensionRequest {
private Object payload;
private Configuration configuration;

public ExtensionRequest() {}

public Object getObject() {
return payload;
}

public void setObject(Object object) {
this.payload = object;
}

public void setConfiguration(Configuration configuration) {
this.configuration = configuration;
}

public Configuration getConfiguration() {
return this.configuration;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
public class ExtensionResponse {
private Object object;
private boolean allowed;
private boolean allowed = true;

public ExtensionResponse() {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* TeleStax, Open Source Cloud Communications
* Copyright 2011-2013, Telestax Inc and individual contributors
* by the @authors tag.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
/**
* When an Extension returns a MessageReponse, RC will reconfigure the message it will send
*/
package org.restcomm.connect.extension.api;
public class MessageExtensionResponse extends ExtensionResponse {
//TODO: needs discussion, definition
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* TeleStax, Open Source Cloud Communications
* Copyright 2011-2013, Telestax Inc and individual contributors
* by the @authors tag.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
/**
* When an Extension returns a NodeReponse, RC will reconfigure the specific RC node it is in
*/
package org.restcomm.connect.extension.api;
public class NodeExtensionResponse extends ExtensionResponse {
//TODO: needs discussion, definition
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public interface RestcommExtensionGeneric {
* and either block/allow it or modify the session before Restcomm process it
* @return ExtensionResponse see ExtensionResponse
*/
ExtensionResponse preOutboundAction(Object message);
ExtensionResponse preOutboundAction(ExtensionRequest extensionRequest);
/**
* Method that will be executed AFTER the process of an Outbound session
* Implement this method so you will be able to check the Outgoing session
Expand All @@ -78,4 +78,15 @@ public interface RestcommExtensionGeneric {
*/
ExtensionResponse postApiAction(ApiRequest apiRequest);

/**
* Extension name getter
* @return String name of Extension
*/
String getName();

/**
* Extension version getter
* @return String version of Extension
*/
String getVersion();
}
Loading