Search in sources :

Example 26 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project nifi by apache.

the class MockPropertyValue method evaluateAttributeExpressions.

@Override
public PropertyValue evaluateAttributeExpressions(FlowFile flowFile, Map<String, String> additionalAttributes, AttributeValueDecorator decorator, Map<String, String> stateValues) throws ProcessException {
    markEvaluated();
    if (rawValue == null) {
        return this;
    }
    final PropertyValue newValue = stdPropValue.evaluateAttributeExpressions(flowFile, additionalAttributes, decorator, stateValues);
    return new MockPropertyValue(newValue.getValue(), serviceLookup, propertyDescriptor, true, variableRegistry);
}
Also used : StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue)

Example 27 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project nifi by apache.

the class PutHDFS method preProcessConfiguration.

@Override
protected void preProcessConfiguration(final Configuration config, final ProcessContext context) {
    // Set umask once, to avoid thread safety issues doing it in onTrigger
    final PropertyValue umaskProp = context.getProperty(UMASK);
    final short dfsUmask;
    if (umaskProp.isSet()) {
        dfsUmask = Short.parseShort(umaskProp.getValue(), 8);
    } else {
        dfsUmask = FsPermission.DEFAULT_UMASK;
    }
    FsPermission.setUMask(config, new FsPermission(dfsUmask));
}
Also used : PropertyValue(org.apache.nifi.components.PropertyValue) FsPermission(org.apache.hadoop.fs.permission.FsPermission)

Example 28 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project nifi by apache.

the class CompositeUserGroupProviderTestBase method mockProperties.

protected void mockProperties(final AuthorizerConfigurationContext configurationContext) {
    when(configurationContext.getProperties()).then((invocation) -> {
        final Map<String, String> properties = new HashMap<>();
        int i = 1;
        while (true) {
            final String key = PROP_USER_GROUP_PROVIDER_PREFIX + i++;
            final PropertyValue value = configurationContext.getProperty(key);
            if (value == null) {
                break;
            } else {
                properties.put(key, value.getValue());
            }
        }
        return properties;
    });
}
Also used : HashMap(java.util.HashMap) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue)

Example 29 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project nifi by apache.

the class CSVUtils method buildCustomFormat.

private static CSVFormat buildCustomFormat(final PropertyContext context) {
    final char valueSeparator = getUnescapedChar(context, VALUE_SEPARATOR);
    CSVFormat format = CSVFormat.newFormat(valueSeparator).withAllowMissingColumnNames().withIgnoreEmptyLines();
    final PropertyValue skipHeaderPropertyValue = context.getProperty(FIRST_LINE_IS_HEADER);
    if (skipHeaderPropertyValue.getValue() != null && skipHeaderPropertyValue.asBoolean()) {
        format = format.withFirstRecordAsHeader();
    }
    format = format.withQuote(getChar(context, QUOTE_CHAR));
    format = format.withEscape(getChar(context, ESCAPE_CHAR));
    format = format.withTrim(context.getProperty(TRIM_FIELDS).asBoolean());
    if (context.getProperty(COMMENT_MARKER).isSet()) {
        format = format.withCommentMarker(getChar(context, COMMENT_MARKER));
    }
    if (context.getProperty(NULL_STRING).isSet()) {
        format = format.withNullString(CSVUtils.unescape(context.getProperty(NULL_STRING).getValue()));
    }
    final PropertyValue quoteValue = context.getProperty(QUOTE_MODE);
    if (quoteValue != null) {
        final QuoteMode quoteMode = QuoteMode.valueOf(quoteValue.getValue());
        format = format.withQuoteMode(quoteMode);
    }
    final PropertyValue trailingDelimiterValue = context.getProperty(TRAILING_DELIMITER);
    if (trailingDelimiterValue != null) {
        final boolean trailingDelimiter = trailingDelimiterValue.asBoolean();
        format = format.withTrailingDelimiter(trailingDelimiter);
    }
    final PropertyValue recordSeparator = context.getProperty(RECORD_SEPARATOR);
    if (recordSeparator != null) {
        final String separator = unescape(recordSeparator.getValue());
        format = format.withRecordSeparator(separator);
    }
    return format;
}
Also used : QuoteMode(org.apache.commons.csv.QuoteMode) PropertyValue(org.apache.nifi.components.PropertyValue) CSVFormat(org.apache.commons.csv.CSVFormat)

Example 30 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project nifi by apache.

the class TestSchemaNamePropertyStrategy method testNameAndVersion.

@Test
public void testNameAndVersion() throws SchemaNotFoundException, IOException {
    final PropertyValue nameValue = new MockPropertyValue("person");
    final PropertyValue branchValue = new MockPropertyValue(null);
    final PropertyValue versionValue = new MockPropertyValue("1");
    final SchemaNamePropertyStrategy schemaNamePropertyStrategy = new SchemaNamePropertyStrategy(schemaRegistry, nameValue, branchValue, versionValue);
    final SchemaIdentifier expectedSchemaIdentifier = SchemaIdentifier.builder().name(nameValue.getValue()).version(versionValue.asInteger()).build();
    when(schemaRegistry.retrieveSchema(argThat(new SchemaIdentifierMatcher(expectedSchemaIdentifier)))).thenReturn(recordSchema);
    final RecordSchema retrievedSchema = schemaNamePropertyStrategy.getSchema(Collections.emptyMap(), null, recordSchema);
    assertNotNull(retrievedSchema);
}
Also used : MockPropertyValue(org.apache.nifi.util.MockPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) SchemaIdentifier(org.apache.nifi.serialization.record.SchemaIdentifier) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) Test(org.junit.Test)

Aggregations

PropertyValue (org.apache.nifi.components.PropertyValue)73 HashMap (java.util.HashMap)29 Test (org.junit.Test)22 StandardPropertyValue (org.apache.nifi.attribute.expression.language.StandardPropertyValue)21 ComponentLog (org.apache.nifi.logging.ComponentLog)18 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)16 IOException (java.io.IOException)15 Map (java.util.Map)13 FlowFile (org.apache.nifi.flowfile.FlowFile)11 ProcessException (org.apache.nifi.processor.exception.ProcessException)11 MockPropertyValue (org.apache.nifi.util.MockPropertyValue)11 ArrayList (java.util.ArrayList)9 SSLContext (javax.net.ssl.SSLContext)7 Relationship (org.apache.nifi.processor.Relationship)7 AuthorizerCreationException (org.apache.nifi.authorization.exception.AuthorizerCreationException)6 File (java.io.File)5 DynamicRelationship (org.apache.nifi.annotation.behavior.DynamicRelationship)5 RecordSchema (org.apache.nifi.serialization.record.RecordSchema)5 SchemaIdentifier (org.apache.nifi.serialization.record.SchemaIdentifier)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5