admin
2024-10-16 bd885c7015446c6c0495d3299ef64068a4c9b30e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package cn.jpush.api.schedule.model;
 
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
 
import cn.jiguang.common.utils.StringUtils;
import cn.jpush.api.push.model.PushPayload;
 
public class SchedulePayload implements IModel {
 
    private static final String CID = "cid";
    private static final String NAME = "name";
    private static final String ENABLED = "enabled";
    private static final String TRIGGER = "trigger";
    private static final String PUSH = "push";
 
    private static Gson gson = new Gson();
 
    private String cid;
    private String name;
    private Boolean enabled;
    private TriggerPayload trigger;
    private PushPayload push;
 
    private SchedulePayload(String cid, String name, Boolean enabled, TriggerPayload trigger, PushPayload push) {
        this.cid = cid;
        this.name = name;
        this.enabled = enabled;
        this.trigger = trigger;
        this.push = push;
    }
 
    public SchedulePayload setCid(String cid) {
        this.cid = cid;
        return this;
    }
 
    public String getCid() {
        return cid;
    }
 
    /**
     *
     * The entrance for building a SchedulePayload object.
     * @return SchedulePayload builder
     */
    public static Builder newBuilder() {
        return new Builder();
    }
 
    @Override
    public JsonElement toJSON() {
        JsonObject json = new JsonObject();
        if ( null != cid ) {
            json.addProperty(CID, cid);
        }
        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 void resetPushApnsProduction(boolean apnsProduction) {
        if(null != push) {
            push.resetOptionsApnsProduction(apnsProduction);
        }
    }
 
    public void resetPushTimeToLive(long timeToLive) {
        if(null != push) {
            push.resetOptionsTimeToLive(timeToLive);
        }
    }
 
    public static class Builder{
        private String cid;
        private String name;
        private Boolean enabled;
        private TriggerPayload trigger;
        private PushPayload push;
 
        public Builder setCid(String cid) {
            this.cid = cid;
            return this;
        }
 
        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(cid, name, enabled, trigger, push);
        }
    }
}