@Override public void onPropertyModified(PropertyDescriptor descriptor, String oldValue, String newValue) { if (descriptor.isDynamic()) { if (!StringUtils.equals(oldValue, newValue)) { if (oldValue != null) { cachedJsonPathMap.remove(oldValue); } } } }
@Override public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) { if (descriptor.isDynamic()) { final Set<String> newDynamicPropertyNames = new HashSet<>(dynamicPropertyNames); if (newValue == null) { // removing a property newDynamicPropertyNames.remove(descriptor.getName()); } else if (oldValue == null) { // adding a new property newDynamicPropertyNames.add(descriptor.getName()); } this.dynamicPropertyNames = Collections.unmodifiableSet(newDynamicPropertyNames); } }
@OnScheduled public void initialize(final ProcessContext context) { attachments.clear(); for (Map.Entry<PropertyDescriptor, String> property : context.getProperties().entrySet()) { PropertyDescriptor descriptor = property.getKey(); if (descriptor.isDynamic()) { attachments.add(descriptor); } } }
@OnScheduled public void setup(final ProcessContext context) { userDefinedProperties = new ArrayList<>(); for (final PropertyDescriptor descriptor : context.getProperties().keySet()) { if (descriptor.isDynamic()) { userDefinedProperties.add(descriptor); } } }
@OnScheduled public void onScheduled(final ProcessContext context) { // Load up all the dynamic properties once for use later in onTrigger final Map<PropertyDescriptor, PropertyValue> dynamicProperties = new HashMap<>(); for (final Map.Entry<PropertyDescriptor, String> e : context.getProperties().entrySet()) { final PropertyDescriptor descriptor = e.getKey(); if (descriptor.isDynamic()) { final PropertyValue value = context.getProperty(descriptor); dynamicProperties.put(descriptor, value); } } this.dynamicProperties = Collections.unmodifiableMap(dynamicProperties); }
private Map<String, String> getDynamicAttributesMap(ProcessContext context, FlowFile flowFile) { final Map<String, String> attributes = new HashMap<>(); for (final Map.Entry<PropertyDescriptor, String> entry : context.getProperties().entrySet()) { if (entry.getKey().isDynamic()) { final String value = context.getProperty(entry.getKey()).evaluateAttributeExpressions(flowFile).getValue(); attributes.put(entry.getKey().getName(), value); } } return attributes; }
@Override public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) { if (descriptor.isDynamic()) { final Set<Relationship> relationships = new HashSet<>(this.relationships.get()); final Relationship relationship = new Relationship.Builder().name(descriptor.getName()).build(); if (newValue == null) { relationships.remove(relationship); } else { relationships.add(relationship); } this.relationships.set(relationships); } }
@OnEnabled public void onEnabled(final ConfigurationContext context) { final Map<String,DBCPService> serviceMap = new HashMap<>(); for (final PropertyDescriptor descriptor : context.getProperties().keySet()) { if (descriptor.isDynamic()) { final DBCPService dbcpService = context.getProperty(descriptor).asControllerService(DBCPService.class); serviceMap.put(descriptor.getName(), dbcpService); } } dbcpServiceMap = Collections.unmodifiableMap(serviceMap); }
@Override protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) { final boolean containsDynamic = validationContext.getProperties().keySet().stream() .anyMatch(property -> property.isDynamic()); if (containsDynamic) { return Collections.emptyList(); } return Collections.singleton(new ValidationResult.Builder() .subject("User-defined Properties") .valid(false) .explanation("At least one RecordPath must be specified") .build()); }
@OnScheduled public void createRecordPaths(final ProcessContext context) { recordPathCache = new RecordPathCache(context.getProperties().size() * 2); final List<String> recordPaths = new ArrayList<>(context.getProperties().size() - 2); for (final PropertyDescriptor property : context.getProperties().keySet()) { if (property.isDynamic()) { recordPaths.add(property.getName()); } } this.recordPaths = recordPaths; }
protected Map<String, RecordPath> getRecordPaths(ProcessContext context, FlowFile flowFile) { return context.getProperties().keySet() .stream().filter(p -> p.isDynamic()) .collect(Collectors.toMap( e -> e.getName(), e -> { String val = context.getProperty(e).evaluateAttributeExpressions(flowFile).getValue(); return cache.getCompiled(val); }) ); }
@Override protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) { final boolean hasDynamic = validationContext.getProperties().keySet().stream() .anyMatch(prop -> prop.isDynamic()); if (hasDynamic) { return Collections.emptyList(); } return Collections.singleton(new ValidationResult.Builder() .subject("User-defined Properties") .valid(false) .explanation("At least one RecordPath must be added to this processor by adding a user-defined property") .build()); }
private void buildHeaders(ConfigurationContext context) { headers = new HashMap<>(); for (PropertyDescriptor descriptor : context.getProperties().keySet()) { if (descriptor.isDynamic()) { headers.put( descriptor.getDisplayName(), context.getProperty(descriptor).evaluateAttributeExpressions().getValue() ); } } }
@Override public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) { if (!descriptor.isDynamic()) { return; } final Map<Relationship, HL7Query> updatedQueryMap = new HashMap<>(queries); final Relationship relationship = new Relationship.Builder().name(descriptor.getName()).build(); if (newValue == null) { updatedQueryMap.remove(relationship); } else { final HL7Query query = HL7Query.compile(newValue); updatedQueryMap.put(relationship, query); } this.queries = updatedQueryMap; }
@OnScheduled public synchronized void setupQueues(final ProcessContext context) { // Create a Queue of PreparedStatements for each property that is user-defined. This allows us to easily poll the // queue and add as necessary, knowing that the queue already exists. for (final PropertyDescriptor descriptor : context.getProperties().keySet()) { if (!descriptor.isDynamic()) { continue; } final String sql = context.getProperty(descriptor).evaluateAttributeExpressions().getValue(); final BlockingQueue<CachedStatement> queue = new LinkedBlockingQueue<>(context.getMaxConcurrentTasks()); statementQueues.put(sql, queue); } }
/** * Provides cleanup of the map for any JsonPath values that may have been created. This will remove common values shared between multiple instances, but will be regenerated when the next * validation cycle occurs as a result of isStale() * * @param processContext context */ @OnRemoved public void onRemoved(ProcessContext processContext) { for (PropertyDescriptor propertyDescriptor : getPropertyDescriptors()) { if (propertyDescriptor.isDynamic()) { cachedJsonPathMap.remove(processContext.getProperty(propertyDescriptor).getValue()); } } }
@Override public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) { if (!descriptor.isDynamic()) { return; } final Relationship relationship = new Relationship.Builder() .name(descriptor.getName()) .description("User-defined relationship that specifies where data that matches the specified SQL query should be routed") .build(); if (newValue == null) { relationships.remove(relationship); } else { relationships.add(relationship); } }
@Override protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) { final List<ValidationResult> results = new ArrayList<>(); if (validationContext.getProperty(TRANSLATE_CONTENT).asBoolean().equals(Boolean.FALSE)) { boolean foundDynamic = false; for (final PropertyDescriptor descriptor : validationContext.getProperties().keySet()) { if (descriptor.isDynamic()) { foundDynamic = true; break; } } if (!foundDynamic) { results.add(new ValidationResult.Builder().subject("Text to translate").input("<none>").valid(false) .explanation("Must either set 'Translate Content' to true or add at least one user-defined property").build()); } } return results; }
@Override protected Collection<ValidationResult> customValidate(final ValidationContext context) { final List<ValidationResult> results = new ArrayList<>(super.customValidate(context)); final String destination = context.getProperty(DESTINATION).getValue(); if (DESTINATION_CONTENT.equals(destination)) { int xpathCount = 0; for (final PropertyDescriptor desc : context.getProperties().keySet()) { if (desc.isDynamic()) { xpathCount++; } } if (xpathCount != 1) { results.add(new ValidationResult.Builder().subject("XPaths").valid(false) .explanation("Exactly one XPath must be set if using destination of " + DESTINATION_CONTENT).build()); } } return results; }
/** * When this processor is scheduled, update the dynamic properties into the map * for quick access during each onTrigger call * @param context ProcessContext used to retrieve dynamic properties */ @OnScheduled public void onScheduled(final ProcessContext context) { final Map<Relationship, PropertyValue> newPropertyMap = new HashMap<>(); for (final PropertyDescriptor descriptor : context.getProperties().keySet()) { if (!descriptor.isDynamic()) { continue; } getLogger().debug("Adding new dynamic property: {}", new Object[]{descriptor}); newPropertyMap.put(new Relationship.Builder().name(descriptor.getName()).build(), context.getProperty(descriptor)); } this.propertyMap = newPropertyMap; }