Search in sources :

Example 1 with TipException

use of com.tale.exception.TipException in project tale by otale.

the class LinksController method saveLink.

@Route(value = "save", method = HttpMethod.POST)
@JSON
public RestResponse saveLink(@QueryParam String title, @QueryParam String url, @QueryParam String logo, @QueryParam Integer mid, @QueryParam(value = "sort", defaultValue = "0") int sort) {
    try {
        Metas metas = new Metas();
        metas.setName(title);
        metas.setSlug(url);
        metas.setDescription(logo);
        metas.setSort(sort);
        metas.setType(Types.LINK);
        if (null != mid) {
            metas.setMid(mid);
            metasService.update(metas);
        } else {
            metasService.saveMeta(metas);
        }
        siteService.cleanCache(Types.C_STATISTICS);
    } catch (Exception e) {
        String msg = "友链保存失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
    return RestResponse.ok();
}
Also used : Metas(com.tale.model.Metas) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException) JSON(com.blade.mvc.annotation.JSON) Route(com.blade.mvc.annotation.Route)

Example 2 with TipException

use of com.tale.exception.TipException in project tale by otale.

the class PageController method modifyArticle.

@Route(value = "modify", method = HttpMethod.POST)
@JSON
public RestResponse modifyArticle(@QueryParam Integer cid, @QueryParam String title, @QueryParam String content, @QueryParam String fmt_type, @QueryParam String status, @QueryParam String slug, @QueryParam Boolean allow_comment) {
    Users users = this.user();
    Contents contents = new Contents();
    contents.setCid(cid);
    contents.setTitle(title);
    contents.setContent(content);
    contents.setStatus(status);
    contents.setFmt_type(fmt_type);
    contents.setSlug(slug);
    contents.setType(Types.PAGE);
    contents.setAllow_comment(allow_comment);
    contents.setAllow_ping(true);
    contents.setAuthor_id(users.getUid());
    try {
        contentsService.updateArticle(contents);
    } catch (Exception e) {
        String msg = "页面编辑失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
    return RestResponse.ok();
}
Also used : Contents(com.tale.model.Contents) Users(com.tale.model.Users) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException)

Example 3 with TipException

use of com.tale.exception.TipException in project tale by otale.

the class CommentsServiceImpl method delete.

@Override
public void delete(Integer coid, Integer cid) {
    if (null == coid) {
        throw new TipException("主键为空");
    }
    try {
        activeRecord.delete(Comments.class, coid);
        Contents contents = contentsService.getContents(cid + "");
        if (null != contents && contents.getComments_num() > 0) {
            Contents temp = new Contents();
            temp.setCid(cid);
            temp.setComments_num(contents.getComments_num() - 1);
            contentsService.update(temp);
        }
    } catch (Exception e) {
        throw e;
    }
}
Also used : Contents(com.tale.model.Contents) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException)

Example 4 with TipException

use of com.tale.exception.TipException in project tale by otale.

the class CommentsServiceImpl method saveComment.

@Override
public void saveComment(Comments comments) {
    if (null == comments) {
        throw new TipException("评论对象为空");
    }
    if (StringKit.isBlank(comments.getAuthor())) {
        throw new TipException("姓名不能为空");
    }
    if (StringKit.isBlank(comments.getMail())) {
        throw new TipException("邮箱不能为空");
    }
    if (!TaleUtils.isEmail(comments.getMail())) {
        throw new TipException("请输入正确的邮箱格式");
    }
    if (StringKit.isBlank(comments.getContent())) {
        throw new TipException("评论内容不能为空");
    }
    if (comments.getContent().length() < 5 || comments.getContent().length() > 2000) {
        throw new TipException("评论字数在5-2000个字符");
    }
    if (null == comments.getCid()) {
        throw new TipException("评论文章不能为空");
    }
    Contents contents = activeRecord.byId(Contents.class, comments.getCid());
    if (null == contents) {
        throw new TipException("不存在的文章");
    }
    try {
        comments.setOwner_id(contents.getAuthor_id());
        comments.setCreated(DateKit.getCurrentUnixTime());
        activeRecord.insert(comments);
        Contents temp = new Contents();
        temp.setCid(contents.getCid());
        temp.setComments_num(contents.getComments_num() + 1);
        activeRecord.update(temp);
    } catch (Exception e) {
        throw e;
    }
}
Also used : Contents(com.tale.model.Contents) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException)

Example 5 with TipException

use of com.tale.exception.TipException in project tale by otale.

the class SiteServiceImpl method initSite.

@Override
public void initSite(Users users) {
    String pwd = Tools.md5(users.getUsername() + users.getPassword());
    users.setPassword(pwd);
    users.setScreen_name(users.getUsername());
    users.setCreated(DateKit.getCurrentUnixTime());
    Integer uid = activeRecord.insert(users);
    try {
        String cp = SiteServiceImpl.class.getClassLoader().getResource("").getPath();
        File lock = new File(cp + "install.lock");
        lock.createNewFile();
        TaleConst.INSTALL = Boolean.TRUE;
        logService.save(LogActions.INIT_SITE, null, "", uid.intValue());
    } catch (Exception e) {
        throw new TipException("初始化站点失败");
    }
}
Also used : File(java.io.File) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException)

Aggregations

TipException (com.tale.exception.TipException)24 JSON (com.blade.mvc.annotation.JSON)12 Route (com.blade.mvc.annotation.Route)12 Users (com.tale.model.Users)10 Contents (com.tale.model.Contents)7 Comments (com.tale.model.Comments)4 Take (com.blade.jdbc.core.Take)3 Config (com.blade.kit.base.Config)3 Attach (com.tale.model.Attach)2 Metas (com.tale.model.Metas)2 File (java.io.File)2 IOException (java.io.IOException)2 FileItem (com.blade.mvc.multipart.FileItem)1 RestResponse (com.blade.mvc.view.RestResponse)1 BackResponse (com.tale.dto.BackResponse)1 ArrayList (java.util.ArrayList)1