From 6ee1c53ad6055002eb8ec73ba6c970f8d001b29e Mon Sep 17 00:00:00 2001 From: "j.goderbauer" <j.goderbauer@adito.de> Date: Fri, 1 Mar 2019 11:36:00 +0100 Subject: [PATCH] [Projekt: Entwicklung - Neon][TicketNr.: 1030337][Umsetzung Keywordlogik] --- .../expression.js | 0 .../expression.js | 0 .../onValueChange.js | 0 .../onValueChange.js | 0 .../expression.js | 0 .../expression.js | 0 .../onValueChange.js | 0 .../onValueChange.js | 0 .../expression.js | 0 .../expression.js | 0 process/Communication_lib/process.js | 39 ++++++++++------- process/Keyword_lib/process.js | 29 ++++++++++++- process/Organisation_lib/process.js | 42 ++++++------------- 13 files changed, 64 insertions(+), 46 deletions(-) rename entity/AnyContact_entity/recordcontainers/db/recordfieldmappings/{standard_email_comm.value => standard_email_communication.value}/expression.js (100%) rename entity/AnyContact_entity/recordcontainers/db/recordfieldmappings/{standard_phone_comm.value => standard_phone_communication.value}/expression.js (100%) rename entity/Organisation_entity/entityfields/{standard_email_comm => standard_email_communication}/onValueChange.js (100%) rename entity/Organisation_entity/entityfields/{standard_phone_comm => standard_phone_communication}/onValueChange.js (100%) rename entity/Organisation_entity/recordcontainers/db/recordfieldmappings/{standard_email_comm.displayvalue => standard_email_communication.displayvalue}/expression.js (100%) rename entity/Organisation_entity/recordcontainers/db/recordfieldmappings/{standard_phone_comm.displayvalue => standard_phone_communication.displayvalue}/expression.js (100%) rename entity/Person_entity/entityfields/{standard_email_comm => standard_email_communication}/onValueChange.js (100%) rename entity/Person_entity/entityfields/{standard_phone_comm => standard_phone_communication}/onValueChange.js (100%) rename entity/Person_entity/recordcontainers/db/recordfieldmappings/{standard_email_comm.displayvalue => standard_email_communication.displayvalue}/expression.js (100%) rename entity/Person_entity/recordcontainers/db/recordfieldmappings/{standard_phone_comm.displayvalue => standard_phone_communication.displayvalue}/expression.js (100%) diff --git a/entity/AnyContact_entity/recordcontainers/db/recordfieldmappings/standard_email_comm.value/expression.js b/entity/AnyContact_entity/recordcontainers/db/recordfieldmappings/standard_email_communication.value/expression.js similarity index 100% rename from entity/AnyContact_entity/recordcontainers/db/recordfieldmappings/standard_email_comm.value/expression.js rename to entity/AnyContact_entity/recordcontainers/db/recordfieldmappings/standard_email_communication.value/expression.js diff --git a/entity/AnyContact_entity/recordcontainers/db/recordfieldmappings/standard_phone_comm.value/expression.js b/entity/AnyContact_entity/recordcontainers/db/recordfieldmappings/standard_phone_communication.value/expression.js similarity index 100% rename from entity/AnyContact_entity/recordcontainers/db/recordfieldmappings/standard_phone_comm.value/expression.js rename to entity/AnyContact_entity/recordcontainers/db/recordfieldmappings/standard_phone_communication.value/expression.js diff --git a/entity/Organisation_entity/entityfields/standard_email_comm/onValueChange.js b/entity/Organisation_entity/entityfields/standard_email_communication/onValueChange.js similarity index 100% rename from entity/Organisation_entity/entityfields/standard_email_comm/onValueChange.js rename to entity/Organisation_entity/entityfields/standard_email_communication/onValueChange.js diff --git a/entity/Organisation_entity/entityfields/standard_phone_comm/onValueChange.js b/entity/Organisation_entity/entityfields/standard_phone_communication/onValueChange.js similarity index 100% rename from entity/Organisation_entity/entityfields/standard_phone_comm/onValueChange.js rename to entity/Organisation_entity/entityfields/standard_phone_communication/onValueChange.js diff --git a/entity/Organisation_entity/recordcontainers/db/recordfieldmappings/standard_email_comm.displayvalue/expression.js b/entity/Organisation_entity/recordcontainers/db/recordfieldmappings/standard_email_communication.displayvalue/expression.js similarity index 100% rename from entity/Organisation_entity/recordcontainers/db/recordfieldmappings/standard_email_comm.displayvalue/expression.js rename to entity/Organisation_entity/recordcontainers/db/recordfieldmappings/standard_email_communication.displayvalue/expression.js diff --git a/entity/Organisation_entity/recordcontainers/db/recordfieldmappings/standard_phone_comm.displayvalue/expression.js b/entity/Organisation_entity/recordcontainers/db/recordfieldmappings/standard_phone_communication.displayvalue/expression.js similarity index 100% rename from entity/Organisation_entity/recordcontainers/db/recordfieldmappings/standard_phone_comm.displayvalue/expression.js rename to entity/Organisation_entity/recordcontainers/db/recordfieldmappings/standard_phone_communication.displayvalue/expression.js diff --git a/entity/Person_entity/entityfields/standard_email_comm/onValueChange.js b/entity/Person_entity/entityfields/standard_email_communication/onValueChange.js similarity index 100% rename from entity/Person_entity/entityfields/standard_email_comm/onValueChange.js rename to entity/Person_entity/entityfields/standard_email_communication/onValueChange.js diff --git a/entity/Person_entity/entityfields/standard_phone_comm/onValueChange.js b/entity/Person_entity/entityfields/standard_phone_communication/onValueChange.js similarity index 100% rename from entity/Person_entity/entityfields/standard_phone_comm/onValueChange.js rename to entity/Person_entity/entityfields/standard_phone_communication/onValueChange.js diff --git a/entity/Person_entity/recordcontainers/db/recordfieldmappings/standard_email_comm.displayvalue/expression.js b/entity/Person_entity/recordcontainers/db/recordfieldmappings/standard_email_communication.displayvalue/expression.js similarity index 100% rename from entity/Person_entity/recordcontainers/db/recordfieldmappings/standard_email_comm.displayvalue/expression.js rename to entity/Person_entity/recordcontainers/db/recordfieldmappings/standard_email_communication.displayvalue/expression.js diff --git a/entity/Person_entity/recordcontainers/db/recordfieldmappings/standard_phone_comm.displayvalue/expression.js b/entity/Person_entity/recordcontainers/db/recordfieldmappings/standard_phone_communication.displayvalue/expression.js similarity index 100% rename from entity/Person_entity/recordcontainers/db/recordfieldmappings/standard_phone_comm.displayvalue/expression.js rename to entity/Person_entity/recordcontainers/db/recordfieldmappings/standard_phone_communication.displayvalue/expression.js diff --git a/process/Communication_lib/process.js b/process/Communication_lib/process.js index ef69755635..50f6e2e7e1 100644 --- a/process/Communication_lib/process.js +++ b/process/Communication_lib/process.js @@ -6,6 +6,8 @@ import("system.net"); import("system.mail"); import("system.cti"); import("Sql_lib"); +import("KeywordRegistry_basic"); +import("Keyword_lib"); /** * provides static methods for Comm @@ -22,11 +24,16 @@ function CommUtil(){} */ CommUtil.getMediumIdsByCategory = function (pCategory) { - var kwd = LegacyKeywordUtils.createKeyword("COMMUNICATION.MEDIUM");//filter keyword on category - kwd.filter(function(id, name, customs){ - return customs.category == pCategory; - }); - var mediumIds = kwd.toArray("id"); + var keywordAttr = new KeywordAttribute($KeywordRegistry.communicationMedium(), "category"); + //TODO: waiting for load entity via JDito + var sql = SqlCondition.begin() + .andPrepare("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID", keywordAttr.id) + .andPrepare("AB_KEYWORD_ATTRIBUTERELATION." + keywordAttr.dbField, pCategory) + .buildSql("select AB_KEYWORD_ENTRY.KEYID \n\ + from AB_KEYWORD_ATTRIBUTERELATION \n\ + join AB_KEYWORD_ENTRY on AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID = AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID"); + + var mediumIds = db.array(db.COLUMN, sql); return mediumIds; }; @@ -99,23 +106,23 @@ CommUtil.setStandardMail = function(pAffectedRowId, pNewStandardCommId) /** * returns a sub sql-string (without bracets) for getting the standard address of a COMMUNICATION * @param {String} pCategory value of the keyword "COMMUNICATION.MEDIUM" custom.category; e.g. "PHONE" - * @param {String|SqlCondition} [pRelationField=CONTACT.CONTACTID] SQL-fieldname that shall be used for filtering the CONTACT_ID, this can be a string(fieldname) or an SqlCondition object + * @param {String|SqlCondition} [pContactField=CONTACT.CONTACTID] SQL-fieldname that shall be used for filtering the CONTACT_ID, this can be a string(fieldname) or an SqlCondition object * @return {String} sub-sql */ -CommUtil.getStandardSubSqlForCategory = function(pCategory, pRelationField) +CommUtil.getStandardSubSqlForCategory = function(pCategory, pContactField) { if (!pCategory) return "''"; var cond = SqlCondition.begin(); - if (pRelationField == undefined) + if (pContactField == undefined) cond.and("COMMUNICATION.CONTACT_ID = CONTACT.CONTACTID"); else if (typeof(pRelationField) == "string") - cond.andPrepare("COMMUNICATION.CONTACT_ID", pRelationField); + cond.andPrepare("COMMUNICATION.CONTACT_ID", pContactField); else if (typeof(pRelationField) == "object") { //you may want to sepcify a concrete value - cond.andSqlCondition(pRelationField, "1=2"); + cond.andSqlCondition(pContactField, "1=2"); } else return "''";//TODO: throw error @@ -139,22 +146,22 @@ CommUtil.getStandardSubSqlForCategory = function(pCategory, pRelationField) /** * returns a sub sql-string (without bracets) for getting the standard address of a PHONE-COMMUNICATION - * @param {String|SqlCondition} [pRelationField=CONTACT.CONTACTID] SQL-fieldname that shall be used for filtering the CONTACT_ID, this can be a string(fieldname) or an SqlCondition object + * @param {String|SqlCondition} [pContactField=CONTACT.CONTACTID] SQL-fieldname that shall be used for filtering the CONTACT_ID, this can be a string(fieldname) or an SqlCondition object * @return {String} sub-sql */ -CommUtil.getStandardSubSqlPhone = function(pRelationField) +CommUtil.getStandardSubSqlPhone = function(pContactField) { - return CommUtil.getStandardSubSqlForCategory("PHONE", pRelationField); + return CommUtil.getStandardSubSqlForCategory("PHONE", pContactField); }; /** * returns a sub sql-string (without bracets) for getting the standard address of a EMAIL-COMMUNICATION - * @param {String|SqlCondition} [pRelationField=CONTACT.CONTACTID] SQL-fieldname that shall be used for filtering the CONTACT_ID, this can be a string(fieldname) or an SqlCondition object + * @param {String|SqlCondition} [pContactField=CONTACT.CONTACTID] SQL-fieldname that shall be used for filtering the CONTACT_ID, this can be a string(fieldname) or an SqlCondition object * @return {String} sub-sql */ -CommUtil.getStandardSubSqlMail= function(pRelationField) +CommUtil.getStandardSubSqlMail= function(pContactField) { - return CommUtil.getStandardSubSqlForCategory("EMAIL", pRelationField); + return CommUtil.getStandardSubSqlForCategory("EMAIL", pContactField); }; /** diff --git a/process/Keyword_lib/process.js b/process/Keyword_lib/process.js index a56c542f38..eaab409237 100644 --- a/process/Keyword_lib/process.js +++ b/process/Keyword_lib/process.js @@ -133,7 +133,6 @@ KeywordUtils._getKeywordAttributeRelations = function (pSqlCondition) return res; }; - /** * provides a distinctive list of all keyword-container-names in the system * @@ -145,6 +144,34 @@ KeywordUtils.getContainerNames = function() return list; }; +/** + * object that provides featrues for a single keyword attribute; initalizes itself on creation with a specific keyword-attribute + * + * @param {String} pContainerName specifies the type of the keyword and therefore the list elements; + * e.g. "COUNTRY"; use an entry of the $KeywordRegistry here + * @param {String} pAttributeName the name of the keyword attribute that shall be initalized + * + * @class + */ +function KeywordAttribute(pContainerName, pAttributeName) +{ + this.container = pContainerName; + this.attribute = pAttributeName; + + var sql = SqlCondition.begin() + .andPrepare("AB_KEYWORD_ATTRIBUTE.CONTAINER", pContainerName) + .andPrepare("AB_KEYWORD_ATTRIBUTE.NAME", pAttributeName) + .buildSql("select AB_KEYWORD_ATTRIBUTE.AB_KEYWORD_ATTRIBUTEID, AB_KEYWORD_ATTRIBUTE.TYPE from AB_KEYWORD_ATTRIBUTE"); + + var keywordAttrData = db.array(db.ROW, sql); + + if (keywordAttrData.length == 0) + throw new Error(translate.withArguments("no keyword attribute \"%0\" found in keyword container \"%1\"", this.attribute, this.container)); + + this.id = keywordAttrData[0]; + this.type = keywordAttrData[1]; + this.dbField = this.type.trim(); +} /** * provides methods for interactions with the sepcial-keywords "LANGUAGE" diff --git a/process/Organisation_lib/process.js b/process/Organisation_lib/process.js index b54d93d93e..78565ea988 100644 --- a/process/Organisation_lib/process.js +++ b/process/Organisation_lib/process.js @@ -6,6 +6,7 @@ import("Report_lib"); import("Sql_lib"); import("Keyword_lib"); import("PostalAddress_lib"); +import("Communication_lib"); import("KeywordRegistry_basic"); /** @@ -81,42 +82,23 @@ OrgUtils.openOrgReport = function(pOrgId) commData = ReportData.begin(["KINDOFCOMM", "COMMVALUE"]).add(commData); //select people from the organization - //TODO: Position und Abteilung fehlen noch - var persSql = "select SALUTATION, TITLE, FIRSTNAME, LASTNAME, '', '', '', ORGANISATION_ID, CONTACTID" - + " from PERSON join CONTACT on PERSONID = PERSON_ID"; + + var persSql = "select SALUTATION, TITLE, FIRSTNAME, LASTNAME " + + ",'' as PERSFUNCITON, '' as PERSDEPARTMENT "//TODO: Position und Abteilung fehlen noch + + ",(" + CommUtil.getStandardSubSqlMail() + ")" + + ",(" + CommUtil.getStandardSubSqlPhone() + ")" + + ",ORGANISATION_ID, CONTACTID " + + "from PERSON join CONTACT on PERSONID = PERSON_ID"; persSql = SqlCondition.begin() .andPrepare("CONTACT.ORGANISATION_ID", pOrgId) .and("CONTACT.STATUS = '" + $KeywordRegistry.contactStatus$active() + "'") //TODO: replace this with something that isn't a hard coded id .buildSql(persSql, "", " order by PERSON.LASTNAME asc"); var persData = db.table(persSql); - //TODO: get the keywords in another way when keywords are entitys - var mediumIds = []; - var mediums = LegacyKeywordUtils.getStandardArrayProps("COMMUNICATION.MEDIUM"); - for (let i = 0; i < mediums.length; i++) - if ("category" in mediums[i][2] && (mediums[i][2].category == "PHONE" || mediums[i][2].category == "EMAIL")) - mediumIds.push(mediums[i][0]); - mediums = mediumIds.join(", "); - for (let i = 0; i < persData.length; i++) { _joinArrayVals(persData[i], 0, 4); //join the full name together - - //select the contact info for every person for phone and mail - var persCommSql = "select MEDIUM_ID, ADDR from COMMUNICATION"; - persCommSql = SqlCondition.begin() - .andPrepare("COMMUNICATION.CONTACT_ID", persData[i][5]) - .and("MEDIUM_ID in (" + mediumIds + ")") - .and("STANDARD = 1") - .buildSql(persCommSql); - var persDataComm = db.table(persCommSql); - - //resolve keyword - persData[i][3] = persDataComm.map(function (row) - { - return KeywordUtils.getViewValue($KeywordRegistry.communicationMedium(), row[0]) + ": " + row[1]; - } - ).join("\n"); + _joinArrayVals(persData[i], 3, 2, "\n"); //join communication together } persData = ReportData.begin(["PERSNAMECOMPLETE", "PERSFUNCTION", "PERSDEPARTMENT", "PERSCOMM", "ORGANISATION_ID", "CONTACT_ID"]).add(persData); @@ -185,10 +167,12 @@ OrgUtils.openOrgReport = function(pOrgId) /* * merges multiple columns in an two-dimensional array into one */ - function _joinArrayVals (pArr, pIndex, pHowMany) + function _joinArrayVals (pArr, pIndex, pHowMany, pJoinSeparator) { + if (pJoinSeparator == undefined) + pJoinSeparator = " "; pArr.splice(pIndex, pHowMany, pArr.slice(pIndex, pIndex + pHowMany) - .filter(function (val) {return val;}).join(" ")); + .filter(function (val) {return val;}).join(pJoinSeparator)); } } \ No newline at end of file -- GitLab