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);
}
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;
}
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));
}
}
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);
}
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;
}
Aggregations