public Map mapAttributes()

in data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/mapping/AbstractLogstashPluginAttributesMapper.java [28:67]


    public Map<String, Object> mapAttributes(final List<LogstashAttribute> logstashAttributes, final LogstashAttributesMappings logstashAttributesMappings) {

        Objects.requireNonNull(logstashAttributes);
        Objects.requireNonNull(logstashAttributesMappings);
        Objects.requireNonNull(logstashAttributesMappings.getMappedAttributeNames());
        Objects.requireNonNull(logstashAttributesMappings.getAdditionalAttributes());

        final Map<String, Object> pluginSettings = new LinkedHashMap<>(logstashAttributesMappings.getAdditionalAttributes());
        final Map<String, String> mappedAttributeNames = logstashAttributesMappings.getMappedAttributeNames();

        Collection<String> customMappedAttributeNames = getCustomMappedAttributeNames();

        logstashAttributes
                .stream()
                .filter(logstashAttribute -> !customMappedAttributeNames.contains(logstashAttribute.getAttributeName()))
                .forEach(logstashAttribute -> {
                    final String logstashAttributeName = logstashAttribute.getAttributeName();
                    final String dataPrepperAttributeName = mappedAttributeNames.get(logstashAttributeName);

                    if (mappedAttributeNames.containsKey(logstashAttributeName)) {
                        if (dataPrepperAttributeName.startsWith("!") && logstashAttribute.getAttributeValue().getValue() instanceof Boolean) {
                            pluginSettings.put(
                                    dataPrepperAttributeName.substring(1), !(Boolean) logstashAttribute.getAttributeValue().getValue()
                            );
                        }
                        else {
                            pluginSettings.put(dataPrepperAttributeName, logstashAttribute.getAttributeValue().getValue());
                        }
                    }
                    else {
                        LOG.warn("Attribute name {} is not found in mapping file.", logstashAttributeName);
                    }
        });

        if (!customMappedAttributeNames.isEmpty()) {
            mapCustomAttributes(logstashAttributes, logstashAttributesMappings, pluginSettings);
        }

        return pluginSettings;
    }