Search in sources :

Example 6 with ActionHelper

use of app.hongs.action.ActionHelper in project HongsCORE by ihongs.

the class Form method insertAuthRole.

protected void insertAuthRole(String id) throws HongsException {
    ActionHelper helper = Core.getInstance(ActionHelper.class);
    String uid = (String) helper.getSessibute(Cnst.UID_SES);
    String tan;
    // 写入权限
    tan = (String) table.getParams().get("role.table");
    if (tan != null) {
        Table tab = db.getTable(tan);
        tab.insert(Synt.mapOf("user_id", uid, "role", prefix + "/" + id + "/search"));
        tab.insert(Synt.mapOf("user_id", uid, "role", prefix + "/" + id + "/create"));
        tab.insert(Synt.mapOf("user_id", uid, "role", prefix + "/" + id + "/update"));
        tab.insert(Synt.mapOf("user_id", uid, "role", prefix + "/" + id + "/delete"));
        tab.insert(Synt.mapOf("user_id", uid, "role", prefix + "/" + id + "/revert"));
    }
    // 更新缓存(通过改变权限更新时间)
    tan = (String) table.getParams().get("user.table");
    if (tan != null) {
        Table tab = db.getTable(tan);
        tab.update(Synt.mapOf("rtime", System.currentTimeMillis() / 1000), "`id` = ?", uid);
    }
}
Also used : Table(app.hongs.db.Table) ActionHelper(app.hongs.action.ActionHelper)

Example 7 with ActionHelper

use of app.hongs.action.ActionHelper in project HongsCORE by ihongs.

the class Capts method verify.

@Override
public Object verify(Object value) throws Wrong {
    ActionHelper ah = Core.getInstance(ActionHelper.class);
    String ss = Synt.declare(params.get("capts-sess"), CoreConfig.getInstance().getProperty("core.capts.sess", "capt"));
    long xt = Synt.declare(params.get("capts-time"), CoreConfig.getInstance().getProperty("core.capts.time", 600L));
    String cc = Synt.declare(ah.getSessibute(ss + "_code"), "");
    long ct = Synt.declare(ah.getSessibute(ss + "_time"), 0L);
    String vs = Synt.declare(value, "");
    try {
        // 人机校验
        if (cc.equals("") || !cc.equalsIgnoreCase(vs)) {
            throw new Wrong("fore.capt.invalid");
        }
        if (ct + xt * 1000 < System.currentTimeMillis()) {
            throw new Wrong("fore.capt.timeout");
        }
    } finally {
        // 销毁记录
        ah.setSessibute(ss + "_code", null);
        ah.setSessibute(ss + "_time", null);
    }
    return BLANK;
}
Also used : ActionHelper(app.hongs.action.ActionHelper)

Example 8 with ActionHelper

use of app.hongs.action.ActionHelper in project HongsCORE by ihongs.

the class SearchTitler method addForks.

/**
 * 通过调用关联动作来补全名称
 * @param ls
 * @param fs
 * @param fn
 * @throws HongsException
 */
protected void addForks(List<Object[]> ls, Map fs, String fn) throws HongsException {
    String at = (String) fs.get("data-at");
    String vk = (String) fs.get("data-vk");
    String tk = (String) fs.get("data-tk");
    if (at == null || at.length() == 0 || vk == null || vk.length() == 0 || tk == null || tk.length() == 0) {
        CoreLogger.error("data-at, data-vk or data-tk can not be empty in field " + fn);
        return;
    }
    // 映射关系
    Map<String, List> lm = new HashMap();
    for (Object[] lx : ls) {
        String lv = (String) lx[0];
        List<Object[]> lw = lm.get(lv);
        if (lw == null) {
            lw = new ArrayList();
            lm.put(lv, lw);
        }
        lw.add(lx);
    }
    ActionHelper ah = ActionHelper.newInstance();
    ah.setContextData(Synt.mapOf(Cnst.ORIGIN_ATTR, Core.ACTION_NAME.get()));
    // 查询结构
    Map rd = new HashMap();
    Set rb = new HashSet();
    int ps;
    ps = at.indexOf("?");
    if (ps > -1) {
        String aq;
        aq = at.substring(1 + ps).trim();
        at = at.substring(0, ps).trim();
        if (!"".equals(aq)) {
            if (aq.startsWith("{") && aq.endsWith("}")) {
                rd = (Map) Data.toObject(aq);
            } else {
                rd = ActionHelper.parseQuery(aq);
            }
        }
    }
    ps = at.indexOf("!");
    if (ps > -1) {
        String ap;
        ap = at.substring(1 + ps).trim();
        at = at.substring(0, ps).trim();
        if (!"".equals(ap)) {
            ap = ap + Cnst.ACT_EXT;
            ah.setAttribute(Cnst.ACTION_ATTR, ap);
        }
    }
    rb.add(vk);
    rb.add(tk);
    rd.put(Cnst.RN_KEY, 0);
    rd.put(Cnst.RB_KEY, rb);
    rd.put(Cnst.ID_KEY, lm.keySet());
    // 获取结果
    ah.setRequestData(rd);
    new ActionRunner(ah, at).doInvoke();
    Map sd = ah.getResponseData();
    List<Map> lz = (List) sd.get("list");
    if (lz == null) {
        return;
    }
    // 整合数据
    for (Map ro : lz) {
        String lv = Synt.declare(ro.get(vk), "");
        String lt = Synt.declare(ro.get(tk), "");
        List<Object[]> lw = lm.get(lv);
        if (null != lw)
            for (Object[] lx : lw) {
                lx[1] = lt;
            }
    }
}
Also used : ActionRunner(app.hongs.action.ActionRunner) Set(java.util.Set) HashSet(java.util.HashSet) FormSet(app.hongs.action.FormSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ActionHelper(app.hongs.action.ActionHelper) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 9 with ActionHelper

use of app.hongs.action.ActionHelper 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.get(ActionHelper.class);
    Core.THREAD_CORE.set(core);
    if (act == null || act.length() == 0) {
        senderr(helper, 0x1104, null, "Action URI can not be empty.", "");
        return;
    }
    // 去掉根和扩展名
    act = act.substring(1);
    int pos = act.lastIndexOf('.');
    if (pos != -1)
        act = act.substring(0, pos);
    // 获取并执行动作
    try {
        ActionRunner runner = new ActionRunner(helper, act);
        runner.doAction();
    } catch (ClassCastException ex) {
        // 类型转换失败按 400 错误处理
        senderr(helper, new HongsException(0x1100, ex));
    } catch (HongsException ex) {
        senderr(helper, ex);
    } catch (HongsExpedient ex) {
        senderr(helper, ex);
    } catch (HongsError ex) {
        senderr(helper, ex);
    }
}
Also used : ActionRunner(app.hongs.action.ActionRunner) HongsError(app.hongs.HongsError) HongsException(app.hongs.HongsException) ActionHelper(app.hongs.action.ActionHelper) HongsExpedient(app.hongs.HongsExpedient) Core(app.hongs.Core)

Example 10 with ActionHelper

use of app.hongs.action.ActionHelper in project HongsCORE by ihongs.

the class ApisAction method service.

@Override
protected void service(HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException {
    String act = ActionDriver.getRecentPath(req);
    if (act == null || act.length() == 0) {
        rsp.sendError(HttpServletResponse.SC_NOT_FOUND, "URI can not be empty");
        return;
    }
    int dot;
    dot = act.lastIndexOf(".");
    act = act.subSequence(0, dot) + Cnst.ACT_EXT;
    ActionHelper hlpr = ActionDriver.getActualCore(req).get(ActionHelper.class);
    Object _dat = Dict.getParam(hlpr.getRequestData(), dataKey);
    Object _cnv = Dict.getParam(hlpr.getRequestData(), convKey);
    String _wap = hlpr.getParameter(wrapKey);
    String _sok = hlpr.getParameter(scokKey);
    // 请求数据封装
    Map data = null;
    if (_dat != null) {
        try {
            data = trnsData(_dat);
        } catch (ClassCastException e) {
            hlpr.error400("Can not parse value for " + dataKey);
            return;
        }
    }
    // 数据转换策略
    Set conv = null;
    if (_cnv != null) {
        try {
            conv = trnsConv(_cnv);
        } catch (ClassCastException e) {
            hlpr.error400("Can not parse value for " + convKey);
            return;
        }
    }
    // 包裹返回数据
    boolean wrap;
    try {
        wrap = Synt.declare(_wap, false);
    } catch (ClassCastException e) {
        hlpr.error400("Value for " + wrapKey + " can not be cast to boolean");
        return;
    }
    // 状态总是 200
    boolean scok;
    try {
        scok = Synt.declare(_sok, false);
    } catch (ClassCastException e) {
        hlpr.error400("Value for " + scokKey + " can not be cast to boolean");
        return;
    }
    // 额外请求数据
    if (data != null && !data.isEmpty()) {
        hlpr.getRequestData().putAll(data);
    }
    if (conv != null && !conv.isEmpty()) {
        Core.getInstance().put(Cnst.OBJECT_MODE, true);
    }
    // 转发动作处理, 获取响应数据
    req.getRequestDispatcher(act).include(req, rsp);
    Map resp = hlpr.getResponseData();
    if (resp == null) {
        return;
    }
    // 整理响应数据
    if (conv != null && !conv.isEmpty()) {
        convData(resp, conv);
    }
    if (wrap) {
        wrapData(resp);
    }
    if (scok) {
        rsp.setStatus(HttpServletResponse.SC_OK);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ActionHelper(app.hongs.action.ActionHelper) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

ActionHelper (app.hongs.action.ActionHelper)21 HashSet (java.util.HashSet)10 Map (java.util.Map)7 Set (java.util.Set)7 HongsException (app.hongs.HongsException)5 HashMap (java.util.HashMap)5 Core (app.hongs.Core)4 HongsError (app.hongs.HongsError)4 ActionRunner (app.hongs.action.ActionRunner)4 List (java.util.List)4 NaviMap (app.hongs.action.NaviMap)3 Cmdlet (app.hongs.cmdlet.anno.Cmdlet)3 HongsExpedient (app.hongs.HongsExpedient)2 Table (app.hongs.db.Table)2 LuceneRecord (app.hongs.dh.lucene.LuceneRecord)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 CoreConfig (app.hongs.CoreConfig)1 FormSet (app.hongs.action.FormSet)1