Apache NiFi 文本替换
Apache NiFi Text Replacement
用属性值替换 [](包括方括号)中的字符串的最佳方法是什么?
{
"VoiceMessageTemplateEnglish" : "Hello, this is [LocationName] calling to confirm an appointment for [Name] on [AppointmentDate] at [AppointmentTime] with [Name]. Please press 1 To confirm, Press 2 To Cancel",
}
我尝试在 JS 中使用 ExecuteScript 处理器,但没有成功。
谢谢!
nifi 1.5.0 中的处理器 ExecuteGroovyScript
def ff = session.get()
if(!ff)return
def attr = ff.getAttributes()
def text = ff.read().getText("UTF-8")
text = text.replaceAll( /\[(\w+)\]/ ) { attr[it[1]] ?: "noValue" }
ff.write("UTF-8", text)
REL_SUCCESS << ff
最后我用JS解决了问题:
感谢@daggett 为我指明了正确的方向
var 流文件 = session.get();
如果(流文件!=空){
var lclAppointmentDate = flowFile.getAttribute("AppointmentDate");
var lclAppointmentStartTime = flowFile.getAttribute("AppointmentStartTime");
var lclName = flowFile.getAttribute("Name");
var lclVoiceMailTemplate = flowFile.getAttribute("VoiceMailTemplate");
if (lclVoiceMailTemplate != null){
lclVoiceMailTemplate = lclVoiceMailTemplate
.replace('[Name]', lclName)
.replace('[AppointmentDate]', lclAppointmentDate)
.replace('[AppointmentTime]', lclAppointmentStartTime);
flowFile = session.putAttribute(flowFile, "FinalVoiceMailTemplate", lclVoiceMailTemplate);
}
session.transfer(flowFile, REL_SUCCESS);
session.commit();
}
用属性值替换 [](包括方括号)中的字符串的最佳方法是什么?
{ "VoiceMessageTemplateEnglish" : "Hello, this is [LocationName] calling to confirm an appointment for [Name] on [AppointmentDate] at [AppointmentTime] with [Name]. Please press 1 To confirm, Press 2 To Cancel", }
我尝试在 JS 中使用 ExecuteScript 处理器,但没有成功。
谢谢!
nifi 1.5.0 中的处理器 ExecuteGroovyScript
def ff = session.get()
if(!ff)return
def attr = ff.getAttributes()
def text = ff.read().getText("UTF-8")
text = text.replaceAll( /\[(\w+)\]/ ) { attr[it[1]] ?: "noValue" }
ff.write("UTF-8", text)
REL_SUCCESS << ff
最后我用JS解决了问题:
感谢@daggett 为我指明了正确的方向
var 流文件 = session.get(); 如果(流文件!=空){
var lclAppointmentDate = flowFile.getAttribute("AppointmentDate");
var lclAppointmentStartTime = flowFile.getAttribute("AppointmentStartTime");
var lclName = flowFile.getAttribute("Name");
var lclVoiceMailTemplate = flowFile.getAttribute("VoiceMailTemplate");
if (lclVoiceMailTemplate != null){
lclVoiceMailTemplate = lclVoiceMailTemplate
.replace('[Name]', lclName)
.replace('[AppointmentDate]', lclAppointmentDate)
.replace('[AppointmentTime]', lclAppointmentStartTime);
flowFile = session.putAttribute(flowFile, "FinalVoiceMailTemplate", lclVoiceMailTemplate);
}
session.transfer(flowFile, REL_SUCCESS);
session.commit();
}