All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.moengage.evaluator.ReachabilityEvaluator Maven / Gradle / Ivy

package com.moengage.evaluator;

import com.moengage.datatype.reachability.*;
import com.moengage.enum_models.reachability.Channel;
import org.json.JSONException;
import org.json.JSONObject;

public class ReachabilityEvaluator extends ConditionEvaluator {
    public ReachabilityEvaluator(JSONObject filterCondition, JSONObject filters) {
        super(filterCondition, filters);
    }

    public JSONObject getReachability() throws JSONException, InvalidFieldValueException {
        this.filters = createJSON(this.filters);
        this.filterCondition = createJSON(this.filterCondition);
        JSONObject emailCondition = createJSON((JSONObject) this.filterCondition.opt(Channel.EMAIl));
        JSONObject smsCondition = createJSON((JSONObject) this.filterCondition.opt(Channel.SMS));
        JSONObject androidPushCondition = createJSON((JSONObject) this.filterCondition.opt(Channel.ANDROID_PUSH));
        JSONObject iosPushCondition = createJSON((JSONObject) this.filterCondition.opt(Channel.IOS_PUSH));
        JSONObject whatsappCondition = createJSON((JSONObject) this.filterCondition.opt(Channel.WHATSAPP));

        boolean emailReachability = new Email().getReachability(emailCondition, this.filters);
        boolean smsReachability = new SMS().getReachability(smsCondition, this.filters);
        boolean androidPushReachability = new AndroidPush().getReachability(androidPushCondition, this.filters);
        boolean iosPushReachability = new IOSPush().getReachability(iosPushCondition, this.filters);
        boolean whatsappReachability = new Whatsapp().getReachability(whatsappCondition, this.filters);

        JSONObject reachability = new JSONObject();
        reachability.put(Channel.EMAIl, emailReachability);
        reachability.put(Channel.SMS, smsReachability);
        reachability.put(Channel.ANDROID_PUSH, androidPushReachability);
        reachability.put(Channel.IOS_PUSH, iosPushReachability);
        reachability.put(Channel.WHATSAPP, whatsappReachability);
        return reachability;
    }

    private JSONObject createJSON(JSONObject condition) {
        if (condition == null) {
            return new JSONObject();
        }
        return condition;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy