GetEntity.java
5.33 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.dps.client.producer.EntityProducerDAO
* com.adobe.dps.client.producer.EntityType
* com.adobe.dps.client.producer.exceptions.ProducerException
* com.adobe.dps.client.producer.exceptions.ProducerRequestException
* com.adobe.dps.client.producer.utils.AccessToken
* com.adobe.dps.client.producer.utils.EntityUtils
* com.adobe.dps.client.producer.utils.Session
* com.adobe.dps.producer.entity.dto.ArticleEntity
* com.adobe.dps.producer.entity.dto.BannerEntity
* com.adobe.dps.producer.entity.dto.CollectionEntity
* com.adobe.dps.producer.entity.dto.Entity
* 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.StatusList
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
*/
package com.adobe.cq.mobile.dps.impl.service.actions;
import com.adobe.cq.mobile.dps.DPSException;
import com.adobe.cq.mobile.dps.impl.service.actions.AbstractCallableDPSAction;
import com.adobe.cq.mobile.dps.impl.ui.PerfTimer;
import com.adobe.cq.mobile.dps.impl.utils.MetadataJSONUtil;
import com.adobe.dps.client.producer.EntityProducerDAO;
import com.adobe.dps.client.producer.EntityType;
import com.adobe.dps.client.producer.exceptions.ProducerException;
import com.adobe.dps.client.producer.exceptions.ProducerRequestException;
import com.adobe.dps.client.producer.utils.AccessToken;
import com.adobe.dps.client.producer.utils.EntityUtils;
import com.adobe.dps.client.producer.utils.Session;
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 com.adobe.dps.producer.entity.dto.Entity;
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.StatusList;
import java.util.Date;
import java.util.concurrent.Callable;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
public class GetEntity
extends AbstractCallableDPSAction
implements Callable<JSONObject> {
private final String entityHref;
private final boolean includeStatus;
private final boolean includeReferrers;
private final boolean includeContent;
private final EntityType entityType;
public GetEntity(EntityProducerDAO entityAccess, AccessToken accessToken, Session session, String entityHref, boolean includeReferrers, boolean includeStatus, boolean includeContent, EntityType entityType) {
super(entityAccess, accessToken, session);
this.entityHref = entityHref;
this.includeStatus = includeStatus;
this.includeReferrers = includeReferrers;
this.includeContent = includeContent;
this.entityType = entityType;
}
@Override
public JSONObject call() throws Exception {
return this.getEntity(this.entityType);
}
private JSONObject getEntity(EntityType entityType) throws ProducerException, ProducerRequestException, JSONException, DPSException {
PerfTimer perfTimer = PerfTimer.startTimer(this, this.getClass().getName());
EntityResponse entityResponse = (EntityResponse)this.getEntity(this.entityHref);
String entityURI = EntityUtils.getEntityUrl((EntityResponse)entityResponse);
EntityList referringEntities = null;
if (this.includeReferrers) {
referringEntities = this.getReferringEntities(entityURI, EntityType.COLLECTION);
}
StatusList status = null;
if (this.includeStatus) {
status = this.getStatus(entityURI);
}
JSONObject entityJSON = null;
if (entityType.equals((Object)EntityType.COLLECTION)) {
EntityList contentElements = null;
if (this.includeContent) {
contentElements = this.getContentElements(entityURI);
}
entityJSON = MetadataJSONUtil.getCollectionJSON((CollectionEntity)entityResponse, contentElements, referringEntities, status);
} else {
entityJSON = entityType.equals((Object)EntityType.ARTICLE) ? MetadataJSONUtil.getArticleJSON((ArticleEntity)entityResponse, referringEntities, status) : (entityType.equals((Object)EntityType.BANNER) ? MetadataJSONUtil.getBannerJSON((BannerEntity)entityResponse, referringEntities, status) : (entityType.equals((Object)EntityType.LAYOUT) ? MetadataJSONUtil.getLayoutJSON((LayoutEntity)entityResponse, referringEntities, status) : this.getDefaultEntityJSON(entityResponse)));
}
perfTimer.end();
return entityJSON;
}
private JSONObject getDefaultEntityJSON(EntityResponse entity) throws ProducerException, ProducerRequestException, JSONException {
JSONObject entityJSON = new JSONObject();
entityJSON.put("name", (Object)entity.getEntityName());
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());
return entityJSON;
}
}