mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Embeddable: Create core dbs in proper subdirectory
This commit is contained in:
@@ -13,27 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import gplx.xowa.specials.*; import gplx.xowa.htmls.bridges.*;
|
||||
import gplx.xowa.addons.bldrs.infos.*; import gplx.xowa.addons.bldrs.xodirs.*;
|
||||
public class Xobc_task_addon implements Xoax_addon_itm, Xoax_addon_itm__special, Xoax_addon_itm__json, Xoax_addon_itm__init {
|
||||
public Xobc_xodir_mgr Xodir_mgr() {return xodir_mgr;} private Xobc_xodir_mgr xodir_mgr;
|
||||
public void Xodir_mgr_(Xobc_xodir_mgr v) {this.xodir_mgr = v;}
|
||||
public void Init_addon_by_app(Xoa_app app) {
|
||||
this.xodir_mgr = new Xobc_xodir_mgr__pc(app);
|
||||
}
|
||||
public void Init_addon_by_wiki(Xow_wiki wiki) {}
|
||||
public Xow_special_page[] Special_pages() {
|
||||
return new Xow_special_page[]
|
||||
{ Xobc_task_special.Prototype
|
||||
, Xobc_info_special.Prototype
|
||||
};
|
||||
}
|
||||
public Bridge_cmd_itm[] Json_cmds() {
|
||||
return new Bridge_cmd_itm[]
|
||||
{ gplx.xowa.addons.bldrs.centrals.Xobc_task_bridge.Prototype
|
||||
};
|
||||
}
|
||||
|
||||
public String Addon__key() {return ADDON__KEY;} public static final String ADDON__KEY = "xowa.imports.downloads";
|
||||
}
|
||||
|
||||
@@ -13,50 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.htmls.bridges.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.cmds.*;
|
||||
public class Xobc_task_bridge implements Bridge_cmd_itm {
|
||||
private Xoa_app app;
|
||||
public void Init_by_app(Xoa_app app) {this.app = app;}
|
||||
public String Exec(Json_nde data) {
|
||||
Xobc_task_mgr task_mgr = Xobc_task_special.Task_mgr(app);
|
||||
byte proc_id = proc_hash.Get_as_byte_or(data.Get_as_bry_or(Bridge_cmd_mgr.Msg__proc, null), Byte_ascii.Max_7_bit);
|
||||
Json_nde args = data.Get_kv(Bridge_cmd_mgr.Msg__args).Val_as_nde();
|
||||
switch (proc_id) {
|
||||
case Proc__reload: task_mgr.Reload(); break;
|
||||
case Proc__add_work: task_mgr.Todo_mgr().Add_work(args.Get_as_int("task_id")); break;
|
||||
case Proc__del_work: task_mgr.Work_mgr().Del_work(args.Get_as_int("task_id")); break;
|
||||
case Proc__del_done: task_mgr.Done_mgr().Del_done(args.Get_as_int("task_id")); break;
|
||||
case Proc__del_todo: task_mgr.Todo_mgr().Del_todo(args.Get_as_int("task_id")); break;
|
||||
case Proc__run_next: task_mgr.Work_mgr().Run_next(); break;
|
||||
case Proc__stop_cur: task_mgr.Work_mgr().Stop_cur(); break;
|
||||
case Proc__redo_cur: task_mgr.Work_mgr().Redo_cur(); break;
|
||||
case Proc__filter_todo: task_mgr.Filter_todo(args.Get_as_str("lang_key"), args.Get_as_str("type_key")); break;
|
||||
case Proc__download_db: gplx.xowa.addons.bldrs.centrals.dbs.Xobc_data_db_upgrader.Check_for_updates(task_mgr); break;
|
||||
default: throw Err_.new_unhandled_default(proc_id);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
private static final byte
|
||||
Proc__reload = 0, Proc__add_work = 1, Proc__del_work = 2, Proc__del_done = 3
|
||||
, Proc__run_next = 4, Proc__stop_cur = 5, Proc__redo_cur = 6, Proc__download_db = 7, Proc__filter_todo = 8
|
||||
, Proc__del_todo = 9
|
||||
;
|
||||
private static final Hash_adp_bry proc_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("reload" , Proc__reload)
|
||||
.Add_str_byte("add_work" , Proc__add_work)
|
||||
.Add_str_byte("del_work" , Proc__del_work)
|
||||
.Add_str_byte("del_done" , Proc__del_done)
|
||||
.Add_str_byte("run_next" , Proc__run_next)
|
||||
.Add_str_byte("stop_cur" , Proc__stop_cur)
|
||||
.Add_str_byte("redo_cur" , Proc__redo_cur)
|
||||
.Add_str_byte("download_db" , Proc__download_db)
|
||||
.Add_str_byte("filter_todo" , Proc__filter_todo)
|
||||
.Add_str_byte("del_todo" , Proc__del_todo)
|
||||
;
|
||||
|
||||
public byte[] Key() {return BRIDGE_KEY;} public static final byte[] BRIDGE_KEY = Bry_.new_a7("builder_central.exec");
|
||||
public static final Xobc_task_bridge Prototype = new Xobc_task_bridge(); Xobc_task_bridge() {}
|
||||
}
|
||||
|
||||
@@ -13,20 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import gplx.langs.mustaches.*;
|
||||
class Xobc_task_doc implements Mustache_doc_itm {
|
||||
private final boolean app_is_drd;
|
||||
private final String link_help;
|
||||
public Xobc_task_doc(boolean app_is_drd, String link_help) {
|
||||
this.app_is_drd = app_is_drd; this.link_help = link_help;
|
||||
}
|
||||
public boolean Mustache__write(String key, Mustache_bfr bfr) {
|
||||
if (String_.Eq(key, "link_help")) bfr.Add_str_u8(link_help);
|
||||
return false;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String key) {
|
||||
if (String_.Eq(key, "app_is_drd")) return Mustache_doc_itm_.Ary__bool(app_is_drd);
|
||||
return Mustache_doc_itm_.Ary__empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,30 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import gplx.xowa.specials.*; import gplx.langs.mustaches.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
|
||||
class Xobc_task_html extends Xow_special_wtr__base {
|
||||
@Override protected Io_url Get_addon_dir(Xoa_app app) {return app.Fsys_mgr().Http_root().GenSubDir_nest("bin", "any", "xowa", "addon", "bldr", "central");}
|
||||
@Override protected Io_url Get_mustache_fil(Io_url addon_dir) {return addon_dir.GenSubFil_nest("bin", "xobc.main.mustache.html");}
|
||||
@Override protected Mustache_doc_itm Bld_mustache_root(Xoa_app app) {
|
||||
return new Xobc_task_doc(gplx.core.envs.Op_sys.Cur().Tid_is_drd(), "/site/home/wiki/App/Import/Download_Central");
|
||||
}
|
||||
@Override protected void Bld_tags(Xoa_app app, Io_url addon_dir, Xopage_html_data page_data) {
|
||||
Xopg_tag_mgr head_tags = page_data.Head_tags();
|
||||
Xopg_alertify_.Add_tags (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xocss (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xohelp (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__mustache (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__jquery (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xonotify (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xolog (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xoajax (head_tags, app.Fsys_mgr().Http_root(), app);
|
||||
|
||||
head_tags.Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "xobc.css")));
|
||||
head_tags.Add(Xopg_tag_itm.New_htm_frag(addon_dir.GenSubFil_nest("bin", "xobc.row.mustache.html"), "xobc.row"));
|
||||
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.elem.js")));
|
||||
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.tmpl.js")));
|
||||
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xobc.util.js")));
|
||||
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xobc.js")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,69 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import gplx.core.brys.evals.*; import gplx.core.gfobjs.*; import gplx.core.progs.rates.*; import gplx.core.threads.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.tasks.*; import gplx.xowa.addons.bldrs.centrals.steps.*; import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.mgrs.*;
|
||||
import gplx.xowa.guis.cbks.*;
|
||||
public class Xobc_task_mgr implements Xog_json_wkr {
|
||||
private final Xog_cbk_trg cbk_trg = Xog_cbk_trg.New(Xobc_task_special.Prototype.Special__meta().Ttl_bry());
|
||||
public Xobc_task_mgr(Xoa_app app, Io_url data_db_url) {
|
||||
this.app = app;
|
||||
this.cbk_mgr = app.Gui__cbk_mgr();
|
||||
this.user_db = new Xobc_user_db(app.User().User_db_mgr().Conn());
|
||||
this.data_db = new Xobc_data_db(data_db_url);
|
||||
this.work_mgr = new Xobc_task_regy__work(this, app);
|
||||
this.todo_mgr = new Xobc_task_regy__todo(this);
|
||||
this.done_mgr = new Xobc_task_regy__done(this);
|
||||
this.step_mgr = new Xobc_step_factory(this, data_db, app.Fsys_mgr().Wiki_dir());
|
||||
this.skip_mgr = new Xobc_skip_mgr(this, app);
|
||||
this.ary = new Xobc_task_regy__base[] {work_mgr, todo_mgr, done_mgr};
|
||||
this.rate_mgr = Xobc_cmd__base.New_rate_mgr();
|
||||
}
|
||||
public Xoa_app App() {return app;} private final Xoa_app app;
|
||||
public Xog_cbk_mgr Cbk_mgr() {return cbk_mgr;} private final Xog_cbk_mgr cbk_mgr;
|
||||
public Xobc_task_regy__work Work_mgr() {return work_mgr;} private final Xobc_task_regy__work work_mgr;
|
||||
public Xobc_task_regy__todo Todo_mgr() {return todo_mgr;} private final Xobc_task_regy__todo todo_mgr;
|
||||
public Xobc_task_regy__done Done_mgr() {return done_mgr;} private final Xobc_task_regy__done done_mgr;
|
||||
public Xobc_task_regy__base Get_at(int i) {return ary[i];} private final Xobc_task_regy__base[] ary;
|
||||
public Xobc_data_db Data_db() {return data_db;} private final Xobc_data_db data_db;
|
||||
public Xobc_user_db User_db() {return user_db;} private final Xobc_user_db user_db;
|
||||
public Gfo_rate_mgr Rate_mgr() {return rate_mgr;} private final Gfo_rate_mgr rate_mgr;
|
||||
public Xobc_step_factory Step_mgr() {return step_mgr;} private final Xobc_step_factory step_mgr;
|
||||
public Xobc_filter_mgr Filter_mgr() {return filter_mgr;} private final Xobc_filter_mgr filter_mgr = new Xobc_filter_mgr();
|
||||
public Xobc_skip_mgr Skip_mgr() {return skip_mgr;} private final Xobc_skip_mgr skip_mgr;
|
||||
public Xobc_lang_mgr Lang_mgr() {return lang_mgr;} private final Xobc_lang_mgr lang_mgr = new Xobc_lang_mgr();
|
||||
public void Send_json(String func, Gfobj_nde data) {cbk_mgr.Send_json(cbk_trg, func, data);}
|
||||
public Xobc_task_mgr Load_or_init() {
|
||||
Gfo_log_.Instance.Info("task_mgr.load_or_init.bgn");
|
||||
data_db.Tbl__task_regy().Select_all(todo_mgr);
|
||||
user_db.Work_task_tbl().Select_all(this, todo_mgr, work_mgr);
|
||||
user_db.Done_task_tbl().Select_all(todo_mgr, done_mgr);
|
||||
return this;
|
||||
}
|
||||
public void Reload() {
|
||||
Gfo_log_.Instance.Info("task_mgr.reload.bgn");
|
||||
Gfobj_nde root = Gfobj_nde.New();
|
||||
Gfobj_nde lists_nde = root.New_nde("lists");
|
||||
work_mgr.Save_to(lists_nde.New_ary("work"));
|
||||
todo_mgr.Save_to(lists_nde.New_ary("todo"), filter_mgr.Filter(todo_mgr));
|
||||
done_mgr.Save_to(lists_nde.New_ary("done"));
|
||||
root.Add_nde("filters", filter_mgr.Make_init_msg());
|
||||
root.Add_ary("langs", lang_mgr.Make_init_msg(data_db.Tbl__lang_regy().Select_all()));
|
||||
cbk_mgr.Send_json(cbk_trg, "xo.bldr.core.reload__recv", root);
|
||||
}
|
||||
public void Filter_todo(String lang_key, String type_key) {
|
||||
Gfo_log_.Instance.Info("task_mgr.filter_by_lang.bgn");
|
||||
Gfobj_nde root = Gfobj_nde.New();
|
||||
Gfobj_nde lists_nde = root.New_nde("lists").Add_str("list_name", "todo");
|
||||
todo_mgr.Save_to(lists_nde.New_ary("todo"), filter_mgr.Filter(todo_mgr, lang_key, type_key));
|
||||
cbk_mgr.Send_json(cbk_trg, "xo.bldr.core.reload_list__recv", root);
|
||||
}
|
||||
public void Transfer(Xobc_task_regy__base src, Xobc_task_regy__base trg, Xobc_task_itm task) {
|
||||
Gfo_log_.Instance.Info("task_mgr.transfer.bgn", "task_uid", task.Task_id(), "src", src.Name(), "trg", trg.Name());
|
||||
src.Del_by(task.Task_id());
|
||||
trg.Add(task);
|
||||
cbk_mgr.Send_json(cbk_trg, "xo.bldr.core.transfer__recv", Gfobj_nde.New().Add_str("src", src.Name()).Add_str("trg", trg.Name()).Add_nde("task", task.Save_to(Gfobj_nde.New())));
|
||||
}
|
||||
public static final int Lists_len = 3;
|
||||
}
|
||||
|
||||
@@ -13,32 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import gplx.xowa.specials.*; import gplx.core.net.*; import gplx.core.net.qargs.*; import gplx.xowa.wikis.pages.*;
|
||||
public class Xobc_task_special implements Xow_special_page {
|
||||
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
// init task_mgr
|
||||
page.Html_data().Cbk_enabled_(true); // apply cbk_enabled early to capture logging statements
|
||||
Xoa_app app = wiki.App();
|
||||
if (task_mgr == null) task_mgr = New_task_mgr(app);
|
||||
task_mgr.Load_or_init();
|
||||
|
||||
new Xobc_task_html().Bld_page_by_mustache(app, page, this);
|
||||
}
|
||||
public static Xobc_task_mgr Task_mgr(Xoa_app app) {
|
||||
if (task_mgr == null) {
|
||||
task_mgr = New_task_mgr(app);
|
||||
}
|
||||
return task_mgr;
|
||||
} private static Xobc_task_mgr task_mgr;
|
||||
private static Xobc_task_mgr New_task_mgr(Xoa_app app) {
|
||||
Io_url data_db_url = app.Fsys_mgr().Bin_addon_dir().GenSubFil_nest("bldr", "central", "bldr_central.data_db.xowa");
|
||||
app.User().User_db_mgr().Init_site_mgr();
|
||||
return new Xobc_task_mgr(app, data_db_url);
|
||||
}
|
||||
|
||||
Xobc_task_special(Xow_special_meta special__meta) {this.special__meta = special__meta;}
|
||||
public Xow_special_meta Special__meta() {return special__meta;} private final Xow_special_meta special__meta;
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
public static final Xow_special_page Prototype = new Xobc_task_special(Xow_special_meta.New_xo("XowaDownloadCentral", "Download Central"));
|
||||
}
|
||||
|
||||
@@ -13,144 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.gfobjs.*; import gplx.core.progs.*; import gplx.core.progs.rates.*;
|
||||
import gplx.xowa.apps.apis.*;
|
||||
public abstract class Xobc_cmd__base implements Xobc_cmd_itm {
|
||||
private final Xobc_task_mgr task_mgr;
|
||||
private final Gfo_rate_list rate_list; private final long notify_delay = 1000;
|
||||
private final double delta_threshold = .25d; // allow variance of up to 25% before updating rate
|
||||
private long time_prv;
|
||||
private double rate_cur;
|
||||
private boolean log_verbose;
|
||||
public Xobc_cmd__base(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_id) {
|
||||
this.task_mgr = task_mgr; this.task_id = task_id; this.step_id = step_id; this.cmd_id = cmd_id;
|
||||
this.cmd_uid = String_.Concat_with_str(":", Int_.To_str(task_id), Int_.To_str(step_id), Int_.To_str(cmd_id));
|
||||
this.rate_list = task_mgr == null ? null : task_mgr.Rate_mgr().Get_or_new(this.Cmd_type());
|
||||
}
|
||||
public long Prog_data_cur() {return data_cur;} private long data_cur; public void Prog_data_cur_(long v) {this.data_cur = v;}
|
||||
public long Prog_data_end() {return data_end;} private long data_end; public void Prog_data_end_(long v) {this.data_end = v;}
|
||||
public byte Prog_status() {return status;} private byte status = Gfo_prog_ui_.Status__init; public void Prog_status_(byte v) {status = v;}
|
||||
public void Prog_notify_by_msg(String msg) {task_mgr.Work_mgr().On_stat(task_id, msg);}
|
||||
public boolean Canceled() {return status == Gfo_prog_ui_.Status__suspended;}
|
||||
public void Cancel() {status = Gfo_prog_ui_.Status__suspended;}
|
||||
|
||||
public int Task_id() {return task_id;} private final int task_id;
|
||||
public int Step_id() {return step_id;} private final int step_id;
|
||||
public int Cmd_id() {return cmd_id;} private final int cmd_id;
|
||||
public abstract String Cmd_type();
|
||||
public abstract String Cmd_name();
|
||||
@gplx.Virtual public boolean Cmd_suspendable() {return false;}
|
||||
public String Cmd_uid() {return cmd_uid;} private final String cmd_uid;
|
||||
@gplx.Virtual public String Cmd_fallback() {return this.Cmd_type();}
|
||||
@gplx.Virtual public void Cmd_clear() {// called when restarting failed task
|
||||
this.status = Gfo_prog_ui_.Status__init;
|
||||
this.cmd_exec_err = null; // reset error
|
||||
this.data_cur = 0; // reset progress else bad progress updates; DATE:2016-06-29
|
||||
this.Cmd_cleanup(); // do any cleanup, such as deleting bad downloads
|
||||
}
|
||||
|
||||
public void Cmd_exec(Xobc_cmd_ctx ctx) {
|
||||
// rate_list.Clear(); this.rate_cur = 0; // TOMBSTONE: do not reset rate else pause and resume will show different numbers
|
||||
Xoapi_root api_root = task_mgr.App().Api_root();
|
||||
if (api_root != null)
|
||||
this.log_verbose = api_root.Addon().Bldr().Central().Log_verbose();
|
||||
try {
|
||||
Gfo_log_.Instance.Info("xobc_cmd task bgn", "task_id", task_id, "step_id", step_id, "cmd_id", cmd_id);
|
||||
this.time_prv = gplx.core.envs.System_.Ticks();
|
||||
this.status = Gfo_prog_ui_.Status__working;
|
||||
this.Cmd_exec_hook(ctx);
|
||||
Gfo_log_.Instance.Info("xobc_cmd task end", "task_id", task_id, "step_id", step_id, "cmd_id", cmd_id);
|
||||
switch (status) {
|
||||
case Gfo_prog_ui_.Status__suspended: task_mgr.Work_mgr().On_suspended(this); break;
|
||||
case Gfo_prog_ui_.Status__fail: task_mgr.Work_mgr().On_fail(this, this.Cmd_fail_resumes(), cmd_exec_err); break;
|
||||
case Gfo_prog_ui_.Status__working:
|
||||
this.Prog_notify_and_chk_if_suspended(data_end, data_end); // fire one more time for 100%; note that 100% may not fire due to timer logic below
|
||||
task_mgr.Work_mgr().On_done(this, true);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.status = Gfo_prog_ui_.Status__fail;
|
||||
Gfo_log_.Instance.Warn("xobc_cmd task fail", "task_id", task_id, "step_id", step_id, "cmd_id", cmd_id, "err", Err_.Message_gplx_log(e));
|
||||
task_mgr.Work_mgr().On_fail(this, this.Cmd_fail_resumes(), Err_.Message_lang(e));
|
||||
}
|
||||
finally {
|
||||
Gfo_log_.Instance.Flush();
|
||||
}
|
||||
}
|
||||
protected abstract void Cmd_exec_hook(Xobc_cmd_ctx ctx);
|
||||
@gplx.Virtual protected boolean Cmd_fail_resumes() {return false;}
|
||||
protected void Cmd_exec_err_(String v) {
|
||||
Gfo_log_.Instance.Warn("xobc_cmd task err", "task_id", task_id, "step_id", step_id, "cmd_id", cmd_id, "err", v);
|
||||
this.status = Gfo_prog_ui_.Status__fail;
|
||||
this.cmd_exec_err = v;
|
||||
} private String cmd_exec_err;
|
||||
@gplx.Virtual public void Cmd_cleanup() {}
|
||||
|
||||
public Gfobj_nde Save_to(Gfobj_nde nde) {
|
||||
nde.Add_int ("task_id" , task_id);
|
||||
nde.Add_int ("step_id" , step_id);
|
||||
nde.Add_int ("cmd_id" , cmd_id);
|
||||
nde.Add_str ("cmd_type" , this.Cmd_type());
|
||||
nde.Add_str ("cmd_name" , this.Cmd_name());
|
||||
nde.Add_bool("cmd_suspendable" , this.Cmd_suspendable());
|
||||
nde.Add_byte("prog_status" , this.Prog_status());
|
||||
nde.Add_long("prog_data_cur" , this.Prog_data_cur());
|
||||
nde.Add_long("prog_data_end" , this.Prog_data_end());
|
||||
nde.Add_long("prog_time_end" , 0);
|
||||
return nde;
|
||||
}
|
||||
public void Load_checkpoint() {
|
||||
long data_cur = this.Load_checkpoint_hook();
|
||||
this.Prog_data_cur_(data_cur);
|
||||
if (data_cur > 0)
|
||||
this.Prog_status_(Gfo_prog_ui_.Status__suspended); // set status to suspended, else js won't warn about accidental removal
|
||||
}
|
||||
@gplx.Virtual protected long Load_checkpoint_hook() {return 0;}
|
||||
|
||||
public boolean Prog_notify_and_chk_if_suspended(long new_data_cur, long new_data_end) {
|
||||
if (status == Gfo_prog_ui_.Status__suspended) return true; // task paused by ui; exit now;
|
||||
long time_cur = gplx.core.envs.System_.Ticks();
|
||||
if (time_cur < time_prv + notify_delay) return false; // message came too soon. ignore it
|
||||
|
||||
// update rate
|
||||
double rate_now = (rate_list.Add(new_data_cur - data_cur, (time_cur - time_prv))) * 1000;
|
||||
double delta = Math_.Abs_double((rate_now - rate_cur) / rate_cur);
|
||||
if ( rate_cur == 0 // rate not set
|
||||
|| delta > delta_threshold) { // rate_now is at least 25% different than rate_prv
|
||||
if (delta > delta_threshold * 2) // rate_now is > 50% different
|
||||
rate_cur = rate_now; // update it now
|
||||
else {
|
||||
double rate_new = ((rate_now - rate_cur) * .05) + rate_cur; // calc new rate as 5% of difference
|
||||
// Tfds.Dbg(delta, rate_now, rate_cur, rate_new);
|
||||
rate_cur = rate_new;
|
||||
}
|
||||
}
|
||||
|
||||
// update prog vals
|
||||
this.time_prv = time_cur;
|
||||
this.data_cur = new_data_cur;
|
||||
this.data_end = new_data_end;
|
||||
|
||||
task_mgr.Send_json("xo.bldr.work.prog__update__recv", Gfobj_nde.New()
|
||||
.Add_int ("task_id", task_id).Add_long("prog_data_cur", data_cur).Add_long("prog_data_end", data_end).Add_int("prog_rate", (int)rate_cur));
|
||||
if (log_verbose)
|
||||
Gfo_usr_dlg_.Instance.Note_many("", "", "xobc:notify: task_id=~{0} cmd_id=~{1} prog_data_cur=~{2} prog_data_end=~{3} rate_cur=~{4}", task_id, cmd_id, data_cur, data_end, rate_cur);
|
||||
return false;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk__exec)) Cmd_exec((Xobc_cmd_ctx)m.ReadObj("v"));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public static final String Invk__exec = "exec";
|
||||
public static final int Seqn__0 = 0;
|
||||
public static Gfo_rate_mgr New_rate_mgr() {
|
||||
Gfo_rate_mgr rv = new Gfo_rate_mgr(128);
|
||||
rv.Add_new(Xobc_cmd__verify_dir.CMD_TYPE);
|
||||
rv.Add_new(Xobc_cmd__verify_fil.CMD_TYPE);
|
||||
rv.Add_new(Xobc_cmd__download.CMD_TYPE);
|
||||
rv.Add_new(Xobc_cmd__unzip.CMD_TYPE);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,70 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.progs.*; import gplx.core.net.downloads.*;
|
||||
public class Xobc_cmd__download extends Xobc_cmd__base {
|
||||
private final Xobc_task_mgr task_mgr;
|
||||
private final String src_url; private final Io_url trg_url;
|
||||
private final long expd_size;
|
||||
private final Http_download_wkr wkr;
|
||||
public Xobc_cmd__download(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_id, String src_url, Io_url trg_url, long file_size_zip) {super(task_mgr, task_id, step_id, cmd_id);
|
||||
this.task_mgr = task_mgr;
|
||||
this.src_url = src_url; this.trg_url = trg_url; this.expd_size = file_size_zip;
|
||||
this.wkr = Http_download_wkr_.Proto.Make_new();
|
||||
this.Prog_data_end_(expd_size);
|
||||
}
|
||||
@Override public String Cmd_type() {return CMD_TYPE;} public static final String CMD_TYPE = "xowa.core.download";
|
||||
@Override public String Cmd_name() {return "download";}
|
||||
@Override public boolean Cmd_suspendable() {return true;}
|
||||
|
||||
@Override protected void Cmd_exec_hook(Xobc_cmd_ctx ctx) {
|
||||
int error_wait = 10000, error_tries_max = 6, error_tries_cur = 0; // retry every 10 seconds for a total of 6 tries (1 min)
|
||||
|
||||
// loop while "server ... " error
|
||||
while (true) {
|
||||
long trg_size_bgn = Tmp_url_size();
|
||||
byte status = wkr.Exec(this, src_url, trg_url, expd_size);
|
||||
if (status == Gfo_prog_ui_.Status__fail) {
|
||||
|
||||
// check if server error; note: must not loop if bad size; DATE:2016-09-24
|
||||
String fail_msg = wkr.Fail_msg();
|
||||
if (String_.Has_at_bgn(fail_msg, Http_download_wkr__jre.Err__server_download_failed)) {
|
||||
|
||||
// check if anything more downloaded; if so, then reset to 0; DATE:2016-09-03
|
||||
long trg_size_cur = Tmp_url_size();
|
||||
if (trg_size_cur > trg_size_bgn) {
|
||||
error_tries_cur = 0;
|
||||
trg_size_bgn = trg_size_cur;
|
||||
}
|
||||
|
||||
// retry
|
||||
if (error_tries_cur++ < error_tries_max) {
|
||||
task_mgr.Work_mgr().On_stat(this.Task_id(), String_.Format("connection interrupted: retrying in {0} seconds; attempt {1} of {2}", error_wait / 1000, error_tries_cur, error_tries_max));
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "xobc_cmd task download interrupted; ~{0} ~{1} ~{2} ~{3}", this.Task_id(), this.Step_id(), trg_url, Io_mgr.Instance.QueryFil(trg_url).Size());
|
||||
gplx.core.threads.Thread_adp_.Sleep(error_wait);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// otherewise exit loop
|
||||
this.Cmd_exec_err_(fail_msg);
|
||||
break;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
Gfo_log_.Instance.Info("xobc_cmd task download", "task_id", this.Task_id(), "step_id", this.Step_id(), "trg_url", trg_url, "trg_len", Io_mgr.Instance.QueryFil(trg_url).Size());
|
||||
}
|
||||
private long Tmp_url_size() {
|
||||
return wkr.Tmp_url() == null ? 0 : Io_mgr.Instance.QueryFil(wkr.Tmp_url()).Size(); // NOTE: wkr.Tmp_url is null in some extreme exceptions; DATE:2016-09-24
|
||||
}
|
||||
@Override public void Cmd_cleanup() {
|
||||
wkr.Exec_cleanup();
|
||||
}
|
||||
@Override protected boolean Cmd_fail_resumes() {return true;}
|
||||
|
||||
@Override protected long Load_checkpoint_hook() {
|
||||
return wkr.Checkpoint__load_by_trg_fil(trg_url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,32 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.addons.bldrs.updates.files.*;
|
||||
public class Xobc_cmd__fsdb_delete extends Xobc_cmd__base {
|
||||
private final Io_url deletion_db_url;
|
||||
public Xobc_cmd__fsdb_delete(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_idx, Io_url deletion_db_url) {super(task_mgr, task_id, step_id, cmd_idx);
|
||||
this.deletion_db_url = deletion_db_url;
|
||||
}
|
||||
@Override public String Cmd_type() {return CMD_TYPE;} public static final String CMD_TYPE = "xowa.fsdb.delete";
|
||||
@Override public String Cmd_name() {return "deleting old files";}
|
||||
@Override public boolean Cmd_suspendable() {return true;}
|
||||
@Override protected void Cmd_exec_hook(Xobc_cmd_ctx ctx) {
|
||||
if (!Io_mgr.Instance.ExistsFil(deletion_db_url)) throw Err_.New("deletion db does not exist; file={0}", deletion_db_url.Raw());
|
||||
boolean pass = false;
|
||||
try {
|
||||
new Xodel_exec_mgr().Exec_delete(this, ctx.App().Bldr(), deletion_db_url);
|
||||
pass = true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.Cmd_exec_err_(Err_.Message_gplx_log(e));
|
||||
}
|
||||
Gfo_log_.Instance.Info("xobc_cmd task delete", "task_id", this.Task_id(), "step_id", this.Step_id(), "delete_url", deletion_db_url.Raw(), "pass", pass);
|
||||
}
|
||||
@Override public void Cmd_cleanup() {
|
||||
if (Io_mgr.Instance.ExistsFil(deletion_db_url))
|
||||
new Xodel_exec_mgr().Exec_cleanup(deletion_db_url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,27 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
public class Xobc_cmd__move_fils extends Xobc_cmd__base {
|
||||
private final Io_url src_dir, trg_dir;
|
||||
private final List_adp trg_fils = List_adp_.New();
|
||||
public Xobc_cmd__move_fils(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_idx, Io_url src_dir, Io_url trg_dir) {super(task_mgr, task_id, step_id, cmd_idx);
|
||||
this.src_dir = src_dir; this.trg_dir = trg_dir;
|
||||
}
|
||||
@Override public String Cmd_type() {return CMD_TYPE;} public static final String CMD_TYPE = "xowa.core.move_fil";
|
||||
@Override public String Cmd_name() {return "move";}
|
||||
@Override protected void Cmd_exec_hook(Xobc_cmd_ctx ctx) {
|
||||
Io_url[] src_fils = Io_mgr.Instance.QueryDir_fils(src_dir);
|
||||
int len = src_fils.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Io_url src_fil = src_fils[i];
|
||||
if (String_.Eq(src_fil.Ext(), ".md5")) continue;
|
||||
Io_url trg_fil = trg_dir.GenSubFil(src_fil.NameAndExt());
|
||||
Io_mgr.Instance.MoveFil_args(src_fil, trg_fil, true).Exec();
|
||||
trg_fils.Add(trg_fil);
|
||||
}
|
||||
}
|
||||
@Override public void Cmd_cleanup() {
|
||||
Io_mgr.Instance.Delete_dir_empty(trg_dir.GenSubDir("tmp")); // deletes dir only if empty
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,32 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.ios.zips.*; import gplx.core.progs.*;
|
||||
public class Xobc_cmd__unzip extends Xobc_cmd__base {
|
||||
private final Io_url src_fil, trg_dir;
|
||||
private final Io_zip_decompress_cmd wkr;
|
||||
private final List_adp trg_fils = List_adp_.New();
|
||||
public Xobc_cmd__unzip(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_id, Io_url src_fil, Io_url trg_dir, long prog_data_end) {super(task_mgr, task_id, step_id, cmd_id);
|
||||
this.src_fil = src_fil; this.trg_dir = trg_dir;
|
||||
this.Prog_data_end_(prog_data_end);
|
||||
this.wkr = Io_zip_decompress_cmd_.Proto.Make_new();
|
||||
}
|
||||
@Override public String Cmd_type() {return CMD_TYPE;} public static final String CMD_TYPE = "xowa.core.ios.zips.zip_unzip";
|
||||
@Override public String Cmd_name() {return "unzip";}
|
||||
@Override public boolean Cmd_suspendable() {return true;}
|
||||
@Override public String Cmd_fallback() {return Xobc_cmd__verify_fil.CMD_TYPE;} // if unzip fails, backtrack to verify; if verify fails, it'll backtrack to download; DATE:2016-07-25
|
||||
|
||||
@Override protected void Cmd_exec_hook(Xobc_cmd_ctx ctx) {
|
||||
if (wkr.Exec(this, src_fil, trg_dir, trg_fils) == Gfo_prog_ui_.Status__fail)
|
||||
this.Cmd_exec_err_(wkr.Fail_msg());
|
||||
}
|
||||
@Override public void Cmd_cleanup() {
|
||||
wkr.Exec_cleanup();
|
||||
Io_mgr.Instance.DeleteFil(src_fil);
|
||||
Io_mgr.Instance.DeleteDirDeep(trg_dir);
|
||||
}
|
||||
@Override protected long Load_checkpoint_hook() {
|
||||
return wkr.Checkpoint__load_by_src_fil(src_fil);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,46 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.progs.*;
|
||||
import gplx.core.security.*; import gplx.core.security.files.*;
|
||||
public class Xobc_cmd__verify_dir extends Xobc_cmd__base {
|
||||
private final Io_url delete_fil, checksum_fil;
|
||||
public Xobc_cmd__verify_dir(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_idx, Io_url checksum_fil, Io_url delete_fil) {super(task_mgr, task_id, step_id, cmd_idx);
|
||||
this.checksum_fil = checksum_fil;
|
||||
this.delete_fil = delete_fil;
|
||||
}
|
||||
@Override public String Cmd_type() {return CMD_TYPE;} public static final String CMD_TYPE = "xowa.core.hash_dir";
|
||||
@Override public String Cmd_name() {return "verify";}
|
||||
@Override public String Cmd_fallback() {return Xobc_cmd__unzip.CMD_TYPE;}
|
||||
|
||||
@Override protected void Cmd_exec_hook(Xobc_cmd_ctx ctx) {
|
||||
// parse file
|
||||
Cksum_list list = Cksum_list.Parse_by_fil(checksum_fil);
|
||||
this.Prog_data_end_(list.Itms_size);
|
||||
|
||||
// verify itms
|
||||
Hash_algo algo = Hash_algo_.New_by_tid(list.Type);
|
||||
Cksum_itm[] itms = list.Itms;
|
||||
int len = itms.length;
|
||||
long prog_data_cur = 0;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Cksum_itm itm = itms[i];
|
||||
gplx.core.ios.streams.IoStream stream = Io_mgr.Instance.OpenStreamRead(itm.File_url);
|
||||
byte[] actl_hash = Bry_.Empty;
|
||||
this.Prog_data_cur_(prog_data_cur);
|
||||
try {actl_hash = algo.Hash_stream_as_bry(this, stream);}
|
||||
finally {stream.Rls();}
|
||||
prog_data_cur += itm.File_size;
|
||||
if (this.Prog_notify_and_chk_if_suspended(prog_data_cur, Prog_data_end())) return;
|
||||
if (this.Prog_status() != Gfo_prog_ui_.Status__suspended && !Bry_.Eq(itm.Hash, actl_hash)) {
|
||||
this.Cmd_exec_err_(String_.Format("bad hash; file={0} bad={1} good={2}", itm.File_url.Raw(), actl_hash, itm.Hash));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override public void Cmd_cleanup() {
|
||||
Io_mgr.Instance.DeleteFil(checksum_fil);
|
||||
Io_mgr.Instance.DeleteFil(delete_fil);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,28 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.progs.*; import gplx.core.security.*;
|
||||
public class Xobc_cmd__verify_fil extends Xobc_cmd__base {
|
||||
private final Io_url src_url; private final byte[] expd_hash;
|
||||
public Xobc_cmd__verify_fil(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_id, Io_url src_url, String expd_hash_str, long prog_data_end) {super(task_mgr, task_id, step_id, cmd_id);
|
||||
this.src_url = src_url;
|
||||
this.expd_hash = Bry_.new_a7(expd_hash_str);
|
||||
this.Prog_data_end_(prog_data_end);
|
||||
}
|
||||
@Override public String Cmd_type() {return CMD_TYPE;} public static final String CMD_TYPE = "xowa.core.hash_fil";
|
||||
@Override public String Cmd_name() {return "verify";}
|
||||
@Override public String Cmd_fallback() {return Xobc_cmd__download.CMD_TYPE;}
|
||||
|
||||
@Override protected void Cmd_exec_hook(Xobc_cmd_ctx ctx) {
|
||||
Hash_algo algo = Hash_algo_.New__md5();
|
||||
gplx.core.ios.streams.IoStream stream = Io_mgr.Instance.OpenStreamRead(src_url);
|
||||
byte[] actl_hash = Bry_.Empty;
|
||||
try {actl_hash = algo.Hash_stream_as_bry(this, stream);}
|
||||
finally {stream.Rls();}
|
||||
if (this.Prog_status() != Gfo_prog_ui_.Status__suspended && !Bry_.Eq(expd_hash, actl_hash))
|
||||
this.Cmd_exec_err_(Xobc_cmd__verify_fil.Err_make(actl_hash, expd_hash));
|
||||
}
|
||||
|
||||
public static String Err_make(byte[] actl, byte[] expd) {return String_.Format("bad hash: bad={0} good={1}", String_.new_u8(actl), String_.new_u8(expd));}
|
||||
}
|
||||
|
||||
@@ -13,43 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.addons.bldrs.exports.splits.mgrs.*; import gplx.xowa.addons.bldrs.exports.merges.*;
|
||||
public class Xobc_cmd__wiki_merge extends Xobc_cmd__base {
|
||||
private final String wiki_domain;
|
||||
private final Io_url src_dir;
|
||||
private final Merge2_mgr merge_mgr;
|
||||
private final Merge_prog_wkr prog_wkr;
|
||||
private final int idx_cur;
|
||||
public Xobc_cmd__wiki_merge(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_idx, Merge2_mgr merge_mgr, String wiki_domain, Io_url src_dir
|
||||
, long prog_size_end, int prog_count_end, int idx_cur) {super(task_mgr, task_id, step_id, cmd_idx);
|
||||
this.merge_mgr = merge_mgr;
|
||||
this.wiki_domain = wiki_domain;
|
||||
this.src_dir = src_dir;
|
||||
this.prog_wkr = new Merge_prog_wkr(this, src_dir.GenSubFil("merge.checkpoint"), prog_count_end, prog_size_end);
|
||||
merge_mgr.Prog_wkr_(prog_wkr);
|
||||
this.Prog_data_end_(prog_count_end);
|
||||
this.idx_cur = idx_cur;
|
||||
}
|
||||
@Override public String Cmd_type() {return CMD_TYPE;} public static final String CMD_TYPE = "xowa.wiki.merge";
|
||||
@Override public String Cmd_name() {return "merge";}
|
||||
@Override public boolean Cmd_suspendable() {return true;}
|
||||
@Override protected void Cmd_exec_hook(Xobc_cmd_ctx ctx) {
|
||||
Xow_wiki wiki = ctx.App().Wiki_mgri().Make(Bry_.new_u8(wiki_domain), ctx.App().Fsys_mgr().Wiki_dir().GenSubDir(wiki_domain));
|
||||
Io_url[] fils = Io_mgr.Instance.QueryDir_fils(src_dir);
|
||||
for (Io_url fil : fils) {
|
||||
if (prog_wkr.Checkpoint__skip_fil(fil)) continue;
|
||||
switch (Split_file_tid_.To_tid(fil)) {
|
||||
case Split_file_tid_.Tid__core: merge_mgr.ctx.Idx_cur_add_(); merge_mgr.Merge_core(wiki, fil); break;
|
||||
case Split_file_tid_.Tid__data: merge_mgr.ctx.Idx_cur_add_(); merge_mgr.Merge_data(wiki, fil, idx_cur); break;
|
||||
}
|
||||
}
|
||||
prog_wkr.Checkpoint__delete();
|
||||
}
|
||||
@Override public void Cmd_cleanup() {
|
||||
Io_mgr.Instance.DeleteDirDeep(src_dir.OwnerDir()); // src_dir is "unzip" dir; owner dir is actual archive dir
|
||||
}
|
||||
@Override protected long Load_checkpoint_hook() {return prog_wkr.Checkpoint__load();}
|
||||
}
|
||||
|
||||
@@ -13,39 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.security.*;
|
||||
import gplx.xowa.wikis.*;
|
||||
public class Xobc_cmd__wiki_reg extends Xobc_cmd__base {
|
||||
private final Io_url wiki_dir;
|
||||
private final String wiki_domain;
|
||||
public Xobc_cmd__wiki_reg(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_idx, Io_url wiki_dir, String wiki_domain) {super(task_mgr, task_id, step_id, cmd_idx);
|
||||
this.wiki_dir = wiki_dir;
|
||||
this.wiki_domain = wiki_domain;
|
||||
}
|
||||
@Override public String Cmd_type() {return CMD_TYPE;} public static final String CMD_TYPE = "xowa.wiki.reg";
|
||||
@Override public String Cmd_name() {return "import";}
|
||||
@Override protected void Cmd_exec_hook(Xobc_cmd_ctx ctx) {
|
||||
ctx.App().User().User_db_mgr().Init_site_mgr(); // must init for wiki.register cmd
|
||||
|
||||
// get wiki_core_url
|
||||
Io_url[] wiki_fils = Io_mgr.Instance.QueryDir_fils(wiki_dir);
|
||||
Io_url wiki_core_url = null;
|
||||
int len = wiki_fils.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Io_url url = wiki_fils[i];
|
||||
if (gplx.xowa.wikis.data.Xow_db_file__core_.Is_core_fil_name(wiki_domain, url.NameAndExt())) {
|
||||
wiki_core_url = url;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (wiki_core_url == null) throw Err_.new_("wiki_import", "import_url not found", "domain", wiki_domain);
|
||||
|
||||
// import; open
|
||||
Xoa_wiki_mgr wiki_mgr = ctx.App().Wiki_mgri();
|
||||
Gfo_invk_.Invk_by_val(wiki_mgr, gplx.xowa.wikis.Xoa_wiki_mgr_.Invk__import_by_url, wiki_core_url);
|
||||
// COMMENTED: do not auto-open wiki; wait for true-pack mode
|
||||
// Xow_wiki wiki = wiki_mgr.Get_by_or_null(Bry_.new_u8(wiki_domain));
|
||||
// Gfo_invk_.Invk_by_msg(ctx.App().Gui__tab_mgr() , gplx.xowa.guis.tabs.Xog_tab_mgr_.Invk__new_tab, GfoMsg_.new_cast_("").Add("focus", true).Add("site", wiki_domain).Add("page", String_.new_u8(wiki.Props().Main_page())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
public class Xobc_cmd_ctx {
|
||||
public Xobc_cmd_ctx(Xoa_app app) {this.app = app;}
|
||||
public Xoa_app App() {return app;} private final Xoa_app app;
|
||||
}
|
||||
|
||||
@@ -13,20 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.progs.*; import gplx.core.gfobjs.*;
|
||||
public interface Xobc_cmd_itm extends Gfo_prog_ui, Gfo_invk {
|
||||
int Task_id();
|
||||
int Step_id();
|
||||
int Cmd_id();
|
||||
String Cmd_type(); // "xowa.core.http_download"
|
||||
String Cmd_name(); // "download"
|
||||
boolean Cmd_suspendable(); // "true"
|
||||
String Cmd_uid(); // for thread_pool_mgr: "0:0:0"
|
||||
void Cmd_cleanup();
|
||||
String Cmd_fallback();
|
||||
void Cmd_clear();
|
||||
|
||||
Gfobj_nde Save_to(Gfobj_nde nde);
|
||||
void Load_checkpoint();
|
||||
}
|
||||
|
||||
@@ -13,49 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.dbs.datas.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.imports.*;
|
||||
public class Xobc_data_db {
|
||||
public Xobc_data_db(Io_url db_url) {
|
||||
this.url = db_url;
|
||||
this.conn = Db_conn_bldr.Instance.Get_or_autocreate(true, db_url);
|
||||
this.tbl__task_regy = new Xobc_task_regy_tbl(conn);
|
||||
this.tbl__step_regy = new Xobc_step_regy_tbl(conn);
|
||||
this.tbl__step_map = new Xobc_step_map_tbl(conn);
|
||||
this.tbl__import_step = new Xobc_import_step_tbl(conn);
|
||||
this.tbl__host_regy = new Xobc_host_regy_tbl(conn);
|
||||
this.tbl__version_regy = new Xobc_version_regy_tbl(conn);
|
||||
this.tbl__lang_regy = new Xobc_lang_regy_tbl(conn);
|
||||
conn.Meta_tbl_assert(tbl__task_regy, tbl__step_regy, tbl__step_map, tbl__import_step, tbl__host_regy, tbl__version_regy, tbl__lang_regy);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public Io_url Url() {return url;} private final Io_url url;
|
||||
public Xobc_task_regy_tbl Tbl__task_regy() {return tbl__task_regy;} private final Xobc_task_regy_tbl tbl__task_regy;
|
||||
public Xobc_step_regy_tbl Tbl__step_regy() {return tbl__step_regy;} private final Xobc_step_regy_tbl tbl__step_regy;
|
||||
public Xobc_step_map_tbl Tbl__step_map() {return tbl__step_map;} private final Xobc_step_map_tbl tbl__step_map;
|
||||
public Xobc_import_step_tbl Tbl__import_step() {return tbl__import_step;} private final Xobc_import_step_tbl tbl__import_step;
|
||||
public Xobc_host_regy_tbl Tbl__host_regy() {return tbl__host_regy;} private final Xobc_host_regy_tbl tbl__host_regy;
|
||||
public Xobc_version_regy_tbl Tbl__version_regy() {return tbl__version_regy;} private final Xobc_version_regy_tbl tbl__version_regy;
|
||||
public Xobc_lang_regy_tbl Tbl__lang_regy() {return tbl__lang_regy;} private final Xobc_lang_regy_tbl tbl__lang_regy;
|
||||
|
||||
public void Delete_by_import(byte[] wiki_abrv, String wiki_date) {
|
||||
// get all step ids from import_regy
|
||||
Xobc_task_step_hash task_step_hash = new Xobc_task_step_hash();
|
||||
tbl__import_step.Select_tasks_steps(task_step_hash, tbl__step_map, wiki_abrv, wiki_date);
|
||||
for (int i = 0; i < task_step_hash.Tasks__len(); ++i) {
|
||||
int task_id = task_step_hash.Tasks__get_at(i);
|
||||
tbl__task_regy.Delete(task_id);
|
||||
tbl__step_map.Delete_by_task_id(task_id);
|
||||
}
|
||||
for (int i = 0; i < task_step_hash.Steps__len(); ++i) {
|
||||
int step_id = task_step_hash.Steps__get_at(i);
|
||||
tbl__step_regy.Delete(step_id);
|
||||
tbl__import_step.Delete(step_id);
|
||||
}
|
||||
}
|
||||
|
||||
public static Xobc_data_db New(gplx.xowa.apps.fsys.Xoa_fsys_mgr fsys_mgr) {
|
||||
return new Xobc_data_db(fsys_mgr.Bin_addon_dir().GenSubFil_nest("bldr", "central", "bldr_central.data_db.xowa"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,75 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.core.progs.*; import gplx.core.net.downloads.*; import gplx.core.gfobjs.*;
|
||||
import gplx.xowa.users.data.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*;
|
||||
import gplx.xowa.wikis.pages.tags.*;
|
||||
public class Xobc_data_db_upgrader {
|
||||
private static final String
|
||||
Cfg__last_check_date = "xowa.bldr_central.data_db.last_check_date"
|
||||
// , Cfg__next_check_interval = "xowa.bldr_central.data_db.next_check_interval"
|
||||
, Date_fmt = "yyyy-MM-dd HH:mm"
|
||||
;
|
||||
public static void Check_for_updates(Xobc_task_mgr task_mgr) {
|
||||
Io_url data_db_url = task_mgr.Data_db().Url();
|
||||
Xoud_cfg_mgr cfg_mgr = task_mgr.App().User().User_db_mgr().Cfg_mgr();
|
||||
|
||||
// check if update needed
|
||||
//String last_check_str = cfg_mgr.Select_str_or("", Cfg__last_check_date, "");
|
||||
//int next_check_interval = cfg_mgr.Select_int_or("", Cfg__next_check_interval, 24 * 7);
|
||||
//DateAdp last_check = DateAdp_.parse_fmt_or(last_check_str, Date_fmt, null);
|
||||
//if (last_check != null) { // check if last_check_str exists
|
||||
// Time_span span = Datetime_now.Get().Diff(last_check);
|
||||
// if (span.Total_hours().To_double() < next_check_interval) { // check if enough time passed
|
||||
// Gfo_log_.Instance.Info("xobc_db update not needed", "last_check", last_check_str, "next_check_interval", next_check_interval);
|
||||
// return;
|
||||
// }
|
||||
// else
|
||||
// Gfo_log_.Instance.Info("xobc_db update needed b/c of last_check", "last_check", last_check_str);
|
||||
//}
|
||||
//else
|
||||
// Gfo_log_.Instance.Info("xobc_db update needed b/c of missing or invalid last_check_str", "last_check", last_check_str);
|
||||
|
||||
// update needed; first, update cfg_key, then get host
|
||||
cfg_mgr.Upsert_str("", Cfg__last_check_date, Datetime_now.Get().XtoStr_fmt(Date_fmt));
|
||||
Xobc_data_db bc_db = task_mgr.Data_db();
|
||||
Xobc_host_regy_itm host_itm = bc_db.Tbl__host_regy().Select(Xobc_host_regy_tbl.Host_id__archive_org);
|
||||
|
||||
// download manifest
|
||||
Http_download_wkr download_wkr = Http_download_wkr_.Proto.Make_new();
|
||||
Io_url manifest_url = data_db_url.GenNewExt(".txt");
|
||||
download_wkr.Exec(Gfo_prog_ui_.Always
|
||||
, String_.Format("http://{0}/{1}/bldr_central.data_db.txt", host_itm.Host_domain(), host_itm.Host_update_dir())
|
||||
, manifest_url, -1);
|
||||
|
||||
// parse manifest and get version_id
|
||||
byte[] manifest_txt = Io_mgr.Instance.LoadFilBry(manifest_url);
|
||||
byte[][] manifest_data = Bry_split_.Split(manifest_txt, Byte_ascii.Pipe);
|
||||
int expd_version_id = Bry_.To_int(manifest_data[0]);
|
||||
Xobc_version_regy_itm actl_version = bc_db.Tbl__version_regy().Select_latest();
|
||||
|
||||
// cleanup
|
||||
Io_mgr.Instance.DeleteFil(manifest_url);
|
||||
bc_db.Conn().Rls_conn();
|
||||
if (expd_version_id == actl_version.Id()) {
|
||||
Gfo_log_.Instance.Info("xobc_db update not needed", "version", expd_version_id);
|
||||
Xopg_alertify_.Exec_log(task_mgr, "Wikis are up-to-date", 30);
|
||||
return; // version matches; exit
|
||||
}
|
||||
|
||||
// version doesn't match; download new
|
||||
// next_check_interval = Bry_.To_int(manifest_data[2]);
|
||||
// cfg_mgr.Upsert_int("", Cfg__next_check_interval, next_check_interval);
|
||||
// Gfo_log_.Instance.Info("xobc_db update needed", "version", expd_version_id, "next_check_interval", next_check_interval);
|
||||
byte[] new_db_url = manifest_data[1];
|
||||
String note = String_.new_u8(manifest_data[3]);
|
||||
download_wkr.Exec(Gfo_prog_ui_.Always
|
||||
, String_.new_u8(new_db_url)
|
||||
, data_db_url, -1);
|
||||
Xopg_alertify_.Exec_log(task_mgr, "Wikis have been updated:<br/>" + note, 30);
|
||||
task_mgr.Load_or_init();
|
||||
task_mgr.Reload();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,17 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
public class Xobc_task_step_hash {
|
||||
private final Ordered_hash tasks_hash = Ordered_hash_.New();
|
||||
private final Ordered_hash steps_hash = Ordered_hash_.New();
|
||||
public int Tasks__len() {return tasks_hash.Len();}
|
||||
public int Tasks__get_at(int i) {return Int_.Cast(tasks_hash.Get_at(i));}
|
||||
public int Steps__len() {return steps_hash.Len();}
|
||||
public int Steps__get_at(int i) {return Int_.Cast(steps_hash.Get_at(i));}
|
||||
public void Clear() {tasks_hash.Clear(); steps_hash.Clear();}
|
||||
public void Add(int task_id, int step_id) {
|
||||
tasks_hash.Add_if_dupe_use_nth(task_id, task_id);
|
||||
steps_hash.Add_if_dupe_use_nth(step_id, step_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,17 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.dbs.users.*;
|
||||
public class Xobc_user_db {
|
||||
public Xobc_user_db(Db_conn conn) {
|
||||
this.work_task_tbl = new Xobc_work_task_tbl(conn);
|
||||
this.done_task_tbl = new Xobc_done_task_tbl(conn);
|
||||
this.done_step_tbl = new Xobc_done_step_tbl(conn);
|
||||
conn.Meta_tbl_assert(work_task_tbl, done_task_tbl, done_step_tbl);
|
||||
}
|
||||
public Xobc_work_task_tbl Work_task_tbl() {return work_task_tbl;} private final Xobc_work_task_tbl work_task_tbl;
|
||||
public Xobc_done_task_tbl Done_task_tbl() {return done_task_tbl;} private final Xobc_done_task_tbl done_task_tbl;
|
||||
public Xobc_done_step_tbl Done_step_tbl() {return done_step_tbl;} private final Xobc_done_step_tbl done_step_tbl;
|
||||
}
|
||||
|
||||
@@ -13,16 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
|
||||
public class Xobc_host_regy_itm {
|
||||
public Xobc_host_regy_itm(int host_id, String host_domain, String host_data_dir, String host_update_dir) {
|
||||
this.host_id = host_id;
|
||||
this.host_domain = host_domain;
|
||||
this.host_data_dir = host_data_dir;
|
||||
this.host_update_dir = host_update_dir;
|
||||
}
|
||||
public int Host_id() {return host_id;} private final int host_id;
|
||||
public String Host_domain() {return host_domain;} private final String host_domain;
|
||||
public String Host_data_dir() {return host_data_dir;} private final String host_data_dir;
|
||||
public String Host_update_dir() {return host_update_dir;} private final String host_update_dir;
|
||||
}
|
||||
|
||||
@@ -13,37 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xobc_host_regy_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_host_id, fld_host_domain, fld_host_data_dir, fld_host_update_dir;
|
||||
private final Db_conn conn;
|
||||
public Xobc_host_regy_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "host_regy";
|
||||
this.fld_host_id = flds.Add_int_pkey("host_id");
|
||||
this.fld_host_domain = flds.Add_str("host_domain", 255); // EX: archive.org
|
||||
this.fld_host_data_dir = flds.Add_str("host_data_dir", 255); // EX: download/Xowa_~{host_regy|wiki_abrv}_latest
|
||||
this.fld_host_update_dir = flds.Add_str("host_update_dir", 255); // EX: download/Xowa_app_support
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {
|
||||
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));
|
||||
conn.Stmt_insert(tbl_name, flds)
|
||||
.Val_int(fld_host_id, Host_id__archive_org).Val_str(fld_host_domain, "archive.org")
|
||||
.Val_str(fld_host_data_dir, "download/Xowa_~{host_regy|wiki_abrv}_latest").Val_str(fld_host_update_dir, "download/Xowa_app_support")
|
||||
.Exec_insert();
|
||||
}
|
||||
public Xobc_host_regy_itm Select(int host_id) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_host_id).Crt_int(fld_host_id, host_id).Exec_select__rls_auto();
|
||||
try {return rdr.Move_next() ? Load_itm(rdr) : null;}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
private Xobc_host_regy_itm Load_itm(Db_rdr rdr) {
|
||||
return new Xobc_host_regy_itm(rdr.Read_int(fld_host_id), rdr.Read_str(fld_host_domain), rdr.Read_str(fld_host_data_dir), rdr.Read_str(fld_host_update_dir));
|
||||
}
|
||||
public void Rls() {}
|
||||
public static final int Host_id__archive_org = 1;
|
||||
}
|
||||
|
||||
@@ -13,14 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
|
||||
public class Xobc_lang_regy_itm {
|
||||
public Xobc_lang_regy_itm(int id, String key, String name) {
|
||||
this.id = id;
|
||||
this.key = key;
|
||||
this.name = name;
|
||||
}
|
||||
public int Id() {return id;} private final int id;
|
||||
public String Key() {return key;} private final String key;
|
||||
public String Name() {return name;} private final String name;
|
||||
}
|
||||
|
||||
@@ -13,31 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xobc_lang_regy_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld__lang_id, fld__lang_key, fld__lang_name;
|
||||
private final Db_conn conn;
|
||||
public Xobc_lang_regy_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "lang_regy";
|
||||
this.fld__lang_id = flds.Add_int_pkey("lang_id");
|
||||
this.fld__lang_key = flds.Add_str("lang_key", 255);
|
||||
this.fld__lang_name = flds.Add_str("lang_name", 255);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public Xobc_lang_regy_itm[] Select_all() {
|
||||
List_adp list = List_adp_.New();
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next())
|
||||
list.Add(new Xobc_lang_regy_itm(rdr.Read_int(fld__lang_id), rdr.Read_str(fld__lang_key), rdr.Read_str(fld__lang_name)));
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
return (Xobc_lang_regy_itm[])list.To_ary_and_clear(Xobc_lang_regy_itm.class);
|
||||
}
|
||||
public void Rls() {}
|
||||
}
|
||||
|
||||
@@ -13,16 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
|
||||
public class Xobc_step_map_itm {
|
||||
public Xobc_step_map_itm(int sm_id, int task_id, int step_id, int step_seqn) {
|
||||
this.Sm_id = sm_id;
|
||||
this.Task_id = task_id;
|
||||
this.Step_id = step_id;
|
||||
this.Step_seqn = step_seqn;
|
||||
}
|
||||
public final int Sm_id;
|
||||
public final int Task_id;
|
||||
public final int Step_id;
|
||||
public final int Step_seqn;
|
||||
}
|
||||
|
||||
@@ -13,78 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xobc_step_map_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_sm_id, fld_step_seqn, fld_task_id, fld_step_id;
|
||||
private final Db_conn conn; private Db_stmt insert_stmt;
|
||||
public Xobc_step_map_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "step_map";
|
||||
this.fld_sm_id = flds.Add_int_pkey("sm_id");
|
||||
this.fld_task_id = flds.Add_int("task_id");
|
||||
this.fld_step_id = flds.Add_int("step_id");
|
||||
this.fld_step_seqn = flds.Add_int("step_seqn");
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public int Select_step_id(int task_id, int step_seqn) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_task_id, fld_step_seqn).Crt_int(fld_task_id, task_id).Crt_int(fld_step_seqn, step_seqn).Exec_select__rls_auto();
|
||||
try {
|
||||
if (rdr.Move_next())
|
||||
return rdr.Read_int(fld_step_id);
|
||||
else
|
||||
throw Err_.new_("", "xobc:could not find step_id", "task_id", task_id, "step_seqn", step_seqn);
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public Xobc_step_map_itm Select_one(int task_id, int step_id) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_task_id, fld_step_id).Crt_int(fld_task_id, task_id).Crt_int(fld_step_id, step_id).Exec_select__rls_auto();
|
||||
try {
|
||||
if (rdr.Move_next())
|
||||
return new Xobc_step_map_itm
|
||||
( rdr.Read_int(fld_sm_id)
|
||||
, rdr.Read_int(fld_task_id)
|
||||
, rdr.Read_int(fld_step_id)
|
||||
, rdr.Read_int(fld_step_seqn)
|
||||
);
|
||||
else
|
||||
throw Err_.new_("", "bldr.central:could not find step_id", "task_id", task_id, "step_id", step_id);
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public int Select_seqn_but_skip_done(int task_id, Hash_adp step_ids) {
|
||||
Db_rdr rdr = conn.Stmt_select_order(tbl_name, flds, String_.Ary(fld_task_id), fld_step_seqn).Crt_int(fld_task_id, task_id).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
int step_id = rdr.Read_int("step_id");
|
||||
if (step_ids.Has(step_id))
|
||||
return rdr.Read_int("step_seqn");
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
throw Err_.new_("", "xobc:could not find next sort", "task_id", task_id);
|
||||
}
|
||||
public List_adp Select_all(int task_id) {
|
||||
List_adp rv = List_adp_.New();
|
||||
Db_rdr rdr = conn.Stmt_select_order(tbl_name, flds, String_.Ary(fld_task_id), fld_step_seqn).Crt_int(fld_task_id, task_id).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
rv.Add(rdr.Read_int("step_id"));
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
return rv;
|
||||
}
|
||||
public void Insert(int sm_id, int task_id, int step_id, int step_seqn) {
|
||||
if (insert_stmt == null) insert_stmt = conn.Stmt_insert(tbl_name, flds);
|
||||
insert_stmt.Clear().Val_int(fld_sm_id, sm_id).Val_int(fld_task_id, task_id).Val_int(fld_step_id, step_id).Val_int(fld_step_seqn, step_seqn)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Delete_by_task_id(int task_id) {
|
||||
conn.Stmt_delete(tbl_name, fld_task_id).Crt_int(fld_task_id, task_id).Exec_delete();
|
||||
}
|
||||
public void Rls() {
|
||||
insert_stmt = Db_stmt_.Rls(insert_stmt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,41 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.tasks.*;
|
||||
public class Xobc_step_regy_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_step_id, fld_step_type;
|
||||
private final Db_conn conn; private Db_stmt insert_stmt;
|
||||
public Xobc_step_regy_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "step_regy";
|
||||
this.fld_step_id = flds.Add_int_pkey("step_id");
|
||||
this.fld_step_type = flds.Add_int("step_type");
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public int Select_type(int step_id) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_step_id).Crt_int(fld_step_id, step_id).Exec_select__rls_auto();
|
||||
try {
|
||||
if (rdr.Move_next())
|
||||
return rdr.Read_int(fld_step_type);
|
||||
else
|
||||
throw Err_.new_("", "bldr.central:could not find step_type", "step_id", step_id);
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public void Insert(int step_id, int step_type) {
|
||||
if (insert_stmt == null) insert_stmt = conn.Stmt_insert(tbl_name, flds);
|
||||
insert_stmt.Clear().Val_int(fld_step_id, step_id).Val_int(fld_step_type, step_type)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Delete(int step_id) {
|
||||
conn.Stmt_delete(tbl_name, fld_step_id).Crt_int(fld_step_id, step_id).Exec_delete();
|
||||
}
|
||||
public void Rls() {
|
||||
insert_stmt = Db_stmt_.Rls(insert_stmt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,21 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
|
||||
public class Xobc_task_regy_itm {
|
||||
public Xobc_task_regy_itm(int id, int seqn, byte[] key, byte[] name, int step_count) {
|
||||
this.id = id;
|
||||
this.seqn = seqn;
|
||||
this.key = key;
|
||||
this.name = name;
|
||||
this.step_count = step_count;
|
||||
}
|
||||
public int Id() {return id;} private final int id;
|
||||
public int Seqn() {return seqn;} private final int seqn;
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public byte[] Name() {return name;} private final byte[] name;
|
||||
public int Step_count() {return step_count;} private final int step_count;
|
||||
|
||||
public static final String Type__text = "text", Type__html = "html", Type__file = "file";
|
||||
public static final int Seqn__obsolete = 999999;
|
||||
}
|
||||
|
||||
@@ -13,86 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.tasks.*;
|
||||
public class Xobc_task_regy_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_task_id, fld_task_seqn, fld_step_count, fld_task_key, fld_task_name;
|
||||
private final Db_conn conn; private Db_stmt insert_stmt;
|
||||
public Xobc_task_regy_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "task_regy";
|
||||
this.fld_task_id = flds.Add_int_pkey("task_id");
|
||||
this.fld_task_seqn = flds.Add_int("task_seqn");
|
||||
this.fld_step_count = flds.Add_int("step_count");
|
||||
this.fld_task_key = flds.Add_str("task_key", 255);
|
||||
this.fld_task_name = flds.Add_str("task_name", 255);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {
|
||||
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));
|
||||
conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "task_seqn", fld_task_seqn));
|
||||
}
|
||||
public void Select_all(Xobc_task_regy__base todo_regy) {
|
||||
todo_regy.Clear();
|
||||
Db_rdr rdr = conn.Stmt_select_order(tbl_name, flds, String_.Ary_empty, fld_task_seqn).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
int task_seqn = rdr.Read_int(fld_task_seqn);
|
||||
if (task_seqn == Xobc_task_regy_itm.Seqn__obsolete) continue; // WORKAROUND: do not show old tasks; should add a status column, but don't want to change schema yet; DATE:2016-10-20
|
||||
|
||||
int task_id = rdr.Read_int(fld_task_id);
|
||||
int step_count = rdr.Read_int(fld_step_count);
|
||||
String task_key = rdr.Read_str(fld_task_key);
|
||||
String task_name = rdr.Read_str(fld_task_name);
|
||||
todo_regy.Add(new Xobc_task_itm(task_id, task_seqn, step_count, task_key, task_name));
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public int Select_by_key(String key) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_task_key).Exec_select__rls_auto();
|
||||
try {return rdr.Move_next() ? rdr.Read_int(fld_task_id) : -1;}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public String Select_key_by_id_or_null(int id) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_task_id).Crt_int(fld_task_id, id).Exec_select__rls_auto();
|
||||
try {return rdr.Move_next() ? rdr.Read_str(fld_task_key) : null;}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public void Insert(int task_id, int task_seqn, int step_count, String task_key, String task_name) {
|
||||
if (insert_stmt == null) insert_stmt = conn.Stmt_insert(tbl_name, flds);
|
||||
insert_stmt.Clear().Val_int(fld_task_id, task_id).Val_int(fld_task_seqn, task_seqn).Val_int(fld_step_count, step_count)
|
||||
.Val_str(fld_task_key, task_key).Val_str(fld_task_name, task_name)
|
||||
.Exec_insert();
|
||||
}
|
||||
public Xobc_task_regy_itm[] Select_by_wiki(byte[] wiki_domain) {
|
||||
String sql = Db_sql_.Make_by_fmt(String_.Ary
|
||||
( "SELECT *"
|
||||
, "FROM task_regy"
|
||||
, "WHERE task_key LIKE '{0}%'" // DEPENDENCY:Xobc_task_key
|
||||
, "AND task_seqn != 999999"
|
||||
), wiki_domain);
|
||||
List_adp list = List_adp_.New();
|
||||
Db_rdr rdr = conn.Stmt_sql(sql).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
list.Add(new Xobc_task_regy_itm
|
||||
( rdr.Read_int("task_id")
|
||||
, rdr.Read_int("task_seqn")
|
||||
, rdr.Read_bry_by_str("task_key")
|
||||
, rdr.Read_bry_by_str("task_name")
|
||||
, rdr.Read_int("step_count")
|
||||
));
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
return (Xobc_task_regy_itm[])list.To_ary_and_clear(Xobc_task_regy_itm.class);
|
||||
}
|
||||
public void Delete(int task_id) {
|
||||
conn.Stmt_delete(tbl_name, fld_task_id).Crt_int(fld_task_id, task_id).Exec_delete();
|
||||
}
|
||||
public void Rls() {
|
||||
insert_stmt = Db_stmt_.Rls(insert_stmt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,14 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
|
||||
public class Xobc_version_regy_itm {
|
||||
public Xobc_version_regy_itm(int id, String date, String note) {
|
||||
this.id = id;
|
||||
this.date = date;
|
||||
this.note = note;
|
||||
}
|
||||
public int Id() {return id;} private final int id;
|
||||
public String Date() {return date;} private final String date;
|
||||
public String Note() {return note;} private final String note;
|
||||
}
|
||||
|
||||
@@ -13,36 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.datas; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xobc_version_regy_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_version_id, fld_version_date, fld_version_note;
|
||||
private final Db_conn conn;
|
||||
public Xobc_version_regy_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "version_regy";
|
||||
this.fld_version_id = flds.Add_int_pkey("version_id");
|
||||
this.fld_version_date = flds.Add_str("version_date", 16);
|
||||
this.fld_version_note = flds.Add_str("version_note", 255);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {
|
||||
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));
|
||||
conn.Stmt_insert(tbl_name, flds)
|
||||
.Val_int(fld_version_id, 1).Val_str(fld_version_date, Datetime_now.Get().XtoStr_fmt_yyyy_MM_dd_HH_mm()).Val_str(fld_version_note, "initial")
|
||||
.Exec_insert();
|
||||
}
|
||||
public Xobc_version_regy_itm Select_latest() {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds).Exec_select__rls_auto();
|
||||
try {
|
||||
if (rdr.Move_next())
|
||||
return new Xobc_version_regy_itm(rdr.Read_int(fld_version_id), rdr.Read_str(fld_version_date), rdr.Read_str(fld_version_note));
|
||||
else
|
||||
throw Err_.new_("", "version_regy does not have version");
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public void Rls() {}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.datas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*;
|
||||
public class Xobc_import_date {
|
||||
public static String To_str__yyyy_mm(String raw, String dlm) {
|
||||
return String_.Mid(raw, 0, 4) + dlm + String_.Mid(raw, 4, 6);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,38 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.datas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xobc_import_step_itm {
|
||||
public Xobc_import_step_itm(int step_id, int host_id, byte[] wiki_abrv, String wiki_date
|
||||
, String import_name, int import_type, byte import_zip_type, long import_size_zip, long import_size_raw, String import_md5
|
||||
, long import_prog_data_max, int import_prog_row_max
|
||||
) {
|
||||
this.Step_id = step_id;
|
||||
this.Host_id = host_id;
|
||||
this.wiki_abrv = wiki_abrv;
|
||||
this.Wiki_date = wiki_date;
|
||||
this.Import_name = import_name;
|
||||
this.Import_type = import_type;
|
||||
this.Import_zip_type = import_zip_type;
|
||||
this.Import_size_zip = import_size_zip;
|
||||
this.Import_size_raw = import_size_raw;
|
||||
this.Import_md5 = import_md5;
|
||||
this.Import_prog_data_max = import_prog_data_max;
|
||||
this.Import_prog_row_max = import_prog_row_max;
|
||||
}
|
||||
public final int Step_id;
|
||||
public final int Host_id;
|
||||
public byte[] Wiki_abrv() {return wiki_abrv;} private final byte[] wiki_abrv;
|
||||
public final String Wiki_date;
|
||||
public final String Import_name;
|
||||
public final int Import_type;
|
||||
public final byte Import_zip_type;
|
||||
public final long Import_size_zip;
|
||||
public final long Import_size_raw;
|
||||
public final String Import_md5;
|
||||
public final long Import_prog_data_max;
|
||||
public final int Import_prog_row_max;
|
||||
|
||||
public static final Xobc_import_step_itm Null = null;
|
||||
}
|
||||
|
||||
@@ -13,106 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.datas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xobc_import_step_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_step_id, fld_host_id, fld_wiki_abrv, fld_wiki_date, fld_import_name, fld_import_type, fld_import_zip, fld_import_md5, fld_import_size_zip, fld_import_size_raw, fld_prog_size_end, fld_prog_count_end;
|
||||
public final Db_conn conn; private Db_stmt insert_stmt;
|
||||
public Xobc_import_step_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "import_step";
|
||||
this.fld_step_id = flds.Add_int_pkey("step_id");
|
||||
this.fld_host_id = flds.Add_int("host_id");
|
||||
this.fld_wiki_abrv = flds.Add_str("wiki_abrv", 255);
|
||||
this.fld_wiki_date = flds.Add_str("wiki_date", 8);
|
||||
this.fld_import_name = flds.Add_str("import_name", 255);
|
||||
this.fld_import_type = flds.Add_int("import_type");
|
||||
this.fld_import_zip = flds.Add_byte("import_zip");
|
||||
this.fld_import_size_zip = flds.Add_long("import_size_zip");
|
||||
this.fld_import_size_raw = flds.Add_long("import_size_raw");
|
||||
this.fld_import_md5 = flds.Add_str("import_md5", 48);
|
||||
this.fld_prog_size_end = flds.Add_long("prog_size_end");
|
||||
this.fld_prog_count_end = flds.Add_long("prog_count_end");
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public Xobc_import_step_itm Select_one(int step_id) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_step_id).Crt_int(fld_step_id, step_id).Exec_select__rls_auto();
|
||||
try {
|
||||
return (rdr.Move_next())
|
||||
? New_itm(rdr)
|
||||
: Xobc_import_step_itm.Null;
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public void Delete(int step_id) {
|
||||
conn.Stmt_delete(tbl_name, fld_step_id).Crt_int(fld_step_id, step_id).Exec_delete();
|
||||
}
|
||||
public void Insert(int step_id, int host_id, byte[] wiki_abrv, String wiki_date, String import_name, int import_type, byte zip_type, byte[] md5, long size_zip, long size_raw
|
||||
, long prog_size_end, int prog_count_end) {
|
||||
if (insert_stmt == null) insert_stmt = conn.Stmt_insert(tbl_name, flds);
|
||||
insert_stmt.Clear().Val_int(fld_step_id, step_id).Val_int(fld_host_id, host_id)
|
||||
.Val_bry_as_str(fld_wiki_abrv, wiki_abrv).Val_str(fld_wiki_date, wiki_date)
|
||||
.Val_str(fld_import_name, import_name)
|
||||
.Val_int(fld_import_type, import_type).Val_byte(fld_import_zip, zip_type)
|
||||
.Val_long(fld_import_size_zip, size_zip).Val_long(fld_import_size_raw, size_raw).Val_bry_as_str(fld_import_md5, md5)
|
||||
.Val_long(fld_prog_size_end, prog_size_end).Val_int(fld_prog_count_end, prog_count_end)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Select_tasks_steps(Xobc_task_step_hash task_step_hash, Xobc_step_map_tbl step_map_tbl, byte[] wiki_abrv, String wiki_date) {
|
||||
task_step_hash.Clear();
|
||||
Db_rdr rdr = conn.Stmt_sql(String_.Concat_lines_nl_skip_last
|
||||
( "SELECT DISTINCT sm.task_id, sm.step_id"
|
||||
, "FROM " + tbl_name + " imps"
|
||||
, " JOIN " + step_map_tbl.Tbl_name() + " sm ON sm.step_id = imps.step_id"
|
||||
, "WHERE imps.wiki_abrv = ?"
|
||||
, "AND imps.wiki_date = ?"
|
||||
))
|
||||
.Crt_bry_as_str(fld_wiki_abrv, wiki_abrv)
|
||||
.Crt_str(fld_wiki_date, wiki_date)
|
||||
.Exec_select__rls_auto()
|
||||
;
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
task_step_hash.Add(rdr.Read_int("task_id"), rdr.Read_int("step_id"));
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public Xobc_import_step_itm[] Select_by_task_id(int task_id) {
|
||||
List_adp list = List_adp_.New();
|
||||
Db_rdr rdr = conn.Stmt_sql(Db_sql_.Make_by_fmt(String_.Ary
|
||||
( "SELECT s.*"
|
||||
, "FROM import_step s"
|
||||
, " JOIN step_map sm ON s.step_id = sm.step_id"
|
||||
, "WHERE sm.task_id = {0}"
|
||||
), task_id))
|
||||
.Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
list.Add(New_itm(rdr));
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
return (Xobc_import_step_itm[])list.To_ary_and_clear(Xobc_import_step_itm.class);
|
||||
}
|
||||
public void Rls() {
|
||||
insert_stmt = Db_stmt_.Rls(insert_stmt);
|
||||
}
|
||||
private Xobc_import_step_itm New_itm(Db_rdr rdr) {
|
||||
return new Xobc_import_step_itm
|
||||
( rdr.Read_int(fld_step_id)
|
||||
, rdr.Read_int(fld_host_id)
|
||||
, rdr.Read_bry_by_str(fld_wiki_abrv)
|
||||
, rdr.Read_str(fld_wiki_date)
|
||||
, rdr.Read_str(fld_import_name)
|
||||
, rdr.Read_int(fld_import_type)
|
||||
, rdr.Read_byte(fld_import_zip)
|
||||
, rdr.Read_long(fld_import_size_zip)
|
||||
, rdr.Read_long(fld_import_size_raw)
|
||||
, rdr.Read_str(fld_import_md5)
|
||||
, rdr.Read_long(fld_prog_size_end)
|
||||
, rdr.Read_int(fld_prog_count_end)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,21 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.datas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*;
|
||||
public class Xobc_import_type {
|
||||
public static final int // SERIALIZED: bc_db; import_step
|
||||
Tid__ignore = 0
|
||||
, Tid__pack = 1
|
||||
, Tid__wiki__core = 2
|
||||
, Tid__wiki__srch = 3
|
||||
, Tid__wiki__html = 4
|
||||
, Tid__wiki__text = 5
|
||||
, Tid__file__core = 6
|
||||
, Tid__file__data = 7
|
||||
, Tid__fsdb__delete = 8
|
||||
, Tid__wiki__ctg = 9
|
||||
, Tid__misc = 10
|
||||
, Tid__wiki__wbase = 11
|
||||
, Tid__wiki__lucene = 12
|
||||
;
|
||||
}
|
||||
|
||||
@@ -13,13 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.datas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*;
|
||||
public class Xobc_zip_type {
|
||||
public static String To_str(byte type) {
|
||||
switch (type) {
|
||||
case Type__zip: return "zip";
|
||||
default: throw Err_.new_unhandled_default(type);
|
||||
}
|
||||
}
|
||||
public static final byte Type__zip = 1; // SERIALIZED
|
||||
}
|
||||
|
||||
@@ -13,41 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.users; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.tasks.*;
|
||||
public class Xobc_done_step_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_task_id, fld_step_id;
|
||||
private final Db_conn conn;
|
||||
public Xobc_done_step_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "xobc_done_step";
|
||||
this.fld_task_id = flds.Add_int("task_id");
|
||||
this.fld_step_id = flds.Add_int("step_id");
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {
|
||||
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));
|
||||
conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "main", fld_task_id, fld_step_id));
|
||||
}
|
||||
public void Insert(int task_id, int step_id) {
|
||||
conn.Stmt_insert(tbl_name, fld_task_id, fld_step_id)
|
||||
.Val_int(fld_task_id, task_id).Val_int(fld_step_id, step_id)
|
||||
.Exec_insert();
|
||||
}
|
||||
public Hash_adp Select_all(int task_id) {
|
||||
Hash_adp rv = null;
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, String_.Ary(fld_step_id), fld_task_id).Crt_int(fld_task_id, task_id).Exec_select__rls_auto();
|
||||
try {
|
||||
if (rdr.Move_next()) {
|
||||
if (rv == null) rv = Hash_adp_.New();
|
||||
rv.Add_as_key_and_val(rdr.Read_int("step_id"));
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
return null;
|
||||
}
|
||||
public void Rls() {}
|
||||
}
|
||||
|
||||
@@ -13,50 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.users; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.tasks.*;
|
||||
public class Xobc_done_task_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_task_id, fld_task_seqn;
|
||||
private final Db_conn conn;
|
||||
public Xobc_done_task_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "xobc_done_task";
|
||||
this.fld_task_id = flds.Add_int_pkey("task_id");
|
||||
this.fld_task_seqn = flds.Add_int("task_seqn");
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Insert(int task_id, int task_seqn) {
|
||||
conn.Stmt_insert(tbl_name, fld_task_id, fld_task_seqn)
|
||||
.Val_int(fld_task_id, task_id).Val_int(fld_task_seqn, task_seqn)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Delete(int task_id) {
|
||||
conn.Stmt_delete(tbl_name, fld_task_id)
|
||||
.Crt_int(fld_task_id, task_id)
|
||||
.Exec_delete();
|
||||
}
|
||||
public void Select_all(Xobc_task_regy__base todo_regy, Xobc_task_regy__base done_regy) {
|
||||
done_regy.Clear();
|
||||
Db_rdr rdr = conn.Stmt_select_all(tbl_name, flds).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
int task_id = rdr.Read_int(fld_task_id);
|
||||
int task_seqn = rdr.Read_int(fld_task_seqn);
|
||||
if (task_seqn == gplx.xowa.addons.bldrs.centrals.dbs.datas.Xobc_task_regy_itm.Seqn__obsolete) continue; // WORKAROUND: do not show old tasks; should add a status column, but don't want to change schema yet; DATE:2016-11-03
|
||||
Xobc_task_itm itm = (Xobc_task_itm)todo_regy.Get_by(task_id);
|
||||
if (itm == null) {
|
||||
Gfo_log_.Instance.Warn("task exists in done, but not in todo", "task_id", task_id);
|
||||
continue;
|
||||
}
|
||||
done_regy.Add(itm);
|
||||
todo_regy.Del_by(task_id);
|
||||
itm.Task_seqn_(task_seqn);
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public void Rls() {}
|
||||
}
|
||||
|
||||
@@ -13,59 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.dbs.users; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.tasks.*;
|
||||
public class Xobc_work_task_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_task_id, fld_task_seqn, fld_step_id, fld_cmd_id;
|
||||
private final Db_conn conn;
|
||||
public Xobc_work_task_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "xobc_work_task";
|
||||
this.fld_task_id = flds.Add_int_pkey("task_id");
|
||||
this.fld_task_seqn = flds.Add_int("task_seqn");
|
||||
this.fld_step_id = flds.Add_int("step_id");
|
||||
this.fld_cmd_id = flds.Add_int("cmd_id");
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Select_all(Xobc_task_mgr task_mgr, Xobc_task_regy__base todo_regy, Xobc_task_regy__base work_regy) {
|
||||
work_regy.Clear();
|
||||
Db_rdr rdr = conn.Stmt_select_all(tbl_name, flds).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
int task_id = rdr.Read_int(fld_task_id);
|
||||
int task_seqn = rdr.Read_int(fld_task_seqn);
|
||||
int step_id = rdr.Read_int(fld_step_id);
|
||||
int cmd_id = rdr.Read_int(fld_cmd_id);
|
||||
Xobc_task_itm task = (Xobc_task_itm)todo_regy.Get_by(task_id);
|
||||
if (task == null) {
|
||||
Gfo_log_.Instance.Warn("task exists in work, but not in todo", "task_id", task_id);
|
||||
continue;
|
||||
}
|
||||
work_regy.Add(task);
|
||||
todo_regy.Del_by(task_id);
|
||||
task.Task_seqn_(task_seqn);
|
||||
task.Task_status_(cmd_id == Xobc_cmd__base.Seqn__0 ? gplx.core.progs.Gfo_prog_ui_.Status__init : gplx.core.progs.Gfo_prog_ui_.Status__working);
|
||||
task_mgr.Step_mgr().Load(task, step_id, cmd_id);
|
||||
}
|
||||
work_regy.Sort();
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public void Insert(int task_id, int task_seqn, int step_id, int cmd_id) {
|
||||
conn.Stmt_insert(tbl_name, fld_task_id, fld_task_seqn, fld_step_id, fld_cmd_id)
|
||||
.Val_int(fld_task_id, task_id).Val_int(fld_task_seqn, task_seqn).Val_int(fld_step_id, step_id).Val_int(fld_cmd_id, cmd_id)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Update(int task_id, int task_seqn, int step_id, int cmd_id) {
|
||||
conn.Stmt_update_exclude(tbl_name, flds, fld_task_id)
|
||||
.Val_int(fld_task_seqn, task_seqn).Val_int(fld_step_id, step_id).Val_int(fld_cmd_id, cmd_id).Crt_int(fld_task_id, task_id)
|
||||
.Exec_update();
|
||||
}
|
||||
public void Delete(int task_id) {
|
||||
conn.Stmt_delete(tbl_name, fld_task_id).Val_int(fld_task_id, task_id).Exec_insert();
|
||||
}
|
||||
public void Rls() {}
|
||||
}
|
||||
|
||||
@@ -13,32 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.hosts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*;
|
||||
import gplx.core.brys.evals.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Host_eval_itm {
|
||||
private final Bry_eval_mgr mgr = Bry_eval_mgr.Dflt();
|
||||
private final Host_eval_wkr wkr = new Host_eval_wkr();
|
||||
private final Hash_adp host_hash = Hash_adp_.New();
|
||||
public Host_eval_itm() {
|
||||
mgr.Add_many(wkr);
|
||||
}
|
||||
public byte[] Eval_dir_name(Xow_domain_itm domain_itm) {
|
||||
wkr.Domain_itm_(domain_itm);
|
||||
return mgr.Eval(Bry_.new_u8("Xowa_~{host_regy|wiki_abrv}_latest"));
|
||||
}
|
||||
public String Eval_src_fil(Xobc_data_db data_db, int host_id, Xow_domain_itm domain, String file_name) {
|
||||
return Eval_src_dir(data_db, host_id, domain) + file_name;
|
||||
}
|
||||
public String Eval_src_dir(Xobc_data_db data_db, int host_id, Xow_domain_itm domain) {
|
||||
Xobc_host_regy_itm host_itm = (Xobc_host_regy_itm)host_hash.Get_by(host_id);
|
||||
if (host_itm == null) {
|
||||
host_itm = data_db.Tbl__host_regy().Select(host_id);
|
||||
host_hash.Add(host_id, host_itm);
|
||||
}
|
||||
wkr.Domain_itm_(domain);
|
||||
String host_dir = String_.new_u8(mgr.Eval(Bry_.new_u8(host_itm.Host_data_dir())));
|
||||
return String_.Format("http://{0}/{1}/", host_itm.Host_domain(), host_dir);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,37 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.hosts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.brys.evals.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Host_eval_wkr implements Bry_eval_wkr {
|
||||
private Xow_domain_itm domain_itm;
|
||||
public String Key() {return "host_regy";}
|
||||
public Host_eval_wkr Domain_itm_(Xow_domain_itm domain_itm) {this.domain_itm = domain_itm; return this;}
|
||||
public void Resolve(Bry_bfr rv, byte[] src, int args_bgn, int args_end) {
|
||||
// EX: "~{host_regy|wiki_abrv}" -> "enwiki"
|
||||
int type = hash.Get_as_byte_or(src, args_bgn, args_end, Byte_.Max_value_127);
|
||||
switch (type) {
|
||||
case Type__wiki_abrv:
|
||||
// handle wikidata, commonswiki separately; DATE:2016-10-20
|
||||
if (String_.Eq(domain_itm.Domain_str(), "www.wikidata.org"))
|
||||
rv.Add_str_a7("wikidatawiki");
|
||||
else if (String_.Eq(domain_itm.Domain_str(), "commons.wikimedia.org"))
|
||||
rv.Add_str_a7("commonswiki");
|
||||
// do not use Abrv_mw(); all other wikis will be "generalized" to their language url; EX:"en.wiktionary.org" -> "enwiki" x> "enwiktionary"
|
||||
else {
|
||||
byte[] lang_key = domain_itm.Lang_orig_key();
|
||||
if (lang_key == Bry_.Empty) lang_key = Bry_.new_a7("en"); // handle species
|
||||
rv.Add(lang_key);
|
||||
rv.Add_str_a7("wiki");
|
||||
}
|
||||
break;
|
||||
default: throw Err_.new_unhandled_default(type);
|
||||
}
|
||||
}
|
||||
|
||||
public static final byte Type__wiki_abrv = 0;
|
||||
private static final Hash_adp_bry hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("wiki_abrv", Type__wiki_abrv)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -13,18 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.hosts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.wikis.domains.*;
|
||||
public class Host_eval_wkr__tst {
|
||||
private final Host_eval_wkr__fxt fxt = new Host_eval_wkr__fxt();
|
||||
@Test public void En_w() {fxt.Test__resolve_quick("en.wikipedia.org" , "Xowa_enwiki_latest");}
|
||||
@Test public void Fr_d() {fxt.Test__resolve_quick("fr.wiktionary.org" , "Xowa_frwiki_latest");}
|
||||
@Test public void Species() {fxt.Test__resolve_quick("species.wikimedia.org" , "Xowa_enwiki_latest");}
|
||||
}
|
||||
class Host_eval_wkr__fxt {
|
||||
public void Test__resolve_quick(String domain_str, String expd) {
|
||||
Host_eval_itm eval_itm = new Host_eval_itm();
|
||||
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(Bry_.new_u8(domain_str));
|
||||
Gftest.Eq__bry(Bry_.new_u8(expd), eval_itm.Eval_dir_name(domain_itm));
|
||||
}
|
||||
}
|
||||
@@ -13,38 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.mgrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.gfobjs.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.tasks.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xobc_filter_mgr {
|
||||
private String lang_key_str = Xow_domain_itm_.Lang_key__all, type_key_str = Xow_domain_itm_.Type_key__all;
|
||||
public Xobc_task_itm[] Filter(Xobc_task_regy__base task_list) {return Filter(task_list, lang_key_str, type_key_str);}
|
||||
public Xobc_task_itm[] Filter(Xobc_task_regy__base task_list, String lang_key_str, String type_key_str) {
|
||||
this.lang_key_str = lang_key_str;
|
||||
this.type_key_str = type_key_str;
|
||||
|
||||
List_adp tmp = List_adp_.New();
|
||||
|
||||
// loop tasks and find matches
|
||||
int len = task_list.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xobc_task_itm task = (Xobc_task_itm)task_list.Get_at(i);
|
||||
Xobc_task_key task_key_itm = Xobc_task_key.To_itm(task.Task_key());
|
||||
Xow_domain_itm task_domain = task_key_itm.Wiki_domain_itm();
|
||||
if ( Xow_domain_itm_.Match_lang(task_domain, lang_key_str)
|
||||
&& Xow_domain_itm_.Match_type(task_domain, type_key_str)
|
||||
)
|
||||
tmp.Add(task);
|
||||
}
|
||||
|
||||
return (Xobc_task_itm[])tmp.To_ary_and_clear(Xobc_task_itm.class);
|
||||
}
|
||||
public Gfobj_nde Make_init_msg() {
|
||||
Gfobj_nde root = Gfobj_nde.New();
|
||||
root.New_nde("langs").Add_str("active", lang_key_str);
|
||||
root.New_nde("types").Add_str("active", type_key_str);
|
||||
return root;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,20 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.mgrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.gfobjs.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.dbs.datas.*;
|
||||
public class Xobc_lang_mgr {
|
||||
public Gfobj_ary Make_init_msg(Xobc_lang_regy_itm[] itms) {
|
||||
List_adp list = List_adp_.New();
|
||||
int len = itms.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xobc_lang_regy_itm itm = itms[i];
|
||||
Gfobj_nde itm_nde = Gfobj_nde.New();
|
||||
list.Add(itm_nde);
|
||||
itm_nde.Add_str("key", itm.Key());
|
||||
itm_nde.Add_str("name", itm.Name());
|
||||
}
|
||||
return new Gfobj_ary((Gfobj_nde[])list.To_ary_and_clear(Gfobj_nde.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,25 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.mgrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.dbs.datas.imports.*;
|
||||
public class Xobc_skip_mgr implements Gfo_invk {
|
||||
private boolean category_enabled;
|
||||
public Xobc_skip_mgr(Xobc_task_mgr task_mgr, Xoa_app app) {
|
||||
app.Cfg().Bind_many_app(this, Cfg__namespaces_category);
|
||||
}
|
||||
public boolean Should_skip(Xobc_import_step_itm step_itm) {
|
||||
if (category_enabled && step_itm.Import_type == Xobc_import_type.Tid__wiki__ctg)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Cfg__namespaces_category)) category_enabled = m.ReadBool("v");
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String
|
||||
Cfg__namespaces_category = "xowa.bldr.download_central.namespaces.category"
|
||||
;
|
||||
}
|
||||
|
||||
@@ -13,77 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.steps; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.brys.evals.*; import gplx.core.primitives.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.tasks.*; import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.steps.*; import gplx.xowa.addons.bldrs.centrals.utils.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.imports.*; import gplx.xowa.addons.bldrs.centrals.hosts.*;
|
||||
import gplx.xowa.addons.bldrs.exports.merges.*;
|
||||
import gplx.xowa.addons.bldrs.updates.files.*;
|
||||
import gplx.xowa.addons.bldrs.exports.packs.files.*;
|
||||
import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xobc_step_factory {
|
||||
private final Xobc_task_mgr task_mgr;
|
||||
private final Xobc_data_db data_db;
|
||||
private final Bry_eval_mgr eval_mgr = Bry_eval_mgr.Dflt(); private final Host_eval_itm host_eval = new Host_eval_itm();
|
||||
private final Host_eval_wkr eval_wkr__host_regy = new Host_eval_wkr();
|
||||
public Xobc_step_factory(Xobc_task_mgr task_mgr, Xobc_data_db data_db, Io_url wiki_dir) {
|
||||
this.task_mgr = task_mgr;
|
||||
this.data_db = data_db;
|
||||
eval_mgr.Add_many(new Bry_eval_wkr__builder_central(wiki_dir));
|
||||
}
|
||||
public void Load(Xobc_task_itm task, int step_id, int cmd_idx) {
|
||||
int step_type = data_db.Tbl__step_regy().Select_type(step_id);
|
||||
switch (step_type) {
|
||||
case Xobc_step_itm.Type__wiki_import: Load_wiki_import(task, step_id, cmd_idx); break;
|
||||
default: throw Err_.new_unhandled_default(step_type);
|
||||
}
|
||||
}
|
||||
private void Load_wiki_import(Xobc_task_itm task, int step_id, int cmd_idx) {
|
||||
int step_seqn = data_db.Tbl__step_map().Select_one(task.Task_id(), step_id).Step_seqn;
|
||||
Xobc_import_step_itm import_itm = data_db.Tbl__import_step().Select_one(step_id); String_obj_ref step_name = String_obj_ref.empty_();
|
||||
Xobc_cmd_itm[] cmds = Make_wiki_import_cmds(import_itm, task.Task_id(), step_id, step_name, step_seqn);
|
||||
Xobc_step_itm step = new Xobc_step_itm(step_id, step_seqn, cmds).Cmd_idx_(cmd_idx);
|
||||
step.Step_name_(String_.Format("{0} ·({1}/{2})", step_name.Val(), step_seqn + List_adp_.Base1, task.Step_count()));
|
||||
task.Step_(step);
|
||||
step.Cmd().Load_checkpoint();
|
||||
if (step.Cmd().Prog_status() == gplx.core.progs.Gfo_prog_ui_.Status__suspended)
|
||||
task.Task_status_(step.Cmd().Prog_status());
|
||||
}
|
||||
private Xobc_cmd_itm[] Make_wiki_import_cmds(Xobc_import_step_itm import_itm, int task_id, int step_id, String_obj_ref step_name, int step_seqn) {
|
||||
List_adp list = List_adp_.New();
|
||||
Xow_domain_itm domain_itm = Xow_abrv_xo_.To_itm(import_itm.Wiki_abrv());
|
||||
String wiki_domain = domain_itm.Domain_str();
|
||||
String file_name = import_itm.Import_name;
|
||||
step_name.Val_(file_name);
|
||||
eval_wkr__host_regy.Domain_itm_(domain_itm);
|
||||
String src_http_url = host_eval.Eval_src_fil(data_db, import_itm.Host_id, domain_itm, file_name);
|
||||
Io_url zip_file_url = Eval_url(Bry_eval_wkr__builder_central.Make_str(Bry_eval_wkr__builder_central.Type__download_fil, wiki_domain, file_name));
|
||||
Io_url unzip_dir_url = Eval_url(Bry_eval_wkr__builder_central.Make_str(Bry_eval_wkr__builder_central.Type__unzip_dir, wiki_domain, file_name));
|
||||
Io_url wiki_dir_url = Eval_url(Bry_eval_wkr__builder_central.Make_str(Bry_eval_wkr__builder_central.Type__wiki_dir, wiki_domain, file_name));
|
||||
|
||||
// if lucene, move to /data/search/
|
||||
if (import_itm.Import_type == Xobc_import_type.Tid__wiki__lucene) {
|
||||
wiki_dir_url = gplx.xowa.addons.wikis.fulltexts.Xosearch_fulltext_addon.Get_index_dir(wiki_dir_url);
|
||||
}
|
||||
|
||||
Io_url checksum_url = unzip_dir_url.GenSubFil(file_name + ".md5");
|
||||
int cmd_idx = 0;
|
||||
list.Add(new Xobc_cmd__download (task_mgr, task_id, step_id, cmd_idx++, src_http_url, zip_file_url, import_itm.Import_size_zip));
|
||||
list.Add(new Xobc_cmd__verify_fil (task_mgr, task_id, step_id, cmd_idx++, zip_file_url, import_itm.Import_md5, import_itm.Import_size_zip));
|
||||
list.Add(new Xobc_cmd__unzip (task_mgr, task_id, step_id, cmd_idx++, zip_file_url, unzip_dir_url, import_itm.Import_size_raw));
|
||||
list.Add(new Xobc_cmd__verify_dir (task_mgr, task_id, step_id, cmd_idx++, checksum_url, zip_file_url));
|
||||
// list.Add(new Xobc_cmd__wiki_merge (task_mgr, task_id, step_id, cmd_idx++, merge_mgr, wiki_domain, unzip_dir_url, import_itm.Import_prog_data_max, import_itm.Import_prog_row_max, step_seqn));
|
||||
list.Add(new Xobc_cmd__move_fils (task_mgr, task_id, step_id, cmd_idx++, unzip_dir_url, wiki_dir_url));
|
||||
switch (import_itm.Import_type) {
|
||||
case Xobc_import_type.Tid__wiki__core: list.Add(new Xobc_cmd__wiki_reg (task_mgr, task_id, step_id, cmd_idx++, wiki_dir_url, wiki_domain)); break;
|
||||
case Xobc_import_type.Tid__fsdb__delete: list.Add(new Xobc_cmd__fsdb_delete (task_mgr, task_id, step_id, cmd_idx++, Pack_zip_name_bldr.To_wiki_url(wiki_dir_url, zip_file_url.OwnerDir()))); break;
|
||||
}
|
||||
return (Xobc_cmd_itm[])list.To_ary_and_clear(Xobc_cmd_itm.class);
|
||||
}
|
||||
private Io_url Eval_url(String src) {return Io_url_.new_any_(String_.new_u8(eval_mgr.Eval(Bry_.new_u8(src))));}
|
||||
public static Xow_wiki Get_wiki_by_abrv(Xoa_app app, byte[] wiki_abrv) {
|
||||
Xow_domain_itm domain_itm = Xow_abrv_xo_.To_itm(wiki_abrv);
|
||||
return app.Wiki_mgri().Get_by_or_make_init_y(domain_itm.Domain_bry());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,49 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.steps; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.gfobjs.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.cmds.*;
|
||||
public class Xobc_step_itm {
|
||||
private int cmd_idx = 0;
|
||||
private final Xobc_cmd_itm[] cmds;
|
||||
public Xobc_step_itm(int step_id, int step_seqn, Xobc_cmd_itm[] cmds) {
|
||||
this.step_id = step_id; this.step_seqn = step_seqn; this.cmds = cmds;
|
||||
}
|
||||
public int Step_id() {return step_id;} private final int step_id;
|
||||
public int Step_seqn() {return step_seqn;} private final int step_seqn;
|
||||
public String Step_name() {return step_name;} private String step_name;
|
||||
public Xobc_cmd_itm Cmd() {return cmds[cmd_idx];}
|
||||
public Xobc_step_itm Cmd_idx_(int v) {cmd_idx = v; return this;}
|
||||
public void Cmd_idx_next_() {++cmd_idx;}
|
||||
public boolean Cmd_is_last() {return cmd_idx == cmds.length - 1;}
|
||||
public Xobc_cmd_itm Step_fallback_to(String fallback_id) {
|
||||
int fallback_idx = 0;
|
||||
int len = cmds.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xobc_cmd_itm cmd = cmds[i];
|
||||
if (String_.Eq(cmd.Cmd_type(), fallback_id)) {
|
||||
fallback_idx = cmd.Cmd_id();
|
||||
break;
|
||||
}
|
||||
}
|
||||
cmd_idx = fallback_idx;
|
||||
return Cmd();
|
||||
}
|
||||
public void Step_name_(String v) {this.step_name = v;}
|
||||
public void Step_cleanup() {
|
||||
int len = cmds.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
cmds[i].Cmd_cleanup();
|
||||
}
|
||||
}
|
||||
public Gfobj_nde Save_to(Gfobj_nde nde) {
|
||||
nde.Add_int ("step_id", step_id);
|
||||
nde.Add_str ("step_name", step_name);
|
||||
this.Cmd().Save_to(nde.New_nde("cmd"));
|
||||
return nde; // fluent
|
||||
}
|
||||
|
||||
public static final int Type__wiki_import = 1;
|
||||
public static final int Seqn__0 = 0;
|
||||
}
|
||||
|
||||
@@ -13,39 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.tasks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.gfobjs.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.steps.*;
|
||||
public class Xobc_task_itm implements gplx.CompareAble {
|
||||
private final int task_sort;
|
||||
public Xobc_task_itm(int task_id, int task_seqn, int step_count, String task_key, String task_name) {
|
||||
this.task_id = task_id;
|
||||
this.task_seqn = task_seqn;
|
||||
this.step_count = step_count;
|
||||
this.task_key = task_key;
|
||||
this.task_name = task_name;
|
||||
this.task_sort = task_seqn; // set task_sort to task_seqn; note that task_sort needs to be memorialized b/c "work" changes task_seqn to add-order
|
||||
}
|
||||
public int Task_id() {return task_id;} private final int task_id;
|
||||
public String Task_key() {return task_key;} private final String task_key;
|
||||
public String Task_name() {return task_name;} private final String task_name;
|
||||
public int Step_count() {return step_count;} private final int step_count;
|
||||
public int Task_seqn() {return task_seqn;} private int task_seqn;
|
||||
public byte Task_status() {return task_status;} private byte task_status;
|
||||
public Xobc_step_itm Step() {return step;} public void Step_(Xobc_step_itm v) {this.step = v;} private Xobc_step_itm step;
|
||||
public boolean Step_is_last() {return step.Step_seqn() == step_count - 1;}
|
||||
public void Task_status_(byte v) {task_status = v;} // called when task moves from init -> working -> suspended -> done
|
||||
public void Task_seqn_(int v) {this.task_seqn = v;} // called when task is init'd from db, or added to list
|
||||
public int compareTo(Object obj) {Xobc_task_itm comp = (Xobc_task_itm)obj; return Int_.Compare(task_seqn, comp.task_seqn);}
|
||||
|
||||
public Gfobj_nde Save_to(Gfobj_nde nde) {
|
||||
nde.Add_int ("task_id" , task_id);
|
||||
nde.Add_str ("task_name" , task_name);
|
||||
nde.Add_byte("task_status" , task_status);
|
||||
nde.Add_int ("task_sort" , task_sort);
|
||||
if (step != null) {
|
||||
step.Save_to(nde.New_nde("step"));
|
||||
}
|
||||
return nde; // FLUENT
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,32 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.tasks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xobc_task_key {
|
||||
public Xobc_task_key(String wiki_domain, String wiki_date, String task_type) {
|
||||
this.wiki_domain = wiki_domain;
|
||||
this.wiki_date = wiki_date;
|
||||
this.task_type = task_type;
|
||||
}
|
||||
public String Wiki_domain() {return wiki_domain;} private final String wiki_domain;
|
||||
public String Wiki_date() {return wiki_date;} private final String wiki_date;
|
||||
public String Wiki_date_ui() {return String_.Replace(wiki_date, ".", "-");}
|
||||
public String Task_type() {return task_type;} private final String task_type;
|
||||
public String Task_type_ui() {
|
||||
if (String_.Eq(task_type, "html")) return "Articles";
|
||||
else if (String_.Eq(task_type, "file")) return "Images";
|
||||
else if (String_.Eq(task_type, "text")) return "Source";
|
||||
else if (String_.Eq(task_type, "patch")) return "Patch";
|
||||
else return task_type;
|
||||
}
|
||||
public Xow_domain_itm Wiki_domain_itm() {return Xow_domain_itm_.parse(Bry_.new_u8(wiki_domain));}
|
||||
|
||||
public static Xobc_task_key To_itm(String task_key) {
|
||||
String[] ary = String_.Split(task_key, "|");
|
||||
return new Xobc_task_key(ary[0], ary[1], ary[2]);
|
||||
}
|
||||
public static String To_str(String wiki_domain, String wiki_date, String task_type) {
|
||||
return String_.Concat(wiki_domain, "|", wiki_date, "|", task_type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,29 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.tasks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.gfobjs.*;
|
||||
public abstract class Xobc_task_regy__base {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
protected final Xobc_task_mgr task_mgr;
|
||||
public Xobc_task_regy__base(Xobc_task_mgr task_mgr, String name) {this.task_mgr = task_mgr; this.name = name;}
|
||||
public String Name() {return name;} private final String name;
|
||||
public int Len() {return hash.Len();}
|
||||
public void Add(Xobc_task_itm t) {hash.Add(t.Task_id(), t);}
|
||||
public void Clear() {hash.Clear();}
|
||||
public Xobc_task_itm Get_at(int i) {return (Xobc_task_itm)hash.Get_at(i);}
|
||||
public Xobc_task_itm Get_by(int i) {return (Xobc_task_itm)hash.Get_by(i);}
|
||||
public void Del_by(int i) {hash.Del(i);}
|
||||
public void Sort() {hash.Sort();}
|
||||
|
||||
public void Save_to(Gfobj_ary ary) {Save_to(ary, (Xobc_task_itm[])hash.To_ary(Xobc_task_itm.class));}
|
||||
public void Save_to(Gfobj_ary ary, Xobc_task_itm[] itms) {
|
||||
int len = itms.length;
|
||||
Gfobj_nde[] sub_ndes = new Gfobj_nde[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Gfobj_nde sub_nde = sub_ndes[i] = Gfobj_nde.New();
|
||||
itms[i].Save_to(sub_nde);
|
||||
}
|
||||
ary.Ary_(sub_ndes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.tasks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
public class Xobc_task_regy__done extends Xobc_task_regy__base {
|
||||
public Xobc_task_regy__done(Xobc_task_mgr task_mgr) {super(task_mgr, "done");}
|
||||
public void Del_done(int task_id) {
|
||||
task_mgr.User_db().Done_task_tbl().Delete(task_id);
|
||||
task_mgr.Transfer(this, task_mgr.Todo_mgr(), this.Get_by(task_id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,34 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.tasks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.gfobjs.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.steps.*; import gplx.xowa.addons.bldrs.centrals.dbs.*;
|
||||
public class Xobc_task_regy__todo extends Xobc_task_regy__base {
|
||||
public Xobc_task_regy__todo(Xobc_task_mgr task_mgr) {super(task_mgr, "todo");}
|
||||
public void Add_work(int task_id) {
|
||||
Xobc_user_db user_db = task_mgr.User_db();
|
||||
Xobc_task_itm task = task_mgr.Todo_mgr().Get_by(task_id);
|
||||
task.Task_status_(gplx.core.progs.Gfo_prog_ui_.Status__init);
|
||||
task.Task_seqn_(task_mgr.Work_mgr().Len());
|
||||
|
||||
// get step_id; default is 1st step with seqn=0, but skip any steps that have already been downloaded; handles user accidentally removing item from work;
|
||||
int step_seqn = Xobc_step_itm.Seqn__0;
|
||||
Hash_adp done_steps = user_db.Done_step_tbl().Select_all(task_id);
|
||||
if (done_steps != null)
|
||||
step_seqn = task_mgr.Data_db().Tbl__step_map().Select_seqn_but_skip_done(task_id, done_steps);
|
||||
int step_id = task_mgr.Data_db().Tbl__step_map().Select_step_id(task_id, step_seqn);
|
||||
|
||||
// load task, cur_step, and all cmds
|
||||
task_mgr.Step_mgr().Load(task, step_id, Xobc_cmd__base.Seqn__0);
|
||||
|
||||
// do transfer
|
||||
user_db.Work_task_tbl().Insert(task_id, task.Task_seqn(), step_id, Xobc_cmd__base.Seqn__0);
|
||||
task_mgr.Transfer(this, task_mgr.Work_mgr(), task);
|
||||
}
|
||||
public void Del_todo(int task_id) {
|
||||
Xobc_task_itm task = this.Get_by(task_id);
|
||||
task_mgr.User_db().Done_task_tbl().Insert(task_id, task.Task_seqn());
|
||||
task_mgr.Transfer(this, task_mgr.Done_mgr(), task);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,149 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.tasks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.gfobjs.*; import gplx.core.progs.*; import gplx.core.threads.*;
|
||||
import gplx.xowa.drds.powers.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.steps.*; import gplx.xowa.addons.bldrs.centrals.cmds.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.dbs.datas.imports.*;
|
||||
public class Xobc_task_regy__work extends Xobc_task_regy__base {
|
||||
private final Thread_adp_mgr thread_mgr = new Thread_adp_mgr(1000, 5000);
|
||||
private final Xobc_cmd_ctx ctx;
|
||||
public Xobc_task_regy__work(Xobc_task_mgr task_mgr, Xoa_app app) {super(task_mgr, "work");
|
||||
this.ctx = new Xobc_cmd_ctx(app);
|
||||
}
|
||||
public void Del_work(int task_id) {
|
||||
Xobc_task_itm task = this.Get_by(task_id);
|
||||
if (task.Step() != null) task.Step().Step_cleanup();
|
||||
this.Del_task(task, task_mgr.Todo_mgr());
|
||||
}
|
||||
private void Del_task(Xobc_task_itm task, Xobc_task_regy__base trg) {
|
||||
task_mgr.User_db().Work_task_tbl().Delete(task.Task_id());
|
||||
task_mgr.Transfer(this, trg, task);
|
||||
}
|
||||
public void Run_next() {
|
||||
Xod_power_mgr_.Instance.Wake_lock__get("task_mgr");
|
||||
int len = this.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xobc_task_itm task = this.Get_at(i);
|
||||
Xobc_cmd_itm cmd = task.Step().Cmd();
|
||||
if (gplx.core.bits.Bitmask_.Has_byte(Gfo_prog_ui_.Status__runnable, cmd.Prog_status())) { // must be runnable
|
||||
Run_task(task, cmd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Run_task(Xobc_task_itm task, Xobc_cmd_itm cmd) {
|
||||
// if task marked for skip, launch skip-cmd on separate thread and exit;
|
||||
if (task_mgr.Skip_mgr().Should_skip(task_mgr.Data_db().Tbl__import_step().Select_one(cmd.Step_id()))) {
|
||||
thread_mgr.Add("skip_" + cmd.Cmd_uid(), Thread_adp_.Start_by_key("skip_xobc: " + cmd.Cmd_name(), new Xobc_task_skip(this, cmd), ""));
|
||||
return;
|
||||
}
|
||||
|
||||
task.Task_status_(gplx.core.progs.Gfo_prog_ui_.Status__working);
|
||||
task_mgr.Send_json("xo.bldr.work.prog__start__recv", task.Save_to(Gfobj_nde.New()));
|
||||
thread_mgr.Add(cmd.Cmd_uid(), Thread_adp_.Start_by_val("xobc: " + cmd.Cmd_name(), cmd, cmd, Xobc_cmd__base.Invk__exec, ctx));
|
||||
}
|
||||
public void Stop_cur() {
|
||||
Xod_power_mgr_.Instance.Wake_lock__rls("task_mgr");
|
||||
int len = this.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xobc_task_itm task = this.Get_at(i);
|
||||
Xobc_cmd_itm cmd = task.Step().Cmd();
|
||||
if (gplx.core.bits.Bitmask_.Has_byte(Gfo_prog_ui_.Status__working, cmd.Prog_status())) { // must be runnable
|
||||
Stop_task(cmd.Cmd_uid());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Redo_cur() {
|
||||
int len = this.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xobc_task_itm task = this.Get_at(i);
|
||||
Xobc_step_itm step = task.Step();
|
||||
Xobc_cmd_itm cmd = step.Cmd();
|
||||
if (gplx.core.bits.Bitmask_.Has_byte(Gfo_prog_ui_.Status__fail, cmd.Prog_status())) { // must be runnable
|
||||
Redo_task(task, step, cmd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Stop_task(String cmd_uid) {
|
||||
thread_mgr.Halt(cmd_uid, Thread_halt_cbk_.Noop);
|
||||
}
|
||||
private void Redo_task(Xobc_task_itm task, Xobc_step_itm step, Xobc_cmd_itm cmd) {
|
||||
cmd = step.Step_fallback_to(cmd.Cmd_fallback());
|
||||
cmd.Cmd_clear();
|
||||
task.Task_status_(gplx.core.progs.Gfo_prog_ui_.Status__working);
|
||||
task_mgr.Send_json("xo.bldr.work.prog__start__recv", task.Save_to(Gfobj_nde.New()));
|
||||
thread_mgr.Add(cmd.Cmd_uid(), Thread_adp_.Start_by_val("xobc: " + cmd.Cmd_name(), cmd, cmd, Xobc_cmd__base.Invk__exec, ctx));
|
||||
}
|
||||
public void On_done(Xobc_cmd_itm cmd, boolean notify) {
|
||||
Xobc_task_itm task = this.Get_by(cmd.Task_id());
|
||||
Xobc_step_itm step = task.Step();
|
||||
boolean step_is_done = step.Cmd_is_last();
|
||||
boolean task_is_done = step_is_done && task.Step_is_last();
|
||||
if (notify)
|
||||
task_mgr.Send_json("xo.bldr.work.prog__done__recv", Gfobj_nde.New().Add_int("task_id", task.Task_id()).Add_bool("task_is_done", task_is_done));
|
||||
|
||||
// step.done -> task.done || step.next
|
||||
if (step_is_done) {
|
||||
step.Step_cleanup();
|
||||
task_mgr.User_db().Done_step_tbl().Insert(cmd.Task_id(), cmd.Step_id());
|
||||
// task.done
|
||||
if (task_is_done) {
|
||||
task.Task_status_(Gfo_prog_ui_.Status__done);
|
||||
task_mgr.User_db().Done_task_tbl().Insert(cmd.Task_id(), task.Task_seqn()); // NOTE: this will order by todo's sort, not by actually completed sorted
|
||||
Del_task(task, task_mgr.Done_mgr());
|
||||
}
|
||||
// step.next
|
||||
else {
|
||||
int next_step = task_mgr.Data_db().Tbl__step_map().Select_step_id(task.Task_id(), step.Step_seqn() + 1);
|
||||
task_mgr.Step_mgr().Load(task, next_step, Xobc_cmd__base.Seqn__0);
|
||||
}
|
||||
}
|
||||
// step.work -> cmd.next
|
||||
else {
|
||||
step.Cmd_idx_next_();
|
||||
}
|
||||
|
||||
// release wake_lock; will be acquired when task is run_next; DATE:2016-06-29
|
||||
Xod_power_mgr_.Instance.Wake_lock__rls("task_mgr");
|
||||
|
||||
// task_regy.done
|
||||
if (task_is_done) {
|
||||
if (this.Len() > 0)
|
||||
this.Run_next();
|
||||
}
|
||||
// task_regy.work
|
||||
else {
|
||||
cmd = task.Step().Cmd();
|
||||
task_mgr.User_db().Work_task_tbl().Update(cmd.Task_id(), task.Task_seqn(), cmd.Step_id(), cmd.Cmd_id());
|
||||
this.Run_next();
|
||||
}
|
||||
}
|
||||
public void On_suspended(Xobc_cmd_itm cmd) {
|
||||
Xobc_task_itm task = this.Get_by(cmd.Task_id());
|
||||
task.Task_status_(Gfo_prog_ui_.Status__suspended);
|
||||
task_mgr.Send_json("xo.bldr.work.stop_cur__recv", Gfobj_nde.New().Add_int("task_id", task.Task_id()));
|
||||
}
|
||||
public void On_fail(Xobc_cmd_itm task, boolean resume, String msg) {
|
||||
Xod_power_mgr_.Instance.Wake_lock__rls("task_mgr");
|
||||
task_mgr.Send_json("xo.bldr.work.prog__fail__recv", Gfobj_nde.New().Add_int("task_id", task.Task_id()).Add_str("err", msg).Add_bool("resume", resume));
|
||||
}
|
||||
public void On_stat(int task_id, String msg) {
|
||||
task_mgr.Send_json("xo.bldr.work.prog__stat__recv", Gfobj_nde.New().Add_int("task_id", task_id).Add_str("msg", msg));
|
||||
}
|
||||
}
|
||||
class Xobc_task_skip implements Gfo_invk {
|
||||
private final Xobc_task_regy__work work_regy;
|
||||
private final Xobc_cmd_itm cmd;
|
||||
public Xobc_task_skip(Xobc_task_regy__work work_regy, Xobc_cmd_itm cmd) {
|
||||
this.work_regy = work_regy;
|
||||
this.cmd = cmd;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
work_regy.On_done(cmd, false);
|
||||
return Gfo_invk_.Rv_handled;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,53 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.brys.evals.*;
|
||||
public class Bry_eval_wkr__builder_central implements Bry_eval_wkr {
|
||||
private final byte[] wiki_dir;
|
||||
public Bry_eval_wkr__builder_central(Io_url wiki_dir) {this.wiki_dir = wiki_dir.RawBry();}
|
||||
public String Key() {return "builder_central";}
|
||||
public void Resolve(Bry_bfr rv, byte[] src, int args_bgn, int args_end) {
|
||||
// EX: "~{builder_central|download_fil|en.wikipedia.org|Xowa_enwiki_2016-05_html_ns.000_db.001.zip}" -> "/xowa/wiki/en.wikipedia.org/tmp/bldr/Xowa_enwiki_2016-05_html_ns.000_db.001.zip/download.zip"
|
||||
byte[][] args = Bry_split_.Split(src, args_bgn, args_end, Byte_ascii.Pipe, Bool_.N);
|
||||
int type = hash.Get_as_byte_or(args[0], Byte_.Max_value_127);
|
||||
if (type == Byte_.Max_value_127) throw Err_.new_wo_type("unknown eval type", "src", src);
|
||||
byte dir_spr = gplx.core.envs.Op_sys.Cur().Fsys_dir_spr_byte();
|
||||
rv.Add(wiki_dir); // "/xowa/wiki/"
|
||||
rv.Add(args[1]).Add_byte(dir_spr); // "en.wikipedia.org/"
|
||||
if (type == Type__wiki_dir) return;
|
||||
rv.Add_str_a7("tmp").Add_byte(dir_spr); // "tmp/"
|
||||
rv.Add_str_a7("bldr").Add_byte(dir_spr); // "bldr/"
|
||||
rv.Add(args[2]).Add_byte(dir_spr); // "Xowa_enwiki_2016-05_html_ns.000_db.001.zip/"
|
||||
switch (type) {
|
||||
case Type__download_fil: rv.Add_str_a7("download.zip"); break;
|
||||
case Type__unzip_dir: rv.Add_str_a7("unzip").Add_byte(dir_spr); break;
|
||||
default: throw Err_.new_unhandled_default(type);
|
||||
}
|
||||
}
|
||||
|
||||
public static final byte Type__download_fil = 0, Type__unzip_dir = 1, Type__wiki_dir = 2;
|
||||
private static final Hash_adp_bry hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("download_fil", Type__download_fil)
|
||||
.Add_str_byte("unzip_dir", Type__unzip_dir)
|
||||
.Add_str_byte("wiki_dir", Type__wiki_dir)
|
||||
;
|
||||
public static String Make_str(byte type, String domain, String file_name) {
|
||||
String type_name = null;
|
||||
switch (type) {
|
||||
case Type__download_fil: type_name = "download_fil"; break;
|
||||
case Type__unzip_dir: type_name = "unzip_dir"; break;
|
||||
case Type__wiki_dir: type_name = "wiki_dir"; break;
|
||||
default: throw Err_.new_unhandled_default(type);
|
||||
}
|
||||
return "~{" + String_.Format("builder_central|{0}|{1}|{2}", type_name, domain, file_name) + "}";
|
||||
}
|
||||
public static String Make_str(byte type, String domain) {
|
||||
String type_name = null;
|
||||
switch (type) {
|
||||
case Type__wiki_dir: type_name = "wiki_dir"; break;
|
||||
default: throw Err_.new_unhandled_default(type);
|
||||
}
|
||||
return "~{" + String_.Format("builder_central|{0}|{1}", type_name, domain) + "}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,40 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
public class Time_dhms_ {
|
||||
public static String To_str(Bry_bfr bfr, long val, boolean show_unit, int max_places) {To_bfr(bfr, val, show_unit, max_places); return bfr.To_str_and_clear();}
|
||||
public static void To_bfr(Bry_bfr bfr, long val, boolean show_unit, int max_places) {
|
||||
byte suffix = Byte_ascii.Null;
|
||||
int count = 0;
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
// get factor and unit
|
||||
long factor = 0;
|
||||
byte unit = Byte_ascii.Null;
|
||||
switch(i) {
|
||||
case 0: unit = Byte_ascii.Ltr_d; factor = 86400; break;
|
||||
case 1: unit = Byte_ascii.Ltr_h; factor = 3600; break;
|
||||
case 2: unit = Byte_ascii.Ltr_m; factor = 60; break;
|
||||
case 3: unit = Byte_ascii.Ltr_s; factor = 1; break;
|
||||
}
|
||||
// calc cur and update val; EX: 3690 -> cur:1,mod:90
|
||||
int cur = (int)(val / factor);
|
||||
val %= factor;
|
||||
if (count == 0) { // no str yet
|
||||
if ( cur == 0 // cur is 0; EX: 3690 and factor = 86400 -> 0 days; don't write anything
|
||||
&& i != 3) // unless it is the seconds place; need to handle "0 s" specifically
|
||||
continue;
|
||||
suffix = unit; // set suffix
|
||||
bfr.Add_int_variable(cur); // write cur; note that this is not zero-padded
|
||||
}
|
||||
else { // str exists
|
||||
bfr.Add_int_pad_bgn(Byte_ascii.Num_0, 2, cur); // write cur; note that this zero-padded; also, note will write "00" if cur == 0
|
||||
}
|
||||
if (++count == max_places) break; // stop if max-places reached; EX: 86400 should write 1:00, not 1:00:00:00
|
||||
if (i != 3) // do not add ":" if seconds
|
||||
bfr.Add_byte_colon();
|
||||
}
|
||||
if (show_unit) // add units; EX: " s" for seconds
|
||||
bfr.Add_byte_space().Add_byte(suffix);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,23 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Time_dhms__tst {
|
||||
private final Time_dhms__fxt fxt = new Time_dhms__fxt();
|
||||
@Test public void S__0() {fxt.Test__to_str( 0, 4, "0 s");}
|
||||
@Test public void S__1() {fxt.Test__to_str( 1, 4, "1 s");}
|
||||
@Test public void S__2() {fxt.Test__to_str( 30, 4, "30 s");}
|
||||
@Test public void M__1() {fxt.Test__to_str( 60, 4, "1:00 m");}
|
||||
@Test public void M__2() {fxt.Test__to_str( 600, 4, "10:00 m");}
|
||||
@Test public void H__1() {fxt.Test__to_str( 3600, 4, "1:00:00 h");}
|
||||
@Test public void H__2() {fxt.Test__to_str( 5025, 4, "1:23:45 h");}
|
||||
@Test public void D__1() {fxt.Test__to_str( 86400, 4, "1:00:00:00 d");}
|
||||
@Test public void Max_places() {fxt.Test__to_str( 86400, 2, "1:00 d");}
|
||||
}
|
||||
class Time_dhms__fxt {
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
public Time_dhms__fxt Test__to_str(long v, int max_places, String expd) {
|
||||
Gftest.Eq__str(expd, Time_dhms_.To_str(bfr, v, Bool_.Y, max_places));
|
||||
return this;}
|
||||
}
|
||||
Reference in New Issue
Block a user