/* ==================================================================
* Created [2009-4-27 下午11:32:55] by Jon.King
* ==================================================================
* TSS
* ==================================================================
* mailTo:jinpujun@hotmail.com
* Copyright (c) Jon.King, 2009-2012
* ==================================================================
*/
package com.jinhe.tss.cms.entity;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import com.jinhe.tss.cms.CMSConstants;
import com.jinhe.tss.cms.entity.permission.ChannelResourceView;
import com.jinhe.tss.component.dynproperty.support.AbstractDynEntity;
import com.jinhe.tss.component.support.persistence.entityaop.IDecodable;
import com.jinhe.tss.core.exception.BusinessException;
import com.jinhe.tss.core.util.BeanUtil;
import com.jinhe.tss.core.web.dispaly.tree.ILevelTreeNode;
import com.jinhe.tss.core.web.dispaly.tree.TreeAttributesMap;
import com.jinhe.tss.core.web.dispaly.xform.IXForm;
import com.jinhe.tss.um.permission.IResource;
/**
* 站点、栏目类
*/
@Entity
@Table(name = "cms_channel", uniqueConstraints = {
@UniqueConstraint(name="MULTI_NAME_CHANNEL", columnNames = { "PARENTID", "name" })
})
@SequenceGenerator(name = "channel_sequence", sequenceName = "channel_sequence", initialValue = 1, allocationSize = 1)
public class Channel extends AbstractDynEntity implements IXForm, ILevelTreeNode, IDecodable, IResource {
public final static String DYN_SITE_CODE = "site"; //动态属性站点编码
public final static String DYN_CHANNEL_CODE = "channel"; //动态属性栏目编码
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "channel_sequence")
private Long id;
private String name; // 名称(站点或栏目名称)
private Long siteId; // 栏目所在站点ID
private Integer isSite = CMSConstants.FALSE; // 判断是站点或栏目 1:站点 0:栏目
@Column(nullable = false)
private Integer workflowId; // 所属工作流编号
private Long articleTypeId; // 文章类型ID
@Transient private String workflowName; // 工作流名称
@Transient private String articleTypeName; // 文章种类名称
private String path; // 发布路径
private String imagePath; // 图片上传根路径
private String docPath; // 附件上传根路径
private String overdueDate; // 过期时间
private String remark; // 站点描述
private Integer hotArticleRule = CMSConstants.SITE_DEFAULT_HOT_ARTICLE_RULE; // 热文章规则 缺省5 0不设置
private Integer newArticleRule = CMSConstants.SITE_DEFAULT_NEW_ARTICLE_RULE; // 新文章规则 缺省1 0不设置
//状态值信息
private Integer disabled = CMSConstants.FALSE; // 状态 0:启动 1:停用
//树结构信息
private Long parentId; // 父节点编号 缺省为0,即无父节点
@Column(nullable = false)
private Integer seqNo; // 站点或栏目显示顺序
private String decode; // 层码
private Integer levelNo; // 层次值
public void setDecode(String decode) {
this.decode = decode;
}
public void setLevelNo(Integer levelNo) {
this.levelNo = levelNo;
}
public Long getArticleTypeId() {
return articleTypeId;
}
public void setArticleTypeId(Long articleTypeId) {
this.articleTypeId = articleTypeId;
}
public String getDocPath() {
return docPath;
}
public void setDocPath(String docPath) {
this.docPath = docPath;
}
public Integer getHotArticleRule() {
return hotArticleRule;
}
public void setHotArticleRule(Integer hotArticleRule) {
this.hotArticleRule = hotArticleRule;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getImagePath() {
return imagePath;
}
public void setImagePath(String imagePath) {
this.imagePath = imagePath;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getNewArticleRule() {
return newArticleRule;
}
public void setNewArticleRule(Integer newArticleRule) {
this.newArticleRule = newArticleRule;
}
public String getOverdueDate() {
return overdueDate;
}
public void setOverdueDate(String overdueDate) {
this.overdueDate = overdueDate;
}
public Long getParentId() {
return parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public Integer getSeqNo() {
return seqNo;
}
public void setSeqNo(Integer seqNo) {
this.seqNo = seqNo;
}
public Integer getDisabled() {
return disabled;
}
public void setDisabled(Integer status) {
this.disabled = status;
}
public Integer getWorkflowId() {
return workflowId;
}
public void setWorkflowId(Integer workflowId) {
this.workflowId = workflowId;
}
public String getWorkflowName() {
return workflowName;
}
public void setWorkflowName(String workflowName) {
this.workflowName = workflowName;
}
public Integer getIsSite() {
return isSite;
}
public void setIsSite(Integer isSite) {
this.isSite = isSite;
}
public Long getSiteId() {
return siteId;
}
public void setSiteId(Long siteId) {
this.siteId = siteId;
}
public String getArticleTypeName() {
return articleTypeName;
}
public void setArticleTypeName(String articleTypeName) {
this.articleTypeName = articleTypeName;
}
public Map<String, Object> getAttributesForXForm() {
Map<String, Object> attributes = new HashMap<String, Object>(super.getDynpropertiesMap());
BeanUtil.addBeanProperties2Map(this, attributes);
return attributes;
}
public TreeAttributesMap getAttributes() {
TreeAttributesMap map = new TreeAttributesMap(id, name);
map.put("disabled", this.disabled);
map.put("seqNo", this.seqNo);
map.put("articleTypeId", this.articleTypeId);
map.put("siteId", this.siteId);
map.put("isSite", this.isSite);
map.put("resourceTypeId", getResourceType());
if (isSite()) {
if (CMSConstants.FALSE.equals(disabled)) {
map.put("icon", "../platform/images/icon/site.gif");
} else {
map.put("icon", "../platform/images/icon/site_2.gif");
}
} else {
if (CMSConstants.FALSE.equals(disabled)) {
map.put("icon", "../platform/images/icon/channel.gif");
} else {
map.put("icon", "../platform/images/icon/channel_2.gif");
}
}
super.putOperateInfo2Map(map);
return map;
}
public Integer getLevelNo() {
return levelNo;
}
public String getDecode() {
return decode;
}
public String getEntityCode() {
return isSite() ? DYN_SITE_CODE : DYN_CHANNEL_CODE;
}
public String getArticlesInChannelEntityCode(){
return "article" + this.articleTypeId;
}
public boolean isSite(){
return CMSConstants.TRUE.equals(this.isSite);
}
public String getAttanchmentPath(Attachment attanchment){
if (attanchment.isImage()) {
return this.imagePath;
}
if (attanchment.isOfficeDoc()) {
return this.docPath;
}
throw new BusinessException("指定类型的附件路径不存在");
}
public String toString(){
return "(id:" + this.id + ", name:" + this.name + ", parentId:" + this.parentId + ")" + this.decode;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public String getResourceType() {
return CMSConstants.RESOURCE_TYPE_CHANNEL;
}
public Class<?> getParentClass() {
if(this.parentId.equals(CMSConstants.HEAD_NODE_ID)) {
return ChannelResourceView.class;
}
return getClass();
}
}