From 18459ea7a92c90f28ac752717e15283658918c6e Mon Sep 17 00:00:00 2001
From: Vinzent Broens <v.broens@adito.de>
Date: Tue, 23 Nov 2021 10:43:55 +0100
Subject: [PATCH] Service 2001420 searchcomponent

---
 .../basic/2021.2.2/Mailbridge/changelog.xml   |   6 +
 .../insert_InboxFilterComponent.xml           |  17 +++
 .../Data_alias/basic/2021.2.2/changelog.xml   |   1 +
 .liquibase/Data_alias/basic/changelog.xml     |  35 ++++++
 .../_____LANGUAGE_de/_____LANGUAGE_de.aod     |   8 ++
 process/KeywordRegistry_basic/process.js      |   1 +
 process/mailbridge_service/process.js         | 115 +++++++++++-------
 7 files changed, 137 insertions(+), 46 deletions(-)
 create mode 100644 .liquibase/Data_alias/basic/2021.2.2/Mailbridge/changelog.xml
 create mode 100644 .liquibase/Data_alias/basic/2021.2.2/Mailbridge/insert_InboxFilterComponent.xml
 create mode 100644 .liquibase/Data_alias/basic/changelog.xml

diff --git a/.liquibase/Data_alias/basic/2021.2.2/Mailbridge/changelog.xml b/.liquibase/Data_alias/basic/2021.2.2/Mailbridge/changelog.xml
new file mode 100644
index 0000000000..6bf1aea5c3
--- /dev/null
+++ b/.liquibase/Data_alias/basic/2021.2.2/Mailbridge/changelog.xml
@@ -0,0 +1,6 @@
+<?xml version="1.1" encoding="UTF-8" standalone="no"?>
+<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
+    <include relativeToChangelogFile="true" file="insert_InboxFilterComponent.xml"/>
+</databaseChangeLog>
\ No newline at end of file
diff --git a/.liquibase/Data_alias/basic/2021.2.2/Mailbridge/insert_InboxFilterComponent.xml b/.liquibase/Data_alias/basic/2021.2.2/Mailbridge/insert_InboxFilterComponent.xml
new file mode 100644
index 0000000000..ea752f5f89
--- /dev/null
+++ b/.liquibase/Data_alias/basic/2021.2.2/Mailbridge/insert_InboxFilterComponent.xml
@@ -0,0 +1,17 @@
+<?xml version="1.1" encoding="UTF-8" standalone="no"?>
+<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
+  <changeSet author="" id="27c0ee46-a456-479e-a5b6-27e4624f6b18">
+         <insert tableName="ab_keyword_entry">  
+            <column  name="AB_KEYWORD_ENTRYID"  value="958021c1-e025-4d8c-8cfb-0d963d609dc2"/>  
+            <column  name="KEYID"  value="SUBJECT_BODY"/>  
+            <column  name="TITLE"  value="Subject and Body"/>  
+            <column  name="CONTAINER"  value="InboxFilterComponent"/>  
+            <column  name="SORTING"  valueNumeric="3"/>  
+            <column  name="ISACTIVE"  valueNumeric="1"/>  
+            <column  name="ISESSENTIAL"  valueNumeric="0"/>  
+            <column  name="AB_KEYWORD_CATEGORY_ID"  value="7723f275-e9b2-4a77-92de-e2e558638664"/>
+        </insert> 
+  </changeSet>
+</databaseChangeLog>
\ No newline at end of file
diff --git a/.liquibase/Data_alias/basic/2021.2.2/changelog.xml b/.liquibase/Data_alias/basic/2021.2.2/changelog.xml
index f704b30fcf..c9c9c57ec0 100644
--- a/.liquibase/Data_alias/basic/2021.2.2/changelog.xml
+++ b/.liquibase/Data_alias/basic/2021.2.2/changelog.xml
@@ -7,4 +7,5 @@
     <include relativeToChangelogFile="true" file="Person/changelog.xml"/>
     <include relativeToChangelogFile="true" file="Employee/changelog.xml"/>
     <include relativeToChangelogFile="true" file="Mosaico/insert_mosaico_color_keyword.xml"/>
+    <include relativeToChangelogFile="true" file="mailbridge/changelog.xml"/>
 </databaseChangeLog>
\ No newline at end of file
diff --git a/.liquibase/Data_alias/basic/changelog.xml b/.liquibase/Data_alias/basic/changelog.xml
new file mode 100644
index 0000000000..44a36199ef
--- /dev/null
+++ b/.liquibase/Data_alias/basic/changelog.xml
@@ -0,0 +1,35 @@
+<?xml version="1.1" encoding="UTF-8" standalone="no"?>
+<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
+    <include relativeToChangelogFile="true" file="basic/init/init.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2019.1.4/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2019.2.1/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2019.3.0/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2019.3.1/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2019.3.2/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2019.3.3/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2020.0.0/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2020.0.1/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2020.0.2/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2020.0.3/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2020.1.0/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2020.1.1/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2020.1.2/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2020.1.3/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2020.2.0/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2020.2.1/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2020.2.2/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2020.2.3/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2021.0.0/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2021.0.1/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2021.0.2/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2021.0.3/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2021.1.0/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2021.1.1/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2021.1.2/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2021.1.3/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2021.2.0/changelog.xml"/>
+    <include relativeToChangelogFile="true" file="basic/2021.2.2/changelog.xml"/>
+
+    <include relativeToChangelogFile="true" file="basic/workflows/changelog.xml" context="workflow"/>
+    <include relativeToChangelogFile="true" file="basic/_demoData/changelog.xml" context="example"/>
+</databaseChangeLog>
\ No newline at end of file
diff --git a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
index 06691d8a2a..4fefbed199 100644
--- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
+++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
@@ -57,6 +57,10 @@
       <key>Single (Service/Internal)</key>
       <value>Einzel (Service/Intern)</value>
     </entry>
+    <entry>
+      <key>Subject and Body</key>
+      <value>Betreff und Mailtext</value>
+    </entry>
     <entry>
       <key>Original editor</key>
       <value>Originaler Bearbeiter</value>
@@ -13910,6 +13914,10 @@ Bitte Datumseingabe prüfen</value>
       <key>Task maturity date</key>
       <value>Prüfdatum</value>
     </entry>
+    <entry>
+      <key>New service ticket</key>
+      <value>Neues Serviceticket</value>
+    </entry>
     <entry>
       <key>Support tickets</key>
       <value>Supporttickets</value>
diff --git a/process/KeywordRegistry_basic/process.js b/process/KeywordRegistry_basic/process.js
index aaefacad70..678044ed04 100644
--- a/process/KeywordRegistry_basic/process.js
+++ b/process/KeywordRegistry_basic/process.js
@@ -421,6 +421,7 @@ $KeywordRegistry.inboxFilterComponent = function(){return "InboxFilterComponent"
 $KeywordRegistry.inboxFilterComponent$body = function(){return "BODY";};
 $KeywordRegistry.inboxFilterComponent$subject = function(){return "SUBJECT";};
 $KeywordRegistry.inboxFilterComponent$sender = function(){return "SENDER";};
+$KeywordRegistry.inboxFilterComponent$subject_body = function(){return "SUBJECT_BODY";};
 
 $KeywordRegistry.inboxFilterTarget = function(){return "InboxFilterTarget";};
 $KeywordRegistry.inboxFilterTarget$category = function(){return "CATEGORY";};
diff --git a/process/mailbridge_service/process.js b/process/mailbridge_service/process.js
index d05860bd63..c26b4a2792 100644
--- a/process/mailbridge_service/process.js
+++ b/process/mailbridge_service/process.js
@@ -49,7 +49,6 @@ TicketMailbridgeUtils.insertLog = function(pTicketId, pDescription)
         "USER_NEW" : "adito.server"
     }
     new SqlBuilder().insertFields(valueFields, "AB_LOGHISTORY", "AB_LOGHISTORYID");
- 
 }
 
 /*
@@ -105,47 +104,47 @@ TicketMailbridgeUtils.getDefaultInbox = function ()
 */
 TicketMailbridgeUtils.getInboxInformationAllRecipients = function(pRecipients, pSender, possibleBCC, possibleBCCUnfiltered)
 {
-    var inboxObj                    = {};
+    var inboxObj                    = {};   
     var inboxFound                  = false;
     var inboxInformation;
-    
+ 
     // try to find an Inbox via Recipients
     if (pRecipients != "")
     {
         inboxObj["inboxID"] = TicketMailbridgeUtils.getInbox(pRecipients);
         if(inboxObj.inboxID.length > 0)
-        {
-           inboxInformation = TicketMailbridgeUtils.getInboxInformation(pRecipients,inboxObj["inboxID"][0]);
-           inboxObj["reopenDelay"] = inboxInformation[0];
-           inboxObj["mailSignatureID"] = inboxInformation[1];
-           inboxFound = true;
+        {  
+            inboxInformation = TicketMailbridgeUtils.getInboxInformation(pRecipients,inboxObj["inboxID"][0]);
+            inboxObj["reopenDelay"] = inboxInformation[0];
+            inboxObj["mailSignatureID"] = inboxInformation[1];
+            inboxFound = true;
         }
     }
     // try to find inbox from possible BCC without INBOX-Mails
     if (possibleBCC != "" && inboxFound == false )
     {
-        inboxObj["inboxID"] = TicketMailbridgeUtils.getInbox(possibleBCC);
+        inboxObj["inboxID"] = TicketMailbridgeUtils.getInbox(possibleBCC); 
         // found an Inbox?
         if(inboxObj.inboxID.length > 0)
-        {
-           inboxInformation = TicketMailbridgeUtils.getInboxInformation(possibleBCC,inboxObj["inboxID"][0]);
-           inboxObj["reopenDelay"] = inboxInformation[0];
-           inboxObj["mailSignatureID"] = inboxInformation[1];
-           inboxFound = true;
-        }    
+        {  
+            inboxInformation = TicketMailbridgeUtils.getInboxInformation(possibleBCC,inboxObj["inboxID"][0]);
+            inboxObj["reopenDelay"] = inboxInformation[0];
+            inboxObj["mailSignatureID"] = inboxInformation[1];
+            inboxFound = true;
+        }
     }
     // use BACKUP INBOX-Mails
     if (possibleBCCUnfiltered != "" && inboxFound == false )
     {
-        inboxObj["inboxID"] = TicketMailbridgeUtils.getInbox(possibleBCCUnfiltered);
+        inboxObj["inboxID"] = TicketMailbridgeUtils.getInbox(possibleBCCUnfiltered); 
         // found an Inbox?
         if(inboxObj.inboxID.length > 0)
-        {
-           inboxInformation = TicketMailbridgeUtils.getInboxInformation(possibleBCCUnfiltered,inboxObj["inboxID"][0]);
-           inboxObj["reopenDelay"] = inboxInformation[0];
-           inboxObj["mailSignatureID"] = inboxInformation[1];
-           inboxFound = true;
-        }    
+        {  
+            inboxInformation = TicketMailbridgeUtils.getInboxInformation(possibleBCCUnfiltered,inboxObj["inboxID"][0]);
+            inboxObj["reopenDelay"] = inboxInformation[0];
+            inboxObj["mailSignatureID"] = inboxInformation[1];
+            inboxFound = true;
+        }  
     }
     // else use the Inbox with the default mailsignature
     if (inboxFound == false)
@@ -373,18 +372,27 @@ TicketMailbridgeUtils.findTicket = function(pSubject, pInboxObject, pMailObj)
             
             if(ticketData.length > 0)
             {
-                if(ticketData.length > 1) { //if ticketcode is not unique -> check for sender email
-                    var singleTicket = ticketData.findIndex(function(mail) {
+                if(ticketData.length > 1) 
+                { //if ticketcode is not unique -> check for sender email
+                    var singleTicket = ticketData.findIndex(function(mail) 
+                    {
                         return mail[5] == pMailObj.send;
                     });
                     
-                    if(singleTicket > -1) {
+                    if(singleTicket > -1) 
+                    {
                         ticketData = ticketData[singleTicket];
-                    } else {
+                    } 
+                    else 
+                    {
                         ticketData = ticketData[0];
                     }
-                } else 
+                } 
+                
+                else 
+
                     ticketData = ticketData[0];
+                }
                 
                 // set TicketID    
                 ticketID = ticketData[0];
@@ -506,7 +514,6 @@ TicketMailbridgeUtils.findTicket = function(pSubject, pInboxObject, pMailObj)
                                .and("TICKET.INBOX_ID", pInboxObject.inboxID[0])
                                .cell();
             }
-             
             if(ticketID != "")
             {
                 // insert for ACTIVITY
@@ -717,7 +724,7 @@ TicketMailbridgeUtils.createTicket = function(pMailObject, pFilterResult, pInbox
     // sending Automatic Answeremail 
     if(answerMail != "" && answerMail != undefined && answerMailActive !="" && answerMailActive == true)
     {
-        var eml             = new Email();     
+        var eml             = new Email();
         // use answer mail address, if answer mail address is set for the selected inbox
         var commAddr = pInboxObj.mailSignatureID[6]; // answer_mail_address
         if (commAddr)
@@ -726,7 +733,7 @@ TicketMailbridgeUtils.createTicket = function(pMailObject, pFilterResult, pInbox
         }
         else
         {
-            eml.sender      = mailRec || inboxUser;
+            eml.sender          = mailRec || inboxUser;
         }
         
         // use individual answer, if individual answer template is set for the selected ticket template
@@ -740,7 +747,7 @@ TicketMailbridgeUtils.createTicket = function(pMailObject, pFilterResult, pInbox
         {
             eml.body        = StringUtils.replaceAll(bodyDocuTempl.toString(), "{@Service@}", DocumentTemplateUtils.getTemplate(answerMail, false));
         }        
-
+       
         eml.subject         = ticketSub +" ["+ ticketCode +"]";
         eml.toRecipients    = [persFrom];
         
@@ -773,14 +780,15 @@ TicketMailbridgeUtils.createTicket = function(pMailObject, pFilterResult, pInbox
     
     //start workflow
     var workflowKey = pInboxObj["mailSignatureID"][4]; // workflow
-    if(workflowKey){
-        var processVariables = {
+    if(workflowKey)
+    {
+        var processVariables = 
+        {
             "targetId": ticketID,
             "targetContext": "SupportTicket"
         };
         workflow.startProcessByKey(workflowKey, processVariables);
     }
-    
 }
  
   
@@ -814,6 +822,7 @@ TicketMailbridgeUtils.useFiler = function(pInboxObj, pMailObject, pTicketfromOld
                 componentType = pMailObject[mail.MAIL_TEXT] || " ";
                 break;
             case "SUBJECT":
+            case "SUBJECT_BODY":
                 componentType = pMailObject[mail.MAIL_SUBJECT] || " ";
                 break;
             case "RECIPIENT":
@@ -835,15 +844,27 @@ TicketMailbridgeUtils.useFiler = function(pInboxObj, pMailObject, pTicketfromOld
             scoreObject["scoreData"].push([prioCriteria, tickettemplateId]); // Adding Score to Object      
             categoriesFormatted += translate.text("Search term") + " '" +   searchTerm.toString() +"' " + translate.text("determined in") + " "+ KeywordUtils.getViewValue($KeywordRegistry.inboxFilterComponent(), component) + "\n";
         }
-    }
+        // If subject and body are selected for search, repeat process with body
+        if (component == "SUBJECT_BODY")
+        {
+            componentType = pMailObject[mail.MAIL_TEXT]
+            var score = text.analyzeText(componentType, patternArr, false);
     
+            if(score[searchTerm] > 0)
+            {
+                scoreObject["scoreData"] = scoreObject["scoreData"] || [];
+                scoreObject["scoreData"].push([prioCriteria, tickettemplateId]); // Adding Score to Object      
+                categoriesFormatted += translate.text("Search term") + " '" +   searchTerm.toString() +"' " + translate.text("determined in") + " "+ KeywordUtils.getViewValue($KeywordRegistry.inboxFilterComponent(), component) + "\n";
+            }
+        }
+    }
     scoreObject["CategoryLogInfo"] = categoriesFormatted;
     
     this.createTicket(pMailObject ,scoreObject, pInboxObj, pTicketfromOldOne);
-    
 }
 
-TicketMailbridgeUtils.setTicketCodeRegex = function(pRegexString){
+TicketMailbridgeUtils.setTicketCodeRegex = function(pRegexString)
+{
     this.codeRegex = new RegExp(pRegexString, "g");
 }
 
@@ -858,6 +879,7 @@ TicketMailbridgeUtils.useAttributeFilter = function(pInboxObj, pTicketID, pMailO
     var IDX_EXISTING_ATTRS = 1;
     var IDX_ATTRIBUTEID = 0;
     var attributeCountObj = {};
+    
     if (attributeFilters.length > 0)
     {
     // searches for the appropriate fix attribute filter ids
@@ -878,7 +900,8 @@ TicketMailbridgeUtils.useAttributeFilter = function(pInboxObj, pTicketID, pMailO
         // creates the max count object so that the maximum number of the attribute can be checked
         if(attributesToInsert.length > 0)
         {
-            attributesToInsert.forEach(function(attribute){
+            attributesToInsert.forEach(function(attribute)
+            {
                 attributeIds.push(attribute[IDX_ATTRIBUTEID]);
                 attributeCountObj[attribute[IDX_ATTRIBUTEID]] = [0, 0]; // [maxCount, alreadyExistingAttributes]
             });
@@ -891,13 +914,15 @@ TicketMailbridgeUtils.useAttributeFilter = function(pInboxObj, pTicketID, pMailO
                                 .table();
             
             
-            attributeCounts.forEach(function([attributeId, maxCount]){
+            attributeCounts.forEach(function([attributeId, maxCount])
+            {
                 attributeCountObj[attributeId][IDX_MAX_COUNT] = maxCount;
             });
             
             var table = "AB_ATTRIBUTERELATION";
             var vals = [];
-            var attributeTypeIdx = {
+            var attributeTypeIdx = 
+            {
                 "CHAR_VALUE": 1,
                 "ID_VALUE": 2,
                 "DATE_VALUE": 3,
@@ -905,7 +930,8 @@ TicketMailbridgeUtils.useAttributeFilter = function(pInboxObj, pTicketID, pMailO
                 "INT_VALUE": 5
             }
             
-            attributesToInsert.forEach(function(attribute){
+            attributesToInsert.forEach(function(attribute)
+            {
                 // if there is no maximum count or the maximum count of the attribute has not been exceeded the attribute will be inserted
                 if(attributeCountObj[attribute[IDX_ATTRIBUTEID]][IDX_MAX_COUNT] == 0 || 
                     attributeCountObj[attribute[IDX_ATTRIBUTEID]][IDX_EXISTING_ATTRS] < 
@@ -925,7 +951,6 @@ TicketMailbridgeUtils.useAttributeFilter = function(pInboxObj, pTicketID, pMailO
                     
                 }
             });
-            
             new db.inserts(inserts);
         }
     }
@@ -933,8 +958,6 @@ TicketMailbridgeUtils.useAttributeFilter = function(pInboxObj, pTicketID, pMailO
     { 
         TicketMailbridgeUtils.insertLog(pTicketID, translate.text("Attribute determination") + ":\n" + logMessage);
     }
-
-    
 }
 
 /*
@@ -949,8 +972,8 @@ TicketMailbridgeUtils.checkAttributeFilters = function(pAttributeFilters, pMailO
 {
     var filterResult;
     
-    pAttributeFilters.forEach(function([attributeFilterId, component, searchterm]){
-        
+    pAttributeFilters.forEach(function([attributeFilterId, component, searchterm])
+    {
         var textToSearch;
         searchterm = searchterm || "";
         
-- 
GitLab