Example usage for org.apache.solr.client.solrj.io.stream.expr StreamFactory getNamedOperands

List of usage examples for org.apache.solr.client.solrj.io.stream.expr StreamFactory getNamedOperands

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.io.stream.expr StreamFactory getNamedOperands.

Prototype

public List<StreamExpressionNamedParameter> getNamedOperands(StreamExpression expression) 

Source Link

Usage

From source file:com.dennisgove.streaming.expressions.kafka.KafkaTopicConsumerStream.java

License:Apache License

/**
 * Accepts a valid {@link StreamExpression} adhering to the form above and constructs
 * a new instance of the KafkaTopicConsumerStream.
 *
 * @param expression A valid kafkaConsume {@link StreamExpression}
 * @param factory A valid {@link StreamFactory}
 * @throws IOException If unable to parse or deal with the incoming expression
 *///from www  .j a v a 2  s  .c o m
public KafkaTopicConsumerStream(StreamExpression expression, StreamFactory factory) throws IOException {
    String bootstrapServers = getStringParameter("bootstrapServers", expression, factory);
    String groupId = getStringParameter("groupId", expression, factory);
    String topic = getStringParameter("topic", expression, factory);
    //    List<String> partitions = getMultiStringParameter("partitions", expression, factory);

    Map<String, String> otherParams = new HashMap<>();
    for (StreamExpressionNamedParameter param : factory.getNamedOperands(expression).stream()
            .filter(item -> !knownParameters.contains(item.getName())).collect(Collectors.toList())) {
        if (param.getParameter() instanceof StreamExpressionValue) {
            otherParams.put(param.getName(), ((StreamExpressionValue) param.getParameter()).getValue());
        }
    }

    if (null == bootstrapServers) {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid %s expressions '%s' - expecting a list of bootstrapServers but found none",
                factory.getFunctionName(getClass()), expression));
    }

    if (null == topic) {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid %s expressions '%s' - expecting a single topic but found none",
                factory.getFunctionName(getClass()), expression));
    }

    this.bootstrapServers = bootstrapServers;
    this.otherConsumerParams = otherParams;
    this.groupId = groupId;
    this.topic = topic;
    //    this.partitions = partitions;
}

From source file:com.dennisgove.streaming.expressions.kafka.KafkaTopicConsumerStream.java

License:Apache License

private List<String> getMultiStringParameter(String paramName, StreamExpression expression,
        StreamFactory factory) {
    List<String> values = new ArrayList<>();

    for (StreamExpressionNamedParameter param : factory.getNamedOperands(expression)) {
        if (param.getName().equals(paramName) && param.getParameter() instanceof StreamExpressionValue) {
            String value = ((StreamExpressionValue) param.getParameter()).getValue();
            for (String part : value.split(",")) {
                part = part.trim();//from  w  ww.  j a  v a2s . com
                if (part.length() > 0) {
                    values.add(part);
                }
            }
        }
    }

    return values;
}