Example usage for org.apache.solr.client.solrj.io.stream.expr StreamExpressionNamedParameter getParameter

List of usage examples for org.apache.solr.client.solrj.io.stream.expr StreamExpressionNamedParameter getParameter

Introduction

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

Prototype

public StreamExpressionParameter getParameter() 

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
 *//*  w w w  .j  ava 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 String getStringParameter(String paramName, StreamExpression expression, StreamFactory factory) {
    StreamExpressionNamedParameter param = factory.getNamedOperand(expression, paramName);
    if (null != param) {
        if (param.getParameter() instanceof StreamExpressionValue) {
            return ((StreamExpressionValue) param.getParameter()).getValue();
        }/*  ww  w.j a  v  a 2  s  .  c om*/
    }

    return null;
}

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

License:Apache License

private List<String> getMultiStringParameter(String paramName, StreamExpression expression,
        StreamFactory factory) {//from w  w w.j av  a 2  s .c  om
    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();
                if (part.length() > 0) {
                    values.add(part);
                }
            }
        }
    }

    return values;
}