diff --git a/entity/Organisation_entity/recordcontainers/index/query.js b/entity/Organisation_entity/recordcontainers/index/query.js index 6bd8d82c9550fe160e97d27b7033e1977d7bacb0..675cf5804d681019b2011d681bb48a93f08b7300 100644 --- a/entity/Organisation_entity/recordcontainers/index/query.js +++ b/entity/Organisation_entity/recordcontainers/index/query.js @@ -6,6 +6,12 @@ import("system.db"); import("Sql_lib"); import("Communication_lib"); +/* +Before changing the results that are returned here: +Please keep in mind that some of the indexfields are used in other modules (like the duplicate-scanner or cti-call-handler). +You may want to check out if your change affects other modules. However adding more fields should not be a problem therefor. + */ + var sqlQuery, sqlHelper, queryCondition, affectedIds; var CommMediumPhoneIds = db.array( db.COLUMN, "select KEYID from AB_KEYWORD_ENTRY join ab_keyword_attributerelation on AB_KEYWORD_ENTRYID = AB_KEYWORD_ENTRY_ID " + " join ab_keyword_attribute on AB_KEYWORD_ATTRIBUTEID = AB_KEYWORD_ATTRIBUTE_ID and CHAR_VALUE = 'TELEPHONE' and AB_KEYWORD_ATTRIBUTE.CONTAINER = 'CommunicationMedium'"); diff --git a/entity/Person_entity/recordcontainers/index/query.js b/entity/Person_entity/recordcontainers/index/query.js index a9893146702ac8196ca3d768c6a84f82da9dcffe..73f7ae201a8981dacc1557195c692843f8a3d633 100644 --- a/entity/Person_entity/recordcontainers/index/query.js +++ b/entity/Person_entity/recordcontainers/index/query.js @@ -6,6 +6,12 @@ import("system.db"); import("Sql_lib"); import("Communication_lib"); +/* +Before changing the results that are returned here: +Please keep in mind that some of the indexfields are used in other modules (like the duplicate-scanner or cti-call-handler). +You may want to check out if your change affects other modules. However adding more fields should not be a problem therefor. + */ + var sqlQuery, sqlHelper, queryCondition, affectedIds; var CommMediumPhoneIds = db.array( db.COLUMN, "select KEYID from AB_KEYWORD_ENTRY join ab_keyword_attributerelation on AB_KEYWORD_ENTRYID = AB_KEYWORD_ENTRY_ID " + " join ab_keyword_attribute on AB_KEYWORD_ATTRIBUTEID = AB_KEYWORD_ATTRIBUTE_ID and CHAR_VALUE = 'TELEPHONE' and AB_KEYWORD_ATTRIBUTE.CONTAINER = 'CommunicationMedium'"); diff --git a/process/IncomingCallExecutor_lib/process.js b/process/IncomingCallExecutor_lib/process.js index 03d3395a479c2277bb8351aff17e1fd73ee8c889..3f53e5ecc41a8dc11da06884e013236bcf0b2c29 100644 --- a/process/IncomingCallExecutor_lib/process.js +++ b/process/IncomingCallExecutor_lib/process.js @@ -1,3 +1,4 @@ +import("system.entities"); import("system.datetime"); import("system.util"); import("system.notification"); @@ -7,12 +8,13 @@ import("system.tools"); import("system.db"); import("Sql_lib"); import("system.cti"); +import("system.indexsearch"); -//TODO: comment library +//TODO: comment library completely /** * object for processing cti-calls - * Within the constructor, data is collected but not further processed. To perform operations, different methods are provided. + * Within the constructor, data is collected but not further processed. To perform operations, different methods are provide (lke the .execute-function) * * @class * @param {Object} pCallData object with all the basic call information, the object needs the following parameters: <ul> @@ -176,7 +178,7 @@ IncomingCallExecutor.prototype.getNotificationBaseConfig = function(pUserName) var notificationConfig = notification.createConfig() .addUserWithId(pUserName) - .contentId(this.callData.callId) + .contentId(this.callData.callId)//group all notifications of one call together .notificationType("_____SYSTEM_NOTIFICATION_PHONECALL"); return notificationConfig; @@ -306,38 +308,63 @@ IncomingCallExecutor._callstateToText = function(pCallstate) IncomingCallExecutor._getContactsFromNumber = function(pNumber, pContactIds) { var phoneNumber = pNumber; - if (!phoneNumber && !pContactIds) + if (!phoneNumber && (!pContactIds || pContactIds.length == 0))//either of one needs to be specified, otherwise we wouldn't know what to search + return []; + + var contactIds = pContactIds || []; + + if (pNumber) + { + /* + Searching for a number is done via the index because + - it's fast + - there is no need to sanitize stored phone-addresses or the phone-address we are looking for + (this is done by the api automatically when the indexFieldType is configured as "TELEPHONE") + - the pattern and terms can be configured very detailed (fuzzy, wildcards, boosting) etc. to ensure that the best results are delivered + (currently a basic search is done because this has proven to return the best results till now; however this may need to be adjusted to a connected telephy-system) + + Searching the index is done via the indexsearch-methods and not an index-record container because we need to serach for both personContacts + and organisationContacts. There exists a entity "AnyContact_entity" which represents personContacts- and organisationContacts-data + but that entity has no index record container defined at the moment. So instead searching multiple IndexGroups is done here. + Because different indexGroup store data differently, we cannot directly load usage-data like the organisation-name, person-name and so on + from the index. Instead we are only loading the ID-field (which is the contactId in both groups) and then load the usage-data for these + contactIds. + */ + var patternConfig = indexsearch.createPatternConfig(); + var searchTerm = indexsearch.createTerm(pNumber).setIndexField("phone"); + patternConfig.plus(searchTerm); + var pattern = indexsearch.buildPatternString(patternConfig); + var indexQuery = indexsearch.createIndexQuery().setPattern(pattern) + .addIndexGroups("Person", "Organisation") + .addResultIndexFields([indexsearch.FIELD_ID]); + var indexResult = indexsearch.searchIndex(indexQuery); + if (indexResult.HITS) + contactIds = contactIds.concat(indexResult.HITS.map(function (e){return e[indexsearch.FIELD_ID];})); + } + + if (contactIds.length == 0) return []; - /* - var config = entities.createConfigForLoadingRows().entity("Communication_entity") - .fields(["CONTACT_ID"]) - .provider("PhoneCommunications") - .addParameter("Address_param", phoneNumber); - var rows = entities.getRows(config); - var contactIds = rows.map(function (e){ - return e.CONTACT_ID; - }); - config = entities.createConfigForLoadingRows().entity("AnyContact_entity") - .fields(["CONTACTID", "ORGANISATION_ID", "ORGANISATION_NAME", "PERSON_ID", "ISOLANGUAGE", "PERSON_FULL_NAME"]) - .uids(contactIds); - rows = entities.getRows(); + //load entities does not work in serverProcesses at the moment, so instead use a traditional sql-query: //TODO: change this after #1047680 is done + /* + var config = entities.createConfigForLoadingRows().entity("AnyContact_entity") + .fields(["CONTACTID", "ORGANISATION_ID", "ORGANISATION_NAME", "PERSON_ID", "ISOLANGUAGE", "PERSON_FULL_NAME"]) + .uids(contactIds); + rows = entities.getRows(config); return rows; */ - //load entities does not work here, so instead use a traditional sql-query: var contactSql = SqlCondition.begin() - .andPrepareIfSet("COMMUNICATION.ADDR", phoneNumber) - .andIn("COMMUNICATION.CONTACT_ID", pContactIds)//this is automatically only added if pContactIds is truely - .andPrepare("CONTACT.STATUS", $KeywordRegistry.contactStatus$active()) - .buildSql("select CONTACT.CONTACTID, CONTACT.ORGANISATION_ID, ORGANISATION.NAME, CONTACT.PERSON_ID, \n\ - CONTACT.ISOLANGUAGE, PERSON.LASTNAME, PERSON.FIRSTNAME from CONTACT \n\ - join ORGANISATION on ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID \n\ - left join PERSON on CONTACT.PERSON_ID = PERSON.PERSONID \n\ - join COMMUNICATION on COMMUNICATION.CONTACT_ID = CONTACT.CONTACTID"); - + .andIn("COMMUNICATION.CONTACT_ID", contactIds)//this is automatically only added if pContactIds is filled + .andPrepare("CONTACT.STATUS", $KeywordRegistry.contactStatus$active()) + .buildSql("select CONTACT.CONTACTID, CONTACT.ORGANISATION_ID, ORGANISATION.NAME, CONTACT.PERSON_ID, \n\ + CONTACT.ISOLANGUAGE, PERSON.LASTNAME, PERSON.FIRSTNAME from CONTACT \n\ + join ORGANISATION on ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID \n\ + left join PERSON on CONTACT.PERSON_ID = PERSON.PERSONID \n\ + join COMMUNICATION on COMMUNICATION.CONTACT_ID = CONTACT.CONTACTID"); var contacts = db.table(contactSql); - return contacts.map(function (e){//map to the result how the entities-methods would return it to have less effort later + //map to the result how the entities-methods would return it to have less effort later when the mentioned ticket is done + return contacts.map(function (e){ return { CONTACTID: e[0], ORGANISATION_ID: e[1], diff --git a/process/ctiServerEvents/process.js b/process/ctiServerEvents/process.js index 0375f23402be095c7856026594d7ed536cb87f36..da681a7c366102ad5f3faa5e6e7f51f1943de2f9 100644 --- a/process/ctiServerEvents/process.js +++ b/process/ctiServerEvents/process.js @@ -62,7 +62,7 @@ var ringingHandlerFn = function() notificationConfig.linkInfo(text.encodeMS([affectedContext, affectedContactId])); } - + notification.addNotificationWith(notificationConfig); return null; }, this); @@ -136,6 +136,14 @@ var disconnectingHandlerFn = function() var notificationConfig = this.getNotificationBaseConfig(userObj[tools.NAME]); if (notificationConfig == null) return null; + + if (this.contactsCall.length > 0) + { + var affectedContext = this.contactsCall[0].PERSON_ID.trim() == "" ? "Organisation" : "Person"; + var affectedContactId = this.contactsCall[0].CONTACTID; + notificationConfig.linkInfo(text.encodeMS([affectedContext, affectedContactId])); + } + notificationConfig.description(desc).caption(title); notification.addNotificationWith(notificationConfig); @@ -158,6 +166,10 @@ var callData = { ,isConnectedCall: false }; +//for testing only: +//callData.callAddress = "01731858728"; +//callData.localAddress = "PJSIP/212"; + var ic = new IncomingCallExecutor(callData); //ic.logData(); ic.setHandlerRinging(ringingHandlerFn);