!7 !include early #1030718 // new unstructure set flag unstructure_debug. extend BEAObject { S _originalStruct; } sclass CRef { long id; S gid; } module BEAThoughtBot1 > DynCRUD { switchable S user; switchable S botToken; start { //crud.unshownFields = litset("_originalStruct"); } void importAll { Map data = cast postJSONPage("https://bea.gazelle.rocks/bot/beaList", _user := user, _botToken := botToken); L list = cast data.get("result"); if (list == null) ret with infoBox(str(data.get("error"))); new L objects; for (Map map : list) { //long id = toLong(map.get("id")); GlobalID globalID = GlobalID((S) map.get("gid")); S struct = cast map.get("struct"); BEAObject o = uniq BEAObject(+globalID); objects.add(o); cset(o, _originalStruct := struct); } unpackImportedStructures(objects); } void unpackImportedStructures(Cl l) { fOr (BEAObject o : l) try { S struct = o._originalStruct; continue if empty(struct); cclearAllDynamicFields(o); // make markers explicit so we can modify the token count //LS tok = javaTokForStructure(structure_convertTokenMarkersToExplicit(struct)); // resolve concept references /*jreplace(tok, "CRef(id=)", "null"); jreplace_dyn(tok, "CRef(gid=)", (_tok, cIdx) -> uniq BEAObject(globalID := unquote(_tok.get(cIdx+8))));*/ //print(join(tok))); unstructure_Data ud = new { O postProcessValue(O value) { if (dynShortNameIs CRef(value)) { S gid = getString gid(value); print("CRef found: " + gid); if (gid != null) ret uniq BEAObject(globalID := GlobalID(gid)); null; } ret value; } }; O classFinder = unstructureClassFinderAllowingCertainClasses_preferUtils(false, "GlobalID", "CRef", "BEAObject"); Concept data = cast unstructure_tok(javaTokC_noMLS_iterator(struct), false, classFinder, ud); //O data = safeUnstructureAllowingCertainClasses(struct, "CRef"); print(+struct); print(+data); print(className := className(data)); for (S field, O value : allConceptFieldsAsMap(data)) { printVars_str(+field, +value); //if (eqOneOf(field, "id", "globalID")) continue; //cset(o, field, value); } } catch print e { cset(o, _errorUnpacking := getStackTrace(e)); } } }