user7516956
user7516956

Reputation:

Extracting text from nifi flowfile and usig it as an argument

I have groovy code like this and i want to extract the value of TickSolution and then use it as an argument for invoking service , which nifi processors should i use to make this task?

import java.nio.charset.StandardCharsets 
import org.apache.commons.io.IOUtils
import org.apache.nifi.processor.io.StreamCallback
import java.text.SimpleDateFormat
import java.util.GregorianCalendar

def flowfile = session.get()
if(!flowfile) return
def date=flowfile.getAttribute('fromDate')
 SimpleDateFormat format=new SimpleDateFormat("yyyy-mm-dd");
  def d=new Date(format.parse(date).getTime());
  def newdate=new GregorianCalendar(d.getYear(),d.getMonth(),d.getDay() )
 def TICKS_AT_EPOCH = 621355968000000000;
 def TICKS_PER_MILLISECOND= 10000;
  def TickSolution=(newdate.getTimeInMillis() - TICKS_AT_EPOCH) / TICKS_PER_MILLISECOND

flowfile = session.putAttribute(flowfile, 'filename','Info'+'_'+date)
session.transfer(flowfile, REL_SUCCESS)

Upvotes: 1

Views: 582

Answers (1)

Mahendran V M
Mahendran V M

Reputation: 3496

Sally,

You can try below code to process value of TickSolution.

import java.nio.charset.StandardCharsets 
import org.apache.commons.io.IOUtils
import org.apache.nifi.processor.io.StreamCallback
import java.text.SimpleDateFormat
import java.util.GregorianCalendar

def flowfile = session.get()
if(!flowfile) return
def date=flowfile.getAttribute('fromDate')
 SimpleDateFormat format=new SimpleDateFormat("yyyy-mm-dd");
  def d=new Date(format.parse(date).getTime());
  def newdate=new GregorianCalendar(d.getYear(),d.getMonth(),d.getDay() )
 def TICKS_AT_EPOCH = 621355968000000000;
 def TICKS_PER_MILLISECOND= 10000;
  def TickSolution=(newdate.getTimeInMillis() - TICKS_AT_EPOCH) / TICKS_PER_MILLISECOND

flowfile = session.putAttribute(flowfile, 'filename','Info'+'_'+date)
flowfile=session.putAttribute(flowfile,'TickSolution',TickSolution)
session.transfer(flowfile, REL_SUCCESS)

please let me know if you face any issues.

Upvotes: 1

Related Questions