Skip to content
Snippets Groups Projects
Commit 0f4e6165 authored by Johannes Goderbauer's avatar Johannes Goderbauer
Browse files

Merge branch '1049113-Fix-iKeywordAttribute' into '2020.0'

#1049113 - Fix iKeywordAttribute

See merge request xrm/basic!111
parents 38721782 984e90a4
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ import("system.util");
import("system.datetime");
import("system.logging");
import("Attribute_lib");
import("KeywordRegistry_basic");
import("Sql_lib");
import("Importer_lib");
......@@ -178,90 +179,134 @@ function iAttribute(pObject) {
/*
* Values of the mapping line:
* Attribute req -- the column index with the new attribute value
* AType req -- the type of the attribute
* Container req -- the container name of the keyword
* Keyword opt -- a new keyword name or an existing KeyId (AB_KEYWORD_ATTRIBUTERELATION)
* Value opt - the value of the relation (AB_KEYWORD_ATTRIBUTERELATION)
* - attribute (required): The column index with the new attribute value.
* - attributeType (required): The type of the attribute.
* - keywordContainer (required): The container name of the keyword.
* - keyword (optional): A new keyword name or an existing KeyId (AB_KEYWORD_ATTRIBUTERELATION).
* - value (optional): The value of the relation (AB_KEYWORD_ATTRIBUTERELATION).
*
* @name iKeywordAttribute
* @param {Object} pObject req the mapping line
* @param {Object} pObject (required) the mapping line.
* @return {Boolean} true
* */
function iKeywordAttribute(pObject) {
if (!this.doIfCheck(pObject)) return true;
var attribute = this.InputRecord[pObject.Attribute];
if(attribute == undefined) attribute = this.resolveSymbol(pObject, pObject.Attribute);
var atype = this.InputRecord[pObject.AType];
if(atype == undefined) atype = this.resolveSymbol(pObject, pObject.AType);
var container = this.InputRecord[pObject.Container];
if(container == undefined) container = this.resolveSymbol(pObject, pObject.Container);
var keyword = this.InputRecord[pObject.Keyword];
if(keyword == undefined) keyword = this.resolveSymbol(pObject, pObject.Keyword);
var value = this.InputRecord[pObject.Value];
if(value == undefined) value = this.resolveSymbol(pObject, pObject.Value);
var keywordAttribute = this.InputRecord[pObject.attribute];
if(keywordAttribute == undefined) keywordAttribute = this.resolveSymbol(pObject, pObject.attribute);
var keywordAttributeType = this.InputRecord[pObject.attributeType];
if(keywordAttributeType == undefined) keywordAttributeType = this.resolveSymbol(pObject, pObject.attributeType);
var keywordContainer = this.InputRecord[pObject.keywordContainer];
if(keywordContainer == undefined) keywordContainer = this.resolveSymbol(pObject, pObject.keywordContainer);
if (!attribute || !container || !atype) return true;
atype = atype.toUpperCase();
var keyword = this.InputRecord[pObject.keyword];
if(keyword == undefined) keyword = this.resolveSymbol(pObject, pObject.keyword);
var keywordAttrRelValue = this.InputRecord[pObject.keywordAttrRelValue];
if(keywordAttrRelValue == undefined) keywordAttrRelValue = this.resolveSymbol(pObject, pObject.keywordAttrRelValue);
if (!keywordAttribute || !keywordContainer || !keywordAttributeType) return true;
keywordAttributeType = keywordAttributeType.toUpperCase();
var valueColumn = "";
switch (atype) {
case $AttributeTypes.TEXT.toString():
switch (keywordAttributeType) {
case $KeywordRegistry.keywordAttributeType$char():
valueColumn = this.getColumnCase("char_value");
break;
case $AttributeTypes.NUMBER.toString():
case $KeywordRegistry.keywordAttributeType$number():
valueColumn = this.getColumnCase("number_value");
break;
case $AttributeTypes.BOOLEAN.toString():
case $KeywordRegistry.keywordAttributeType$bool():
valueColumn = this.getColumnCase("bool_value");
break;
case $KeywordRegistry.keywordAttributeType$longChar():
valueColumn = this.getColumnCase("long_char_value");
break;
default:
return true;
}
var sql = "select " + this.getColumnCase("ab_keyword_attributeid") + " from " + this.getTableCase("ab_keyword_attribute")
+ " where " + this.getColumnCase("name") + " = ? and " + this.getColumnCase("container") + " = ?";
var aid = db.cell([sql, [[attribute, SQLTYPES.VARCHAR], [container, SQLTYPES.VARCHAR]]], this.Config.AliasTo);
if (aid == "" || aid == null) {
aid = util.getNewUUID();
var columns = [this.getColumnCase("ab_keyword_attributeid"), this.getColumnCase("name"), this.getColumnCase("container"), this.getColumnCase("type")];
this.insertData(this.getTableCase("ab_keyword_attribute"), columns, null, [aid, attribute, container, atype], this.Config.AliasTo);
var sql = "select " + this.getColumnCase("ab_keyword_attributeid")
+ " 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);
// Creates the entry in AB_KEYWORD_ATTRIBUTE, case if it not exists.
if (attributeId == "" || attributeId == null) {
attributeId = util.getNewUUID();
var columns = [this.getColumnCase("ab_keyword_attributeid"),
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);
}
if (keyword && value) {
sql = "select " + this.getColumnCase("keyid") + " from " + this.getTableCase("ab_keyword_entry") + " where "
+ this.getColumnCase("keyid") + " = ?";
var kid = db.cell([sql, [[keyword, SQLTYPES.CHAR]]], this.Config.AliasTo);
// Creates the entry in AB_KEYWORD_ENTRY and AB_KEYWORD_ATTRIBUTERELATION, case if it not exists.
if (keyword && keywordAttrRelValue) {
sql = "select " + this.getColumnCase("ab_keyword_entryid")
+ " from " + this.getTableCase("ab_keyword_entry")
+ " where " + this.getColumnCase("keyid") + " = ?";
var keywordId = db.cell([sql, [[keyword, SQLTYPES.CHAR]]], this.Config.AliasTo);
if (kid == "" || kid == null) {
sql = "select " + this.getColumnCase("keyid") + " from " + this.getTableCase("ab_keyword_entry") + " where "
+ this.getColumnCase("container") + " = ? and " + this.getColumnCase("title") + " = ?";
kid = db.cell([sql, [[container, SQLTYPES.VARCHAR], [keyword, SQLTYPES.VARCHAR]]], this.Config.AliasTo);
if (kid == "" || kid == null) {
if (keywordId == "" || keywordId == null) {
sql = "select " + this.getColumnCase("keyid")
+ " from " + this.getTableCase("ab_keyword_entry")
+ " where " + this.getColumnCase("container")
+ " = ? and " + this.getColumnCase("title") + " = ?";
keywordId = db.cell([sql, [[keywordContainer, SQLTYPES.VARCHAR], [keyword, SQLTYPES.VARCHAR]]], this.Config.AliasTo);
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 = ?";
var sort = db.cell([sql, [[container, SQLTYPES.VARCHAR]]], this.Config.AliasTo);
var sort = db.cell([sql, [[keywordContainer, SQLTYPES.VARCHAR]]], this.Config.AliasTo);
if(sort == "") sort = "0";
kid = util.getNewUUID();
keywordId = util.getNewUUID();
this.insertData(this.getTableCase("ab_keyword_entry"), columns, null,
[kid, util.getNewUUID(), container, keyword, sort, "1", "0"], this.Config.AliasTo);
[keywordId, util.getNewUUID(), keywordContainer, keyword, sort, "1", "0"], this.Config.AliasTo);
}
}
sql = "select " + this.getColumnCase("ab_keyword_attributerelationid") + " from " + this.getTableCase("ab_keyword_attributerelation")
+ " where " + this.getColumnCase("ab_keyword_entry_id") + " = ? and " + this.getColumnCase("ab_keyword_attribute_id") + " = ?";
id = db.cell([sql, [[kid, SQLTYPES.CHAR], [aid, SQLTYPES.CHAR]]], this.Config.AliasTo);
// Creates or updates the keyword attributerelation.
sql = "select " + this.getColumnCase("ab_keyword_attributerelationid")
+ " from " + this.getTableCase("ab_keyword_attributerelation")
+ " where " + this.getColumnCase("ab_keyword_entry_id")
+ " = ? and " + this.getColumnCase("ab_keyword_attribute_id") + " = ?";
id = db.cell([sql, [[keywordId, SQLTYPES.CHAR], [attributeId, SQLTYPES.CHAR]]], this.Config.AliasTo);
if (id == "" || id == null) {
columns = [this.getColumnCase("ab_keyword_attributerelationid"), this.getColumnCase("ab_keyword_entry_id"),
this.getColumnCase("ab_keyword_attribute_id"), valueColumn];
columns = [this.getColumnCase("ab_keyword_attributerelationid"),
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, kid, aid, value], this.Config.AliasTo);
this.insertData(this.getTableCase("ab_keyword_attributerelation"), columns, null,
[id, keywordId, attributeId, keywordAttrRelValue], this.Config.AliasTo);
} else {
if (this.Config.ImportCommand.indexOf("update") != -1) {
cond = this.getColumnCase("ab_keyword_attributerelationid") + " = '" + id + "'";
this.updateData(this.getTableCase("ab_keyword_attributerelation"), [valueColumn], null, [value], cond, this.Config.AliasTo);
this.updateData(this.getTableCase("ab_keyword_attributerelation"), [valueColumn], null, [keywordAttrRelValue], cond, this.Config.AliasTo);
}
}
}
......
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