From 0961cce11af5eaa460b10e072abed499f75cfdd2 Mon Sep 17 00:00:00 2001 From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local> Date: Tue, 19 May 2020 13:52:11 +0200 Subject: [PATCH] Activty conditionProcess optimized --- .../recordcontainers/db/conditionProcess.js | 75 +++++++++--------- .../Organisation_entity.aod | 2 +- .../entityfields/contactid/valueProcess.js | 7 -- .../onlyshowcontactids_param/valueProcess.js | 77 ++++++++----------- .../WorkflowDefinitionFilter_view.aod | 1 + 5 files changed, 71 insertions(+), 91 deletions(-) delete mode 100644 entity/Organisation_entity/entityfields/contactid/valueProcess.js diff --git a/entity/Activity_entity/recordcontainers/db/conditionProcess.js b/entity/Activity_entity/recordcontainers/db/conditionProcess.js index fe77ebfa1d1..6b1c96c3d19 100644 --- a/entity/Activity_entity/recordcontainers/db/conditionProcess.js +++ b/entity/Activity_entity/recordcontainers/db/conditionProcess.js @@ -1,59 +1,56 @@ -import("system.logging"); import("Employee_lib"); import("system.vars"); import("system.db"); import("system.result"); import("Sql_lib"); -var loadNothing = false; -var cond = newWhere(); +var condition = newWhere(); if (vars.exists("$param.RowId_param") && vars.get("$param.RowId_param") && vars.exists("$param.ObjectId_param") && vars.get("$param.ObjectId_param")) { + var activityLinkSubselect = newSelect("ACTIVITYLINK.ACTIVITYLINKID") + .from("ACTIVITYLINK") + .where("ACTIVITYLINK.ACTIVITY_ID = ACTIVITY.ACTIVITYID") + .and("ACTIVITYLINK.OBJECT_TYPE", "$param.ObjectId_param"); + var rowId = vars.get("$param.RowId_param"); - var rowIds = [rowId]; - var rowIdCond = null; if (vars.get("$param.ObjectId_param") == "Person") { - var personIdSelect = newSelect("CONTACT.CONTACTID") - .from("CONTACT") - .where("CONTACT.CONTACTID", rowId) - .and("CONTACT.PERSON_ID", newSelect("CONTACT.PERSON_ID") - .from("CONTACT") - .where("CONTACT.CONTACTID", rowId)); - rowIds = personIdSelect.array(db.COLUMN); + //in the Person context, all activites linked to the person should be shown, so it is necessary to get all contactIds of that person + var allPersonRelatedContactIds = newSelect("personContacts.CONTACTID") + .from("CONTACT") + .join("CONTACT", "CONTACT.PERSON_ID = personContacts.PERSON_ID", "personContacts") + .where("CONTACT.CONTACTID", "$param.RowId_param") + .arrayColumn(); + + if (allPersonRelatedContactIds.length === 0) + condition.and("1=2"); + else + { + activityLinkSubselect.and("ACTIVITYLINK.OBJECT_ROWID", allPersonRelatedContactIds, SqlBuilder.IN()); + condition.and(null, activityLinkSubselect, SqlBuilder.EXISTS()); + } + } + else + { + activityLinkSubselect.and("ACTIVITYLINK.OBJECT_ROWID", "$param.RowId_param"); + condition.and(null, activityLinkSubselect, SqlBuilder.EXISTS()); } - - var activityLinkSubselect = newSelect("ACTIVITYLINK.ACTIVITY_ID") - .from("ACTIVITYLINK") - .where("ACTIVITYLINK.OBJECT_ROWID", rowIds, SqlBuilder.IN()) - .and("ACTIVITYLINK.OBJECT_TYPE", "$param.ObjectId_param"); - - // TODO: more performant way than IN. Maybe a join?? - cond.and("ACTIVITY.ACTIVITYID", activityLinkSubselect, SqlBuilder.IN()); } -if(vars.getString("$param.OnlyInnate_param") == "true") +if (vars.exists("$param.ActivityIDs_param") && vars.get("$param.ActivityIDs_param")) { - var ownContactId = EmployeeUtils.getCurrentContactId(); - if (ownContactId) - cond.and("ACTIVITY.RESPONSIBLE", ownContactId); - else - loadNothing = true; -} - -if (vars.exists("$param.ActivityIDs_param") && vars.get("$param.ActivityIDs_param")) { - var acticityIDs = JSON.parse(vars.get("$param.ActivityIDs_param")); - cond.and("ACTIVITY.ACTIVITYID",acticityIDs , SqlBuilder.IN()); + var acticityIds = JSON.parse(vars.get("$param.ActivityIDs_param")); + condition.and("ACTIVITY.ACTIVITYID", acticityIds, SqlBuilder.IN()); } -if (loadNothing) -{ - resCond = "1 = 2"; -} -else +if (vars.getString("$param.OnlyInnate_param") == "true") { - //TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 - var resCond = cond.toString(); + var ownContactId = EmployeeUtils.getCurrentContactId(); + if (ownContactId) + condition.and("ACTIVITY.RESPONSIBLE", ownContactId); + else + condition.clearWhere().and("1=2"); } -result.string(resCond); \ No newline at end of file +//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 +result.string(condition.toString()); \ No newline at end of file diff --git a/entity/Organisation_entity/Organisation_entity.aod b/entity/Organisation_entity/Organisation_entity.aod index 78adee42c1f..96b76098fde 100644 --- a/entity/Organisation_entity/Organisation_entity.aod +++ b/entity/Organisation_entity/Organisation_entity.aod @@ -51,7 +51,6 @@ <entityField> <name>CONTACTID</name> <title>CONTACTID</title> - <valueProcess>%aditoprj%/entity/Organisation_entity/entityfields/contactid/valueProcess.js</valueProcess> </entityField> <entityField> <name>STATUS</name> @@ -949,6 +948,7 @@ <entityProvider> <name>SelfDuplicatesProvider</name> <titlePlural>Duplicates</titlePlural> + <recordContainer>index</recordContainer> </entityProvider> <entityParameter> <name>OnlyShowContactIds_param</name> diff --git a/entity/Organisation_entity/entityfields/contactid/valueProcess.js b/entity/Organisation_entity/entityfields/contactid/valueProcess.js deleted file mode 100644 index 86ef789e064..00000000000 --- a/entity/Organisation_entity/entityfields/contactid/valueProcess.js +++ /dev/null @@ -1,7 +0,0 @@ -import("system.util"); -import("system.vars"); -import("system.result"); -import("system.neon"); - -if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW) - result.string(util.getNewUUID()); \ No newline at end of file diff --git a/entity/Organisation_entity/entityfields/selfduplicatesuncached/children/onlyshowcontactids_param/valueProcess.js b/entity/Organisation_entity/entityfields/selfduplicatesuncached/children/onlyshowcontactids_param/valueProcess.js index 45379fef45e..fdbb29bfe39 100644 --- a/entity/Organisation_entity/entityfields/selfduplicatesuncached/children/onlyshowcontactids_param/valueProcess.js +++ b/entity/Organisation_entity/entityfields/selfduplicatesuncached/children/onlyshowcontactids_param/valueProcess.js @@ -5,58 +5,47 @@ import("system.vars"); import("DuplicateScanner_lib"); import("system.result"); -let scannerName = "OrganisationDuplicates"; -let targetEntity = "Organisation_entity"; -let valuesToCheck = {}; +var scannerName = "OrganisationDuplicates"; +var targetEntity = "Organisation_entity"; +var valuesToCheck = {}; var entityFieldsToLoad = DuplicateScannerUtils.GetEntityFieldsFromConfig(scannerName, targetEntity); -if(entityFieldsToLoad == null || entityFieldsToLoad.length == 0) - result.string(JSON.stringify(["nodata"])); +var idsForEmptyResult = JSON.stringify(["nodata"]); + +if (entityFieldsToLoad == null || entityFieldsToLoad.length == 0) + result.string(idsForEmptyResult); else { //Read the values of all available entity fields and write the fieldname7value combination //as key/value pairs into an object. This is used to trigger the scan for duplicates - vars.get("$field.STANDARD_CITY"); - vars.get("$field.STANDARD_ZIP"); - vars.get("$field.STANDARD_ADDRESS"); + vars.get("$field.NAME") + vars.get("$field.STANDARD_CITY"); + vars.get("$field.STANDARD_ZIP"); + vars.get("$field.STANDARD_ADDRESS"); - let field = ''; - let fieldValue = ''; - for (fieldname in entityFieldsToLoad) - { - field = entityFieldsToLoad[fieldname]; - fieldValue = vars.get("$field." + field); + for (let fieldname in entityFieldsToLoad) + { + var field = entityFieldsToLoad[fieldname]; + var fieldValue = vars.get("$field." + field); - if(fieldValue != null && fieldValue != "") - { + if (fieldValue) valuesToCheck[field] = fieldValue; - } - } - - let scanResults = DuplicateScannerUtils.ScanForDuplicates(scannerName, targetEntity, - valuesToCheck, null); - - let duplicateIds = []; - - if(scanResults != undefined && scanResults != null) - { - //Run thru every duplicate result and read out the id. - //Do it now to have a simple array on all usages lateron. - for (let i = 0; i < scanResults.length; i++) - { - let duplicateContactId = scanResults[i][indexsearch.FIELD_ID]; - duplicateIds.push(duplicateContactId); - } - } - - /* - * To achieve that if there are no duplicates, no contacts should be shown and therefore returned by the - * recordcontainer, an invalid id gets returned. It then is used in the conditionProcess to load the duplicates. - * Because of its invalidity, no records are shown. - */ - if(duplicateIds.length == 0) - result.string(JSON.stringify(["nodata"])); - else - result.string(JSON.stringify(duplicateIds)); + } + + var scanResults = DuplicateScannerUtils.ScanForDuplicates(scannerName, targetEntity, valuesToCheck, null) || []; + var duplicateIds = scanResults.map(function (scanResult) + { + return scanResult[indexsearch.FIELD_ID]; + }); + + /* + * To achieve that if there are no duplicates, no contacts should be shown and therefore returned by the + * recordcontainer, an invalid id gets returned. It then is used in the conditionProcess to load the duplicates. + * Because of its invalidity, no records are shown. + */ + if (duplicateIds.length == 0) + result.string(idsForEmptyResult); + else + result.string(JSON.stringify(duplicateIds)); } \ No newline at end of file diff --git a/neonView/WorkflowDefinitionFilter_view/WorkflowDefinitionFilter_view.aod b/neonView/WorkflowDefinitionFilter_view/WorkflowDefinitionFilter_view.aod index 72d74e80652..595adfca1cc 100644 --- a/neonView/WorkflowDefinitionFilter_view/WorkflowDefinitionFilter_view.aod +++ b/neonView/WorkflowDefinitionFilter_view/WorkflowDefinitionFilter_view.aod @@ -39,6 +39,7 @@ <name>Tiles</name> <iconField>DIAGRAM</iconField> <titleField>NAME</titleField> + <subtitleField>KEY</subtitleField> <descriptionField>DESCRIPTION</descriptionField> <infoTopField>VERSION_TITLE</infoTopField> <favoriteActionGroup1>tableActions</favoriteActionGroup1> -- GitLab