Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Ш
Шаблон интеграции с Asterisk
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alina Habibulina
Шаблон интеграции с Asterisk
Commits
12c219a3
Commit
12c219a3
authored
May 22, 2020
by
Alina Habibulina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[#1] README.md
parent
03ae60de
Pipeline
#192
canceled with stages
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
113 deletions
+68
-113
README.md
README.md
+46
-0
build.gradle
build.gradle
+2
-0
src/main/java/kz/arta/demo/asterisk/AsteriskEventListener.java
...ain/java/kz/arta/demo/asterisk/AsteriskEventListener.java
+17
-13
src/main/java/kz/arta/demo/utils/PropCodes.java
src/main/java/kz/arta/demo/utils/PropCodes.java
+1
-12
src/main/java/kz/arta/demo/utils/UserSearchService.java
src/main/java/kz/arta/demo/utils/UserSearchService.java
+2
-88
No files found.
README.md
View file @
12c219a3
# Инструкция по использованию
1.
Результат сборки
`build/libs/asterisk.war`
положить в
`/opt/synergy/jboss/standalone/deployments`
2.
Создать конфиг файл в
`/opt/synergy/jboss/standalone/configuration/arta/apps/asterisk/asterisk.properties`
со следующим содержимым
```
$text
synergy.address=http://host:port/Synergy
user.login=login
user.password=password
asterisk.enabled=true
asterisk.login=asterisklogin
asterisk.password=asteriskpass
asterisk.addresses=10.52.4.10,10.58.4.10,10.54.4.10,10.40.4.10,10.44.4.10,10.46.4.10
#not called 10.38.4.10
#not connect 10.36.4.10
#not called 10.34.4.10
#not tested 10.42.4.10
actualizeOnDeploy=false
ldap.sync.enabled=false
```
3.
Создать ВМК в
`ip:8080/Configurator`
, подключиться по EventSource:
```
jQuery(document).ready(function () {
var isLogin = setInterval(function () {
if (AS.OPTIONS.login && AS.OPTIONS.login != '') {
createWebSocket();
clearInterval(isLogin);
}
}, 100);
});
function createWebSocket() {
var eventSource = new EventSource("/asterisk/demo?userID=" + AS.OPTIONS.currentUser.userId);
eventSource.onmessage = function(event) {
//TODO: ваша логика
console.log(event);
};
}
```
build.gradle
View file @
12c219a3
...
@@ -52,6 +52,8 @@ dependencies {
...
@@ -52,6 +52,8 @@ dependencies {
compile
group:
'org.asteriskjava'
,
name:
'asterisk-java'
,
version:
'1.0.0-final'
compile
group:
'org.asteriskjava'
,
name:
'asterisk-java'
,
version:
'1.0.0-final'
compile
group:
'javax.websocket'
,
name:
'javax.websocket-api'
,
version:
'1.1'
compile
group:
'javax.websocket'
,
name:
'javax.websocket-api'
,
version:
'1.1'
// https://mvnrepository.com/artifact/com.google.guava/guava
compile
group:
'com.google.guava'
,
name:
'guava'
,
version:
'23.3-jre'
}
}
...
...
src/main/java/kz/arta/demo/asterisk/AsteriskEventListener.java
View file @
12c219a3
package
kz.arta.demo.asterisk
;
package
kz.arta.demo.asterisk
;
import
com.google.common.base.Splitter
;
import
kz.arta.demo.utils.PropsUtil
;
import
org.asteriskjava.manager.ManagerConnection
;
import
org.asteriskjava.manager.ManagerConnection
;
import
org.asteriskjava.manager.ManagerConnectionFactory
;
import
org.asteriskjava.manager.ManagerConnectionFactory
;
import
org.asteriskjava.manager.action.StatusAction
;
import
org.asteriskjava.manager.action.StatusAction
;
...
@@ -16,19 +18,21 @@ public class AsteriskEventListener {
...
@@ -16,19 +18,21 @@ public class AsteriskEventListener {
private
static
List
<
ManagerConnection
>
astConnections
=
new
ArrayList
();
private
static
List
<
ManagerConnection
>
astConnections
=
new
ArrayList
();
public
AsteriskEventListener
()
{
public
AsteriskEventListener
()
{
String
ip
=
"172.30.75.155"
;
Splitter
splitter
=
Splitter
.
on
(
","
);
ManagerConnectionFactory
mcf
=
new
ManagerConnectionFactory
(
ip
,
5038
,
"mikhail"
,
"milyutin"
);
for
(
String
ip
:
splitter
.
split
(
PropsUtil
.
getProperty
(
"asterisk.addresses"
)))
{
try
{
ManagerConnectionFactory
mcf
=
new
ManagerConnectionFactory
(
ip
,
PropsUtil
.
getProperty
(
"asterisk.login"
),
PropsUtil
.
getProperty
(
"asterisk.password"
));
ManagerConnection
mc
=
mcf
.
createManagerConnection
();
try
{
mc
.
addEventListener
(
new
ManagerListener
());
ManagerConnection
mc
=
mcf
.
createManagerConnection
();
mc
.
login
();
mc
.
addEventListener
(
new
ManagerListener
());
mc
.
sendAction
(
new
StatusAction
());
mc
.
login
();
astConnections
.
add
(
mc
);
mc
.
sendAction
(
new
StatusAction
());
}
catch
(
Exception
exc
)
{
astConnections
.
add
(
mc
);
LOGGER
.
error
(
"**************************************"
);
}
catch
(
Exception
exc
)
{
LOGGER
.
error
(
"ADD MANAGER IP ADDRESS! FOR IP = "
+
ip
);
LOGGER
.
error
(
"**************************************"
);
LOGGER
.
error
(
"**************************************"
);
LOGGER
.
error
(
"ADD MANAGER IP ADDRESS! FOR IP = "
+
ip
);
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
LOGGER
.
error
(
"**************************************"
);
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
}
}
}
}
...
...
src/main/java/kz/arta/demo/utils/PropCodes.java
View file @
12c219a3
...
@@ -9,17 +9,6 @@ public class PropCodes {
...
@@ -9,17 +9,6 @@ public class PropCodes {
public
static
final
String
itsm_card_userCard
=
"itsm_card_userCard"
;
public
static
final
String
itsm_card_userCard
=
"itsm_card_userCard"
;
public
static
final
String
PROP_FILE
=
"arta/apps/asterisk/asterisk.properties"
;
public
static
final
String
crm_form_contact_phone_phone
=
"crm_form_contact_phone_phone"
;
public
static
final
String
crm_registry_contacts
=
"crm_registry_contacts"
;
public
static
final
String
crm_form_account_phone_phone
=
"crm_form_account_phone_phone"
;
public
static
final
String
crm_registry_accounts
=
"crm_registry_accounts"
;
public
static
final
String
crm_form_account_main_name
=
"crm_form_account_main_name"
;
public
static
final
String
crm_form_contact_main_organization
=
"crm_form_contact_main_organization"
;
public
static
final
String
crm_form_contact_main_fullName
=
"crm_form_contact_main_fullName"
;
public
static
final
String
crm_registry_deals
=
"crm_registry_deals"
;
public
static
final
String
PROP_FILE
=
"arta/apps/crm/crm.properties"
;
}
}
src/main/java/kz/arta/demo/utils/UserSearchService.java
View file @
12c219a3
package
kz.arta.demo.utils
;
package
kz.arta.demo.utils
;
import
kz.arta.demo.objects.Contact
;
import
kz.arta.demo.objects.RegistryData
;
import
kz.arta.demo.objects.RegistrySearchResultDTO
;
import
kz.arta.synergy.forms.common.object.ASFData
;
import
kz.arta.synergy.forms.common.object.ASFDataWrapperExt
;
import
kz.arta.synergy.forms.common.util.JsonUtil
;
import
kz.arta.synergy.forms.common.util.rest.operations.AsfDataApi
;
import
kz.arta.util.index.elastic.HttpBasicOperation
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.HttpURLConnection
;
...
@@ -30,7 +22,7 @@ public class UserSearchService {
...
@@ -30,7 +22,7 @@ public class UserSearchService {
HttpURLConnection
connection
=
null
;
HttpURLConnection
connection
=
null
;
try
{
try
{
//
TODO: находим userid пользователя, которому нам нужно скинуть уведомления
//
логика для поиска пользователя, здесь - по полю в карточке пользователя в itsm
URL
url
=
new
URL
(
"http://test-kzpitsm.arta.pro/Synergy/rest/api/filecabinet/get_by_field_value?formCode="
+
PropCodes
.
itsm_card_userCard
+
"&fieldName="
+
PropCodes
.
user_card_initial_number_field
+
"&value="
+
number
);
URL
url
=
new
URL
(
"http://test-kzpitsm.arta.pro/Synergy/rest/api/filecabinet/get_by_field_value?formCode="
+
PropCodes
.
itsm_card_userCard
+
"&fieldName="
+
PropCodes
.
user_card_initial_number_field
+
"&value="
+
number
);
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setRequestMethod
(
"GET"
);
conn
.
setRequestMethod
(
"GET"
);
...
@@ -64,82 +56,4 @@ public class UserSearchService {
...
@@ -64,82 +56,4 @@ public class UserSearchService {
return
null
;
return
null
;
}
}
public
static
Contact
getContactAndOrganization
(
String
number
)
{
RegistryData
data
=
findRegistryRecord
(
number
,
PropCodes
.
crm_form_contact_phone_phone
,
PropCodes
.
crm_registry_contacts
);
Contact
contact
=
new
Contact
(
number
);
if
(
data
!=
null
)
{
getContactData
(
data
,
contact
);
}
data
=
findRegistryRecord
(
number
,
PropCodes
.
crm_form_account_phone_phone
,
PropCodes
.
crm_registry_accounts
);
if
(
data
!=
null
)
{
getOrgData
(
data
,
contact
);
}
if
(
contact
.
getDocumentID
()
==
null
&&
contact
.
getOrgDocumentID
()
==
null
){
return
null
;
}
return
contact
;
}
private
static
void
getOrgData
(
RegistryData
registryData
,
Contact
contact
)
{
AsfDataApi
asfDataApi
=
new
AsfDataApi
(
PropsUtil
.
getAddress
(),
PropsUtil
.
getAuthEncoded
());
try
{
ASFDataWrapperExt
ext
=
asfDataApi
.
getAsfData
(
registryData
.
getDataUUID
());
ASFData
.
Data
data
=
ext
.
getData
(
PropCodes
.
crm_form_account_main_name
);
contact
.
setOrgName
(
data
.
getValue
());
contact
.
setOrgDocumentID
(
registryData
.
getDocumentID
());
}
catch
(
IOException
exc
)
{
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
}
private
static
void
getContactData
(
RegistryData
registryData
,
Contact
contact
)
{
AsfDataApi
asfDataApi
=
new
AsfDataApi
(
PropsUtil
.
getAddress
(),
PropsUtil
.
getAuthEncoded
());
try
{
ASFDataWrapperExt
ext
=
asfDataApi
.
getAsfData
(
registryData
.
getDataUUID
());
ASFData
.
Data
data
=
ext
.
getData
(
PropCodes
.
crm_form_contact_main_organization
);
if
(
data
!=
null
){
contact
.
setOrgName
(
data
.
getValue
());
contact
.
setOrgDocumentID
(
data
.
getKey
());
}
data
=
ext
.
getData
(
PropCodes
.
crm_form_contact_main_fullName
);
contact
.
setName
(
data
.
getValue
());
contact
.
setDocumentID
(
registryData
.
getDocumentID
());
}
catch
(
IOException
exc
)
{
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
}
private
static
RegistryData
findRegistryRecord
(
String
number
,
String
field
,
String
registryCode
)
{
HttpURLConnection
connection
=
null
;
try
{
HttpBasicOperation
bo
=
new
HttpBasicOperation
();
connection
=
bo
.
openPostConnection
(
new
URL
(
PropsUtil
.
getAddress
()
+
"/rest/api/registry/data_ext_post"
),
PropsUtil
.
getAuthEncoded
());
if
(
connection
==
null
)
{
throw
new
IllegalStateException
(
"connection is null"
);
}
connection
.
setRequestProperty
(
"Content-Type"
,
"application/x-www-form-urlencoded"
);
DataOutputStream
request
=
new
DataOutputStream
(
connection
.
getOutputStream
());
request
.
writeBytes
(
"registryCode="
+
registryCode
);
request
.
writeBytes
(
"&"
);
request
.
writeBytes
(
"loadData=false"
);
request
.
writeBytes
(
"&"
);
request
.
writeBytes
(
"field="
+
field
+
"&condition=TEXT_EQUALS&value="
+
number
);
request
.
flush
();
request
.
close
();
RegistrySearchResultDTO
records
=
JsonUtil
.
getMapper
().
readValue
(
connection
.
getInputStream
(),
RegistrySearchResultDTO
.
class
);
if
(!
records
.
getData
().
isEmpty
())
{
return
records
.
getData
().
get
(
records
.
getData
().
size
()
-
1
);
}
}
catch
(
IOException
e
)
{
LOGGER
.
error
(
e
.
getMessage
(),
e
);
}
finally
{
if
(
connection
!=
null
)
{
connection
.
disconnect
();
}
}
return
null
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment