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
03ae60de
Commit
03ae60de
authored
May 22, 2020
by
Alina Habibulina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Pipeline
#191
canceled with stages
Changes
17
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
1004 additions
and
0 deletions
+1004
-0
.idea/vcs.xml
.idea/vcs.xml
+7
-0
README.md
README.md
+0
-0
build.gradle
build.gradle
+68
-0
settings.gradle
settings.gradle
+2
-0
src/main/java/kz/arta/demo/StartupTimer.java
src/main/java/kz/arta/demo/StartupTimer.java
+107
-0
src/main/java/kz/arta/demo/asterisk/AsteriskEventListener.java
...ain/java/kz/arta/demo/asterisk/AsteriskEventListener.java
+48
-0
src/main/java/kz/arta/demo/asterisk/ManagerListener.java
src/main/java/kz/arta/demo/asterisk/ManagerListener.java
+40
-0
src/main/java/kz/arta/demo/objects/Contact.java
src/main/java/kz/arta/demo/objects/Contact.java
+81
-0
src/main/java/kz/arta/demo/objects/RegistryData.java
src/main/java/kz/arta/demo/objects/RegistryData.java
+109
-0
src/main/java/kz/arta/demo/objects/RegistrySearchResultDTO.java
...in/java/kz/arta/demo/objects/RegistrySearchResultDTO.java
+37
-0
src/main/java/kz/arta/demo/socket/Socket.java
src/main/java/kz/arta/demo/socket/Socket.java
+149
-0
src/main/java/kz/arta/demo/utils/PropCodes.java
src/main/java/kz/arta/demo/utils/PropCodes.java
+25
-0
src/main/java/kz/arta/demo/utils/PropsUtil.java
src/main/java/kz/arta/demo/utils/PropsUtil.java
+112
-0
src/main/java/kz/arta/demo/utils/SynergyAPI.java
src/main/java/kz/arta/demo/utils/SynergyAPI.java
+54
-0
src/main/java/kz/arta/demo/utils/UserSearchService.java
src/main/java/kz/arta/demo/utils/UserSearchService.java
+145
-0
src/main/webapp/WEB-INF/beans.xml
src/main/webapp/WEB-INF/beans.xml
+8
-0
src/main/webapp/WEB-INF/web.xml
src/main/webapp/WEB-INF/web.xml
+12
-0
No files found.
.idea/vcs.xml
0 → 100644
View file @
03ae60de
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
"$PROJECT_DIR$"
vcs=
"Git"
/>
</component>
</project>
\ No newline at end of file
README.md
0 → 100644
View file @
03ae60de
build.gradle
0 → 100644
View file @
03ae60de
plugins
{
id
'java'
id
'war'
id
'idea'
}
group
'asterisk'
version
'1'
war
.
archiveName
=
"asterisk.war"
def
jacksonVersion
=
'1.9.2'
sourceCompatibility
=
1.7
repositories
{
mavenCentral
()
}
dependencies
{
compile
group:
'org.json'
,
name:
'json'
,
version:
'20170516'
compile
group:
'org.apache.poi'
,
name:
'poi'
,
version:
'3.11-beta2'
compile
group:
'org.apache.poi'
,
name:
'poi-ooxml'
,
version:
'3.11-beta2'
// providedCompile fileTree(dir: 'lib', includes: ['data-source-3.13.jar', 'asf-common-3.13.jar', 'util-common-3.13.jar'])
// compile fileTree(dir: 'lib', includes: ['crm-messages-3.0.jar'])
compile
fileTree
(
dir:
'lib'
,
includes:
[
'asf-common-3.13.jar'
,
'util-common-3.13.jar'
])
providedCompile
"javax:javaee-api:6.0"
providedCompile
group:
'org.slf4j'
,
name:
'slf4j-api'
,
version:
'1.6.1'
,
transitive:
false
providedCompile
"log4j:log4j:1.2.16"
providedCompile
"org.codehaus.jackson:jackson-mapper-asl:$jacksonVersion"
providedCompile
"org.codehaus.jackson:jackson-core-asl:$jacksonVersion"
providedCompile
'org.apache.httpcomponents:httpclient:4.5'
providedCompile
"commons-io:commons-io:2.1"
compile
group:
'org.atmosphere.jboss.as'
,
name:
'jboss-as-websockets'
,
version:
'0.5'
compile
group:
'org.atmosphere'
,
name:
'atmosphere-compat-jbossweb'
,
version:
'2.0.1'
providedCompile
fileTree
(
dir:
'lib'
,
includes:
[
'resteasy-jaxrs-2.3.3.Final.jar'
,
'resteasy-jaxrs-2.3.3.Final-jandex.jar'
,
'resteasy-multipart-provider-2.3.3.Final.jar'
,
'resteasy-multipart-provider-2.3.3.Final-jandex.jar'
])
compile
group:
'org.asteriskjava'
,
name:
'asterisk-java'
,
version:
'1.0.0-final'
compile
group:
'javax.websocket'
,
name:
'javax.websocket-api'
,
version:
'1.1'
}
ext
.
manifestMap
=
[
"Dependencies"
:
"deployment.ESB.ear, deployment.Synergy.ear"
]
war
{
manifest
{
attributes
manifestMap
}
archiveName
=
'asterisk.war'
}
settings.gradle
0 → 100644
View file @
03ae60de
rootProject
.
name
=
'demoAsterisk'
src/main/java/kz/arta/demo/StartupTimer.java
0 → 100644
View file @
03ae60de
package
kz.arta.demo
;
import
kz.arta.demo.asterisk.AsteriskEventListener
;
import
kz.arta.demo.utils.PropsUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PreDestroy
;
import
javax.ejb.Singleton
;
import
javax.ejb.Startup
;
import
java.util.*
;
/**
* User: Aigul
* Date: 11/9/16
* Time: 5:48 PM
*
* Класс с таймерами которые запускаются при старте приложения
*/
@Startup
@Singleton
public
class
StartupTimer
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
StartupTimer
.
class
);
private
Timer
gcTimer
;
//Актуализация скрытых полей сделки
private
Timer
deployTimer
;
//Синхронизация календарей
private
Timer
ldapSync
;
//Запуск соединения с астериском
private
Timer
asteriskConnectionTimer
;
@PostConstruct
public
void
run
()
{
startCreateThread
();
}
private
void
startCreateThread
()
{
GregorianCalendar
calendar
=
new
GregorianCalendar
();
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
1
);
calendar
.
add
(
Calendar
.
DAY_OF_YEAR
,
1
);
if
(
gcTimer
!=
null
)
{
gcTimer
.
cancel
();
gcTimer
.
purge
();
}
gcTimer
=
new
Timer
();
gcTimer
.
schedule
(
new
TimerTask
()
{
@Override
public
void
run
()
{
createNotifications
();
}
},
calendar
.
getTime
()
);
String
enabled
=
PropsUtil
.
getProperty
(
"asterisk.enabled"
);
if
(
enabled
!=
null
&&
enabled
.
equals
(
"true"
))
{
asteriskConnectionTimer
=
new
Timer
();
TimerTask
hourlyTask
=
new
TimerTask
()
{
@Override
public
void
run
()
{
String
sync
=
PropsUtil
.
getProperty
(
"ldap.sync.enabled"
);
AsteriskEventListener
.
closeConnections
();
if
(
sync
!=
null
&&
sync
.
equals
(
"true"
))
{
new
AsteriskEventListener
();
LOGGER
.
error
(
"Asterisk restarted"
);
}
}
};
asteriskConnectionTimer
.
schedule
(
hourlyTask
,
0L
,
1000
*
60
*
60
);
}
}
private
void
createNotifications
()
{
startCreateThread
();
}
@PreDestroy
public
void
stop
()
{
if
(
gcTimer
!=
null
)
{
gcTimer
.
cancel
();
gcTimer
.
purge
();
LOGGER
.
info
(
"timer stopped"
);
}
if
(
deployTimer
!=
null
)
{
deployTimer
.
cancel
();
deployTimer
.
purge
();
}
if
(
asteriskConnectionTimer
!=
null
)
{
asteriskConnectionTimer
.
cancel
();
asteriskConnectionTimer
.
purge
();
AsteriskEventListener
.
closeConnections
();
}
if
(
ldapSync
!=
null
)
{
ldapSync
.
cancel
();
ldapSync
.
purge
();
}
}
}
src/main/java/kz/arta/demo/asterisk/AsteriskEventListener.java
0 → 100644
View file @
03ae60de
package
kz.arta.demo.asterisk
;
import
org.asteriskjava.manager.ManagerConnection
;
import
org.asteriskjava.manager.ManagerConnectionFactory
;
import
org.asteriskjava.manager.action.StatusAction
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
public
class
AsteriskEventListener
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
AsteriskEventListener
.
class
);
private
static
List
<
ManagerConnection
>
astConnections
=
new
ArrayList
();
public
AsteriskEventListener
()
{
String
ip
=
"172.30.75.155"
;
ManagerConnectionFactory
mcf
=
new
ManagerConnectionFactory
(
ip
,
5038
,
"mikhail"
,
"milyutin"
);
try
{
ManagerConnection
mc
=
mcf
.
createManagerConnection
();
mc
.
addEventListener
(
new
ManagerListener
());
mc
.
login
();
mc
.
sendAction
(
new
StatusAction
());
astConnections
.
add
(
mc
);
}
catch
(
Exception
exc
)
{
LOGGER
.
error
(
"**************************************"
);
LOGGER
.
error
(
"ADD MANAGER IP ADDRESS! FOR IP = "
+
ip
);
LOGGER
.
error
(
"**************************************"
);
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
}
public
static
void
closeConnections
()
{
Iterator
i
$
=
astConnections
.
iterator
();
while
(
i
$
.
hasNext
())
{
ManagerConnection
con
=
(
ManagerConnection
)
i
$
.
next
();
if
(
con
!=
null
)
{
con
.
logoff
();
}
}
astConnections
.
clear
();
}
}
src/main/java/kz/arta/demo/asterisk/ManagerListener.java
0 → 100644
View file @
03ae60de
package
kz.arta.demo.asterisk
;
import
kz.arta.demo.socket.Socket
;
import
org.asteriskjava.live.ChannelState
;
import
org.asteriskjava.live.HangupCause
;
import
org.asteriskjava.manager.ManagerEventListener
;
import
org.asteriskjava.manager.event.HangupEvent
;
import
org.asteriskjava.manager.event.ManagerEvent
;
import
org.asteriskjava.manager.event.NewStateEvent
;
/**
* Непосредственно сам слушатель который принимает события о звонках
*/
public
class
ManagerListener
implements
ManagerEventListener
{
@Override
public
void
onManagerEvent
(
ManagerEvent
event
)
{
String
event_name
=
event
.
getClass
().
getSimpleName
();
if
(
event_name
.
equals
(
"NewStateEvent"
))
{
NewStateEvent
e
=
(
NewStateEvent
)
event
;
//Входящий звонок
if
(
ChannelState
.
RINGING
.
getStatus
()
==
e
.
getChannelState
())
{
String
from
=
e
.
getConnectedlinenum
();
String
to
=
e
.
getCallerIdNum
();
Socket
.
fireCallEvent
(
from
,
to
);
}
}
if
(
event_name
.
equals
(
"HangupEvent"
))
{
HangupEvent
e
=
(
HangupEvent
)
event
;
//Положили трубку
if
(
HangupCause
.
AST_CAUSE_NORMAL_CLEARING
.
getCode
()
==
e
.
getCause
())
{
Socket
.
hangUpEvent
(
e
.
getConnectedlinenum
());
}
}
}
}
\ No newline at end of file
src/main/java/kz/arta/demo/objects/Contact.java
0 → 100644
View file @
03ae60de
package
kz.arta.demo.objects
;
/**
* User: Mikhail Milyutin
* Date: 25.05.17.
* Time: 15:04.
*/
public
class
Contact
{
private
String
documentID
;
private
String
name
;
private
String
orgDocumentID
;
private
String
orgName
;
private
String
number
;
private
String
userID
;
private
boolean
hangup
;
public
Contact
()
{
}
public
Contact
(
String
number
)
{
this
.
number
=
number
;
}
public
String
getDocumentID
()
{
return
this
.
documentID
;
}
public
void
setDocumentID
(
String
documentID
)
{
this
.
documentID
=
documentID
;
}
public
String
getName
()
{
return
this
.
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getOrgDocumentID
()
{
return
this
.
orgDocumentID
;
}
public
void
setOrgDocumentID
(
String
orgDocumentID
)
{
this
.
orgDocumentID
=
orgDocumentID
;
}
public
String
getOrgName
()
{
return
this
.
orgName
;
}
public
void
setOrgName
(
String
orgName
)
{
this
.
orgName
=
orgName
;
}
public
String
getNumber
()
{
return
this
.
number
;
}
public
void
setNumber
(
String
number
)
{
this
.
number
=
number
;
}
public
String
getUserID
()
{
return
this
.
userID
;
}
public
void
setUserID
(
String
userID
)
{
this
.
userID
=
userID
;
}
public
boolean
isHangup
()
{
return
this
.
hangup
;
}
public
void
setHangup
(
boolean
hangup
)
{
this
.
hangup
=
hangup
;
}
}
src/main/java/kz/arta/demo/objects/RegistryData.java
0 → 100644
View file @
03ae60de
package
kz.arta.demo.objects
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
java.io.Serializable
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* Created by val
* Date: 04.04.2013
* Time: 12:26
* <p/>
* Данные документов по форме для реестра
*/
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
RegistryData
implements
Serializable
{
/**
* Статус записи реестра - незапущенный
*/
public
static
final
int
STATE_NO_ROUTE
=
0
;
/**
* Статус записи реестра - незавершенный
*/
public
static
final
int
STATE_NOT_FINISHED
=
1
;
/**
* Статус записи реестра - успешно завершенный
*/
public
static
final
int
STATE_SUCCESSFUL
=
2
;
/**
* Статус записи реестра - не успешно завершенный
*/
public
static
final
int
STATE_UNSUCCESSFUL
=
3
;
/**
* Ид реестра
*/
private
String
registryID
;
/**
* Ид данных по форме
*/
private
String
dataUUID
;
/**
* идентификатор документа
*/
private
String
documentID
;
/**
* Ключ - поле реестра,
* Значение - данные, записанные в поле реестра
*/
private
Map
<
String
,
String
>
fieldValue
=
new
HashMap
<
String
,
String
>();
/**
* Активирована ли запись реестра
*/
private
boolean
active
;
public
RegistryData
()
{
}
public
String
getDocumentID
()
{
return
documentID
;
}
public
void
setDocumentID
(
String
documentID
)
{
this
.
documentID
=
documentID
;
}
public
RegistryData
(
String
registryID
)
{
this
.
registryID
=
registryID
;
}
public
String
getRegistryID
()
{
return
registryID
;
}
public
void
setRegistryID
(
String
registryID
)
{
this
.
registryID
=
registryID
;
}
public
String
getDataUUID
()
{
return
dataUUID
;
}
public
void
setDataUUID
(
String
dataUUID
)
{
this
.
dataUUID
=
dataUUID
;
}
public
void
setActive
(
boolean
active
)
{
this
.
active
=
active
;
}
public
Map
<
String
,
String
>
getFieldValue
()
{
return
fieldValue
;
}
public
void
setFieldValue
(
String
field
,
String
value
)
{
fieldValue
.
put
(
field
,
value
);
}
}
src/main/java/kz/arta/demo/objects/RegistrySearchResultDTO.java
0 → 100644
View file @
03ae60de
package
kz.arta.demo.objects
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Created by exile
* Date: 20.07.16
* Time: 12:37
*/
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
RegistrySearchResultDTO
{
private
List
<
RegistryData
>
data
=
new
ArrayList
<>();
private
int
count
=
0
;
public
RegistrySearchResultDTO
()
{
}
public
List
<
RegistryData
>
getData
()
{
return
data
;
}
public
void
setData
(
List
<
RegistryData
>
data
)
{
this
.
data
=
data
;
}
public
int
getCount
()
{
return
count
;
}
public
void
setCount
(
int
count
)
{
this
.
count
=
count
;
}
}
src/main/java/kz/arta/demo/socket/Socket.java
0 → 100644
View file @
03ae60de
package
kz.arta.demo.socket
;
import
kz.arta.demo.objects.Contact
;
import
kz.arta.demo.utils.UserSearchService
;
import
kz.arta.synergy.forms.common.util.JsonUtil
;
import
org.atmosphere.jboss.as.websockets.WebSocket
;
import
org.atmosphere.jboss.as.websockets.servlet.WebSocketServlet
;
import
org.atmosphere.jboss.websockets.Frame
;
import
org.atmosphere.jboss.websockets.frame.TextFrame
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.servlet.AsyncContext
;
import
javax.servlet.AsyncEvent
;
import
javax.servlet.AsyncListener
;
import
javax.servlet.ServletException
;
import
javax.servlet.annotation.WebServlet
;
import
javax.servlet.http.HttpServlet
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
@WebServlet
(
urlPatterns
=
{
"/demo"
},
asyncSupported
=
true
)
public
class
Socket
extends
HttpServlet
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
Socket
.
class
);
private
static
Map
<
String
,
List
<
AsyncContext
>>
asyncContexts
=
new
ConcurrentHashMap
<>();
@Override
public
void
destroy
()
{
asyncContexts
.
clear
();
}
@Override
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
if
(
"text/event-stream"
.
equals
(
request
.
getHeader
(
"Accept"
)))
{
request
.
setAttribute
(
"org.apache.catalina.ASYNC_SUPPORTED"
,
true
);
response
.
setContentType
(
"text/event-stream"
);
response
.
setHeader
(
"Cache-Control"
,
"no-cache"
);
response
.
setHeader
(
"X-Accel-Buffering"
,
"no"
);
response
.
setHeader
(
"Connection"
,
"keep-alive"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
getWriter
().
println
(
"retry: 1000\n"
);
final
String
userID
=
request
.
getParameter
(
"userID"
);
final
AsyncContext
ac
=
request
.
startAsync
();
ac
.
addListener
(
new
AsyncListener
()
{
@Override
public
void
onComplete
(
AsyncEvent
event
)
throws
IOException
{
if
(
asyncContexts
.
containsKey
(
userID
))
{
asyncContexts
.
get
(
userID
).
remove
(
event
.
getAsyncContext
());
}
}
@Override
public
void
onError
(
AsyncEvent
event
)
throws
IOException
{
if
(
asyncContexts
.
containsKey
(
userID
))
{
asyncContexts
.
get
(
userID
).
remove
(
event
.
getAsyncContext
());
}
}
@Override
public
void
onStartAsync
(
AsyncEvent
event
)
throws
IOException
{
}
@Override
public
void
onTimeout
(
AsyncEvent
event
)
throws
IOException
{
if
(
asyncContexts
.
containsKey
(
userID
))
{
asyncContexts
.
get
(
userID
).
remove
(
event
.
getAsyncContext
());
}
}
});
if
(
asyncContexts
!=
null
&&
!
asyncContexts
.
containsKey
(
userID
))
{
asyncContexts
.
put
(
userID
,
new
ArrayList
<
AsyncContext
>());
}
asyncContexts
.
get
(
userID
).
add
(
ac
);
sendMessage
(
userID
,
false
,
false
);
}
}
private
static
void
sendMessage
(
String
userID
,
Boolean
isHangup
,
Boolean
isDocID
)
{
List
<
AsyncContext
>
acList
=
asyncContexts
.
get
(
userID
);
for
(
AsyncContext
asyncContext
:
acList
)
{
try
{
PrintWriter
writer
=
asyncContext
.
getResponse
().
getWriter
();
writer
.
print
(
"data: "
);
if
(
isHangup
)
{
writer
.
println
(
userID
);
writer
.
println
(
"HANGUP"
);
}
else
if
(
isDocID
)
{
writer
.
println
(
userID
);
}
else
{
writer
.
println
(
userID
);
writer
.
println
(
"UP"
);
}
writer
.
println
();
writer
.
flush
();
}
catch
(
Exception
exc
)
{
acList
.
remove
(
asyncContext
);
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
}
}
public
static
void
fireCallEvent
(
String
from
,
String
to
)
{
if
(
to
==
null
||
to
.
trim
().
isEmpty
()
||
to
.
equalsIgnoreCase
(
"NULL"
))
{
return
;
}
if
(
from
==
null
||
from
.
trim
().
isEmpty
()
||
from
.
equalsIgnoreCase
(
"NULL"
))
{
return
;
}
String
userID
=
UserSearchService
.
getUserByNumber
(
to
);
if
(
userID
==
null
)
{
return
;
}
String
contact
=
UserSearchService
.
getUserByNumber
(
from
);
if
(
contact
==
null
)
{
return
;
}
try
{
sendMessage
(
contact
,
false
,
false
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
.
getMessage
(),
e
);
}
}
public
static
void
hangUpEvent
(
String
to
)
{
if
(
to
==
null
||
to
.
trim
().
isEmpty
()
||
to
.
equalsIgnoreCase
(
"NULL"
))
{
return
;
}
String
userID
=
UserSearchService
.
getUserByNumber
(
to
);
if
(
userID
==
null
)
{
return
;
}
try
{
sendMessage
(
userID
,
true
,
false
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
.
getMessage
(),
e
);
}
}
}
src/main/java/kz/arta/demo/utils/PropCodes.java
0 → 100644
View file @
03ae60de
package
kz.arta.demo.utils
;
public
class
PropCodes
{
//поле из карточки пользователя, по которому будет происходить поиск контакта и оператора
public
static
final
String
user_card_initial_number_field
=
"itsm_card_userCard_OfficePhone"
;
//код формы для поиска
public
static
final
String
itsm_card_userCard
=
"itsm_card_userCard"
;
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/PropsUtil.java
0 → 100644
View file @
03ae60de
package
kz.arta.demo.utils
;
import
org.slf4j.Logger
;
import
javax.xml.bind.DatatypeConverter
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.InputStreamReader
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.util.Properties
;
/**
* User: Aigul
* Date: 3/18/17
* Time: 3:43 PM
*/
public
class
PropsUtil
{
private
static
final
Logger
LOGGER
=
org
.
slf4j
.
LoggerFactory
.
getLogger
(
PropsUtil
.
class
);
private
static
Properties
properties
;
/**
* Получение относительного пути конфигурационного файла
*/
private
static
String
getConfFilePath
(
String
relativePath
)
{
return
getCfgURL
()
+
"/"
+
relativePath
;
}
/**
* поднимаем конфиг директорию
*
* @return
*/
public
static
String
getCfgURL
()
{
String
cfgDir
=
System
.
getProperty
(
"jboss.server.config.url"
);
if
(
cfgDir
!=
null
&&
cfgDir
.
startsWith
(
"file://"
))
{
try
{
URL
url
=
new
URL
(
cfgDir
);
return
url
.
getFile
();
}
catch
(
MalformedURLException
e
)
{
LOGGER
.
error
(
e
.
getMessage
(),
e
);
}
}
if
(
cfgDir
==
null
)
{
cfgDir
=
System
.
getProperty
(
"jboss.server.config.dir"
);
if
(
cfgDir
!=
null
)
{
return
cfgDir
;
}
else
{
LOGGER
.
error
(
"NOT FOUND CONFIG DIRECTORY"
);
return
"/home/conf"
;
}
}
return
cfgDir
;
}
public
static
String
getProperty
(
String
key
)
{
return
getProps
().
getProperty
(
key
);
}
public
static
String
getAddress
()
{
return
getProperty
(
"synergy.address"
);
}
public
static
String
getPassword
()
{
return
getProperty
(
"user.password"
);
}
public
static
String
getLogin
()
{
return
getProperty
(
"user.login"
);
}
private
static
String
getAuthEncoded
(
String
login
,
String
password
)
{
return
DatatypeConverter
.
printBase64Binary
((
login
+
":"
+
password
).
getBytes
());
}
public
static
String
getAuthEncoded
()
{
String
login
=
getLogin
();
String
password
=
getPassword
();
return
"Basic "
+
DatatypeConverter
.
printBase64Binary
((
login
+
":"
+
password
).
getBytes
());
}
/**
* Настройки
*/
public
static
Properties
getProps
()
{
if
(
properties
!=
null
)
return
properties
;
properties
=
new
Properties
();
try
{
File
file
=
new
File
(
getConfFilePath
(
PropCodes
.
PROP_FILE
));
if
(
file
.
exists
())
{
LOGGER
.
debug
(
"Reading settings from "
+
file
.
getAbsolutePath
());
properties
.
load
(
new
InputStreamReader
(
new
FileInputStream
(
file
),
"UTF-8"
));
}
else
{
properties
=
null
;
LOGGER
.
debug
(
"File "
+
file
.
getAbsolutePath
()
+
" does not exist!"
);
}
}
catch
(
Exception
exc
)
{
properties
=
null
;
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
return
properties
;
}
}
src/main/java/kz/arta/demo/utils/SynergyAPI.java
0 → 100644
View file @
03ae60de
package
kz.arta.demo.utils
;
import
com.sun.org.apache.xerces.internal.impl.dv.util.Base64
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.BufferedReader
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URLEncoder
;
public
class
SynergyAPI
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
SynergyAPI
.
class
);
private
static
String
address
=
"http://127.0.0.1:8080/Synergy/rest/api"
;
private
static
String
login
=
"user"
;
private
static
String
password
=
"user"
;
public
static
void
signalProcess
(
String
signal
,
String
executionID
,
String
comment
)
{
try
{
URL
url
=
new
URL
(
address
+
"/processes/signal?signal="
+
signal
+
"&executionID="
+
executionID
+
"¶m1=resolution&value1="
+
URLEncoder
.
encode
(
comment
,
"UTF-8"
));
LOGGER
.
info
(
"[API.REQ] "
+
url
.
toString
());
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setRequestMethod
(
"GET"
);
conn
.
setRequestProperty
(
"Accept"
,
"application/json; charset=utf-8"
);
String
encoded
=
Base64
.
encode
((
login
+
":"
+
password
).
getBytes
());
conn
.
setRequestProperty
(
"Authorization"
,
"Basic "
+
encoded
);
String
output
;
StringBuilder
result
=
new
StringBuilder
();
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
((
conn
.
getInputStream
())));
while
((
output
=
br
.
readLine
())
!=
null
)
{
result
.
append
(
output
);
}
conn
.
disconnect
();
LOGGER
.
info
(
"[API.RESP] "
+
result
.
toString
());
}
catch
(
Exception
exc
)
{
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
}
}
src/main/java/kz/arta/demo/utils/UserSearchService.java
0 → 100644
View file @
03ae60de
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.LoggerFactory
;
import
java.io.BufferedReader
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
/**
* User: Mikhail Milyutin
* Date: 25.05.17.
* Time: 14:41.
*/
public
class
UserSearchService
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
UserSearchService
.
class
);
public
static
String
getUserByNumber
(
String
number
)
{
HttpURLConnection
connection
=
null
;
try
{
//TODO: находим userid пользователя, которому нам нужно скинуть уведомления
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
();
conn
.
setRequestMethod
(
"GET"
);
conn
.
setRequestProperty
(
"Accept"
,
"application/json; charset=utf-8"
);
conn
.
setRequestProperty
(
"Authorization"
,
PropsUtil
.
getAuthEncoded
());
String
output
;
StringBuilder
result
=
new
StringBuilder
();
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
((
conn
.
getInputStream
())));
while
((
output
=
br
.
readLine
())
!=
null
)
{
result
.
append
(
output
);
}
conn
.
disconnect
();
LOGGER
.
info
(
"[API.RESP] "
+
result
.
toString
());
if
(!
result
.
toString
().
isEmpty
())
{
return
result
.
toString
();
}
}
catch
(
IOException
e
)
{
LOGGER
.
error
(
e
.
getMessage
(),
e
);
}
finally
{
if
(
connection
!=
null
)
{
connection
.
disconnect
();
}
}
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
;
}
}
src/main/webapp/WEB-INF/beans.xml
0 → 100644
View file @
03ae60de
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://java.sun.com/xml/ns/javaee"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"
>
</beans>
\ No newline at end of file
src/main/webapp/WEB-INF/web.xml
0 → 100644
View file @
03ae60de
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns=
"http://java.sun.com/xml/ns/javaee"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version=
"2.5"
>
<display-name>
DemoAsterisk
</display-name>
<description>
Demo Asterisk Integration App
</description>
</web-app>
\ No newline at end of file
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