Skip to content
Snippets Groups Projects
Commit ed718e80 authored by Johannes Hörmann's avatar Johannes Hörmann
Browse files

Lead import: move error logs to import logs-preview && bugfixes && refactorings && use SqlBuilder

parent d6f5d616
No related branches found
No related tags found
No related merge requests found
Showing
with 300 additions and 269 deletions
......@@ -211,6 +211,12 @@
<fieldName>DocumentC</fieldName>
<isConsumer v="false" />
</entityDependency>
<entityDependency>
<name>cea7ef62-e3fb-43af-8a11-952d809e8242</name>
<entityName>LeadLog_entity</entityName>
<fieldName>LogDocuments</fieldName>
<isConsumer v="false" />
</entityDependency>
</dependencies>
<children>
<entityParameter>
......
......@@ -57,13 +57,28 @@
<name>IMPORTROWS</name>
<title>Inserted rows</title>
</entityField>
<entityActionField>
<name>resetImport</name>
<title>Reset import</title>
<onActionProcess>&#xD;
</onActionProcess>
<isSelectionAction v="true" />
</entityActionField>
<entityConsumer>
<name>LogDocuments</name>
<dependency>
<name>dependency</name>
<entityName>Document_entity</entityName>
<fieldName>Documents</fieldName>
</dependency>
<children>
<entityParameter>
<name>AssignmentName_param</name>
<valueProcess>%aditoprj%/entity/LeadLog_entity/entityfields/logdocuments/children/assignmentname_param/valueProcess.js</valueProcess>
</entityParameter>
<entityParameter>
<name>AssignmentRowId_param</name>
<valueProcess>%aditoprj%/entity/LeadLog_entity/entityfields/logdocuments/children/assignmentrowid_param/valueProcess.js</valueProcess>
</entityParameter>
<entityParameter>
<name>AssignmentTable_param</name>
<valueProcess>%aditoprj%/entity/LeadLog_entity/entityfields/logdocuments/children/assignmenttable_param/valueProcess.js</valueProcess>
</entityParameter>
</children>
</entityConsumer>
</entityFields>
<recordContainers>
<dbRecordContainer>
......
import("system.result");
result.string("ERRORLOG");
\ No newline at end of file
import("system.vars");
import("system.result");
result.string(vars.get("$field.LEADLOGID"));
\ No newline at end of file
import("system.result");
result.string("LEADLOG");
\ No newline at end of file
......@@ -24,6 +24,7 @@
<entityField>
<name>NAME</name>
<title>Import name</title>
<mandatory v="true" />
</entityField>
<entityField>
<name>LEADIMPORT_EMPLOYEE</name>
......@@ -53,7 +54,7 @@
<title>File</title>
<contentType>FILE</contentType>
<mandatory v="true" />
<valueProcess></valueProcess>
<displayValueProcess>%aditoprj%/entity/Leadimport_entity/entityfields/bindata/displayValueProcess.js</displayValueProcess>
</entityField>
<entityField>
<name>LEADIMPORTID</name>
......@@ -215,12 +216,6 @@
</entityParameter>
</children>
</entityConsumer>
<entityField>
<name>filename</name>
<linkedContext>Document</linkedContext>
<valueProcess>%aditoprj%/entity/Leadimport_entity/entityfields/filename/valueProcess.js</valueProcess>
<displayValueProcess>%aditoprj%/entity/Leadimport_entity/entityfields/filename/displayValueProcess.js</displayValueProcess>
</entityField>
<entityConsumer>
<name>LogHistoryC</name>
<dependency>
......
import("Sql_lib");
import("system.result");
import("system.vars");
import("system.db");
var binMetadatas = db.getBinaryMetadata("LEADIMPORT", "IMPORTFILE", vars.get("$field.LEADIMPORTID"), false, SqlUtils.getBinariesAlias(), "");
if (binMetadatas.length > 0)
{
result.string(binMetadatas[0].filename);
} else {
result.string("FILE MISSING");
}
\ No newline at end of file
import("system.result");
import("Sql_lib");
import("system.vars");
import("system.db");
var data = db.cell(SqlCondition.begin(SqlUtils.getBinariesAlias())
.andPrepare("ASYS_BINARIES.ROW_ID", vars.getString("$field.LEADIMPORTID"))
.buildSql("select FILENAME from ASYS_BINARIES"), SqlUtils.getBinariesAlias());
result.string(data);
\ No newline at end of file
import("system.result");
import("Sql_lib");
import("system.vars");
import("system.db");
var data = db.cell(SqlCondition.begin(SqlUtils.getBinariesAlias())
.andPrepare("ASYS_BINARIES.ROW_ID", vars.getString("$field.LEADIMPORTID"))
.buildSql("select FILENAME from ASYS_BINARIES"), SqlUtils.getBinariesAlias());
result.string(data);
\ No newline at end of file
......@@ -14,56 +14,63 @@ var assignmentRowId = vars.get("$field.LEADIMPORTID");
var importDate = vars.get("$field.LEADIMPORT_DATE");
var importName = vars.get("$field.NAME");
var binId = db.cell(SqlCondition.begin(SqlUtils.getBinariesAlias())
.andPrepare("ASYS_BINARIES.ROW_ID", assignmentRowId)
.buildSql("select ID from ASYS_BINARIES", "1=2"), SqlUtils.getBinariesAlias());
var fieldSep = KeywordUtils.getViewValue($KeywordRegistry.fieldSeparator(), vars.get("$field.FIELDSEPARATOR"));
var fieldLimit = KeywordUtils.getViewValue($KeywordRegistry.fieldLimit(), vars.get("$field.FIELDDELIMITERS"));
var recordSep = KeywordUtils.getViewValue($KeywordRegistry.recordSeparator(), vars.get("$field.SENTENCESEPARATOR"));
var binMetadatas = db.getBinaryMetadata("LEADIMPORT", "IMPORTFILE", vars.get("$field.LEADIMPORTID"), false, SqlUtils.getBinariesAlias(), "");
if (binMetadatas.length > 0)
{
var binId = binMetadatas[0].id;
if (recordSep == "CRLF") recordSep = '\r\n';
if ( fieldSep == "TAB" ) fieldSep = '\t';
else fieldSep = fieldSep.charAt(0);
var fieldSep = KeywordUtils.getViewValue($KeywordRegistry.fieldSeparator(), vars.get("$field.FIELDSEPARATOR"));
var fieldLimit = KeywordUtils.getViewValue($KeywordRegistry.fieldLimit(), vars.get("$field.FIELDDELIMITERS"));
var recordSep = KeywordUtils.getViewValue($KeywordRegistry.recordSeparator(), vars.get("$field.SENTENCESEPARATOR"));
var data = db.getBinaryContent(binId, SqlUtils.getBinariesAlias());
data = util.decodeBase64String(data);
var table = text.parseCSV(data.replace(/(^\s+)|(\s+$)/g,""), recordSep, fieldSep, fieldLimit.charAt(0));
if (recordSep == "CRLF") recordSep = '\r\n';
if ( fieldSep == "TAB" ) fieldSep = '\t';
else fieldSep = fieldSep.charAt(0);
var insertTable = "LEADTEMP";
var insertCols = LeadImportUtils.leadTempColumns();
var insertTypes = db.getColumnTypes(insertTable, insertCols);
var insertVals = [];
var data = db.getBinaryContent(binId, SqlUtils.getBinariesAlias());
data = util.decodeBase64String(data);
var toInsert = [];
var table = text.parseCSV(data.replace(/(^\s+)|(\s+$)/g,""), recordSep, fieldSep, fieldLimit.charAt(0));
db.deleteData(insertTable, "ROW_ID = '" + assignmentRowId + "'");//delete existing
var insertTable = "LEADTEMP";
var insertCols = LeadImportUtils.leadTempColumns();
var insertTypes = db.getColumnTypes(insertTable, insertCols);
var insertVals = [];
for (i = 0; i < table.length; i++)//and load new
{
insertVals = [];
for (j = 0; j < 30; j++) //fill the 30 data-columns of the table
var toInsert = [];
db.deleteData(insertTable, "ROW_ID = '" + assignmentRowId + "'");//delete existing
for (i = 0; i < table.length; i++)//and load new
{
if(table[i][j] == undefined)
table[i][j] = "";
insertVals.push(table[i][j]);
insertVals = [];
for (j = 0; j < 30; j++) //fill the 30 data-columns of the table
{
if(table[i][j] == undefined)
table[i][j] = "";
insertVals.push(table[i][j]);
}
insertVals.push(importDate, util.getNewUUID(), importName, i.toString(), assignmentRowId);//push other necessary data for the insert
toInsert.push([insertTable, insertCols, insertTypes, insertVals]);
}
insertVals.push(importDate, util.getNewUUID(), importName, i.toString(), assignmentRowId);//push other necessary data for the insert
toInsert.push([insertTable, insertCols, insertTypes, insertVals]);
}
db.inserts(toInsert);
db.inserts(toInsert);
question.showMessage("Daten wurden geladen! Zeilen: " + eMath.subInt(table.length, 1));
question.showMessage("Daten wurden geladen! Zeilen: " + eMath.subInt(table.length, 1));
var updTable = "LEADIMPORT";
var updCols = ["STATUS"];
var updTypes = db.getColumnTypes(updTable, updCols);
var updTable = "LEADIMPORT";
var updCols = ["STATUS"];
var updTypes = db.getColumnTypes(updTable, updCols);
db.updateData(updTable, updCols, updTypes, [$KeywordRegistry.importStatus$loaded()], newWhere([updTable, "LEADIMPORTID"], assignmentRowId));
db.updateData(updTable, updCols, updTypes, [$KeywordRegistry.importStatus$loaded()], "LEADIMPORTID = '" + assignmentRowId + "'");
neon.refreshAll();
neon.refreshAll();
} else {
question.showMessage("Error: The Importfile could not be found anymore.");
}
\ No newline at end of file
import("system.question");
import("Employee_lib");
import("system.process");
import("KeywordRegistry_basic");
......@@ -7,33 +8,39 @@ import("system.db");
import("system.vars");
import("system.neon");
var binMetadatas = db.getBinaryMetadata("LEADIMPORT", "IMPORTFILE", vars.get("$field.LEADIMPORTID"), false, SqlUtils.getBinariesAlias(), "");
var assignmentRowId = vars.get("$field.LEADIMPORTID");
var name = vars.get("$field.NAME");
var fieldSep = KeywordUtils.getViewValue($KeywordRegistry.fieldSeparator(), vars.get("$field.FIELDSEPARATOR"));
var recordSep = KeywordUtils.getViewValue($KeywordRegistry.recordSeparator(), vars.get("$field.SENTENCESEPARATOR"));
var fieldLimit = KeywordUtils.getViewValue($KeywordRegistry.fieldLimit(), vars.get("$field.FIELDDELIMITERS"));
var user = vars.get("$sys.user");
if (recordSep == "CRLF") recordSep = '\r\n';
if ( fieldSep == "TAB" ) fieldSep = '\t';
else fieldSep = fieldSep.charAt(0);
var params =
if (binMetadatas.length > 0)
{
importdefid: vars.get("$field.LEADIMPORTID"),
assignmentRowId: assignmentRowId,
binId: db.cell(SqlCondition.begin(SqlUtils.getBinariesAlias()).andPrepare("ASYS_BINARIES.ROW_ID", assignmentRowId).buildSql("select ID from ASYS_BINARIES", "1=2"), SqlUtils.getBinariesAlias()),
recordSep: recordSep,
fieldSep: fieldSep,
fieldLimit: fieldLimit,
user: user,
source: vars.getString("$field.IMPORTSOURCE"),
currDate: vars.get("$sys.date"),
userId: EmployeeUtils.getCurrentUserId(),
importName: name
}
var binId = binMetadatas[0].id;
var assignmentRowId = vars.get("$field.LEADIMPORTID");
var name = vars.get("$field.NAME");
var fieldSep = KeywordUtils.getViewValue($KeywordRegistry.fieldSeparator(), vars.get("$field.FIELDSEPARATOR"));
var recordSep = KeywordUtils.getViewValue($KeywordRegistry.recordSeparator(), vars.get("$field.SENTENCESEPARATOR"));
var fieldLimit = KeywordUtils.getViewValue($KeywordRegistry.fieldLimit(), vars.get("$field.FIELDDELIMITERS"));
var user = vars.get("$sys.user");
if (recordSep == "CRLF") recordSep = '\r\n';
if ( fieldSep == "TAB" ) fieldSep = '\t';
else fieldSep = fieldSep.charAt(0);
//process.execute("importLead_serverProcess", params);
process.executeAsync("importLead_serverProcess", params, false, user, process.THREADPRIORITY_LOW, process.TIMERTYPE_SERVER)
var params =
{
importdefid: vars.get("$field.LEADIMPORTID"),
assignmentRowId: assignmentRowId,
binId: binId,
recordSep: recordSep,
fieldSep: fieldSep,
fieldLimit: fieldLimit,
user: user,
source: vars.getString("$field.IMPORTSOURCE"),
currDate: vars.get("$sys.date"),
userId: EmployeeUtils.getCurrentUserId(),
importName: name
}
//process.execute("importLead_serverProcess", params);
process.executeAsync("importLead_serverProcess", params, false, user, process.THREADPRIORITY_LOW, process.TIMERTYPE_SERVER)
} else {
question.showMessage("Error: The Importfile could not be found anymore.");
}
\ No newline at end of file
......@@ -3,16 +3,33 @@ import("system.vars");
import("system.db");
var leadImportId = vars.getString("$field.LEADIMPORTID");
var binId = db.cell(SqlCondition.begin(SqlUtils.getBinariesAlias())
.andPrepare("ASYS_BINARIES.ROW_ID", leadImportId)
.buildSql("select ID from ASYS_BINARIES", "1=2"), SqlUtils.getBinariesAlias());
// the import file
var binMetadata = db.getBinaryMetadata("LEADIMPORT", "IMPORTFILE", leadImportId, false, SqlUtils.getBinariesAlias(), "");
// additional uploaded files from Document tab
binMetadata = binMetadata.concat(db.getBinaryMetadata("LEADIMPORT", "DOCUMENT", leadImportId, false, SqlUtils.getBinariesAlias(), ""));
// error log files
newSelect("LEADLOGID")
.from("LEADLOG")
.where("LEADLOG.LEADIMPORT_ID", leadImportId)
.arrayColumn()
.forEach(function(leadLogId)
{
binMetadata = binMetadata.concat(db.getBinaryMetadata("LEADLOG", "ERRORLOG", leadLogId, false, SqlUtils.getBinariesAlias(), ""));
});
if(leadImportId != "")//delete the connected importfields
{
db.deleteData("IMPORTFIELD", "LEADIMPORT_ID = '" + leadImportId + "'");
db.deleteData("LEADTEMP", "ROW_ID = '" + leadImportId + "'");
db.deleteData("LEAD", "LEADIMPORT_ID = '" + leadImportId + "'");
}
{
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());
}
if(binId != "")//delete the connected binData
db.deleteBinary(binId, SqlUtils.getBinariesAlias());
\ No newline at end of file
binMetadata.forEach(function(pMeta)
{ //delete the connected binData
db.deleteBinary(pMeta.id, SqlUtils.getBinariesAlias());
});
\ No newline at end of file
import("Sql_lib");
import("KeywordRegistry_basic");
import("Keyword_lib");
import("Binary_lib");
......@@ -18,11 +19,10 @@ var recordSep = KeywordUtils.getViewValue($KeywordRegistry.recordSeparator(), va
if(bindata != '' && filename != '')
{
var mimeType = DocumentUtil.getMimeTypeFromUpload(vars.get("$field.bindata"));
if (mimeType == "application/vnd.ms-excel")
{
SingleBinaryUtils.insertMainDocument("LEADIMPORT", "", assignmentRowId, bindata, filename, "");
LeadImportUtils.loadImportFile(vars.get("$field.bindata"), fieldSep, fieldLimit, recordSep, assignmentRowId);
var documentId = SingleBinaryUtils.insertMainDocument("LEADIMPORT", "IMPORTFILE", assignmentRowId, bindata, filename, "", SqlUtils.getBinariesAlias());
LeadImportUtils.loadImportFile(documentId, fieldSep, fieldLimit, recordSep, assignmentRowId);
}
}
import("system.neon");
import("Sql_lib");
import("KeywordRegistry_basic");
import("Keyword_lib");
......@@ -21,12 +22,12 @@ if(bindata != '' && filename != '')
if (mimeType == "application/vnd.ms-excel")
{
var binId = db.cell(SqlCondition.begin(SqlUtils.getBinariesAlias())
.andPrepare("ASYS_BINARIES.ROW_ID", vars.getString("$field.LEADIMPORTID"))
.buildSql("select ID from ASYS_BINARIES", "1=2"), SqlUtils.getBinariesAlias());
db.updateBinary(binId, "", bindata, filename, "", "MAINDOCUMENT", SqlUtils.getBinariesAlias());
LeadImportUtils.loadImportFile(vars.get("$field.bindata"), fieldSep, fieldLimit, recordSep, assignmentRowId, true, vars.get("$param.LeadimportNewFile_param"));
var binMetadata = db.getBinaryMetadata("LEADIMPORT", "IMPORTFILE", assignmentRowId, false, SqlUtils.getBinariesAlias(), "MAINDOCUMENT");
if (binMetadata.length > 0) {
db.updateBinary(binMetadata[0].id, "", bindata, filename, "", "MAINDOCUMENT", SqlUtils.getBinariesAlias());
LeadImportUtils.loadImportFile(binMetadata[0].id, fieldSep, fieldLimit, recordSep, assignmentRowId, true, vars.get("$param.LeadimportNewFile_param"));
}
}
}
neon.refreshAll();
\ No newline at end of file
......@@ -2,11 +2,17 @@
<neonContext xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.0" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonContext/1.1.0">
<name>LeadLog</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<filterview>LeadLogFilter_view</filterview>
<preview>LeadLogPreview_view</preview>
<entity>LeadLog_entity</entity>
<references>
<neonViewReference>
<name>dab31f69-12a0-4074-af81-f497853eca24</name>
<view>LeadLogFilter_view</view>
</neonViewReference>
<neonViewReference>
<name>3e5f7e73-5a5c-4004-9b08-95f495e84a06</name>
<view>LeadLogPreview_view</view>
</neonViewReference>
</references>
</neonContext>
<?xml version="1.0" encoding="UTF-8"?>
<neonView xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.2" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.2">
<name>DocumentList_view</name>
<title>Errorlogs</title>
<majorModelMode>DISTRIBUTED</majorModelMode>
<layout>
<drawerLayout>
......
<?xml version="1.0" encoding="UTF-8"?>
<neonView xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.2" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.2">
<name>LeadLogPreview_view</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<layout>
<headerFooterLayout>
<name>layout</name>
</headerFooterLayout>
</layout>
<children>
<neonViewReference>
<name>b18d95d9-c767-4dca-a5c4-1171fd436ce9</name>
<entityField>LogDocuments</entityField>
<view>DocumentList_view</view>
</neonViewReference>
</children>
</neonView>
......@@ -60,8 +60,8 @@
<entityField>#ENTITY</entityField>
<fields>
<entityFieldLink>
<name>1b7aaf10-ed58-4f0d-9dbc-f329e89b71e6</name>
<entityField>filename</entityField>
<name>24d3036f-be4e-418c-a13f-e21c44112edf</name>
<entityField>bindata</entityField>
</entityFieldLink>
</fields>
</genericViewTemplate>
......
......@@ -72,7 +72,7 @@ LeadImportUtils.leadTempColumns = function()
/*
* Load the data
*
* @param {String} pFile req the bindata of the file
* @param {String} pBinId req the binary id for loading the binary
* @param {String} pFieldSep req the fieldSeparator
* @param {String} pFieldLimit req the fieldLimit
* @param {String} pRecordSep req the recordSeparator
......@@ -82,7 +82,7 @@ LeadImportUtils.leadTempColumns = function()
*
* @return {integer} rows the number of rows which have been inserted
*/
LeadImportUtils.loadImportFile = function(pFile, pFieldSep, pFieldLimit, pRecordSep, pLeadImportId, pUpdate, pNewFile)
LeadImportUtils.loadImportFile = function(pBinId, pFieldSep, pFieldLimit, pRecordSep, pLeadImportId, pUpdate, pNewFile)
{
var rows = 0;
var toInsert = [];
......@@ -93,26 +93,23 @@ LeadImportUtils.loadImportFile = function(pFile, pFieldSep, pFieldLimit, pRecord
if(pUpdate == undefined) pUpdate = false;
if (pFile != "")
if (pBinId)
{
if (pRecordSep == "CRLF") pRecordSep = '\r\n';
if ( pFieldSep == "TAB" ) pFieldSep = '\t';
if (pFieldSep == "TAB") pFieldSep = '\t';
else pFieldSep = pFieldSep.charAt(0);
try
{
var binId = db.cell(SqlCondition.begin(SqlUtils.getBinariesAlias())
.andPrepare("ASYS_BINARIES.ROW_ID", pLeadImportId)
.buildSql("select ID from ASYS_BINARIES", "1=2"), SqlUtils.getBinariesAlias());
var data = db.getBinaryContent(binId, SqlUtils.getBinariesAlias());
{
var data = db.getBinaryContent(pBinId, SqlUtils.getBinariesAlias());
data = util.decodeBase64String(data, "UTF-8");
var table = text.parseCSV( data.replace(/(^\s+)|(\s+$)/g,""), pRecordSep, pFieldSep, pFieldLimit.charAt(0));
logging.log(JSON.stringify([table], null, "\t"))
if(pNewFile != "true")
{
if(pUpdate)
db.deleteData("IMPORTFIELD", "LEADIMPORT_ID = '" + pLeadImportId + "'");
if(pUpdate) {
db.deleteData("IMPORTFIELD", newWhere("IMPORTFIELD.LEADIMPORT_ID", pLeadImportId).build());
}
//insert the importfields
for (i = 0; i < table[0].length; i++)
{
......@@ -122,10 +119,11 @@ LeadImportUtils.loadImportFile = function(pFile, pFieldSep, pFieldLimit, pRecord
db.inserts(toInsert);
}
db.deleteData("LEADTEMP", "ROW_ID = '" + pLeadImportId + "'");//delete existing temp data
db.deleteData("LEADTEMP", newWhere("LEADTEMP.ROW_ID", pLeadImportId).build());//delete existing temp data
}
catch(ex)
{
logging.log(ex);
question.showMessage(translate.text("Fehler beim einlesen der Datei !"));
}
}
......@@ -211,7 +209,7 @@ LeadImportUtils.importData = function(pDataFields, pDataTypes, pFieldDef, pField
LeadValues["LEADIMPORT_ID"] = pImportDefID;
LeadValues["ORGANISATION_ID"] = orgid;
LeadValues["PERSON_ID"] = persid;
var leadId = LeadImportUtils.insertTable(pDataFields, pDataTypes ,LeadValues, "LEAD", pUser, pDate);//inserts the LEAD dataset
LeadImportUtils.insertLeadAttr(pAttrObject, orgid, persid, LeadValues["DATE_NEW"], pUser, pDate, (orgRet && orgRet.length >= 4 && orgRet[3]));
......@@ -319,19 +317,14 @@ LeadImportUtils.setValues = function(pFields, pFieldDef, pFieldValues)
*
* @return {[]} ImportFieldDef
*/
LeadImportUtils.getImportFieldDef = function( pID )
LeadImportUtils.getImportFieldDef = function(pID)
{
var condition = SqlCondition.begin();
var ImportFieldDef = db.table(SqlBuilder.begin()
.select("distinct FIELDNUMBER, " + SqlMaskingUtils.prototype.trim("MAPPINGFIELD") + ", ''")
.from("IMPORTFIELD")
.where(condition
.andPrepare("IMPORTFIELD.LEADIMPORT_ID", pID)
.and("MAPPINGFIELD is not null"))
.orderBy("IMPORTFIELD.FIELDNUMBER asc")
.build()
);
var ImportFieldDef = newSelect(["distinct FIELDNUMBER", SqlMaskingUtils.prototype.trim("MAPPINGFIELD"), "''"])
.from("IMPORTFIELD")
.where("IMPORTFIELD.LEADIMPORT_ID", pID)
.and("MAPPINGFIELD is not null")
.orderBy("IMPORTFIELD.FIELDNUMBER asc")
.table();
var FieldDef = new Array();
for (let i = 0; i < ImportFieldDef.length; i++)
......@@ -340,13 +333,15 @@ LeadImportUtils.getImportFieldDef = function( pID )
if(ImportFieldDef[i][1].substr(0, 9) == "ATTRIBUTE")//ATTRIBUTES are defined like ATTRIBUTE_Loyalty
{
var attrName = ImportFieldDef[i][1].substr(10);// so cut the first 10 characters off to get the ATTRIBUTENAME "Loyalty"
var attrdata = db.array(db.ROW, SqlCondition.begin()
.andPrepare("AB_ATTRIBUTE.ATTRIBUTE_NAME", attrName)
.buildSql("select AB_ATTRIBUTEID, ATTRIBUTE_TYPE from AB_ATTRIBUTE", "1=2"));
var attrdata = newSelect("AB_ATTRIBUTEID, ATTRIBUTE_TYPE")
.from("AB_ATTRIBUTE")
.where("AB_ATTRIBUTE.ATTRIBUTE_NAME", attrName)
.arrayRow();
var attrobj = db.table(SqlCondition.begin()
.andPrepare("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", attrdata[0])
.buildSql("select OBJECT_TYPE, MAX_COUNT from AB_ATTRIBUTEUSAGE", "1=2"));
var attrobj = newSelect("OBJECT_TYPE, MAX_COUNT")
.from("AB_ATTRIBUTEUSAGE")
.where("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", attrdata[0])
.table();
var attrobject = new Object();
for (let j = 0; j < attrobj.length; j++)
......@@ -400,11 +395,12 @@ LeadImportUtils.insertAttr = function(pDataFields, pDataTypes, pFieldDef, pLeadV
switch(attrdata[1][1].trim())//type
{
case "COMBO":
value = db.cell(SqlCondition.begin()
.andPrepare("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", attrdata[1][0])
.andPrepare("AB_ATTRIBUTE.ATTRIBUTE_NAME", value)
.buildSql("select AB_ATTRIBUTEID from AB_ATTRIBUTE", "1=2"));
value = newSelect("AB_ATTRIBUTEID")
.from("AB_ATTRIBUTE")
.where("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", attrdata[1][0])
.and("AB_ATTRIBUTE.ATTRIBUTE_NAME", value)
.cell();
type = "ID_VALUE";
break;
//other cases can be added here
......@@ -637,11 +633,12 @@ LeadImportUtils.insertLeadAttr = function(pAttrObject, orgid, persid, pUser, pD
if (orgid != "" && pInsertOrgAttr)
{
AttrValues[0] = "Organisation";
AttrValues[7] = db.cell(SqlCondition.begin()
.andPrepare("CONTACT.ORGANISATION_ID", orgid)
.and("CONTACT.PERSON_ID is null")
.buildSql("select CONTACTID from CONTACT", "1=2"));
AttrValues[7] = newSelect("CONTACTID")
.from("CONTACT")
.where("CONTACT.ORGANISATION_ID", orgid)
.and("CONTACT.PERSON_ID is null")
.cell();
sqlInsertAttr(pAttrObject, AttrValues, pUser, pDate);
}
// Attribute für the Person
......@@ -649,10 +646,11 @@ LeadImportUtils.insertLeadAttr = function(pAttrObject, orgid, persid, pUser, pD
{
AttrValues[0] = "Person";
if (orgid == "") orgid = "0"; // Private
AttrValues[7] = db.cell(SqlCondition.begin()
.andPrepare("CONTACT.ORGANISATION_ID", orgid)
.andPrepare("CONTACT.PERSON_ID", persid)
.buildSql("select CONTACT.CONTACTID from CONTACT", "1=2"));
AttrValues[7] = newSelect("CONTACT.CONTACTID")
.from("CONTACT")
.where("CONTACT.ORGANISATION_ID", orgid)
.and("CONTACT.PERSON_ID", persid)
.cell();
sqlInsertAttr(pAttrObject, AttrValues, pUser, pDate);
}
......@@ -687,104 +685,58 @@ LeadImportUtils.sqlInsertAttr = function(pAttrObject, pAttrValues, pUser, pDate)
*/
LeadImportUtils.getLeadAttr = function(pImportDefID)
{
var ret = new Object();
var condition = SqlCondition.begin();
ret["Fields"] = new Array("OBJECT_TYPE", "AB_ATTRIBUTE_ID", "CHAR_VALUE","DATE_VALUE","NUMBER_VALUE", "INT_VALUE", "ID_VALUE", "OBJECT_ROWID", "AB_ATTRIBUTERELATIONID", "DATE_NEW", "USER_NEW");
ret["Types"] = db.getColumnTypes("AB_ATTRIBUTERELATION", ret["Fields"]);
ret["Values"] = db.table(SqlBuilder.begin()
.select("AB_ATTRIBUTERELATION.OBJECT_TYPE, AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID, CHAR_VALUE, DATE_VALUE, NUMBER_VALUE, INT_VALUE, ID_VALUE, -1, -1, '', ''")
.from("AB_ATTRIBUTERELATION")
.join("AB_ATTRIBUTEUSAGE", " AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID")
.where(condition
.andPrepare("AB_ATTRIBUTERELATION.OBJECT_ROWID", pImportDefID)
.and("AB_ATTRIBUTERELATION.OBJECT_TYPE = 'Leadimport'")
).build());
return ret;
let fields = ["OBJECT_TYPE", "AB_ATTRIBUTE_ID", "CHAR_VALUE","DATE_VALUE","NUMBER_VALUE", "INT_VALUE", "ID_VALUE", "OBJECT_ROWID", "AB_ATTRIBUTERELATIONID", "DATE_NEW", "USER_NEW"];
return {
Fields: fields,
Types: db.getColumnTypes("AB_ATTRIBUTERELATION", fields),
Values: newSelect("AB_ATTRIBUTERELATION.OBJECT_TYPE, AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID, CHAR_VALUE, DATE_VALUE, NUMBER_VALUE, INT_VALUE, ID_VALUE, -1, -1, '', ''")
.from("AB_ATTRIBUTERELATION")
.join("AB_ATTRIBUTEUSAGE", "AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID")
.where("AB_ATTRIBUTERELATION.OBJECT_ROWID", pImportDefID)
.and("AB_ATTRIBUTERELATION.OBJECT_TYPE = 'Leadimport'")
.table()
};
}
/*
* Checks and validates the COUNTRY
* If the lenght of the COUNTRY is 2 (e. g. DE) then DE
* If the lenght of the COUNTRY is 3 (e. g. DEU) then DE
* If the lenght of the COUNTRY is more then 3 (e. g. Germany) then DE
* If there is no COUNTRY then DE
*
* @param {String} pValue req the COUNTRY
* Checks if the COUNTRY is a valid one.
* The value is checked against ISO2, ISO3 and NAME_LATIN
*
* @param {String} pCountry req the COUNTRY
*
* @return {String} validated COUNTRY
* @return {String} validated COUNTRY as ISO2, Default is "DE".
*/
LeadImportUtils.checkCountry = function( pValue )
LeadImportUtils.checkCountry = function(pCountry)
{
var ret = "";
if (pValue.length == 2)
{
ret = db.cell(SqlCondition.begin()
.andPrepare("AB_COUNTRYINFO.ISO2", pValue)
.buildSql("select ISO2 from AB_COUNTRYINFO", "1=2"));
}
else
if (pValue.length == 3)
{
ret = db.cell(SqlCondition.begin()
.andPrepare("AB_COUNTRYINFO.ISO3", pValue)
.buildSql("select ISO2 from AB_COUNTRYINFO", "1=2"));
}
else
if (pValue.length > 3)
{
ret = db.cell(SqlCondition.begin()
.andPrepare("AB_COUNTRYINFO.NAME_LATIN", pValue)
.buildSql("select ISO2 from AB_COUNTRYINFO", "1=2"));
}
if ( ret == "") ret = "DE";
return ret;
var iso2 = newSelect("MAX(ISO2)") // normally there should be only one so MAX is only to be safe here...
.from("AB_COUNTRYINFO")
.where("AB_COUNTRYINFO.ISO2", pCountry)
.or("AB_COUNTRYINFO.ISO3", pCountry)
.or("AB_COUNTRYINFO.NAME_LATIN", pCountry)
.cell();
return iso2 ? iso2 : "DE";
}
/*
* Checks and validates the LANGUAGE
* If the lenght of the LANGUAGE is 2 (e. g. de) then deu
* If the lenght of the LANGUAGE is 3 (e. g. deu) then deu
* If the lenght of the LANGUAGE is more then 3 (e. g. German) then deu
* If there is no LANGUAGE then deu
* Checks if the LANGUAGE is a valid one.
* The value is checked against ISO2, ISO3 and NAME_LATIN
*
* @param {String} pValue req the LANGUAGE
* @param {String} pLanguage req the LANGUAGE
*
* @return {String} validated LANGUAGE
* @return {String} validated LANGUAGE as ISO3. Default is "deu".
*/
LeadImportUtils.checkISOLanguage = function(pValue)
LeadImportUtils.checkISOLanguage = function(pLanguage)
{
var ret = "";
if (pValue.length == 2)
{
ret = db.cell(SqlCondition.begin()
.andPrepare("AB_LANGUAGE.ISO2", pValue)
.buildSql("select ISO3 from AB_LANGUAGE", "1=2"));
}
else
if (pValue.length == 3)
{
ret = db.cell(SqlCondition.begin()
.andPrepare("AB_LANGUAGE.ISO3", pValue)
.buildSql("select ISO3 from AB_LANGUAGE", "1=2"));
}
else
if (pValue.length > 3)
{
ret = db.cell(SqlCondition.begin()
.andPrepare("AB_LANGUAGE.NAME_LATIN", pValue)
.buildSql("select ISO3 from AB_LANGUAGE", "1=2"));
}
if (ret == "") ret = "deu";
var iso3 = newSelect("MAX(ISO3)") // normally there should be only one so MAX is only to be safe here...
.from("AB_LANGUAGE")
.where("AB_LANGUAGE.ISO2", pLanguage)
.or("AB_LANGUAGE.ISO3", pLanguage)
.or("AB_LANGUAGE.NAME_LATIN", pLanguage)
.cell();
return ret;
return iso3 ? iso3 : "deu";
}
......@@ -847,8 +799,8 @@ LeadImportUtils.scanLeadDups = function(pAllContactData)
var leadID = "";
var toUpdate = [];
var updDupVals = [];
var persObj =[];
var orgObj =[];
var persObj = {};
var orgObj = {};
for(let pLeadID in pAllContactData)
{
......@@ -859,8 +811,7 @@ LeadImportUtils.scanLeadDups = function(pAllContactData)
leadID = pLeadID;
persObj = pAllContactData[pLeadID][0];//personData
orgObj = pAllContactData[pLeadID][1];//organisationData
if(orgObj != undefined && Object.keys(orgObj).length > 0)//checks if there is an ORGANISATIONDUPLICATE
{
let scanResultsOrg = DuplicateScannerUtils.ScanForDuplicates("OrganisationDuplicates", "Organisation_entity", orgObj, null);
......@@ -889,7 +840,7 @@ LeadImportUtils.scanLeadDups = function(pAllContactData)
updDupVals = [dupStatus];
toUpdate.push([dupUpdateLeadTable, ["DUPSTATUS"], null, updDupVals, "LEADID = '" + leadID + "'"]);
toUpdate.push([dupUpdateLeadTable, ["DUPSTATUS"], null, updDupVals, newWhere([dupUpdateLeadTable, "LEADID"], leadID).build()]);
}
db.updates(toUpdate);//update Leads with the new status
}
......@@ -1030,12 +981,14 @@ ContactInfoUtils.getGender = function(pLeadValues)
*/
ContactInfoUtils.getSalutation = function(pLeadValues, pIsoLanguage)
{
// TODO: use getRows
if ( pLeadValues["SALUTATION"] != undefined && pLeadValues["SALUTATION"] != "" )
{
var salutation = db.array(db.COLUMN, SqlCondition.begin()
.andPrepare("SALUTATION.ISOLANGUAGE", pIsoLanguage)
.and("SALUTATION.SALUTATION is not null")
.buildSql("select distinct SALUTATION from SALUTATION", "1=2"));
var salutation = newSelect("distinct SALUTATION")
.from("SALUTATION")
.where("SALUTATION.ISOLANGUAGE", pIsoLanguage)
.and("SALUTATION.SALUTATION is not null")
.arrayColumn();
for (let i = 0; i < salutation.length; i++)
{
......@@ -1055,12 +1008,15 @@ ContactInfoUtils.getSalutation = function(pLeadValues, pIsoLanguage)
*/
ContactInfoUtils.getTitle = function(pLeadValues, pIsoLanguage)
{
// TODO: use getRows
if ( pLeadValues["TITLE"] != undefined && pLeadValues["TITLE"] != "" )
{
var title = db.array(db.COLUMN, SqlCondition.begin()
.andPrepare("SALUTATION.ISOLANGUAGE", pIsoLanguage)
.and("SALUTATION.TITLE is not null")
.buildSql("select distinct TITLE from SALUTATION", "1=2"));
var title = newSelect("distinct TITLE")
.from("SALUTATION")
.where("SALUTATION.ISOLANGUAGE", pIsoLanguage)
.and("SALUTATION.TITLE is not null")
.arrayColumn();
for (let i = 0; i < title.length; i++)
{
if(pLeadValues["TITLE"].trim() == title[i].trim())
......
......@@ -153,21 +153,20 @@ rows = eMath.subInt(rows, errorCount);//datasetcount - errors = inserts
var updTable = "LEADIMPORT";
var updFields =["IMPORT_DATE", "DATE_EDIT", "USER_EDIT", "STATUS"];
var updTypes = db.getColumnTypes(updTable, updFields);
var updVals = [ImportDate, currDate, user, $KeywordRegistry.importStatus$transfered()];
var insTable = "LEADLOG";
var insFields =["LEADLOGID", "ROWSINSERTED", "IMPORTERRORS", "LEADIMPORT_ID", "IMPORTSOURCE", "USER_NEW", "DATE_NEW"];
var insTypes = db.getColumnTypes(insTable, insFields);
var logTable = "LEADLOG";
var logFields =["LEADLOGID", "ROWSINSERTED", "IMPORTERRORS", "LEADIMPORT_ID", "IMPORTSOURCE", "USER_NEW", "DATE_NEW"];
var logVals = [util.getNewUUID(), rows, errorCount, importdefid, source, user, currDate];
var insVals = [util.getNewUUID(), rows, errorCount, importdefid, source, user, currDate];
db.insertData(insTable, insFields, insTypes, insVals);
db.updateData(updTable, updFields, updTypes, updVals, "LEADIMPORTID = '" + importdefid + "'");
db.deleteData("LEADTEMP", "ROW_ID = '" + importdefid + "'");//delete existing temp data
db.insertData(logTable, logFields, null, logVals);
newWhere("LEADIMPORT.LEADIMPORTID", importdefid)
.updateData(true, updTable, updFields, null, updVals);
newWhere("LEADTEMP.ROW_ID", importdefid)
.deleteData(true, "LEADTEMP");//delete existing temp data
if(exeptions != "")//insert error document
db.insertBinary("LEADIMPORT", "DOCUMENT", assignmentRowId,
db.insertBinary("LEADLOG", "ERRORLOG", logVals[0],
"", util.encodeBase64String(exeptions, "UTF-8"), "Error-Log " + source + " " + datetime.toDate(currDate, "dd.MM.yyyy HH:mm") , "", "", SqlUtils.getBinariesAlias());
if (userId)// if there is an user - show a notification to this user when the import is complete
......
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