Java Code Examples for org.apache.nifi.components.PropertyValue#isExpressionLanguagePresent()

The following examples show how to use org.apache.nifi.components.PropertyValue#isExpressionLanguagePresent() . 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: SchemaRegistryRecordSetWriter.java    From nifi with Apache License 2.0 6 votes vote down vote up
@OnEnabled
public void storeSchemaWriteStrategy(final ConfigurationContext context) {
    this.configurationContext = context;

    // If Schema Protocol Version is specified without EL then we can create it up front, otherwise when
    // EL is present we will re-create it later so we can re-evaluate the EL against the incoming variables

    final String strategy = context.getProperty(getSchemaWriteStrategyDescriptor()).getValue();
    if (strategy != null) {
        final RecordSchemaCacheService recordSchemaCacheService = context.getProperty(SCHEMA_CACHE).asControllerService(RecordSchemaCacheService.class);

        final PropertyValue protocolVersionValue = getConfigurationContext().getProperty(SCHEMA_PROTOCOL_VERSION);
        if (!protocolVersionValue.isExpressionLanguagePresent()) {
            final int protocolVersion = context.getProperty(SCHEMA_PROTOCOL_VERSION).asInteger();
            this.schemaAccessWriter = createSchemaWriteStrategy(strategy, protocolVersion, recordSchemaCacheService);
        }
    }
}
 
Example 2
Source File: SchemaRegistryRecordSetWriter.java    From nifi with Apache License 2.0 6 votes vote down vote up
protected SchemaAccessWriter getSchemaAccessWriter(final RecordSchema schema, final Map<String,String> variables) throws SchemaNotFoundException {
    // If Schema Protocol Version is using expression language, then we reevaluate against the passed in variables
    final PropertyValue protocolVersionValue = getConfigurationContext().getProperty(SCHEMA_PROTOCOL_VERSION);
    if (protocolVersionValue.isExpressionLanguagePresent()) {
        final int protocolVersion;
        final String protocolVersionString = protocolVersionValue.evaluateAttributeExpressions(variables).getValue();
        try {
            protocolVersion = Integer.parseInt(protocolVersionString);
        } catch (NumberFormatException nfe) {
            throw new SchemaNotFoundException("Unable to create Schema Write Strategy because " + SCHEMA_PROTOCOL_VERSION.getDisplayName()
                    + " must be a positive integer, but was '" + protocolVersionString + "'", nfe);
        }

        // Now recreate the SchemaAccessWriter since we may have a new value for Schema Protocol Version
        final String strategy = getConfigurationContext().getProperty(getSchemaWriteStrategyDescriptor()).getValue();
        if (strategy != null) {
            final RecordSchemaCacheService recordSchemaCacheService = getConfigurationContext().getProperty(SCHEMA_CACHE).asControllerService(RecordSchemaCacheService.class);
            schemaAccessWriter = createSchemaWriteStrategy(strategy, protocolVersion, recordSchemaCacheService);
        }
    }

    schemaAccessWriter.validateSchema(schema);
    return schemaAccessWriter;
}
 
Example 3
Source File: GenerateTableFetch.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
    List<ValidationResult> results = new ArrayList<>(super.customValidate(validationContext));
    final PropertyValue columnForPartitioning = validationContext.getProperty(COLUMN_FOR_VALUE_PARTITIONING);
    // If no EL is present, ensure it's a single column (i.e. no commas in the property value)
    if (columnForPartitioning.isSet() && !columnForPartitioning.isExpressionLanguagePresent() && columnForPartitioning.getValue().contains(",")) {
        results.add(new ValidationResult.Builder().valid(false).explanation(
                COLUMN_FOR_VALUE_PARTITIONING.getDisplayName() + " requires a single column name, but a comma was detected").build());
    }

    return results;
}
 
Example 4
Source File: FetchDistributedMapCache.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
    List<ValidationResult> results = new ArrayList<>(super.customValidate(validationContext));

    PropertyValue cacheEntryIdentifier = validationContext.getProperty(PROP_CACHE_ENTRY_IDENTIFIER);
    boolean elPresent = false;
    try {
        elPresent = cacheEntryIdentifier.isExpressionLanguagePresent();
    } catch (NullPointerException npe) {
        // Unfortunate workaround to a mock framework bug (NIFI-4590)
    }

    if (elPresent) {
        // This doesn't do a full job of validating against the requirement that Put Cache Value In Attribute must be set if multiple
        // Cache Entry Identifiers are supplied (if Expression Language is used). The user could conceivably have a comma-separated list of EL statements,
        // or a single EL statement with commas inside it but that evaluates to a single item.
        results.add(new ValidationResult.Builder().valid(true).explanation("Contains Expression Language").build());
    } else {
        if (!validationContext.getProperty(FetchDistributedMapCache.PROP_PUT_CACHE_VALUE_IN_ATTRIBUTE).isSet()) {
            String identifierString = cacheEntryIdentifier.getValue();
            if (identifierString.contains(",")) {
                results.add(new ValidationResult.Builder().valid(false)
                        .explanation("Multiple Cache Entry Identifiers specified without Put Cache Value In Attribute set").build());
            }
        }
    }
    return results;
}
 
Example 5
Source File: TestStandardPropertyValue.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testisExpressionLanguagePresentShouldHandleNPE() {
    // Arrange
    final PropertyValue value = new StandardPropertyValue(null, lookup, ParameterLookup.EMPTY, null, null);

    // Act
    boolean elPresent = value.isExpressionLanguagePresent();

    // Assert
    assertFalse(elPresent);
}