Skip to content
Snippets Groups Projects
Commit 7f9cafbc authored by Sebastian Listl's avatar Sebastian Listl :speech_balloon:
Browse files

1083903 importer standard communications

parent 2c73e0b8
No related branches found
No related tags found
No related merge requests found
import("Keyword_lib");
import("Communication_lib");
import("system.fileIO");
import("system.SQLTYPES");
import("system.text");
......@@ -480,41 +482,79 @@ function iKeywordAttribute (pObject)
* @return {Boolean} true
* */
function iComm(pObject) {
if (! this.doIfCheck(pObject)) return true;
function iComm (pObject)
{
if (!this.doIfCheck(pObject))
return true;
var address = this.InputRecord[pObject.Address];
var medium = this.InputRecord[pObject.Medium];
var contact = this.InputRecord[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 == 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;
if (!address || !medium || !contact)
return true;
const COMMUNICATION = this.getTableCase("communication");
const COMMUNICATIONID = this.getColumnCase("communicationid");
const OBJECT_ROWID = this.getColumnCase("object_rowid");
const OBJECT_TYPE = this.getColumnCase("object_type");
const ISSTANDARD = this.getColumnCase("isstandard");
const MEDIUM_ID = this.getColumnCase("medium_id");
const ADDR = this.getColumnCase("addr");
var keywordAttr = new KeywordAttribute($KeywordRegistry.communicationMedium(), "category");
mediumCategory = new SqlBuilder(this.Config.AliasTo)
.select("AB_KEYWORD_ATTRIBUTERELATION." + keywordAttr.dbField)
.from("AB_KEYWORD_ATTRIBUTERELATION")
.join("AB_KEYWORD_ENTRY", "AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID = AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID")
.where("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID", keywordAttr.id)
.and("AB_KEYWORD_ENTRY.KEYID", medium)
.cell();
var sql = "select " + this.getColumnCase("communicationid") + ", " + this.getColumnCase("addr") + " from " + this.getTableCase("communication")
+" where " + this.getColumnCase("object_rowid") + " = ? and " + this.getColumnCase("medium_id") + " = ? and "
+ this.getColumnCase("isstandard") + " = ? and " + this.getColumnCase("object_type") + " = ?";
var existingData = db.array(db.ROW, [sql, [[contact, SQLTYPES.CHAR], [medium, SQLTYPES.CHAR], //TODO: define types dynamically and not hardcoded
[standard, SQLTYPES.SMALLINT], ["Contact", SQLTYPES.CHAR]]], this.Config.AliasTo, 0, this.getConfiguredTimeout());
var sql = new SqlBuilder(this.Config.AliasTo)
.select([COMMUNICATIONID, ADDR, MEDIUM_ID, ISSTANDARD])
.from(COMMUNICATION)
.where(COMMUNICATION + "." + OBJECT_ROWID, contact)
.and(COMMUNICATION + "." + OBJECT_TYPE, "Contact")
.and(COMMUNICATION + "." + MEDIUM_ID, CommUtil.getMediumIdsByCategory(mediumCategory), SqlBuilder.IN());
var existingData = sql.table(null, null, this.getConfiguredTimeout());
var hasStandardAddr = existingData.some(function (commData)
{
return commData[3] == "1"; //check if there is already a standard address for the medium category
});
if (hasStandardAddr)
{
standard = "0";
}
var existingComm = existingData.find(function (commData)
{
return commData[2] == medium; //check if communication with the same medium exists
});
if (existingData.length == 0)
if (!existingComm)
{
var columns = [this.getColumnCase("communicationid"), this.getColumnCase("addr"),
this.getColumnCase("medium_id"), this.getColumnCase("object_rowid"), this.getColumnCase("isstandard")];
this.insertData(this.getTableCase("communication"), columns, null, [util.getNewUUID(), address, medium, contact, standard], this.Config.AliasTo);
var columns = [COMMUNICATIONID, ADDR, MEDIUM_ID, OBJECT_ROWID, ISSTANDARD];
this.insertData(COMMUNICATION, columns, null, [util.getNewUUID(), address, medium, contact, standard], this.Config.AliasTo);
}
else
{
var existingId = existingData[0];
var existingAddress = existingData[1];
var existingId = existingComm[0];
var existingAddress = existingComm[1];
if (address != existingAddress)
{
var cond = this.getColumnCase("communicationid") + " = '" + existingId + "'";
this.updateData(this.getTableCase("communication"), [this.getColumnCase("addr")], null, [address], cond, this.Config.AliasTo);
var cond = COMMUNICATIONID + " = '" + existingId + "'";
this.updateData(COMMUNICATION, [ADDR], null, [address], cond, this.Config.AliasTo);
}
}
return true;
......
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