Commit 12c219a3 authored by Alina Habibulina's avatar Alina Habibulina

[#1] README.md

parent 03ae60de
Pipeline #192 canceled with stages
# Инструкция по использованию
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);
};
}
```
...@@ -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'
} }
......
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,8 +18,9 @@ public class AsteriskEventListener { ...@@ -16,8 +18,9 @@ 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"))) {
ManagerConnectionFactory mcf = new ManagerConnectionFactory(ip, PropsUtil.getProperty("asterisk.login"), PropsUtil.getProperty("asterisk.password"));
try { try {
ManagerConnection mc = mcf.createManagerConnection(); ManagerConnection mc = mcf.createManagerConnection();
mc.addEventListener(new ManagerListener()); mc.addEventListener(new ManagerListener());
...@@ -30,6 +33,7 @@ public class AsteriskEventListener { ...@@ -30,6 +33,7 @@ public class AsteriskEventListener {
LOGGER.error("**************************************"); LOGGER.error("**************************************");
LOGGER.error(exc.getMessage(), exc); LOGGER.error(exc.getMessage(), exc);
} }
}
} }
......
...@@ -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";
} }
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;
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment