use of app.hongs.action.ActionRunner in project HongsCORE by ihongs.
the class IsFork method verify.
@Override
public Object verify(Object value) throws Wrongs, HongsException {
if (value == null || "".equals(value)) {
// 允许为空
return null;
}
String vl = Synt.declare(params.get("verify-type"), "");
if ("any".equals(vl)) {
return value;
} else if ("number".equals(vl)) {
IsNumber rl;
rl = new IsNumber();
rl.setHelper(helper);
rl.setParams(params);
rl.setValues(values);
rl.setCleans(cleans);
return rl.verify(value);
} else if ("string".equals(vl)) {
IsString rl;
rl = new IsString();
rl.setHelper(helper);
rl.setParams(params);
rl.setValues(values);
rl.setCleans(cleans);
return rl.verify(value);
}
String at = Synt.declare(params.get("data-at"), "");
String vk = Synt.declare(params.get("data-vk"), "");
String cl = Synt.declare(params.get("conf"), "");
String fl = Synt.declare(params.get("form"), "");
String ck = Synt.declare(params.get("__conf__"), "");
String fk = Synt.declare(params.get("__name__"), "");
String ap = null;
String aq = null;
if ("".equals(vk)) {
vk = Cnst.ID_KEY;
}
if ("".equals(cl)) {
cl = ck;
}
if ("".equals(fl)) {
fl = fk.replaceFirst("_id$", "");
}
if ("".equals(at)) {
at = cl + "/" + fl + "/search";
} else {
// 尝试解析附加参数
int ps;
ps = at.indexOf('?');
if (ps > 0) {
aq = at.substring(1 + ps).trim();
at = at.substring(0, ps).trim();
}
ps = at.indexOf('!');
if (ps > 0) {
ap = at.substring(1 + ps).trim();
at = at.substring(0, ps).trim();
}
}
ActionHelper ah = ActionHelper.newInstance();
ah.setContextData(Synt.mapOf(Cnst.ORIGIN_ATTR, Core.ACTION_NAME.get()));
// 请求数据
Map rd = new HashMap();
Set rb = Synt.setOf(vk);
Set id = Synt.asSet(value);
rb.add(vk);
rd.put(Cnst.RN_KEY, 0);
rd.put(Cnst.RB_KEY, rb);
rd.put(Cnst.ID_KEY, id);
ah.setRequestData(rd);
// 虚拟路径
if (ap != null && ap.length() != 0) {
ah.setAttribute(Cnst.ACTION_ATTR, ap + Cnst.ACT_EXT);
}
// 附加参数
if (aq != null && aq.length() != 0) {
if (aq.startsWith("{") && aq.endsWith("}")) {
rd.putAll((Map) Data.toObject(aq));
} else {
rd.putAll(ActionHelper.parseQuery(aq));
}
}
// 获取结果
new ActionRunner(ah, at).doInvoke();
Map sd = ah.getResponseData();
List<Map> ls = (List) sd.get("list");
// 对比结果
Set vs = Synt.asSet(value);
Set us = new HashSet();
if (null != ls) {
for (Map um : ls) {
us.add(um.get(vk));
}
}
if (vs.size() != us.size() || !vs.containsAll(us)) {
throw new Wrong("fore.form.is.not.exists", fl);
}
return value;
}
use of app.hongs.action.ActionRunner in project HongsCORE by ihongs.
the class DataAction method export.
@Action("stream")
@Preset(conf = "", form = "")
@CustomReplies
public void export(ActionHelper helper) throws HongsException, IOException {
ActionRunner runner = (ActionRunner) helper.getAttribute(ActionRunner.class.getName());
String ent = runner.getEntity();
String mod = runner.getModule();
Data sr = (Data) getEntity(helper);
Map rd = helper.getRequestData();
rd = getReqMap(helper, sr, "export", rd);
int rn = Synt.declare(rd.get("rn"), 0);
int pn = Synt.declare(rd.get("pn"), 0);
Loop lp = sr.search(rd, pn, rn);
/**
* 逐行输出
*/
HttpServletResponse rs = helper.getResponse();
String csv = ent + "_" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
rs.setHeader("Content-Disposition", "attachment;filename=" + csv + ".csv");
rs.setHeader("Content-Type", "application/octet-stream;charset=UTF-8");
rs.setHeader("Transfer-Encoding", "chunked");
Writer ot = rs.getWriter();
Map fs = sr.getFields();
Map es = new HashMap();
if (lp.hasNext()) {
Map<String, Object> ds = lp.next();
StringBuilder sf = new StringBuilder();
StringBuilder sb = new StringBuilder();
Map ts = FormSet.getInstance("default").getEnum("__types__");
for (Map.Entry<String, Object> et : ds.entrySet()) {
Object fv = et.getValue();
String fn = et.getKey();
Map mt = (Map) fs.get(fn);
Map ex = null;
String fx, ft;
fx = (String) mt.get("__text__");
ft = (String) mt.get("__type__");
ft = (String) ts.get(ft);
if ("enum".equals(ft)) {
String xonf = (String) mt.get("conf");
String xame = (String) mt.get("enum");
if (null == xonf || "".equals(xonf))
xonf = mod;
if (null == xame || "".equals(xame))
xame = fn;
ex = FormSet.getInstance(xonf).getEnum(xame);
es.put(fn, ex);
}
sf.append(",\"").append(escape(fx, null)).append("\"");
sb.append(",\"").append(escape(fv, ex)).append("\"");
}
ot.write(sf.append("\r\n").substring(1));
ot.write(sb.append("\r\n").substring(1));
ot.flush();
}
while (lp.hasNext()) {
Map<String, Object> ds = lp.next();
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, Object> et : ds.entrySet()) {
Object fv = et.getValue();
String fn = et.getKey();
Map ex = (Map) es.get(fn);
sb.append(",\"").append(escape(fv, ex)).append("\"");
}
ot.write(sb.append("\r\n").substring(1));
}
}
use of app.hongs.action.ActionRunner in project HongsCORE by ihongs.
the class SearchAction method counts.
@Action("counts/search")
public void counts(ActionHelper helper) throws HongsException {
ActionRunner runner = (ActionRunner) helper.getAttribute(ActionRunner.class.getName());
String ent = runner.getEntity();
String mod = runner.getModule();
LuceneRecord sr = (LuceneRecord) getEntity(helper);
SearchHelper sh = new SearchHelper(sr);
Map rd = helper.getRequestData();
rd = getReqMap(helper, sr, "counts", rd);
Map sd = sh.counts(rd);
sd = getRspMap(helper, sr, "counts", sd);
// sr.close ( ); // 应用容器可自行关闭
// 增加标题
titled(rd, sd, mod, ent);
helper.reply(sd);
}
use of app.hongs.action.ActionRunner in project HongsCORE by ihongs.
the class SearchAction method statis.
@Action("statis/search")
public void statis(ActionHelper helper) throws HongsException {
ActionRunner runner = (ActionRunner) helper.getAttribute(ActionRunner.class.getName());
String ent = runner.getEntity();
String mod = runner.getModule();
LuceneRecord sr = (LuceneRecord) getEntity(helper);
SearchHelper sh = new SearchHelper(sr);
Map rd = helper.getRequestData();
rd = getReqMap(helper, sr, "statis", rd);
Map sd = sh.statis(rd);
sd = getRspMap(helper, sr, "statis", sd);
// sr.close ( ); // 应用容器可自行关闭
// 增加标题
titled(rd, sd, mod, ent);
helper.reply(sd);
}
use of app.hongs.action.ActionRunner 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;
}
}
}
Aggregations