package com.jinhe.tss.cms;
import java.io.File;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.jinhe.tss.cms.action.ArticleAction;
import com.jinhe.tss.cms.action.ChannelAction;
import com.jinhe.tss.cms.entity.Article;
import com.jinhe.tss.cms.entity.Channel;
import com.jinhe.tss.cms.publish.PublishManger;
import com.jinhe.tss.cms.service.IArticleService;
import com.jinhe.tss.component.support.web.upload.FileUploadAction;
import com.jinhe.tss.component.support.web.upload.FileUploadManager;
import com.jinhe.tss.core.cachepool.proxy.profier.CGLIBProfiler;
import com.jinhe.tss.core.util.BeanUtil;
public class CMSCommonOperation4TestSupport extends TxSupportTest4CMS {
protected ChannelAction channelAction;
protected ArticleAction articleAction;
protected FileUploadAction fileUploadAction;
@Autowired protected IArticleService articleService;
@Autowired protected PublishManger publishManger;
@Autowired protected FileUploadManager fuManager;
public void setUp() throws Exception {
super.setUp();
channelAction = (ChannelAction) new CGLIBProfiler().getProxy(ChannelAction.class);
channelAction.setChannelService(channelService);
channelAction.setPropertyService(propertyService);
channelAction.setPublishManger(publishManger);
articleAction = (ArticleAction) new CGLIBProfiler().getProxy(ArticleAction.class);
articleAction.setService(articleService);
articleAction.setPropertyService(propertyService);
articleAction.setChannelService(channelService);
fileUploadAction = (FileUploadAction) new CGLIBProfiler().getProxy(FileUploadAction.class);
fileUploadAction.setManager(fuManager);
}
// 新建站点
protected Channel createSite() {
Channel site = new Channel();
site.setParentId(CMSConstants.HEAD_NODE_ID);
site.setName("交行门户");
site.setIsSite(CMSConstants.TRUE);
site.setArticleTypeId(defaultArticleType.getId());
site.setArticleTypeName(defaultArticleType.getName());
site.setPath("d:/Temp/cms");
site.setDocPath("docDir");
site.setImagePath("imgDir");
site.setWorkflowId(2);
site.setWorkflowName("简单工作流");
site = channelService.createChannel(site);
Long siteId = site.getId();
assertNotNull(siteId);
return site;
}
// 新建栏目
protected Channel createChannel(String name, Channel site, Long parentId) {
Channel channel = new Channel();
BeanUtil.copy(channel, site, new String[]{"id", "name"});
channel.setName(name);
channel.setSiteId(site.getId());
channel.setParentId(parentId);
channel = channelService.createChannel(channel);
return channel;
}
protected void uploadAttachment(Long channelId, Long tempArticleId, String filePath,
String fileName, Integer type) {
fileUploadAction.getParams().put("channelId", channelId.toString());
fileUploadAction.getParams().put("articleId", tempArticleId.toString());
fileUploadAction.setFile(new File(filePath));
fileUploadAction.getParams().put("type", type.toString());
fileUploadAction.getParams().put("fileName", fileName);
fileUploadAction.getParams().put("name", fileName);
fileUploadAction.execute();
}
protected Article createArticle(Channel channel, Long tempArticleId) {
Article article = articleAction.getArticle();
article.setArticleTypeId(channel.getArticleTypeId());
article.setTitle("历史的轮回怪圈");
article.setAuthor("Jon.King");
article.setSubtitle("对于当前中国社会矛盾的历史思考");
article.setKeyword("历史 轮回 社会矛盾");
article.setSummary("历史 轮回 社会矛盾");
articleAction.setArticleContent(" 最近几年以来,社会矛盾逐渐成为了中国公众瞩目的焦点---" +
"官员腐败,贫富差距扩大化,三农问题,仇富心态,教育改革,房产价格,医疗社保等一系列问题犹如走马灯" +
"一般纷纷闯入人们的视野,同时,许多富于代表性的事件也先后挑战着中国人眼球和心理的承受能力。" +
"我们的社会怎么了?相信只要稍微有点头脑的人都会问这个问题,也有很多人提出了解答。其中,有一种最为" +
"通行的说法就是:历史的轮回。具体地说来,历朝历代的统治时期大致可以分为三个阶段:" +
"1。天下创世 2。矛盾丛生3。总崩溃 个别王朝由于在中晚期实行了一些改革,缓和了社会矛盾," +
"从而延长了统治时间。这是中国历史所特有的周期性振荡。综观国史,史实让笔者也不得不承认上述说法的合理性。" +
"那么,目前的中国是否在重新陷入这个历史的轮回怪圈呢?这倒的确是一个值得商榷的问题。");
article.setWzrq(new Date());
article.setOverdueDate(new Date(System.currentTimeMillis() + 1000*60*60*24*365));
articleAction.setChannelId(channel.getId());
articleAction.setArticleId(tempArticleId);
articleAction.setAttachList("1,2");
articleAction.saveArticleInfo();
Long articleId = article.getId();
assertNotNull(articleId);
return article;
}
protected void deleteSite(Long siteId) {
channelService.deleteChannel(siteId);
List<?> list = channelService.getAllChannels();
assertNotNull(list);
assertTrue(list.isEmpty());
String hql = "select a from Article a, ChannelArticle ca, Channel c where a.id = ca.id.articleId and ca.id.channelId = c.id and c.siteId=? ";
List<?> articles = channelDao.getEntities(hql, siteId);
assertTrue(articles.isEmpty());
}
protected List<?> getArticleIdByChannelId(Long channelId) {
String hql = "select a from Article a, ChannelArticle ca where a.id = ca.id.articleId and ca.id.channelId = ? ";
return channelDao.getEntities(hql, channelId);
}
}