ModelConversionUtil.java
11.2 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.dps.producer.entity.dto.ArticleEntity
* com.adobe.dps.producer.entity.dto.ArticleEntity$AccessState
* com.adobe.dps.producer.entity.dto.ArticleEntity$AdType
* com.adobe.dps.producer.entity.dto.ArticleEntity$Importance
* com.adobe.dps.producer.entity.dto.BannerEntity
* com.adobe.dps.producer.entity.dto.BannerEntity$AdType
* com.adobe.dps.producer.entity.dto.BannerEntity$BannerTapAction
* com.adobe.dps.producer.entity.dto.BannerEntity$Importance
* com.adobe.dps.producer.entity.dto.CollectionEntity
* com.adobe.dps.producer.entity.dto.CollectionEntity$Importance
* com.adobe.dps.producer.entity.dto.CollectionEntity$OpenTo
* com.adobe.dps.producer.entity.dto.CollectionEntity$ReadingPosition
* org.apache.commons.lang3.StringUtils
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.mobile.dps.impl.utils;
import com.adobe.cq.mobile.dps.AdType;
import com.adobe.cq.mobile.dps.DPSArticle;
import com.adobe.cq.mobile.dps.DPSBanner;
import com.adobe.cq.mobile.dps.DPSCollection;
import com.adobe.cq.mobile.dps.Importance;
import com.adobe.cq.mobile.dps.ProtectedAccess;
import com.adobe.dps.producer.entity.dto.ArticleEntity;
import com.adobe.dps.producer.entity.dto.BannerEntity;
import com.adobe.dps.producer.entity.dto.CollectionEntity;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ModelConversionUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(ModelConversionUtil.class);
public static ArticleEntity.AccessState convertAccessState(ProtectedAccess access) {
if (access != null) {
switch (access) {
case FREE: {
return ArticleEntity.AccessState.FREE;
}
case PROTECTED: {
return ArticleEntity.AccessState.PROTECTED;
}
case METERED: {
return ArticleEntity.AccessState.METERED;
}
}
LOGGER.warn("Failed to convert to AccessState " + (Object)((Object)access));
}
return null;
}
public static ArticleEntity.AdType convertAdType(DPSArticle dpsEntity) {
AdType adType = dpsEntity.getAdType();
if (adType != null) {
switch (adType) {
case STATIC: {
return ArticleEntity.AdType.STATIC;
}
case EFT: {
return ArticleEntity.AdType.EFT;
}
}
LOGGER.warn("Failed to convert to AdType " + (Object)((Object)adType));
}
return null;
}
public static BannerEntity.AdType convertAdType(DPSBanner dpsEntity) {
AdType adType = dpsEntity.getAdType();
if (adType != null) {
switch (adType) {
case STATIC: {
return BannerEntity.AdType.STATIC;
}
case EFT: {
return BannerEntity.AdType.EFT;
}
}
LOGGER.warn("Failed to convert to AdType " + (Object)((Object)adType));
}
return null;
}
public static ArticleEntity.Importance convertToArticleImportance(Importance importance) {
if (importance != null) {
switch (importance) {
case HIGH: {
return ArticleEntity.Importance.HIGH;
}
case NORMAL: {
return ArticleEntity.Importance.NORMAL;
}
case LOW: {
return ArticleEntity.Importance.LOW;
}
}
LOGGER.warn("Failed to convert to Importance " + (Object)((Object)importance));
}
return null;
}
public static BannerEntity.Importance convertToBannerImportance(Importance importance) {
if (importance != null) {
switch (importance) {
case HIGH: {
return BannerEntity.Importance.HIGH;
}
case NORMAL: {
return BannerEntity.Importance.NORMAL;
}
case LOW: {
return BannerEntity.Importance.LOW;
}
}
LOGGER.warn("Failed to convert to Importance " + (Object)((Object)importance));
}
return null;
}
public static CollectionEntity.Importance convertToCollectionImportance(Importance importance) {
if (importance != null) {
switch (importance) {
case HIGH: {
return CollectionEntity.Importance.HIGH;
}
case NORMAL: {
return CollectionEntity.Importance.NORMAL;
}
case LOW: {
return CollectionEntity.Importance.LOW;
}
}
LOGGER.warn("Failed to convert to Importance " + (Object)((Object)importance));
}
return null;
}
public static CollectionEntity.ReadingPosition convertToCollectionReadingPosition(String value) {
CollectionEntity.ReadingPosition readingPosition = null;
if (value != null) {
try {
readingPosition = CollectionEntity.ReadingPosition.fromValue((String)value);
}
catch (Exception ex) {
LOGGER.warn("Failed to convert to ReadingPosition " + value, (Throwable)ex);
}
}
return readingPosition;
}
public static CollectionEntity.OpenTo convertToCollectionOpenTo(String value) {
CollectionEntity.OpenTo openTo = null;
if (value != null) {
try {
openTo = CollectionEntity.OpenTo.fromValue((String)value);
}
catch (Exception ex) {
LOGGER.warn("Failed to convert to OpenTo " + value, (Throwable)ex);
}
}
return openTo;
}
public static void updateEntity(ArticleEntity article, DPSArticle dpsArticle) throws Exception {
article.setTitle(dpsArticle.getTitle());
article.setShortTitle(dpsArticle.getShortTitle());
article.setAbstract(dpsArticle.getAbstract());
article.setShortAbstract(dpsArticle.getShortAbstract());
article.setDepartment(dpsArticle.getDepartment());
article.setCategory(dpsArticle.getCategory());
article.setKeywords(dpsArticle.getKeywords());
article.setInternalKeywords(dpsArticle.getInternalKeywords());
article.setImportance(ModelConversionUtil.convertToArticleImportance(dpsArticle.getImportance()));
HashMap<String, String> userData = new HashMap<String, String>();
userData.put("aem.path", dpsArticle.getPath());
article.setUserData(userData);
article.setAuthor(dpsArticle.getAuthor());
if (StringUtils.isNotEmpty((CharSequence)dpsArticle.getAuthorURL())) {
article.setAuthorUrl(new URI(dpsArticle.getAuthorURL()));
}
article.setHideFromBrowsePage(Boolean.valueOf(dpsArticle.isHiddenFromBrowsePage()));
article.setIsTrustedContent(Boolean.valueOf(dpsArticle.isTrustedContent()));
article.setAccessState(ModelConversionUtil.convertAccessState(dpsArticle.getAccess()));
article.setIsAd(Boolean.valueOf(dpsArticle.isAdvertisement()));
article.setAdType(ModelConversionUtil.convertAdType(dpsArticle));
article.setAdCategory(dpsArticle.getAdCategory());
article.setAdvertiser(dpsArticle.getAdvertiser());
article.setArticleText(dpsArticle.getArticleText());
if (StringUtils.isNotEmpty((CharSequence)dpsArticle.getSocialShareURL())) {
article.setSocialShareUrl(new URI(dpsArticle.getSocialShareURL()));
}
if (StringUtils.isNotEmpty((CharSequence)dpsArticle.getWebArticleURL())) {
article.setUrl(new URI(dpsArticle.getWebArticleURL()));
}
}
public static void updateEntity(BannerEntity banner, DPSBanner dpsBanner) throws Exception {
banner.setTitle(dpsBanner.getTitle());
banner.setShortTitle(dpsBanner.getShortTitle());
banner.setAbstract(dpsBanner.getAbstract());
banner.setShortAbstract(dpsBanner.getShortAbstract());
banner.setDepartment(dpsBanner.getDepartment());
banner.setCategory(dpsBanner.getCategory());
banner.setKeywords(dpsBanner.getKeywords());
banner.setInternalKeywords(dpsBanner.getInternalKeywords());
banner.setImportance(ModelConversionUtil.convertToBannerImportance(dpsBanner.getImportance()));
HashMap<String, String> userData = new HashMap<String, String>();
userData.put("aem.path", dpsBanner.getPath());
banner.setUserData(userData);
banner.setIsAd(Boolean.valueOf(dpsBanner.isAdvertisement()));
banner.setAdType(ModelConversionUtil.convertAdType(dpsBanner));
banner.setAdCategory(dpsBanner.getAdCategory());
banner.setAdvertiser(dpsBanner.getAdvertiser());
String tapActionStr = dpsBanner.getTapAction();
if (StringUtils.isNotEmpty((CharSequence)tapActionStr)) {
BannerEntity.BannerTapAction tapAction = BannerEntity.BannerTapAction.fromValue((String)tapActionStr);
banner.setBannerTapAction(tapAction);
}
if (StringUtils.isNotEmpty((CharSequence)dpsBanner.getTapActionURL())) {
banner.setUrl(new URI(dpsBanner.getTapActionURL()));
}
}
public static void updateEntity(CollectionEntity collectionEntity, DPSCollection dpsCollection) throws Exception {
collectionEntity.setTitle(dpsCollection.getTitle());
collectionEntity.setShortTitle(dpsCollection.getShortTitle());
collectionEntity.setAbstract(dpsCollection.getAbstract());
collectionEntity.setShortAbstract(dpsCollection.getShortAbstract());
collectionEntity.setDepartment(dpsCollection.getDepartment());
collectionEntity.setCategory(dpsCollection.getCategory());
collectionEntity.setKeywords(dpsCollection.getKeywords());
collectionEntity.setInternalKeywords(dpsCollection.getInternalKeywords());
collectionEntity.setImportance(ModelConversionUtil.convertToCollectionImportance(dpsCollection.getImportance()));
HashMap<String, String> userData = new HashMap<String, String>();
userData.put("aem.path", dpsCollection.getPath());
collectionEntity.setUserData(userData);
ArrayList<String> productIds = new ArrayList<String>();
String productId = dpsCollection.getProductId();
if (StringUtils.isNotEmpty((CharSequence)productId)) {
productIds.add(productId);
}
collectionEntity.setProductIds(productIds);
collectionEntity.setLateralNavigation(Boolean.valueOf(dpsCollection.getEnableHorizontalSwipe()));
collectionEntity.setAllowDownload(Boolean.valueOf(dpsCollection.getAllowDownload()));
collectionEntity.setReadingPosition(ModelConversionUtil.convertToCollectionReadingPosition(dpsCollection.getReadingPosition()));
collectionEntity.setOpenTo(ModelConversionUtil.convertToCollectionOpenTo(dpsCollection.getOpenDefault()));
}
}