Search in sources :

Example 1 with CmsModel

use of com.publiccms.views.pojo.entities.CmsModel in project PublicCMS-preview by sanluan.

the class CmsContentAdminController method save.

/**
 * 保存内容
 *
 * @param entity
 * @param attribute
 * @param contentParamters
 * @param draft
 * @param checked
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("save")
public String save(CmsContent entity, CmsContentAttribute attribute, @ModelAttribute CmsContentParamters contentParamters, Boolean draft, Boolean checked, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    SysUser user = getAdminFromSession(session);
    SysDept dept = sysDeptService.getEntity(user.getDeptId());
    if (ControllerUtils.verifyNotEmpty("deptId", user.getDeptId(), model) && ControllerUtils.verifyNotEmpty("deptId", dept, model) && ControllerUtils.verifyCustom("noright", !(dept.isOwnsAllCategory() || null != sysDeptCategoryService.getEntity(new SysDeptCategoryId(user.getDeptId(), entity.getCategoryId()))), model)) {
        return TEMPLATE_ERROR;
    }
    CmsCategoryModel categoryModel = categoryModelService.getEntity(new CmsCategoryModelId(entity.getCategoryId(), entity.getModelId()));
    if (ControllerUtils.verifyNotEmpty("categoryModel", categoryModel, model)) {
        return TEMPLATE_ERROR;
    }
    CmsCategory category = categoryService.getEntity(entity.getCategoryId());
    if (null != category && site.getId() != category.getSiteId()) {
        category = null;
    }
    CmsModel cmsModel = modelComponent.getMap(site).get(entity.getModelId());
    if (ControllerUtils.verifyNotEmpty("category", category, model) || ControllerUtils.verifyNotEmpty("model", cmsModel, model)) {
        return TEMPLATE_ERROR;
    }
    entity.setHasFiles(cmsModel.isHasFiles());
    entity.setHasImages(cmsModel.isHasImages());
    entity.setOnlyUrl(cmsModel.isOnlyUrl());
    if ((null == checked || !checked) && null != draft && draft) {
        entity.setStatus(CmsContentService.STATUS_DRAFT);
    } else {
        entity.setStatus(CmsContentService.STATUS_PEND);
    }
    Date now = CommonUtils.getDate();
    if (null == entity.getPublishDate()) {
        entity.setPublishDate(now);
    }
    if (null != attribute.getText()) {
        String text = HtmlUtils.removeHtmlTag(attribute.getText());
        attribute.setWordCount(text.length());
        if (CommonUtils.empty(entity.getDescription())) {
            entity.setDescription(StringUtils.substring(text, 0, 300));
        }
    }
    if (null != entity.getId()) {
        CmsContent oldEntity = service.getEntity(entity.getId());
        if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
            return TEMPLATE_ERROR;
        }
        entity.setUpdateDate(now);
        entity = service.update(entity.getId(), entity, entity.isOnlyUrl() ? ignoreProperties : ignorePropertiesWithUrl);
        if (null != entity) {
            logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.content", RequestUtils.getIpAddress(request), now, 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_MANAGER, "save.content", RequestUtils.getIpAddress(request), now, JsonUtils.getString(entity)));
    }
    Long[] tagIds = tagService.update(site.getId(), contentParamters.getTags());
    // 更新保存标签
    service.updateTagIds(entity.getId(), arrayToDelimitedString(tagIds, BLANK_SPACE));
    if (entity.isHasImages() || entity.isHasFiles()) {
        contentFileService.update(entity.getId(), user.getId(), entity.isHasFiles() ? contentParamters.getFiles() : null, // 更新保存图集,附件
        entity.isHasImages() ? contentParamters.getImages() : null);
    }
    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);
    // 更新保存推荐内容
    cmsContentRelatedService.update(entity.getId(), user.getId(), contentParamters.getContentRelateds());
    // 静态化
    templateComponent.createContentFile(site, entity, category, categoryModel);
    if (null != checked && checked) {
        service.check(site.getId(), user.getId(), new Long[] { entity.getId() }, false);
        if (CommonUtils.notEmpty(entity.getParentId())) {
            publish(new Long[] { entity.getParentId() }, request, session, model);
        }
        templateComponent.createCategoryFile(site, category, null, null);
    }
    return TEMPLATE_DONE;
}
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) SysDept(com.publiccms.entities.sys.SysDept) SysExtendField(com.publiccms.entities.sys.SysExtendField) ExtendField(com.publiccms.views.pojo.entities.ExtendField) SysDeptCategoryId(com.publiccms.entities.sys.SysDeptCategoryId) StringUtils.arrayToDelimitedString(org.springframework.util.StringUtils.arrayToDelimitedString) CmsCategoryModelId(com.publiccms.entities.cms.CmsCategoryModelId) CmsCategoryModel(com.publiccms.entities.cms.CmsCategoryModel) Date(java.util.Date) 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 2 with CmsModel

use of com.publiccms.views.pojo.entities.CmsModel in project PublicCMS-preview by sanluan.

the class AbstractCmsUpgrader method updateModelAddFieldList.

protected void updateModelAddFieldList(Connection connection) {
    try (Statement statement = connection.createStatement();
        ResultSet rs = statement.executeQuery("select * from sys_site")) {
        while (rs.next()) {
            String filePath = CommonConstants.CMS_FILEPATH + SEPARATOR + SiteComponent.TEMPLATE_PATH + SEPARATOR + SiteComponent.SITE_PATH_PREFIX + rs.getString("id") + SEPARATOR + SiteComponent.MODEL_FILE;
            File file = new File(filePath);
            try {
                Map<String, CmsModel> modelMap = objectMapper.readValue(file, new TypeReference<Map<String, CmsModel>>() {
                });
                if (null != modelMap && !modelMap.isEmpty()) {
                    for (CmsModel model : modelMap.values()) {
                        List<String> fieldList = new ArrayList<>();
                        Map<String, String> fieldTextMap = new HashMap<>();
                        List<String> requiredFieldList = new ArrayList<>();
                        fieldTextMap.put("title", "标题");
                        if (model.isOnlyUrl()) {
                            fieldTextMap.put("url", "网址");
                        } else {
                            fieldList.add("copied");
                            fieldTextMap.put("copied", "转载");
                            fieldTextMap.put("source", "来源");
                            fieldTextMap.put("sourceUrl", "来源网址");
                            requiredFieldList.add("source");
                            requiredFieldList.add("sourceUrl");
                            fieldList.add("content");
                            fieldTextMap.put("content", "正文");
                            requiredFieldList.add("content");
                            fieldList.add("tag");
                            fieldTextMap.put("tag", "标签");
                            fieldList.add("author");
                            fieldTextMap.put("author", "作者");
                            fieldList.add("editor");
                            fieldTextMap.put("editor", "编辑");
                        }
                        fieldList.add("description");
                        fieldTextMap.put("description", "描述");
                        requiredFieldList.add("description");
                        fieldList.add("cover");
                        fieldTextMap.put("cover", "封面图");
                        model.setFieldList(fieldList);
                        model.setFieldTextMap(fieldTextMap);
                        model.setRequiredFieldList(requiredFieldList);
                    }
                }
                try {
                    objectMapper.writeValue(file, modelMap);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } catch (IOException | ClassCastException e) {
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : CmsModel(com.publiccms.views.pojo.entities.CmsModel) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ResultSet(java.sql.ResultSet) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with CmsModel

use of com.publiccms.views.pojo.entities.CmsModel in project PublicCMS-preview by sanluan.

the class AbstractCmsUpgrader method updateModelToFile.

protected void updateModelToFile(Connection connection) throws SQLException {
    try (Statement statement = connection.createStatement();
        ResultSet rs = statement.executeQuery("select * from cms_model")) {
        while (rs.next()) {
            CmsModel entity = new CmsModel();
            String filePath = CommonConstants.CMS_FILEPATH + SEPARATOR + SiteComponent.TEMPLATE_PATH + SEPARATOR + SiteComponent.SITE_PATH_PREFIX + rs.getString("site_id") + SEPARATOR + SiteComponent.MODEL_FILE;
            File file = new File(filePath);
            file.getParentFile().mkdirs();
            Map<String, CmsModel> modelMap;
            try {
                modelMap = objectMapper.readValue(file, new TypeReference<Map<String, CmsModel>>() {
                });
            } catch (IOException | ClassCastException e) {
                modelMap = new HashMap<>();
            }
            entity.setId(rs.getString("id"));
            entity.setHasChild(rs.getBoolean("has_child"));
            entity.setHasFiles(rs.getBoolean("has_files"));
            entity.setHasImages(rs.getBoolean("has_images"));
            entity.setName(rs.getString("name"));
            entity.setOnlyUrl(rs.getBoolean("only_url"));
            if (null != rs.getString("parent_id")) {
                entity.setParentId(String.valueOf(rs.getString("parent_id")));
            }
            entity.setTemplatePath((String) rs.getString("template_path"));
            if (null != rs.getString("extend_id")) {
                List<ExtendField> extendList = new ArrayList<>();
                try (Statement extendFieldStatement = connection.createStatement();
                    ResultSet extendFieldRs = extendFieldStatement.executeQuery("select * from sys_extend_field where extend_id = " + rs.getString("extend_id"))) {
                    while (extendFieldRs.next()) {
                        ExtendField e = new ExtendField(extendFieldRs.getString("code"), extendFieldRs.getString("input_type"), extendFieldRs.getBoolean("required"), extendFieldRs.getString("name"), extendFieldRs.getString("description"), extendFieldRs.getString("default_value"));
                        extendList.add(e);
                    }
                }
                entity.setExtendList(extendList);
            }
            modelMap.put(entity.getId(), entity);
            try (FileOutputStream outputStream = new FileOutputStream(file)) {
                objectMapper.writeValue(outputStream, modelMap);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : CmsModel(com.publiccms.views.pojo.entities.CmsModel) HashMap(java.util.HashMap) Statement(java.sql.Statement) ExtendField(com.publiccms.views.pojo.entities.ExtendField) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) ResultSet(java.sql.ResultSet) TypeReference(com.fasterxml.jackson.core.type.TypeReference) File(java.io.File)

Example 4 with CmsModel

use of com.publiccms.views.pojo.entities.CmsModel 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 5 with CmsModel

use of com.publiccms.views.pojo.entities.CmsModel in project PublicCMS-preview by sanluan.

the class ModelComponent method getMap.

/**
 * @param site
 * @return model map
 */
public Map<String, CmsModel> getMap(SysSite site) {
    Map<String, CmsModel> modelMap = modelCache.get(site.getId());
    if (CommonUtils.empty(modelMap)) {
        File file = new File(siteComponent.getModelFilePath(site));
        if (CommonUtils.notEmpty(file)) {
            try {
                modelMap = objectMapper.readValue(file, new TypeReference<Map<String, CmsModel>>() {
                });
            } catch (IOException | ClassCastException e) {
                modelMap = new HashMap<>();
            }
        } else {
            modelMap = new HashMap<>();
        }
        modelCache.put(site.getId(), modelMap);
    }
    return modelMap;
}
Also used : CmsModel(com.publiccms.views.pojo.entities.CmsModel) HashMap(java.util.HashMap) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) File(java.io.File)

Aggregations

CmsModel (com.publiccms.views.pojo.entities.CmsModel)9 SysSite (com.publiccms.entities.sys.SysSite)5 LogOperate (com.publiccms.entities.log.LogOperate)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ExtendField (com.publiccms.views.pojo.entities.ExtendField)3 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 CmsCategory (com.publiccms.entities.cms.CmsCategory)2 CmsCategoryModel (com.publiccms.entities.cms.CmsCategoryModel)2 CmsCategoryModelId (com.publiccms.entities.cms.CmsCategoryModelId)2 CmsContent (com.publiccms.entities.cms.CmsContent)2 SysExtendField (com.publiccms.entities.sys.SysExtendField)2 SysUser (com.publiccms.entities.sys.SysUser)2 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 SysDept (com.publiccms.entities.sys.SysDept)1 SysDeptCategoryId (com.publiccms.entities.sys.SysDeptCategoryId)1