ModelConversionUtil.java 11.2 KB
/*
 * 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()));
    }

}