OfferHelper.java
5.79 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.WCMMode
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* org.apache.commons.lang.StringUtils
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ValueMap
*/
package com.day.cq.analytics.testandtarget.util;
import com.day.cq.analytics.testandtarget.util.MboxHelper;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.WCMMode;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.apache.commons.lang.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
public class OfferHelper {
private static final String DISPLAY_MBOX = "* display mbox *";
public static final String PN_THIRDPARTYID = "ttThirdPartyId";
public static final String RT_CAMPAIGN = "cq/personalization/components/campaignpage";
public static final String RT_EXPERIENCE = "cq/personalization/components/experiencepage";
public static final String RT_TEASER = "cq/personalization/components/teaserpage";
public static final String RT_OFFER_PROXY = "cq/personalization/components/offerproxy";
public static final String PN_TESTANDTARGETCONFIG = "testandtargetconfig";
public static final String PN_LOCATION = "location";
public static String getOfferName(String path) {
return path.substring(1).replace("/", "-");
}
public static String getOfferName(Page offerPage, WCMMode wcmMode) {
String location = (String)offerPage.getProperties().get("location", (Object)"");
if ("".equals(location)) {
return OfferHelper.getOfferName(offerPage.getPath());
}
StringBuilder offerName = new StringBuilder(OfferHelper.getOfferLocation(offerPage, wcmMode));
offerName.append("-").append(offerPage.getParent().getName()).append("-").append(offerPage.getName());
return offerName.toString();
}
public static String getOfferName(Page offerPage, WCMMode wcmMode, String ambitName) {
if (ambitName.equals("master")) {
return OfferHelper.getOfferName(offerPage, wcmMode);
}
StringBuilder offerName = new StringBuilder(OfferHelper.getOfferLocation(offerPage, wcmMode));
return StringUtils.join((Object[])new String[]{offerName.toString(), ambitName, offerPage.getParent().getName(), offerPage.getName()}, (String)"-");
}
public static String getCampaignName(String path) {
return OfferHelper.getOfferName(path);
}
public static synchronized void setThirdPartyID(Node node, String operation, String thirdpartyid) throws RepositoryException {
if ("saveWidgetOffer".equals(operation)) {
node.setProperty("ttThirdPartyId", thirdpartyid);
} else if ("deleteWidgetOffer".equals(operation) && node.hasProperty("ttThirdPartyId")) {
node.getProperty("ttThirdPartyId").remove();
}
}
public static String getThirdPartyID(Node node) throws RepositoryException {
String thirdPartyID = null;
thirdPartyID = node.hasProperty("ttThirdPartyId") ? node.getProperty("ttThirdPartyId").getString() : Long.toString(System.currentTimeMillis());
return thirdPartyID;
}
public static String getThirdPartyCampaignId(Node contentResourceNode) throws RepositoryException {
if (contentResourceNode.hasProperty("ttThirdPartyId")) {
return contentResourceNode.getProperty("ttThirdPartyId").getString();
}
return OfferHelper.getCampaignName(contentResourceNode.getParent().getPath());
}
public static synchronized void setConfigurationPath(String path, Page page) throws RepositoryException {
Page campaignPage = OfferHelper.getCampaign(page);
if (campaignPage != null) {
Node campaignContent = (Node)campaignPage.getContentResource().adaptTo(Node.class);
campaignContent.setProperty("testandtargetconfig", path);
}
}
public static Page getCampaign(Page page) {
Page campaignPage;
for (campaignPage = page; campaignPage != null && !"cq/personalization/components/campaignpage".equals(campaignPage.getContentResource().getResourceType()); campaignPage = campaignPage.getParent()) {
}
return campaignPage;
}
public static String getOfferLocation(Page offerPage, WCMMode wcmMode) {
String location = (String)offerPage.getProperties().get("location", (Object)"");
if ("".equals(location)) {
return "* display mbox *";
}
return MboxHelper.qualifyMboxNameOrId(MboxHelper.getMboxId(location), wcmMode);
}
public static String getOfferLocation(Page offerPage, WCMMode wcmMode, String ambitName) {
if (StringUtils.isEmpty((String)ambitName) || "master".equals(ambitName)) {
return OfferHelper.getOfferLocation(offerPage, wcmMode);
}
String location = (String)offerPage.getProperties().get("location", (Object)"");
if ("".equals(location)) {
return "* display mbox *";
}
return MboxHelper.qualifyMboxNameOrId(MboxHelper.getMboxId(location), wcmMode);
}
public static long getOfferId(Page offerPage) {
return OfferHelper.getOfferId(offerPage, WCMMode.DISABLED);
}
public static long getOfferId(Page offerPage, WCMMode wcmMode) {
String idProperty = wcmMode == WCMMode.DISABLED ? "cq:publishExternalId" : "cq:authorExternalId";
ValueMap pageProps = offerPage.getProperties();
String legacyExternalId = idProperty.replace("cq:", "");
long offerId = (Long)pageProps.get(idProperty, (Object)0) != 0 ? (Long)pageProps.get(idProperty, (Object)0) : (Long)pageProps.get(legacyExternalId, (Object)0);
return offerId;
}
}