package com.fshark.overseas.advert.processor;

import com.fshark.overseas.advert.modle.SinkMetricEvent;
import com.fshark.overseas.advert.modle.metrics.EventMetrics;
import com.fshark.overseas.advert.util.Constants;
import com.google.gson.Gson;
import org.apache.flink.api.common.functions.RichFlatMapFunction;
import org.apache.flink.util.Collector;

public class EventMetricsToStringProcessor extends RichFlatMapFunction<EventMetrics, String> {
    @Override
    public void flatMap(EventMetrics value, Collector<String> out) throws Exception {
        SinkMetricEvent sinkMetricEvent = new SinkMetricEvent();
        sinkMetricEvent.setEventType(Constants.TYPE_SINK_EVENT);
        sinkMetricEvent.setEventMetrics(value);
        Gson gson = new Gson();
        out.collect(gson.toJson(sinkMetricEvent));
    }
}
