ResourcesMetadata.java 1.49 KB
package com.yohoufo.resource.model;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.beanutils.BeanUtils;

import com.google.common.base.Throwables;
import com.yohoufo.dal.resource.model.Resources;
import com.yohoufo.dal.resource.model.ResourcesContentData;

import lombok.Data;
import lombok.Builder;
import lombok.extern.slf4j.Slf4j;

@Data
@Builder
@Slf4j
public class ResourcesMetadata implements Serializable {

    private String contentCode;

    private Resources resources;

    private List<ResourcesContentData> resourcesContentDatas;
    //首页资源位焦点图个性化推荐数量
    private int topBannerNum;

    public ResourcesMetadata cloneBean() {
        try {
            ResourcesMetadataBuilder builder = ResourcesMetadata.builder().contentCode(contentCode);
            builder.resources(cloneBean(resources));
            builder.resourcesContentDatas(getResourcesContentDatas().stream().map(e -> cloneBean(e)).collect(Collectors.toList()));
            builder.topBannerNum(topBannerNum);
            return builder.build();
        } catch (Exception e) {
            log.error("clone {} exception.", ResourcesMetadata.class.getName(), e);
            throw new RuntimeException("clone ResourcesMetadata exception:", e);
        }
    }

    private <T> T cloneBean(T e) {
        try {
            return (T) BeanUtils.cloneBean(e);
        } catch (Exception e1) {
            throw Throwables.propagate(e1);
        }
    }

}