PushPublishCampaignTransportHandler.java
4.67 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.replication.AgentConfig
* com.day.cq.replication.ReplicationAction
* com.day.cq.replication.ReplicationActionType
* com.day.cq.replication.ReplicationContent
* com.day.cq.replication.ReplicationContentFactory
* com.day.cq.replication.ReplicationException
* com.day.cq.replication.ReplicationLog
* com.day.cq.replication.ReplicationResult
* com.day.cq.replication.ReplicationTransaction
* com.day.cq.replication.TransportContext
* com.day.cq.replication.TransportHandler
* javax.jcr.RepositoryException
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.LoginException
* org.apache.sling.api.resource.ResourceUtil
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.analytics.testandtarget.impl;
import com.day.cq.analytics.testandtarget.TargetMediator;
import com.day.cq.analytics.testandtarget.TestandtargetException;
import com.day.cq.replication.AgentConfig;
import com.day.cq.replication.ReplicationAction;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationContent;
import com.day.cq.replication.ReplicationContentFactory;
import com.day.cq.replication.ReplicationException;
import com.day.cq.replication.ReplicationLog;
import com.day.cq.replication.ReplicationResult;
import com.day.cq.replication.ReplicationTransaction;
import com.day.cq.replication.TransportContext;
import com.day.cq.replication.TransportHandler;
import java.util.List;
import javax.jcr.RepositoryException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service(value={TransportHandler.class})
public class PushPublishCampaignTransportHandler
implements TransportHandler {
@Reference
private TargetMediator campaignMediator;
private static final Logger LOG = LoggerFactory.getLogger(PushPublishCampaignTransportHandler.class);
public boolean canHandle(AgentConfig config) {
return config.getTransportURI().startsWith("tnt://");
}
public ReplicationResult deliver(TransportContext ctx, ReplicationTransaction tx) throws ReplicationException {
try {
return this.process(tx);
}
catch (RepositoryException e) {
return this.logAndReturn(tx, (Throwable)e);
}
catch (LoginException e) {
return this.logAndReturn(tx, (Throwable)e);
}
catch (TestandtargetException e) {
return this.logAndReturn(tx, e);
}
}
private ReplicationResult logAndReturn(ReplicationTransaction tx, Throwable t) {
tx.getLog().error("Error replicating " + tx.getAction().getPath() + " - " + t.getClass().getName() + " : " + t.getMessage());
return new ReplicationResult(false, 0, t.getMessage());
}
private ReplicationResult process(ReplicationTransaction tx) throws RepositoryException, LoginException, TestandtargetException, ReplicationException {
String path = tx.getAction().getPath();
ReplicationActionType actionType = tx.getAction().getType();
LOG.debug("Received action {} for path {}", (Object)actionType, (Object)path);
switch (actionType) {
case ACTIVATE: {
this.campaignMediator.syncPublishCampaign(path);
return new ReplicationResult(true, 0, null);
}
case DEACTIVATE: {
this.campaignMediator.deactivatePublishCampaign(path);
return new ReplicationResult(true, 0, null);
}
case DELETE: {
this.campaignMediator.deactivatePublishCampaign(ResourceUtil.getParent((String)path));
return new ReplicationResult(true, 0, null);
}
}
throw new ReplicationException("Not supported");
}
public ReplicationResult poll(TransportContext ctx, ReplicationTransaction tx, List<ReplicationContent> result, ReplicationContentFactory factory) throws ReplicationException {
throw new ReplicationException("Not supported");
}
protected void bindCampaignMediator(TargetMediator targetMediator) {
this.campaignMediator = targetMediator;
}
protected void unbindCampaignMediator(TargetMediator targetMediator) {
if (this.campaignMediator == targetMediator) {
this.campaignMediator = null;
}
}
}