diff --git a/entity/Leadimport_entity/recordcontainers/db/onDBInsert.js b/entity/Leadimport_entity/recordcontainers/db/onDBInsert.js index 876e7ba14138d02e923f98395df187fece74ea1e..9c821ae17443aa994dc984faed821d9189c025e2 100644 --- a/entity/Leadimport_entity/recordcontainers/db/onDBInsert.js +++ b/entity/Leadimport_entity/recordcontainers/db/onDBInsert.js @@ -22,7 +22,7 @@ if(bindata != '' && filename != '') if (mimeType == "application/vnd.ms-excel") { SingleBinaryUtils.insertMainDocument("LEADIMPORT", "", assignmentRowId, bindata, filename, ""); - LoadImportFile(vars.get("$field.bindata"), fieldSep, fieldLimit, recordSep, assignmentRowId); + LeadImportUtils.loadImportFile(vars.get("$field.bindata"), fieldSep, fieldLimit, recordSep, assignmentRowId); } } diff --git a/entity/Leadimport_entity/recordcontainers/db/onDBUpdate.js b/entity/Leadimport_entity/recordcontainers/db/onDBUpdate.js index 5f7c2dc29c2209bd73b1f43557d6b7be47c111cb..cd9205f937f53c476accda7ce1f0eebae0a58cef 100644 --- a/entity/Leadimport_entity/recordcontainers/db/onDBUpdate.js +++ b/entity/Leadimport_entity/recordcontainers/db/onDBUpdate.js @@ -26,7 +26,7 @@ if(bindata != '' && filename != '') .buildSql("select ID from ASYS_BINARIES", "1=2"), SqlUtils.getBinariesAlias()); db.updateBinary(binId, "", bindata, filename, "", "MAINDOCUMENT", SqlUtils.getBinariesAlias()); - LoadImportFile(vars.get("$field.bindata"), fieldSep, fieldLimit, recordSep, assignmentRowId, true, vars.get("$param.LeadimportNewFile_param")); + LeadImportUtils.loadImportFile(vars.get("$field.bindata"), fieldSep, fieldLimit, recordSep, assignmentRowId, true, vars.get("$param.LeadimportNewFile_param")); } } diff --git a/process/Leadimport_lib/process.js b/process/Leadimport_lib/process.js index f0ccc50866953215ba0dbcdc947e7bc5281c0f4e..857d35cf48a8f7867f69beb182cf299da455de3d 100644 --- a/process/Leadimport_lib/process.js +++ b/process/Leadimport_lib/process.js @@ -82,7 +82,7 @@ LeadImportUtils.leadTempColumns = function() * * @return {integer} rows the number of rows which have been inserted */ -function LoadImportFile(pFile, pFieldSep, pFieldLimit, pRecordSep, pLeadImportId, pUpdate, pNewFile) +LeadImportUtils.loadImportFile = function(pFile, pFieldSep, pFieldLimit, pRecordSep, pLeadImportId, pUpdate, pNewFile) { var rows = 0; var toInsert = []; @@ -150,9 +150,9 @@ function LoadImportFile(pFile, pFieldSep, pFieldLimit, pRecordSep, pLeadImportId * and the organisationobject for duplicate checking in the third place * */ -function ImportData(pDataFields, pDataTypes, pFieldDef, pFieldValues, pImportDefID, pAttrObject, pSource, pUser, pDate ) +LeadImportUtils.importData = function(pDataFields, pDataTypes, pFieldDef, pFieldValues, pImportDefID, pAttrObject, pSource, pUser, pDate ) { - var LeadValues = SetValues(pDataFields["LEAD"], pFieldDef, pFieldValues); // set the Lead values + var LeadValues = LeadImportUtils.setValues(pDataFields["LEAD"], pFieldDef, pFieldValues); // set the Lead values var orgid = ""; var persid = ""; @@ -169,7 +169,7 @@ function ImportData(pDataFields, pDataTypes, pFieldDef, pFieldValues, pImportDef if (LeadValues["NAME"] != "")//only if Organame is filled { orgObjID = "Organisation";//for attribute - orgRet = InsertOrg(pDataFields, pDataTypes, pFieldDef, pFieldValues, pUser, pDate); + orgRet = LeadImportUtils.insertOrg(pDataFields, pDataTypes, pFieldDef, pFieldValues, pUser, pDate); orgid = orgRet[0]; orgContactId = orgRet[1]; @@ -177,22 +177,22 @@ function ImportData(pDataFields, pDataTypes, pFieldDef, pFieldValues, pImportDef if(orgRet[3])//not a new organisation { - InsertAttr(pDataFields, pDataTypes, pFieldDef, LeadValues, orgContactId, orgObjID, pUser, pDate); - InsertComm(pDataFields, pDataTypes, LeadValues, orgContactId, pUser, pDate); + LeadImportUtils.insertAttr(pDataFields, pDataTypes, pFieldDef, LeadValues, orgContactId, orgObjID, pUser, pDate); + LeadImportUtils.insertComm(pDataFields, pDataTypes, LeadValues, orgContactId, pUser, pDate); } } //------create person if (LeadValues[ "LASTNAME" ] != "")//only if lastname is filled { persObjID = "Person";//for attribute - persRet = InsertPers(pDataFields, pDataTypes, pFieldDef, pFieldValues, orgid, LeadValues, pUser, pDate); + persRet = LeadImportUtils.insertPers(pDataFields, pDataTypes, pFieldDef, pFieldValues, orgid, LeadValues, pUser, pDate); persid = persRet[0]; persContactId = persRet[1]; persForDubCheck = persRet[2]; - InsertAttr(pDataFields, pDataTypes, pFieldDef, LeadValues, persContactId, persObjID , pUser, pDate); - InsertComm(pDataFields, pDataTypes, LeadValues, persContactId, pUser, pDate); + LeadImportUtils.insertAttr(pDataFields, pDataTypes, pFieldDef, LeadValues, persContactId, persObjID , pUser, pDate); + LeadImportUtils.insertComm(pDataFields, pDataTypes, LeadValues, persContactId, pUser, pDate); } //------create activitys for organisation and person var activityData = @@ -212,9 +212,9 @@ function ImportData(pDataFields, pDataTypes, pFieldDef, pFieldValues, pImportDef LeadValues["ORGANISATION_ID"] = orgid; LeadValues["PERSON_ID"] = persid; - var leadId = InsertTable(pDataFields, pDataTypes ,LeadValues, "LEAD", pUser, pDate);//inserts the LEAD dataset + var leadId = LeadImportUtils.insertTable(pDataFields, pDataTypes ,LeadValues, "LEAD", pUser, pDate);//inserts the LEAD dataset - InsertLeadAttr(pAttrObject, orgid, persid, LeadValues["DATE_NEW"], pUser, pDate, (orgRet && orgRet.length >= 4 && orgRet[3])); + LeadImportUtils.insertLeadAttr(pAttrObject, orgid, persid, LeadValues["DATE_NEW"], pUser, pDate, (orgRet && orgRet.length >= 4 && orgRet[3])); return [leadId, persForDubCheck, orgsForDubCheck]; } @@ -227,7 +227,7 @@ function ImportData(pDataFields, pDataTypes, pFieldDef, pFieldValues, pImportDef * * @return {[]} new Array */ -function AddArray(pArray, pAddArray) +LeadImportUtils.addArray = function(pArray, pAddArray) { var NewArray = new Array() for(var i = 0; i < pArray.length; i++) @@ -243,7 +243,7 @@ function AddArray(pArray, pAddArray) * * @return {Object} Object with columns */ -function GetDataFields(pDataTables) +LeadImportUtils.getDataFields = function(pDataTables) { var DataFields = new Object(); for (var i = 0; i < pDataTables.length; i++) @@ -267,7 +267,7 @@ function GetDataFields(pDataTables) * * @return {Object} object of the column types */ -function GetDataTypes(pDataFields, pDataTables) +LeadImportUtils.getDataTypes = function(pDataFields, pDataTables) { var DataTypes = new Object(); for (var i = 0; i < pDataTables.length; i++) @@ -287,7 +287,7 @@ function GetDataTypes(pDataFields, pDataTables) * * @return {Object} Object with the assigned values */ -function SetValues (pFields, pFieldDef, pFieldValues) +LeadImportUtils.setValues = function(pFields, pFieldDef, pFieldValues) { var DataValues = new Object(); var i; @@ -319,7 +319,7 @@ function SetValues (pFields, pFieldDef, pFieldValues) * * @return {[]} ImportFieldDef */ -function getImportFieldDef( pID ) +LeadImportUtils.getImportFieldDef = function( pID ) { var condition = SqlCondition.begin(); @@ -373,7 +373,7 @@ function getImportFieldDef( pID ) * * @return {void} */ -function InsertAttr(pDataFields, pDataTypes, pFieldDef, pLeadValues, pContactId, pObjectID, pUser, pDate) +LeadImportUtils.insertAttr = function(pDataFields, pDataTypes, pFieldDef, pLeadValues, pContactId, pObjectID, pUser, pDate) { var Fields = pDataFields["AB_ATTRIBUTERELATION"]; @@ -412,7 +412,7 @@ function InsertAttr(pDataFields, pDataTypes, pFieldDef, pLeadValues, pContactId, if (value != "" && type != "") { DataValues[type] = value; - InsertTable(pDataFields, pDataTypes, DataValues, "AB_ATTRIBUTERELATION", pUser, pDate); + LeadImportUtils.insertTable(pDataFields, pDataTypes, DataValues, "AB_ATTRIBUTERELATION", pUser, pDate); } } } @@ -430,7 +430,7 @@ function InsertAttr(pDataFields, pDataTypes, pFieldDef, pLeadValues, pContactId, * * @return {void} */ -function InsertComm(pDataFields, pDataTypes, pLeadValues, contactId, pUser, pDate) +LeadImportUtils.insertComm = function(pDataFields, pDataTypes, pLeadValues, contactId, pUser, pDate) { var Fields = pDataFields["COMMUNICATION"]; var commMedium = KeywordUtils.getEntryNamesAndIdsByContainer("CommunicationMedium"); @@ -451,7 +451,7 @@ function InsertComm(pDataFields, pDataTypes, pLeadValues, contactId, pUser, pDat DataValues[ "ADDR" ] = pLeadValues[medium];//e. g. +49 123 45678900 DataValues[ "ISSTANDARD" ] = 1;//insert only standard communication data DataValues[ "COMMUNICATIONID" ] = ""; - InsertTable(pDataFields, pDataTypes, DataValues, "COMMUNICATION", pUser, pDate); + LeadImportUtils.insertTable(pDataFields, pDataTypes, DataValues, "COMMUNICATION", pUser, pDate); } } } @@ -466,34 +466,34 @@ function InsertComm(pDataFields, pDataTypes, pLeadValues, contactId, pUser, pDat * @param {String} pUser req the importuser * @param {String} pDate req the importdate * -* @return {String[]} ( organisationId, contactId, duplicateMapping, true/false) +* @return {String[]} [organisationId, contactId, duplicateMapping, true/false] */ -function InsertOrg(pDataFields, pDataTypes, pFieldDef, pFieldValues, pUser, pDate) +LeadImportUtils.insertOrg = function(pDataFields, pDataTypes, pFieldDef, pFieldValues, pUser, pDate) { //Organisation - var OrgValues = SetValues(pDataFields["ORGANISATION"], pFieldDef, pFieldValues); + var OrgValues = LeadImportUtils.setValues(pDataFields["ORGANISATION"], pFieldDef, pFieldValues); var entityFieldValues = []; var ids = CheckDup(OrgValues, "ORGANISATION");//checks if there is already an organisation like this if (ids.length == 0)//there is no organisation like this { - var orgid = InsertTable(pDataFields, pDataTypes, OrgValues, "ORGANISATION", pUser, pDate); + var orgid = LeadImportUtils.insertTable(pDataFields, pDataTypes, OrgValues, "ORGANISATION", pUser, pDate); //contact - var ContactValues = SetValues( pDataFields["CONTACT"], pFieldDef, pFieldValues ); + var ContactValues = LeadImportUtils.setValues( pDataFields["CONTACT"], pFieldDef, pFieldValues ); ContactValues["STATUS"] = "CONTACTSTATACTIVE"; ContactValues["ORGANISATION_ID"] = orgid; ContactValues["ADDRESS_ID"] = util.getNewUUID(); ContactValues["ISOLANGUAGE"] = ""; - var contactId = InsertTable(pDataFields, pDataTypes, ContactValues, "CONTACT", pUser, pDate); + var contactId = LeadImportUtils.insertTable(pDataFields, pDataTypes, ContactValues, "CONTACT", pUser, pDate); //address - var AddrValues = SetValues(pDataFields["ADDRESS"], pFieldDef, pFieldValues ); + var AddrValues = LeadImportUtils.setValues(pDataFields["ADDRESS"], pFieldDef, pFieldValues ); AddrValues["ADDRESSID"] = ContactValues["ADDRESS_ID"]; AddrValues["ADDR_TYPE"] = "OFFICEADDR"; AddrValues["CONTACT_ID"] = contactId; - InsertTable(pDataFields, pDataTypes, AddrValues, "ADDRESS", pUser, pDate); + LeadImportUtils.insertTable(pDataFields, pDataTypes, AddrValues, "ADDRESS", pUser, pDate); entityFieldValues = getEntityFieldsOrg(OrgValues, ContactValues, AddrValues); @@ -518,40 +518,40 @@ function InsertOrg(pDataFields, pDataTypes, pFieldDef, pFieldValues, pUser, pDa * * @return {String []} ( personId, contactId, duplicateMapping) */ -function InsertPers(pDataFields, pDataTypes, pFieldDef, pFieldValues, pOrgId, pLeadValues, pUser, pDate) +LeadImportUtils.insertPers = function(pDataFields, pDataTypes, pFieldDef, pFieldValues, pOrgId, pLeadValues, pUser, pDate) { var isoLanguage = checkISOLanguage(pLeadValues["ISOLANGUAGE"]); //Person - var PersValues = SetValues(pDataFields["PERSON"], pFieldDef, pFieldValues); - PersValues["TITLE"] = GetContactInformation.getTitle(pLeadValues, isoLanguage); - PersValues["SALUTATION"] = GetContactInformation.getSalutation(pLeadValues, isoLanguage); - PersValues["GENDER"] = GetContactInformation.getGender(pLeadValues); - var persid = InsertTable(pDataFields, pDataTypes, PersValues, "PERSON", pUser, pDate); + var PersValues = LeadImportUtils.setValues(pDataFields["PERSON"], pFieldDef, pFieldValues); + PersValues["TITLE"] = ContactInfoUtils.getTitle(pLeadValues, isoLanguage); + PersValues["SALUTATION"] = ContactInfoUtils.getSalutation(pLeadValues, isoLanguage); + PersValues["GENDER"] = ContactInfoUtils.getGender(pLeadValues); + var persid = LeadImportUtils.insertTable(pDataFields, pDataTypes, PersValues, "PERSON", pUser, pDate); //contact - var ContactValues = SetValues(pDataFields["CONTACT"], pFieldDef, pFieldValues); + var ContactValues = LeadImportUtils.setValues(pDataFields["CONTACT"], pFieldDef, pFieldValues); ContactValues["STATUS"] = "CONTACTSTATACTIVE";//only insert active persons ContactValues["PERSON_ID"] = persid; ContactValues["ADDRESS_ID"] = util.getNewUUID(); - ContactValues["DEPARTMENT"] = GetContactInformation.getContactDepartment(pLeadValues); - ContactValues["CONTACTROLE"] = GetContactInformation.getContactRole(pLeadValues); - ContactValues["CONTACTPOSITION"] = GetContactInformation.getContactPosition(pLeadValues); - ContactValues["CONTACTPOSITION"] = GetContactInformation.getContactPosition(pLeadValues); + ContactValues["DEPARTMENT"] = ContactInfoUtils.getContactDepartment(pLeadValues); + ContactValues["CONTACTROLE"] = ContactInfoUtils.getContactRole(pLeadValues); + ContactValues["CONTACTPOSITION"] = ContactInfoUtils.getContactPosition(pLeadValues); + ContactValues["CONTACTPOSITION"] = ContactInfoUtils.getContactPosition(pLeadValues); if (pOrgId == "")//private ContactValues["ORGANISATION_ID"] = 0; else ContactValues["ORGANISATION_ID"] = pOrgId; - var contactId = InsertTable(pDataFields, pDataTypes, ContactValues, "CONTACT", pUser, pDate); + var contactId = LeadImportUtils.insertTable(pDataFields, pDataTypes, ContactValues, "CONTACT", pUser, pDate); //Address - var AddrValues = SetValues(pDataFields["ADDRESS"], pFieldDef, pFieldValues); + var AddrValues = LeadImportUtils.setValues(pDataFields["ADDRESS"], pFieldDef, pFieldValues); AddrValues["ADDRESSID"] = ContactValues["ADDRESS_ID"]; AddrValues["ADDR_TYPE"] = "HOMEADDR"; AddrValues["CONTACT_ID"] = contactId; - InsertTable(pDataFields, pDataTypes, AddrValues, "ADDRESS", pUser, pDate); + LeadImportUtils.insertTable(pDataFields, pDataTypes, AddrValues, "ADDRESS", pUser, pDate); var entityFieldValues = getEntityFieldsPers(PersValues, ContactValues, AddrValues); @@ -570,7 +570,7 @@ function InsertPers(pDataFields, pDataTypes, pFieldDef, pFieldValues, pOrgId, p * * @return {String} Tableid */ -function InsertTable(pDataFields, pDataTypes, pValues, pTable, pUser, pDate) +LeadImportUtils.insertTable = function(pDataFields, pDataTypes, pValues, pTable, pUser, pDate) { var Fields = pDataFields[pTable]; var Types = pDataTypes[pTable]; @@ -627,7 +627,7 @@ function InsertTable(pDataFields, pDataTypes, pValues, pTable, pUser, pDate) * * @return {void} */ -function InsertLeadAttr (pAttrObject, orgid, persid, pUser, pDate, pInsertOrgAttr) +LeadImportUtils.insertLeadAttr = function(pAttrObject, orgid, persid, pUser, pDate, pInsertOrgAttr) { for ( var i = 0; i < pAttrObject["Values"].length; i++ ) { @@ -669,7 +669,7 @@ function InsertLeadAttr (pAttrObject, orgid, persid, pUser, pDate, pInsertOrgAtt * * @return {void} */ -function sqlInsertAttr(pAttrObject, pAttrValues, pUser, pDate) +LeadImportUtils.sqlInsertAttr = function(pAttrObject, pAttrValues, pUser, pDate) { pAttrValues[8] = util.getNewUUID(); pAttrValues[9] = pUser; @@ -685,7 +685,7 @@ function sqlInsertAttr(pAttrObject, pAttrValues, pUser, pDate) * * @return {Object} object for the leadattribute */ -function getLeadAttr(pImportDefID) +LeadImportUtils.getLeadAttr = function(pImportDefID) { var ret = new Object(); var condition = SqlCondition.begin(); @@ -716,7 +716,7 @@ function getLeadAttr(pImportDefID) * * @return {String} validated COUNTRY */ -function checkCountry( pValue ) +LeadImportUtils.checkCountry = function( pValue ) { var ret = ""; if (pValue.length == 2) @@ -757,7 +757,7 @@ function checkCountry( pValue ) * * @return {String} validated LANGUAGE */ -function checkISOLanguage(pValue) +LeadImportUtils.checkISOLanguage = function(pValue) { var ret = ""; @@ -787,12 +787,150 @@ function checkISOLanguage(pValue) return ret; } + +/* +* mapping for the duplicate search for ORGANISATION +* maps the DB-Field to the ENTITY-Field +* +* @param {Object} pOrgDataFields the the ORGANISATION values; +* @param {Object} pContactDataFields the CONTACT values; +* @param {Object} pAddressDataFields the ADDRESS values; +* +* @return {Object} the mapping +*/ +LeadImportUtils.getEntityFieldsOrg = function(pOrgDataFields, pContactDataFields, pAddressDataFields) +{ + var EntityOrgFieldObj = {}; + EntityOrgFieldObj["CONTACTID"] = pContactDataFields["CONTACTID"]; + EntityOrgFieldObj["CUSTOMERCODE"] = pOrgDataFields["CUSTOMERCODE"]; + EntityOrgFieldObj["NAME"] = pOrgDataFields["NAME"]; + EntityOrgFieldObj["INFO"] = pOrgDataFields["INFO"]; + + return EntityOrgFieldObj; +} + +/* +* mapping for the duplicate search for PERSON +* maps the DB-Field to the ENTITY-Field +* +* @param {Object} pPersDataFields the the PERSON values; +* @param {Object} pContactDataFields the CONTACT values; +* @param {Object} pAddressDataFields the ADDRESS values; +* +* @return {Object} the mapping +*/ +LeadImportUtils.getEntityFieldsPers = function(pPersDataFields, pContactDataFields, pAddressDataFields) +{ + var EntityPersFieldObj = {}; + EntityPersFieldObj["CONTACTID"] = pContactDataFields["CONTACTID"]; + EntityPersFieldObj["FIRSTNAME"] = pPersDataFields["FIRSTNAME"]; + EntityPersFieldObj["LASTNAME"] = pPersDataFields["LASTNAME"]; + EntityPersFieldObj["SALUTATION"] = pPersDataFields["SALUTATION"]; + EntityPersFieldObj["TITLE"] = pPersDataFields["TITLE"]; + EntityPersFieldObj["DATEOFBIRTH"] = pPersDataFields["DATEOFBIRTH"]; + EntityPersFieldObj["GENDER"] = pPersDataFields["GENDER"]; + + return EntityPersFieldObj; +} + +/* +* checks if there are dups for the LEAD and updates the status of it +* +* @param {Object} pAllContactData the contactData; + +* @return {void} +*/ +LeadImportUtils.scanLeadDups = function(pAllContactData) +{ + var dupUpdateLeadTable = "LEAD"; + + var leadID = ""; + var toUpdate = []; + var updDupVals = []; + var persObj =[]; + var orgObj =[]; + + for(let pLeadID in pAllContactData) + { + var dupStatus = "NODUP"; + dupOrg = false; + dupPers = false; + + 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); + if(scanResultsOrg != null && scanResultsOrg.length > 0) + { + let insertCountOrg = DuplicateScannerUtils.CacheNewScanResults(orgObj["CONTACTID"], scanResultsOrg, "Organisation_entity"); + dupOrg = true; + } + } + if(persObj != undefined && Object.keys(persObj).length > 0)//checks if there is an PERSONDUPLICATE + { + let scanResultsPers = DuplicateScannerUtils.ScanForDuplicates("PersonDuplicates", "Person_entity", persObj, null); + if(scanResultsPers != null && scanResultsPers.length > 0) + { + let insertCountPers = DuplicateScannerUtils.CacheNewScanResults(persObj["CONTACTID"], scanResultsPers, "Person_entity"); + dupPers = true; + } + } + + if(dupOrg && dupPers) + dupStatus = "ORGPERSDUP";//organisation and person duplicate + else if(dupOrg) + dupStatus = "ORGDUP";//organisation duplicate + else if(dupPers) + dupStatus = "PERSDUP";//person duplicate + + updDupVals = [dupStatus]; + + toUpdate.push([dupUpdateLeadTable, ["DUPSTATUS"], null, updDupVals, "LEADID = '" + leadID + "'"]); + } + db.updates(toUpdate);//update Leads with the new status +} + +/* +* Checks if there is already an ORGANISATION +* if there is one then return the ids of it +* else return no ids +* +* @param {Object} pLeadValues req values of the Lead + +* @return {[]} [ORGANISATIONID, CONTACTID] +*/ +LeadImportUtils.CheckDup = function( pLeadValues) +{ + // search whether the organisation already exists + var query = newSelect("ORGANISATIONID, CONTACTID") + .from("ORGANISATION") + .join("CONTACT", "ORGANISATIONID = CONTACT.ORGANISATION_ID") + .join("ADDRESS", "ADDRESSID = ADDRESS_ID"); + + var fields; + + fields = ["ORGANISATION.NAME", "ADDRESS.COUNTRY", "ADDRESS.ADDRESS", "ADDRESS.CITY", "ADDRESS.ZIP", "ADDRESS.COUNTRY"]; + query.and("PERSON_ID is null"); + + for (var i = 0; i < fields.length; i++) + { + query.and(fields[i], pLeadValues[ fields[i].split(".")[1] ].replace(new RegExp("'", "g"),"''")); + query.and(fields[i] + " is not null"); + } + + return query.array(); +} + /** * a static Utility class for contact infos * * @class */ -function GetContactInformation() {} +function ContactInfoUtils() {} /* * checks if there is a department for the contact @@ -801,7 +939,7 @@ function GetContactInformation() {} * * @return {String} the department */ -GetContactInformation.getContactDepartment = function(pLeadValues) +ContactInfoUtils.getContactDepartment = function(pLeadValues) { if ( pLeadValues["DEPARTMENT"] != undefined && pLeadValues["DEPARTMENT"] != "" ) { @@ -823,7 +961,7 @@ GetContactInformation.getContactDepartment = function(pLeadValues) * * @return {String} the position */ -GetContactInformation.getContactPosition = function(pLeadValues) +ContactInfoUtils.getContactPosition = function(pLeadValues) { if ( pLeadValues["CONTACTPOSITION"] != undefined && pLeadValues["CONTACTPOSITION"] != "" ) { @@ -845,7 +983,7 @@ GetContactInformation.getContactPosition = function(pLeadValues) * * @return {String} the contactRole */ -GetContactInformation.getContactRole = function(pLeadValues) +ContactInfoUtils.getContactRole = function(pLeadValues) { if ( pLeadValues["CONTACTROLE"] != undefined && pLeadValues["CONTACTROLE"] != "" ) { @@ -867,7 +1005,7 @@ GetContactInformation.getContactRole = function(pLeadValues) * * @return {String} the gender */ -GetContactInformation.getGender = function(pLeadValues) +ContactInfoUtils.getGender = function(pLeadValues) { if ( pLeadValues["GENDER"] != undefined && pLeadValues["GENDER"] != "" ) { @@ -890,7 +1028,7 @@ GetContactInformation.getGender = function(pLeadValues) * * @return {String} the salutation */ -GetContactInformation.getSalutation = function(pLeadValues, pIsoLanguage) +ContactInfoUtils.getSalutation = function(pLeadValues, pIsoLanguage) { if ( pLeadValues["SALUTATION"] != undefined && pLeadValues["SALUTATION"] != "" ) { @@ -915,7 +1053,7 @@ GetContactInformation.getSalutation = function(pLeadValues, pIsoLanguage) * * @return {String} the title */ -GetContactInformation.getTitle = function(pLeadValues, pIsoLanguage) +ContactInfoUtils.getTitle = function(pLeadValues, pIsoLanguage) { if ( pLeadValues["TITLE"] != undefined && pLeadValues["TITLE"] != "" ) { @@ -930,141 +1068,4 @@ GetContactInformation.getTitle = function(pLeadValues, pIsoLanguage) } } return ""; -}; - -/* -* mapping for the duplicate search for ORGANISATION -* maps the DB-Field to the ENTITY-Field -* -* @param {Object} pOrgDataFields the the ORGANISATION values; -* @param {Object} pContactDataFields the CONTACT values; -* @param {Object} pAddressDataFields the ADDRESS values; -* -* @return {Object} the mapping -*/ -function getEntityFieldsOrg(pOrgDataFields, pContactDataFields, pAddressDataFields) -{ - var EntityOrgFieldObj = {}; - EntityOrgFieldObj["CONTACTID"] = pContactDataFields["CONTACTID"]; - EntityOrgFieldObj["CUSTOMERCODE"] = pOrgDataFields["CUSTOMERCODE"]; - EntityOrgFieldObj["NAME"] = pOrgDataFields["NAME"]; - EntityOrgFieldObj["INFO"] = pOrgDataFields["INFO"]; - - return EntityOrgFieldObj; -} - -/* -* mapping for the duplicate search for PERSON -* maps the DB-Field to the ENTITY-Field -* -* @param {Object} pPersDataFields the the PERSON values; -* @param {Object} pContactDataFields the CONTACT values; -* @param {Object} pAddressDataFields the ADDRESS values; -* -* @return {Object} the mapping -*/ -function getEntityFieldsPers(pPersDataFields, pContactDataFields, pAddressDataFields) -{ - var EntityPersFieldObj = {}; - EntityPersFieldObj["CONTACTID"] = pContactDataFields["CONTACTID"]; - EntityPersFieldObj["FIRSTNAME"] = pPersDataFields["FIRSTNAME"]; - EntityPersFieldObj["LASTNAME"] = pPersDataFields["LASTNAME"]; - EntityPersFieldObj["SALUTATION"] = pPersDataFields["SALUTATION"]; - EntityPersFieldObj["TITLE"] = pPersDataFields["TITLE"]; - EntityPersFieldObj["DATEOFBIRTH"] = pPersDataFields["DATEOFBIRTH"]; - EntityPersFieldObj["GENDER"] = pPersDataFields["GENDER"]; - - return EntityPersFieldObj; -} - -/* -* checks if there are dups for the LEAD and updates the status of it -* -* @param {Object} pAllContactData the contactData; - -* @return {void} -*/ -function scanLeadDups(pAllContactData){ - - var dupUpdateLeadTable = "LEAD"; - - var leadID = ""; - var toUpdate = []; - var updDupVals = []; - var persObj =[]; - var orgObj =[]; - - for(let pLeadID in pAllContactData) - { - var dupStatus = "NODUP"; - dupOrg = false; - dupPers = false; - - 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); - if(scanResultsOrg != null && scanResultsOrg.length > 0) - { - let insertCountOrg = DuplicateScannerUtils.CacheNewScanResults(orgObj["CONTACTID"], scanResultsOrg, "Organisation_entity"); - dupOrg = true; - } - } - if(persObj != undefined && Object.keys(persObj).length > 0)//checks if there is an PERSONDUPLICATE - { - let scanResultsPers = DuplicateScannerUtils.ScanForDuplicates("PersonDuplicates", "Person_entity", persObj, null); - if(scanResultsPers != null && scanResultsPers.length > 0) - { - let insertCountPers = DuplicateScannerUtils.CacheNewScanResults(persObj["CONTACTID"], scanResultsPers, "Person_entity"); - dupPers = true; - } - } - - if(dupOrg && dupPers) - dupStatus = "ORGPERSDUP";//organisation and person duplicate - else if(dupOrg) - dupStatus = "ORGDUP";//organisation duplicate - else if(dupPers) - dupStatus = "PERSDUP";//person duplicate - - updDupVals = [dupStatus]; - - toUpdate.push([dupUpdateLeadTable, ["DUPSTATUS"], null, updDupVals, "LEADID = '" + leadID + "'"]); - } - db.updates(toUpdate);//update Leads with the new status -} - -/* -* Checks if there is already an ORGANISATION -* if there is one then return the ids of it -* else return no ids -* -* @param {Object} pLeadValues req values of the Lead - -* @return {[]} [ORGANISATIONID, CONTACTID] -*/ -function CheckDup( pLeadValues) -{ - // search whether the organisation already exists - var query = newSelect("ORGANISATIONID, CONTACTID") - .from("ORGANISATION") - .join("CONTACT", "ORGANISATIONID = CONTACT.ORGANISATION_ID") - .join("ADDRESS", "ADDRESSID = ADDRESS_ID"); - - var fields; - - fields = ["ORGANISATION.NAME", "ADDRESS.COUNTRY", "ADDRESS.ADDRESS", "ADDRESS.CITY", "ADDRESS.ZIP", "ADDRESS.COUNTRY"]; - query.and("PERSON_ID is null"); - - for (var i = 0; i < fields.length; i++) - { - query.and(fields[i], pLeadValues[ fields[i].split(".")[1] ].replace(new RegExp("'", "g"),"''")); - query.and(fields[i] + " is not null"); - } - - return query.array(); -} \ No newline at end of file +}; \ No newline at end of file diff --git a/process/importLead_serverProcess/process.js b/process/importLead_serverProcess/process.js index a1e3c5104afb7a44c421da7c76c40f62b2514077..bde3d74c070d7559450a83a319287e572336b24c 100644 --- a/process/importLead_serverProcess/process.js +++ b/process/importLead_serverProcess/process.js @@ -39,14 +39,14 @@ var DataFieldCount = data[0].length; // Attributes that should be created for Organisations and persons var AttrObject = getLeadAttr(importdefid); -var FieldDef = AddArray(ImportFieldDef, new Array(DataFieldCount++, "SOURCE", "")); +var FieldDef = LeadImportUtils.addArray(ImportFieldDef, new Array(DataFieldCount++, "SOURCE", "")); FieldDef.push(new Array(DataFieldCount++, "DATE_NEW", "")); // für Tabellen Felder und Typen ermitteln var DataTables = new Array("ORGANISATION", "PERSON", "CONTACT", "ADDRESS", "LEAD", "COMMUNICATION", "AB_ATTRIBUTERELATION"); -var DataFields = GetDataFields(DataTables); -var DataTypes = GetDataTypes(DataFields, DataTables); +var DataFields = LeadImportUtils.getDataFields(DataTables); +var DataTypes = LeadImportUtils.getDataTypes(DataFields, DataTables); // Check if a BUILDINGNO is declared var addressPos = getFieldPos(ImportFieldDef, "ADDRESS"); @@ -74,7 +74,7 @@ try for (; dsanz < data.length; dsanz++) { //iterate over the fielddefinitions and set the values - var impvalues = AddArray(data[dsanz], source); + var impvalues = LeadImportUtils.addArray(data[dsanz], source); impvalues.push(ImportDate); // if there is no BUILDINGNO the select it from the ADDRESS @@ -127,7 +127,7 @@ try try//import data { - var dupCheck = ImportData(DataFields, DataTypes, FieldDef, impvalues, importdefid, AttrObject, source, user, currDate); + var dupCheck = LeadImportUtils.importData(DataFields, DataTypes, FieldDef, impvalues, importdefid, AttrObject, source, user, currDate); allContactData[dupCheck[0]] = [dupCheck[1], dupCheck[2]]; //persObj, orgObj } @@ -173,7 +173,6 @@ if(exeptions != "")//insert error document if (userId)// if there is an user - show a notification to this user when the import is complete { var description = translate.withArguments("%0 leads imported, %1 errors", [rows, errorCount]); - logging.log(JSON.stringify([exeptions], null, "\t")) notification.addNotification(util.getNewUUID(), null, null, null, "LeadImport_Notification", notification.PRIO_NORMAL, 2, notification.STATE_UNSEEN, [userId], importName, description); }