GuideProgressiveSectionManager.java
9.82 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.sightly.WCMUse
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.request.RequestParameter
* org.apache.sling.api.request.RequestParameterMap
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.scripting.SlingScriptHelper
* org.apache.sling.commons.json.JSONArray
* org.apache.sling.commons.json.JSONObject
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.progressive;
import com.adobe.aemds.guide.progressive.GuideProgressiveCompletionInfo;
import com.adobe.aemds.guide.progressive.GuideProgressiveField;
import com.adobe.aemds.guide.progressive.GuideProgressiveSectionInfo;
import com.adobe.aemds.guide.service.GuideProgressiveStrategy;
import com.adobe.aemds.guide.service.GuideProgressiveStrategyManager;
import com.adobe.aemds.guide.utils.GuideUtils;
import com.adobe.aemds.guide.utils.NodeStructureUtils;
import com.adobe.cq.sightly.WCMUse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.request.RequestParameter;
import org.apache.sling.api.request.RequestParameterMap;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.scripting.SlingScriptHelper;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class GuideProgressiveSectionManager
extends WCMUse {
private GuideProgressiveSectionInfo guideProgressiveSectionInfo;
private List<Object> allSections;
private GuideProgressiveCompletionInfo guideProgressiveCompletionInfo;
private Boolean fetchedFromService;
private String serviceType;
private static Logger log = LoggerFactory.getLogger(GuideProgressiveSectionManager.class);
public Boolean getFetchedFromService() {
return this.fetchedFromService;
}
public List<Object> getAllSections() {
return this.allSections;
}
public String getSectionJSON() {
if (this.guideProgressiveCompletionInfo == null) {
if (this.guideProgressiveSectionInfo != null) {
return this.guideProgressiveSectionInfo.convertToJSON();
}
return "";
}
return this.guideProgressiveCompletionInfo.convertToJSON();
}
private JSONArray extractJsonArrayFromJSONObject(JSONObject jsonObject, String arg) {
JSONArray result = new JSONArray();
if (jsonObject.has(arg)) {
try {
result = (JSONArray)jsonObject.get(arg);
}
catch (Exception e) {
log.error("Error while extracting JSON Array from JSON Object", (Throwable)e);
}
}
return result;
}
private String extractFromJSONObject(JSONObject jsonObject, String arg) {
String result = "";
if (jsonObject.has(arg)) {
try {
result = (String)jsonObject.get(arg);
}
catch (Exception e) {
log.error("Error while extracting value from JSON Object", (Throwable)e);
}
}
return result;
}
public void activate() throws Exception {
String sectionId;
SlingHttpServletRequest request = this.getRequest();
ValueMap properties = this.getProperties();
RequestParameterMap params = request.getRequestParameterMap();
String afAssetPath = (String)properties.get("guideRef", (Object)"");
String type = (String)properties.get("guideStrategyType", (Object)"");
String progressiveStrategyName = (String)properties.get("strategyName", (Object)"");
String progressiveStrategyParams = (String)properties.get("guideProgressiveStrategyParams", (Object)"");
String progressiveStrategyJcrPath = (String)properties.get("strategyJcrPath", (Object)"");
this.fetchedFromService = Boolean.TRUE;
Map<String, String> paramMap = GuideUtils.convertStringToMap(progressiveStrategyParams);
paramMap.put("sectionFieldValue", GuideUtils.paramToString(params.getValue("sectionFieldValue")));
paramMap.put("strategyJcrPath", progressiveStrategyJcrPath);
String currentSectionId = GuideUtils.paramToString(params.getValue("currentSectionId"));
paramMap.put("renderCurrentSection", GuideUtils.paramToString(params.getValue("renderCurrentSection")));
String lastSectionInfo = request.getParameter("lastSectionInfo");
JSONObject lastSectionInfoJSONObject = null;
if (lastSectionInfo != null && (sectionId = this.extractFromJSONObject(lastSectionInfoJSONObject = new JSONObject(lastSectionInfo), "id")) != null && !sectionId.isEmpty()) {
JSONArray sectionFields = this.extractJsonArrayFromJSONObject(lastSectionInfoJSONObject, "fields");
ArrayList<GuideProgressiveField> sectionFieldsList = new ArrayList<GuideProgressiveField>();
if (sectionFields != null && sectionFields.length() > 0) {
for (int i = 0; i < sectionFields.length(); ++i) {
JSONObject field = sectionFields.getJSONObject(i);
String id = field.getString("id");
String path = field.getString("path");
String prefixId = null;
if (field.has("prefixId")) {
prefixId = field.getString("prefixId");
}
GuideProgressiveField progressiveField = new GuideProgressiveField(id, path, prefixId, this.getResourceResolver());
sectionFieldsList.add(progressiveField);
}
}
if (sectionFieldsList.size() > 0) {
this.fetchedFromService = Boolean.FALSE;
String repeatablePanelPath = this.extractFromJSONObject(lastSectionInfoJSONObject, "repeatablePanelPath");
String repeatablePanelId = this.extractFromJSONObject(lastSectionInfoJSONObject, "repeatablePanelId");
String sectionTitle = this.extractFromJSONObject(lastSectionInfoJSONObject, "title");
String sectionName = this.extractFromJSONObject(lastSectionInfoJSONObject, "name");
if (repeatablePanelId != null && repeatablePanelId.isEmpty() && repeatablePanelPath != null && !repeatablePanelPath.isEmpty()) {
ResourceResolver resourceResolver = this.getResourceResolver();
Resource repeatablePanelResource = resourceResolver.getResource(repeatablePanelPath);
repeatablePanelId = NodeStructureUtils.getGuideNodeHtmlId(repeatablePanelResource);
}
this.guideProgressiveSectionInfo = new GuideProgressiveSectionInfo(sectionId, sectionTitle, sectionName, sectionFieldsList, repeatablePanelPath, repeatablePanelId, this.fetchedFromService);
} else if ("completion".equals(sectionId)) {
this.fetchedFromService = Boolean.FALSE;
String completionTitle = this.extractFromJSONObject(lastSectionInfoJSONObject, "completionTitle");
String completionBeforeMessage = this.extractFromJSONObject(lastSectionInfoJSONObject, "completionBeforeMessage");
String completionAfterMessage = this.extractFromJSONObject(lastSectionInfoJSONObject, "completionAfterMessage");
String completionScript = this.extractFromJSONObject(lastSectionInfoJSONObject, "completionScript");
String completionButtonText = this.extractFromJSONObject(lastSectionInfoJSONObject, "completionButtonText");
String completionSuccessScript = this.extractFromJSONObject(lastSectionInfoJSONObject, "completionSuccessScript");
String completionFailureScript = this.extractFromJSONObject(lastSectionInfoJSONObject, "completionFailureScript");
this.guideProgressiveCompletionInfo = new GuideProgressiveCompletionInfo(completionTitle, completionBeforeMessage, completionAfterMessage, completionScript, completionButtonText, completionSuccessScript, completionFailureScript, this.fetchedFromService);
}
}
if ("service".equals(type) && this.fetchedFromService.booleanValue()) {
paramMap.put("fetchedFromService", this.fetchedFromService.toString());
GuideProgressiveStrategyManager guideProgressiveStrategyManager = (GuideProgressiveStrategyManager)this.getSlingScriptHelper().getService(GuideProgressiveStrategyManager.class);
GuideProgressiveStrategy guideProgressiveStrategy = guideProgressiveStrategyManager.getGuideProgressiveStrategyService(progressiveStrategyName);
this.serviceType = guideProgressiveStrategy.getServiceType();
if (this.allSections == null || this.allSections.size() == 0) {
this.allSections = guideProgressiveStrategy.getAllSections(paramMap);
}
if (guideProgressiveStrategy != null) {
this.guideProgressiveSectionInfo = guideProgressiveStrategy.getNextSection(afAssetPath, currentSectionId, paramMap);
if (this.guideProgressiveSectionInfo == null) {
this.guideProgressiveCompletionInfo = guideProgressiveStrategy.getCompletionSection(afAssetPath, paramMap);
}
}
}
}
public GuideProgressiveSectionInfo getGuideProgressiveSectionInfo() {
return this.guideProgressiveSectionInfo;
}
public GuideProgressiveCompletionInfo getGuideProgressiveCompletionInfo() {
return this.guideProgressiveCompletionInfo;
}
}