package com.lanyuanxiaoyao.service.sync.functions;

import cn.hutool.core.util.ObjectUtil;
import com.lanyuanxiaoyao.service.common.entity.FlinkJob;
import com.lanyuanxiaoyao.service.common.entity.Record;
import com.lanyuanxiaoyao.service.common.entity.TableMeta;
import com.lanyuanxiaoyao.service.sync.configuration.GlobalConfiguration;
import org.apache.flink.api.common.functions.RichFilterFunction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 判断 Record 是否正确
 *
 * @author ZhangJiacheng
 * @date 2022-11-15
 */
public class ValidateRecordFilter extends RichFilterFunction<Record> {
    private static final Logger logger = LoggerFactory.getLogger(ValidateRecordFilter.class);

    public ValidateRecordFilter(GlobalConfiguration configuration, FlinkJob flinkJob, TableMeta tableMeta) {
    }

    @Override
    public boolean filter(Record record) {
        if (ObjectUtil.isNull(record)) {
            logger.warn("Record is null");
            return false;
        }
        if (ObjectUtil.isNull(record.getSource())) {
            logger.warn("Record Source is null");
            return false;
        }
        if (ObjectUtil.isNull(record.getStatement())) {
            logger.warn("Record Statement is null");
            return false;
        }
        return true;
    }
}
