ReplicationJob.java
4.83 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.event.jobs.Job
* org.apache.sling.event.jobs.consumer.JobExecutionContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.replication.impl.queue;
import com.day.cq.replication.ReplicationAction;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationContentFacade;
import java.util.Calendar;
import java.util.Date;
import org.apache.sling.event.jobs.Job;
import org.apache.sling.event.jobs.consumer.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ReplicationJob {
private static final Logger log = LoggerFactory.getLogger(ReplicationJob.class);
public static final String JOB_TOPIC = "com/day/cq/replication/job";
private static final int JOB_TOPIC_LENGTH = "com/day/cq/replication/job".length();
public static final String PROPERTY_REPLICATION_CONTENT = "replicationContent";
@Deprecated
private static final String PROPERTY_REPLICATION_ACTION = "replicationAction";
public static final String PROPERTY_CQ_ACTION_PATH = "cq:path";
public static final String PROPERTY_CQ_ACTION_PATHS = "cq:paths";
public static final String PROPERTY_CQ_ACTION_REV = "cq:revision";
public static final String PROPERTY_CQ_ACTION_TIME = "cq:time";
public static final String PROPERTY_CQ_ACTION_TYPE = "cq:type";
public static final String PROPERTY_CQ_ACTION_USER = "cq:user";
public static final String NODE_PROPERTY_LAST_PUBLISHED = "cq:lastPublished";
public static final String NODE_PROPERTY_LAST_PUBLISHED_BY = "cq:lastPublishedBy";
public static final String NODE_PROPERTY_LAST_REPLICATED = "cq:lastReplicated";
public static final String NODE_PROPERTY_LAST_REPLICATED_BY = "cq:lastReplicatedBy";
public static final String NODE_PROPERTY_LAST_REPLICATION_ACTION = "cq:lastReplicationAction";
public static final String NODE_PROPERTY_LAST_REPLICATION_STATUS = "cq:lastReplicationStatus";
public static final String NODE_TYPE = "cq:ReplicationStatus";
private final Job job;
private final JobExecutionContext context;
private ReplicationAction action;
public ReplicationJob(Job job) {
this(job, null);
}
public ReplicationJob(Job job, JobExecutionContext context) {
this.job = job;
if (!job.getTopic().startsWith("com/day/cq/replication/job/")) {
throw new IllegalArgumentException("Invalid topic for replication job: " + job.getTopic());
}
this.context = context;
}
public Object getProperty(String name) {
if (":sling:jobs:asynchandler".equals(name)) {
return this.context;
}
return this.job.getProperty(name);
}
public String getEventId() {
return this.job.getId();
}
public String getPath() {
ReplicationAction action;
String path = (String)this.getProperty("cq:path");
if (path == null && (action = this.getAction()) != null) {
path = action.getPath();
}
return path;
}
public String getQueueName() {
String name = this.job.getTopic();
if (name == null || !name.startsWith("com/day/cq/replication/job/")) {
log.error("Invalid queue name: {}", (Object)name);
return null;
}
return name.substring(JOB_TOPIC_LENGTH + 1);
}
public ReplicationContentFacade getContent() {
return (ReplicationContentFacade)this.getProperty("replicationContent");
}
public ReplicationAction getAction() {
if (this.action == null) {
this.action = (ReplicationAction)this.getProperty("replicationAction");
if (this.action == null) {
Object lastMod = this.getProperty("cq:time");
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[])this.getProperty("cq:paths");
if (paths == null) {
paths = new String[]{(String)this.getProperty("cq:path")};
}
this.action = new ReplicationAction(ReplicationActionType.fromName((String)this.getProperty("cq:type")), paths, time, (String)this.getProperty("cq:user"), (String)this.getProperty("cq:revision"));
}
}
return this.action;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("ReplicationJob");
sb.append("{job=").append((Object)this.job);
sb.append('}');
return sb.toString();
}
}