用属性值替换including the brackets中的字符串的最佳方法是什么?
{ "VoiceMessageTemplateEnglish“:”你好,我是LocationName打电话来确认AppointmentDate上有名字的约会。请按1确认,按2取消“,}
我尝试在JS中使用ExecuteScript处理器,但是没有任何运气。
谢谢!
发布于 2018-02-10 20:36:12
最后我使用JS解决了这个问题:
谢谢达吉特为我指明了正确的方向
var flowFile = session.get();if (flowFile != null) {
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();}
发布于 2018-02-09 09:12:15
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 << ffhttps://stackoverflow.com/questions/48699181
复制相似问题