Sally,

I don't think you want a FlowFileFilter here, as your smaller flow
files will remain in the queue while the large enough ones get
processed. Here's a script that I think does what you want it to, but
please let me know if I've misunderstood your intent:

def ffList = session.get(1000)
def largeEnough = ffList.findAll {ff -> ff.size > 831}
def lastLargeEnough = largeEnough ? largeEnough.pop() : null
def notLargeEnough = ffList.findAll {ff -> ff.size <= 831}

if(notLargeEnough) session.remove(notLargeEnough)
if(largeEnough) session.remove(largeEnough)
if(lastLargeEnough) session.transfer(lastLargeEnough, REL_SUCCESS)


This script gets up to 1000 flow files at a time, finds the ones that
are large enough, saves off the last one (if present), then transfers
it to success, while removing the flow files that aren't large enough
or weren't the last of the large enough ones.

Regards,
Matt

On Thu, Dec 7, 2017 at 7:12 AM, sally <[email protected]> wrote:
> I want to get all flowfile from the queu which fileSize is greater than 831
> and then put them into the list after that catch last flowfile from the list
> and transfer to success relationship and finally remove all other flowfiles
> , here is my code which throws exception that transfer relationship not
> specified , what should i change in this case?
>
>
> import org.apache.nifi.processor.FlowFileFilter;
> import groovy.json.JsonSlurper
> import groovy.json.JsonBuilder
> import java.nio.charset.StandardCharsets
> import org.apache.commons.io.IOUtils
>
> def flowFile = session.get()
> def  n=0;
> if(!flowFile)return
> def size = flowFile.getAttribute('fileSize');
> log.error(size.toString())
> int value = size as Integer;
>
> if((value/831)>1){
> def ffList = session.get(new FlowFileFilter(){
>     public FlowFileFilterResult filter(FlowFile ff) {
>
>         if( size == ff.getAttribute('fileSize') ) n++; return
> FlowFileFilterResult.ACCEPT_AND_CONTINUE
>         return FlowFileFilterResult.REJECT_AND_CONTINUE
>     }
>
> })
> session.transfer(ffList.get(n-1),REL_SUCCESS)
> //session.remove(ffList);
> }
> session.remove(flowFile);
>
>
>
>
> --
> Sent from: http://apache-nifi-users-list.2361937.n4.nabble.com/

Reply via email to