ReplicationAction.java
5.8 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.osgi.service.event.Event
* org.osgi.service.event.EventProperties
*/
package com.day.cq.replication;
import com.day.cq.replication.AgentConfig;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationLog;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventProperties;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class ReplicationAction
implements Serializable {
private static final long serialVersionUID = -151606943486007293L;
public static final String EVENT_TOPIC = "com/day/cq/replication";
public static final String PROPERTY_MODIFICATION_DATE = "modificationDate";
public static final String PROPERTY_USER_ID = "userId";
public static final String PROPERTY_PATH = "path";
public static final String PROPERTY_PATHS = "paths";
public static final String PROPERTY_TYPE = "type";
public static final String PROPERTY_REVISION = "revision";
public static final String PN_PATH = "cq:repPath";
public static final String PN_ACTION_TYPE = "cq:repActionType";
private final ReplicationActionType type;
private final String[] paths;
private final long time;
private final String userId;
private String revision;
private transient AgentConfig config;
private transient ReplicationLog log;
public ReplicationAction(ReplicationActionType type, String path, long time, String userId, String revision) {
if (type == null) {
throw new IllegalArgumentException("Type must not be null.");
}
if (path == null) {
throw new IllegalArgumentException("Path must not be null.");
}
if (userId == null) {
throw new IllegalArgumentException("Userid must not be null.");
}
this.type = type;
this.paths = new String[]{path};
this.time = time == 0 ? System.currentTimeMillis() : time;
this.userId = userId;
this.revision = revision;
}
public ReplicationAction(ReplicationActionType type, String[] paths, long time, String userId, String revision) {
if (type == null) {
throw new IllegalArgumentException("Type must not be null.");
}
if (paths == null || paths.length == 0) {
throw new IllegalArgumentException("Paths must not be null or empty.");
}
if (userId == null) {
throw new IllegalArgumentException("Userid must not be null.");
}
this.type = type;
this.paths = paths;
this.time = time == 0 ? System.currentTimeMillis() : time;
this.userId = userId;
this.revision = revision;
}
public ReplicationAction(ReplicationActionType type, String path) {
this(type, path, 0, "", null);
}
public ReplicationActionType getType() {
return this.type;
}
public String getPath() {
return this.paths[0];
}
public String[] getPaths() {
return this.paths;
}
public String getRevision() {
return this.revision;
}
public long getTime() {
return this.time;
}
public String getUserId() {
return this.userId;
}
public AgentConfig getConfig() {
return this.config;
}
public void setConfig(AgentConfig config) {
this.config = config;
}
public ReplicationLog getLog() {
return this.log;
}
public void setLog(ReplicationLog log) {
this.log = log;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("ReplicationAction");
sb.append("{type=").append((Object)this.type);
sb.append(", path[0]='").append(this.paths[0]).append('\'');
sb.append(", time=").append(this.time);
sb.append(", userId='").append(this.userId).append('\'');
sb.append(", revision='").append(this.revision).append('\'');
sb.append('}');
return sb.toString();
}
public static ReplicationAction fromEvent(Event evt) {
if (!evt.getTopic().equals("com/day/cq/replication")) {
return null;
}
Object lastMod = evt.getProperty("modificationDate");
long time = 0;
if (lastMod instanceof Date) {
time = ((Date)lastMod).getTime();
} else if (lastMod instanceof Calendar) {
time = ((Calendar)lastMod).getTimeInMillis();
} else if (lastMod instanceof Long) {
time = (Long)lastMod;
}
String[] paths = (String[])evt.getProperty("paths");
if (paths == null) {
paths = new String[]{(String)evt.getProperty("path")};
}
return new ReplicationAction(ReplicationActionType.fromName((String)evt.getProperty("type")), paths, time, (String)evt.getProperty("userId"), (String)evt.getProperty("revision"));
}
public Map<String, Object> createEventProperties(boolean distribute) {
HashMap<String, Object> properties = new HashMap<String, Object>();
properties.put("type", this.type.toString());
properties.put("paths", this.paths);
Calendar c = Calendar.getInstance();
c.setTimeInMillis(this.time);
properties.put("modificationDate", c);
properties.put("userId", this.userId);
if (this.revision != null) {
properties.put("revision", this.revision);
}
if (distribute) {
properties.put("event.distribute", "");
}
return new EventProperties(properties);
}
public Event toEvent() {
return this.toEvent(false);
}
public Event toEvent(boolean distribute) {
return new Event("com/day/cq/replication", this.createEventProperties(distribute));
}
}