GetEntity.java 5.33 KB
/*
 * 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;
    }
}