GuideModuleImporterImpl.java
9.78 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemds.guide.service.GuideModuleImporter
* com.adobe.dct.exception.DCTException
* com.adobe.dct.service.DataDictionaryUtilService
* com.adobe.dct.transfer.DataDictionaryInstance
* com.adobe.icc.dbforms.obj.Letter
* com.adobe.icc.ddg.api.HTML5ModuleResolverService
* com.adobe.icc.ddg.api.HTML5ModuleResolverService$ResolutionType
* com.adobe.icc.render.obj.ContextData
* com.adobe.icc.services.api.LetterService
* org.apache.commons.lang3.StringUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.fd.adaddon.service.impl;
import com.adobe.aemds.guide.service.GuideModuleImporter;
import com.adobe.dct.exception.DCTException;
import com.adobe.dct.service.DataDictionaryUtilService;
import com.adobe.dct.transfer.DataDictionaryInstance;
import com.adobe.fd.adaddon.internal.utils.ADUtils;
import com.adobe.fd.adaddon.service.impl.ADHelperServiceImpl;
import com.adobe.icc.dbforms.obj.Letter;
import com.adobe.icc.ddg.api.HTML5ModuleResolverService;
import com.adobe.icc.render.obj.ContextData;
import com.adobe.icc.services.api.LetterService;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.xpath.XPathExpressionException;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
@Component(immediate=1, label="AD Module Resolver", description="AD Module Resolver.")
@Service(value={GuideModuleImporter.class})
public class GuideModuleImporterImpl
implements GuideModuleImporter {
private Logger logger = LoggerFactory.getLogger(GuideModuleImporterImpl.class);
@Reference
ADHelperServiceImpl adHelperService;
@Reference
private LetterService letterService;
@Reference
private DataDictionaryUtilService dataDictionaryUtilService;
@Reference
private HTML5ModuleResolverService html5ModuleResolverService;
private Object getParam(String paramName, Map<String, Object> moduleParameter) {
if (moduleParameter != null) {
return moduleParameter.get(paramName);
}
return null;
}
private ContextData getContextData(Map<String, Object> moduleParameter) {
ContextData contextData = (ContextData)this.getParam("CONTEXT_DATA", moduleParameter);
if (contextData == null) {
Map<String, String> variablesFromXML;
String letterRef = (String)this.getParam("letterRef", moduleParameter);
String ddRef = (String)this.getParam("ddRef", moduleParameter);
if (letterRef != null) {
return this.createContextDataForLetterCase(letterRef, moduleParameter);
}
if (ddRef != null && this.getParam("AD_DATA_DOCUMENT", moduleParameter) != null) {
return this.createContextDataForDDCase(ddRef, moduleParameter);
}
contextData = ADUtils.createContextData(new DataDictionaryInstance());
Map<String, String> map = variablesFromXML = moduleParameter != null ? (Map<String, String>)moduleParameter.get("VARIABLE_VALUE_MAP") : null;
if (variablesFromXML == null && this.getParam("AD_DATA_DOCUMENT", moduleParameter) != null) {
Document data = (Document)this.getParam("AD_DATA_DOCUMENT", moduleParameter);
variablesFromXML = this.extractVariablesFromDataSafe(data);
}
contextData.setLocalVariables(ADUtils.prepareVariablesMapForContextData(variablesFromXML));
}
return contextData;
}
private Map<String, String> extractVariablesFromDataSafe(Document data) {
try {
return ADUtils.extractVariablesFromData(data);
}
catch (XPathExpressionException e) {
this.logger.error("Exception ", (Throwable)e);
return new HashMap<String, String>();
}
}
private ContextData createContextDataForLetterCase(String letterRef, Map<String, Object> moduleParameter) {
Document data = (Document)this.getParam("AD_DATA_DOCUMENT", moduleParameter);
ContextData contextData = new ContextData();
try {
this.adHelperService.updateContextDataForLetter(letterRef, data, contextData);
}
catch (XPathExpressionException e) {
this.logger.error("Exception when creating context data for letter", (Throwable)e);
}
catch (DCTException e) {
this.logger.error("Exception when creating context data for letter", (Throwable)e);
}
return contextData;
}
private ContextData createContextDataForDDCase(String ddRef, Map<String, Object> moduleParameter) {
Document data = (Document)this.getParam("AD_DATA_DOCUMENT", moduleParameter);
ContextData contextData = new ContextData();
try {
this.adHelperService.updateContextDataForDD(ddRef, data, contextData);
}
catch (XPathExpressionException e) {
this.logger.error("Exception when creating context data for dd", (Throwable)e);
}
return contextData;
}
public String getModuleResolution(String assetRef, Map<String, Object> moduleParameter) {
String resolvedHtml = null;
HTML5ModuleResolverService.ResolutionType resolutionType = null;
ArrayList<String> moduleAssetRefs = new ArrayList<String>();
moduleAssetRefs.add(assetRef);
if (moduleParameter != null) {
resolutionType = (HTML5ModuleResolverService.ResolutionType)moduleParameter.get("resolutionType");
}
if (resolutionType == null) {
resolutionType = HTML5ModuleResolverService.ResolutionType.RESOLVED;
}
ContextData contextData = null;
if (resolutionType != HTML5ModuleResolverService.ResolutionType.SUMMARY) {
contextData = this.getContextData(moduleParameter);
}
resolvedHtml = this.html5ModuleResolverService.resolveDataModules(moduleAssetRefs, contextData, resolutionType);
return resolvedHtml;
}
public String getModuleGroupResolution(String assetRef, Map<String, Object> moduleParameter) {
String resolvedHtml = null;
if (moduleParameter != null) {
HTML5ModuleResolverService.ResolutionType resolutionType = (HTML5ModuleResolverService.ResolutionType)moduleParameter.get("resolutionType");
if (resolutionType == null) {
resolutionType = HTML5ModuleResolverService.ResolutionType.RESOLVED;
}
ContextData contextData = null;
if (resolutionType != HTML5ModuleResolverService.ResolutionType.SUMMARY) {
contextData = this.getContextData(moduleParameter);
}
if (!StringUtils.isEmpty((CharSequence)assetRef)) {
assetRef = StringUtils.substringAfter((String)assetRef, (String)"TAA_ID:");
if (moduleParameter.get("LETTER_OBJ") != null) {
Letter letter = (Letter)moduleParameter.get("LETTER_OBJ");
try {
resolvedHtml = this.html5ModuleResolverService.resolveTargetAreaAssignment(letter, assetRef, contextData, resolutionType);
}
catch (Exception e) {
this.logger.warn("Failed to get resolved html", (Throwable)e);
}
} else {
String letterRef = (String)moduleParameter.get("letterRef");
resolvedHtml = this.html5ModuleResolverService.resolveTargetAreaAssignment(letterRef, assetRef, contextData, resolutionType);
}
} else {
resolvedHtml = this.html5ModuleResolverService.resolveDataModules((List)moduleParameter.get("moduleList"), contextData, resolutionType);
}
}
return resolvedHtml;
}
public void extractVariablesFromData(Document data, Map<String, Object> moduleParameter) throws XPathExpressionException {
moduleParameter.put("VARIABLE_VALUE_MAP", ADUtils.extractVariablesFromData(data));
}
protected void bindAdHelperService(ADHelperServiceImpl aDHelperServiceImpl) {
this.adHelperService = aDHelperServiceImpl;
}
protected void unbindAdHelperService(ADHelperServiceImpl aDHelperServiceImpl) {
if (this.adHelperService == aDHelperServiceImpl) {
this.adHelperService = null;
}
}
protected void bindLetterService(LetterService letterService) {
this.letterService = letterService;
}
protected void unbindLetterService(LetterService letterService) {
if (this.letterService == letterService) {
this.letterService = null;
}
}
protected void bindDataDictionaryUtilService(DataDictionaryUtilService dataDictionaryUtilService) {
this.dataDictionaryUtilService = dataDictionaryUtilService;
}
protected void unbindDataDictionaryUtilService(DataDictionaryUtilService dataDictionaryUtilService) {
if (this.dataDictionaryUtilService == dataDictionaryUtilService) {
this.dataDictionaryUtilService = null;
}
}
protected void bindHtml5ModuleResolverService(HTML5ModuleResolverService hTML5ModuleResolverService) {
this.html5ModuleResolverService = hTML5ModuleResolverService;
}
protected void unbindHtml5ModuleResolverService(HTML5ModuleResolverService hTML5ModuleResolverService) {
if (this.html5ModuleResolverService == hTML5ModuleResolverService) {
this.html5ModuleResolverService = null;
}
}
}