Search in sources :

Example 1 with TemplateBuilder

use of io.siddhi.core.util.transport.TemplateBuilder in project siddhi by wso2.

the class SinkMapper method buildMapperTemplate.

/**
 * Method to create mapper template.
 *
 * @param streamDefinition    Stream definition corresponding to mapper
 * @param unmappedPayloadList mapper payload template list
 */
protected void buildMapperTemplate(StreamDefinition streamDefinition, List<Element> unmappedPayloadList) {
    if (unmappedPayloadList != null && !unmappedPayloadList.isEmpty()) {
        templateBuilderMap = new HashMap<>();
        for (Element e : unmappedPayloadList) {
            TemplateBuilder templateBuilder = new TemplateBuilder(streamDefinition, e.getValue());
            if (templateBuilderMap.containsKey(e.getKey())) {
                throw new SiddhiAppCreationException("Duplicate Keys, " + e.getKey() + ", in @payload() ");
            }
            templateBuilderMap.put(e.getKey(), templateBuilder);
        }
    }
}
Also used : SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) Element(io.siddhi.query.api.annotation.Element) TemplateBuilder(io.siddhi.core.util.transport.TemplateBuilder)

Example 2 with TemplateBuilder

use of io.siddhi.core.util.transport.TemplateBuilder in project siddhi by wso2.

the class TestSinkOptionSinkMapper method mapAndSend.

@Override
public void mapAndSend(Event[] events, OptionHolder optionHolder, Map<String, TemplateBuilder> payloadTemplateBuilderMap, SinkListener sinkListener) {
    for (Event event : events) {
        String topic = topicOption.getValue(event);
        if (mapType) {
            for (TemplateBuilder templateBuilder : payloadTemplateBuilderMap.values()) {
                sinkListener.publish(new Event(System.currentTimeMillis(), new Object[] { sinkType, topic, templateBuilder.isObjectMessage() + "-" + templateBuilder.getType().toString() }));
            }
        } else {
            // to change the topic as topic is picked from the original event
            event.getData()[0] = sinkType;
            sinkListener.publish(new Event(System.currentTimeMillis(), new Object[] { sinkType, topic, prefix }));
        }
    }
}
Also used : TemplateBuilder(io.siddhi.core.util.transport.TemplateBuilder) Event(io.siddhi.core.event.Event)

Example 3 with TemplateBuilder

use of io.siddhi.core.util.transport.TemplateBuilder in project siddhi by wso2.

the class TestSinkOptionSinkMapper method mapAndSend.

@Override
public void mapAndSend(Event event, OptionHolder optionHolder, Map<String, TemplateBuilder> payloadTemplateBuilderMap, SinkListener sinkListener) {
    String topic = topicOption.getValue(event);
    if (mapType) {
        for (TemplateBuilder templateBuilder : payloadTemplateBuilderMap.values()) {
            sinkListener.publish(new Event(System.currentTimeMillis(), new Object[] { sinkType, topic, templateBuilder.isObjectMessage() + "-" + templateBuilder.getType().toString() }));
        }
    } else {
        // to change the topic as topic is picked from the original event
        event.getData()[0] = sinkType;
        sinkListener.publish(new Event(System.currentTimeMillis(), new Object[] { sinkType, topic, prefix }));
    }
}
Also used : TemplateBuilder(io.siddhi.core.util.transport.TemplateBuilder) Event(io.siddhi.core.event.Event)

Aggregations

TemplateBuilder (io.siddhi.core.util.transport.TemplateBuilder)3 Event (io.siddhi.core.event.Event)2 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)1 Element (io.siddhi.query.api.annotation.Element)1