Java Code Examples for org.apache.nifi.processor.ProcessContext#getProperties()
The following examples show how to use
org.apache.nifi.processor.ProcessContext#getProperties() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenerateFlowFile.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) { final byte[] data; if (context.getProperty(UNIQUE_FLOWFILES).asBoolean()) { data = generateData(context); } else if(context.getProperty(CUSTOM_TEXT).isSet()) { data = context.getProperty(CUSTOM_TEXT).evaluateAttributeExpressions().getValue().getBytes(); } else { data = this.data.get(); } Map<PropertyDescriptor, String> processorProperties = context.getProperties(); Map<String, String> generatedAttributes = new HashMap<String, String>(); for (final Map.Entry<PropertyDescriptor, String> entry : processorProperties.entrySet()) { PropertyDescriptor property = entry.getKey(); if (property.isDynamic() && property.isExpressionLanguageSupported()) { String dynamicValue = context.getProperty(property).evaluateAttributeExpressions().getValue(); generatedAttributes.put(property.getName(), dynamicValue); } } for (int i = 0; i < context.getProperty(BATCH_SIZE).asInteger(); i++) { FlowFile flowFile = session.create(); if (data.length > 0) { flowFile = session.write(flowFile, new OutputStreamCallback() { @Override public void process(final OutputStream out) throws IOException { out.write(data); } }); } flowFile = session.putAllAttributes(flowFile, generatedAttributes); session.getProvenanceReporter().create(flowFile); session.transfer(flowFile, SUCCESS); } }
Example 2
Source File: TestExtractMediaMetadata.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testProperties() { final TestRunner runner = TestRunners.newTestRunner(new ExtractMediaMetadata()); ProcessContext context = runner.getProcessContext(); Map<PropertyDescriptor, String> propertyValues = context.getProperties(); assertEquals(4, propertyValues.size()); }
Example 3
Source File: TestExtractMediaMetadata.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testProperties() { final TestRunner runner = TestRunners.newTestRunner(new ExtractMediaMetadata()); ProcessContext context = runner.getProcessContext(); Map<PropertyDescriptor, String> propertyValues = context.getProperties(); assertEquals(4, propertyValues.size()); }
Example 4
Source File: GenerateFlowFile.java From nifi with Apache License 2.0 | 4 votes |
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) { final byte[] data; if (context.getProperty(UNIQUE_FLOWFILES).asBoolean()) { data = generateData(context); } else if(context.getProperty(CUSTOM_TEXT).isSet()) { final Charset charset = Charset.forName(context.getProperty(CHARSET).getValue()); data = context.getProperty(CUSTOM_TEXT).evaluateAttributeExpressions().getValue().getBytes(charset); } else { data = this.data.get(); } Map<PropertyDescriptor, String> processorProperties = context.getProperties(); Map<String, String> generatedAttributes = new HashMap<String, String>(); for (final Map.Entry<PropertyDescriptor, String> entry : processorProperties.entrySet()) { PropertyDescriptor property = entry.getKey(); if (property.isDynamic() && property.isExpressionLanguageSupported()) { String dynamicValue = context.getProperty(property).evaluateAttributeExpressions().getValue(); generatedAttributes.put(property.getName(), dynamicValue); } } if(context.getProperty(MIME_TYPE).isSet()) { generatedAttributes.put(CoreAttributes.MIME_TYPE.key(), context.getProperty(MIME_TYPE).getValue()); } for (int i = 0; i < context.getProperty(BATCH_SIZE).asInteger(); i++) { FlowFile flowFile = session.create(); if (data.length > 0) { flowFile = session.write(flowFile, new OutputStreamCallback() { @Override public void process(final OutputStream out) throws IOException { out.write(data); } }); } flowFile = session.putAllAttributes(flowFile, generatedAttributes); session.getProvenanceReporter().create(flowFile); session.transfer(flowFile, SUCCESS); } }