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).

!7

!include early #1030718 // new unstructure
set flag unstructure_debug.

extend BEAObject {
  S _originalStruct;
}

sclass CRef {
  long id;
  S gid;
}

module BEAThoughtBot1 > DynCRUD<BEAObject> {
  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<Map> list = cast data.get("result");
    if (list == null) ret with infoBox(str(data.get("error")));
    new L<BEAObject> 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<BEAObject> 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=<int>)", "null");
      jreplace_dyn(tok, "CRef(gid=<quoted>)", (_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));
    }
  }
}

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: 176 / 461
Version history: 31 change(s)
Referenced in: [show references]