From 47d8c6e37bb723882d8b15e4667f343021fca418 Mon Sep 17 00:00:00 2001 From: "j.goderbauer" <j.goderbauer@adito.de> Date: Thu, 28 Feb 2019 16:05:14 +0100 Subject: [PATCH] =?UTF-8?q?[Projekt:=20Entwicklung=20-=20Neon][TicketNr.:?= =?UTF-8?q?=201032312][Keywords=20f=C3=BCr=20bestehende=20Module=20anlegen?= =?UTF-8?q?]=20->=20getPropForKey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entityfields/icon/valueProcess.js | 10 +++-- .../entityfields/addr/contentTypeProcess.js | 17 ++++---- .../entityfields/addr/onValidation.js | 10 +++-- entity/Task_entity/iconIdProcess.js | 6 ++- process/Communication_lib/process.js | 2 +- process/Keyword_lib/process.js | 41 ++++++++++++++++--- process/Organisation_lib/process.js | 2 +- 7 files changed, 64 insertions(+), 24 deletions(-) diff --git a/entity/Activity_entity/entityfields/icon/valueProcess.js b/entity/Activity_entity/entityfields/icon/valueProcess.js index 505a2c92f1..19bec4e77a 100644 --- a/entity/Activity_entity/entityfields/icon/valueProcess.js +++ b/entity/Activity_entity/entityfields/icon/valueProcess.js @@ -2,9 +2,13 @@ import("system.vars"); import("system.result"); import("system.neon"); import("Keyword_lib"); +import("KeywordRegistry_basic"); var category = vars.getString("$field.CATEGORY"); -var kwd = LegacyKeywordUtils.createKeyword("ACTIVITY.CATEGORY");//getPropForKey -var icon = kwd.getPropForKey(category, "defaultAvatarRepresentation", true); - +var icon; +if (category) +{ + var keywordAttributes = KeywordUtils.getAttributeRelationsByKey(category, $KeywordRegistry.activityCategory()) + icon = keywordAttributes.defaultAvatarRepresentation; +} result.string(icon || "NEON:HISTORY"); diff --git a/entity/Communication_entity/entityfields/addr/contentTypeProcess.js b/entity/Communication_entity/entityfields/addr/contentTypeProcess.js index a960f567b9..25141c5377 100644 --- a/entity/Communication_entity/entityfields/addr/contentTypeProcess.js +++ b/entity/Communication_entity/entityfields/addr/contentTypeProcess.js @@ -1,17 +1,16 @@ import("Keyword_lib"); +import("KeywordRegistry_basic"); import("system.vars"); import("system.result"); import("system.neon"); -var medium, contentType; //TODO: add constants for contentTypes #1022547 -medium = vars.get("$field.MEDIUM_ID"); -if (medium){ - contentType = LegacyKeywordUtils.createKeyword("COMMUNICATION.MEDIUM").getPropForKey(medium, "contentType", true) || "TEXT"; +var medium = vars.get("$field.MEDIUM_ID"); +var contentType; +if (medium) +{ + var keywordAttributes = KeywordUtils.getAttributeRelationsByKey(medium, $KeywordRegistry.communicationMedium()); + contentType = keywordAttributes.contentType; } -else { - contentType = "TEXT"; -} -result.string(contentType); - +result.string(contentType || "TEXT"); \ No newline at end of file diff --git a/entity/Communication_entity/entityfields/addr/onValidation.js b/entity/Communication_entity/entityfields/addr/onValidation.js index bf2171c209..54a9148c82 100644 --- a/entity/Communication_entity/entityfields/addr/onValidation.js +++ b/entity/Communication_entity/entityfields/addr/onValidation.js @@ -7,13 +7,17 @@ import("Keyword_lib"); import("Communication_lib"); import("Util_lib"); import("Entity_lib"); +import("KeywordRegistry_basic"); -var kwd = LegacyKeywordUtils.createKeyword("COMMUNICATION.MEDIUM"); var commMedium = vars.get("$field.MEDIUM_ID"); -var commCategory = kwd.getPropForKey(commMedium, "contentType", true);//TODO: maybe accessible via $property - then it's not needed to keep this information within the keyword + +//TODO: maybe accessible via $property - then it's not needed to load that info twice +var keywordAttributes = KeywordUtils.getAttributeRelationsByKey(commMedium, $KeywordRegistry.communicationMedium()); +var commCategory = keywordAttributes.contentType || "TEXT"; var fn = CommValidationUtil.makeValidationFn(commCategory); -if (fn != null){ +if (fn != null) +{ var commAddr = ProcessHandlingUtils.getOnValidationValue(vars.get("$field.ADDR")); var additional = CommValidationUtil.getExtensionsBlueprint(); additional.countryCode = vars.get("$param.ContactsMainCountry_param");//TODO: try to use users language first and then the companies diff --git a/entity/Task_entity/iconIdProcess.js b/entity/Task_entity/iconIdProcess.js index 446b9205ba..c7a5eb8867 100644 --- a/entity/Task_entity/iconIdProcess.js +++ b/entity/Task_entity/iconIdProcess.js @@ -2,9 +2,11 @@ import("system.vars"); import("system.result"); import("system.neon"); import("Keyword_lib"); +import("KeywordRegistry_basic"); var category = vars.getString("$field.PRIORITY"); -var kwd = LegacyKeywordUtils.createKeyword("TASK.PRIORITY"); -var icon = kwd.getPropForKey(category, "defaultAvatarRepresentation", true); + +var keywordAttributes = KeywordUtils.getAttributeRelationsByKey(category, $KeywordRegistry.taskPriority()); +var icon = keywordAttributes.defaultAvatarRepresentation; result.string(icon || "VAADIN:TASKS"); \ No newline at end of file diff --git a/process/Communication_lib/process.js b/process/Communication_lib/process.js index f704ccfc6d..ef69755635 100644 --- a/process/Communication_lib/process.js +++ b/process/Communication_lib/process.js @@ -22,7 +22,7 @@ function CommUtil(){} */ CommUtil.getMediumIdsByCategory = function (pCategory) { - var kwd = LegacyKeywordUtils.createKeyword("COMMUNICATION.MEDIUM"); + var kwd = LegacyKeywordUtils.createKeyword("COMMUNICATION.MEDIUM");//filter keyword on category kwd.filter(function(id, name, customs){ return customs.category == pCategory; }); diff --git a/process/Keyword_lib/process.js b/process/Keyword_lib/process.js index c11bd2e8b7..a56c542f38 100644 --- a/process/Keyword_lib/process.js +++ b/process/Keyword_lib/process.js @@ -62,14 +62,45 @@ KeywordUtils.getViewValue = function(keywordContainer, key) * @return {Object} key-value-pair of the keyword-attributes; contains all attribute-keys for the keywords-entries container; * if there is no value set for a key the null-value is given */ -KeywordUtils.getKeywordAttributeRelations = function (pEntryId) +KeywordUtils.getAttributeRelationsByEntryId = function(pEntryId) { - var sql = SqlCondition.begin() - .andPrepare("AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID", pEntryId) - .buildSql("select AB_KEYWORD_ATTRIBUTE.NAME, AB_KEYWORD_ATTRIBUTE.TYPE, \n\ + var cond = SqlCondition.begin() + .andPrepare("AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID", pEntryId); + + return KeywordUtils._getKeywordAttributeRelations(cond); +}; + +/** + * collects possible and defined keyword-attributes per keyword entry and returns them + * + * @param {String} pKeyId the key of an element within a containerName - this is the value that is stored in the reference-table (e.g. "DE") + * @param {String} pContainerName specifies the type of the keyword and therefore the list elements; + * e.g. "COUNTRY"; use an entry of the $KeywordRegistry here + * @return {Object} key-value-pair of the keyword-attributes; contains all attribute-keys for the keywords-entries container; + * if there is no value set for a key the null-value is given + */ +KeywordUtils.getAttributeRelationsByKey = function(pKeyId, pContainerName) +{ + var cond = SqlCondition.begin() + .andPrepare("AB_KEYWORD_ENTRY.KEYID", pKeyId) + .andPrepare("AB_KEYWORD_ENTRY.CONTAINER", pContainerName); + + return KeywordUtils._getKeywordAttributeRelations(cond); +}; + +/** + * internal function that collects possible and defined keyword-attributes per keyword entry and returns them + * + * @param {SqlCondition} pSqlCondition condition that shrinks a resultset to one AB_KEYWORD_ENTRY + * @return {Object} SQL-Condition object that filters + */ +KeywordUtils._getKeywordAttributeRelations = function (pSqlCondition) +{ + var cond = pSqlCondition; + var sql = cond.buildSql("select AB_KEYWORD_ATTRIBUTE.NAME, AB_KEYWORD_ATTRIBUTE.TYPE, \n\ AB_KEYWORD_ATTRIBUTERELATION.CHAR_VALUE, AB_KEYWORD_ATTRIBUTERELATION.NUMBER_VALUE, AB_KEYWORD_ATTRIBUTERELATION.BOOL_VALUE \n\ from AB_KEYWORD_ENTRY \n\ - left join AB_KEYWORD_ATTRIBUTE on (AB_KEYWORD_ATTRIBUTE.CONTAINER = AB_KEYWORD_ENTRY.CONTAINER) \n\ + join AB_KEYWORD_ATTRIBUTE on (AB_KEYWORD_ATTRIBUTE.CONTAINER = AB_KEYWORD_ENTRY.CONTAINER) \n\ left join AB_KEYWORD_ATTRIBUTERELATION \n\ on (AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID = AB_KEYWORD_ATTRIBUTE.AB_KEYWORD_ATTRIBUTEID\n\ and AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID = AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID)"); diff --git a/process/Organisation_lib/process.js b/process/Organisation_lib/process.js index 27589bda8a..5296413175 100644 --- a/process/Organisation_lib/process.js +++ b/process/Organisation_lib/process.js @@ -133,7 +133,7 @@ OrgUtils.openOrgReport = function(pOrgId) histData.forEach(function (row) { row[0] = datetime.toDate(row[0], dateFormat); - row[1] = LegacyKeywordUtils.getViewValue($KeywordRegistry.activityCategory(), row[1]); + row[1] = KeywordUtils.getViewValue($KeywordRegistry.activityCategory(), row[1]); _joinArrayVals(row, 2, 2); }); histData = ReportData.begin(["ENTRYDATE", "MEDIUM", "LOGIN", "INFO"]).add(histData); -- GitLab