๐ปTech/๐งnifi
[NiFi] Groovy-Java๋ก ์ฌ๋ฌ ๋ ์ง ๋ฝ๋ ๋ฐฉ๋ฒ
_viper_
2022. 9. 22. 11:14
๋ฐ์ํ
NiFi์์ ์ ๊ณตํ๋ Groovy Script๋ ์๋ฐ ํธํ์ด ๊ฑฐ์ ๋๋ฏ๋ก ์๋ฐ ์ฝ๋๋ก ์์ฑํ์ฌ๋ ์ ๋์๊ฐ
- Create ExecuteScript Processor
- PROPERTIES > Select Groovy > Write Script Body
- Script Contents
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
//attribute์ ๋ ์ง(yyyymmdd) ๊ธฐ์ค๋ถํฐ -30์ผ๊น์ง ์ถ์ถ
flowFile = session.get();
if(!flowFile) return;
dt = flowFile.getAttribute('dt');
session.transfer(flowFile, REL_SUCCESS);
for(int i=0; i<31; i++){
DateFormat dateFormat = null;
Date date = new Date();
try {
dateFormat = new SimpleDateFormat("yyyyMMdd");
date = dateFormat.parse(part_dt);
}catch(Exception e){
System.out.println(e.getMessage());
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, -i);
dt = dateFormat.format(cal.getTime());
flowFile = session.create();
newFlowFile = session.putAttribute(flowFile, 'dt', dt);
session.transfer(newFlowFile, REL_SUCCESS);
}