use of app.hongs.cmdlet.anno.Cmdlet in project HongsCORE by ihongs.
the class SearchCmdlet method update.
@Cmdlet("update")
public void update(String[] args) throws HongsException {
Map opts = CmdletHelper.getOpts(args, new String[] { "conf=s", "name=s", "id*s" });
String conf = Synt.asString(opts.remove("conf"));
String name = Synt.asString(opts.remove("name"));
List<String> ds = Synt.asList(opts.remove("id"));
ActionHelper ah = Core.getInstance(ActionHelper.class);
LuceneRecord so = LuceneRecord.getInstance(conf, name);
Map rd = ah.getRequestData();
if (!rd.isEmpty()) {
// 有数据则校验数据
VerifyHelper vh = new VerifyHelper();
vh.addRulesByForm(conf, name);
rd = vh.verify(rd);
try {
so.begin();
for (String id : ds) {
so.set(id, rd);
}
so.commit();
} catch (HongsException ex) {
so.revert();
throw ex;
} finally {
so.close();
}
} else {
// 不给内容即为删除
try {
so.begin();
for (String id : ds) {
so.del(id);
}
so.commit();
} catch (HongsException ex) {
so.revert();
throw ex;
} finally {
so.close();
}
}
}
use of app.hongs.cmdlet.anno.Cmdlet in project HongsCORE by ihongs.
the class Cmdrun method exec.
@Cmdlet("__main__")
public static void exec(String[] args) throws HongsException {
Map opts = CmdletHelper.getOpts(args, "from=s", "to=s", "sync:b", "del-tables:b", "del-fields", "!U", "!A");
String fr = (String) opts.get("from");
String to = (String) opts.get("to");
boolean sc = (boolean) opts.get("sync");
boolean dt = (boolean) opts.get("del-tables");
boolean df = (boolean) opts.get("del-fields");
Pattern patt = Pattern.compile("\\.\\w+$");
Matcher frMt = patt.matcher(fr);
Matcher toMt = patt.matcher(to);
if (frMt.find() && toMt.find()) {
DB frDb = DB.getInstance(fr.substring(0, frMt.start()));
Table frTb = frDb.getTable(fr.substring(frMt.start() + 1));
DB toDb = DB.getInstance(to.substring(0, toMt.start()));
Table toTb = toDb.getTable(to.substring(toMt.start() + 1));
if (sc) {
new TableDeff(frTb).syncSlaver(toTb, df);
} else {
new TableDeff(frTb).deffSlaver(toTb, df);
}
} else {
DB frDb = DB.getInstance(fr);
DB toDb = DB.getInstance(fr);
if (sc) {
new DBDeff(frDb).syncSlaver(toDb, null, null, dt, df);
} else {
new DBDeff(frDb).deffSlaver(toDb, null, null, dt, df);
}
}
}
use of app.hongs.cmdlet.anno.Cmdlet in project HongsCORE by ihongs.
the class Common method showCmdlets.
@Cmdlet("show-cmdlets")
public static void showCmdlets(String[] args) {
Map<String, String> a = new TreeMap(new PropComparator());
int i = 0, j;
for (Map.Entry<String, Method> et : CmdletRunner.getCmdlets().entrySet()) {
String k = et.getKey();
Method v = et.getValue();
a.put(k, v.getDeclaringClass().getName() + "." + v.getName());
j = k.length();
if (i < j && j < 31) {
i = j;
}
}
for (Map.Entry<String, String> n : a.entrySet()) {
StringBuilder s = new StringBuilder();
s.append(n.getKey());
for (j = n.getKey().length(); j < i; j++) {
s.append(" ");
}
s.append("\t");
s.append(n.getValue());
System.out.println(s);
}
}
use of app.hongs.cmdlet.anno.Cmdlet in project HongsCORE by ihongs.
the class Common method execAction.
@Cmdlet("exec-action")
public static void execAction(String[] args) throws HongsException {
Map<String, Object> opts;
opts = CmdletHelper.getOpts(args, "request:s", "context:s", "session:s", "cookies:s");
args = (String[]) opts.get("");
if (args.length == 0) {
System.err.println("Action name required!\r\nUsage: ACTION_NAME --request QUERY_STRING --cookies QUERY_STRING --session QUERY_STRING --context QUERY_STRING");
return;
}
ActionHelper helper = Core.getInstance(ActionHelper.class);
helper.setRequestData(data((String) opts.get("request")));
helper.setContextData(data((String) opts.get("context")));
helper.setSessionData(data((String) opts.get("session")));
helper.setCookiesData(data((String) opts.get("cookies")));
ActionRunner runner = new ActionRunner(helper, args[0]);
runner.doAction();
CmdletHelper.preview(helper.getResponseData());
}
use of app.hongs.cmdlet.anno.Cmdlet in project HongsCORE by ihongs.
the class Common method callAction.
@Cmdlet("call-action")
public static void callAction(String[] args) throws HongsException {
Map<String, Object> opts;
opts = CmdletHelper.getOpts(args, "request:s", "cookies:s");
args = (String[]) opts.get("");
String act = args[0];
String req = text((String) opts.get("request"));
Map<String, String> cok = data((String) opts.get("cookies"));
String hst = System.getProperty("server.host", "localhost");
String pot = System.getProperty("server.port", "8080");
String url = "http://" + hst + ":" + pot + Core.BASE_HREF + "/" + act + Cnst.ACT_EXT;
try {
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setConnectTimeout(0);
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json,text/html,*/*;q=0.8");
conn.setRequestProperty("X-Requested-With", "HongsCORE/0.4");
// 放入 cookie
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> et : cok.entrySet()) {
sb.append(URLEncoder.encode(et.getKey(), "UTF-8"));
sb.append("=");
sb.append(URLEncoder.encode(et.getValue(), "UTF-8"));
sb.append(";");
}
conn.setRequestProperty("Cookie", sb.toString());
PrintWriter out = new PrintWriter(conn.getOutputStream());
out.print(req);
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.print(line);
}
} catch (UnsupportedEncodingException ex) {
throw new HongsException.Common(ex);
} catch (MalformedURLException ex) {
throw new HongsException.Common(ex);
} catch (IOException ex) {
throw new HongsException.Common(ex);
}
}
Aggregations