Skip to content

Commit d61f5e5

Browse files
author
maria-farooq
authored
Merge pull request #2763 from RestComm/restcomm-1514
Profile Associations DAO Impl
2 parents 40d57db + d0bc922 commit d61f5e5

14 files changed

Lines changed: 590 additions & 0 deletions

File tree

restcomm/restcomm.application/src/main/webapp/WEB-INF/conf/mybatis.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@
5353
<mapper url="file://${sql}/extensions-configuration.xml"/>
5454
<mapper url="file://${sql}/geolocation.xml"/>
5555
<mapper url="file://${sql}/organization.xml"/>
56+
<mapper url="file://${sql}/profile-association.xml"/>
5657
</mappers>
5758
</configuration>

restcomm/restcomm.application/src/main/webapp/WEB-INF/data/hsql/restcomm.script

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ CREATE MEMORY TABLE "restcomm_sand_boxes"("date_created" DATETIME NOT NULL,"date
2121
CREATE MEMORY TABLE "restcomm_gateways"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL,"friendly_name" VARCHAR(255),"user_name" VARCHAR(255),"password" VARCHAR(255),"proxy" LONGVARCHAR NOT NULL,"register" BOOLEAN NOT NULL,"ttl" INT NOT NULL,"uri" LONGVARCHAR NOT NULL)
2222
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))
2323
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"))
24+
CREATE MEMORY TABLE "restcomm_profile_associations"("target_sid" LONGVARCHAR NOT NULL PRIMARY KEY, "profile_sid" LONGVARCHAR NOT NULL, "date_created" DATETIME NOT NULL, "date_updated" DATETIME NOT NULL)
2425
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)
2526
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))
2627
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)

restcomm/restcomm.application/src/main/webapp/WEB-INF/scripts/mariadb/init.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,13 @@ date_updated DATETIME,
393393
enabled BOOLEAN NOT NULL DEFAULT TRUE
394394
);
395395

396+
CREATE TABLE restcomm_profile_associations(
397+
target_sid TEXT NOT NULL PRIMARY KEY,
398+
profile_sid TEXT NOT NULL,
399+
date_created DATETIME NOT NULL,
400+
date_updated DATETIME NOT NULL
401+
);
402+
396403
CREATE TABLE restcomm_accounts_extensions (
397404
account_sid VARCHAR(34) NOT NULL,
398405
extension_sid VARCHAR(34) NOT NULL,
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3+
<!-- @author maria farooq -->
4+
<mapper namespace="org.mobicents.servlet.sip.restcomm.dao.ProfileAssociationsDao">
5+
<insert id="addProfileAssociation" parameterType="map">
6+
INSERT INTO restcomm_profile_associations (profile_sid, target_sid, date_created, date_updated)
7+
VALUES(#{profile_sid}, #{target_sid}, #{date_created}, #{date_updated});
8+
</insert>
9+
10+
<select id="getProfileAssociationByTargetSid" parameterType="string" resultType="hashmap">
11+
SELECT * FROM restcomm_profile_associations WHERE target_sid=#{target_sid};
12+
</select>
13+
14+
<select id="getProfileAssociationsByProfileSid" parameterType="string" resultType="hashmap">
15+
SELECT * FROM restcomm_profile_associations WHERE profile_sid=#{profile_sid};
16+
</select>
17+
18+
<update id="updateProfileAssociationOfTargetSid" parameterType="map">
19+
UPDATE restcomm_profile_associations SET date_updated=NOW(),
20+
profile_sid=#{profile_sid}
21+
WHERE target_sid=#{target_sid};
22+
</update>
23+
24+
<update id="updateAssociatedProfileOfAllSuchProfileSid" parameterType="map">
25+
UPDATE restcomm_profile_associations SET date_updated=NOW(),
26+
profile_sid=#{profile_sid}
27+
WHERE profile_sid=#{old_profile_sid};
28+
</update>
29+
30+
<delete id="deleteProfileAssociationByProfileSid" parameterType="map">
31+
DELETE from restcomm_profile_associations
32+
WHERE profile_sid=#{profile_sid};
33+
</delete>
34+
35+
<delete id="deleteProfileAssociationByTargetSid" parameterType="map">
36+
DELETE from restcomm_profile_associations
37+
WHERE target_sid=#{target_sid};
38+
</delete>
39+
</mapper>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3+
<!-- @author maria farooq -->
4+
<mapper namespace="org.mobicents.servlet.sip.restcomm.dao.ProfileAssociationsDao">
5+
<insert id="addProfileAssociation" parameterType="map">
6+
INSERT INTO "restcomm_profile_associations" ("profile_sid", "target_sid", "date_created", "date_updated")
7+
VALUES(#{profile_sid}, #{target_sid}, #{date_created}, #{date_updated});
8+
</insert>
9+
10+
<select id="getProfileAssociationByTargetSid" parameterType="string" resultType="hashmap">
11+
SELECT * FROM "restcomm_profile_associations" WHERE "target_sid"=#{target_sid};
12+
</select>
13+
14+
<select id="getProfileAssociationsByProfileSid" parameterType="string" resultType="hashmap">
15+
SELECT * FROM "restcomm_profile_associations" WHERE "profile_sid"=#{profile_sid};
16+
</select>
17+
18+
<update id="updateProfileAssociationOfTargetSid" parameterType="map">
19+
UPDATE "restcomm_profile_associations" SET "date_updated"=NOW(),
20+
"profile_sid"=#{profile_sid}
21+
WHERE "target_sid"=#{target_sid};
22+
</update>
23+
24+
<update id="updateAssociatedProfileOfAllSuchProfileSid" parameterType="map">
25+
UPDATE "restcomm_profile_associations" SET "date_updated"=NOW(),
26+
"profile_sid"=#{profile_sid}
27+
WHERE "profile_sid"=#{old_profile_sid};
28+
</update>
29+
30+
<delete id="deleteProfileAssociationByProfileSid" parameterType="map">
31+
DELETE from "restcomm_profile_associations"
32+
WHERE "profile_sid"=#{profile_sid};
33+
</delete>
34+
35+
<delete id="deleteProfileAssociationByTargetSid" parameterType="map">
36+
DELETE from "restcomm_profile_associations"
37+
WHERE "target_sid"=#{target_sid};
38+
</delete>
39+
</mapper>

restcomm/restcomm.dao/src/main/java/org/restcomm/connect/dao/DaoManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public interface DaoManager extends Configurable, LifeCycle {
7272

7373
GeolocationDao getGeolocationDao();
7474

75+
ProfileAssociationsDao getProfileAssociationsDao();
76+
7577
OrganizationsDao getOrganizationsDao();
7678

7779
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* TeleStax, Open Source Cloud Communications
3+
* Copyright 2011-2014, Telestax Inc and individual contributors
4+
* by the @authors tag.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation; either version 3 of
9+
* the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>
18+
*
19+
*/
20+
package org.restcomm.connect.dao;
21+
22+
import java.util.List;
23+
24+
import org.restcomm.connect.dao.entities.ProfileAssociation;
25+
26+
/**
27+
* @author maria.farooq@telestax.com (Maria Farooq)
28+
*/
29+
public interface ProfileAssociationsDao {
30+
31+
/**
32+
* @param targetSid
33+
* @return ProfileAssociation as per provided target sid
34+
*/
35+
ProfileAssociation getProfileAssociationByTargetSid(String targetSid);
36+
37+
/**
38+
* @param profileSid
39+
* @return List of all ProfileAssociation with a give profile sid
40+
*/
41+
List<ProfileAssociation> getProfileAssociationsByProfileSid(String profileSid);
42+
43+
/**
44+
* @param profileAssociation
45+
* @return
46+
*/
47+
int addProfileAssociation(ProfileAssociation profileAssociation);
48+
49+
/**
50+
* update ProfileAssociation Of TargetSid to new Profile Sid.
51+
* @param profileAssociation
52+
*/
53+
void updateProfileAssociationOfTargetSid(ProfileAssociation profileAssociation);
54+
55+
/**
56+
* update Associated Profile Of All Such ProfileSid
57+
* @param oldProfileSid
58+
* @param newProfileSid
59+
*/
60+
void updateAssociatedProfileOfAllSuchProfileSid(String oldProfileSid, String newProfileSid);
61+
62+
/**
63+
* will delete all associations of given profile sid
64+
* @param profileSid
65+
*/
66+
void deleteProfileAssociationByProfileSid(String profileSid);
67+
68+
/**
69+
* will delete all associations of given target sid
70+
* @param targetSid
71+
*/
72+
void deleteProfileAssociationByTargetSid(String targetSid);
73+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* TeleStax, Open Source Cloud Communications
3+
* Copyright 2011-2014, Telestax Inc and individual contributors
4+
* by the @authors tag.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation; either version 3 of
9+
* the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>
18+
*
19+
*/
20+
package org.restcomm.connect.dao.entities;
21+
22+
import java.util.Calendar;
23+
import java.util.Date;
24+
25+
import org.restcomm.connect.commons.annotations.concurrency.Immutable;
26+
import org.restcomm.connect.commons.annotations.concurrency.NotThreadSafe;
27+
import org.restcomm.connect.commons.dao.Sid;
28+
29+
/**
30+
* @author maria.farooq@telestax.com (Maria Farooq)
31+
*/
32+
@Immutable
33+
public final class ProfileAssociation{
34+
private final Sid profileSid;
35+
private final Sid targetSid;
36+
private final Date dateCreated;
37+
private final Date dateUpdated;
38+
39+
/**
40+
* @param profileSid
41+
* @param targetSid can be account or organizaation Sid
42+
* @param dateCreated
43+
* @param dateUpdated
44+
*/
45+
public ProfileAssociation(final Sid profileSid, final Sid targetSid, final Date dateCreated, final Date dateUpdated) {
46+
super();
47+
this.profileSid = profileSid;
48+
this.targetSid = targetSid;
49+
this.dateCreated = dateCreated;
50+
this.dateUpdated = dateUpdated;
51+
}
52+
53+
public static Builder builder() {
54+
return new Builder();
55+
}
56+
57+
public Sid getProfileSid() {
58+
return profileSid;
59+
}
60+
61+
public Sid getTargetSid() {
62+
return targetSid;
63+
}
64+
65+
public Date getDateCreated() {
66+
return dateCreated;
67+
}
68+
69+
public Date getDateUpdated() {
70+
return dateUpdated;
71+
}
72+
73+
/**
74+
* @param newProfileSid
75+
* @return
76+
*/
77+
public ProfileAssociation setProfileSid(final Sid newProfileSid){
78+
return new ProfileAssociation(newProfileSid, targetSid, dateCreated, Calendar.getInstance().getTime());
79+
}
80+
@NotThreadSafe
81+
public static final class Builder {
82+
private Sid profileSid;
83+
private Sid targetSid;
84+
private Date dateCreated;
85+
86+
private Builder() {
87+
super();
88+
profileSid = null;
89+
targetSid = null;
90+
dateCreated = null;
91+
}
92+
93+
public ProfileAssociation build() {
94+
return new ProfileAssociation(profileSid, targetSid, dateCreated, Calendar.getInstance().getTime());
95+
}
96+
97+
public void setProfileDocument(final Sid targetSid) {
98+
this.targetSid = targetSid;
99+
}
100+
101+
public void setSid(final Sid profileSid) {
102+
this.profileSid = profileSid;
103+
}
104+
105+
public void setDateCreated(final Date dateCreated) {
106+
this.dateCreated = dateCreated;
107+
}
108+
}
109+
110+
@Override
111+
public String toString() {
112+
return "ProfileAssociation [profileSid=" + profileSid + ", targetSid=" + targetSid + ", dateCreated="
113+
+ dateCreated + ", dateUpdated=" + dateUpdated + "]";
114+
}
115+
}

restcomm/restcomm.dao/src/main/java/org/restcomm/connect/dao/mybatis/MybatisDaoManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@
4848
import org.restcomm.connect.dao.NotificationsDao;
4949
import org.restcomm.connect.dao.OrganizationsDao;
5050
import org.restcomm.connect.dao.OutgoingCallerIdsDao;
51+
import org.restcomm.connect.dao.ProfileAssociationsDao;
5152
import org.restcomm.connect.dao.RecordingsDao;
5253
import org.restcomm.connect.dao.RegistrationsDao;
5354
import org.restcomm.connect.dao.ShortCodesDao;
5455
import org.restcomm.connect.dao.SmsMessagesDao;
5556
import org.restcomm.connect.dao.TranscriptionsDao;
5657
import org.restcomm.connect.dao.UsageDao;
58+
5759
import scala.concurrent.ExecutionContext;
5860

5961
/**
@@ -89,6 +91,7 @@ public final class MybatisDaoManager implements DaoManager {
8991
private MediaResourceBrokerDao mediaResourceBrokerDao;
9092
private ExtensionsConfigurationDao extensionsConfigurationDao;
9193
private GeolocationDao geolocationDao;
94+
private ProfileAssociationsDao profileAssociationsDao;
9295
private OrganizationsDao organizationsDao;
9396

9497
private ExecutionContext ec;
@@ -220,6 +223,11 @@ public GeolocationDao getGeolocationDao() {
220223
return geolocationDao;
221224
}
222225

226+
@Override
227+
public ProfileAssociationsDao getProfileAssociationsDao() {
228+
return profileAssociationsDao;
229+
}
230+
223231
@Override
224232
public OrganizationsDao getOrganizationsDao() {
225233
return organizationsDao;
@@ -298,6 +306,7 @@ public void start(final SqlSessionFactory sessions) {
298306
mediaResourceBrokerDao = new MybatisMediaResourceBrokerDao(sessions);
299307
extensionsConfigurationDao = new MybatisExtensionsConfigurationDao(sessions);
300308
geolocationDao = new MybatisGeolocationDao(sessions);
309+
profileAssociationsDao = new MybatisProfileAssociationsDao(sessions);
301310
organizationsDao = new MybatisOrganizationDao(sessions);
302311
}
303312
}

0 commit comments

Comments
 (0)