diff --git a/process/ImporterMappingFunctions_lib/process.js b/process/ImporterMappingFunctions_lib/process.js index f267488b4e2ada4f55de7738ff4239cccd152c7d..47f80a6506c12ec6d36401548fef555824482957 100644 --- a/process/ImporterMappingFunctions_lib/process.js +++ b/process/ImporterMappingFunctions_lib/process.js @@ -350,16 +350,17 @@ function iKeywordAttribute(pObject) { * @param {Object} pObject req the mapping line * @return {Boolean} true * */ + function iComm(pObject) { if (! this.doIfCheck(pObject)) return true; - var address = this.InputRecord[pObject.Address]; - if(address == undefined) address = this.resolveSymbol(pObject, pObject.Address); var medium = this.InputRecord[pObject.Medium]; - if(medium == undefined) medium = this.resolveSymbol(pObject, pObject.Medium); var contact = this.InputRecord[pObject.ContactID]; - if(contact == undefined) contact = this.resolveSymbol(pObject, pObject.ContactID); var standard = "0"; + + if(address == undefined) address = this.resolveSymbol(pObject, pObject.address); + if(medium == undefined) medium = this.resolveSymbol(pObject, pObject.medium); + if(contact == undefined) contact = this.resolveSymbol(pObject, pObject.ContactID); if(pObject.Standard) standard = "1"; if(!address || !medium || !contact) return true; @@ -379,38 +380,61 @@ function iComm(pObject) { /* * Values of the mapping line: - * Reason opt -- the reason - * Medium req -- the medium id - * ContactID req -- the id of the entry in the contact table - * Type req -- yes or no to communication + * contact (required): The id of the entry in the contact table. + * restrictionMedium (required): The medium id. + * restrictionReason (optional): The reason. + * startDate (optional): The date when the restrictions begins. + * involvedEmployee (optional): The contact which is responsible for the restriction. * * @name iCommRestriction - * @param {Object} pObject req the mapping line + * @param {Object} pObject (required): Associative Array with required informations. * @return {Boolean} true * */ -function iCommRestriction(pObject) { + +function iCommRestriction(pObject) +{ if (!this.doIfCheck(pObject)) return true; - var reason = this.InputRecord[pObject.Reason]; - if(reason == undefined) reason = this.resolveSymbol(pObject, pObject.Reason); - var medium = this.InputRecord[pObject.Medium]; - if(medium == undefined) medium = this.resolveSymbol(pObject, pObject.Medium); - var contact = this.InputRecord[pObject.ContactID]; - if(contact == undefined) contact = this.resolveSymbol(pObject, pObject.ContactID); - var type = this.InputRecord[pObject.Type]; - if(type == undefined) type = this.resolveSymbol(pObject, pObject.Type); + var restrictionContact = this.InputRecord[pObject.restrictionContact]; + var restrictionReason = this.InputRecord[pObject.restrictionReason]; + var restrictionMedium = this.InputRecord[pObject.restrictionMedium]; + var restrictionStartDate = this.InputRecord[pObject.restrictionStartDate]; + var restrictionInvolvedEmployee = this.InputRecord[pObject.restrictionInvolvedEmployee]; + + if(restrictionContact == undefined) restrictionContact = this.resolveSymbol(pObject, pObject.restrictionContact); + if(restrictionReason == undefined) restrictionReason = this.resolveSymbol(pObject, pObject.restrictionReason); + if(restrictionReason == undefined || restrictionReason == null) restrictionReason = "NULL"; + if(restrictionMedium == undefined) restrictionMedium = this.resolveSymbol(pObject, pObject.restrictionMedium); + if(restrictionStartDate == undefined) restrictionStartDate = this.resolveSymbol(pObject.restrictionStartDate); + if(restrictionStartDate == undefined || restrictionStartDate == null) restrictionStartDate = "NULL"; + if(restrictionInvolvedEmployee == undefined) restrictionInvolvedEmployee = this.resolveSymbol(pObject.restrictionInvolvedEmployee); + if(restrictionInvolvedEmployee == undefined || restrictionInvolvedEmployee == null) restrictionInvolvedEmployee = "NULL"; + + if (!restrictionMedium || !restrictionContact) return true; + + var alias = this.Config.AliasTo; + var commRestriction = this.getTableCase("commrestriction"); + var commRestrictionId = this.getColumnCase("commrestriction.commrestrictionid"); + var contactId = this.getColumnCase("commrestriction.contact_id"); + var medium = this.getColumnCase("commrestriction.medium"); + var reason = this.getColumnCase("commrestriction.reason"); + var startDate = this.getColumnCase("commrestriction.startdate"); + var involvedEmployee = this.getColumnCase("commrestriction.employee_involved"); + + var id = newSelect(commRestrictionId, alias).from(commRestriction).where(contactId, restrictionContact).and(medium, restrictionMedium).cell(); + var columns = [commRestrictionId, medium, reason, contactId, startDate, involvedEmployee]; + var values = [id, restrictionMedium, restrictionReason, restrictionContact, restrictionStartDate, restrictionInvolvedEmployee]; + + if (id == "" || id == null) + { + values[0] = util.getNewUUID(); + this.insertData(commRestriction, columns, null, values, alias); + } + else + { + this.updateData(commRestriction, columns, null, values, alias); + } - if (!medium || !contact || !type) return true; - - var sql = "select top 1 " + this.getColumnCase("type") + " from " + this.getTableCase("commrestriction") - +" where " + this.getColumnCase("contact_id") + " = ? and " + this.getColumnCase("medium") + " = ? order by " - + this.getColumnCase("date_edit") + " desc, " + this.getColumnCase("date_new") + " desc"; - var id = db.cell([sql, [[contact, SQLTYPES.CHAR], [medium, SQLTYPES.CHAR]]], this.Config.AliasTo); - if (id == "" || id == null || id != type) { - if(reason == undefined || reason == null) reason = "NULL"; - var columns = [this.getColumnCase("commrestrictionid"), this.getColumnCase("medium"), this.getColumnCase("contact_id"), this.getColumnCase("type"), this.getColumnCase("reason")]; - this.insertData(this.getTableCase("commrestriction"), columns, null, [util.getNewUUID(), medium, contact, type, reason], this.Config.AliasTo); - } return true; } diff --git a/process/test_iCommRestriction/process.js b/process/test_iCommRestriction/process.js new file mode 100644 index 0000000000000000000000000000000000000000..3e3c5c98515c35629064e74489141098754033da --- /dev/null +++ b/process/test_iCommRestriction/process.js @@ -0,0 +1,37 @@ +import("system.db"); +import("Importer_lib"); +import("ImporterMappingFunctions_lib"); + +var importerMapping = { + AliasTo: "Data_alias", + DataFunction: function (pCurrentBatchNum) + { + if (pCurrentBatchNum > 1) + return null; + return [ + ["a8a5f214-8165-4627-bee2-bceb3578147e", "cfebe176-0a64-428d-b0ec-bba454d2ca3e", "Testing"], + ["c7ddf982-0e58-4152-b82b-8f5673b0b729", "cb07397b-a976-4960-b8e5-9edf189c5caf", "Testing"] + ]; + }, + ImportCommand: "insert+update", + Mapping: [ + [ iCommRestriction, + { + contact: 0, + restrictionMedium: 1, + restrictionReason: 2 + } + ] + ] +}; + +var imp = new Importer(importerMapping); +imp.Log = "CONSOLE"; +imp.ImportUser = "IMPORTER_TESTER"; +imp.Preview = false; +imp.Debug = true; +imp.LogLevel = imp.LogLevels.Info; + +// MariaDB requires lower table cases +if (db.getDatabaseType("Data_alias") == db.DBTYPE_MARIADB10) imp.TableCase = imp.Cases.Lower; +imp.process(); \ No newline at end of file diff --git a/process/test_iCommRestriction/test_iCommRestriction.aod b/process/test_iCommRestriction/test_iCommRestriction.aod new file mode 100644 index 0000000000000000000000000000000000000000..cc954a462d091f6b3efef2b7797b92a18ae0b2f8 --- /dev/null +++ b/process/test_iCommRestriction/test_iCommRestriction.aod @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<process xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.2.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/process/1.2.1"> + <name>test_iCommRestriction</name> + <majorModelMode>DISTRIBUTED</majorModelMode> + <process>%aditoprj%/process/test_iCommRestriction/process.js</process> + <variants> + <element>EXECUTABLE</element> + </variants> +</process>