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

merged origin/1075052_blacklisting into dev_xrm_marketing

parents b529fb03 8e92d47a
No related branches found
No related tags found
No related merge requests found
Showing
with 655 additions and 113 deletions
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<neonContext xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonContext/1.1.1"> <neonContext xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonContext/1.1.1">
<name>CommunicationBlacklist</name> <name>CommunicationBlacklist</name>
<title>Blacklist</title>
<majorModelMode>DISTRIBUTED</majorModelMode> <majorModelMode>DISTRIBUTED</majorModelMode>
<filterView>CommunicationBlacklistFilter_view</filterView>
<editView>CommunicationBlacklistEdit_view</editView>
<entity>CommunicationBlacklist_entity</entity>
<references>
<neonViewReference>
<name>664796b3-d90b-439d-b960-a1f09e00c99d</name>
<view>CommunicationBlacklistFilter_view</view>
</neonViewReference>
<neonViewReference>
<name>c08fe896-0181-4243-8639-cb96e302d3c8</name>
<view>CommunicationBlacklistEdit_view</view>
</neonViewReference>
</references>
</neonContext> </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.8" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.8">
<name>CommunicationBlacklistEdit_view</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<size>SMALL</size>
<layout>
<boxLayout>
<name>layout</name>
</boxLayout>
</layout>
<children>
<genericViewTemplate>
<name>Generic</name>
<editMode v="true" />
<fields>
<entityFieldLink>
<name>5bf6cb8b-20da-4e64-ab86-e654e1f9f6a5</name>
<entityField>BLACKLIST_TYPE</entityField>
</entityFieldLink>
<entityFieldLink>
<name>bad5d056-972e-4d10-b3c7-a25bf6233cb5</name>
<entityField>BLACKLIST_FILTER</entityField>
</entityFieldLink>
<entityFieldLink>
<name>f74c2a6a-1b70-4914-8059-8866a0e5db77</name>
<entityField>START_DATE</entityField>
</entityFieldLink>
<entityFieldLink>
<name>2b2bb0e7-7cdf-42ca-8c0b-89d1d869fa44</name>
<entityField>END_DATE</entityField>
</entityFieldLink>
<entityFieldLink>
<name>947da750-50bd-47bb-af2d-7446b3756482</name>
<entityField>REASON</entityField>
</entityFieldLink>
</fields>
</genericViewTemplate>
</children>
</neonView>
<?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.8" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.8">
<name>CommunicationBlacklistFilter_view</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<filterable v="true" />
<layout>
<groupLayout>
<name>layout</name>
</groupLayout>
</layout>
<children>
<tableViewTemplate>
<name>Table</name>
<columns>
<neonTableColumn>
<name>86497fa4-acda-4041-8cbc-8d11838b4876</name>
<entityField>BLACKLIST_TYPE</entityField>
</neonTableColumn>
<neonTableColumn>
<name>304b2589-aabf-42f6-916f-a69cff5a1b00</name>
<entityField>START_DATE</entityField>
</neonTableColumn>
<neonTableColumn>
<name>fd5077c1-942b-42f0-8f44-80e9c568db44</name>
<entityField>END_DATE</entityField>
</neonTableColumn>
<neonTableColumn>
<name>d7050f91-da78-4ffc-a31c-30985d808473</name>
<entityField>REASON</entityField>
</neonTableColumn>
</columns>
</tableViewTemplate>
</children>
</neonView>
import("system.logging");
import("system.entities");
import("MarketingCondition_lib");
import("system.fileIO"); import("system.fileIO");
import("system.project"); import("system.project");
import("Util_lib"); import("Util_lib");
...@@ -18,7 +21,6 @@ import("Email_lib"); ...@@ -18,7 +21,6 @@ import("Email_lib");
import("system.process"); import("system.process");
import("system.notification"); import("system.notification");
import("Document_lib"); import("Document_lib");
import("system.db");
/** /**
* Functions for bulk mails. * Functions for bulk mails.
...@@ -59,57 +61,60 @@ BulkMailUtils.sendBulkMailOnServer = function (pBulkMailId, pTestRun, pUser) ...@@ -59,57 +61,60 @@ BulkMailUtils.sendBulkMailOnServer = function (pBulkMailId, pTestRun, pUser)
* *
* @param {String} pBulkMailId <p> * @param {String} pBulkMailId <p>
* Id of the bulk mail.<br> * Id of the bulk mail.<br>
* @param {Bool} pTestRun (optional) <p> * @param {Bool} pIsTestRun (optional) <p>
* True indicates a Testrun<br> * True indicates a Testrun<br>
* @return {Object} <p> * @return {Object} <p>
* Count of sucessful and failed mails.<br> * Count of sucessful and failed mails.<br>
*/ */
BulkMailUtils.sendBulkMail = function (pBulkMailId, pTestRun) BulkMailUtils.sendBulkMail = function (pBulkMailId, pIsTestRun)
{ {
if (pIsTestRun == undefined)
{
pIsTestRun = false;
}
var [templateId, subject, emailSender, createActivity, bulkMailName, useTemplateAttachments] = var [templateId, subject, emailSender, createActivity, bulkMailName, useTemplateAttachments] =
newSelect("DOCUMENTTEMPLATE_ID, SUBJECT, SENDER_EMAIL_ADDRESS, CREATEACTIVITIES, NAME, USE_TEMPLATE_ATTACHMENTS") newSelect("DOCUMENTTEMPLATE_ID, SUBJECT, SENDER_EMAIL_ADDRESS, CREATEACTIVITIES, NAME, USE_TEMPLATE_ATTACHMENTS")
.from("BULKMAIL") .from("BULKMAIL")
.where("BULKMAIL.BULKMAILID", pBulkMailId) .where("BULKMAIL.BULKMAILID", pBulkMailId)
.arrayRow(); .arrayRow();
useTemplateAttachments = useTemplateAttachments == "1"; useTemplateAttachments = Utils.toBoolean(useTemplateAttachments);
var template = BulkMailUtils.getBulkMailTemplate(pBulkMailId, templateId, true, useTemplateAttachments); var template = BulkMailUtils.getBulkMailTemplate(pBulkMailId, templateId, true, useTemplateAttachments);
var recipientData;
var testRecipientData; var testRecipientData;
if (pTestRun) var recipientLoadConfig = entities.createConfigForLoadingRows()
.fields(["BULKMAILRECIPIENTID", "CONTACT_ID", "EMAIL_ADDRESS", "PERSON_ID", "ORGANISATION_ID"])
.entity("BulkmailRecipient_entity")
.provider("RecipientsToBeMailed")
.addParameter("BulkMailId_param", pBulkMailId)
.addParameter("IsTestMail_param", pIsTestRun);
var recipientData = entities.getRows(recipientLoadConfig);
if (pIsTestRun)
{ {
recipientData = newSelect("BULKMAILRECIPIENTID, BULKMAILRECIPIENT.CONTACT_ID, BULKMAILRECIPIENT.EMAIL_ADDRESS, PERSON_ID, ORGANISATION_ID")
.from("CONTACT")
.join("BULKMAILRECIPIENT", "BULKMAILRECIPIENT.CONTACT_ID = CONTACT.CONTACTID")
.where("BULKMAILRECIPIENT.BULKMAIL_ID", pBulkMailId)
.and("BULKMAILRECIPIENT.TEST_RECIPIENT",1)
.table();
testRecipientData = newSelect("BULKMAILTESTRECIPIENT.CONTACT_ID, BULKMAILTESTRECIPIENT.EMAIL_ADDRESS") testRecipientData = newSelect("BULKMAILTESTRECIPIENT.CONTACT_ID, BULKMAILTESTRECIPIENT.EMAIL_ADDRESS")
.from("BULKMAILTESTRECIPIENT") .from("BULKMAILTESTRECIPIENT")
.where("BULKMAILTESTRECIPIENT.BULKMAIL_ID",pBulkMailId) .where("BULKMAILTESTRECIPIENT.BULKMAIL_ID", pBulkMailId)
.table();
}
else
{
recipientData = newSelect("BULKMAILRECIPIENTID, BULKMAILRECIPIENT.CONTACT_ID, BULKMAILRECIPIENT.EMAIL_ADDRESS, PERSON_ID, ORGANISATION_ID")
.from("CONTACT")
.join("BULKMAILRECIPIENT", "BULKMAILRECIPIENT.CONTACT_ID = CONTACT.CONTACTID")
.where("BULKMAILRECIPIENT.BULKMAIL_ID", pBulkMailId)
.and("BULKMAILRECIPIENT.STATUS", $KeywordRegistry.bulkMailRecipientStatus$sent(), SqlBuilder.NOT_EQUAL())
.and(ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$mail(), true))
.table(); .table();
} }
var mailrunId = util.getNewUUID(); var mailrunId = util.getNewUUID();
new SqlBuilder()
db.insertData("MAIL_RUN", ["MAIL_RUNID","OBJECT_ROWID","OBJECT_TYPE","DATE_RUN_START","STATUS","TESTRUN"], null, [mailrunId,pBulkMailId,"BULKMAIL",vars.get("$sys.date"),$KeywordRegistry.bulkMailStatus$beingSent(),(pTestRun?1:0)]); .tableName("MAIL_RUN")
.insertFields({
"MAIL_RUNID": mailrunId,
"OBJECT_ROWID": pBulkMailId,
"OBJECT_TYPE": "Bulkmail",
"DATE_RUN_START": vars.get("$sys.date"),
"STATUS": $KeywordRegistry.bulkMailStatus$beingSent(),
"TESTRUN": pIsTestRun ? 1 : 0
});
var contactIds = recipientData.map(function (e) {return e[1];}); var contactIds = recipientData.map(function (recipient) {return recipient["CONTACT_ID"];});
var successIds = []; var successIds = [];
var failedIds = []; var failedIds = [];
var sentDate = vars.get("$sys.date"); var sentDate = vars.get("$sys.date");
...@@ -120,96 +125,115 @@ BulkMailUtils.sendBulkMail = function (pBulkMailId, pTestRun) ...@@ -120,96 +125,115 @@ BulkMailUtils.sendBulkMail = function (pBulkMailId, pTestRun)
var bulkMailLink = [["BulkMail", pBulkMailId]]; var bulkMailLink = [["BulkMail", pBulkMailId]];
var activitySubject = translate.withArguments("Bulk mail \"%0\" sent", [bulkMailName]); var activitySubject = translate.withArguments("Bulk mail \"%0\" sent", [bulkMailName]);
if (!pTestRun){ if (!pIsTestRun)
for (let i = 0, l = recipientData.length; i < l; i++) {
recipientData.forEach(function (recipient)
{
let isSuccess = false;
let recipientId = recipient["BULKMAILRECIPIENTID"];
let contactId = recipient["CONTACT_ID"];
let emailAddress = recipient["EMAIL_ADDRESS"];
let personId = recipient["PERSON_ID"];
let organisationId = recipient["ORGANISATION_ID"];
let email = mails[contactId];
let mailLogId = util.getNewUUID();
if (email !== undefined && emailAddress)
{
email.toRecipients = [emailAddress];
email.sender = emailSender;
email.subject = subjects[contactId];
BulkMailUtils.storeEmlFile(pBulkMailId, mailrunId, mailLogId,email.getEML());
isSuccess = email.send();
}
//set the recipient status to 'sent' or 'failed'
new SqlBuilder()
.tableName("MAIL_LOG")
.insertFields({
"MAIL_LOGID": mailLogId,
"MAIL_RUN_ID": mailrunId,
"CONTACT_ID": contactId,
"STATUS": isSuccess ? $KeywordRegistry.bulkMailRecipientStatus$sent() : $KeywordRegistry.bulkMailRecipientStatus$failed(),
"SENDER_EMAIL": emailSender,
"RECIPIENT_EMAIL": emailAddress,
"MAILING_SUBJECT": subjects[contactId],
"DATE_SEND": vars.get("$sys.date")
});
//TODO: Klären was von alter Logik noch bleiben soll. Status macht nur Sinn wenn jede Bulkmail nur einmal gesendet wird. Bleiben Activitys?
Array.prototype.push.call(isSuccess ? successIds : failedIds, recipientId);
if (isSuccess && createActivity == "1")
{ {
let activityData = {
let isSuccess = false; categoryKeywordId : $KeywordRegistry.activityCategory$mail(),
let contactId = recipientData[i][1]; directionKeywordId : $KeywordRegistry.activityDirection$outgoing(),
let email = mails[contactId]; subject : activitySubject,
let mailLogId = util.getNewUUID(); content : email.body
if (email !== undefined && recipientData[i][2]) };
{ let contactLink = [[ContactUtils.getContextByPersOrg(personId, organisationid), contactId]];
email.toRecipients = [recipientData[i][2]]; ActivityUtils.insertNewActivity(activityData, bulkMailLink.concat(contactLink));
email.sender = emailSender;
email.subject = subjects[contactId];
this.storeEmlFile(pBulkMailId, mailrunId, mailLogId,email.getEML());
isSuccess = email.send();
}
if (recipientData[i][0]) //set the recipient status to 'sent' or 'failed'
{
db.insertData("MAIL_LOG", ["MAIL_LOGID","MAIL_RUN_ID","CONTACT_ID","STATUS","SENDER_EMAIL","RECIPIENT_EMAIL","MAILING_SUBJECT","DATE_SEND"], null, [mailLogId,mailrunId,contactId,(isSuccess ?$KeywordRegistry.bulkMailRecipientStatus$sent(): $KeywordRegistry.bulkMailRecipientStatus$failed()),emailSender,recipientData[i][2],subjects[contactId],vars.get("$sys.date")]);
//TODO: Klären was von alter Logik noch bleiben soll. Status macht nur Sinn wenn jede Bulkmail nur einmal gesendet wird. Bleiben Activitys?
Array.prototype.push.call(isSuccess ? successIds : failedIds, recipientData[i][0]);
if (isSuccess && createActivity == "1")
{
let activityData = {
categoryKeywordId : $KeywordRegistry.activityCategory$mail(),
directionKeywordId : $KeywordRegistry.activityDirection$outgoing(),
subject : activitySubject,
content : email.body
};
let contactLink = [[ContactUtils.getContextByPersOrg(recipientData[i][3], recipientData[i][4]), recipientData[i][1]]];
ActivityUtils.insertNewActivity(activityData, bulkMailLink.concat(contactLink));
}
}
} }
});
newWhereIfSet("BULKMAILRECIPIENT.BULKMAILRECIPIENTID", successIds, SqlBuilder.IN())
.updateData(true, "BULKMAILRECIPIENT", ["STATUS", "SENTDATE"], null, [$KeywordRegistry.bulkMailRecipientStatus$sent(), sentDate]); newWhereIfSet("BULKMAILRECIPIENT.BULKMAILRECIPIENTID", successIds, SqlBuilder.IN())
.updateFields({
"STATUS": $KeywordRegistry.bulkMailRecipientStatus$sent(),
newWhereIfSet("BULKMAILRECIPIENT.BULKMAILRECIPIENTID", failedIds, SqlBuilder.IN()) "SENTDATE": sentDate
.updateData(true, "BULKMAILRECIPIENT", ["STATUS", "SENTDATE"], null, [$KeywordRegistry.bulkMailRecipientStatus$failed(), sentDate]); });
newWhere("MAIL_RUN.MAIL_RUNID",mailrunId) newWhereIfSet("BULKMAILRECIPIENT.BULKMAILRECIPIENTID", failedIds, SqlBuilder.IN())
.updateData(true,"MAIL_RUN",["STATUS","DATE_RUN_FINISHED"],null,[$KeywordRegistry.bulkMailStatus$sent(),vars.get("$sys.date")]); .updateFields({
"STATUS": $KeywordRegistry.bulkMailRecipientStatus$failed(),
"SENTDATE": sentDate
newWhere("BULKMAIL.BULKMAILID", pBulkMailId) });
.updateData(true, "BULKMAIL", ["STATUS"], null, [$KeywordRegistry.bulkMailStatus$sent()]);
newWhere("MAIL_RUN.MAIL_RUNID", mailrunId)
.updateFields({
"STATUS": $KeywordRegistry.bulkMailStatus$sent(),
"DATE_RUN_FINISHED": vars.get("$sys.date")
});
newWhere("BULKMAIL.BULKMAILID", pBulkMailId)
.updateFields({
"STATUS": $KeywordRegistry.bulkMailStatus$sent()
});
}
else
{
for (let i = 0, l = recipientData.length; i < l; i++)
{
}else{ let isSuccess = false;
for (let i = 0, l = recipientData.length; i < l; i++){ let contactId = recipientData[i][1];
logging.log("here"); let email = mails[contactId];
let isSuccess = false;
let contactId = recipientData[i][1]; if (email !== undefined)
let email = mails[contactId]; {
email.sender = emailSender;
email.subject = "Test: "+subjects[contactId];
if (email !== undefined) for (let j =0; j<testRecipientData.length;j++){
{ if(testRecipientData[j][1]){
logging.log("email not undefined"); email.toRecipients = [testRecipientData[j][1]];
logging.log(JSON.stringify(testRecipientData)); isSuccess = email.send();
email.sender = emailSender;
email.subject = "Test: "+subjects[contactId]; Array.prototype.push.call(isSuccess ? successIds : failedIds, recipientData[i][0]);
for (let j =0; j<testRecipientData.length;j++){
if(testRecipientData[j][1]){ if (testRecipientData[j][0])
email.toRecipients = [testRecipientData[j][1]]; {
isSuccess = email.send(); let mailLogId = util.getNewUUID();
db.insertData("MAIL_LOG", ["MAIL_LOGID","MAIL_RUN_ID","CONTACT_ID","STATUS","SENDER_EMAIL","RECIPIENT_EMAIL","MAILING_SUBJECT","DATE_SEND"], null, [mailLogId,mailrunId,testRecipientData[j][0],(isSuccess ?$KeywordRegistry.bulkMailRecipientStatus$sent(): $KeywordRegistry.bulkMailRecipientStatus$failed()),emailSender,testRecipientData[j][1],email.subject,vars.get("$sys.date")]);
Array.prototype.push.call(isSuccess ? successIds : failedIds, recipientData[i][0]); this.storeEmlFile(pBulkMailId, mailrunId, mailLogId,email.getEML());
if(testRecipientData[j][0]){
let mailLogId = util.getNewUUID();
db.insertData("MAIL_LOG", ["MAIL_LOGID","MAIL_RUN_ID","CONTACT_ID","STATUS","SENDER_EMAIL","RECIPIENT_EMAIL","MAILING_SUBJECT","DATE_SEND"], null, [mailLogId,mailrunId,testRecipientData[j][0],(isSuccess ?$KeywordRegistry.bulkMailRecipientStatus$sent(): $KeywordRegistry.bulkMailRecipientStatus$failed()),emailSender,testRecipientData[j][1],email.subject,vars.get("$sys.date")]);
this.storeEmlFile(pBulkMailId, mailrunId, mailLogId,email.getEML());
}
} }
} }
}
} }
newWhere("MAIL_RUN.MAIL_RUNID",mailrunId)
.updateData(true,"MAIL_RUN",["STATUS","DATE_RUN_FINISHED"],null,[$KeywordRegistry.bulkMailStatus$sent(),vars.get("$sys.date")]);
}
} }
newWhere("MAIL_RUN.MAIL_RUNID",mailrunId)
.updateData(true,"MAIL_RUN",["STATUS","DATE_RUN_FINISHED"],null,[$KeywordRegistry.bulkMailStatus$sent(),vars.get("$sys.date")]);
}
return { return {
sucessful : successIds.length, sucessful : successIds.length,
......
...@@ -376,4 +376,7 @@ $KeywordRegistry.interestStatus$inactive = function(){return "INTEREST_INACTIVE" ...@@ -376,4 +376,7 @@ $KeywordRegistry.interestStatus$inactive = function(){return "INTEREST_INACTIVE"
$KeywordRegistry.interestLinkStatus = function(){return "InterestLinkStatus";}; $KeywordRegistry.interestLinkStatus = function(){return "InterestLinkStatus";};
$KeywordRegistry.interestLinkStatus$subscribed = function(){return "INTERESTLINK_SUBSCRIBED";}; $KeywordRegistry.interestLinkStatus$subscribed = function(){return "INTERESTLINK_SUBSCRIBED";};
$KeywordRegistry.interestLinkStatus$notSubscribed = function(){return "INTERESTLINK_NOTSUBSCRIBED";}; $KeywordRegistry.interestLinkStatus$notSubscribed = function(){return "INTERESTLINK_NOTSUBSCRIBED";};
\ No newline at end of file
$KeywordRegistry.communicationBlacklistType = function(){return "CommunicationBlacklistType";};
$KeywordRegistry.communicationBlacklistType$emailRecipientFilter = function(){return "BLACKLIST_TYPE_EMAILRECIPIENT_FILTER";};
\ No newline at end of file
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<name>MarketingCondition_lib</name> <name>MarketingCondition_lib</name>
<majorModelMode>DISTRIBUTED</majorModelMode> <majorModelMode>DISTRIBUTED</majorModelMode>
<process>%aditoprj%/process/MarketingCondition_lib/process.js</process> <process>%aditoprj%/process/MarketingCondition_lib/process.js</process>
<alias>Data_alias</alias>
<variants> <variants>
<element>LIBRARY</element> <element>LIBRARY</element>
</variants> </variants>
......
import("Util_lib");
import("JditoFilter_lib");
import("system.vars");
import("Sql_lib");
import("KeywordRegistry_basic");
function MarketingCondition () /**
* Object for building communication settings sql conditions.
*/
function CommunicationSettingsCondition ()
{ {
this._contactIdSql = "CONTACT.CONTACTID";
this._channelType = null;
this._medium = null;
this._channelIdSql = null;
this._settingStatus = null;
this._existsOperator = SqlBuilder.EXISTS();
}
CommunicationSettingsCondition.prototype.contactIdField = function (pContactIdSql)
{
this._contactIdSql = pContactIdSql;
return this;
}
CommunicationSettingsCondition.prototype.existNoSettings = function ()
{
this._existsOperator = SqlBuilder.NOT_EXISTS();
return this;
}
CommunicationSettingsCondition.prototype.existSettings = function ()
{
this._existsOperator = SqlBuilder.EXISTS();
return this;
}
/**
* Sets the medium and the source of the communication address for filtering the communication settings.
*
* @param {String} pMedium communication medium
* @param {String} pAddressSql sql field or expression for the communication address
* @return {CommunicationSettingsCondition} current object
*/
CommunicationSettingsCondition.prototype.medium = function (pMedium, pAddressSql)
{
this._channelType = $KeywordRegistry.communicationChannelType$communication();
this._medium = pMedium;
if (pAddressSql)
this._channelIdSql = pAddressSql;
return this;
}
/**
* Sets the medium to email and the source of the email address for filtering the communication settings.
*
* @param {String} pAddressSql sql field or expression for the email address
* @return {CommunicationSettingsCondition} current object
*/
CommunicationSettingsCondition.prototype.emails = function (pAddressSql)
{
return this.medium($KeywordRegistry.communicationMediumCampaign$mail(), pAddressSql);
}
/**
* Sets the source of the address to filter the communication settings by address.
*
* @param {String} pAddressSql sql field or expression for the address id
* @return {CommunicationSettingsCondition} current object
*/
CommunicationSettingsCondition.prototype.address = function (pAddressSql)
{
this._channelType = $KeywordRegistry.communicationChannelType$address();
this._channelIdSql = pAddressSql;
return this;
}
/**
* Only fetch communication settings with the status 'rejected'
*
* @return {CommunicationSettingsCondition} current object
*/
CommunicationSettingsCondition.prototype.rejected = function ()
{
this._settingStatus = $KeywordRegistry.communicationSettingStatus$rejected();
return this;
}
/**
* Only fetch communication settings with the status 'allowed'
*
* @return {CommunicationSettingsCondition} current object
*/
CommunicationSettingsCondition.prototype.allowed = function ()
{
this._settingStatus = $KeywordRegistry.communicationSettingStatus$allowed();
return this;
}
/**
* Only fetch communication settings with the status 'pending'
*
* @return {CommunicationSettingsCondition} current object
*/
CommunicationSettingsCondition.prototype.pending = function ()
{
this._settingStatus = $KeywordRegistry.communicationSettingStatus$pending();
return this;
}
/**
* Builds a sub select for fetching the communication settings with the properies as configured.
*
* @param {String|Array} [pSelectFields=COMMUNICATIONSETTINGSID] columns to select
* @return {SqlBuilder} SqlBuilder object with the full sql select
*/
CommunicationSettingsCondition.prototype.buildSelect = function (pSelectFields)
{
if (pSelectFields == undefined)
pSelectFields = "COMMUNICATIONSETTINGS.COMMUNICATIONSETTINGSID";
var sql = newSelect(pSelectFields)
.from("COMMUNICATIONSETTINGS")
.where("COMMUNICATIONSETTINGS.CONTACT_ID = " + this._contactIdSql)
.andIfSet("COMMUNICATIONSETTINGS.STATUS", this._settingStatus);
var channelCondition = newWhere("COMMUNICATIONSETTINGS.CHANNEL_TYPE", $KeywordRegistry.communicationChannelType$global());
if (this._channelType)
{
var specificChannelCondition = newWhere("COMMUNICATIONSETTINGS.CHANNEL_TYPE", this._channelType)
.andIfSet("COMMUNICATIONSETTINGS.MEDIUM", this._medium);
if (this._channelIdSql)
{
specificChannelCondition.and(newWhere("COMMUNICATIONSETTINGS.CHANNEL_ID = " + this._channelIdSql)
.or("COMMUNICATIONSETTINGS.CHANNEL_ID is null"));
}
channelCondition.or(specificChannelCondition);
}
sql.and(channelCondition);
return sql;
}
/**
* Builds a sql condition for fetching only contacts with communication settings that have the configured properties.
*
* @return {SqlBuilder} sql condition
*/
CommunicationSettingsCondition.prototype.buildCondition = function ()
{
return newWhere(null, this.buildSelect(), this._existsOperator);
} }
/* required functionality: /* required functionality:
* - make communication settings condition * - make communication settings condition
* - make interest condition * - make interest condition
* - make blacklist condition * - make blacklist condition
* - make full condition * - make full condition
* - check for single contact * - check for single contact
*/ */
\ No newline at end of file
function CommunicationBlacklist ()
{
this.filter = null;
}
CommunicationBlacklist.getMailRecipientBlacklist = function ()
{
var currentDate = vars.get("$sys.date");
var filters = newSelect("BLACKLIST_FILTER")
.from("COMMUNICATIONBLACKLIST")
.where("COMMUNICATIONBLACKLIST.BLACKLIST_TYPE", $KeywordRegistry.communicationBlacklistType$contactFilter())
.and(newWhere("COMMUNICATIONBLACKLIST.START_DATE", currentDate, SqlBuilder.GREATER_OR_EQUAL())
.or("COMMUNICATIONBLACKLIST.START_DATE is null"))
.and(newWhere("COMMUNICATIONBLACKLIST.END_DATE", currentDate, SqlBuilder.LESS_OR_EQUAL()))
.or("COMMUNICATIONBLACKLIST.END_DATE is null")
.table();
var filterMappingFn = function ([blacklistFilter])
{
blacklistFilter = JSON.parse(blacklistFilter);
if (!blacklistFilter.filter || blacklistFilter.entity != "AnyContact" || Utils.isNullOrEmpty(blacklistFilter.filter.childs))
return null;
return blacklistFilter.filter;
};
var blacklist = new CommunicationBlacklist();
blacklist.filter = {
type: "group",
operator: "AND",
childs: filters.map(filterMappingFn).filter(Utils.isObject)
};
return blacklist;
}
CommunicationBlacklistCondition.prototype.buildCondition = function ()
{
return new FilterSqlTranslator()
.filter(this.filter)
.table("BULKMAILRECIPIENT")
.getSqlCondition();
}
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.2.2" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/process/1.2.2">
<name>MarketingCondition_test</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<process>%aditoprj%/process/MarketingCondition_test/process.js</process>
<variants>
<element>EXECUTABLE</element>
</variants>
</process>
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.2.2" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/process/1.2.2">
<name>SetCommunicationSetting_workflowService</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<process>%aditoprj%/process/SetCommunicationSetting_workflowService/process.js</process>
<alias>Data_alias</alias>
<variants>
<element>WORKFLOW</element>
</variants>
</process>
import("KeywordRegistry_basic");
import("system.vars");
var variables = JSON.parse(vars.get("$local.value"));
var contactId = variables.contactId || variables.targetId;
var channelType = variables.channelType;
var channelId = variables.channelId;
var status = variables.status || $KeywordRegistry.communicationSettingStatus$rejected();
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.2.2" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/process/1.2.2">
<name>SetInterestLink_workflowService</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<process>%aditoprj%/process/SetInterestLink_workflowService/process.js</process>
<alias>Data_alias</alias>
<variants>
<element>WORKFLOW</element>
</variants>
</process>
import("KeywordRegistry_basic");
import("system.vars");
import("system.util");
import("Sql_lib");
var variables = JSON.parse(vars.get("$local.value"));
var contactId = variables.contactId || variables.targetId;
var interestId = variables.interestId;
var status = variables.status || $KeywordRegistry.interestLinkStatus$notSubscribed();
var interestLinkId = new SqlBuilder()
.select("INTERESTLINKID")
.from("INTERESTLINK")
.where("INTERESTLINK.CONTACT_ID", contactId)
.and("INTERESTLINK.INTEREST_ID", interestId)
.and("INTERESTLINK.STATUS", status)
.cell();
if (interestLinkId)
{
newWhere("INTERESTLINK.INTERESTLINKID", interestLinkId)
.updateFields({"STATUS": status});
}
else
{
new SqlBuilder()
.tableName("INTERESTLINK")
.insertFields({
"INTERESTLINKID": util.getNewUUID(),
"INTEREST_ID": interestId,
"CONTACT_ID": contactId,
"STATUS": status
});
}
\ No newline at end of file
...@@ -1017,6 +1017,22 @@ SqlBuilder.prototype.selectDistinct = function (pFields) ...@@ -1017,6 +1017,22 @@ SqlBuilder.prototype.selectDistinct = function (pFields)
return this; return this;
} }
/**
* Sets the select clause to "select count(...)"
* @param {String} [pField=*] sql column to count, if omitted "count(*)" will be used
* @return {SqlBuilder} current SqlBuilder object
*/
SqlBuilder.prototype.selectCount = function (pField)
{
if (pField == undefined)
{
pField = "*";
}
this._select = SqlBuilder._getStatement(pField, "select count(", ")", true, true);
return this;
}
/** /**
* sets an alias-name which is added at some places if this SqlBuilder is used as subselect (e.g. in .select(), .join(), .from(), ...) * sets an alias-name which is added at some places if this SqlBuilder is used as subselect (e.g. in .select(), .join(), .from(), ...)
* @param {String} pSubselectAlias * @param {String} pSubselectAlias
......
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.2.2" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/process/1.2.2">
<name>gitLabWebhook_rest</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<process>%aditoprj%/process/gitLabWebhook_rest/process.js</process>
<publishAsWebservice v="true" />
<style>REST</style>
<restAcceptedMimeType>application/json</restAcceptedMimeType>
<restDeliveredMimeType>application/json</restDeliveredMimeType>
<loginTypeId>
<element>internal.none</element>
</loginTypeId>
<variants>
<element>EXECUTABLE</element>
</variants>
</process>
import("system.auth");
import("system.net");
import("system.util");
import("system.logging");
function restpost (pRequest)
{
var config = {
active: true,
gitlabToken: "youtube.com/watch?v=dQw4w9WgXcQ",
teamsUrl: "https://aditosoftware.webhook.office.com/webhookb2/85493214-0e4b-4577-8fc4-0e421a2dc196@c7308693-318b-4725-9e59-73b455c6ae05/IncomingWebhook/66a53e7f47c040eda146b372c742169b/70528b00-bbf1-45e2-9925-0cc55ff8951b",
push: {
active: true,
targetBranchRegExp: null
},
mergeRequest: {
active: true,
onlyUnassigned: true,
excludeWIP: true,
priorityLabels: ["critical"]
},
tag: {
active: true
}
};
logging.log(pRequest);
var request = JSON.parse(pRequest);
var secretToken = request.header["X-Gitlab-Token"] || request.header["X-gitlab-token"];
if (secretToken != config.gitlabToken)
{
request.response.httpStatusCode = 403;
return JSON.stringify(request);
}
var body = JSON.parse(util.decodeBase64String(request.body));
var teamsMessage = _getMessage(body, config);
if (teamsMessage)
{
var authConfig = auth.createConfigForNoAuth();
var restConfig = net.createConfigForRestWebserviceCall()
.actionType(net.POST)
.url(config.teamsUrl)
.dataTypeSend("application/json")
.dataTypeJDitoSend(util.DATA_TEXT)
.requestEntity(JSON.stringify(teamsMessage));
logging.log(JSON.stringify(teamsMessage))
net.callRestWebservice(restConfig, authConfig);
}
request.response.httpStatusCode = 200;
return JSON.stringify(request);
function _getMessage (pEvent, pConfig)
{
if (!pConfig.active)
return null;
var message = {
"@context": "https://schema.org/extensions",
"@type": "MessageCard",
"title": "Merged branch whatever into whatever",
"text": "-link- merged by That Guy",
"sections": [{
"activityTitle": "420 commits added"
}]
};
if (pEvent.object_kind == "push")
return _getPushMessage(pEvent, pConfig.push);
if (pEvent.object_kind == "merge_request")
return _getMergeRequestMessage(pEvent, pConfig.mergeRequest);
if (pEvent.object_kind == "tag_push")
return _getTagMessage(pEvent, pConfig.tag);
return null;
function _getPushMessage (pEvent, pConfig)
{
if (!pConfig.active)
return null;
return null;
}
function _getMergeRequestMessage (pEvent, pConfig)
{
if (!pConfig.active || pEvent.object_attributes.action != "open")
return null;
var info = pEvent.object_attributes;
var labels = pEvent.labels.map(function (label)
{
return label.title;
});
var isCritical = pConfig.priorityLabels.some(function (prioLabel) {return labels.includes(prioLabel);});
var isUnassigned = !pEvent.assignees || pEvent.assignees.length === 0;
var isMessageRequired = isCritical
|| ((!pConfig.onlyUnassigned || isUnassigned)
&& (!pConfig.excludeWIP || !info.work_in_progress))
if (!isMessageRequired)
return null;
var objectTitle = "Merge Request";
if (isCritical)
objectTitle = "Critical Merge Request";
else if (isUnassigned)
objectTitle = "Unassigned Merge Request";
var title = objectTitle + " opened by " + pEvent.user.name;
var message = {
"@context": "https://schema.org/extensions",
"@type": "MessageCard",
"summary": title,
"sections": [{
"activityTitle": title + " in <a href=\"" + pEvent.project.web_url + "\">" + pEvent.project.path_with_namespace + "</a>",
"activitySubtitle": "<a href=\"" + info.url + "\">!" + info.iid + "</a> " + info.title
+ " | Request to merge " + info.source_branch + " into " + info.target_branch
}]
};
if (isCritical)
message.themeColor = "F00420";
return message;
}
function _getTagMessage (pEvent, pConfig)
{
if (!pConfig.active)
return null;
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