Skip to content
Snippets Groups Projects
Commit 0961cce1 authored by S.Listl's avatar S.Listl
Browse files

Activty conditionProcess optimized

parent 7a44b81f
No related branches found
No related tags found
No related merge requests found
import("system.logging");
import("Employee_lib"); import("Employee_lib");
import("system.vars"); import("system.vars");
import("system.db"); import("system.db");
import("system.result"); import("system.result");
import("Sql_lib"); import("Sql_lib");
var loadNothing = false; var condition = newWhere();
var cond = newWhere();
if (vars.exists("$param.RowId_param") && vars.get("$param.RowId_param") && vars.exists("$param.ObjectId_param") && vars.get("$param.ObjectId_param")) 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 rowId = vars.get("$param.RowId_param");
var rowIds = [rowId];
var rowIdCond = null;
if (vars.get("$param.ObjectId_param") == "Person") if (vars.get("$param.ObjectId_param") == "Person")
{ {
var personIdSelect = newSelect("CONTACT.CONTACTID") //in the Person context, all activites linked to the person should be shown, so it is necessary to get all contactIds of that person
.from("CONTACT") var allPersonRelatedContactIds = newSelect("personContacts.CONTACTID")
.where("CONTACT.CONTACTID", rowId) .from("CONTACT")
.and("CONTACT.PERSON_ID", newSelect("CONTACT.PERSON_ID") .join("CONTACT", "CONTACT.PERSON_ID = personContacts.PERSON_ID", "personContacts")
.from("CONTACT") .where("CONTACT.CONTACTID", "$param.RowId_param")
.where("CONTACT.CONTACTID", rowId)); .arrayColumn();
rowIds = personIdSelect.array(db.COLUMN);
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(); var acticityIds = JSON.parse(vars.get("$param.ActivityIDs_param"));
if (ownContactId) condition.and("ACTIVITY.ACTIVITYID", acticityIds, SqlBuilder.IN());
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());
} }
if (loadNothing) if (vars.getString("$param.OnlyInnate_param") == "true")
{
resCond = "1 = 2";
}
else
{ {
//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 var ownContactId = EmployeeUtils.getCurrentContactId();
var resCond = cond.toString(); if (ownContactId)
condition.and("ACTIVITY.RESPONSIBLE", ownContactId);
else
condition.clearWhere().and("1=2");
} }
result.string(resCond); //TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
\ No newline at end of file result.string(condition.toString());
\ No newline at end of file
...@@ -51,7 +51,6 @@ ...@@ -51,7 +51,6 @@
<entityField> <entityField>
<name>CONTACTID</name> <name>CONTACTID</name>
<title>CONTACTID</title> <title>CONTACTID</title>
<valueProcess>%aditoprj%/entity/Organisation_entity/entityfields/contactid/valueProcess.js</valueProcess>
</entityField> </entityField>
<entityField> <entityField>
<name>STATUS</name> <name>STATUS</name>
...@@ -949,6 +948,7 @@ ...@@ -949,6 +948,7 @@
<entityProvider> <entityProvider>
<name>SelfDuplicatesProvider</name> <name>SelfDuplicatesProvider</name>
<titlePlural>Duplicates</titlePlural> <titlePlural>Duplicates</titlePlural>
<recordContainer>index</recordContainer>
</entityProvider> </entityProvider>
<entityParameter> <entityParameter>
<name>OnlyShowContactIds_param</name> <name>OnlyShowContactIds_param</name>
......
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
...@@ -5,58 +5,47 @@ import("system.vars"); ...@@ -5,58 +5,47 @@ import("system.vars");
import("DuplicateScanner_lib"); import("DuplicateScanner_lib");
import("system.result"); import("system.result");
let scannerName = "OrganisationDuplicates"; var scannerName = "OrganisationDuplicates";
let targetEntity = "Organisation_entity"; var targetEntity = "Organisation_entity";
let valuesToCheck = {}; var valuesToCheck = {};
var entityFieldsToLoad = DuplicateScannerUtils.GetEntityFieldsFromConfig(scannerName, targetEntity); var entityFieldsToLoad = DuplicateScannerUtils.GetEntityFieldsFromConfig(scannerName, targetEntity);
if(entityFieldsToLoad == null || entityFieldsToLoad.length == 0) var idsForEmptyResult = JSON.stringify(["nodata"]);
result.string(JSON.stringify(["nodata"]));
if (entityFieldsToLoad == null || entityFieldsToLoad.length == 0)
result.string(idsForEmptyResult);
else else
{ {
//Read the values of all available entity fields and write the fieldname7value combination //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 //as key/value pairs into an object. This is used to trigger the scan for duplicates
vars.get("$field.STANDARD_CITY"); vars.get("$field.NAME")
vars.get("$field.STANDARD_ZIP"); vars.get("$field.STANDARD_CITY");
vars.get("$field.STANDARD_ADDRESS"); vars.get("$field.STANDARD_ZIP");
vars.get("$field.STANDARD_ADDRESS");
let field = ''; for (let fieldname in entityFieldsToLoad)
let fieldValue = ''; {
for (fieldname in entityFieldsToLoad) var field = entityFieldsToLoad[fieldname];
{ var fieldValue = vars.get("$field." + field);
field = entityFieldsToLoad[fieldname];
fieldValue = vars.get("$field." + field);
if(fieldValue != null && fieldValue != "") if (fieldValue)
{
valuesToCheck[field] = fieldValue; valuesToCheck[field] = fieldValue;
} }
}
var scanResults = DuplicateScannerUtils.ScanForDuplicates(scannerName, targetEntity, valuesToCheck, null) || [];
let scanResults = DuplicateScannerUtils.ScanForDuplicates(scannerName, targetEntity, var duplicateIds = scanResults.map(function (scanResult)
valuesToCheck, null); {
return scanResult[indexsearch.FIELD_ID];
let duplicateIds = []; });
if(scanResults != undefined && scanResults != null) /*
{ * To achieve that if there are no duplicates, no contacts should be shown and therefore returned by the
//Run thru every duplicate result and read out the id. * recordcontainer, an invalid id gets returned. It then is used in the conditionProcess to load the duplicates.
//Do it now to have a simple array on all usages lateron. * Because of its invalidity, no records are shown.
for (let i = 0; i < scanResults.length; i++) */
{ if (duplicateIds.length == 0)
let duplicateContactId = scanResults[i][indexsearch.FIELD_ID]; result.string(idsForEmptyResult);
duplicateIds.push(duplicateContactId); else
} result.string(JSON.stringify(duplicateIds));
}
/*
* 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));
} }
\ No newline at end of file
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
<name>Tiles</name> <name>Tiles</name>
<iconField>DIAGRAM</iconField> <iconField>DIAGRAM</iconField>
<titleField>NAME</titleField> <titleField>NAME</titleField>
<subtitleField>KEY</subtitleField>
<descriptionField>DESCRIPTION</descriptionField> <descriptionField>DESCRIPTION</descriptionField>
<infoTopField>VERSION_TITLE</infoTopField> <infoTopField>VERSION_TITLE</infoTopField>
<favoriteActionGroup1>tableActions</favoriteActionGroup1> <favoriteActionGroup1>tableActions</favoriteActionGroup1>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment