Search in sources :

Example 6 with CmsPlace

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

the class PlaceController method save.

/**
 * @param entity
 * @param returnUrl
 * @param placeParamters
 * @param request
 * @param session
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping(value = "save")
public String save(CmsPlace entity, String returnUrl, @ModelAttribute CmsPlaceParamters placeParamters, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    SysSite site = getSite(request);
    if (CommonUtils.empty(returnUrl)) {
        returnUrl = site.getDynamicPath();
    }
    if (null != entity && CommonUtils.notEmpty(entity.getPath())) {
        entity.setPath(entity.getPath().replace("//", SEPARATOR));
        String filePath = siteComponent.getWebTemplateFilePath(site, TemplateComponent.INCLUDE_DIRECTORY + entity.getPath());
        CmsPlaceMetadata metadata = metadataComponent.getPlaceMetadata(filePath);
        SysUser user = getUserFromSession(session);
        if (ControllerUtils.verifyCustom("contribute", null == metadata || !metadata.isAllowContribute() || 0 >= metadata.getSize() || (null == user && !metadata.isAllowAnonymous()), model)) {
            return REDIRECT + returnUrl;
        }
        if (null != entity.getId()) {
            CmsPlace oldEntity = service.getEntity(entity.getId());
            if (null == oldEntity || CommonUtils.empty(oldEntity.getUserId()) || null == user || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model) || ControllerUtils.verifyNotEquals("siteId", user.getId(), oldEntity.getUserId(), model)) {
                return REDIRECT + returnUrl;
            }
            entity = service.update(entity.getId(), entity, ignoreProperties);
            logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, "update.place", RequestUtils.getIpAddress(request), CommonUtils.getDate(), entity.getPath()));
        } else {
            entity.setSiteId(site.getId());
            Long userId = null;
            if (null != user) {
                userId = user.getId();
                entity.setUserId(user.getId());
            }
            service.save(entity);
            logOperateService.save(new LogOperate(site.getId(), userId, LogLoginService.CHANNEL_WEB, "save.place", RequestUtils.getIpAddress(request), CommonUtils.getDate(), entity.getPath()));
        }
        Map<String, String> map = ExtendUtils.getExtentDataMap(placeParamters.getExtendDataList(), metadataComponent.getPlaceMetadata(filePath).getExtendList());
        String extentString = ExtendUtils.getExtendString(map);
        attributeService.updateAttribute(entity.getId(), extentString);
    }
    return REDIRECT + returnUrl;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) CmsPlace(com.publiccms.entities.cms.CmsPlace) SysUser(com.publiccms.entities.sys.SysUser) CmsPlaceMetadata(com.publiccms.views.pojo.entities.CmsPlaceMetadata) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

CmsPlace (com.publiccms.entities.cms.CmsPlace)6 SysSite (com.publiccms.entities.sys.SysSite)5 LogOperate (com.publiccms.entities.log.LogOperate)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 SysUser (com.publiccms.entities.sys.SysUser)3 CmsPlaceMetadata (com.publiccms.views.pojo.entities.CmsPlaceMetadata)3 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1