From 572996a00e3e43f3f8c61879356e02ac68d4645b Mon Sep 17 00:00:00 2001 From: Daniel Tran <d.tran@adito.de> Date: Tue, 11 Feb 2020 08:01:33 +0100 Subject: [PATCH] Zwischencommit --- .../ImporterMappingFunctions_lib/process.js | 171 ++++++++++-------- 1 file changed, 95 insertions(+), 76 deletions(-) diff --git a/process/ImporterMappingFunctions_lib/process.js b/process/ImporterMappingFunctions_lib/process.js index a7c2ddaf30f..71eae92e708 100644 --- a/process/ImporterMappingFunctions_lib/process.js +++ b/process/ImporterMappingFunctions_lib/process.js @@ -41,13 +41,13 @@ function iKeyword(pObject) { if(!keyword || !container) return true; var sql = "select " + this.getColumnCase("keyid") + " from " + this.getTableCase("ab_keyword_entry") + " where " - + this.getColumnCase("container") + " = ? and " + this.getColumnCase("title") + " = ?"; + + this.getColumnCase("container") + " = ? and " + this.getColumnCase("title") + " = ?"; var id = db.cell([sql, [[container, SQLTYPES.VARCHAR], [keyword, SQLTYPES.VARCHAR]]], this.Config.AliasTo); if(id == "" || id == null) { id = util.getNewUUID(); var columns = [this.getColumnCase("ab_keyword_entryid"), this.getColumnCase("keyid"), this.getColumnCase("container"), - this.getColumnCase("title"), this.getColumnCase("sorting"), this.getColumnCase("isactive"), this.getColumnCase("isessential")]; + this.getColumnCase("title"), this.getColumnCase("sorting"), this.getColumnCase("isactive"), this.getColumnCase("isessential")]; sql = "select max(coalesce(sorting, 0))+1 from ab_keyword_entry where container = ?"; var sort = db.cell([sql, [[container, SQLTYPES.VARCHAR]]], this.Config.AliasTo); if(sort == "") sort = "0"; @@ -91,7 +91,7 @@ function iAttribute(pObject) { var valueColumn = ""; var attributes = attribute.split("."); var columns = [this.getColumnCase("ab_attributeid"), this.getColumnCase("attribute_parent_id"), this.getColumnCase("attribute_name"), - this.getColumnCase("attribute_type"), this.getColumnCase("attribute_level"), this.getColumnCase("attribute_active")]; + this.getColumnCase("attribute_type"), this.getColumnCase("attribute_level"), this.getColumnCase("attribute_active")]; var type = $AttributeTypes.GROUP.toString(); switch (atype) { case $AttributeTypes.TEXT.toString(): @@ -129,12 +129,12 @@ function iAttribute(pObject) { if (i == 0) { var parent = "NULL"; var sql = "select " + this.getColumnCase("ab_attributeid") + " from " + this.getTableCase("ab_attribute") + " where " - + this.getColumnCase("attribute_name") + " = ? and " + this.getColumnCase("attribute_level") + " = 0"; + + this.getColumnCase("attribute_name") + " = ? and " + this.getColumnCase("attribute_level") + " = 0"; id = db.cell([sql, [[attributes[i], SQLTYPES.VARCHAR]]], this.Config.AliasTo); } else { parent = pathToFollow["id"]; sql = "select " + this.getColumnCase("ab_attributeid") + " from " + this.getTableCase("ab_attribute") + " where " - + this.getColumnCase("attribute_name") + " = ? and " + this.getColumnCase("attribute_parent_id") + " = ?"; + + this.getColumnCase("attribute_name") + " = ? and " + this.getColumnCase("attribute_parent_id") + " = ?"; id = db.cell([sql, [[attributes[i], SQLTYPES.VARCHAR], [parent, SQLTYPES.CHAR]]], this.Config.AliasTo); } if (id == "" || id == null) { @@ -152,7 +152,7 @@ function iAttribute(pObject) { if (otype) { var aid = id; sql = "select " + this.getColumnCase("ab_attributeusageid") + " from " + this.getTableCase("ab_attributeusage") + " where " - + this.getColumnCase("ab_attribute_id") + " = ? and " + this.getColumnCase("object_type") + " = ?"; + + this.getColumnCase("ab_attribute_id") + " = ? and " + this.getColumnCase("object_type") + " = ?"; id = db.cell([sql, [[aid, SQLTYPES.CHAR], [otype, SQLTYPES.VARCHAR]]], this.Config.AliasTo); if (id == "" || id == null) { columns = [this.getColumnCase("ab_attributeusageid"), this.getColumnCase("ab_attribute_id"), this.getColumnCase("object_type")]; @@ -161,12 +161,12 @@ function iAttribute(pObject) { if (value && oid) { sql = "select " + this.getColumnCase("ab_attributerelationid") + " from " + this.getTableCase("ab_attributerelation") + " where " - + this.getColumnCase("ab_attribute_id") + " = ? and " + this.getColumnCase("object_rowid") + " = ? and " - + this.getColumnCase("object_type") + " = ?"; + + this.getColumnCase("ab_attribute_id") + " = ? and " + this.getColumnCase("object_rowid") + " = ? and " + + this.getColumnCase("object_type") + " = ?"; id = db.cell([sql, [[aid, SQLTYPES.CHAR], [oid, SQLTYPES.CHAR], [otype, SQLTYPES.VARCHAR]]], this.Config.AliasTo); if (id == "" || id == null) { columns = [this.getColumnCase("ab_attributerelationid"), this.getColumnCase("ab_attribute_id"), this.getColumnCase("object_type"), - this.getColumnCase("object_rowid"), valueColumn]; + this.getColumnCase("object_rowid"), valueColumn]; this.insertData(this.getTableCase("ab_attributerelation"), columns, null, [util.getNewUUID(), aid, otype, oid, value], this.Config.AliasTo); } else if (this.Config.ImportCommand.indexOf("update") != -1) { cond = this.getColumnCase("ab_attributerelationid") + " = '" + id + "'"; @@ -231,9 +231,9 @@ function iKeywordAttribute(pObject) { } var sql = "select " + this.getColumnCase("ab_keyword_attributeid") - + " from " + this.getTableCase("ab_keyword_attribute") - + " where " + this.getColumnCase("name") - + " = ? and " + this.getColumnCase("container") + " = ?"; + + " from " + this.getTableCase("ab_keyword_attribute") + + " where " + this.getColumnCase("name") + + " = ? and " + this.getColumnCase("container") + " = ?"; var attributeId = db.cell([sql, [[keywordAttribute, SQLTYPES.VARCHAR], [keywordContainer, SQLTYPES.VARCHAR]]], this.Config.AliasTo); @@ -241,12 +241,12 @@ function iKeywordAttribute(pObject) { if (attributeId == "" || attributeId == null) { attributeId = util.getNewUUID(); var columns = [this.getColumnCase("ab_keyword_attributeid"), - this.getColumnCase("name"), - this.getColumnCase("container"), - this.getColumnCase("kind")]; + this.getColumnCase("name"), + this.getColumnCase("container"), + this.getColumnCase("kind")]; this.insertData(this.getTableCase("ab_keyword_attribute"), columns, null, - [attributeId, keywordAttribute, keywordContainer, keywordAttributeType], this.Config.AliasTo); + [attributeId, keywordAttribute, keywordContainer, keywordAttributeType], this.Config.AliasTo); } // Creates the entry in AB_KEYWORD_ENTRY and AB_KEYWORD_ATTRIBUTERELATION, case if it not exists. @@ -269,8 +269,8 @@ function iKeywordAttribute(pObject) { if (keywordId == "" || keywordId == null) { columns = [this.getColumnCase("ab_keyword_entryid"), this.getColumnCase("keyid"), this.getColumnCase("container"), - this.getColumnCase("title"), this.getColumnCase("sorting"), this.getColumnCase("isactive"), - this.getColumnCase("isessential")]; + this.getColumnCase("title"), this.getColumnCase("sorting"), this.getColumnCase("isactive"), + this.getColumnCase("isessential")]; sql = "select max(coalesce(sorting, 0))+1 from ab_keyword_entry where container = ?"; @@ -281,7 +281,7 @@ function iKeywordAttribute(pObject) { keywordId = util.getNewUUID(); this.insertData(this.getTableCase("ab_keyword_entry"), columns, null, - [keywordId, util.getNewUUID(), keywordContainer, keyword, sort, "1", "0"], this.Config.AliasTo); + [keywordId, util.getNewUUID(), keywordContainer, keyword, sort, "1", "0"], this.Config.AliasTo); } } @@ -295,13 +295,13 @@ function iKeywordAttribute(pObject) { if (id == "" || id == null) { columns = [this.getColumnCase("ab_keyword_attributerelationid"), - this.getColumnCase("ab_keyword_entry_id"), - this.getColumnCase("ab_keyword_attribute_id"), - valueColumn]; + this.getColumnCase("ab_keyword_entry_id"), + this.getColumnCase("ab_keyword_attribute_id"), + valueColumn]; id = util.getNewUUID(); this.insertData(this.getTableCase("ab_keyword_attributerelation"), columns, null, - [id, keywordId, attributeId, keywordAttrRelValue], this.Config.AliasTo); + [id, keywordId, attributeId, keywordAttrRelValue], this.Config.AliasTo); } else { if (this.Config.ImportCommand.indexOf("update") != -1) { @@ -324,28 +324,29 @@ 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; var sql = "select " + this.getColumnCase("communicationid") + " from " + this.getTableCase("communication") - +" where " + this.getColumnCase("contact_id") + " = ? and " + this.getColumnCase("medium_id") + " = ? and " - + this.getColumnCase("isstandard") + " = ? and " + this.getColumnCase("addr") + " = ?" + +" where " + this.getColumnCase("contact_id") + " = ? and " + this.getColumnCase("medium_id") + " = ? and " + + this.getColumnCase("isstandard") + " = ? and " + this.getColumnCase("addr") + " = ?" var id = db.cell([sql, [[contact, SQLTYPES.CHAR], [medium, SQLTYPES.CHAR], //TODO: define types dynamically and not hardcoded - [standard, SQLTYPES.SMALLINT], [address, SQLTYPES.VARCHAR]]], this.Config.AliasTo); + [standard, SQLTYPES.SMALLINT], [address, SQLTYPES.VARCHAR]]], this.Config.AliasTo); if (id == "" || id == null) { var columns = [this.getColumnCase("communicationid"), this.getColumnCase("addr"), - this.getColumnCase("medium_id"), this.getColumnCase("contact_id"), this.getColumnCase("isstandard")]; + this.getColumnCase("medium_id"), this.getColumnCase("contact_id"), this.getColumnCase("isstandard")]; this.insertData(this.getTableCase("communication"), columns, null, [util.getNewUUID(), address, medium, contact, standard], this.Config.AliasTo); } return true; @@ -353,33 +354,51 @@ 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 + * reason (optional): The reason. + * medium (required): The medium id. + * contactId (required): The id of the entry in the contact table. + * type (required): Yes or no to communication. * * @name iCommRestriction * @param {Object} pObject req the mapping line * @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 restrictionReason = this.InputRecord[pObject.restrictionReason]; + var restrictionMedium = this.InputRecord[pObject.restrictionMedium]; + var contact = this.InputRecord[pObject.contact]; + var restricionType = this.InputRecord[pObject.restricionType]; + + if(reason == undefined) reason = this.resolveSymbol(pObject, pObject.reason); + if(medium == undefined) medium = this.resolveSymbol(pObject, pObject.medium); + if(contact == undefined) contact = this.resolveSymbol(pObject, pObject.contactId); + if(type == undefined) restricionType = this.resolveSymbol(pObject, pObject.restricionType); 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); + + var alias = this.Config.AliasTo; + var type = this.getColumnCase("type"); + var commRestriction = this.getColumnCase("commrestriction"); + var commRestrictionId = this.getColumnCase("commrestrictionid"); + var contactId = this.getColumnCase("contact_id"); + var medium = this.getColumnCase("medium"); + var dateEdit = this.getColumnCase("date_edit"); + var dateNew = this.getColumnCase("date_new"); + var reason = this.getColumnCase("reason"); + +// 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"; + +// db.cell([sql, [[contact, SQLTYPES.CHAR], [medium, SQLTYPES.CHAR]]], this.Config.AliasTo); + + var id = newSelect(type, alias).from(commRestriction).where(contactId, contact).and(medium, restrictionMedium) + .orderBy(dateEdit + " desc" + dateNew + " desc").; + 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")]; @@ -430,11 +449,11 @@ function iActivityLink(pObject) var configAliasTo = this.Config.AliasTo; var sql = "select " + columnCaseActivityLinkId - +" from " + tableCaseActivityLink - + " where " + columnCaseActivityId - + " = ? and " + columnCaseObjectType - + " = ? and " + columnCaseObjectRowId - + " = ?"; + +" from " + tableCaseActivityLink + + " where " + columnCaseActivityId + + " = ? and " + columnCaseObjectType + + " = ? and " + columnCaseObjectRowId + + " = ?"; var id = db.cell([sql, [[activityId, SQLTYPES.VARCHAR], [objectType, SQLTYPES.VARCHAR], [objectId, SQLTYPES.CHAR]]], configAliasTo); @@ -469,15 +488,15 @@ function iDocumentByPath(pObject){ logging.log(filename + " " + dateNew) } var sql = "select count(" + this.getColumnCase("row_id") + ") from " + this.getTableCase("asys_binaries") - + " where " + this.getColumnCase("row_id") + " = ? and " + this.getColumnCase("filename") + " = ?"; + + " where " + this.getColumnCase("row_id") + " = ? and " + this.getColumnCase("filename") + " = ?"; var count = db.cell([sql, [[row, SQLTYPES.CHAR], [filename, SQLTYPES.VARCHAR]]], this.Config. AliasSys); if(count == 0) { var cols = [this.getColumnCase("Id"), this.getColumnCase("Tablename"), this.getColumnCase("Datasize"), - this.getColumnCase("date_new"), this.getColumnCase("date_edit"), this.getColumnCase("user_new"), - this.getColumnCase("bindata"), this.getColumnCase("containername"), this.getColumnCase("filename"), - this.getColumnCase("row_id"), this.getColumnCase("mimetype")]; + this.getColumnCase("date_new"), this.getColumnCase("date_edit"), this.getColumnCase("user_new"), + this.getColumnCase("bindata"), this.getColumnCase("containername"), this.getColumnCase("filename"), + this.getColumnCase("row_id"), this.getColumnCase("mimetype")]; var vals = [util.getNewUUID(), "$!GENERIC!$", length, dateNew, dateNew, vars.getString("$sys.user"), data, - "DOCUMENT", filename, row, util.getMimeType(filename)]; + "DOCUMENT", filename, row, util.getMimeType(filename)]; db.insertData(this.getTableCase("asys_binaries"), cols, null, vals, this.Config. AliasSys); } } @@ -518,15 +537,15 @@ function iDocument(pObject) if(pObject.Rowid != "" && pObject.Filename != "") db.insertBinary( - pObject.Tablename, - pObject.Container, - this.getOutput(pObject, "Rowid"), - null, - this.InputRecord[pObject.Source], - this.InputRecord[pObject.Filename], - desc, - keyw, - this.Config.AliasTo); + pObject.Tablename, + pObject.Container, + this.getOutput(pObject, "Rowid"), + null, + this.InputRecord[pObject.Source], + this.InputRecord[pObject.Filename], + desc, + keyw, + this.Config.AliasTo); } catch(ex) { @@ -739,17 +758,17 @@ function iJoin(pObject) { if (pObject.Source != undefined) if(this.InputRecord[pObject.Source[i]] != "") - { - if(i > 0 ) s += pObject.Delimiter; - s += this.InputRecord[pObject.Source[i]]; - } + { + if(i > 0 ) s += pObject.Delimiter; + s += this.InputRecord[pObject.Source[i]]; + } if(pObject.Value != undefined) if(this.resolveSymbol(pObject, pObject.Value[i]) != "") - { - if(i > 0 ) s += pObject.Delimiter; - s += this.resolveSymbol(pObject, pObject.Value[i]); - } + { + if(i > 0 ) s += pObject.Delimiter; + s += this.resolveSymbol(pObject, pObject.Value[i]); + } } this.setOutput(pObject, s); -- GitLab