MetadataJSONUtil.java
32.3 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.dps.client.producer.utils.EntityUtils
* 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.ArticleLinks
* 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
* com.adobe.dps.producer.entity.dto.CollectionLinks
* com.adobe.dps.producer.entity.dto.ContentLink
* com.adobe.dps.producer.entity.dto.EntityLink
* com.adobe.dps.producer.entity.dto.EntityList
* com.adobe.dps.producer.entity.dto.EntityResponse
* com.adobe.dps.producer.entity.dto.LayoutEntity
* com.adobe.dps.producer.entity.dto.Status
* com.adobe.dps.producer.entity.dto.Status$Aspect
* com.adobe.dps.producer.entity.dto.Status$EventType
* com.adobe.dps.producer.entity.dto.StatusList
* org.apache.sling.api.resource.ModifiableValueMap
* org.apache.sling.commons.json.JSONArray
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* 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.DPSEntity;
import com.adobe.cq.mobile.dps.Importance;
import com.adobe.cq.mobile.dps.ProtectedAccess;
import com.adobe.cq.mobile.dps.impl.utils.DPSUtil;
import com.adobe.cq.mobile.dps.impl.utils.JSONUtil;
import com.adobe.dps.client.producer.utils.EntityUtils;
import com.adobe.dps.producer.entity.dto.ArticleEntity;
import com.adobe.dps.producer.entity.dto.ArticleLinks;
import com.adobe.dps.producer.entity.dto.BannerEntity;
import com.adobe.dps.producer.entity.dto.CollectionEntity;
import com.adobe.dps.producer.entity.dto.CollectionLinks;
import com.adobe.dps.producer.entity.dto.ContentLink;
import com.adobe.dps.producer.entity.dto.EntityLink;
import com.adobe.dps.producer.entity.dto.EntityList;
import com.adobe.dps.producer.entity.dto.EntityResponse;
import com.adobe.dps.producer.entity.dto.LayoutEntity;
import com.adobe.dps.producer.entity.dto.Status;
import com.adobe.dps.producer.entity.dto.StatusList;
import java.net.URI;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MetadataJSONUtil {
static final String JSON_KEY_ENTITY_NAME = "name";
static final String JSON_KEY_ENTITY_NODE_NAME = "entityName";
static final String JSON_KEY_ENTITY_TITLE = "title";
static final String JSON_KEY_ENTITY_SHORT_TITLE = "shortTitle";
static final String JSON_KEY_ENTITY_ABSTRACT = "abstract";
static final String JSON_KEY_ENTITY_SHORT_ABSTRACT = "shortAbstract";
static final String JSON_KEY_ENTITY_DEPARTMENT = "department";
static final String JSON_KEY_ENTITY_CATEGORY = "category";
static final String JSON_KEY_ENTITY_KEYWORDS = "keywords";
static final String JSON_KEY_ENTITY_INTERNAL_KEYWORDS = "internalKeywords";
static final String JSON_KEY_ENTITY_IMPORTANCE = "importance";
static final String JSON_KEY_ENTITY_SOURCE = "source";
static final String JSON_KEY_ENTITY_ID = "id";
static final String JSON_KEY_ENTITY_DPS_RESOURCE_TYPE = "dpsResourceType";
static final String JSON_KEY_ENTITY_CREATED = "created";
static final String JSON_KEY_ENTITY_CREATED_BY = "createdBy";
static final String JSON_KEY_ENTITY_LAST_IMPORTED = "lastImported";
static final String JSON_KEY_ENTITY_LAST_UPLOADED = "lastUploaded";
static final String JSON_KEY_ENTITY_LAST_UPLOADED_BY = "lastUploadedBy";
static final String JSON_KEY_ENTITY_LAST_PUBLISHED = "lastPublished";
static final String JSON_KEY_ENTITY_LAST_PUBLISHED_BY = "lastPublishedBy";
static final String JSON_KEY_ENTITY_LAST_MODIFIED = "lastModified";
static final String JSON_KEY_ENTITY_LAST_MODIFIED_BY = "lastModifiedBy";
static final String JSON_KEY_ENTITY_IMAGE = "image";
static final String JSON_KEY_ENTITY_PATH = "path";
public static final String JSON_KEY_ENTITY_URL = "entityURL";
static final String JSON_KEY_ARTICLE_AUTHOR = "author";
static final String JSON_KEY_ARTICLE_AUTHOR_URL = "authorURL";
static final String JSON_KEY_ARTICLE_HIDE_FROM_BROWSER = "hideFromBrowsePage";
static final String JSON_KEY_ARTICLE_IS_TRUSTED = "isTrustedContent";
static final String JSON_KEY_ARTICLE_SOCIAL_IMAGE = "socialImage";
static final String JSON_KEY_ARTICLE_TEXT = "articleText";
static final String JSON_KEY_ARTICLE_SOCIAL_SHARE_URL = "socialShareURL";
static final String JSON_KEY_ARTICLE_WEB_URL = "url";
static final String JSON_KEY_ARTICLE_ACCESS = "access";
static final String JSON_KEY_ARTICLE_IS_AD = "isAd";
static final String JSON_KEY_ARTICLE_AD_TYPE = "adType";
static final String JSON_KEY_ARTICLE_AD_CATEGORY = "adCategory";
static final String JSON_KEY_ARTICLE_ADVERTISER = "advertiser";
static final String JSON_KEY_BANNER_TAP_ACTION = "tapAction";
static final String JSON_KEY_BANNER_TAP_ACTION_URL = "tapActionURL";
static final String JSON_KEY_COLLECTION_BACKGROUND_IMAGE = "backgroundImage";
static final String JSON_KEY_COLLECTION_PRODUCT_ID = "productId";
static final String JSON_KEY_COLLECTION_HORIZONTAL_SWIPE = "horizontalSwipe";
static final String JSON_KEY_COLLECTION_ALLOW_DOWNLOAD = "allowDownload";
static final String JSON_KEY_COLLECTION_READING_POS = "readingPosition";
static final String JSON_KEY_COLLECTION_OPEN_DEFAULT = "openDefault";
static final String JSON_KEY_COLLECTION_CONTENT_LINKS = "contentLinks";
static final String JSON_KEY_COLLECTION_CONTENT_DETAILS = "contentDetails";
static final String JSON_KEY_COLLECTION_LAYOUT = "layout";
static final String JSON_KEY_COLLECTION_LAYOUT_TITLE = "layoutTitle";
private static final Logger LOGGER = LoggerFactory.getLogger(MetadataJSONUtil.class);
public static JSONObject getArticleJSON(DPSArticle entity) throws JSONException {
JSONObject entityJSON = new JSONObject();
MetadataJSONUtil.addEntityMetadata(entityJSON, entity);
entityJSON.put("socialImage", (Object)entity.getSocialImagePath());
entityJSON.put("author", (Object)entity.getAuthor());
entityJSON.put("authorURL", (Object)entity.getAuthorURL());
entityJSON.put("hideFromBrowsePage", entity.isHiddenFromBrowsePage());
entityJSON.put("isTrustedContent", entity.isTrustedContent());
if (entity.getAccess() != null) {
entityJSON.put("access", (Object)entity.getAccess().getValue());
}
entityJSON.put("isAd", entity.isAdvertisement());
if (entity.getAdType() != null) {
entityJSON.put("adType", (Object)entity.getAdType().getValue());
}
entityJSON.put("adCategory", (Object)entity.getAdCategory());
entityJSON.put("advertiser", (Object)entity.getAdvertiser());
entityJSON.put("articleText", (Object)entity.getArticleText());
entityJSON.put("socialShareURL", (Object)entity.getSocialShareURL());
entityJSON.put("url", (Object)entity.getWebArticleURL());
return entityJSON;
}
public static JSONObject getBannerJSON(DPSBanner entity) throws JSONException {
JSONObject entityJSON = new JSONObject();
MetadataJSONUtil.addEntityMetadata(entityJSON, entity);
entityJSON.put("isAd", entity.isAdvertisement());
if (entity.getAdType() != null) {
entityJSON.put("adType", (Object)entity.getAdType().getValue());
}
entityJSON.put("adCategory", (Object)entity.getAdCategory());
entityJSON.put("advertiser", (Object)entity.getAdvertiser());
entityJSON.put("tapAction", (Object)entity.getTapAction());
entityJSON.put("tapActionURL", (Object)entity.getTapActionURL());
return entityJSON;
}
private static void addEntityMetadata(JSONObject entityJSON, DPSEntity entity) throws JSONException {
entityJSON.put("name", (Object)entity.getName());
entityJSON.put("entityName", (Object)entity.getEntityName());
entityJSON.put("title", (Object)entity.getTitle());
entityJSON.put("shortTitle", (Object)entity.getShortTitle());
entityJSON.put("abstract", (Object)entity.getAbstract());
entityJSON.put("shortAbstract", (Object)entity.getShortAbstract());
entityJSON.put("department", (Object)entity.getDepartment());
entityJSON.put("category", (Object)entity.getCategory());
entityJSON.put("keywords", entity.getKeywords());
entityJSON.put("internalKeywords", entity.getInternalKeywords());
if (entity.getImportance() != null) {
entityJSON.put("importance", (Object)entity.getImportance().getValue());
}
entityJSON.put("entityType", (Object)MetadataJSONUtil.getEntityType(entity));
if (entity.isImported()) {
entityJSON.put("source", (Object)"DPS");
entityJSON.put("lastImported", (Object)DPSUtil.getJSONDateValue(entity.getLastDPSSynced()));
} else {
entityJSON.put("source", (Object)"AEM");
}
entityJSON.put("id", (Object)entity.getId());
entityJSON.put("dpsResourceType", (Object)entity.getDPSResourceType());
entityJSON.put("created", (Object)DPSUtil.getJSONDateValue(entity.getCreated()));
entityJSON.put("createdBy", (Object)entity.getCreatedBy());
entityJSON.put("lastUploaded", (Object)DPSUtil.getJSONDateValue(entity.getLastDPSUpload()));
entityJSON.put("lastUploadedBy", (Object)entity.getLastDPSUploadBy());
entityJSON.put("lastPublished", (Object)DPSUtil.getJSONDateValue(entity.getLastDPSPublished()));
entityJSON.put("lastPublishedBy", (Object)entity.getLastDPSPublishedBy());
entityJSON.put("lastModified", (Object)DPSUtil.getJSONDateValue(entity.getLastCQModified()));
entityJSON.put("lastModifiedBy", (Object)entity.getLastCQModifiedBy());
entityJSON.put("image", (Object)entity.getImagePath());
entityJSON.put("path", (Object)entity.getPath());
}
private static String getEntityType(DPSEntity dpsEntity) {
if (dpsEntity instanceof DPSArticle) {
return "article";
}
if (dpsEntity instanceof DPSBanner) {
return "banner";
}
if (dpsEntity instanceof DPSCollection) {
return "collection";
}
return null;
}
public static JSONObject getCollectionJSON(DPSCollection entity) throws JSONException {
JSONObject entityJSON = new JSONObject();
MetadataJSONUtil.addEntityMetadata(entityJSON, entity);
entityJSON.put("backgroundImage", (Object)entity.getBackgroundImagePath());
entityJSON.put("productId", (Object)entity.getProductId());
entityJSON.put("horizontalSwipe", entity.getEnableHorizontalSwipe());
entityJSON.put("allowDownload", entity.getAllowDownload());
entityJSON.put("readingPosition", (Object)entity.getReadingPosition());
entityJSON.put("openDefault", (Object)entity.getOpenDefault());
entityJSON.put("layout", (Object)entity.getLayout());
entityJSON.put("layoutTitle", (Object)entity.getLayoutTitle());
JSONArray contentLinks = entity.getContentLinks();
if (contentLinks != null) {
entityJSON.put("contentLinks", (Object)contentLinks);
}
return entityJSON;
}
public static JSONObject getArticleJSON(ArticleEntity entity, EntityList referringEntities, StatusList statusList) throws JSONException {
JSONObject entityJSON = new JSONObject();
entityJSON.put("name", (Object)entity.getEntityName());
entityJSON.put("title", (Object)entity.getTitle());
entityJSON.put("shortTitle", (Object)entity.getShortTitle());
entityJSON.put("abstract", (Object)entity.getAbstract());
entityJSON.put("shortAbstract", (Object)entity.getShortAbstract());
entityJSON.put("department", (Object)entity.getDepartment());
entityJSON.put("category", (Object)entity.getCategory());
entityJSON.put("keywords", (Collection)entity.getKeywords());
entityJSON.put("internalKeywords", (Collection)entity.getInternalKeywords());
entityJSON.put("importance", (Object)entity.getImportance());
entityJSON.put("source", (Object)"DPS");
entityJSON.put("entityType", (Object)entity.getEntityType());
entityJSON.put("dpsCreated", (Object)entity.getCreated());
entityJSON.put("dpsModified", (Object)entity.getModified());
entityJSON.put("version", (Object)entity.getVersion());
entityJSON.put("userData", (Map)entity.getUserData());
entityJSON.put("entityURL", (Object)EntityUtils.getEntityUrl((EntityResponse)entity));
if (statusList != null) {
entityJSON.put("status", (Object)MetadataJSONUtil.getStatus(statusList));
}
entityJSON.put("isAd", (Object)entity.getIsAd());
entityJSON.put("adType", (Object)entity.getAdType());
entityJSON.put("adCategory", (Object)entity.getAdCategory());
entityJSON.put("advertiser", (Object)entity.getAdvertiser());
entityJSON.put("author", (Object)entity.getAuthor());
entityJSON.put("authorURL", (Object)entity.getAuthorUrl());
entityJSON.put("hideFromBrowsePage", (Object)entity.getHideFromBrowsePage());
entityJSON.put("isTrustedContent", (Object)entity.getIsTrustedContent());
entityJSON.put("access", (Object)entity.getAccessState());
entityJSON.put("socialShareURL", (Object)entity.getSocialShareUrl());
entityJSON.put("url", (Object)entity.getUrl());
entityJSON.put("articleText", (Object)entity.getArticleText());
ArticleLinks articleLinks = entity.getLinks();
ContentLink folio = articleLinks.getArticleFolio();
if (folio != null) {
entityJSON.put("folio", (Object)(folio.getType() + " - " + folio.getHref()));
}
if (referringEntities != null) {
entityJSON.put("referenceLinks", (Object)MetadataJSONUtil.getReferringEntitiesJSON(referringEntities));
}
return entityJSON;
}
public static JSONObject getBannerJSON(BannerEntity entity, EntityList referringEntities, StatusList statusList) throws JSONException {
JSONObject entityJSON = new JSONObject();
entityJSON.put("name", (Object)entity.getEntityName());
entityJSON.put("title", (Object)entity.getTitle());
entityJSON.put("shortTitle", (Object)entity.getShortTitle());
entityJSON.put("abstract", (Object)entity.getAbstract());
entityJSON.put("shortAbstract", (Object)entity.getShortAbstract());
entityJSON.put("department", (Object)entity.getDepartment());
entityJSON.put("category", (Object)entity.getCategory());
entityJSON.put("keywords", (Collection)entity.getKeywords());
entityJSON.put("internalKeywords", (Collection)entity.getInternalKeywords());
entityJSON.put("importance", (Object)entity.getImportance());
entityJSON.put("source", (Object)"DPS");
entityJSON.put("entityType", (Object)entity.getEntityType());
entityJSON.put("dpsCreated", (Object)entity.getCreated());
entityJSON.put("dpsModified", (Object)entity.getModified());
entityJSON.put("version", (Object)entity.getVersion());
entityJSON.put("userData", (Map)entity.getUserData());
entityJSON.put("entityURL", (Object)EntityUtils.getEntityUrl((EntityResponse)entity));
if (statusList != null) {
entityJSON.put("status", (Object)MetadataJSONUtil.getStatus(statusList));
}
entityJSON.put("isAd", (Object)entity.getIsAd());
entityJSON.put("adType", (Object)entity.getAdType());
entityJSON.put("adCategory", (Object)entity.getAdCategory());
entityJSON.put("advertiser", (Object)entity.getAdvertiser());
entityJSON.put("tapAction", (Object)entity.getBannerTapAction());
entityJSON.put("tapActionURL", (Object)entity.getUrl());
if (referringEntities != null) {
entityJSON.put("referenceLinks", (Object)MetadataJSONUtil.getReferringEntitiesJSON(referringEntities));
}
return entityJSON;
}
public static JSONObject getStatusJSON(StatusList statusList) throws JSONException {
JSONObject entityJSON = new JSONObject();
if (statusList != null) {
entityJSON.put("status", (Object)MetadataJSONUtil.getStatus(statusList));
}
return entityJSON;
}
public static JSONObject getLayoutJSON(LayoutEntity entity, EntityList referringEntities, StatusList statusList) throws JSONException {
JSONObject entityJSON = new JSONObject();
entityJSON.put("name", (Object)entity.getEntityName());
entityJSON.put("title", (Object)entity.getTitle());
entityJSON.put("source", (Object)"DPS");
entityJSON.put("entityType", (Object)entity.getEntityType());
entityJSON.put("dpsCreated", (Object)entity.getCreated());
entityJSON.put("dpsModified", (Object)entity.getModified());
entityJSON.put("version", (Object)entity.getVersion());
entityJSON.put("userData", (Map)entity.getUserData());
entityJSON.put("entityURL", (Object)EntityUtils.getEntityUrl((EntityResponse)entity));
if (statusList != null) {
entityJSON.put("status", (Object)MetadataJSONUtil.getStatus(statusList));
}
if (referringEntities != null) {
entityJSON.put("referenceLinks", (Object)MetadataJSONUtil.getReferringEntitiesJSON(referringEntities));
}
return entityJSON;
}
private static void fillValueMapFromCommonJSON(ModifiableValueMap modifiableValueMap, JSONObject entityJSONObject) throws JSONException {
MetadataJSONUtil.updateString(modifiableValueMap, "jcr:title", JSONUtil.getSafeString(entityJSONObject, "title"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-title", JSONUtil.getSafeString(entityJSONObject, "title"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-id", JSONUtil.getSafeString(entityJSONObject, "entityURL"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-shortTitle", JSONUtil.getSafeString(entityJSONObject, "shortTitle"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-abstract", JSONUtil.getSafeString(entityJSONObject, "abstract"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-shortAbstract", JSONUtil.getSafeString(entityJSONObject, "shortAbstract"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-department", JSONUtil.getSafeString(entityJSONObject, "department"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-category", JSONUtil.getSafeString(entityJSONObject, "category"));
MetadataJSONUtil.updateObject(modifiableValueMap, "dps-keywords", (Object)JSONUtil.getSafeJSONArray(entityJSONObject, "keywords"));
MetadataJSONUtil.updateObject(modifiableValueMap, "dps-internalKeywords", (Object)JSONUtil.getSafeJSONArray(entityJSONObject, "internalKeywords"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-importance", JSONUtil.getSafeString(entityJSONObject, "importance"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-version", JSONUtil.getSafeString(entityJSONObject, "version"));
}
private static void fillValueMapFromEntityCommonJSON(ModifiableValueMap modifiableValueMap, JSONObject entityJSONObject) throws JSONException {
MetadataJSONUtil.fillValueMapFromCommonJSON(modifiableValueMap, entityJSONObject);
MetadataJSONUtil.updateObject(modifiableValueMap, "dps-isAdvertisement", JSONUtil.getSafeObject(entityJSONObject, "isAd"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-adType", JSONUtil.getSafeString(entityJSONObject, "adType"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-adCategory", JSONUtil.getSafeString(entityJSONObject, "adCategory"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-advertiser", JSONUtil.getSafeString(entityJSONObject, "advertiser"));
}
public static void fillValueMapFromArticleJSON(ModifiableValueMap modifiableValueMap, JSONObject entityJSONObject) throws JSONException {
MetadataJSONUtil.fillValueMapFromEntityCommonJSON(modifiableValueMap, entityJSONObject);
MetadataJSONUtil.updateString(modifiableValueMap, "dps-author", JSONUtil.getSafeString(entityJSONObject, "author"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-authorURL", JSONUtil.getSafeString(entityJSONObject, "authorURL"));
MetadataJSONUtil.updateObject(modifiableValueMap, "dps-hideFromBrowsePage", JSONUtil.getSafeObject(entityJSONObject, "hideFromBrowsePage"));
MetadataJSONUtil.updateObject(modifiableValueMap, "dps-isTrustedContent", JSONUtil.getSafeObject(entityJSONObject, "isTrustedContent"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-access", JSONUtil.getSafeString(entityJSONObject, "access"));
MetadataJSONUtil.updateObject(modifiableValueMap, "dps-articleText", JSONUtil.getSafeString(entityJSONObject, "articleText"));
MetadataJSONUtil.updateObject(modifiableValueMap, "dps-socialShareURL", JSONUtil.getSafeString(entityJSONObject, "socialShareURL"));
MetadataJSONUtil.updateObject(modifiableValueMap, "dps-url", JSONUtil.getSafeString(entityJSONObject, "url"));
}
public static void fillValueMapFromBannerJSON(ModifiableValueMap modifiableValueMap, JSONObject entityJSONObject) throws JSONException {
MetadataJSONUtil.fillValueMapFromEntityCommonJSON(modifiableValueMap, entityJSONObject);
MetadataJSONUtil.updateObject(modifiableValueMap, "dps-tapAction", JSONUtil.getSafeString(entityJSONObject, "tapAction"));
MetadataJSONUtil.updateObject(modifiableValueMap, "dps-tapActionURL", JSONUtil.getSafeString(entityJSONObject, "tapActionURL"));
}
public static JSONArray getReferringEntitiesJSON(EntityList referringEntities) throws JSONException {
JSONArray array = new JSONArray();
for (EntityLink link : referringEntities) {
JSONObject linkJSON = new JSONObject();
URI href = link.getHref();
linkJSON.put("href", (Object)href);
linkJSON.put("name", (Object)MetadataJSONUtil.getLinkName(href.getPath()));
linkJSON.put("version", (Object)MetadataJSONUtil.getLinkVersion(href.getPath()));
linkJSON.put("type", (Object)link.getType());
linkJSON.put("class", link.getClass());
array.put((Object)linkJSON);
}
return array;
}
private static JSONObject getStatus(StatusList statusList) throws JSONException {
JSONObject statusListJSON = new JSONObject();
for (Status status : statusList) {
if (!status.getAspect().equals((Object)Status.Aspect.PUBLISHING) && !status.getAspect().equals((Object)Status.Aspect.PREVIEW)) continue;
JSONObject statusJSON = new JSONObject();
String type = status.getAspect().name();
statusJSON.put("type", (Object)type);
statusJSON.put("status", (Object)status.getEventType());
statusJSON.put("lastStatus", (Object)status.getEventDate());
statusListJSON.put(type, (Object)statusJSON);
}
return statusListJSON;
}
public static JSONObject getCollectionJSON(CollectionEntity entity, EntityList contentEntities, EntityList referringEntities, StatusList statusList) throws JSONException {
JSONObject entityJSON = new JSONObject();
entityJSON.put("name", (Object)entity.getEntityName());
entityJSON.put("title", (Object)entity.getTitle());
entityJSON.put("shortTitle", (Object)entity.getShortTitle());
entityJSON.put("abstract", (Object)entity.getAbstract());
entityJSON.put("shortAbstract", (Object)entity.getShortAbstract());
entityJSON.put("department", (Object)entity.getDepartment());
entityJSON.put("category", (Object)entity.getCategory());
entityJSON.put("keywords", (Collection)entity.getKeywords());
entityJSON.put("internalKeywords", (Collection)entity.getInternalKeywords());
entityJSON.put("importance", (Object)entity.getImportance());
entityJSON.put("source", (Object)"DPS");
entityJSON.put("entityType", (Object)entity.getEntityType());
entityJSON.put("dpsCreated", (Object)entity.getCreated());
entityJSON.put("dpsModified", (Object)entity.getModified());
entityJSON.put("version", (Object)entity.getVersion());
entityJSON.put("userData", (Map)entity.getUserData());
entityJSON.put("entityURL", (Object)EntityUtils.getEntityUrl((EntityResponse)entity));
if (statusList != null) {
entityJSON.put("status", (Object)MetadataJSONUtil.getStatus(statusList));
}
entityJSON.put("productId", (Collection)entity.getProductIds());
entityJSON.put("horizontalSwipe", (Object)entity.getLateralNavigation());
entityJSON.put("allowDownload", (Object)entity.getAllowDownload());
entityJSON.put("readingPosition", (Object)entity.getReadingPosition());
entityJSON.put("openDefault", (Object)entity.getOpenTo());
CollectionLinks collectionLinks = entity.getLinks();
EntityLink layoutLink = collectionLinks.getLayout();
if (layoutLink != null) {
entityJSON.put("layout", (Object)layoutLink.getHref());
entityJSON.put("layoutTitle", (Object)layoutLink.getName());
}
if (contentEntities != null) {
JSONArray contentLinksArray = new JSONArray();
entityJSON.put("contentLinks", (Object)contentLinksArray);
for (EntityLink link : contentEntities) {
JSONObject linkJSON = new JSONObject();
URI href = link.getHref();
linkJSON.put("href", (Object)href);
linkJSON.put("name", (Object)MetadataJSONUtil.getLinkName(href.getPath()));
linkJSON.put("version", (Object)MetadataJSONUtil.getLinkVersion(href.getPath()));
linkJSON.put("type", (Object)link.getType());
linkJSON.put("class", link.getClass());
contentLinksArray.put((Object)linkJSON);
}
}
if (referringEntities != null) {
entityJSON.put("referenceLinks", (Object)MetadataJSONUtil.getReferringEntitiesJSON(referringEntities));
}
return entityJSON;
}
public static void fillValueMapFromCollectionJSON(ModifiableValueMap modifiableValueMap, JSONObject entityJSONObject, boolean localAEMOwned) throws JSONException {
MetadataJSONUtil.fillValueMapFromCommonJSON(modifiableValueMap, entityJSONObject);
MetadataJSONUtil.updateString(modifiableValueMap, "dps-productId", MetadataJSONUtil.getProductId(entityJSONObject));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-horizontalSwipe", JSONUtil.getSafeString(entityJSONObject, "horizontalSwipe"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-allowDownload", JSONUtil.getSafeString(entityJSONObject, "allowDownload"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-readingPosition", JSONUtil.getSafeString(entityJSONObject, "readingPosition"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-openDefault", JSONUtil.getSafeString(entityJSONObject, "openDefault"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-layout", JSONUtil.getSafeString(entityJSONObject, "layout"));
MetadataJSONUtil.updateString(modifiableValueMap, "dps-layoutTitle", JSONUtil.getSafeString(entityJSONObject, "layoutTitle"));
JSONArray contentEntities = JSONUtil.getSafeJSONArray(entityJSONObject, "contentLinks");
if (contentEntities != null) {
String[] contentLinksArray = new String[contentEntities.length()];
for (int i = 0; i < contentEntities.length(); ++i) {
JSONObject linkJSON = contentEntities.getJSONObject(i);
contentLinksArray[i] = linkJSON.toString();
}
modifiableValueMap.put((Object)"dps-contentLinks", (Object)contentLinksArray);
}
}
private static String getProductId(JSONObject entityJSONObject) {
String productId = null;
try {
JSONArray productIds = JSONUtil.getSafeJSONArray(entityJSONObject, "productId");
if (productIds != null && productIds.length() > 0) {
productId = productIds.getString(0);
}
}
catch (JSONException ex) {
LOGGER.warn("Failed to get productId from " + JSONUtil.getSafeString(entityJSONObject, "url"), (Throwable)ex);
}
return productId;
}
public static String getLinkName(String href) {
String uri = href;
int versionDelim = href.lastIndexOf(";");
if (versionDelim > 0) {
uri = href.substring(0, versionDelim);
uri = uri.substring(uri.lastIndexOf("/") + 1);
} else {
uri = uri.substring(uri.lastIndexOf("/") + 1);
}
return uri;
}
public static String stripVersionFromURI(String href) {
String uri = href;
int versionDelim = href.indexOf(";");
if (versionDelim > 0) {
uri = href.substring(0, versionDelim);
}
return uri;
}
public static String getLinkVersion(String href) {
String version = href;
int versionDelim = href.indexOf(";");
if (versionDelim > 0) {
String versionPart = href.substring(href.lastIndexOf(";"), href.length());
version = versionPart.substring(versionPart.indexOf("=") + 1, versionPart.length());
}
return version;
}
public static void mergeEntity(JSONObject existingEntityJSON, JSONObject aemEntityJSON, boolean includeDiffs) throws JSONException {
Iterator keys = aemEntityJSON.keys();
JSONArray diffs = new JSONArray();
while (keys.hasNext()) {
String key = (String)keys.next();
if (existingEntityJSON.has(key) && !aemEntityJSON.get(key).toString().equals(existingEntityJSON.get(key).toString())) {
JSONObject diff = new JSONObject();
diff.put(key, existingEntityJSON.get(key));
diffs.put((Object)diff);
}
existingEntityJSON.put(key, aemEntityJSON.get(key));
}
if (includeDiffs && diffs.length() > 0) {
existingEntityJSON.put("_diffs", (Object)diffs);
}
}
private static void updateString(ModifiableValueMap modifiableValueMap, String pnKey, String value) {
if (value != null) {
modifiableValueMap.put((Object)pnKey, (Object)value);
}
}
private static void updateObject(ModifiableValueMap modifiableValueMap, String pnKey, Object value) {
if (value != null) {
if (value instanceof JSONArray) {
JSONArray arrayValue = (JSONArray)value;
if (arrayValue.length() > 0) {
String[] arrayListValues = new String[arrayValue.length()];
for (int i = 0; i < arrayValue.length(); ++i) {
try {
arrayListValues[i] = arrayValue.getString(i);
continue;
}
catch (JSONException jsonEx) {
LOGGER.error("Error saving value index '{}' for '{}'.", (Object)i, (Object)pnKey);
}
}
modifiableValueMap.put((Object)pnKey, (Object)arrayListValues);
}
} else {
modifiableValueMap.put((Object)pnKey, value);
}
}
}
}