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

ActiveDirectory import formatting fixes

parent f057fd67
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
......@@ -11,6 +11,8 @@ import("system.tools");
import("system.project");
import("ActiveDirectoryXml_lib");
//TODO: add comments to methods
var ColumnMetadataProvider = (function () {
var metadataInstance = {};
......@@ -104,7 +106,7 @@ LdapImporter.prototype.getLdapConfig = function()
LdapImporter.prototype.createSearchAction = function()
{
var ldapConfiguration = this.getLdapConfig();
var dataMappingKeys = Object.keys(this.dataMapping);//TODO: good/bad?
var dataMappingKeys = Object.keys(this.dataMapping);
var attributeArray = dataMappingKeys.map(function (key) {
return new LDAPAttribute(key);
});
......@@ -184,7 +186,8 @@ LdapImporter.prototype.process = function()
var usersMissingInLdap = {};//only keep internal userid to ensure a small memory footprint
//first, collect users that are in ADITO and should be in LDAP
tools.getStoredUsers().forEach(function (user, idx) {
tools.getStoredUsers().forEach(function (user, idx)
{
if (USERMODEL_IDENTIFIER == tools.NAME)
usersMissingInLdap[user[0]] = idx;
else if (USERMODEL_IDENTIFIER == tools.TITLE)
......@@ -239,7 +242,8 @@ LdapImporter.prototype._createAditoKeyValueArray = function(pLdapAttribute)
{
let ldapAttributes = {};
for(var [key, mapping] in this.dataMapping) {
for (var [key, mapping] in this.dataMapping)
{
if (mapping.FIELD_NAME)
{
mapping.FIELD_NAME.forEach(function (fieldName){
......@@ -260,11 +264,12 @@ LdapImporter.prototype._prepareLdapValue = function (pPreparedValue, pMapping, p
{
pPreparedValue = (pPreparedValue == null || pPreparedValue.getValues() == null) ? "" : pPreparedValue.getValues().toString();
if(pMapping.FUNCTION) {
if(pMapping.FUNCTION)
{
if(typeof pMapping.FUNCTION == "function")
pPreparedValue = pMapping.FUNCTION(pPreparedValue, pMapping, pLdapAttributeObj, pLdapAttributName, pAditoKeyValueArray);
else
pPreparedValue = eval(pMapping.FUNCTION);
// else
// pPreparedValue = eval(pMapping.FUNCTION);
} else if(pMapping.MAPPING) {
pPreparedValue = this._mappingLdapValue(pPreparedValue, pMapping, pLdapAttributeObj, pLdapAttributName, pAditoKeyValueArray);
}
......@@ -284,14 +289,20 @@ LdapImporter.prototype._mappingLdapValue = function(pPreparedValue, pMapping, pL
{
let valuesToAssign = [];
for(var key in pMapping.MAPPING) {
if(pPreparedValue.match(key)) {
for(var key in pMapping.MAPPING)
{
if (pPreparedValue.match(key))
{
var mapValues = pMapping.MAPPING[key];
if(typeof mapValues == "string") {
if(mapValues[0] == ";" && mapValues[mapValues.length - 1] == ";") {
if (typeof mapValues == "string")
{
if(mapValues[0] == ";" && mapValues[mapValues.length - 1] == ";")
{
mapValues = text.decodeMS(mapValues);
} else {
}
else
{
mapValues = [mapValues];
}
}
......@@ -355,10 +366,13 @@ ActiveDirectoryUtils._createUpdateUserDatamodel = function (pDataSet, pUserModel
effectiveUserModel[tools.PARAMS][tools.EXCHANGE_EMAIL] = effectiveUserModel[tools.PARAMS][tools.EXCHANGE_EMAIL].toLowerCase();
if(mode == LDAP_ACTION.INSERT)
try {
try
{
logging.log("insert User Model");
tools.insertUser(effectiveUserModel);
} catch (onInsertException) {
}
catch (onInsertException)
{
logging.log(effectiveUserModel[tools.NAME])
logging.log("Error insert User: " + effectiveUserModel[tools.TITLE], logging.ERROR, onInsertException);
logging.log(JSON.stringify(effectiveUserModel, null, " "), logging.ERROR);
......@@ -366,7 +380,6 @@ ActiveDirectoryUtils._createUpdateUserDatamodel = function (pDataSet, pUserModel
else
tools.updateUser(effectiveUserModel);
}
ActiveDirectoryUtils._createInsertUpdateCommMixStatements = function (pDataSet, pContactId)
......@@ -378,9 +391,9 @@ ActiveDirectoryUtils._createInsertUpdateCommMixStatements = function (pDataSet,
var existingCommData = null;//only load when necessary, so let's load later
for(var commType in this.custom.commTypes)
for (var commType in this.custom.commTypes)
{
if(pDataSet[commType] == null || !ActiveDirectoryUtils._isCorrectLdapAction(pDataSet[commType], ldapAction))
if (pDataSet[commType] == null || !ActiveDirectoryUtils._isCorrectLdapAction(pDataSet[commType], ldapAction))
continue;
var commMedium = this.custom.commTypes[commType].MEDIUM;
if (ldapAction == LDAP_ACTION.INSERT)
......@@ -428,18 +441,22 @@ ActiveDirectoryUtils._createInsertUpdateCommMixStatements = function (pDataSet,
var isCommExists = false;
var isCommEqual = false;
for each(var [MEDIUM_ID, ISSTANDARD, ADDR] in existingCommData) {
if(MEDIUM_ID == commMedium) {
for each(var [MEDIUM_ID, ISSTANDARD, ADDR] in existingCommData)
{
if (MEDIUM_ID == commMedium)
{
isCommExists = true;
if(ADDR.trim() == pDataSet[commType].VALUE.trim()){
if (ADDR.trim() == pDataSet[commType].VALUE.trim())
{
isCommEqual = true;
}
break;
}
}
if(!isCommExists) {
if (!isCommExists)
{
ActiveDirectoryUtils._setDataObject(pDataSet, "COMMUNICATION.COMMUNICATIONID", util.getNewUUID());
ActiveDirectoryUtils._setDataObject(pDataSet, "COMMUNICATION.MEDIUM_ID", commMedium);
ActiveDirectoryUtils._setDataObject(pDataSet, "COMMUNICATION.ADDR", pDataSet[commType].VALUE);
......@@ -450,7 +467,7 @@ ActiveDirectoryUtils._createInsertUpdateCommMixStatements = function (pDataSet,
if (tmpInsUpdC != null) sqlMixDataSet.push(tmpInsUpdC)
}
else if(!isCommEqual)
else if (!isCommEqual)
{
ActiveDirectoryUtils._setDataObject(pDataSet, "COMMUNICATION.MEDIUM_ID", commMedium);
ActiveDirectoryUtils._setDataObject(pDataSet, "COMMUNICATION.ADDR", pDataSet[commType].VALUE);
......@@ -490,7 +507,8 @@ ActiveDirectoryUtils._getColumnsAndTypesArray = function (pTableName, pDataSet,
};
var tableConfig = ColumnMetadataProvider.getInstanceFor(pTableName);
tableConfig.columns.forEach(function (column, idx){
tableConfig.columns.forEach(function (column, idx)
{
var dataSet = pDataSet[pTableName + "." + column];
if(dataSet == null || !ActiveDirectoryUtils._isCorrectLdapAction(dataSet, pDbAction))
return null;
......
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