Hello Wodnicki, here is the code of my topology rule.
var exceptionBUList = ["WTCRU","WTCUA" ,"WTCTR" , "SRU"];
var sg = new StringGroup("nms:core");
var debug = 1;
//-------------------------------------------------------------------
// Constructor
//-------------------------------------------------------------------
function aswPrivacyURLPolicy(){
}
//-------------------------------------------------------------------
// Return the Privacy URL for the BU to which delivery belongs to
// @return : privacy URL for a BU
//-------------------------------------------------------------------
aswPrivacyURLPolicy.prototype.getURL = function(deliveryId) {
var query = xtk.queryDef.create(
<queryDef schema="nms:delivery" operation="get">
<select>
<node expr="[operation/@bu_Code]" alias="@buCode"/>
<node expr="@Lang_id" alias="@langId"/>
</select>
<where>
<condition expr={"@id = " + deliveryId}/>
</where>
</queryDef>
);
var res = query.ExecuteQuery();
this.buCode = res.@buCode.toString();
this.langId=res.@langId.toString();
var privacyURL = "";
switch (this.buCode){
case "KVF":
privacyURL = "https://www.kruidvat.fr/confidentialite";
break;
case "KVB":
{
if (this.langId === "NLD")
privacyURL = "https://www.kruidvat.be/nl/privacybeleid";
if (this.langId === "FRB")
privacyURL = "https://www.kruidvat.be/fr/politiquedeconfidentialite"
};
break;
case "KVN":
privacyURL = "https://www.kruidvat.nl/privacybeleid";
break;
default:
privacyURL = "";
} //End - switch (this.buCode)
if (debug) logInfo('URL:#' + privacyURL + '#');
this.privacyURL=privacyURL;
query = null;
res = null;
}
//-------------------------------------------------------------------
// Check if BU is part of exception list for which GDPR is not mandatory
// @return : true if BU belongs to exception list
//-------------------------------------------------------------------
aswPrivacyURLPolicy.prototype.ifExceptionBU = function() {
var exception = false;
for (index = 0; index < exceptionBUList.length; index++) {
if (this.buCode === exceptionBUList[index]){
exception = true;
return exception;
}//End - (this.buCode === exceptionBUList[index])
}//End - for
if (debug) logInfo("Is Exception BU = " + exception);
return exception;
}
//-------------------------------------------------------------------
// Check for the presence of privacy URL in the URL list
// @return message:
// true - found
// false - Not found
//-------------------------------------------------------------------
aswPrivacyURLPolicy.prototype.checkUrlSource = function(urlList, strContent, privURL)
{
for( var i=0 ; i<urlList.length ; i++ ){
if( urlList[i].trackingType != 1 && urlList[i].trackingType != 3 ){
// check an URL
var url = urlList[i].source;
if (debug) logInfo('FOUNDURL: '+url+'+index='+url.indexOf(privURL));
if( url.indexOf(privURL) > -1 ){
if (debug) logInfo('urlcheckreturntrue');
return true;
}//End - if( url.indexOf(privURL) > -1 )
} //End-if( urlList[i].trackingType != 1 && urlList[i].trackingType != 3 )
}//End - for
return false;
}
//-------------------------------------------------------------------
// Audit a delivery to check for inclusion of privacy URL
// @return message:
// Empty String - Success
// message- Error or Warning
//-------------------------------------------------------------------
aswPrivacyURLPolicy.prototype.auditDelivery = function(deliveryId) {
if (debug) logInfo("Applying Typlogy rule aswPrivacyURLPolicy");
this.getURL(deliveryId);
var message = "Typology aswPrivacyLinkValidation: Missing Privacy URL:" + this.privacyURL + " for BU:"+ this.buCode + " and Language:" + this.langId;
//Set default log level to warning for BU's in exception list else set default to Error
if(this.privacyURL.length == 0){
return message;
}
if(delivery.deliveryMode ==0){
message = "";
return message;
}
var sourceHTML = delivery.content.html.source;
var sourceText = delivery.content.text.source;
//logInfo("sourceHTML = " + sourceHTML);
var bSucessText = false;
var bSucessHtml = false;
if( !delivery.tracking.enabled ){
// nothing to do if tracking is disabled
bSucessText = null;
bSucessText = null;
message = "";
return message;
}
var bSucessText = this.checkUrlSource(delivery.content.text.urlConfig.url, "TEXT", this.privacyURL);
var bSucessHtml = this.checkUrlSource(delivery.content.html.urlConfig.url, "HTML", this.privacyURL);
if( bSucessText && bSucessHtml ){
if (debug) logInfo('Success! Returning Success');
bSucessText = null;
bSucessText = null;
message = "";
return message;
}
if (debug) logInfo('Failure! Returning Error Message');
return message;
}