AbstractCallableDPSAction.java 3.68 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.Entity
 *  com.adobe.dps.producer.entity.dto.EntityList
 *  com.adobe.dps.producer.entity.dto.StatusList
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.mobile.dps.impl.service.actions;

import com.adobe.cq.mobile.dps.DPSException;
import com.adobe.cq.mobile.dps.impl.ui.PerfTimer;
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.Entity;
import com.adobe.dps.producer.entity.dto.EntityList;
import com.adobe.dps.producer.entity.dto.StatusList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AbstractCallableDPSAction {
    protected final Logger logger;
    protected final EntityProducerDAO entityAccess;
    protected final AccessToken accessToken;
    protected final Session session;

    AbstractCallableDPSAction(EntityProducerDAO entityAccess, AccessToken accessToken, Session session) {
        this.entityAccess = entityAccess;
        this.accessToken = accessToken;
        this.session = new Session(session);
        this.logger = LoggerFactory.getLogger(this.getClass());
    }

    protected Entity getEntity(String entityURI) throws ProducerException, ProducerRequestException, DPSException {
        PerfTimer perfTimer = PerfTimer.startTimer(this, "entityAccess.readEntity");
        Entity entity = this.entityAccess.readEntity(this.accessToken, entityURI, this.session);
        if (entity == null) {
            throw new DPSException("Entity not found for " + entityURI);
        }
        perfTimer.end();
        return entity;
    }

    protected EntityList getContentElements(String entityURI) throws ProducerException, ProducerRequestException {
        PerfTimer perfTimer = PerfTimer.startTimer(this, "entityAccess.getContentElements");
        EntityList contentElements = this.entityAccess.getContentElements(this.accessToken, entityURI, this.session);
        contentElements = EntityUtils.filter((EntityList)contentElements, (EntityType[])new EntityType[]{EntityType.ARTICLE, EntityType.COLLECTION, EntityType.BANNER});
        perfTimer.end();
        return contentElements;
    }

    protected EntityList getReferringEntities(String entityURI, EntityType entityType) throws ProducerException, ProducerRequestException {
        PerfTimer perfTimer = PerfTimer.startTimer(this, "entityAccess.getReferringEntities");
        EntityList referringEntities = this.entityAccess.getReferringEntities(this.accessToken, entityURI, entityType, this.session);
        perfTimer.end();
        return referringEntities;
    }

    protected StatusList getStatus(String entityURI) throws ProducerException, ProducerRequestException {
        PerfTimer perfTimer = PerfTimer.startTimer(this, "entityAccess.getEntityStatus");
        StatusList status = this.entityAccess.getEntityStatus(this.accessToken, entityURI, this.session);
        perfTimer.end();
        return status;
    }
}