Search in sources :

Example 1 with ActionRunner

use of io.github.ihongs.action.ActionRunner in project HongsCORE by ihongs.

the class DataAction method reveal.

@Action("reveal")
public void reveal(ActionHelper helper) throws HongsException {
    ActionRunner runner = (ActionRunner) helper.getAttribute(ActionRunner.class.getName());
    String ent = runner.getEntity();
    String mod = runner.getModule();
    Data ett = (Data) getEntity(helper);
    Map req = helper.getRequestData();
    req.put("form_id", ett.getFormId());
    req.put("user_id", req.get("user"));
    Map rsp = ett.getModel().search(req);
    // 详情数据转换
    if (rsp.containsKey("info")) {
        Map df = (Map) rsp.remove("info");
        Map dt = (Map) Dawn.toObject((String) df.remove("data"));
        rsp.put("snap", df);
        rsp.put("info", dt);
        // 补充枚举和关联
        Set ab = Synt.toTerms(req.get(Cnst.AB_KEY));
        if (null != ab) {
            byte md = 0;
            if (ab.contains(".enfo"))
                md += SelectHelper.ENFO;
            if (ab.contains(".info"))
                md += SelectHelper.INFO;
            if (ab.contains(".fall"))
                md += SelectHelper.FALL;
            if (ab.contains("_text"))
                md += SelectHelper.TEXT;
            if (ab.contains("_time"))
                md += SelectHelper.TIME;
            if (ab.contains("_link"))
                md += SelectHelper.LINK;
            if (ab.contains("_fork"))
                md += SelectHelper.FORK;
            if (md != 0) {
                new SelectHelper().addItemsByForm(mod, ent).select(rsp, md);
            }
            // 新的和旧的
            if (ab.contains("older") || ab.contains("newer")) {
                Object id = df.get(/**/
                "id");
                Object fid = df.get("form_id");
                long ctime = Synt.declare(df.get("ctime"), 0L);
                if (ab.contains("older")) {
                    Map row = ett.getModel().table.fetchCase().filter("`id` = ? AND `form_id` = ? AND `ctime` < ?", id, fid, ctime).assort("`ctime` DESC").select("`ctime`").getOne();
                    df.put("older", !row.isEmpty() ? row.get("ctime") : null);
                }
                if (ab.contains("newer")) {
                    Map row = ett.getModel().table.fetchCase().filter("`id` = ? AND `form_id` = ? AND `ctime` > ?", id, fid, ctime).assort("`ctime`  ASC").select("`ctime`").getOne();
                    df.put("newer", !row.isEmpty() ? row.get("ctime") : null);
                }
            }
        }
    }
    helper.reply(rsp);
}
Also used : ActionRunner(io.github.ihongs.action.ActionRunner) Set(java.util.Set) Data(io.github.ihongs.serv.matrix.Data) Map(java.util.Map) SelectHelper(io.github.ihongs.action.SelectHelper) Action(io.github.ihongs.action.anno.Action) SearchAction(io.github.ihongs.dh.search.SearchAction)

Example 2 with ActionRunner

use of io.github.ihongs.action.ActionRunner in project HongsCORE by ihongs.

the class DataAction method getEntity.

/**
 * 获取模型对象
 * 注意:
 *  对象 Action 注解的命名必须为 "模型路径/实体名称"
 *  方法 Action 注解的命名只能是 "动作名称", 不得含子级实体名称
 * @param helper
 * @return
 * @throws HongsException
 */
@Override
public IEntity getEntity(ActionHelper helper) throws HongsException {
    ActionRunner runner = (ActionRunner) helper.getAttribute(ActionRunner.class.getName());
    Data entity = Data.getInstance(runner.getModule(), runner.getEntity());
    String userId = (String) helper.getSessibute(Cnst.UID_SES);
    // 匿名用户
    if (userId == null)
        userId = Cnst.ADM_GID;
    entity.setUserId(userId);
    return entity;
}
Also used : ActionRunner(io.github.ihongs.action.ActionRunner) Data(io.github.ihongs.serv.matrix.Data)

Example 3 with ActionRunner

use of io.github.ihongs.action.ActionRunner in project HongsCORE by ihongs.

the class ActsAction method service.

/**
 * 服务方法
 * Servlet Mapping: *.act<br/>
 * 注意: 不支持请求URI的路径中含有"."(句点), 且必须区分大小写;
 * 其目的是为了防止产生多种形式的请求路径, 影响动作过滤, 产生安全隐患.
 *
 * @param req
 * @param rsp
 * @throws javax.servlet.ServletException
 */
@Override
public void service(HttpServletRequest req, HttpServletResponse rsp) throws ServletException {
    String act = ActionDriver.getRecentPath(req);
    Core core = ActionDriver.getActualCore(req);
    ActionHelper helper = core.got(ActionHelper.class);
    Core.THREAD_CORE.set(core);
    if (act == null || act.length() == 0) {
        helper.fault(new HongsException(404, "Action URI can not be empty."));
        return;
    }
    // 去掉根和扩展名
    int pos = act.lastIndexOf('.');
    if (pos != -1) {
        act = act.substring(1, pos);
    } else {
        act = act.substring(1);
    }
    // 获取并执行动作
    try {
        new ActionRunner(helper, act).doAction();
    } catch (HongsException e) {
        helper.fault(e);
    } catch (HongsExemption e) {
        helper.fault(e);
    } catch (RuntimeException e) {
        helper.fault(new HongsException(500, e));
    }
}
Also used : ActionRunner(io.github.ihongs.action.ActionRunner) HongsException(io.github.ihongs.HongsException) ActionHelper(io.github.ihongs.action.ActionHelper) HongsExemption(io.github.ihongs.HongsExemption) Core(io.github.ihongs.Core)

Example 4 with ActionRunner

use of io.github.ihongs.action.ActionRunner in project HongsCORE by ihongs.

the class JAction method getRspMsg.

/**
 * 获取返回消息
 * @param helper
 * @param ett
 * @param opr
 * @param num
 * @return
 * @throws HongsException
 */
protected String getRspMsg(ActionHelper helper, IEntity ett, String opr, int num) throws HongsException {
    ActionRunner runner = (ActionRunner) helper.getAttribute(ActionRunner.class.getName());
    String mod = runner.getModule();
    String ent = runner.getEntity();
    String cnt = Integer.toString(num);
    CoreLocale locale = CoreLocale.getInstance().clone();
    locale.fill(mod);
    String key = "fore." + opr + "." + ent + ".success";
    if (!locale.containsKey(key)) {
        key = "fore." + opr + /**/
        ".success";
    }
    return locale.translate(key, null, cnt);
}
Also used : ActionRunner(io.github.ihongs.action.ActionRunner) CoreLocale(io.github.ihongs.CoreLocale)

Example 5 with ActionRunner

use of io.github.ihongs.action.ActionRunner in project HongsCORE by ihongs.

the class DataAction method getEntity.

/**
 * 获取模型对象
 * 注意:
 *  对象 Action 注解的命名必须为 "模型路径/实体名称"
 *  方法 Action 注解的命名只能是 "动作名称", 不得含子级实体名称
 * @param helper
 * @return
 * @throws HongsException
 */
@Override
public IEntity getEntity(ActionHelper helper) throws HongsException {
    ActionRunner runner = (ActionRunner) helper.getAttribute(ActionRunner.class.getName());
    Data entity = Data.getInstance(runner.getModule(), runner.getEntity());
    String userId = (String) helper.getSessibute(Cnst.UID_SES);
    // if  (  userId == null  ) userId = Cnst.ADM_GID; // 禁止匿名
    entity.setUserId(userId);
    return entity;
}
Also used : ActionRunner(io.github.ihongs.action.ActionRunner) Data(io.github.ihongs.serv.matrix.Data)

Aggregations

ActionRunner (io.github.ihongs.action.ActionRunner)7 Data (io.github.ihongs.serv.matrix.Data)3 CoreLocale (io.github.ihongs.CoreLocale)2 ActionHelper (io.github.ihongs.action.ActionHelper)2 Map (java.util.Map)2 Set (java.util.Set)2 Core (io.github.ihongs.Core)1 HongsException (io.github.ihongs.HongsException)1 HongsExemption (io.github.ihongs.HongsExemption)1 FormSet (io.github.ihongs.action.FormSet)1 SelectHelper (io.github.ihongs.action.SelectHelper)1 Action (io.github.ihongs.action.anno.Action)1 SearchAction (io.github.ihongs.dh.search.SearchAction)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1