From d03a685f7a01ed6eb3a0eb6c6aaa68dadc4c3644 Mon Sep 17 00:00:00 2001
From: "b.ulrich" <b.ulrich@adito.de>
Date: Wed, 20 Jan 2021 08:22:59 +0100
Subject: [PATCH] 1070913

---
 .liquibase/Data_alias/changelog.xml           |  2 +-
 .../ClassificationAdmin_entity.aod            | 10 +++-
 .../onActionProcess.js                        | 24 +++++++++
 .../process.js                                | 49 ++++++++++++++-----
 4 files changed, 71 insertions(+), 14 deletions(-)
 create mode 100644 entity/ClassificationAdmin_entity/entityfields/filterviewactiongroup/children/updateallclassifications/onActionProcess.js

diff --git a/.liquibase/Data_alias/changelog.xml b/.liquibase/Data_alias/changelog.xml
index e49dccc3c73..c6e5850fd70 100644
--- a/.liquibase/Data_alias/changelog.xml
+++ b/.liquibase/Data_alias/changelog.xml
@@ -22,5 +22,5 @@
     <include relativeToChangelogFile="true" file="basic/2021.0.0/changelog.xml"/>
 
     <!--enable this only when you definetly want to overwrite the existing data with demo records:-->
-    <!--<include relativeToChangelogFile="true" file="basic/_demoData/changelog.xml" context="example"/>-->
+    <include relativeToChangelogFile="true" file="basic/_demoData/changelog.xml" context="example"/>
 </databaseChangeLog>
diff --git a/entity/ClassificationAdmin_entity/ClassificationAdmin_entity.aod b/entity/ClassificationAdmin_entity/ClassificationAdmin_entity.aod
index 50832393a42..70859b3cb7a 100644
--- a/entity/ClassificationAdmin_entity/ClassificationAdmin_entity.aod
+++ b/entity/ClassificationAdmin_entity/ClassificationAdmin_entity.aod
@@ -92,9 +92,17 @@
       <children>
         <entityActionField>
           <name>UpdateClassification</name>
-          <title>Recalculate all Classifications</title>
+          <title>Recalculate Classifications</title>
           <onActionProcess>%aditoprj%/entity/ClassificationAdmin_entity/entityfields/filterviewactiongroup/children/updateclassification/onActionProcess.js</onActionProcess>
           <iconId>VAADIN:AUTOMATION</iconId>
+          <tooltip>Use this to manually start the serverprocess after changes to the configuration of classifications. It will recalculate all outdated classifications.</tooltip>
+        </entityActionField>
+        <entityActionField>
+          <name>UpdateAllClassifications</name>
+          <title>Recalculate all Classifications</title>
+          <onActionProcess>%aditoprj%/entity/ClassificationAdmin_entity/entityfields/filterviewactiongroup/children/updateallclassifications/onActionProcess.js</onActionProcess>
+          <iconId>VAADIN:AUTOMATION</iconId>
+          <tooltip>Use this to manually start the serverprocess, which will this time recalculate all classifications. Do this after e.g importing data from elswhere where the outdated flag couldn't been set correctly</tooltip>
         </entityActionField>
       </children>
     </entityActionGroup>
diff --git a/entity/ClassificationAdmin_entity/entityfields/filterviewactiongroup/children/updateallclassifications/onActionProcess.js b/entity/ClassificationAdmin_entity/entityfields/filterviewactiongroup/children/updateallclassifications/onActionProcess.js
new file mode 100644
index 00000000000..a8ccdd28ccb
--- /dev/null
+++ b/entity/ClassificationAdmin_entity/entityfields/filterviewactiongroup/children/updateallclassifications/onActionProcess.js
@@ -0,0 +1,24 @@
+import("system.process");
+import("system.question");
+import("system.text");
+import("system.translate");
+import("system.util");
+import("system.vars");
+
+var execute = question.askYesNo(translate.text("Start Serveprocess"), translate.text("Are you sure you want to recalculate all classifications using the current classificationgradings? This can take some time, since ALL classifications will get freshly calculated and updated if needed."), false);
+if(execute)
+{
+    
+    
+    var processConfig = process.createStartAsyncConfig()
+                                                        .setName("updateClassifications_serverProcess")
+                                                        .setUser( vars.get("$sys.user"))
+                                                        .setThreadPriority(process.THREADPRIORITY_LOW)
+                                                        .setTimerType(process.TIMERTYPE_SERVER)
+                                                        .setLocalVariables({"recalculateAll_param" : true});
+                                                        
+
+    process.startAsync(processConfig);
+
+    question.showMessage(translate.text("Serverprocess has been started"), question.INFORMATION, translate.text("Classification"));
+}
diff --git a/process/updateClassifications_serverProcess/process.js b/process/updateClassifications_serverProcess/process.js
index 4bcfa2bb221..9bdf040f4cd 100644
--- a/process/updateClassifications_serverProcess/process.js
+++ b/process/updateClassifications_serverProcess/process.js
@@ -52,23 +52,36 @@ var table = "CLASSIFICATIONSTORAGE";
 var column = ["CLASSIFICATIONVALUE"];
 var runUpdating = 0;
 var singleRefresh = false;
+var recalculateAll = false;
+
 if(vars.exists("$local.refreshSingleRecord_param") && vars.get("$local.refreshSingleRecord_param"))
 {
     singleRefresh = vars.get("$local.refreshSingleRecord_param");
 }
-//all classificationgroups and their object_type that have atleast one classificationtype with the outdated flag set
-if(!singleRefresh)
+else if(vars.exists("$local.recalculateAll_param") && vars.get("$local.recalculateAll_param"))
+{
+    recalculateAll = vars.get("$local.recalculateAll_param");
+}
+
+
+if(singleRefresh)
 {
     outdatedGroupsAndObjectTypes = newSelect("CLASSIFICATIONTYPE.OBJECT_TYPE, CLASSIFICATIONTYPE.CLASSIFICATIONGROUP_ID, CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID, CLASSIFICATIONTYPE.FILTER")
                                         .from("CLASSIFICATIONTYPE")
-                                        .where("CLASSIFICATIONTYPE.OUTDATED", 1)
+                                        .where("CLASSIFICATIONTYPE.OBJECT_TYPE", vars.get("$local.ObjectType_param"))
                                         .table();
 }
-else
+else if(recalculateAll)
 {
     outdatedGroupsAndObjectTypes = newSelect("CLASSIFICATIONTYPE.OBJECT_TYPE, CLASSIFICATIONTYPE.CLASSIFICATIONGROUP_ID, CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID, CLASSIFICATIONTYPE.FILTER")
                                         .from("CLASSIFICATIONTYPE")
-                                        .where("CLASSIFICATIONTYPE.OBJECT_TYPE", vars.get("$local.ObjectType_param"))
+                                        .table();
+}
+else //all classificationgroups and their object_type that have atleast one classificationtype with the outdated flag set
+{
+    outdatedGroupsAndObjectTypes = newSelect("CLASSIFICATIONTYPE.OBJECT_TYPE, CLASSIFICATIONTYPE.CLASSIFICATIONGROUP_ID, CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID, CLASSIFICATIONTYPE.FILTER")
+                                        .from("CLASSIFICATIONTYPE")
+                                        .where("CLASSIFICATIONTYPE.OUTDATED", 1)
                                         .table();
 }
 
@@ -112,13 +125,25 @@ for (i = 0; i < outdatedGroupsAndObjectTypes.length; i++)
 }
 if(!singleRefresh)
 {
-    //object_type, object_rowId, classificationstorageId and the classificationstring (e.g. "ACB") of the classificationStorage datasets that habe the outdated flag set
-    outdatedStoredClassifications = newSelect("CLASSIFICATIONSTORAGE.OBJECT_TYPE, CLASSIFICATIONSTORAGE.OBJECT_ROWID, \n\
-                                                        CLASSIFICATIONSTORAGE.CLASSIFICATIONSTORAGEID, CLASSIFICATIONSTORAGE.CLASSIFICATIONVALUE")
-                                                    .from("CLASSIFICATIONSTORAGE")
-                                                    .where("CLASSIFICATIONSTORAGE.OUTDATED", 1)
-                                                    .orderBy("OBJECT_TYPE")
-                                                    .table();
+    if(recalculateAll)
+    {
+        outdatedStoredClassifications = newSelect("CLASSIFICATIONSTORAGE.OBJECT_TYPE, CLASSIFICATIONSTORAGE.OBJECT_ROWID, \n\
+                                                            CLASSIFICATIONSTORAGE.CLASSIFICATIONSTORAGEID, CLASSIFICATIONSTORAGE.CLASSIFICATIONVALUE")
+                                                        .from("CLASSIFICATIONSTORAGE")
+                                                        .where("CLASSIFICATIONSTORAGE.OUTDATED", 1)
+                                                        .orderBy("OBJECT_TYPE")
+                                                        .table();
+    }
+    else
+    {
+        //object_type, object_rowId, classificationstorageId and the classificationstring (e.g. "ACB") of the classificationStorage datasets that habe the outdated flag set
+        outdatedStoredClassifications = newSelect("CLASSIFICATIONSTORAGE.OBJECT_TYPE, CLASSIFICATIONSTORAGE.OBJECT_ROWID, \n\
+                                                            CLASSIFICATIONSTORAGE.CLASSIFICATIONSTORAGEID, CLASSIFICATIONSTORAGE.CLASSIFICATIONVALUE")
+                                                        .from("CLASSIFICATIONSTORAGE")
+                                                        .where("CLASSIFICATIONSTORAGE.OUTDATED", 1)
+                                                        .orderBy("OBJECT_TYPE")
+                                                        .table();
+    }
     helperObject = {};                                      
     if(outdatedStoredClassifications)
     {
-- 
GitLab