Created 09-28-2017 10:53 AM
I have attribute names like startDate:2017-09-07 and endDate:2017-09-16 i want to reitrive data with this parameters and after writing response into the base i want to change this parameter i mean (startDate:2017-09-07 and endDate:2017-09-16 with 2017-09-17 and 2017-09-24) i tried this ecmascript code:
<code> var OutputStreamCallback = Java.type("org.apache.nifi.processor.io.OutputStreamCallback"); var StandardCharsets = Java.type("java.nio.charset.StandardCharsets"); Date.prototype.isValid = function () { return (Object.prototype.toString.call(this) === "[object Date]") && !isNaN(this.getTime()); }; function addDays(date, days) { var result =new Date(date); result.setDate(result.getDate() + days); var dateFormated = result.toISOString().substr(0,10); return formatDate(dateFormated); } function formatDate(date) { var d = new Date(date), month = '' + (d.getMonth() + 1), day = '' + d.getDate(), year = d.getFullYear(); if (month.length < 2) month = '0' + month; if (day.length < 2) day = '0' + day; return [year, month, day].join('-'); } var startDate = startDate.getValue(), endDate = endDate.getValue(), parametr=parameter.getValue(), count=count.getValue(); var flowFile = session.crete(); var param=8; var endDate = addDays(end, param*count); var startDate = formatDate(newStart); flowFile = session.putAttribute(flowFile, 'startDate', startDate); flowFile = session.putAttribute(flowFile, 'endDate', endDate); session.transfer(flowFile, REL_SUCCESS)
but i don't know how can i make my code known when it should increase count in order to change endDate and startTdate manually and replace it with valid startDate and EndDate is there any service or processor i can use to simplify this task?
Created on 09-28-2017 02:06 PM - edited 08-17-2019 10:18 PM
You can use a distributedcache to write startdate and enddate values. The retrieve those from the distributecache using fetchdistributedcache. I have a sample setting attached for fetchdistributemapcache. Once you are done incrementing the new value, you can push it back to the cache using putdistributemapcache.
Created 09-28-2017 02:27 PM
@Karthik Narayanan can you link me any article or example of how can i use it?
Created 09-28-2017 02:28 PM
I mean how can i use distributedCashService
Created 09-28-2017 02:30 PM