84 lines
2.1 KiB
Plaintext
84 lines
2.1 KiB
Plaintext
package com.ifish.jpush.schedule.model;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.JsonElement;
|
|
import com.google.gson.JsonObject;
|
|
import com.ifish.jpush.push.model.PushPayload;
|
|
import com.ifish.jpush.utils.StringUtils;
|
|
|
|
public class SchedulePayload implements IModel {
|
|
|
|
private static Gson gson = new Gson();
|
|
|
|
private String name;
|
|
private Boolean enabled;
|
|
private TriggerPayload trigger;
|
|
private PushPayload push;
|
|
|
|
private SchedulePayload(String name, Boolean enabled, TriggerPayload trigger, PushPayload push) {
|
|
this.name = name;
|
|
this.enabled = enabled;
|
|
this.trigger = trigger;
|
|
this.push = push;
|
|
}
|
|
|
|
public static Builder newBuilder() {
|
|
return new Builder();
|
|
}
|
|
|
|
@Override
|
|
public JsonElement toJSON() {
|
|
JsonObject json = new JsonObject();
|
|
if ( StringUtils.isNotEmpty(name) ) {
|
|
json.addProperty("name", name);
|
|
}
|
|
if ( null != enabled ) {
|
|
json.addProperty("enabled", enabled);
|
|
}
|
|
if ( null != trigger ) {
|
|
json.add("trigger", trigger.toJSON());
|
|
}
|
|
if ( null != push ) {
|
|
json.add("push", push.toJSON());
|
|
}
|
|
return json;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return gson.toJson(toJSON());
|
|
}
|
|
|
|
public static class Builder{
|
|
private String name;
|
|
private Boolean enabled;
|
|
private TriggerPayload trigger;
|
|
private PushPayload push;
|
|
|
|
public Builder setName(String name) {
|
|
this.name = name;
|
|
return this;
|
|
}
|
|
|
|
public Builder setEnabled(Boolean enabled) {
|
|
this.enabled = enabled;
|
|
return this;
|
|
}
|
|
|
|
public Builder setTrigger(TriggerPayload trigger) {
|
|
this.trigger = trigger;
|
|
return this;
|
|
}
|
|
|
|
public Builder setPush(PushPayload push) {
|
|
this.push = push;
|
|
return this;
|
|
}
|
|
|
|
public SchedulePayload build() {
|
|
|
|
return new SchedulePayload(name, enabled, trigger, push);
|
|
}
|
|
}
|
|
}
|