Fixing contrib check and addressing comments

Signed-off-by: Matt Gilman <matt.c.gilman@gmail.com>
This commit is contained in:
Joe Percivall 2015-08-20 13:24:30 -04:00 committed by Matt Gilman
parent dedff148ca
commit b17be66a10
2 changed files with 13 additions and 26 deletions

View File

@ -27,7 +27,6 @@ import org.apache.nifi.annotation.behavior.WritesAttributes;
import org.apache.nifi.annotation.documentation.CapabilityDescription; import org.apache.nifi.annotation.documentation.CapabilityDescription;
import org.apache.nifi.annotation.documentation.Tags; import org.apache.nifi.annotation.documentation.Tags;
import org.apache.nifi.components.PropertyDescriptor; import org.apache.nifi.components.PropertyDescriptor;
import org.apache.nifi.components.PropertyValue;
import org.apache.nifi.flowfile.FlowFile; import org.apache.nifi.flowfile.FlowFile;
import org.apache.nifi.logging.ProcessorLog; import org.apache.nifi.logging.ProcessorLog;
import org.apache.nifi.processor.AbstractProcessor; import org.apache.nifi.processor.AbstractProcessor;
@ -61,8 +60,8 @@ import java.util.HashMap;
@SupportsBatching @SupportsBatching
public class ExtractImageMetadata extends AbstractProcessor { public class ExtractImageMetadata extends AbstractProcessor {
public static final PropertyDescriptor MaxAttributes = new PropertyDescriptor.Builder() public static final PropertyDescriptor MAX_NUMBER_OF_ATTRIBUTES = new PropertyDescriptor.Builder()
.name("Max number of attributes") .name("Max Number of Attributes")
.description("Specify the max number of attributes to add to the flowfile. There is no guarantee in what order" .description("Specify the max number of attributes to add to the flowfile. There is no guarantee in what order"
+ " the tags will be processed. By default it will process all of them.") + " the tags will be processed. By default it will process all of them.")
.required(false) .required(false)
@ -86,7 +85,7 @@ public class ExtractImageMetadata extends AbstractProcessor {
protected void init(final ProcessorInitializationContext context) { protected void init(final ProcessorInitializationContext context) {
final List<PropertyDescriptor> properties = new ArrayList<>(); final List<PropertyDescriptor> properties = new ArrayList<>();
properties.add(MaxAttributes); properties.add(MAX_NUMBER_OF_ATTRIBUTES);
this.properties = Collections.unmodifiableList(properties); this.properties = Collections.unmodifiableList(properties);
final Set<Relationship> relationships = new HashSet<>(); final Set<Relationship> relationships = new HashSet<>();
@ -107,16 +106,14 @@ public class ExtractImageMetadata extends AbstractProcessor {
@Override @Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
final ProcessorLog logger = this.getLogger();
FlowFile flowfile = session.get(); FlowFile flowfile = session.get();
if (flowfile == null) { if (flowfile == null) {
return; return;
} }
final ProcessorLog logger = this.getLogger();
final ObjectHolder<Metadata> value = new ObjectHolder<>(null); final ObjectHolder<Metadata> value = new ObjectHolder<>(null);
String propertyValue = context.getProperty(MaxAttributes).getValue(); final Integer max = context.getProperty(MAX_NUMBER_OF_ATTRIBUTES).asInteger();
final int max = propertyValue!=null ? Integer.parseInt(propertyValue) : -1;
try { try {
session.read(flowfile, new InputStreamCallback() { session.read(flowfile, new InputStreamCallback() {
@ -132,7 +129,7 @@ public class ExtractImageMetadata extends AbstractProcessor {
}); });
Metadata metadata = value.get(); Metadata metadata = value.get();
Map<String, String> results = max == -1 ? getTags(metadata) : getTags(max, metadata); Map<String, String> results = getTags(max, metadata);
// Write the results to an attribute // Write the results to an attribute
if (!results.isEmpty()) { if (!results.isEmpty()) {
@ -146,19 +143,7 @@ public class ExtractImageMetadata extends AbstractProcessor {
} }
} }
private Map<String, String> getTags(Metadata metadata) { private Map<String, String> getTags(Integer max, Metadata metadata) {
Map<String, String> results = new HashMap<>();
for (Directory directory : metadata.getDirectories()) {
for (Tag tag : directory.getTags()) {
results.put(directory.getName() + "." + tag.getTagName(), tag.getDescription());
}
}
return results;
}
private Map<String, String> getTags(int max, Metadata metadata) {
Map<String, String> results = new HashMap<>(); Map<String, String> results = new HashMap<>();
int i =0; int i =0;
@ -166,9 +151,11 @@ public class ExtractImageMetadata extends AbstractProcessor {
for (Tag tag : directory.getTags()) { for (Tag tag : directory.getTags()) {
results.put(directory.getName() + "." + tag.getTagName(), tag.getDescription()); results.put(directory.getName() + "." + tag.getTagName(), tag.getDescription());
i++; if(max!=null) {
if(i>=max) { i++;
return results; if (i >= max) {
return results;
}
} }
} }
} }

View File

@ -139,7 +139,7 @@ public class ExtractImageMetadataTest {
Path path = Paths.get(pathStr); Path path = Paths.get(pathStr);
testRunner.enqueue(path); testRunner.enqueue(path);
if(max != null) { if(max != null) {
testRunner.setProperty(ExtractImageMetadata.MaxAttributes, max); testRunner.setProperty(ExtractImageMetadata.MAX_NUMBER_OF_ATTRIBUTES, max);
} }
testRunner.run(); testRunner.run();