Search in sources :

Example 11 with CmsContent

use of com.publiccms.entities.cms.CmsContent in project PublicCMS-preview by sanluan.

the class ContentController method save.

/**
 * 保存内容
 *
 * @param entity
 * @param attribute
 * @param contentParamters
 * @param returnUrl
 * @param request
 * @param session
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping(value = "save", method = RequestMethod.POST)
public String save(CmsContent entity, CmsContentAttribute attribute, @ModelAttribute CmsContentParamters contentParamters, String returnUrl, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    SysSite site = getSite(request);
    if (CommonUtils.empty(returnUrl)) {
        returnUrl = site.getDynamicPath();
    }
    SysUser user = getUserFromSession(session);
    CmsCategoryModel categoryModel = categoryModelService.getEntity(new CmsCategoryModelId(entity.getCategoryId(), entity.getModelId()));
    if (ControllerUtils.verifyNotEmpty("categoryModel", categoryModel, model) || ControllerUtils.verifyCustom("contribute", null == user, model)) {
        return REDIRECT + returnUrl;
    }
    CmsCategory category = categoryService.getEntity(entity.getCategoryId());
    if (null != category && (site.getId() != category.getSiteId() || !category.isAllowContribute())) {
        category = null;
    }
    CmsModel cmsModel = modelComponent.getMap(site).get(entity.getModelId());
    if (ControllerUtils.verifyNotEmpty("category", category, model) || ControllerUtils.verifyNotEmpty("model", cmsModel, model)) {
        return REDIRECT + returnUrl;
    }
    entity.setHasFiles(cmsModel.isHasFiles());
    entity.setHasImages(cmsModel.isHasImages());
    entity.setOnlyUrl(cmsModel.isOnlyUrl());
    entity.setStatus(CmsContentService.STATUS_PEND);
    if (null != entity.getId()) {
        CmsContent oldEntity = service.getEntity(entity.getId());
        if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
            return REDIRECT + returnUrl;
        }
        entity = service.update(entity.getId(), entity, entity.isOnlyUrl() ? ignoreProperties : ignorePropertiesWithUrl);
        if (null != entity.getId()) {
            logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, "update.content", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
        }
    } else {
        entity.setSiteId(site.getId());
        entity.setUserId(user.getId());
        service.save(entity);
        if (CommonUtils.notEmpty(entity.getParentId())) {
            service.updateChilds(entity.getParentId(), 1);
        }
        logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, "save.content", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    if (entity.isHasImages() || entity.isHasFiles()) {
        contentFileService.update(entity.getId(), user.getId(), entity.isHasFiles() ? contentParamters.getFiles() : null, // 更新保存图集,附件
        entity.isHasImages() ? contentParamters.getImages() : null);
    }
    if (null != attribute.getText()) {
        attribute.setWordCount(HtmlUtils.removeHtmlTag(attribute.getText()).length());
    }
    List<ExtendField> modelExtendList = cmsModel.getExtendList();
    Map<String, String> map = ExtendUtils.getExtentDataMap(contentParamters.getModelExtendDataList(), modelExtendList);
    if (null != category && null != extendService.getEntity(category.getExtendId())) {
        List<SysExtendField> categoryExtendList = extendFieldService.getList(category.getExtendId());
        Map<String, String> categoryMap = ExtendUtils.getSysExtentDataMap(contentParamters.getCategoryExtendDataList(), categoryExtendList);
        if (CommonUtils.notEmpty(map)) {
            map.putAll(categoryMap);
        } else {
            map = categoryMap;
        }
    }
    if (CommonUtils.notEmpty(map)) {
        attribute.setData(ExtendUtils.getExtendString(map));
    } else {
        attribute.setData(null);
    }
    // 更新保存扩展字段,文本字段
    attributeService.updateAttribute(entity.getId(), attribute);
    return REDIRECT + returnUrl;
}
Also used : CmsContent(com.publiccms.entities.cms.CmsContent) LogOperate(com.publiccms.entities.log.LogOperate) SysUser(com.publiccms.entities.sys.SysUser) CmsModel(com.publiccms.views.pojo.entities.CmsModel) SysExtendField(com.publiccms.entities.sys.SysExtendField) ExtendField(com.publiccms.views.pojo.entities.ExtendField) CmsCategoryModelId(com.publiccms.entities.cms.CmsCategoryModelId) CmsCategoryModel(com.publiccms.entities.cms.CmsCategoryModel) SysSite(com.publiccms.entities.sys.SysSite) SysExtendField(com.publiccms.entities.sys.SysExtendField) CmsCategory(com.publiccms.entities.cms.CmsCategory) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with CmsContent

use of com.publiccms.entities.cms.CmsContent in project PublicCMS-preview by sanluan.

the class PublishContentDirective method execute.

@Override
public void execute(RenderHandler handler) throws IOException, Exception {
    Long id = handler.getLong("id");
    SysSite site = getSite(handler);
    Map<String, Boolean> map = new LinkedHashMap<>();
    if (CommonUtils.notEmpty(id)) {
        map.put(id.toString(), templateComponent.createContentFile(site, service.getEntity(id), null, null));
    } else {
        Long[] ids = handler.getLongArray("ids");
        if (CommonUtils.notEmpty(ids)) {
            List<CmsContent> entityList = service.getEntitys(ids);
            for (CmsContent entity : entityList) {
                map.put(entity.getId().toString(), templateComponent.createContentFile(site, entity, null, null));
            }
        }
    }
    handler.put("map", map).render();
}
Also used : CmsContent(com.publiccms.entities.cms.CmsContent) SysSite(com.publiccms.entities.sys.SysSite) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with CmsContent

use of com.publiccms.entities.cms.CmsContent in project PublicCMS-preview by sanluan.

the class CreateContentFileDirective method execute.

@Override
public void execute(RenderHandler handler) throws IOException, Exception {
    Long id = handler.getLong("id");
    String templatePath = handler.getString("templatePath");
    String filePath = handler.getString("filePath");
    Integer pageIndex = handler.getInteger("pageIndex");
    if (CommonUtils.notEmpty(id) && CommonUtils.notEmpty(templatePath) && CommonUtils.notEmpty(filePath)) {
        SysSite site = getSite(handler);
        String templateFullPath = SiteComponent.getFullFileName(site, templatePath);
        try {
            CmsContent content = contentService.getEntity(id);
            if (null != content && site.getId() == content.getSiteId()) {
                CmsCategory category = categoryService.getEntity(content.getCategoryId());
                handler.put("url", templateComponent.createContentFile(site, content, category, false, templateFullPath, filePath, pageIndex)).render();
            }
        } catch (IOException | TemplateException e) {
            handler.print(e.getMessage());
        }
    }
}
Also used : CmsContent(com.publiccms.entities.cms.CmsContent) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) CmsCategory(com.publiccms.entities.cms.CmsCategory) SysSite(com.publiccms.entities.sys.SysSite)

Example 14 with CmsContent

use of com.publiccms.entities.cms.CmsContent in project PublicCMS-preview by sanluan.

the class CmsContentService method check.

/**
 * @param siteId
 * @param userId
 * @param ids
 * @param refresh
 * @return results list
 */
public List<CmsContent> check(short siteId, Long userId, Serializable[] ids, Boolean refresh) {
    List<CmsContent> entityList = new ArrayList<>();
    for (CmsContent entity : getEntitys(ids)) {
        if (null != entity && siteId == entity.getSiteId() && STATUS_PEND == entity.getStatus()) {
            entity.setStatus(STATUS_NORMAL);
            entity.setCheckUserId(userId);
            entity.setCheckDate(CommonUtils.getDate());
            entityList.add(entity);
            if (null != refresh && refresh) {
                Date now = CommonUtils.getDate();
                if (now.after(entity.getPublishDate())) {
                    entity.setPublishDate(now);
                }
            }
        }
    }
    return entityList;
}
Also used : CmsContent(com.publiccms.entities.cms.CmsContent) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 15 with CmsContent

use of com.publiccms.entities.cms.CmsContent in project PublicCMS-preview by sanluan.

the class CmsContentService method recycle.

/**
 * @param siteId
 * @param ids
 * @return list of data deleted
 */
@SuppressWarnings("unchecked")
public List<CmsContent> recycle(short siteId, Serializable[] ids) {
    List<CmsContent> entityList = new ArrayList<>();
    for (CmsContent entity : getEntitys(ids)) {
        if (siteId == entity.getSiteId() && entity.isDisabled()) {
            if (0 < entity.getChilds()) {
                for (CmsContent child : (List<CmsContent>) getPage(new CmsContentQuery(siteId, null, null, null, null, null, entity.getId(), null, null, null, null, null, null, null, null), false, null, null, null, null).getList()) {
                    child.setDisabled(false);
                    entityList.add(child);
                }
            }
            entity.setDisabled(false);
            entityList.add(entity);
        }
    }
    return entityList;
}
Also used : CmsContent(com.publiccms.entities.cms.CmsContent) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CmsContentQuery(com.publiccms.views.pojo.query.CmsContentQuery)

Aggregations

CmsContent (com.publiccms.entities.cms.CmsContent)20 SysSite (com.publiccms.entities.sys.SysSite)12 LogOperate (com.publiccms.entities.log.LogOperate)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 CmsCategory (com.publiccms.entities.cms.CmsCategory)6 ArrayList (java.util.ArrayList)4 SysUser (com.publiccms.entities.sys.SysUser)3 Date (java.util.Date)3 CmsCategoryModel (com.publiccms.entities.cms.CmsCategoryModel)2 CmsCategoryModelId (com.publiccms.entities.cms.CmsCategoryModelId)2 SysExtendField (com.publiccms.entities.sys.SysExtendField)2 CmsModel (com.publiccms.views.pojo.entities.CmsModel)2 ExtendField (com.publiccms.views.pojo.entities.ExtendField)2 CmsContentQuery (com.publiccms.views.pojo.query.CmsContentQuery)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 CmsContentAttribute (com.publiccms.entities.cms.CmsContentAttribute)1 SysDept (com.publiccms.entities.sys.SysDept)1 SysDeptCategoryId (com.publiccms.entities.sys.SysDeptCategoryId)1