ReplicationEvent.java
3.56 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
/*
* 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.ReplicationAction;
import com.day.cq.replication.ReplicationActionType;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventProperties;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ReplicationEvent
implements Serializable {
public static final String EVENT_TOPIC = "com/adobe/granite/replication";
public static final String PATHS = "paths";
private static final String PROPERTY_MODIFICATIONS = "modifications";
private static final String TYPE = "type";
private static final String TIME = "time";
private static final String USER_ID = "userId";
private static final String REVISION = "revision";
private ReplicationAction replicationAction;
private final boolean isLocal;
public ReplicationEvent(ReplicationAction replicationAction) {
this(replicationAction, true);
}
public ReplicationEvent(ReplicationAction replicationAction, boolean isLocal) {
this.replicationAction = replicationAction;
this.isLocal = isLocal;
}
public ReplicationAction getReplicationAction() {
return this.replicationAction;
}
public static ReplicationEvent fromEvent(Event evt) {
if (!evt.getTopic().equals("com/adobe/granite/replication")) {
return null;
}
ReplicationAction action = null;
List modProps = (List)evt.getProperty("modifications");
if (modProps != null && modProps.size() == 1) {
Map modProp = (Map)modProps.get(0);
String[] paths = (String[])modProp.get("paths");
ReplicationActionType type = (ReplicationActionType)((Object)modProp.get("type"));
Long time = (Long)modProp.get("time");
String userId = (String)modProp.get("userId");
String revision = (String)modProp.get("revision");
action = new ReplicationAction(type, paths, (long)time, userId, revision);
}
if (action == null) {
throw new RuntimeException();
}
return new ReplicationEvent(action, evt.getProperty("event.application") == null);
}
protected Map<String, Object> getEventProperties(boolean distribute) {
HashMap<String, Object> properties = new HashMap<String, Object>();
ArrayList modProps = new ArrayList();
HashMap<String, Object> actionProps = new HashMap<String, Object>();
actionProps.put("paths", this.replicationAction.getPaths());
actionProps.put("type", (Object)this.replicationAction.getType());
actionProps.put("time", this.replicationAction.getTime());
actionProps.put("userId", this.replicationAction.getUserId());
actionProps.put("revision", this.replicationAction.getRevision());
modProps.add(actionProps);
properties.put("modifications", modProps);
if (!this.isLocal) {
properties.put("event.application", "unknown");
}
if (distribute) {
properties.put("event.distribute", "");
}
return new EventProperties(properties);
}
public Event toEvent() {
return new Event("com/adobe/granite/replication", this.getEventProperties(true));
}
public Event toNonDistributableEvent() {
return new Event("com/adobe/granite/replication", this.getEventProperties(false));
}
}