4 api calls to make a full extension so that we can make a call

This commit is contained in:
MathewFrancis 2025-04-08 15:29:37 +05:30
parent ab41e16bb2
commit b1921bef4f
37 changed files with 170 additions and 51 deletions

View File

@ -13,7 +13,7 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"id\": \"1005\",\n \"transport\": \"transport-udp\",\n \"aors\": \"1005\",\n \"auth\": \"1005\",\n \"context\": \"default\",\n \"disallow\": \"all\",\n \"allow\": \"ulaw,alaw\",\n \"directMedia\": \"no\",\n \"connectedLineMethod\": \"invite\",\n \"callerid\": \"User <1005>\",\n \"dtmfMode\": \"rfc4733\",\n \"mohsuggest\": \"default\",\n \"mailboxes\": \"1005@default\"\n}\n\n// {\n// \"id\": \"1004\",\n// \"transport\": \"transport-udp\",\n// \"aors\": \"1004\",\n// \"auth\": \"1004\",\n// \"context\": \"default\",\n// \"disallow\": \"all\",\n// \"allow\": \"ulaw,alaw\",\n// \"directMedia\": \"no\",\n// \"connectedLineMethod\": null,\n// \"callerid\": \"User <1004>\",\n// \"dtmfMode\": null,\n// \"mohsuggest\": \"default\",\n// \"mailboxes\": \"1004@default\"\n// }",
"raw": "{\n \"id\": \"1005\",\n \"transport\": \"transport-udp\",\n \"aors\": \"1005\",\n \"auth\": \"1005\",\n \"context\": \"default\",\n \"disallow\": \"all\",\n \"allow\": \"ulaw,alaw\",\n \"directMedia\": \"no\",\n \"connectedLineMethod\": null,\n \"callerid\": null,\n \"dtmfMode\": null,\n \"mohsuggest\": \"default\",\n \"mailboxes\": null\n}\n\n// {\n// \"id\": \"1004\",\n// \"transport\": \"transport-udp\",\n// \"aors\": \"1004\",\n// \"auth\": \"1004\",\n// \"context\": \"default\",\n// \"disallow\": \"all\",\n// \"allow\": \"ulaw,alaw\",\n// \"directMedia\": \"no\",\n// \"connectedLineMethod\": null,\n// \"callerid\": \"User <1004>\",\n// \"dtmfMode\": null,\n// \"mohsuggest\": \"default\",\n// \"mailboxes\": \"1004@default\"\n// }",
"options": {
"raw": {
"language": "json"
@ -42,7 +42,7 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"context\": \"default\",\n \"extension\": \"1005\",\n \"priority\": 2,\n \"app\": \"Dial\",\n \"appdata\": \"PJSIP/1005,20,m(default)\"\n}\n",
"raw": "{\n \"context\": \"default\",\n \"extension\": \"1005\",\n \"priority\": 1,\n \"app\": \"Dial\",\n \"appdata\": \"PJSIP/1005,20,m(default)\"\n}\n",
"options": {
"raw": {
"language": "json"
@ -92,6 +92,35 @@
}
},
"response": []
},
{
"name": "New Request",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"id\": \"1005\",\n \"maxContacts\": 1\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8081/cezen/set_aors",
"protocol": "http",
"host": [
"localhost"
],
"port": "8081",
"path": [
"cezen",
"set_aors"
]
}
},
"response": []
}
]
}

View File

@ -27,6 +27,7 @@ DELETE FROM `extensions_table` WHERE priority = 4 and exten = "1005" ;
DELETE FROM `extensions_table` WHERE exten = "1005" OR exten = "1004";
DELETE FROM `ps_endpoints` WHERE id = "1004" OR id = "1005";
DELETE FROM `extensions_table` WHERE exten = "1004" OR exten = "1005";
SELECT * FROM `extensions_table` WHERE app = "Dial";

View File

@ -113,16 +113,13 @@
2,18
1,18
3,17
2,48
2,17
1,17
3,16
2,16
1,49
1,16
3,45
3,15
2,47
2,15
1,48
1,15
@ -137,9 +134,7 @@
2,12
1,12
3,11
2,45
2,11
1,47
1,11
3,10
2,10
@ -154,6 +149,7 @@
3,7
2,7
1,7
3,46
3,6
2,6
1,6

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,9 +1,7 @@
package com.example.cezenPBX.DAO;
import com.example.cezenPBX.DTO.ReturnStatus;
import com.example.cezenPBX.entity.ExtensionsTable;
import com.example.cezenPBX.entity.PsAuths;
import com.example.cezenPBX.entity.PsEndPoints;
import com.example.cezenPBX.entity.*;
import jakarta.persistence.EntityManager;
import jakarta.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
@ -17,8 +15,7 @@ public class BasicAsteriskOpsDAO implements CezenPbxOpsDAO {
private EntityManager entityManager;
// find end point details by id
@Override
public PsEndPoints findEndPontById(String id) {
private PsEndPoints findEndPontById(String id) {
return this.entityManager.find(PsEndPoints.class, id);
}
@ -38,19 +35,13 @@ public class BasicAsteriskOpsDAO implements CezenPbxOpsDAO {
return true;
}
// Save an extension
@Override
@Transactional
public ReturnStatus saveAnExtension(ExtensionsTable extensionsTable) {
// check if endpoint exists
try{
System.out.println("End point ID is " + findEndPontById(extensionsTable.getExtension()).getId());
}catch (Exception e){
return new ReturnStatus(false, "Create Endpoint for " + extensionsTable.getExtension(),e.toString() + " First");
}
this.entityManager.persist(extensionsTable);
return new ReturnStatus(true, extensionsTable.getExtension() + " Persisted ", "");
//save only if endpoint exists
return persistOnlyIfEndpointExists(extensionsTable);
}
// the method persists
@ -58,16 +49,29 @@ public class BasicAsteriskOpsDAO implements CezenPbxOpsDAO {
@Transactional
public ReturnStatus setThePasswordForSipEndpoint(PsAuths psAuths) {
//check if endpoint exists
try{
System.out.println("End point ID is " + findEndPontById(psAuths.getId()));
}catch (Exception e){
return new ReturnStatus(false, "Create Endpoint for " + findEndPontById(psAuths.getId()),e.toString() + " First");
//save only if endpoint exists
return persistOnlyIfEndpointExists(psAuths);
}
this.entityManager.persist(psAuths);
return new ReturnStatus(true, psAuths.getId() + " Persisted ", "");
@Override
@Transactional
public ReturnStatus setTheAorsForTheEndPoint(PsAors psAors) {
//save only if endpoint exists
return persistOnlyIfEndpointExists(psAors);
}
private ReturnStatus persistOnlyIfEndpointExists(PBXentiry pbXentiry){
String endpoint = pbXentiry.getExtension();
// check if the endpoint exists
if(findEndPontById(endpoint) == null){
return new ReturnStatus(false, "Create Endpoint for " + endpoint, " ");
}
// then persist
this.entityManager.persist(pbXentiry);
return new ReturnStatus(true, endpoint + " Persisted ", "");
}
}

View File

@ -2,16 +2,17 @@ package com.example.cezenPBX.DAO;
import com.example.cezenPBX.DTO.ReturnStatus;
import com.example.cezenPBX.entity.ExtensionsTable;
import com.example.cezenPBX.entity.PsAors;
import com.example.cezenPBX.entity.PsAuths;
import com.example.cezenPBX.entity.PsEndPoints;
public interface CezenPbxOpsDAO {
PsEndPoints findEndPontById(String id);
boolean addNewEndPoint(PsEndPoints psEndPoints);
ReturnStatus saveAnExtension(ExtensionsTable extensionsTable);
ReturnStatus setThePasswordForSipEndpoint(PsAuths psAuths);
ReturnStatus setTheAorsForTheEndPoint(PsAors psAors);
}

View File

@ -0,0 +1,4 @@
package com.example.cezenPBX.DTO;
public record PsAorsDTO(String id, int maxContacts) {
}

View File

@ -1,8 +1,5 @@
package com.example.cezenPBX.controller;
import com.example.cezenPBX.DTO.ExtensionsDTO;
import com.example.cezenPBX.DTO.PsEndPointsDTO;
import com.example.cezenPBX.DTO.ReturnStatus;
import com.example.cezenPBX.DTO.SipPasswordDTO;
import com.example.cezenPBX.DTO.*;
import com.example.cezenPBX.service.BasicPbxServiceInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
@ -68,4 +65,13 @@ public class CezenPbxController {
sipPasswordDTO.realm()
);
}
@PostMapping("/set_aors")
public ReturnStatus setAorsForSipEndpoint(@RequestBody PsAorsDTO psAorsDTO){
return this.basicPbxServiceInterface.setAors(
psAorsDTO.id(),
psAorsDTO.maxContacts()
);
}
}

View File

@ -5,7 +5,7 @@ import jdk.jfr.Name;
@Entity
@Table(name = "extensions_table")
public class ExtensionsTable {
public class ExtensionsTable implements PBXentiry{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)

View File

@ -0,0 +1,6 @@
package com.example.cezenPBX.entity;
public interface PBXentiry {
public String getExtension();
}

View File

@ -0,0 +1,39 @@
package com.example.cezenPBX.entity;
import jakarta.persistence.*;
@Table(name = "ps_aors")
@Entity
public class PsAors implements PBXentiry{
@Id
@Column(name = "id")
private String extension;
@Column(name = "max_contacts")
private int maxContacts;
public PsAors(String extension, int maxContacts) {
this.extension = extension;
this.maxContacts = maxContacts;
}
public PsAors() {
}
public String getExtension() {
return extension;
}
public void setExtension(String extension) {
this.extension = extension;
}
public int getMaxContacts() {
return maxContacts;
}
public void setMaxContacts(int maxContacts) {
this.maxContacts = maxContacts;
}
}

View File

@ -7,11 +7,11 @@ import jakarta.persistence.Table;
@Table(name = "ps_auths")
@Entity
public class PsAuths {
public class PsAuths implements PBXentiry{
@Id
@Column(name = "id")
private String id;
private String extension;
@Column(name = "auth_type")
private String authType;
@ -29,8 +29,8 @@ public class PsAuths {
private String realm;
public PsAuths(String id, String authType, String userName, String password, String md5Cred, String realm) {
this.id = id;
public PsAuths(String extension, String authType, String userName, String password, String md5Cred, String realm) {
this.extension = extension;
this.authType = authType;
this.userName = userName;
this.password = password;
@ -38,12 +38,12 @@ public class PsAuths {
this.realm = realm;
}
public String getId() {
return id;
public String getExtension() {
return extension;
}
public void setId(String id) {
this.id = id;
public void setExtension(String extension) {
this.extension = extension;
}
public String getAuthType() {

View File

@ -7,11 +7,11 @@ import jakarta.persistence.Table;
@Entity
@Table(name = "ps_endpoints")
public class PsEndPoints {
public class PsEndPoints implements PBXentiry{
@Id
@Column(name = "id")
private String id;
private String extension;
@Column(name = "transport")
private String transport;
@ -49,10 +49,10 @@ public class PsEndPoints {
@Column(name = "mailboxes")
private String mailboxes;
public PsEndPoints(String id, String transport, String aors, String auth, String context,
public PsEndPoints(String extension, String transport, String aors, String auth, String context,
String disallow, String allow, String directMedia, String connectedLineMethod,
String callerid, String dtmfMode, String mohsuggest, String mailboxes) {
this.id = id;
this.extension = extension;
this.transport = transport;
this.aors = aors;
this.auth = auth;
@ -70,8 +70,8 @@ public class PsEndPoints {
public PsEndPoints() {
}
public String getId() {
return id;
public String getExtension() {
return extension;
}
public String getTransport() {

View File

@ -3,6 +3,7 @@ package com.example.cezenPBX.service;
import com.example.cezenPBX.DAO.CezenPbxOpsDAO;
import com.example.cezenPBX.DTO.ReturnStatus;
import com.example.cezenPBX.entity.ExtensionsTable;
import com.example.cezenPBX.entity.PsAors;
import com.example.cezenPBX.entity.PsAuths;
import com.example.cezenPBX.entity.PsEndPoints;
import org.springframework.beans.factory.annotation.Autowired;
@ -81,4 +82,16 @@ public class BasicPbxService implements BasicPbxServiceInterface {
return new ReturnStatus(false, "Endpoint and password already set ",e.getMessage());
}
}
@Override
public ReturnStatus setAors(String id, int maxContacts) {
PsAors psAors = new PsAors(id, maxContacts);
try{
return this.cezenPbxOpsDAO.setTheAorsForTheEndPoint(psAors);
}catch (Exception e){
return new ReturnStatus(false, "Endpoint and password already set ",e.getMessage());
}
}
}

View File

@ -14,4 +14,6 @@ public interface BasicPbxServiceInterface {
public ReturnStatus addExtensionForUser(String context, String extension, int priority, String app, String appdata);
public ReturnStatus addAPasswordForEndpoint(String id, String authType, String userName, String password, String md5Cred, String realm);
public ReturnStatus setAors(String id, int maxContacts);
}

View File

@ -0,0 +1,18 @@
;
; Message Information file
;
[message]
origmailbox=1002
context=default
macrocontext=
exten=1002
rdnis=unknown
priority=30
callerchan=PJSIP/1003-00000002
callerid="mat@1003" <1003>
origdate=Tue Apr 8 06:07:42 AM UTC 2025
origtime=1744092462
category=
msg_id=1744092462-00000000
flag=
duration=0