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

Deletion of AttributeRelations in onDBDelete processes

parent 4e9759ae
No related branches found
No related tags found
No related merge requests found
Showing
with 193 additions and 26 deletions
import("Context_lib");
import("system.vars");
import("Sql_lib");
import("Attribute_lib");
newWhere("ACTIVITYLINK.ACTIVITY_ID", "$field.ACTIVITYID").deleteData();
\ No newline at end of file
newWhere("ACTIVITYLINK.ACTIVITY_ID", "$field.ACTIVITYID").deleteData();
new AttributeRelationQuery(vars.get("$field.ACTIVITYID"), null, ContextUtils.getCurrentContextId())
.deleteAllAttributes();
\ No newline at end of file
import("Context_lib");
import("system.db");
import("system.vars");
import("Sql_lib");
import("Attribute_lib");
var currentId = vars.getString("$field.CAMPAIGNID");
......@@ -19,4 +21,7 @@ if (currentId)
});
db.deletes(toDelete);
}
\ No newline at end of file
}
new AttributeRelationQuery(currentId, null, ContextUtils.getCurrentContextId())
.deleteAllAttributes();
\ No newline at end of file
......@@ -384,6 +384,7 @@
<fromClauseProcess>%aditoprj%/entity/Contract_entity/recordcontainers/db/fromClauseProcess.js</fromClauseProcess>
<conditionProcess>%aditoprj%/entity/Contract_entity/recordcontainers/db/conditionProcess.js</conditionProcess>
<orderClauseProcess>%aditoprj%/entity/Contract_entity/recordcontainers/db/orderClauseProcess.js</orderClauseProcess>
<onDBDelete>%aditoprj%/entity/Contract_entity/recordcontainers/db/onDBDelete.js</onDBDelete>
<linkInformation>
<linkInformation>
<name>78925203-f1c5-4e7e-9424-1a23500c655d</name>
......
import("system.vars");
import("Context_lib");
import("Attribute_lib");
new AttributeRelationQuery(vars.get("$field.CONTRACTID"), null, ContextUtils.getCurrentContextId())
.deleteAllAttributes();
\ No newline at end of file
import("Context_lib");
import("Sql_lib");
import("system.vars");
import("system.db");
import("Attribute_lib");
var binaryId = newSelect("ID", SqlUtils.getBinariesAlias())
.from("ASYS_BINARIES")
.where("ASYS_BINARIES.ROW_ID", "$field.DOCUMENTTEMPLATEID")
.cell();
if (binaryId)
db.deleteBinary(binaryId, SqlUtils.getBinariesAlias());
\ No newline at end of file
db.deleteBinary(binaryId, SqlUtils.getBinariesAlias());
new AttributeRelationQuery(vars.get("$field.DOCUMENTTEMPLATEID"), null, ContextUtils.getCurrentContextId())
.deleteAllAttributes();
\ No newline at end of file
......@@ -363,6 +363,7 @@
<name>jdito</name>
<jDitoRecordAlias>Data_alias</jDitoRecordAlias>
<isFilterable v="true" />
<isRequireContainerFiltering v="true" />
<isSortable v="true" />
<contentProcess>%aditoprj%/entity/Employee_entity/recordcontainers/jdito/contentProcess.js</contentProcess>
<onInsert>%aditoprj%/entity/Employee_entity/recordcontainers/jdito/onInsert.js</onInsert>
......
import("system.logging");
import("Sql_lib");
import("system.db");
import("Attribute_lib");
......@@ -7,7 +8,7 @@ import("system.tools");
import("Util_lib");
import("Contact_lib");
import("JditoFilter_lib");
import("Employee_lib");
import("Employee_lib");attrib
var users;
if (vars.exists("$local.idvalues") && vars.get("$local.idvalues"))
......@@ -43,7 +44,7 @@ users = users.map(function (user)
var filter = vars.get("$local.filter");
//TODO: this is a workaround that filters the records manually, it should be possible to filter the users with a tools.* method
var filterFields = ["UID", "TITLE", "ISACTIVE", "FIRSTNAME", "LASTNAME", "EMAIL_ADDRESS", "", "DESCRIPTION", "CONTACT_ID", "DEPARTMENT", "", "", "ROLE_FILTER"];
var filterFields = ["UID", "TITLE", "ISACTIVE", "FIRSTNAME", "LASTNAME", "EMAIL_ADDRESS", "", "DESCRIPTION", "CONTACT_ID", "DEPARTMENT", "", "", "ROLE_FILTER", "$$$LOOKUPFIELD$$$"];
var filterFns = {
"ROLE_FILTER" : function (pRecordVal, pFilterVal, pOperator)
{
......@@ -62,8 +63,20 @@ var filterFns = {
default:
return false;
}
},
"$$$LOOKUPFIELD$$$" : function (pRecordValue, pFilterValue, pOperator, pRow)
{
if (pOperator == "CONTAINS")
{
return pRow.some(function (fieldValue)
{
return (new RegExp(pFilterValue, "i")).test(fieldValue);
});
}
return false;
}
};
logging.log(JSON.stringify(filter, null, "\t"))
users = JditoFilterUtils.filterRecords(filterFields, users, filter.filter, filterFns);
users.forEach(function (user) {user[12] = "";}); //clean up the ROLE_FILTER field, we don't need it after filtering
......
import("Context_lib");
import("Attribute_lib");
import("system.neon");
import("system.vars");
import("system.tools");
......@@ -5,4 +7,9 @@ import("Employee_lib");
//the current user should not delete himself
if (EmployeeUtils.getCurrentUserName() != vars.get("$field.TITLE") && !EmployeeUtils.hasRelations(vars.get("$field.CONTACT_ID")))
tools.deleteUser(vars.get("$field.TITLE"));
\ No newline at end of file
{
tools.deleteUser(vars.get("$field.TITLE"));
AttributeRelationQuery(EmployeeUtils.sliceUserId(vars.get("$field.UID")), null, ContextUtils.getCurrentContextId())
.deleteAllAttributes();
}
\ No newline at end of file
import("Context_lib");
import("Sql_lib");
import("system.vars");
import("system.db");
import("Attribute_lib");
var leadImportId = vars.getString("$field.LEADIMPORTID");
......@@ -22,14 +24,16 @@ newSelect("LEADLOGID")
if(leadImportId != "")//delete the connected importfields
{
db.deleteData("IMPORTFIELD", newWhere("IMPORTFIELD.LEADIMPORT_ID", leadImportId).build());
db.deleteData("LEADTEMP", newWhere("LEADTEMP.ROW_ID", leadImportId).build());
db.deleteData("LEAD", newWhere("LEAD.LEADIMPORT_ID", leadImportId).build());
db.deleteData("LEADLOG", newWhere("LEADLOG.LEADIMPORT_ID", leadImportId).build());
newWhere("IMPORTFIELD.LEADIMPORT_ID", leadImportId).deleteData();
newWhere("LEADTEMP.ROW_ID", leadImportId).deleteData();
newWhere("LEAD.LEADIMPORT_ID", leadImportId).deleteData();
newWhere("LEADLOG.LEADIMPORT_ID", leadImportId).deleteData();
}
binMetadata.forEach(function(pMeta)
{ //delete the connected binData
db.deleteBinary(pMeta.id, SqlUtils.getBinariesAlias());
});
\ No newline at end of file
new AttributeRelationQuery(leadImportId, null, ContextUtils.getCurrentContextId())
.deleteAllAttributes();
\ No newline at end of file
import("Context_lib");
import("Workflow_lib");
import("Sql_lib");
import("system.vars");
import("Attribute_lib");
newWhere("OFFERITEM.OFFER_ID", "$field.OFFERID")
.deleteData();
new AttributeRelationQuery(vars.get("$field.OFFERID"), null, ContextUtils.getCurrentContextId())
.deleteAllAttributes();
WorkflowStarter.deleted({sum : Number(vars.get("$field.TotalGross")), status : vars.get("$field.STATUS")});
WorkflowSignalSender.deleted();
\ No newline at end of file
import("Context_lib");
import("system.vars");
import("Sql_lib");
import("Attribute_lib");
newWhere("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID").deleteData();
\ No newline at end of file
newWhere("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID").deleteData();
new AttributeRelationQuery(vars.get("$field.SALESORDERID"), null, ContextUtils.getCurrentContextId())
.deleteAllAttributes();
\ No newline at end of file
import("Context_lib");
import("Workflow_lib");
import("system.vars");
import("DuplicateScanner_lib");
import("Attribute_lib");
// TODO: enable when duplicate-module is finalized
let contactId = vars.get("$field.CONTACTID");
DuplicateScannerUtils.DeleteCachedDuplicate(contactId);
new AttributeRelationQuery(contactId, null, ContextUtils.getCurrentContextId())
.deleteAllAttributes();
//WorkflowStarter.deleted();
//WorkflowSignalSender.deleted();
\ No newline at end of file
import("Context_lib");
import("Attribute_lib");
import("Workflow_lib");
import("system.vars");
import("DuplicateScanner_lib");
......@@ -5,5 +7,8 @@ import("DuplicateScanner_lib");
let contactId = vars.get("$field.CONTACTID");
DuplicateScannerUtils.DeleteCachedDuplicate(contactId);
new AttributeRelationQuery(contactId, null, ContextUtils.getCurrentContextId())
.deleteAllAttributes();
//WorkflowStarter.deleted();
//WorkflowSignalSender.deleted();
\ No newline at end of file
import("Context_lib");
import("Sql_lib");
import("Attribute_lib");
newWhereIfSet("PROD2PROD.DEST_ID", "$field.PRODUCTID")
.deleteData();
......@@ -10,4 +12,7 @@ newWhereIfSet("PRODUCTPRICE.PRODUCT_ID", "$field.PRODUCTID")
.deleteData();
newWhereIfSet("STOCK.PRODUCT_ID", "$field.PRODUCTID")
.deleteData();
\ No newline at end of file
.deleteData();
new AttributeRelationQuery(productId, null, ContextUtils.getCurrentContextId())
.deleteAllAttributes();
\ No newline at end of file
......@@ -3,6 +3,7 @@ import("Context_lib");
import("system.db");
import("system.vars");
import("Sql_lib");
import("Attribute_lib");
var currentId = vars.getString("$field.SALESPROJECTID");
......@@ -42,4 +43,7 @@ if (currentId)
// TODO: auch Dokumente, Aktivitäten, Aufgaben, Zeiterfassungen löschen?
}
new AttributeRelationQuery(currentId, null, ContextUtils.getCurrentContextId())
.deleteAllAttributes();
WorkflowStarter.deleted();
\ No newline at end of file
......@@ -405,6 +405,7 @@
<conditionProcess>%aditoprj%/entity/SupportTicket_entity/recordcontainers/db/conditionProcess.js</conditionProcess>
<orderClauseProcess>%aditoprj%/entity/SupportTicket_entity/recordcontainers/db/orderClauseProcess.js</orderClauseProcess>
<onDBInsert>%aditoprj%/entity/SupportTicket_entity/recordcontainers/db/onDBInsert.js</onDBInsert>
<onDBDelete>%aditoprj%/entity/SupportTicket_entity/recordcontainers/db/onDBDelete.js</onDBDelete>
<linkInformation>
<linkInformation>
<name>512c662b-33f6-4491-bd24-a8b862f2de84</name>
......
import("Context_lib");
import("system.vars");
import("Attribute_lib");
import("Sql_lib");
newWhereIfSet("TASKLINK.TASK_ID", "$field.TASK_TASKID").deleteData();
\ No newline at end of file
newWhereIfSet("TASKLINK.TASK_ID", "$field.TASK_TASKID").deleteData();
new AttributeRelationQuery(vars.get("$field.TICKETID"), null, ContextUtils.getCurrentContextId())
.deleteAllAttributes();
\ No newline at end of file
......@@ -1301,7 +1301,7 @@ AttributeRelationQuery.prototype.includeDisplayValue = function ()
/**
* Executes the query and returns the result, depending on the properties of the AttributeRelationQuery object.
*
* @return {Object[]} Array of objects. By default, the objects contain the properties {attributeId, value, attributeRelationId, attributeName, attributeType}.
* @return {AttributeRelation[]} Array of objects. By default, the objects contain the properties {attributeId, value, attributeRelationId, attributeName, attributeType}.
* If includeDisplayValue is true, the object also contains the property 'displayValue' and if includeFullAttributeName is true, there is also the property
* 'fullAttributeName'.
*/
......@@ -1313,7 +1313,9 @@ AttributeRelationQuery.prototype.getAttributes = function ()
"AB_ATTRIBUTE.ATTRIBUTE_NAME",
"COMBOVAL.ATTRIBUTE_NAME",
"AB_ATTRIBUTE.AB_ATTRIBUTEID",
"AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID"
"AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID",
"AB_ATTRIBUTERELATION.OBJECT_ROWID",
"AB_ATTRIBUTERELATION.OBJECT_TYPE"
];
var valueFields = AttributeTypeUtil.getAllDatabaseFields();
......@@ -1328,13 +1330,7 @@ AttributeRelationQuery.prototype.getAttributes = function ()
var mappingFn = function (row)
{
var attrObj = {
attributeId : row[4],
value : row[AttributeTypeUtil.getTypeColumnIndex(row[0]) + defaultFields.length],
attributeRelationId : row[5],
attributeName : row[2],
attributeType : row[0]
};
var attrObj = new AttributeRelation(row[5], row[4], row[AttributeTypeUtil.getTypeColumnIndex(row[0]) + defaultFields.length], row[2], row[0], row[6], row[7]);
if (this._includeDisplayValue)
{
......@@ -1355,7 +1351,7 @@ AttributeRelationQuery.prototype.getAttributes = function ()
}
/**
* @return {Object}
* @return {AttributeRelation}
*/
AttributeRelationQuery.prototype.getSingleAttribute = function ()
{
......@@ -1442,13 +1438,98 @@ AttributeRelationQuery.prototype.insertAttribute = function (pValue, pOmitValida
/**
* deletes all attribute relations with the given rowId and objectType
*
* @return {Number} count of deleted rows
*/
AttributeRelationQuery.prototype.deleteAllAttributes = function ()
{
if (!this._rowId)
throw new Error("AttributeRelationQuery: Row id is required for delete");
newWhere("AB_ATTRIBUTERELATION.OBJECT_ROWID", this._rowId)
.andIfSet("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", this._objectType)
return newWhere("AB_ATTRIBUTERELATION.OBJECT_ROWID", this._rowId)
.andIfSet("AB_ATTRIBUTERELATION.OBJECT_TYPE", this._objectType)
.deleteData();
}
/**
* Object representing one attribute relation in the database. Don't use this constructor in you own code!
* Instances of this should only be created by functions in this library.
*
* @param {String} pAttributeRelationId attribute relation id
* @param {String} pAttributeId attribute id
* @param {String} pValue value of the attribute
* @param {String} pAttributeName name of the attribute
* @param {String} pAttributeType type of the attribute
* @param {String} pObjectRowId rowId of the linked object
* @param {String} pObjectType context of the linked object
*/
function AttributeRelation (pAttributeRelationId, pAttributeId, pValue, pAttributeName, pAttributeType, pObjectRowId, pObjectType)
{
if (!pAttributeRelationId)
throw new Error("AttributeRelation: pAttributeRelationId must be provided");
this.attributeRelationId = pAttributeRelationId;
this.attributeId = pAttributeId;
this.value = pValue;
this.attributeName = pAttributeName;
this.attributeType = pAttributeType;
this.objectRowId = pObjectRowId;
this.objectType = pObjectType;
this.displayValue = undefined;
this.fullAttributeName = undefined;
}
/**
* updates the value of the attribute in the database
*
* @param {String} pValue the new value of the attribute relation
* @return {Boolean} currently the function always returns true (if some kind of validation is implemented in the future,
* it will return false if the validation fails)
*/
AttributeRelation.prototype.updateAttribute = function (pValue)
{
if (pValue == undefined || pValue == "")
throw new Error("AttributeRelation: no value provided for update");
var attrData = {
"DATE_EDIT" : vars.get("$sys.date"),
"USER_EDIT" : vars.get("$sys.user")
};
var valueField = AttributeTypeUtil.getDatabaseField(this.attributeType);
if (valueField)
attrData[valueField] = pValue;
newWhere("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", this.attributeRelationId)
.updateFields(attrData);
return true;
}
/**
* deletes the attribute relation from the database
*
* @param {Boolean} [pOmitValidation=false] if set to true, the function won't check if the min count prohibits the deletion
* @retun {Boolean} true if it was deleted and false if the min count doesn't allow the deletion
*/
AttributeRelation.prototype.deleteAttribute = function (pOmitValidation)
{
if (!pOmitValidation)
{
var minCount = newSelect("MIN_COUNT")
.from("AB_ATTRIBUTEUSAGE")
.where("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", this.attributeId)
.and("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", this.objectType)
.cell();
if (minCount && minCount != 0)
{
let timesUsed = new AttributeRelationQuery(this.objectRowId, this.attributeId, this.objectType).getAttributeCount();
if (timesUsed <= minCount)
return false;
}
}
newWhere("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", this.attributeRelationId)
.deleteData();
return true;
}
\ No newline at end of file
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