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("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
......@@ -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>
......
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");
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
......@@ -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>
......
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