org.apache.nifi.components.PropertyValue Java Examples

The following examples show how to use org.apache.nifi.components.PropertyValue. 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: UpdateAttributeCreateOwnProperty.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
    FlowFile flowFile = session.get();
    if (flowFile == null) {
        return;
    }

    for (final String propertyName : context.getAllProperties().keySet()) {
        final String propertyValue = context.getProperty(propertyName).getValue();
        final PropertyValue propValue = context.newPropertyValue(propertyValue);
        final String evaluated = propValue.evaluateAttributeExpressions(flowFile).getValue();
        flowFile = session.putAttribute(flowFile, propertyName, evaluated);
    }

    session.transfer(flowFile, REL_SUCCESS);
}
 
Example #2
Source File: SchemaAccessUtils.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static SchemaAccessStrategy getSchemaAccessStrategy(final String allowableValue, final SchemaRegistry schemaRegistry, final PropertyContext context) {
    if (allowableValue.equalsIgnoreCase(SCHEMA_NAME_PROPERTY.getValue())) {
        final PropertyValue schemaName = context.getProperty(SCHEMA_NAME);
        final PropertyValue schemaBranchName = context.getProperty(SCHEMA_BRANCH_NAME);
        final PropertyValue schemaVersion = context.getProperty(SCHEMA_VERSION);
        return new SchemaNamePropertyStrategy(schemaRegistry, schemaName, schemaBranchName, schemaVersion);
    } else if (allowableValue.equalsIgnoreCase(INHERIT_RECORD_SCHEMA.getValue())) {
        return new InheritSchemaFromRecord();
    } else if (allowableValue.equalsIgnoreCase(SCHEMA_TEXT_PROPERTY.getValue())) {
        return new AvroSchemaTextStrategy(context.getProperty(SCHEMA_TEXT));
    } else if (allowableValue.equalsIgnoreCase(HWX_CONTENT_ENCODED_SCHEMA.getValue())) {
        return new HortonworksEncodedSchemaReferenceStrategy(schemaRegistry);
    } else if (allowableValue.equalsIgnoreCase(HWX_SCHEMA_REF_ATTRIBUTES.getValue())) {
        return new HortonworksAttributeSchemaReferenceStrategy(schemaRegistry);
    } else if (allowableValue.equalsIgnoreCase(CONFLUENT_ENCODED_SCHEMA.getValue())) {
        return new ConfluentSchemaRegistryStrategy(schemaRegistry);
    }

    return null;
}
 
Example #3
Source File: ParametersIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testSensitivePropertyReferenceParameterSupportsEL() {
    final ProcessorNode usernamePassword = createProcessorNode(UsernamePasswordProcessor.class);

    final ParameterReferenceManager referenceManager = new StandardParameterReferenceManager(getFlowController().getFlowManager());
    final ParameterContext parameterContext = new StandardParameterContext(UUID.randomUUID().toString(), "param-context", referenceManager, null);
    parameterContext.setParameters(Collections.singletonMap("pass", new Parameter(new ParameterDescriptor.Builder().name("pass").sensitive(true).build(), "secret")));

    getRootGroup().setParameterContext(parameterContext);

    final Map<String, String> properties = new HashMap<>();
    properties.put("password", "#{pass}");
    usernamePassword.setProperties(properties);

    final ProcessContext processContext = new StandardProcessContext(usernamePassword, getFlowController().getControllerServiceProvider(), getFlowController().getEncryptor(),
        getFlowController().getStateManagerProvider().getStateManager(usernamePassword.getIdentifier()), () -> false);
    final PropertyDescriptor descriptor = usernamePassword.getPropertyDescriptor("password");
    final PropertyValue propertyValue = processContext.getProperty(descriptor);
    final PropertyValue evaluatedPropertyValue = propertyValue.evaluateAttributeExpressions();
    final String evaluatedPassword = evaluatedPropertyValue.getValue();
    assertEquals("secret", evaluatedPassword);
}
 
Example #4
Source File: MockPropertyValue.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public PropertyValue evaluateAttributeExpressions(final FlowFile flowFile) throws ProcessException {
    /*
     * The reason for this null check is that somewhere in the test API, it automatically assumes that a null FlowFile
     * should be treated as though it were evaluated with the VARIABLE_REGISTRY scope instead of the flowfile scope. When NiFi
     * is running, it doesn't care when it's evaluating EL against a null flowfile. However, the testing framework currently
     * raises an error which makes it not mimick real world behavior.
     */
    if (flowFile == null && expressionLanguageScope == ExpressionLanguageScope.FLOWFILE_ATTRIBUTES) {
        return evaluateAttributeExpressions(new HashMap<>());
    } else if (flowFile == null && expressionLanguageScope == ExpressionLanguageScope.VARIABLE_REGISTRY) {
        return evaluateAttributeExpressions(); //Added this to get around a similar edge case where the a null flowfile is passed
                                                //and the scope is to the registry
    }

    return evaluateAttributeExpressions(flowFile, null, null);
}
 
Example #5
Source File: TestSiteToSiteReportingRecordSink.java    From nifi with Apache License 2.0 6 votes vote down vote up
public MockSiteToSiteReportingRecordSink initTask(Map<PropertyDescriptor, String> customProperties) throws InitializationException, IOException {

        final MockSiteToSiteReportingRecordSink task = new MockSiteToSiteReportingRecordSink();
        context = Mockito.mock(ConfigurationContext.class);
        StateManager stateManager = new MockStateManager(task);

        final PropertyValue pValue = Mockito.mock(StandardPropertyValue.class);
        MockRecordWriter writer = new MockRecordWriter(null, false); // No header, don't quote values
        Mockito.when(context.getProperty(RecordSinkService.RECORD_WRITER_FACTORY)).thenReturn(pValue);
        Mockito.when(pValue.asControllerService(RecordSetWriterFactory.class)).thenReturn(writer);

        final ComponentLog logger = Mockito.mock(ComponentLog.class);
        final ControllerServiceInitializationContext initContext = new MockControllerServiceInitializationContext(writer, UUID.randomUUID().toString(), logger, stateManager);
        task.initialize(initContext);

        return task;
    }
 
Example #6
Source File: RouteText.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * 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 String regex = context.getProperty(GROUPING_REGEX).getValue();
    if (regex != null) {
        groupingRegex = Pattern.compile(regex);
    }

    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;
}
 
Example #7
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 #8
Source File: RouteText.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * 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 String regex = context.getProperty(GROUPING_REGEX).getValue();
    if (regex != null) {
        groupingRegex = Pattern.compile(regex);
    }

    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;
}
 
Example #9
Source File: SFTPTransfer.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public List<FileInfo> getListing() throws IOException {
    final String path = ctx.getProperty(FileTransfer.REMOTE_PATH).evaluateAttributeExpressions().getValue();
    final int depth = 0;

    final int maxResults;
    final PropertyValue batchSizeValue = ctx.getProperty(FileTransfer.REMOTE_POLL_BATCH_SIZE);
    if (batchSizeValue == null) {
        maxResults = Integer.MAX_VALUE;
    } else {
        final Integer configuredValue = batchSizeValue.asInteger();
        maxResults = configuredValue == null ? Integer.MAX_VALUE : configuredValue;
    }

    final List<FileInfo> listing = new ArrayList<>(1000);
    getListing(path, depth, maxResults, listing);
    return listing;
}
 
Example #10
Source File: VisibilityUtil.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static String pickVisibilityString(String columnFamily, String columnQualifier, FlowFile flowFile, ProcessContext context) {
    if (StringUtils.isBlank(columnFamily)) {
        return null;
    }
    String lookupKey = String.format("visibility.%s%s%s", columnFamily, !StringUtils.isBlank(columnQualifier) ? "." : "", columnQualifier);
    String fromAttribute = flowFile.getAttribute(lookupKey);

    if (fromAttribute == null && !StringUtils.isBlank(columnQualifier)) {
        String lookupKeyFam = String.format("visibility.%s", columnFamily);
        fromAttribute = flowFile.getAttribute(lookupKeyFam);
    }

    if (fromAttribute != null) {
        return fromAttribute;
    } else {
        PropertyValue descriptor = context.getProperty(lookupKey);
        if (descriptor == null || !descriptor.isSet()) {
            descriptor = context.getProperty(String.format("visibility.%s", columnFamily));
        }

        String retVal = descriptor != null ? descriptor.evaluateAttributeExpressions(flowFile).getValue() : null;

        return retVal;
    }
}
 
Example #11
Source File: StatelessPropertyValue.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public PropertyValue evaluateAttributeExpressions(final FlowFile flowFile) throws ProcessException {
    /*
     * The reason for this null check is that somewhere in the test API, it automatically assumes that a null FlowFile
     * should be treated as though it were evaluated with the VARIABLE_REGISTRY scope instead of the flowfile scope. When NiFi
     * is running, it doesn't care when it's evaluating EL against a null flowfile. However, the testing framework currently
     * raises an error which makes it not mimick real world behavior.
     */
    if (flowFile == null && expressionLanguageScope == ExpressionLanguageScope.FLOWFILE_ATTRIBUTES) {
        return evaluateAttributeExpressions(new HashMap<>());
    } else if (flowFile == null && expressionLanguageScope == ExpressionLanguageScope.VARIABLE_REGISTRY) {
        return evaluateAttributeExpressions(); //Added this to get around a similar edge case where the a null flowfile is passed
        //and the scope is to the registry
    }

    return evaluateAttributeExpressions(flowFile, null, null);
}
 
Example #12
Source File: RecordBinManager.java    From nifi with Apache License 2.0 6 votes vote down vote up
private RecordBinThresholds createThresholds(FlowFile flowfile) {
    int minRecords = context.getProperty(MergeRecord.MIN_RECORDS).evaluateAttributeExpressions().asInteger();
    final int maxRecords = context.getProperty(MergeRecord.MAX_RECORDS).evaluateAttributeExpressions().asInteger();
    final long minBytes = context.getProperty(MergeRecord.MIN_SIZE).asDataSize(DataUnit.B).longValue();

    final PropertyValue maxSizeValue = context.getProperty(MergeRecord.MAX_SIZE);
    final long maxBytes = maxSizeValue.isSet() ? maxSizeValue.asDataSize(DataUnit.B).longValue() : Long.MAX_VALUE;

    final PropertyValue maxMillisValue = context.getProperty(MergeRecord.MAX_BIN_AGE);
    final String maxBinAge = maxMillisValue.getValue();
    final long maxBinMillis = maxMillisValue.isSet() ? maxMillisValue.asTimePeriod(TimeUnit.MILLISECONDS) : Long.MAX_VALUE;

    final String fragmentCountAttribute;
    final String mergeStrategy = context.getProperty(MergeRecord.MERGE_STRATEGY).getValue();
    if (MergeRecord.MERGE_STRATEGY_DEFRAGMENT.getValue().equals(mergeStrategy)) {
        fragmentCountAttribute = MergeContent.FRAGMENT_COUNT_ATTRIBUTE;
        // We don't know minRecords in defragment mode.
        minRecords = Integer.MAX_VALUE;
    } else {
        fragmentCountAttribute = null;
    }

    return new RecordBinThresholds(minRecords, maxRecords, minBytes, maxBytes, maxBinMillis, maxBinAge, fragmentCountAttribute);
}
 
Example #13
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 #14
Source File: MockPropertyValue.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public PropertyValue evaluateAttributeExpressions(FlowFile flowFile, Map<String, String> additionalAttributes, AttributeValueDecorator decorator, Map<String, String> stateValues)
        throws ProcessException {
    markEvaluated();
    if (rawValue == null) {
        return this;
    }

    validateExpressionScope(flowFile != null || additionalAttributes != null);

    final PropertyValue newValue = stdPropValue.evaluateAttributeExpressions(flowFile, additionalAttributes, decorator, stateValues);
    return new MockPropertyValue(newValue.getValue(), serviceLookup, propertyDescriptor, true, variableRegistry);
}
 
Example #15
Source File: TestSchemaNamePropertyStrategy.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test(expected = SchemaNotFoundException.class)
public void testNameAndNonNumericVersion() throws SchemaNotFoundException, IOException {
    final PropertyValue nameValue = new MockPropertyValue("person");
    final PropertyValue branchValue = new MockPropertyValue(null);
    final PropertyValue versionValue = new MockPropertyValue("XYZ");

    final SchemaNamePropertyStrategy schemaNamePropertyStrategy = new SchemaNamePropertyStrategy(
            schemaRegistry, nameValue, branchValue, versionValue);

    schemaNamePropertyStrategy.getSchema(Collections.emptyMap(), null, recordSchema);
}
 
Example #16
Source File: TestAlertHandler.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidContext(){
    final Map<String, String> attributes = new HashMap<>();
    final Map<String, Object> metrics = new HashMap<>();

    final String category = "Rules Alert";
    final String message = "This should be sent as an alert!";
    final String severity =  "INFO";
    attributes.put("category", category);
    attributes.put("message", message);
    attributes.put("severity", severity);
    metrics.put("jvmHeap", "1000000");
    metrics.put("cpu", "90");

    final Action action = new Action();
    action.setType("ALERT");
    action.setAttributes(attributes);
    PropertyContext fakeContext = new PropertyContext() {
        @Override
        public PropertyValue getProperty(PropertyDescriptor descriptor) {
            return null;
        }

        @Override
        public Map<String, String> getAllProperties() {
            return null;
        }
    };
    alertHandler.execute(fakeContext, action, metrics);
    final String debugMessage = mockComponentLog.getWarnMessage();
    assertTrue(StringUtils.isNotEmpty(debugMessage));
    assertEquals(debugMessage,"Reporting context was not provided to create bulletins.");
}
 
Example #17
Source File: TestStandardPropertyValue.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubstituteAttributesWithOneMatchingArg() {
    final PropertyValue value = new StandardPropertyValue("Hello, ${audience}!", lookup);
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("audience", "World");
    assertEquals("Hello, World!", value.evaluateAttributeExpressions(createFlowFile(attributes)).getValue());
}
 
Example #18
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 #19
Source File: StandardPropertyValue.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public PropertyValue evaluateAttributeExpressions(FlowFile flowFile, Map<String, String> additionalAttributes, AttributeValueDecorator decorator, Map<String, String> stateValues)
        throws ProcessException {
    if (rawValue == null || preparedQuery == null) {
        return this;
    }
    final ValueLookup lookup = new ValueLookup(variableRegistry, flowFile, additionalAttributes);
    return new StandardPropertyValue(preparedQuery.evaluateExpressions(lookup, decorator, stateValues), serviceLookup, null);
}
 
Example #20
Source File: StandardSSLContextService.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void verifySslConfig(final ValidationContext validationContext) throws ProcessException {
    final String protocol = validationContext.getProperty(SSL_ALGORITHM).getValue();
    try {
        final PropertyValue keyPasswdProp = validationContext.getProperty(KEY_PASSWORD);
        final char[] keyPassword = keyPasswdProp.isSet() ? keyPasswdProp.getValue().toCharArray() : null;

        final String keystoreFile = validationContext.getProperty(KEYSTORE).getValue();
        if (keystoreFile == null) {
            SslContextFactory.createTrustSslContext(
                    validationContext.getProperty(TRUSTSTORE).getValue(),
                    validationContext.getProperty(TRUSTSTORE_PASSWORD).getValue().toCharArray(),
                    validationContext.getProperty(TRUSTSTORE_TYPE).getValue(),
                    protocol);
            return;
        }
        final String truststoreFile = validationContext.getProperty(TRUSTSTORE).getValue();
        if (truststoreFile == null) {
            SslContextFactory.createSslContext(
                    validationContext.getProperty(KEYSTORE).getValue(),
                    validationContext.getProperty(KEYSTORE_PASSWORD).getValue().toCharArray(),
                    keyPassword,
                    validationContext.getProperty(KEYSTORE_TYPE).getValue(),
                    protocol);
            return;
        }

        SslContextFactory.createSslContext(
                validationContext.getProperty(KEYSTORE).getValue(),
                validationContext.getProperty(KEYSTORE_PASSWORD).getValue().toCharArray(),
                keyPassword,
                validationContext.getProperty(KEYSTORE_TYPE).getValue(),
                validationContext.getProperty(TRUSTSTORE).getValue(),
                validationContext.getProperty(TRUSTSTORE_PASSWORD).getValue().toCharArray(),
                validationContext.getProperty(TRUSTSTORE_TYPE).getValue(),
                org.apache.nifi.security.util.SslContextFactory.ClientAuth.REQUIRED,
                protocol);
    } catch (final Exception e) {
        throw new ProcessException(e);
    }
}
 
Example #21
Source File: TestZooKeeperStateProvider.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void initializeProvider(final ZooKeeperStateProvider provider, final Map<PropertyDescriptor, String> properties) throws IOException {
    provider.initialize(new StateProviderInitializationContext() {
        @Override
        public String getIdentifier() {
            return "Unit Test Provider Initialization Context";
        }

        @Override
        public Map<PropertyDescriptor, PropertyValue> getProperties() {
            final Map<PropertyDescriptor, PropertyValue> propValueMap = new HashMap<>();
            for (final Map.Entry<PropertyDescriptor, String> entry : properties.entrySet()) {
                propValueMap.put(entry.getKey(), new StandardPropertyValue(entry.getValue(), null));
            }
            return propValueMap;
        }

        @Override
        public PropertyValue getProperty(final PropertyDescriptor property) {
            final String prop = properties.get(property);
            return new StandardPropertyValue(prop, null);
        }

        @Override
        public SSLContext getSSLContext() {
            return null;
        }
    });
}
 
Example #22
Source File: TestStandardPropertyValue.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testEscaped() {
    final PropertyValue value = new StandardPropertyValue("Hello, $${audience}!", lookup, ParameterLookup.EMPTY);
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("audience", "World");
    assertEquals("Hello, ${audience}!", value.evaluateAttributeExpressions(createFlowFile(attributes)).getValue());
}
 
Example #23
Source File: AbstractJMSProcessor.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void validateLocalConnectionFactoryConfig(List<PropertyDescriptor> localConnectionFactoryProperties, PropertyDescriptor indicatorProperty, List<ValidationResult> results) {
    for (PropertyDescriptor propertyDescriptor : localConnectionFactoryProperties) {
        if (propertyDescriptor.isRequired()) {
            PropertyValue propertyValue = validationContext.getProperty(propertyDescriptor);
            if (!propertyValue.isSet()) {
                results.add(new ValidationResult.Builder()
                        .subject("Connection Factory config")
                        .valid(false)
                        .explanation(String.format("'%s' must be specified when '%s' has been configured.", propertyDescriptor.getDisplayName(), indicatorProperty.getDisplayName()))
                        .build());
            }
        }
    }
}
 
Example #24
Source File: MockConfigurationContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public PropertyValue getProperty(final PropertyDescriptor property) {
    String value = properties.get(property);
    if (value == null) {
        value = getActualDescriptor(property).getDefaultValue();
    }
    return new MockPropertyValue(value, serviceLookup, variableRegistry);
}
 
Example #25
Source File: SFTPTransfer.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public SFTPTransfer(final ProcessContext processContext, final ComponentLog logger) {
    this.ctx = processContext;
    this.logger = logger;

    final PropertyValue disableListing = processContext.getProperty(DISABLE_DIRECTORY_LISTING);
    disableDirectoryListing = disableListing == null ? false : Boolean.TRUE.equals(disableListing.asBoolean());
}
 
Example #26
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);
}
 
Example #27
Source File: StandardProcessContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public PropertyValue getProperty(final PropertyDescriptor descriptor) {
    verifyTaskActive();

    final String setPropertyValue = properties.get(descriptor);
    if (setPropertyValue != null) {
        return new StandardPropertyValue(setPropertyValue, this, procNode.getParameterLookup(), preparedQueries.get(descriptor), procNode.getVariableRegistry());
    }

    // Get the "canonical" Property Descriptor from the Processor
    final PropertyDescriptor canonicalDescriptor = procNode.getProcessor().getPropertyDescriptor(descriptor.getName());
    final String defaultValue = canonicalDescriptor.getDefaultValue();

    return new StandardPropertyValue(defaultValue, this, procNode.getParameterLookup(), preparedQueries.get(descriptor), procNode.getVariableRegistry());
}
 
Example #28
Source File: LookupAttribute.java    From nifi with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #29
Source File: TestStandardPropertyValue.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubstituteAttributesRecursively() {
    final PropertyValue value = new StandardPropertyValue("Hello, ${'${a}${b}'}!", lookup);
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("a", "b");
    attributes.put("b", "World");
    attributes.put("bWorld", "World");
    assertEquals("Hello, World!", value.evaluateAttributeExpressions(createFlowFile(attributes)).getValue());
}
 
Example #30
Source File: StandardStateProviderInitializationContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String,String> getAllProperties() {
    final Map<String,String> propValueMap = new LinkedHashMap<>();
    for (final Map.Entry<PropertyDescriptor, PropertyValue> entry : getProperties().entrySet()) {
        propValueMap.put(entry.getKey().getName(), entry.getValue().getValue());
    }
    return propValueMap;
}