nifi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pat Trainor <pat.trai...@gmail.com>
Subject How to create additional attributes in a flowfile?
Date Wed, 08 Jun 2016 02:48:06 GMT
Experts,  
  
I have figured out how to CHANGE a flowfile's attributes (make a new one), but
not how to ADD to it new attributes. My tinkering is at this level currently:

  

**@Override  
public void onTrigger(final ProcessContext context, final ProcessSession
session) throws ProcessException {  
FlowFile flowFileBefore = session.get();  
if ( flowFileBefore == null ) {  
    return;  
}  
// TODO implement  
//  
System.out.println("Received a flow file"); // I never see this... Where to
look?  
// String p = flowFile.getAttribute(MY_PROPERTY.getName()); // "My Property"**

**  
**

**

// This works, as long as I only change an existing (input) attribute...

// FlowFile flowFileAfter = session.putAttribute(flowFileBefore,"My Property",
"foo!");  

  

// I need to build a _complete_ descriptor, I'm thinking? (see below after
this method)

Map&lt;String, String&gt; mAfter = ListToMap(descriptors);  
mAfter.put("Third name", "Third Description"); // &lt;\--- doesn't make Nifi
happy!  
//  
FlowFile flowFileAfter = session.putAllAttributes(flowFileBefore, mAfter);  
session.transfer(flowFileAfter, MY_RELATIONSHIP);  
}**

**  
**

_Creating a descriptor (Attribute):_

**  
**

public static final PropertyDescriptor MY_PROPERTY2 = new PropertyDescriptor  
.Builder().name("My Property2")  
.description("Example Property2")  
.required(false)  
.build();**  
**

**  
**

It must be really simple, but even with me being simple, I'm just staring at
forum posts...

  

TIA!

  

Thanks!  
  

[pat](http://about.me/PatTrainor)  

( ͡° ͜ʖ ͡°)  

  

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message