Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

83
LINES

< > BotCompany Repo | #1030709 // BEA Thought Bot 1 [dev.]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (24520L/168K).

1  
!7
2  
3  
!include early #1030718 // new unstructure
4  
set flag unstructure_debug.
5  
6  
extend BEAObject {
7  
  S _originalStruct;
8  
}
9  
10  
sclass CRef {
11  
  long id;
12  
  S gid;
13  
}
14  
15  
module BEAThoughtBot1 > DynCRUD<BEAObject> {
16  
  switchable S user;
17  
  switchable S botToken;
18  
19  
  start {
20  
    //crud.unshownFields = litset("_originalStruct");
21  
  }
22  
  
23  
  void importAll {
24  
    Map data = cast postJSONPage("https://bea.gazelle.rocks/bot/beaList", _user := user, _botToken := botToken);
25  
    L<Map> list = cast data.get("result");
26  
    if (list == null) ret with infoBox(str(data.get("error")));
27  
    new L<BEAObject> objects;
28  
    for (Map map : list) {
29  
      //long id = toLong(map.get("id"));
30  
      GlobalID globalID = GlobalID((S) map.get("gid"));
31  
      S struct = cast map.get("struct");
32  
      BEAObject o = uniq BEAObject(+globalID);
33  
      objects.add(o);
34  
      cset(o, _originalStruct := struct);
35  
    }
36  
37  
    unpackImportedStructures(objects);
38  
  }
39  
40  
  void unpackImportedStructures(Cl<BEAObject> l) {
41  
    fOr (BEAObject o : l) try {
42  
      S struct = o._originalStruct;
43  
      continue if empty(struct);
44  
      cclearAllDynamicFields(o);
45  
46  
      // make markers explicit so we can modify the token count
47  
      //LS tok = javaTokForStructure(structure_convertTokenMarkersToExplicit(struct));
48  
49  
      // resolve concept references
50  
      /*jreplace(tok, "CRef(id=<int>)", "null");
51  
      jreplace_dyn(tok, "CRef(gid=<quoted>)", (_tok, cIdx) ->
52  
        uniq BEAObject(globalID := unquote(_tok.get(cIdx+8))));*/
53  
      //print(join(tok)));
54  
55  
      unstructure_Data ud = new {
56  
        O postProcessValue(O value) {
57  
          if (dynShortNameIs CRef(value)) {
58  
            S gid = getString gid(value);
59  
            print("CRef found: " + gid);
60  
            if (gid != null)
61  
              ret uniq BEAObject(globalID := GlobalID(gid));
62  
            null;
63  
          }
64  
          ret value;
65  
        }
66  
      };
67  
      O classFinder = unstructureClassFinderAllowingCertainClasses_preferUtils(false, "GlobalID", "CRef", "BEAObject");
68  
      Concept data = cast unstructure_tok(javaTokC_noMLS_iterator(struct), false, classFinder, ud);
69  
      //O data = safeUnstructureAllowingCertainClasses(struct, "CRef");
70  
71  
      print(+struct);
72  
      print(+data);
73  
      print(className := className(data));
74  
      for (S field, O value : allConceptFieldsAsMap(data)) {
75  
        printVars_str(+field, +value);
76  
        //if (eqOneOf(field, "id", "globalID")) continue;
77  
        //cset(o, field, value);
78  
      }
79  
    } catch print e {
80  
      cset(o, _errorUnpacking := getStackTrace(e));
81  
    }
82  
  }
83  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030709
Snippet name: BEA Thought Bot 1 [dev.]
Eternal ID of this version: #1030709/32
Text MD5: f64da41d5cfd0de4be09dcc0b86152be
Transpilation MD5: 8703e43a84d04622b70e8eafbf9b8dc9
Author: stefan
Category:
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-03-16 17:29:57
Source code size: 2516 bytes / 83 lines
Pitched / IR pitched: No / No
Views / Downloads: 125 / 389
Version history: 31 change(s)
Referenced in: [show references]