diff --git a/entity/District_entity/District_entity.aod b/entity/District_entity/District_entity.aod index a1a87636487b90e137336f59ef630c1a8f709b53..a3e061e2370b6fb63d9937cf112d5c958de5231b 100644 --- a/entity/District_entity/District_entity.aod +++ b/entity/District_entity/District_entity.aod @@ -175,6 +175,12 @@ <entityName>LogHistory_entity</entityName> <fieldName>LogHistoryProvider</fieldName> </dependency> + <children> + <entityParameter> + <name>tablenames_param</name> + <valueProcess>%aditoprj%/entity/District_entity/entityfields/loghistories/children/tablenames_param/valueProcess.js</valueProcess> + </entityParameter> + </children> </entityConsumer> <entityField> <name>parentFilter</name> diff --git a/entity/District_entity/entityfields/loghistories/children/tablenames_param/valueProcess.js b/entity/District_entity/entityfields/loghistories/children/tablenames_param/valueProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..92a62600733c4a0b3e48ba036628bb93f372dbf7 --- /dev/null +++ b/entity/District_entity/entityfields/loghistories/children/tablenames_param/valueProcess.js @@ -0,0 +1,9 @@ +import("system.vars"); +import("system.result"); +import("Context_lib"); + +var res = []; +res.push({id: vars.get("$field.DISTRICTID"), tableNames: ["DISTRICT"]}); + +res = JSON.stringify(res);//currently only strings can be passed as param +result.object(res); \ No newline at end of file diff --git a/entity/Organisation_entity/Organisation_entity.aod b/entity/Organisation_entity/Organisation_entity.aod index 7bcc4de17a6cb52acae9aa20beda4c3b3c0190ce..1d1ed6f7718812b0c2badbd5f3851a54d035685a 100644 --- a/entity/Organisation_entity/Organisation_entity.aod +++ b/entity/Organisation_entity/Organisation_entity.aod @@ -8,6 +8,7 @@ <grantDeleteProcess>%aditoprj%/entity/Organisation_entity/grantDeleteProcess.js</grantDeleteProcess> <contentTitleProcess>%aditoprj%/entity/Organisation_entity/contentTitleProcess.js</contentTitleProcess> <afterUiInit>%aditoprj%/entity/Organisation_entity/afterUiInit.js</afterUiInit> + <afterSave>%aditoprj%/entity/Organisation_entity/afterSave.js</afterSave> <initFilterProcess>%aditoprj%/entity/Organisation_entity/initFilterProcess.js</initFilterProcess> <useFavorites v="true" /> <iconId>VAADIN:BUILDING</iconId> diff --git a/entity/Organisation_entity/afterSave.js b/entity/Organisation_entity/afterSave.js new file mode 100644 index 0000000000000000000000000000000000000000..4e40d8d824716c3690bb87b0f774ea3895246b3d --- /dev/null +++ b/entity/Organisation_entity/afterSave.js @@ -0,0 +1,11 @@ +import("system.logging"); +import("system.vars"); +import("District_lib"); +import("system.neon"); + +if (vars.get("$local.recordstate") == neon.OPERATINGSTATE_NEW) +{ + //Assign this new organisation to all according districts with auto assignment is true + //2nd parameter "undefined" means, that the current user is determined in the function + DistrictUtils.assignDistrictOnServer([], undefined, vars.get("$local.entitydata")["CONTACTID"]) +} \ No newline at end of file diff --git a/process/District_lib/process.js b/process/District_lib/process.js index 47c2f38c68eeae7c8ec11f665f7ea31feebd219e..6f77c41867db968f82bf6e6421c03b72bf34f8b1 100644 --- a/process/District_lib/process.js +++ b/process/District_lib/process.js @@ -3,7 +3,6 @@ import("system.text"); import("system.datetime"); import("system.notification"); import("system.translate"); -import("system.logging"); import("Contact_lib"); import("KeywordRegistry_basic"); import("system.vars"); @@ -68,7 +67,7 @@ DistrictUtils.getDataFromDistrict = function (pDistrictId) */ DistrictUtils.getDataFromDistrictContact = function (pDistrictContactId) { - var arrData = newSelect("DISTRICT_ID, ADVISER_CONTACT_ID") + var arrData = newSelect("DISTRICT_ID, ADVISER_CONTACT_ID, CONTACT_ID") .from("DISTRICTCONTACT") .where("DISTRICTCONTACT.DISTRICTCONTACTID", pDistrictContactId) .arrayRow(); @@ -83,11 +82,13 @@ DistrictUtils.getDataFromDistrictContact = function (pDistrictContactId) * @param {Array} pArrDistrictIds <p> * Array of district-IDs.<br> * @param {String} pUser=currentUser (optional) <p> - * User that will get the notification, <br> - * if null (not undefined!), no notification<br> - * will be created.<br> + * User who will get the notification, <br> + * User who will start the batch job <br> + * @param {String} pContactId (optional) <p> + * Organisation which should be assigned to all <br> + * according districts with auto assignment is true <br> */ -DistrictUtils.assignDistrictOnServer = function (pArrDistrictIds, pUser) +DistrictUtils.assignDistrictOnServer = function (pArrDistrictIds, pUser, pContactId) { //pUser hat folgendes Format: _____USER_bcdfb521-c7d0-4ef1-8916-78e7d3232046 if (pUser === undefined) @@ -96,9 +97,10 @@ DistrictUtils.assignDistrictOnServer = function (pArrDistrictIds, pUser) .setName("assignDistrict_serverProcess") .setLocalVariables({ arrDistrictIds : pArrDistrictIds.join(";"), - user : pUser || "" + user : pUser || "", + contactId : pContactId || "" }) - .setUser(pUser) + .setUser(pUser); process.startAsync(processConfig); } @@ -127,7 +129,7 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId //Einlesen von allen bereits existierenden automatischen Zuordnungen, //die nicht auf Status 'zur Prüfung' stehen //Nur notwendig, wenn pContactId leer ist. Ansonsten soll ja gezielt ein neuer Datensatz angelegt werden - var arrExistingIds = [] + var arrExistingIds = []; if (!pContactId) { arrExistingIds = new SqlBuilder() @@ -150,9 +152,8 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId //Aufbereiten des im JSON-Format übergebenen Filters in eine SQL-Condition var appliedFilterCondition = JSON.parse(pAppliedFilter).filter; appliedFilterCondition = JSON.stringify(appliedFilterCondition); - logging.log("appliedFilterCondition: " + appliedFilterCondition); - var sqlCondition = db.toFilterCondition(appliedFilterCondition, "Organisation_entity") - logging.log("sqlCondition: " + sqlCondition) + var sqlCondition = db.toFilterCondition(appliedFilterCondition, "Organisation_entity"); + //Einlesen der Contact-IDs zu den Firmen, die gemäß Filter diesem Gebiet zugeordnet sind var arrOrgContactIds = new SqlBuilder() .selectDistinct("CONTACT.CONTACTID") @@ -162,8 +163,8 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId .leftJoin("CLASSIFICATIONSTORAGE", "CLASSIFICATIONSTORAGE.OBJECT_ROWID = CONTACT.CONTACTID") .whereIfSet(sqlCondition) .andIfSet("CONTACT.CONTACTID", pContactId) - .arrayColumn(); - logging.log("arrOrgContactIds.length: " + arrOrgContactIds.length) + .arrayColumn(); + var insertArray = []; var colsInsert = [ "DISTRICTCONTACTID", @@ -191,7 +192,7 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId for (var j=0; j<arrResponsibleIds.length; j++) { //Existiert der Firmen-Betreuer-Datensatz bereits? - var found = 'N' + var found = 'N'; for (var k=0; k<arrExistingIds.length; k++) { if (arrExistingIds[k][1] == arrOrgContactIds[i] && arrExistingIds[k][2] == arrResponsibleIds[j][0]) @@ -393,52 +394,6 @@ DistrictUtils.setDistrictContactStatus = function (pArrIds, pStatus) } -/** - * This function will assign a new organisation to all districts, which - * - have the property "auto assignment" - * - and are part of the regarding filter - * @param {String} pOrganisationId <p> - * Organisation-ID of the new Organisation<br> - * @param {String} pUserLogin <p> - * login,who created the new organistion<br> - * @return <none> <p> - */ -DistrictUtils.assignOrganisationToDistrict = function (pOrganisationId, pUserLogin) -{ - //contactid zur organisationid ermitteln - var contactId = ContactUtils.getOrgContactId(pOrganisationId); - - //alle Filter ermitteln, die auf auto-assignment gleich true gesetzt sind - var allAutoDistricts = newSelect("DISTRICTID") - .from("DISTRICT") - .where("DISTRICT.DISTRICT_AUTOADD", 1) - .arrayColumn(); - - //TODO: pUserLogin noch bis zum Schreiben von date_new durchschleusen - logging.log("pUerLogin: " + pUserLogin) - - - //Variante 1 - for (var i=0; i<allAutoDistricts.length; i++) - { - logging.log("allAutoDistricts[i]: " + allAutoDistricts[i]); - //pro District den kompletten Filter ermitteln - var districtData = DistrictUtils.getDataFromDistrict(allAutoDistricts[i]); - var completeFilter = DistrictUtils.getAppliedFilter(districtData[0], districtData[1]) - //logging.log("completeFilter: " + completeFilter) - //prüfen, ob die neue contactid im filter enthalten wäre - //und im Erfolgsfall die Daten in der districtcontact anlegen - //TODO: pUserLogin als 4ten Parameter übergeben. Wenn gefüllt, diesen als USER_NEW/EDIT setzen, sonst den sys.user verwenden - var res = DistrictUtils.assignDistrict(allAutoDistricts[i], completeFilter, contactId); - } - - -//Variante 2: Aufruf des Server-Prozessen mit allen Gebieten mit Auto-Zuordnung gleich true -//Wirft den gleichen Fehler wie Variante 1 -//TODO: Aus dem pUserLogin noch die Employee-ID ermitteln -//DistrictUtils.assignDistrictOnServer(allAutoDistricts, pUserLogin); -} - /** * This function will notificate the district contact that he/she was assigned * @@ -451,15 +406,18 @@ DistrictUtils.notificateNewDistrictContact = function(pDistrictContactId){ //[0]: DISTRICT_ID, [1]: ADVISER_CONTACT_ID, [2]: CONTACT_ID var arrayDistrictContact = DistrictUtils.getDataFromDistrictContact(pDistrictContactId); - //get corresponding profile information of the systemalias var user = tools.getUserByAttribute(tools.CONTACTID, arrayDistrictContact[1], tools.PROFILE_DEFAULT); - var userName = user[tools.NAME]; - - var districtName = DistrictUtils.getDistrictName(arrayDistrictContact[0]); - var organisationName = ContactUtils.getFullTitleByContactId(arrayDistrictContact[2]); - // Benachrichtigung am Ende der Zuordnungen - description = translate.withArguments("You were assigned as new district contact to district %0 and organisation %1.", - [districtName, organisationName]) - notification.addNotification(util.getNewUUID(), text.encodeMS(["Organisation", arrayDistrictContact[2]]), null, null, "DistrictAssigned", notification.PRIO_NORMAL, 2, notification.STATE_UNSEEN, [userName], message, description); + + //You can only send a notification, if the user is an employee + if (user) + { + var userName = user[tools.NAME]; + var districtName = DistrictUtils.getDistrictName(arrayDistrictContact[0]); + var organisationName = ContactUtils.getFullTitleByContactId(arrayDistrictContact[2]); + // Benachrichtigung am Ende der Zuordnungen + description = translate.withArguments("You were assigned as new district contact to district %0 and organisation %1.", + [districtName, organisationName]); + notification.addNotification(util.getNewUUID(), text.encodeMS(["Organisation", arrayDistrictContact[2]]), null, null, "DistrictAssigned", notification.PRIO_NORMAL, 2, notification.STATE_UNSEEN, [userName], message, description); + } } diff --git a/process/assignDistrict_serverProcess/process.js b/process/assignDistrict_serverProcess/process.js index 48f1e807144572e80847b1bb4603fd9051dc50a7..f3434cef31913e4ff8323905783bdf0a3f9710eb 100644 --- a/process/assignDistrict_serverProcess/process.js +++ b/process/assignDistrict_serverProcess/process.js @@ -7,46 +7,79 @@ import("system.vars"); import("system.notification"); import("District_lib"); +var i; +var districtData; +var completeFilter; var res; -var message; -var description; -var newAssigned = 0; -var unchanged = 0; -var invalid = 0; - -var startTime = datetime.date(); var user = vars.get("$local.user"); var arrDistrictIds = vars.get("$local.arrDistrictIds").split(";"); +var contactId = vars.get("$local.contactId"); -//Alle übergebenen Gebiete bearbeiten -for (var i=0; i<arrDistrictIds.length; i++) +// Do the assignment for all transferred districts +if (vars.get("$local.arrDistrictIds").length > 0 && arrDistrictIds.length > 0) { - //Pro Gebiet den kompletten hierarchieschen Filter aufbauen - var districtData = DistrictUtils.getDataFromDistrict(arrDistrictIds[i]); - var completeFilter = DistrictUtils.getAppliedFilter(districtData[0], districtData[1]) - - //Automatische Zuordnung - res = DistrictUtils.assignDistrict(arrDistrictIds[i], completeFilter); - - newAssigned += res.newAssigned; - unchanged += res.unchanged; - invalid += res.invalid; + var message; + var description; + + var newAssigned = 0; + var unchanged = 0; + var invalid = 0; + + var startTime = datetime.date(); + + //Assign all transferred districts + for (i=0; i<arrDistrictIds.length; i++) + { + //Build the complete hierarchical filter for every district + districtData = DistrictUtils.getDataFromDistrict(arrDistrictIds[i]); + completeFilter = DistrictUtils.getAppliedFilter(districtData[0], districtData[1]); + + //Automatic assignment + res = DistrictUtils.assignDistrict(arrDistrictIds[i], completeFilter); + + newAssigned += res.newAssigned; + unchanged += res.unchanged; + invalid += res.invalid; + } + + if (arrDistrictIds.length == 1) + { + var districtName = DistrictUtils.getDistrictName(arrDistrictIds[0]); + message = translate.withArguments("Assignment of district \"%0\" is completed!", [districtName]); + } + else + message = translate.text("Assignment of all selected districts is completed!"); + + // Notification at the end of the assignment + description = translate.withArguments("%0 companies were newley assigned. \n" + + "%1 companies are no longer assigned (these assignments got the status 'review'). \n" + + "%2 valid assignments were unchanged.\n" + + "The Process took %3 seconds.", + [newAssigned, invalid, unchanged, Math.round((datetime.date() - startTime) / datetime.ONE_SECOND)]); + notification.addNotification(util.getNewUUID(), null, null, null, "DistrictAssigned", notification.PRIO_NORMAL, 2, notification.STATE_UNSEEN, [user], message, description); } -if (arrDistrictIds.length == 1) -{ - var districtName = DistrictUtils.getDistrictName(arrDistrictIds[0]); - message = translate.withArguments("Assignment of district \"%0\" is completed!", [districtName]); + +//Assign a new organisation to all according districts with auto assignment is true +//NOTICE: The new organisation must be part of the filter of the district +if (contactId != "") +{ + //Get all filters where auto assingment is true + var allAutoDistricts = newSelect("DISTRICTID") + .from("DISTRICT") + .where("DISTRICT.DISTRICT_AUTOADD", 1) + .arrayColumn(); + + for (i=0; i<allAutoDistricts.length; i++) + { + //Build the complete filter + districtData = DistrictUtils.getDataFromDistrict(allAutoDistricts[i]); + completeFilter = DistrictUtils.getAppliedFilter(districtData[0], districtData[1]); + + //Check if the new contactid is part ot this filter + //if so, write data in table districtcontact + res = DistrictUtils.assignDistrict(allAutoDistricts[i], completeFilter, contactId); + } } -else - message = translate.text("Assignment of all selected districts is completed!"); - -// Benachrichtigung am Ende der Zuordnungen -description = translate.withArguments("%0 companies were newley assigned. \n" + - "%1 companies are no longer assigned (these assignments got the status 'review'). \n" + - "%2 valid assignments were unchanged.\n" + - "The Process took %3 seconds.", - [newAssigned, invalid, unchanged, Math.round((datetime.date() - startTime) / datetime.ONE_SECOND)]) -notification.addNotification(util.getNewUUID(), null, null, null, "DistrictAssigned", notification.PRIO_NORMAL, 2, notification.STATE_UNSEEN, [user], message, description); \ No newline at end of file diff --git a/process/process_audit/process.js b/process/process_audit/process.js index 2a6f8cac186f152024ad1ea1daf967a4b3f50bd4..5b0cb6d15d46bed1c566b4a21f9f91c5def3392d 100644 --- a/process/process_audit/process.js +++ b/process/process_audit/process.js @@ -17,12 +17,6 @@ if (sqlAction != 'X') (new LogHistoryExecutor(tableName, userLogin, columns, newvalues, oldvalues, timestamp, sqlAction, id)).execute(); } -//Ticketnummer: 1066031 -//if (sqlAction == 'I' && tableName == 'ORGANISATION') -//{ -// DistrictUtils.assignOrganisationToDistrict(id, userLogin); -//} - if(sqlAction == 'I' && tableName == 'DISTRICTCONTACT'){ DistrictUtils.notificateNewDistrictContact(id); } \ No newline at end of file