Skip to content

Commit e4a890f

Browse files
committed
Merge branch 'master' of github.com:RestComm/Restcomm-Connect
2 parents a1bfd6c + 292ca16 commit e4a890f

36 files changed

Lines changed: 1167 additions & 232 deletions

File tree

restcomm/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@
181181
<module>restcomm.monitoring.service</module>
182182
<module>restcomm.tts.awspolly</module>
183183
<module>restcomm.sdr.api</module>
184-
</modules>
184+
<module>restcomm-connect.core</module>
185+
</modules>
185186

186187
<dependencyManagement>
187188
<dependencies>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.restcomm</groupId>
6+
<artifactId>restcomm-connect</artifactId>
7+
<version>8.3.1-SNAPSHOT</version>
8+
</parent>
9+
<artifactId>restcomm-connect.core</artifactId>
10+
<name>restcomm-connect.core</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.restcomm</groupId>
20+
<artifactId>restcomm-connect.dao</artifactId>
21+
<version>${project.version}</version>
22+
<scope>provided</scope>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.restcomm</groupId>
26+
<artifactId>restcomm-connect.commons</artifactId>
27+
<version>${project.version}</version>
28+
<scope>provided</scope>
29+
</dependency>
30+
<dependency>
31+
<groupId>com.googlecode.libphonenumber</groupId>
32+
<artifactId>libphonenumber</artifactId>
33+
</dependency>
34+
</dependencies>
35+
36+
</project>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
21+
package org.restcomm.connect.core.service.api;
22+
23+
import java.util.Set;
24+
25+
import org.restcomm.connect.commons.dao.Sid;
26+
import org.restcomm.connect.core.service.number.api.NumberSelectionResult;
27+
import org.restcomm.connect.core.service.number.api.SearchModifier;
28+
import org.restcomm.connect.dao.entities.IncomingPhoneNumber;
29+
30+
31+
32+
public interface NumberSelectorService {
33+
/**
34+
* @param phone
35+
* @param sourceOrganizationSid
36+
* @param destinationOrganizationSid
37+
* @return
38+
*/
39+
IncomingPhoneNumber searchNumber(String phone,
40+
Sid sourceOrganizationSid, Sid destinationOrganizationSid);
41+
42+
/**
43+
* @param phone
44+
* @param sourceOrganizationSid
45+
* @param destinationOrganizationSid
46+
* @param modifiers
47+
* @return
48+
*/
49+
IncomingPhoneNumber searchNumber(String phone,
50+
Sid sourceOrganizationSid, Sid destinationOrganizationSid, Set<SearchModifier> modifiers);
51+
52+
/**
53+
* The main logic is: -Find a perfect match in DB using different formats.
54+
* -If not matched, use available Regexes in the organization. -If not
55+
* matched, try with the special * match.
56+
*
57+
* @param phone
58+
* @param sourceOrganizationSid
59+
* @param destinationOrganizationSid
60+
* @return
61+
*/
62+
NumberSelectionResult searchNumberWithResult(String phone,
63+
Sid sourceOrganizationSid, Sid destinationOrganizationSid);
64+
65+
/**
66+
* The main logic is: -Find a perfect match in DB using different formats.
67+
* -If not matched, use available Regexes in the organization. -If not
68+
* matched, try with the special * match.
69+
*
70+
* @param phone
71+
* @param sourceOrganizationSid
72+
* @param destinationOrganizationSid
73+
* @param modifiers
74+
* @return
75+
*/
76+
NumberSelectionResult searchNumberWithResult(String phone,
77+
Sid sourceOrganizationSid, Sid destinationOrganizationSid, Set<SearchModifier> modifiers);
78+
79+
/**
80+
*
81+
* @param result whether the call should be rejected depending on results
82+
* found
83+
* @param srcOrg
84+
* @param destOrg
85+
* @return
86+
*/
87+
boolean isFailedCall(NumberSelectionResult result, Sid srcOrg, Sid destOrg);
88+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
21+
package org.restcomm.connect.core.service.api;
22+
23+
import org.restcomm.connect.commons.dao.Sid;
24+
import org.restcomm.connect.dao.entities.Profile;
25+
26+
public interface ProfileService {
27+
/**
28+
* @param accountSid
29+
* @return will return associated profile of provided account sid
30+
*/
31+
Profile retrieveEffectiveProfileByAccountSid(Sid accountSid);
32+
33+
/**
34+
* @param organizationSid
35+
* @return will return associated profile of provided organization sid
36+
*/
37+
Profile retrieveEffectiveProfileByOrganizationSid(Sid organizationSid);
38+
39+
/**
40+
* @param targetSid
41+
* @return will return explicitly associated profile of provided target (account or
42+
* organization) will return null if no profile is explicitly assigned to the target resource.
43+
*/
44+
Profile retrieveExplicitlyAssociatedProfile(Sid targetSid);
45+
}

restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/NumberSelectorService.java renamed to restcomm/restcomm-connect.core/src/main/java/org/restcomm/connect/core/service/number/NumberSelectorServiceImpl.java

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>
1818
*
1919
*/
20-
package org.restcomm.connect.interpreter;
20+
package org.restcomm.connect.core.service.number;
2121

2222
import java.util.ArrayList;
2323
import java.util.Arrays;
@@ -32,6 +32,10 @@
3232

3333
import org.apache.log4j.Logger;
3434
import org.restcomm.connect.commons.dao.Sid;
35+
import org.restcomm.connect.core.service.api.NumberSelectorService;
36+
import org.restcomm.connect.core.service.number.api.NumberSelectionResult;
37+
import org.restcomm.connect.core.service.number.api.ResultType;
38+
import org.restcomm.connect.core.service.number.api.SearchModifier;
3539
import org.restcomm.connect.dao.IncomingPhoneNumbersDao;
3640
import org.restcomm.connect.dao.entities.IncomingPhoneNumber;
3741
import org.restcomm.connect.dao.entities.IncomingPhoneNumberFilter;
@@ -52,13 +56,13 @@
5256
* yet, then null values are allowed, but Regexes will not be evaluated in these
5357
* cases.
5458
*/
55-
public class NumberSelectorService {
59+
public class NumberSelectorServiceImpl implements NumberSelectorService {
5660

57-
private static Logger logger = Logger.getLogger(NumberSelectorService.class);
61+
private static Logger logger = Logger.getLogger(NumberSelectorServiceImpl.class);
5862

5963
private IncomingPhoneNumbersDao numbersDao;
6064

61-
public NumberSelectorService(IncomingPhoneNumbersDao numbersDao) {
65+
public NumberSelectorServiceImpl(IncomingPhoneNumbersDao numbersDao) {
6266
this.numbersDao = numbersDao;
6367
}
6468

@@ -182,7 +186,7 @@ private NumberSelectionResult findByNumber(List<String> numberQueries,
182186
Boolean orgFiltered = false;
183187
NumberSelectionResult matchedNumber = new NumberSelectionResult(null, orgFiltered, null);
184188
int i = 0;
185-
while (matchedNumber.number == null && i < numberQueries.size()) {
189+
while (matchedNumber.getNumber() == null && i < numberQueries.size()) {
186190
matchedNumber = findSingleNumber(numberQueries.get(i),
187191
sourceOrganizationSid, destinationOrganizationSid, modifiers);
188192
//preserve the orgFiltered flag along the queries
@@ -201,6 +205,7 @@ private NumberSelectionResult findByNumber(List<String> numberQueries,
201205
* @param destinationOrganizationSid
202206
* @return
203207
*/
208+
@Override
204209
public IncomingPhoneNumber searchNumber(String phone,
205210
Sid sourceOrganizationSid, Sid destinationOrganizationSid) {
206211
return searchNumber(phone, sourceOrganizationSid, destinationOrganizationSid, new HashSet<>(Arrays.asList(SearchModifier.ORG_COMPLIANT)));
@@ -213,10 +218,11 @@ public IncomingPhoneNumber searchNumber(String phone,
213218
* @param modifiers
214219
* @return
215220
*/
221+
@Override
216222
public IncomingPhoneNumber searchNumber(String phone,
217223
Sid sourceOrganizationSid, Sid destinationOrganizationSid, Set<SearchModifier> modifiers) {
218224
NumberSelectionResult searchNumber = searchNumberWithResult(phone, sourceOrganizationSid, destinationOrganizationSid, modifiers);
219-
return searchNumber.number;
225+
return searchNumber.getNumber();
220226
}
221227

222228
/**
@@ -227,6 +233,7 @@ public IncomingPhoneNumber searchNumber(String phone,
227233
* @param destOrg
228234
* @return
229235
*/
236+
@Override
230237
public boolean isFailedCall(NumberSelectionResult result, Sid srcOrg, Sid destOrg) {
231238
boolean failCall = false;
232239

@@ -250,6 +257,7 @@ public boolean isFailedCall(NumberSelectionResult result, Sid srcOrg, Sid destOr
250257
* @param destinationOrganizationSid
251258
* @return
252259
*/
260+
@Override
253261
public NumberSelectionResult searchNumberWithResult(String phone,
254262
Sid sourceOrganizationSid, Sid destinationOrganizationSid){
255263
return searchNumberWithResult(phone, sourceOrganizationSid, destinationOrganizationSid, new HashSet<>(Arrays.asList(SearchModifier.ORG_COMPLIANT)));
@@ -266,6 +274,7 @@ public NumberSelectionResult searchNumberWithResult(String phone,
266274
* @param modifiers
267275
* @return
268276
*/
277+
@Override
269278
public NumberSelectionResult searchNumberWithResult(String phone,
270279
Sid sourceOrganizationSid, Sid destinationOrganizationSid, Set<SearchModifier> modifiers) {
271280
if (logger.isDebugEnabled()) {
@@ -276,7 +285,7 @@ public NumberSelectionResult searchNumberWithResult(String phone,
276285
List<String> numberQueries = createPhoneQuery(phone);
277286

278287
NumberSelectionResult numberfound = findByNumber(numberQueries, sourceOrganizationSid, destinationOrganizationSid, modifiers);
279-
if (numberfound.number == null) {
288+
if (numberfound.getNumber() == null) {
280289
//only use regex if perfect match didnt worked
281290
if (destinationOrganizationSid != null
282291
&& (sourceOrganizationSid == null || destinationOrganizationSid.equals(sourceOrganizationSid))
@@ -288,16 +297,16 @@ public NumberSelectionResult searchNumberWithResult(String phone,
288297
if (regexFound.getNumber() != null) {
289298
numberfound = regexFound;
290299
}
291-
if (numberfound.number == null) {
300+
if (numberfound.getNumber() == null) {
292301
//if no regex match found, try with special star number in the end
293302
NumberSelectionResult starfound = findSingleNumber("*", sourceOrganizationSid, destinationOrganizationSid, modifiers);
294-
if (starfound.number != null) {
295-
numberfound = new NumberSelectionResult(starfound.number, false, ResultType.REGEX);
303+
if (starfound.getNumber() != null) {
304+
numberfound = new NumberSelectionResult(starfound.getNumber(), false, ResultType.REGEX);
296305
}
297306
}
298307
}
299308
}
300-
if (numberfound.number == null) {
309+
if (numberfound.getNumber() == null) {
301310
if (logger.isDebugEnabled()) {
302311
StringBuffer stringBuffer = new StringBuffer();
303312

@@ -365,7 +374,7 @@ private NumberSelectionResult findByRegex(List<String> numberQueries,
365374
regexSet.addAll(regexList);
366375
if (regexList != null && regexList.size() > 0) {
367376
NumberSelectionResult matchingRegex = findFirstMatchingRegex(numberQueries, regexSet);
368-
if (matchingRegex.number != null) {
377+
if (matchingRegex.getNumber() != null) {
369378
numberFound = matchingRegex;
370379
}
371380
}
@@ -379,12 +388,12 @@ private NumberSelectionResult findByRegex(List<String> numberQueries,
379388
* @param regexSet The set of regexes to evaluate against given numbers
380389
* @return the first regex matching any number in list, null if no match
381390
*/
382-
public NumberSelectionResult findFirstMatchingRegex(List<String> numberQueries, Set<IncomingPhoneNumber> regexSet
391+
private NumberSelectionResult findFirstMatchingRegex(List<String> numberQueries, Set<IncomingPhoneNumber> regexSet
383392
) {
384393
NumberSelectionResult matchedRegex = new NumberSelectionResult(null, false, null);
385394
try {
386395
Iterator<IncomingPhoneNumber> iterator = regexSet.iterator();
387-
while (matchedRegex.number == null && iterator.hasNext()) {
396+
while (matchedRegex.getNumber() == null && iterator.hasNext()) {
388397
IncomingPhoneNumber currentRegex = iterator.next();
389398
String phoneRegexPattern = null;
390399
//here we perform string replacement to allow proper regex compilation
@@ -401,7 +410,7 @@ public NumberSelectionResult findFirstMatchingRegex(List<String> numberQueries,
401410
int i = 0;
402411
//we evalute the current regex to the list of incoming numbers
403412
//we stop as soon as a match is found
404-
while (matchedRegex.number == null && i < numberQueries.size()) {
413+
while (matchedRegex.getNumber() == null && i < numberQueries.size()) {
405414
Matcher m = p.matcher(numberQueries.get(i));
406415
if (m.find()) {
407416
//match found, exit from loops and return
@@ -419,7 +428,7 @@ public NumberSelectionResult findFirstMatchingRegex(List<String> numberQueries,
419428
logger.debug(msg);
420429
}
421430
}
422-
if (matchedRegex.number == null) {
431+
if (matchedRegex.getNumber() == null) {
423432
logger.info("No matching phone number found, make sure your Restcomm Regex phone number is correctly defined");
424433
}
425434

restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/NumberSelectionResult.java renamed to restcomm/restcomm-connect.core/src/main/java/org/restcomm/connect/core/service/number/api/NumberSelectionResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>
1818
*
1919
*/
20-
package org.restcomm.connect.interpreter;
20+
package org.restcomm.connect.core.service.number.api;
2121

2222
import org.restcomm.connect.dao.entities.IncomingPhoneNumber;
2323

restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/ResultType.java renamed to restcomm/restcomm-connect.core/src/main/java/org/restcomm/connect/core/service/number/api/ResultType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>
1919
*
2020
*/
21-
package org.restcomm.connect.interpreter;
21+
package org.restcomm.connect.core.service.number.api;
2222

2323
public enum ResultType {
2424
REGULAR, REGEX, STAR;

restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SearchModifier.java renamed to restcomm/restcomm-connect.core/src/main/java/org/restcomm/connect/core/service/number/api/SearchModifier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* You should have received a copy of the GNU Affero General Public License
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>
1818
*/
19-
package org.restcomm.connect.interpreter;
19+
package org.restcomm.connect.core.service.number.api;
2020

2121
/**
2222
* @author maria-farooq@live.com (Maria Farooq)

0 commit comments

Comments
 (0)